function fun_getNum(obj){
	    $("Msg").innerHTML="";
		$("mms").innerHTML="";
		var Act=$("Action").value;
		$("pc_list_content_text1").style.background="";
		
		var toobj=$("btn_").value;
		if (toobj!=""){
		if($(toobj).value.length<6){
		  $(toobj).focus();
		  $(toobj).value +=obj.value;
		}
	}
}
function Jta_Enter(str){
	str_Arr=str.split("|");
	var LoginType=str_Arr[1];
	var ClockType=str_Arr[2];
	var CheckLock=str_Arr[3];

	var stepNext =$("step").value;
	var ActType  =$("Action").value;
	Check_ESMan_No();
	var frm_name="form1";
	var vito="Msg";
	var action="jta_pc_Action.asp?LoginType="+LoginType+"&ClockType="+ClockType+"&CheckLock="+CheckLock;
	var ajax=new AJAXRequest({
		url: action,
		method: "POST",
	    //oncomplete: callback,
		charset: "UTF-8"
	}); 
    ajax.postf($(frm_name),
	function(obj) {
	  Rstr=obj.responseText;

	  if (Rstr.split("@v@")[1]!=""){
         Rstr1=Rstr.split("@v@")[1];
		 Rstr=Rstr.split("@v@")[0];
	  }
 
	//  return false
	  if (Rstr!=="cOK"){
		var f=Rstr.split("|")[4];
		var l=Rstr.split("|")[5];
		var fl=f+","+l;
		Rstr=Rstr.split("|")[0];
	  }

     
	  switch(stepNext){
	  case "CheckEid":
	   if (Rstr=="cOK"){
	    if (LoginType!="1"){
			
		 //select in or out
		  if (ClockType!="2"){
		    $("select_ul").style.display="block";
            $("lfname").innerHTML=fl;
		    $("select_ul1").style.display="block";
		    $("step").value="SelectType";
		    $("Action").value="no";
			$("btn_").value="ESt";
			$("ESt").value="";
		  }else{
		    can(Rstr);
			$("Msg").innerHTML="Accepted - Swipe & Go";
			$($("btn_").value).value="";
			$("pc_list_content_text1").style.background="#00CC00";
            if (Rstr1!="" && Rstr1!=undefined){
	        var ms="";
		    if (Rstr1.split("|")[0]=="OK"){
			if (Rstr1.split("|")[1]!=""){
			  ms += "PUBL: "+Rstr1.split("|")[1];
			}
			if (Rstr1.split("|")[2]!=""){
			  ms +=	"<br>PRIV: "+Rstr1.split("|")[2];
			}
			 $("mms").innerHTML=ms;
			 can(Rstr);
			 $("Msg").innerHTML="Accepted - Swipe & Go";
		   }
		  
	      }
 //      can(Rstr);
//		  
//	      if (Rstr=="cOK"){
//			 $("Msg").innerHTML="Accepted - Swipe & Go";
//			 $($("btn_").value).value="";
//			 $("pc_list_content_text1").style.background="#00CC00";
//		  }else{
//			 $("Msg").innerHTML=Rstr;
//		     $($("btn_").value).value="";
//			 $("pc_list_content_text1").style.background="#FF0000";  
//		  }

		  }
		  
		}else{
		  //check Card
		   $("select_ul").style.display="none";
		   $("select_ul1").style.display="none";
		   $("ESt").value="";
		   $("card_ul").style.display="block";
		   $("Action").value="no";
		   $("step").value="CheckCard";
		   $("btn_").value="ECard";
		}
	   }else if(Rstr!=""){
	     $("Msg").innerHTML=Rstr;
		 $("pc_list_content_text1").style.background="#FF0000";
		 $($("btn_").value).value="";
	   }
	  break
	  case "CheckCard":
	 
	   if(Rstr=="cOK"){
	  	
		   if (ClockType!="2"){
			 $("select_ul").style.display="block";
			 $("lfname").innerHTML=fl;
			 $("select_ul1").style.display="block";
			 
			 $("Action").value="no";
			 $("step").value="SelectType";
			 $("btn_").value="ESt";
			 $("ESt").value="";
			}else{
			  can(Rstr);
			  
			  if (Rstr=="cOK"){
				 
				 $($("btn_").value).value="";
				 $("pc_list_content_text1").style.background="#00CC00";
				if (Rstr1!="" && Rstr1!=undefined){
				var ms="";
				if (Rstr1.split("|")[0]=="OK"){
				if (Rstr1.split("|")[1]!=""){
				  ms += "PUBL: "+Rstr1.split("|")[1];
				}
				if (Rstr1.split("|")[2]!=""){
				  ms +=	"<br>PRIV: "+Rstr1.split("|")[2];
				}
				 $("mms").innerHTML=ms;
				 can(Rstr);
				 $("Msg").innerHTML="Accepted - Swipe & Go";
			   }
			  
		  	}
		  }else{
			 
		     $($("btn_").value).value="";
			 $("pc_list_content_text1").style.background="#FF0000";  
			 can(Rstr);
			 $("Msg").innerHTML=Rstr;
			 $("Msg").innerHTML="Accepted - Swipe & Go";
		  }
		}
	   }else if(Rstr!=""){
	   
		$($("btn_").value).value="";
		$("pc_list_content_text1").style.background="#FF0000";
		can(Rstr);
		$("Msg").innerHTML=Rstr;
	   }
	  break
	  case"SelectType":

	  if (Rstr1!="" && Rstr1!=undefined){
	      var ms="";
		  if (Rstr1.split("|")[0]=="OK"){
			if (Rstr1.split("|")[1]!=""){
			  ms += "PUBL: "+Rstr1.split("|")[1];
			}
			if (Rstr1.split("|")[2]!=""){
			  ms +=	"<br>PRIV: "+Rstr1.split("|")[2];
			}
			 $("mms").innerHTML=ms;
			 can(Rstr);
		   }
		  
	  }
	 
	  var Mstr=$("Mstr").value;
	  if (Mstr!=""){
	     m_Arr=Mstr.split("|");
      }
	    switch(ActType){
		 case "1":  can(Rstr); $("Msg").innerHTML="";	$($("btn_").value).focus(); if (Rstr.indexOf("locked")>=0){ can(Rstr);}break;
		 case "2":  can(Rstr); $("Msg").innerHTML=Rstr;	$($("btn_").value).focus(); if (Rstr.indexOf("locked")>=0){ can(Rstr);}break;
		 case "3":  can(Rstr); $("Msg").innerHTML=Rstr;	$($("btn_").value).focus(); if (Rstr.indexOf("locked")>=0){ can(Rstr);}break;
		 case "4":  fun_Msg(Rstr); $($("btn_").value).focus(); if (Rstr.indexOf("locked")>=0){ can(Rstr);}break;
		 case "5":  fun_Msg(Rstr); $($("btn_").value).focus(); if (Rstr.indexOf("locked")>=0){ can(Rstr);}break;
		 case "6":  fun_Msg(Rstr); $($("btn_").value).focus(); if (Rstr.indexOf("locked")>=0){ can(Rstr);}break;
		 case "7":  fun_Msg(Rstr); $($("btn_").value).focus(); if (Rstr.indexOf("locked")>=0){ can(Rstr);}break;
		 case "8":
		   if(Rstr=="OK1"){
		     if(($("step3_").value=="3_1")&&m_Arr[3]!=""){
		      $("Msg").innerHTML="";
			  $("Msgbox2_ul").style.display="block";
			  $("Msgbox2").innerHTML=m_Arr[3];
			  $("step3_").value="3_2";
			  $("btn_").value="EBrch";
			 }
			}else if (Rstr.indexOf("-")>0){
		     can(Rstr);
			 
		   }else{
		     $("Msg").innerHTML=Rstr;
			 $($("btn_").value).value="";
			 if (Rstr!=""){
               $("pc_list_content_text1").style.background="#FF0000";
			 }else{
			   $("pc_list_content_text1").style.background="#FFFFFF";
			 }
			 if (Rstr.indexOf("locked")>=0){ can(Rstr);}
			}
		 break;
		 case "9":
		 	if(Rstr=="OK1"){
		    if(($("step3_").value=="3_1")&&m_Arr[3]!=""){
		      $("Msg").innerHTML="";
			  $("Msgbox3_ul").style.display="block";
			  $("Msgbox3").innerHTML=m_Arr[3];
			  $("step3_").value="3_3";
			  $("btn_").value="EDept";
		
			  }
			}else if (Rstr.indexOf("-")>0){
		     can(Rstr);
		    }else{
		     $("Msg").innerHTML=Rstr;
			 $($("btn_").value).value="";
			 if (Rstr!=""){
               $("pc_list_content_text1").style.background="#FF0000";
			 }else{
			   $("pc_list_content_text1").style.background="#FFFFFF";
			 }
			 if (Rstr.indexOf("locked")>=0){ can(Rstr);}
		   }
		 break;
		 case "10":
		 if(Rstr=="OK"){
		    if(($("step3_").value=="3_2")&&m_Arr[3]!=""){
		      $("Msg").innerHTML="";
			  $("Msgbox3_ul").style.display="block";
			  $("Msgbox3").innerHTML=m_Arr[3];
			  $("step3_").value="3_3";
			  $("btn_").value="EDept";

			  }
			}else if (Rstr.indexOf("-")>0){
		     can(Rstr);

		    }else{
		     $("Msg").innerHTML=Rstr;
			 $($("btn_").value).value="";
			 if (Rstr!=""){
               $("pc_list_content_text1").style.background="#FF0000";
			 }else{
			   $("pc_list_content_text1").style.background="#FFFFFF";
			 }
			 if (Rstr.indexOf("locked")>=0){ can(Rstr);}
		 }
		 break;
		 case "11":
		 if(Rstr=="OK1" || Rstr=="OK2"){

		      if(($("step3_").value=="3_1")&&m_Arr[3]!="" && Rstr=="OK1"){
		         $("Msg").innerHTML="";
			     $("Msgbox2_ul").style.display="block";
			     $("Msgbox2").innerHTML=m_Arr[3];
			     $("step3_").value="3_2";
				 $("btn_").value="EBrch";

			  }else if (($("step3_").value=="3_2")&&m_Arr[4]!="" && Rstr=="OK2"){
			     $("Msg").innerHTML="";
			     $("Msgbox3_ul").style.display="block";
			     $("Msgbox3").innerHTML=m_Arr[4];
			     $("step3_").value="3_3"; 
				 $("btn_").value="EDept";
		
			  }
			}else if (Rstr.indexOf("-")>0){
		     can(Rstr);

		    }else{

		     $("Msg").innerHTML=Rstr;
			 if (Rstr!=""){
               $("pc_list_content_text1").style.background="#FF0000";
			 }else{
			   $("pc_list_content_text1").style.background="#FFFFFF";
			 }
			 $($("btn_").value).value="";
			 if (Rstr.indexOf("locked")>=0){ can(Rstr);}
		 }
		 
		 break;
		 case "12":		   can(Rstr); 	if (Rstr.indexOf("locked")>=0){ can(Rstr);} break;
		 case "13":		   can(Rstr);   if (Rstr.indexOf("locked")>=0){ can(Rstr);}	 break;
		 case "14":		   can(Rstr);   if (Rstr.indexOf("locked")>=0){ can(Rstr);}	 break;
		 case "15":		   can(Rstr);	if (Rstr.indexOf("locked")>=0){ can(Rstr);} break;
		 case "16": 	   can(Rstr); 	if (Rstr.indexOf("locked")>=0){ can(Rstr);} break;
		 case "17":		   can(Rstr); 	if (Rstr.indexOf("locked")>=0){ can(Rstr);} break;
		 case "18":       can(Rstr); 	if (Rstr.indexOf("locked")>=0){ can(Rstr);} break;
		 case "19": 	  can(Rstr); 	if (Rstr.indexOf("locked")>=0){ can(Rstr);} break;
		 case "20":      can(Rstr);  if (Rstr.indexOf("locked")>=0){ can(Rstr);} break;
		 case "21":  	  can(Rstr); 	if (Rstr.indexOf("locked")>=0){ can(Rstr);} break;
		}
				
	  break
	  
	}
	$($("btn_").value).focus(); 
  }
);

}
function fun_Msg(Rstr){
	if(Rstr=="OK"){
    }else if(Rstr.indexOf("-")>0 && Rstr.indexOf("ERROR")!=0){//else if (){
      can(Rstr);
	$("pc_list_content_text1").style.background="#00CC00";
    }else if (Rstr.indexOf("ERROR")>=0 || Rstr.indexOf("locked")>=0){
		can(Rstr);
	}else{
	 $("Msg").innerHTML=Rstr;
	 $($("btn_").value).value="";
	 $("pc_list_content_text1").style.background="#FF0000";
	 $($("btn_").value).focus(); 
  } 
}
function can(Rstr){
	 $("Msg").innerHTML=Rstr; 
	 $("step3_").value="";
	 $("Action").value="no";
	 $("Mstr").value="";
	 $("Msgbox1_ul").style.display="none";
	 $("Msgbox2_ul").style.display="none";
	 $("Msgbox3_ul").style.display="none";
	 //$("step").value="CheckEid";
	 $("Eid").value="";
	 $("ECard").value="";
	 $("select_ul").style.display="none";
	 $("select_ul1").style.display="none";
	 $("card_ul").style.display="none";
	 $("ECmpy").value="";
	 $("EBrch").value="";
	 $("EDept").value="";
	 $("ESt").value="";
	// $("btn_").value="Eid";
	 fun_init();
	 $("ctr").value="";
    
	 if(Rstr!="" && Rstr.indexOf("ERROR")<1 && Rstr.indexOf("locked")<1 && Rstr.indexOf("not")<1){ 
		   $("pc_list_content_text1").style.background="#00CC00";
	 }else if(Rstr.indexOf("ERROR")>=0 || Rstr.indexOf("locked")>=0 || Rstr.indexOf("not")>=0){ 
		   $("pc_list_content_text1").style.background="#FF0000";
	 }else{
		   $("pc_list_content_text1").style.background="#ffffff";
	 }
}
function Jta_IN_OUT(str){
if ($("step").value=="SelectType"){
  $("Action").value=str;
}
}

function fun_focus_move(){
	$($("btn_").value).focus();
//      var   txtRange   =   $($("btn_").value).createTextRange();   
//      txtRange.moveStart("character",$($("btn_").value).value.length);   
//      txtRange.moveEnd("character",0);   
//      txtRange.select(); 
//	  
}
function fun_show(num,TxtName,Msgbox1){
     $("mms").innerHTML="";
	 $("select_ul1").style.display="none";
	 $("Msgbox"+num+"_ul").style.display="block";
	 $(TxtName).style.display="block";
	 $("Msgbox"+num+"").innerHTML=Msgbox1;
	 $("step3_").value="3_"+num+"";
	 $("btn_").value=TxtName;
	 $(TxtName).focus();
}

function fun_Setvalue(str){
	str_arr=str.split("|")
	var type        =str_arr[0];
	var fun_Key_Cap =str_arr[1];
	var Msgbox1     =str_arr[2];
	var Msgbox2     =str_arr[3];
	var Msgbox3     =str_arr[4];
	var payCode     =str_arr[5];
	var key         =str_arr[6]; 
	var cResult     =$("cResult").value;
 	if ($("step").value=="SelectType"){
    if ($("Mstr").value=="" && type!="no"){
		 $("Mstr").value=str;
		 $("Action").value=type;
		 switch (type){
		 case "1":    return false;	                        break;
		 case "2":    Jta_IN_OUT(type); Jta_Enter(cResult);	break;
		 case "3":    Jta_IN_OUT(type); Jta_Enter(cResult);  	break;
		 case "4":    fun_show('3','EDept',Msgbox1);         	break;
		 case "5":    fun_show('1','ECmpy',Msgbox1);	        break;
		 case "6":    fun_show('2','EBrch',Msgbox1);           break;
		 case "7":	   fun_show('3','EDept',Msgbox1);	        break;
		 case "8": 	   fun_show('1','ECmpy',Msgbox1);	        break;
		 case "9":	   fun_show('1','ECmpy',Msgbox1);            break;
		 case "10":	   fun_show('2','EBrch',Msgbox1);	        break;
		 case "11":	   fun_show('1','ECmpy',Msgbox1);	        break;
		 case "12":   Jta_IN_OUT('12');Jta_Enter(cResult);      break; //3
		 case "13":   Jta_IN_OUT('13');Jta_Enter(cResult);      break;//2
		 case "14":   Jta_IN_OUT('14');Jta_Enter(cResult);      break;
		 case "15":   Jta_IN_OUT('15');Jta_Enter(cResult);      break;
		 case "16":	   fun_show('1','ECmpy',Msgbox1);	        break;
		 case "17":	   fun_show('1','ECmpy',Msgbox1);	        break;
		 case "18":   Jta_IN_OUT(type);Jta_Enter(cResult);     break;
		 case "19":   Jta_IN_OUT(type);Jta_Enter(cResult);     break;
		 case "20":   Jta_IN_OUT(type);Jta_Enter(cResult);     break;
		 case "21":   Jta_IN_OUT(type);Jta_Enter(cResult);     break;
   }
  }
 }

}
function fun_keypress(k){
$("mms").innerHTML="";
var how;
  $("pc_list_content_text1").style.background="";
  $("Msg").innerHTML="";
  var cResult=$("cResult").value;
  c_Arr=cResult.split("|");
  var step=$("step").value;
  if (k==17 && step!=="CheckEid"){$("ctr").value="";$("ctr").value=17;}
switch(k){
	  case 13 : Jta_Enter(cResult); break;//Jta_IN_OUT('2');Jta_IN_OUT('3');Jta_IN_OUT('21');;Jta_Enter(cResult);Jta_Enter(cResult);
	  case 73 : if(c_Arr[2]!="2" && step!=="CheckEid"){fun_Setvalue('2|in||||0|IN'); } break;
	  case 79 : if(c_Arr[2]!="2" && step!=="CheckEid"){fun_Setvalue('3|OUT||||0|OUT'); } break;
	  case 80 : if(c_Arr[2]=="3" && step!=="CheckEid"){fun_Setvalue('21|Punch||||0|Swipe & Go');}break;
	  case 49 : if ($("ctr").value==17 && step!=="CheckEid"){ how=1; $("ctr").value=""}break;
	  case 50 : if ($("ctr").value==17 && step!=="CheckEid"){ how=2; $("ctr").value=""}break;
	  case 51 : if ($("ctr").value==17 && step!=="CheckEid"){ how=3; $("ctr").value=""}break;
	  case 52 : if ($("ctr").value==17 && step!=="CheckEid"){ how=4; $("ctr").value=""}break;
	  case 53 : if ($("ctr").value==17 && step!=="CheckEid"){ how=5; $("ctr").value=""}break;
	  case 54 : if ($("ctr").value==17 && step!=="CheckEid"){ how=6; $("ctr").value=""}break;
}
if(c_Arr[2]=="2"){
  how=0;
}
if (c_Arr[2]!="2" && how>0) {
 var j=1;
  for (i=4;i<c_Arr.length;i++){
  var a= "Ctrl + "+j;
  switch(c_Arr[i]){
  case "2" : a="In"; break;
  case "3" : a="Out"; break;
  case "4" : a="Swipe & Go"; break;
  case "12": a="Break Start"; break;
  case "13": a="Break End"; break;
  case "14": a="Lunch Start"; break;
  case "15": a="Lunch End"; break;
 
  }
    str=c_Arr[i]+"|"+c_Arr[i+1]+"|"+c_Arr[i+2]+"|"+c_Arr[i+3]+"|"+c_Arr[i+4]+"|"+c_Arr[i+5]+"|"+a;
	if (j==how){
	  fun_Setvalue(str);
	  return false;
	}
	i=i+5;
	j++;
  }
 }
 
}
function fun_Clear(){
  $($("btn_").value).value="";
  $($("btn_").value).focus();
}
function fun_black(){
  var h=$($("btn_").value).value.length;
  $($("btn_").value).value =$($("btn_").value).value.substr(0,h-1);
  $($("btn_").value).focus();
}
function fun_Close(){
  this.close();
}

function Check_ESMan_No(){
   var No_End=$("Eid").value;
   No_End=No_End.replace(/(^\s*)|(\s*$)/g, ""); 
   var Len_No=No_End.length;
   if (Len_No<6 && Len_No>0){
	   for (var i=0;i<6-Len_No;i++){
	   No_End="0"+No_End;
	   }
	   $("Eid").value=No_End;
   }
   if ($("Eid").value==""){
       $("Eid").value="000000";
   }
}
function fun_init(){
str=$("cResult").value;
str_Arr=str.split("|");
var LoginType=str_Arr[1];
var ClockType=str_Arr[2];
var CheckLock=str_Arr[3];
if (LoginType=="3"){
 $("card_ul").style.display="block";
 $("eid_ul").style.display="none";
 $("btn_").value="ECard";
 $("step").value="CheckCard";
 $($("btn_").value).focus();
}else{
 $("card_ul").style.display="none";
 $("eid_ul").style.display="block";
 $("btn_").value="Eid";
 $("step").value="CheckEid";
 $($("btn_").value).focus();
}

}
function fun_Get_Date(){
  var ajax=new AJAXRequest;
  ajax.update('show_','jta_pc_Action.asp?Action=GetDate',1000);
}
