
function Card(){ this.days=new Array(); this.hours=0; }
function ETime(){ this.Cards=new Array(); this.chkOption=0; }
var eTime=new ETime();

//----------------------------------------------------------------------- PRINT ETIME CARD ----------------

	function onETimePrint(hIndex,isPreview,frmID){
		var frm=window.Lib.getFormByID(frmID);
		frm.hIndex.value=hIndex;

		if(isPreview==1){ 
			window.location.href="report.asp?hEvent=etime-card-preview&hIndex="+ hIndex;
		}else{
			window.Lib.quickSubmit(frmID,'etime-printer-clicked');
		}
	}

//----------------------------------------------------------------------- SCROLL TIMECARDS ----------------

	function tcMoveNext(){ window.Lib.quickSubmit('info','mnu_timecards_next'); }
	function tcMovePrev(){ window.Lib.quickSubmit('info','mnu_timecards_prev'); }
	
	function pcMoveNext(){ window.Lib.quickSubmit('info','mnu_paychecks_next'); }
	function pcMovePrev(){ window.Lib.quickSubmit('info','mnu_paychecks_prev'); }

//----------------------------------------------------------------------- DIRECT DEPOSIT ------------------

	function ddEvalAddress(frm,direction){
		var mnu=(direction=="BACK") ? 'mnu_directdepsit_address_back' : 'mnu_directdepsit_banking';
		var s="";					// from info.inc
		s+=frm.txtStreet1.value					+":";
		s+=frm.txtStreet2.value					+":";
		s+=frm.txtCity.value					+":";
		s+=frm.txtState.value					+":";
		s+=frm.txtZip.value						+":";
		s+=(frm.rdoMailing[0].checked) ? 2 : 1	+":";
		frm.hString.value=s;
		window.Lib.quickSubmit(frm.id,mnu);
	}
	
	function btnNext_Clicked(){
	var PROC="btnNext_Clicked";
		try{
			var acRB=window.Lib.getcontrol('rb-AccNum');
			var acDV=window.Lib.getcontrol('dv-AccNum');
			if(acDV.value==acRB.value){
				ddEvalBankingGO('mnu_directdepsit_conf');
			}else{
				alert(MSG7);
			}
		}catch(e){ window.Lib.errorLogout(e.message,PROC,"Emp"); }	
	}

	function ddEvalBanking(frm){
		var PROC="ddEvalBanking";
		try{
			var mnu=(arguments[1]) ? 'mnu_directdepsit_banking_back' : 'mnu_directdepsit_conf';
			if(mnu=='mnu_directdepsit_conf'){	
				if(frm.txtAccNum.value!=frm.hidAccNum.value){
					//if(window.ExecQ=="0"){
						var s=prompt("Please confirm your checking account number","");
						if(s==frm.txtAccNum.value){ 
							ddEvalBankingGO(mnu); 
						}else{
							alert("Invalid value, please reenter.");
						}
					//}else{
						//vzmac
						//var cm=new clsConfirm(frm.txtAccNum,mnu,30,260);	
					//}	
				}else{
					ddEvalBankingGO(mnu);
				}
			}else{
				ddEvalBankingGO(mnu);
			}
		}catch(e){ window.Lib.errorLogout(e.message,PROC,"Emp"); }
	}

	function ddEvalBankingGO(menu){ 
		var PROC="ddEvalBankingGO";
		try{
			var BankName=window.Lib.getcontrol('rb-BankName');
			var BankNum=window.Lib.getcontrol('rb-BankNum');
			var AccNum=window.Lib.getcontrol('rb-AccNum');
			var hAccType=window.Lib.getcontrol('h-AccType');
			var frm=window.Lib.getFormByID('right-box');
			
			var s="";	
			s+=BankName.value					+":";
			s+=BankNum.value					+":";
			s+=AccNum.value						+":";
			s+=hAccType.value					+":";	
			frm.hString.value=s;

			if(BankNum.value.length<9){alert(MSG8);return false;}

			if(getDDSubmitValidationError(BankName.value,BankNum.value,AccNum.value)){
				window.Lib.quickSubmit(frm.id,menu);
			}else{
				window.Lib.hidelayer('eleminfo');
				alert(MSG8);
			}
		}catch(e){ window.Lib.errorLogout(e.message,PROC,"Emp"); }	
	}
	
	function getDDSubmitValidationError(bname,bnum,anum){
		if(window.Lib.validate(bname,'alphanumericplus',true)){
			if(window.Lib.validate(bnum,'numeric',true,false)){
				return window.Lib.validate(anum,'numeric',true,false);
			}else{
				return false;
			}
		}else{
			return false;
		}
		return true;	
	}

//----------------------------------------------------------------------- EMPLOYEE INFO -------------------

function gotoUpdateEmpInfo(frmID){
	var frm=window.Lib.getFormByID(frmID);
	frm.hEvent.value='persupd-screen';
	frm.submit();
}

function saveEmpInfo(frm){
	frm.hEvent.value="saveempinfo";
	frm.submit();
}

function updatePassword(frm){
	var flag=true;
	if(frm.txtPassword1.value!=frm.txtPassword2.value){	flag=false; }
	if(flag){ flag=window.Lib.validate(frm.txtPassword2,'alphanumeric') }
	if(flag){
		window.Lib.quickSubmit(frm.id,'updpassword');
	}else{
		alert("Incorrect Value");
		frm.txtPassword1.value="";
		frm.txtPassword2.value="";
		frm.txtPassword1.focus();	
	}	
}

//------------------------------------------------------------------ CHANGE DIRECT INFO ------------------

function changeDirectInfo(frm){
	if(frm.rdoDirect[0].checked==true){
		window.Lib.quickSubmit(frm.id,'mnu_etime_update');
	}else{
		alert(MSG3);
	}
}

//------------------------------------------------------------------ ETIME CARDS -----------------------

function submitETime(frm){
	if(parent.GL_ETIMEFLAG=="print"){
		parent.GL_ETIMEFLAG="print-etime";
	}
	if(frm.rdoAgree[0].checked==true){
		window.Lib.quickSubmit(frm.id,'mnu_etime_update');
	}else{
		alert(MSG3);
	}
}

function getETimeCard(idx){
	var frm=window.Lib.getFormByID('right-box');
	if(frm.hCheckMethod.value==0){
		if(frm.cboCheckOptions){
			alert(MSG4);
			return;
		}else{
			frm.hEvent.value="link_getetimecard";
			frm.hIndex.value=idx;
			frm.submit();		
		}
	}else{
		frm.hEvent.value="link_getetimecard";
		frm.hIndex.value=idx;
		frm.submit();	
	}
}//-- end

function checkMethodChanged(frm){
	var val=frm.cboCheckOptions.value;
	frm.hCheckMethod.value=val;
}

function etimeToAgreement(frm,eTimeFlag){
	var ht=""; var ts=""; var flag=false;
	
	if(eTimeFlag==1){ calculateTime1(frm) } 
	if(eTimeFlag==2){ calculateTime2(frm) } 
	if(eTimeFlag==0){ parent.GL_ETIMEFLAG="print"; calculateTime2(frm) }
	
	for(var i=0; i<eTime.Cards.length; i++){
		for(var j=0; j<eTime.Cards[i].days.length; j++){
			ht+=eTime.Cards[i].days[j] +":";
		}
		ht+=eTime.Cards[i].hours +"!";
	}
	
	var ts=ht;
	ts=window.Lib.replace(ts,"!",":0:");
	ts=ts.substr(0,ts.length-1);
	
	var sp=ts.split(":")
	for(var i=0; i<sp.length; i++){
		if(sp[i]!="0"){ flag=true; break; }
	}
	
	if(flag){
		if(arguments[2]){
			frm.hEvent.value="mnu_etime_savevalues";
		}else{
			frm.hEvent.value="mnu_etime_agree";
		}
		
		ht+=eTime.chkOption;                                    
		frm.hTime.value=ht;
		frm.submit();
		
	}else{
		alert(MSG2);
	}
}//-- end

function calculateTime2(frm){
	var ar=new Array();
	var cd=new Card();
	var j=0; var val=0; var tot=0;
	for(var i=0; i<frm.elements.length; i++){
		if(frm.elements[i].name=="h"){
			val+=parseFloat(frm.elements[i].value);
			ar[j]=val; val=0;
		}
		if(frm.elements[i].name=="q"){
			val+=parseFloat(frm.elements[i].value);
			ar[j]=ar[j] + val; tot+=ar[j]; val=0; 
			j++
		}
	}
	
	eTime.chkOption=0;	//-- 0=direct deposit
	
	cd.days=ar;
	if(tot>84){
		alert(MSG1)		
	}else{
		var txt=frm.txtHours;
		txt.value=tot; cd.hours=tot;
		eTime.Cards[0]=cd;
	}
}//-- end

function calculateTime1(frm){
	var sm=0;
	var cd=new Card();
	var val=0; var tot=0; can="";
	
	for(var i=0; i<frm.elements.length; i++){

		if(frm.elements[i].name=="hc"){
			val+=frm.elements[i].value;
			can+=val
			sm=parseFloat(can); val=0; can=0;
		}		
		
		if(frm.elements[i].name=="mc"){
			val+=parseFloat(frm.elements[i].value);
			sm=sm + val; tot+=sm; val=0; 
		}
	
		eTime.chkOption=0;	//-- 0=direct deposit

	}
	var ar=new Array(0,0,0,0,0,0,0);
	cd.days=ar;
	if(tot>84){
		alert(MSG1)		
	}else{
		var txt=frm.txtHours;
		txt.value=tot; cd.hours=tot;
		eTime.Cards[0]=cd;
	}
}//-- end

//------------------------------------------------------------ ADOBE HEADER ---------------------------------

	window.Lib.getAdobeHeader=function(){
		var s="";
		s+="<table>";
		s+="<tr>";
		s+="<td width='120'></td>";
		s+="<td width='50'></td>"
		s+="<td class='c-b9' width='300' align='right'>"
		s+="Some of these documents are in PDF ";
		s+="format and need the required reader ";
		s+="that is available by clicking on the logo.";
		s+="</td>";
		s+="<td width='20'></td>";
		s+="<td>";
		s+="	<a href='http:/www.adobe.com/products/acrobat/readstep2.html'><img src='employee/images/adobe.gif' border='0' width='61' height='21'></a>";
		s+="</td>";
		s+="<td width='300' align='right'>";
		s+="	<input class='btn-ora' type='button' value=' Close ' "; 
		s+="		    onclick=window.Lib.hidelayer();>";
		s+="			&nbsp;&nbsp;&nbsp;";
		s+="</td>";
		s+="</tr>";
		s+="</table>";
		return s;
	}

//-------------------------------------------------------- HELP SYSTEM ---------------------------------------

	function clsHelpSys(prID,offTop,offLeft){ 
	
		if(window.dialogs['helpsys']){ window.dialogs['helpsys'].remove(); }
		window.Lib.getcontrol(prID).click();
		
		this.Extends(window.Lib.LayCreator());
		this.isPopup=false;
		var ps=window.Lib.getParentPosition(prID);
		this.create(html(),'helpsys',ps.top+offTop,ps.left+offLeft);
		var Me=this;
		
		this.init=function(){;}
		Me.init(); Me.show();
//-------------------------------------------------------------------------------------------			

		function html(){
			var c=window.Lib.colHTML();
			var s="";

			s+="<table cellpadding='0' cellspacing='0' class='oB1GRY'>";
			s+="<tr>";
			//s+="	<td colspan='7' height='15' "+ setid('drag') +" bgcolor='gray'>";
			//s+="	</td>";
			s+="	<td>"+ c.setid('btnX') +" bgcolor='gray'>";
			s+="	<img src='extends/images/xu.jpg'></td>";
			s+="</tr>";
			//s+="<tr><td height='3'></td></tr>";
			//s+="<tr><td height='3'></td></tr>";
			s+="</table>";			

			var col=new Array();
			col['html']=s;
			col['controls']=c.controls;
			return col;
		}		
	}
//--------------------------------------------------------------------------------------------	
	
	function clsConfirm(oAccNum,mnu,moreTop,moreLeft){
		
		this.Extends(window.Lib.LayCreator());
		var ps=window.Lib.getParentPosition(oAccNum.id);
		
		this.isPopup=true;
		this.create(html(),'confirm',ps.top+moreTop,ps.left+moreLeft);
		var Me=this;

		with(this){
			btnNext.onclick=function(){
				var btn=document.getElementById("b-next");
				if(oAccNum.value==txtAccNum.value){
					lblInvalid.style.visibility="hidden";
					ddEvalBankingGO(mnu);
				}else{
					lblInvalid.style.visibility="visible"
				}
			}	
			
			btnX.onclick=function(){  me.close(); }
			Show=function(){ /* Me.drag.style.cursor=''; */ }			
		}
		this.init=function(){
			this.txtAccNum.focus();
			this.lblInvalid.style.visibility="hidden";
		}
		
		Me.show(); Me.init();
				
//------------------------------------------------------------------------------------------

		function html(){
		 var c=window.Lib.colHTML();
		 var s='';
		 
		 with(c){
			s+="<table cellpadding='0' cellspacing='0' class='oB1GRY'>"
			s+="<tr>"
			s+="	<td width='300'"+ setid('drag') +" class='cb-r11'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Please confirm your accout number.</td>"
			s+="	<td "+ setid('btnX') +"><img src='extends/images/close.jpg' border='0'></td>"
			s+="</tr>";
			
			s+="<tr><td height='3'></td><td></td></tr>";
					
			s+="<tr>"
			s+="<td"+ setid('') +">";
			s+="	&nbsp;&nbsp;<input"+ setid('txtAccNum') +"size='30' class='c-b11'>";
			s+="	&nbsp;&nbsp;&nbsp;<input"+ setid('btnNext') +"type='button' class='btn-gra' value='  Next  '></td>";
			s+="<td height='30'"+ setid('') +"></td>";
			s+="</tr>";
			
			
			s+="<tr>"
			s+="<td"+ setid('lblInvalid') +" class='c-r11'>";
			s+="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Invalid value, please reenter.</td>";
			s+="<td"+ setid('') +"></td>";
			s+="</tr>";
			
			s+="<tr><td height='3'></td><td></td></tr>";
			
			s+="</table>"
		 }
			var col=new Array();
			col['html']=s;
			col['controls']=c.controls;
			return col;
		}		
	}//-- end class	
