<!--//
var clickCnt=0;

function selectApprove(fChecked){
	var fmName=document.forms[0];
	for(cntType=1; cntType!=(fmName.length - 1);cntType++){	
		if(fmName.elements[cntType].value=='E')
			fmName.elements[cntType].checked = fChecked;
	}
}

function setIncPast(val) {
	window.location = 'default.asp?subpage=Enter_Time_Sheet&incpast=' + val
}
function attachDoc(emailWho) {
	var t, l, w, h;
	w = 575;
	h = 310;
	l = (screen.width - w) / 2;
	t = (screen.height - h) / 2; 
	window.open(emailWho,'Resume','scrollbars=yes,left=' + l + ',top=' + t + ',width=' + w + ',height=' + h);
}

function validate() {
	if ( document.postResume.ATTACHED_RESUME.value == '' )
		alert('You must attach your resume in order to proceed.');
	else
		document.postResume.submit();
	return;
}
function keyDump() { 
clickCnt++;
//alert(clickCnt);
	if(clickCnt > 1){
		alert('Processing');
		return false;
	}
	return true;
} 


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function findObj(objname) {
	var n, i;
	
	for ( n = 0; n < document.forms.length; n++ ) {
		for ( i = 0; i < document.forms[n].elements.length; i++ ) {
			if ( document.forms[n].elements[i].name == objname ) {
				return document.forms[n].elements[i];			
			}
		}	
	}
	return null;
}

function showCal(objname, wloc,event) {
	var date = (objname);
	var nFile = "include/Calendar.asp?date=" + date + "&objname=" + objname, win, props;	
	var width = 300, height = 167;
	var xPos=event.screenX;
	var yPos=event.screenY;
	//incase they are using netscape
	if (xPos == "undefined" || xPos == null){
		xPos=(eventObj.screenX);
		yPos=(eventObj.screenY);
	}
	var left = xPos, top = yPos - (height + 50);
	if ( top < 20 )	top = 20;		
	if ( (left + width) > screen.width ) left = screen.width - (width + 10);
	if ( wloc == undefined )
		wloc = '';
	else if ( wloc != '' ) {
		wloc = wloc + '/';
	}
	props = 'status=no,titlebar=no,resizable=no,left=' + left + ',top=' + top + ',width=' + width + ',height=' + height
	win = window.open(wloc + nFile, 'calendar', props);
	return false;
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function showCalALL(objname, wloc,event) {
//alert(objname)
	var date = (objname);
	var nFile = "include/CalendarALL.asp?date=" + date + "&objname=" + objname;	
	var width = 300, height = 167;
	var xPos=event.screenX;
	var yPos=event.screenY;
	//incase they are using netscape
	if (xPos == "undefined" || xPos == null){
		xPos=(eventObj.screenX);
		yPos=(eventObj.screenY);
	}
	var left = xPos, top = yPos - (height + 50);
	if ( top < 20 )	top = 20;		
	if ( (left + width) > screen.width ) left = screen.width - (width + 10);
	if ( wloc == undefined )
		wloc = '';
	else if ( wloc != '' ) {
		wloc = wloc + '/';
	}
	props = 'status=no,titlebar=no,resizable=no,left=' + left + ',top=' + top + ',width=' + width + ',height=' + height
	win = window.open(wloc + nFile, 'calendar', props);
	return false;
}

function valWeek(fmName){
var fmObject=document[fmName];
var wValue=fmObject.weekend.value;
var wExp = /^\d{1,2}\/\d{1,2}\/\d{2}$/;
var mssg="Your weekending date\nmust be in M/D/YY format";
	if(wExp.test(wValue)==false){
		alert(mssg);
		return false;
	}
	else{
		var StringVal = wValue.indexOf("/");
		var comNum = parseInt(wValue.substring(0,StringVal));
			if ((comNum > 12) || (comNum <= 0)){
				alert(mssg);
				return false;
			}
		var midVal = wValue.lastIndexOf("/");
		var midNum = parseInt(wValue.substring((StringVal+1),midVal));
			if ((midNum > 31) || (midNum <= 0)){
				alert(mssg);
				return false;
			}
			else{
				return true;
			}
	}
}
function runEmail(email){
	var fmName=document.forms[0];
	var atSym=email.lastIndexOf("@")
	if(atSym==-1){
		alert('You must use a valid email address')
		return false;
	}
	if(atSym < 20){
		fmName['UserName'].value=email.substring(0,atSym)
		return false;
	}else{
		fmName['UserName'].value=email.substring(0,20)
	}
}
function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function maxCert(objName,fmName){
	var fmLength=fmName[objName].options.length;
	var i=0,z=0;
	for(i=0;i<fmLength;i++){
		if (z > 3){
			while (i <= fmLength ){
				fmName[objName].options[i-1].selected=false;
				i=i+1
			}
			alert('You may only select 3 Certifications')
			break;
		}
		if (fmName[objName].options[i].selected){
			z=z+1
		}
	}
}

function maxLang(objName,fmName){
	var fmLength=fmName[objName].options.length;
	var i=0,z=0;
	for(i=0;i<fmLength;i++){
		if (z > 2){
			while (i <= fmLength ){
				fmName[objName].options[i-1].selected=false;
				i=i+1
			}
			alert('You may only select 2 Languages')
			break;
		}
		if (fmName[objName].options[i].selected){
			z=z+1
		}
	}
}

/*-----------------------Trim Inside and Out-----------------------*/
function trim(str){
   return str.replace(/^\s*|\s*$|\s*/g,"");
}

/*----------------------Num Decimals To Round----------------------*/
function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}

function pad_with_zeros(rounded_value, decimal_places) {
    var value_string = rounded_value.toString()
    var decimal_location = value_string.indexOf(".")
    if (decimal_location == -1) {
        decimal_part_length = 0
        value_string += decimal_places > 0 ? "." : ""
    }
    else {
        decimal_part_length = value_string.length - decimal_location - 1
    }
    var pad_total = decimal_places - decimal_part_length
    if (pad_total > 0) {
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}

/*----------------Calculate Grand Totals-------------------*/
function GrandTotals(fmObject){
	var totTime =0;
	var OTTime =0;
	var DTTime =0;
	for (i = 0;i < 7; i++){
		totTime += parseFloat(fmObject["totTime"+i].value);
		OTTime += parseFloat(fmObject["OTTime"+i].value); 
		DTTime += parseFloat(fmObject["DTTime"+i].value); 
	}
	fmObject.weekHoursTotal.value = round_decimals(totTime,2);
	fmObject.weekHoursOT.value = round_decimals(OTTime,2);
	fmObject.weekHoursDT.value = round_decimals(DTTime,2);
}

/*----------function for calculating week totals------------*/
function valForm(fmName,fmFldName,fmValue,alter){
	// not in use hard code the form object var thisform = fmName;
	var fmObject = document.forms[0];
	var smin, shr, sfmt, emin, ehr, efmt, lhr, lmin;
	var sTime, endTime, lTime, timePDay,tot_min;
	var GrandWeekReg = 0;

	for(i = 0; i < 7; i++){	
		timePDay = 0; 
		fmObject['totTime'+i].value = 0;
		fmObject[('OTTime'+i)].value = 0;
		fmObject[('DTTime'+i)].value = 0;
		/*Start Hrs & Mins*/
		start_hr=parseInt(fmObject['sTimeHr'+i].value);
		smin=parseFloat(fmObject['sTimeMin'+i].value);
		sfmt=fmObject['sTimeFmt'+i].value; //AM or PM
		/*End Hrs & Mins*/
		end_hr=parseInt(fmObject['eTimeHr'+i].value);
		emin=parseFloat(fmObject['eTimeMin'+i].value);
		efmt=fmObject['eTimeFmt'+i].value;
		/*Lunch Hrs & Mins*/
		break_hr=parseInt(fmObject['LTimeHr'+i].value);
		lmin=parseFloat(fmObject['LTimeMin'+i].value);
		
		/*If both of the hour values on a row are not empty, then calculate the total 24 hour clock*/
		if(start_hr != -1 && end_hr != -1){
			if(start_hr == 12){start_hr = 0};
			if(end_hr == 12){end_hr = 0};		
			if(sfmt == 'pm'){start_hr += 12};
			if(efmt == 'pm'){end_hr += 12};
			if(start_hr > end_hr){end_hr += 24};

			/*Hours for start end hours and break*/
			tot_hr = (end_hr - start_hr - break_hr);
			/*Minutes for start end hours and break*/
			tot_min = (emin - smin - lmin) 
			
			/*Convert Hours to Mins Add with Mins convert back to hours & minutes*/	
			isTotal=parseFloat(parseFloat(tot_hr)*60 + (parseFloat(tot_min)))/60
			if (isTotal > 0){
				tot =isTotal 
			}else{
				tot=0;
			}
			/*calculate daily totals make sure Total Reg Weekly not over 40*/
				if ((GrandWeekReg+8.00) <= 40.00 || (GrandWeekReg+ tot)<=40.00){
					if (tot <= 8 ){
						fmObject[('totTime'+i)].value = round_decimals(tot,2);
					}else{
						fmObject[('totTime'+i)].value = round_decimals(8,2);
						if(tot-8 <= 4){
							fmObject[('OTTime'+i)].value = round_decimals(tot-8,2);
						}else{
							fmObject[('OTTime'+i)].value = round_decimals(4,2);
							fmObject[('DTTime'+i)].value = round_decimals(tot-12,2);
						}
					}
				}else{ /*Its over 40 or will be over 40 split out the time with REG AND OR write all to OT DT column*/
					fmObject[('totTime'+i)].value = round_decimals((40-GrandWeekReg ),2);// Write the split REG time
					if(tot-(40-GrandWeekReg)<= 4.00 ){//Just write OT
						fmObject[('OTTime'+i)].value = round_decimals(tot-(40-GrandWeekReg),2);
					}else{//Write OT & DT
						fmObject[('OTTime'+i)].value = round_decimals(4,2);
						fmObject[('DTTime'+i)].value = round_decimals((tot-4)-(40-GrandWeekReg),2);
					}
				}
			/*keep running total of Total Reg Weekly Hours to make sure it doesnt go over 40*/
				GrandWeekReg += parseFloat(fmObject[('totTime'+i)].value)
		}
	}
	/*Get REG,OT,DT grand totals from calculated daily totals*/
	GrandTotals(fmObject)
}

/*------------Begin Functions For Expenses and Milage------------*/
function clearbox(wday,kValue){
	var fmName;
	var fmName=document.forms[0];
	if (kValue==0){
	fmName.elements[wday].value="";
	}
}
	
function setbox(wday,kValue){
	var fmName;
	var fmName=document.forms[0];
	if (kValue==""){
	fmName.elements[wday].value=0;
	}
}

function calc_hours(wday,kValue,event){
	var fmName;
	var fmName=document.forms[0];
	var setregExp = /[^\d\.]/;
	var textBN=(wday);
	var rowCalc=textBN.substring(1,4);
	var wokRow,dayCalc,wTot=0;
	var dayArr = new Array("0","1", "2", "3","4","5","6");
	var bDisplay=fmName.elements[wday].value

	if((event.keyCode!=9)&&(event.keyCode!=8)&&(event.keyCode!=46)){
		if ((isNaN(kValue))&&(kValue!='.')||(kValue=='')){
			alert("You Must Enter\nA Number");
				if(bDisplay.length > 1){
					while ((isNaN(bDisplay)!=false)&& (bDisplay!="")){
						bDisplay=bDisplay.replace(setregExp,"");
					}
					fmName.elements[wday].value=bDisplay
				}
				else {
					fmName.elements[wday].value="";
				}
		}
	}	

	for(cntType=0; cntType!=7;cntType++){
		dayCalc=(dayArr[cntType]+rowCalc);
			dayCalc=dayCalc.replace(" ","");
			wokRow=fmName.elements[dayCalc].value;
			wokRow=wokRow.replace(" ","");
			if(isNaN(parseFloat(wokRow))){
				break;
			}
			wTot=(wTot+parseFloat(wokRow));
	}
	//fmName.elements[(rowCalc+"Tot")].value=round_decimals(wTot,2);
	fmName.elements[(rowCalc+"Tot")].value= (wTot);

}

/*-----------------------Lock Check Box---------------------------*/
function lockCheck(theState,theObj){
	var fmName=document.forms[0];
	if(theState == false){
		fmName[theObj].checked = true;
	}else{
		fmName[theObj].checked = false;
	}
}


//-->