function focusFld(id) {
	if (document.all) document.all(id).className='InputItemOn';
	else if (document.getElementById) document.getElementById(id).className='InputItemOn'; 
}
function blurFld(id) {
	if (document.all) document.all(id).className='InputItemOff';
	else if (document.getElementById) document.getElementById(id).className='InputItemOff'; 
}
function checkFocus() {
	/*var sFormName = 'form1';
	var iTFld = 0;
	iTFld = eval('document.'+ sFormName + '.elements.length');
	for (i=0; i<iTFld; i++) {
		if (eval('document.'+ sFormName + '.elements['+i+'].id').substring(0,3) != 'btn') {
			//alert(eval('document.'+ sFormName + '.elements['+i+'].id'));
			//alert(eval('document.'+ sFormName + '.elements['+i+'].onfocus'));
			if (eval('document.'+ sFormName + '.elements['+i+'].focus')) {
				focusFld(eval('document.'+ sFormName + '.elements['+i+'].id'));
			//	alert(eval('document.'+ sFormName + '.elements['+i+'].id')+' is onfocus');
			} else {
				blurFld(eval('document.'+ sFormName + '.elements['+i+'].id'));
			//	alert(eval('document.'+ sFormName + '.elements['+i+'].id')+' is not onfocus');
			}
		}
	}*/
}
function setDate(formField, formValue) {
	if ((formValue != null) && formValue.length > 0) {
		var sHourMin = "";
		var diffOperation = fTimeDiff.substring(0,1);
		var diffHour = parseFloat(fTimeDiff.substring(1,3));
		var diffMin = parseFloat(fTimeDiff.substring(4,7));
		var diffHourMin = (diffHour * 60) + diffMin;
		
		if(diffOperation == "-"){
			diffHourMin = -diffHourMin;
		}
		
		var actualYear = formValue.substr(0,4)
		
		if (eval(formValue.substr(5,1)+"=='0'")) {
			var actualMonth = formValue.substr(6,1);
		} else {
			var actualMonth = formValue.substr(5,2)
		}
		
		
		if (eval(formValue.substr(8,1)+"=='0'")) {
			var actualDay = formValue.substr(9,1);
		} else {
			var actualDay = formValue.substr(8,2);
		}
		
		var actualHour = parseFloat(formValue.substr(11,2));
		var actualMin = parseFloat(formValue.substr(14,2));
		
		
		var dateObject = new Date(parseFloat(actualYear),parseFloat(actualMonth)-1,parseFloat(actualDay),actualHour,actualMin,00);
		dateObject = new Date(dateObject.getTime() - (diffHourMin*60000));
		
		eval("document.all['"+formField+"Day'].value='"+dateObject.getDate()+"';");
		eval("document.all['"+formField+"Month'].value='"+(dateObject.getMonth() + 1)+"';");
		eval("document.all['"+formField+"Year'].value='"+dateObject.getYear()+"';");
		
		if(dateObject.getHours() < 10){
			sHourMin = "0" + dateObject.getHours();
		}else{
			sHourMin = dateObject.getHours();
		}
		
		if(dateObject.getMinutes() < 10){
			sHourMin += ":0" + dateObject.getMinutes();
		}else{
			sHourMin += ":" + dateObject.getMinutes();
		}
		eval("document.all['"+formField+"HourMin'].value='"+sHourMin+"';");
	}
	
	return;
}
function setYesNo(formField, formValue) {
	if (formValue == "1") {
		eval("document.all['" + formField + "Y'].checked = true;");
	} else {
		eval("document.all['" + formField + "N'].checked = true;");
	}
	return;
}
function checkGroupEmpty(ary, msg) {
	var bEmpty = true;
	
	for(i=0;i<eval(ary).length;i++) {
		if (eval("document.all['" + eval(ary)[i] + "'].value") != "") {
			bEmpty = false;
			break;
		}
	}
	if (!(bEmpty)) {
		return true;
	} else {
		alert(msg);
		return false;
	}
}
function checkdigit(field, fieldtype, sMsg){
	var numval;
	var minclip=-Math.pow(2,32);
	var maxclip=Math.pow(2,64); // Sized by our max allowable check size.
	var val = eval("document.all['" +field+"'].value");
	val = val.replace(/,/g,"");
	if(eval("document.all['" +field+"'].value") != ""){
		if (fieldtype == "integer") {
			numval = parseInt(val,10);	
        	} else if (fieldtype == "posinteger"){
        		numval = parseInt(val,10);
	          	minclip=0;
		} else if (fieldtype == "posfloat"){
			numval = parseFloat(val);
        		minclip=0;
		} else {
			numval = parseFloat(val);
     		}
		
		if (isNaN(numval) || numval >= maxclip || numval <= minclip){
     			if (fieldtype=="posinteger" || fieldtype=="posfloat"){
          			alert(sMsg);
				eval("document.all['" +field+"'].value") = '';
			}else if (fieldtype=="integer" || fieldtype=="float"){
          			if (isNaN(numval) && (numval != "")){
	          			alert(sMsg);
					eval("document.all['" +field+"'].value = '';");
					eval("document.all['" +field+"'].focus();");
				}else if (numval != ""){
					alert(sMsg);
					eval("document.all['" +field+"'].value = '';");
					eval("document.all['" +field+"'].focus();");
				}
			}else{
          			alert(sMsg);
          		}
	          	validflag = false;
			eval("document.all['" +field+"'].value = '';");
		}else{
        		eval("document.all['" +field+"'].value = " + numval + ";");
	        	validflag = true;
		}
		return validflag;
	} else {
		return true;
	}
}

function checkEmptyField(ary) {
	var bEmpty = false;
	var fieldName, alertMsg, fieldQuote, totalOption, elementType;
	
	for(i=0;i<eval(ary).length;i++) {
		fieldName = eval(ary)[i][0];
		alertMsg = eval(ary)[i][1];
		fieldQuote = eval(ary)[i][2];
		totalOption = eval(ary)[i][3];
		elementType = getEleType(fieldName);
		switch (fieldQuote) {
			case "s":
				if (!(elementType=="checkbox")) {
					if (totalOption==1) {
						if (eval("document.all['" + fieldName + "'].value") == "") {
							bEmpty = true;
						}
					} else if (totalOption>1) {
						if (checkMultiText(fieldName, totalOption)) {
							bEmpty = true;
						}
					}
				} else {
					if (checkCheckbox(fieldName, totalOption)) {
						bEmpty = true;
					}
				}
				break;
			case "t":
				if (eval("document.all['" + fieldName + "'].value") == "") {
					bEmpty = true;
				}
				break;
			case "i":
				if (eval("document.all['" + fieldName + "'].value") == "") {
					bEmpty = true;
				}
				if (isNaN(parseFloat(eval("document.all['" +fieldName+"'].value")))) {
					bEmpty = true;
				}
				break;
			case "f":
				if (eval("document.all['" + fieldName + "'].value") == "") {
					bEmpty = true;
				}
				if (isNaN(parseFloat(eval("document.all['" +fieldName+"'].value")))) {
					bEmpty = true;
				}
				break;
			case "c":
				if (eval("document.all['" + fieldName + "'].value") == "") {
					bEmpty = true;
				}
				break;
			case "d":
				if (eval("document.all['" + fieldName + "'].value") == "") {
					bEmpty = true;
				}
				break;
			case "b":
				if ((!(eval("document.all['"+fieldName+"Y'].checked"))) && (!(eval("document.all['"+fieldName+"N'].checked")))) {
					bEmpty = true;
				}
				break;
		}
		if (bEmpty) {
			break;
		}
	}
	if (bEmpty) {
		alert(alertMsg);
		/*if (fieldName.indexOf("hdn")==-1) {
			if ((elementType != "checkbox") && (elementType != "radio")) {
				eval("document.all['" + fieldName + "'].focus();");
			} else if (getEleType(fieldName) == "checkbox") {
				eval("document.all['" + fieldName + "1'].focus();");
			} else if (getEleType(fieldName) != "radio") {
				eval("document.all['" + fieldName + "Y'].focus();");
			}
		}*/
		return true;
	} else {
		return false;
	}
}

function getEleType(fieldName) {
	for (h=0;h<document.form1.elements.length;h++) {
		if (document.form1.elements[h].name==fieldName) {
			return document.form1.elements[h].type;
			break;
		}
	}
}

function checkCheckbox(fieldName, totalOption) {
	var bEmpty = true;
	
	for(p=1;p<totalOption;p++) {
		if (!(eval("document.all['" + fieldName + p + "'].checked"))) {
			bEmpty = false;
			break;
		}
	}
	if (!(bEmpty)) {
		return true;
	} else {
		return false;
	}
}

function checkMultiText(fieldName, totalOption) {
	var bEmpty = true;
	
	for(p=1;p<totalOption;p++) {
		if (eval("document.all['" + fieldName + p + "'].value" == "")) {
			bEmpty = false;
			break;
		}
	}
	if (!(bEmpty)) {
		return true;
	} else {
		return false;
	}
}

function checkDate(ary) {
	var bIsDate = true;
	
	for(j=0;j<eval(ary).length;j++) {
		dDay = eval("document.all['" + eval(ary)[j][0] + "Day'].value");
		dMonth = eval("document.all['" + eval(ary)[j][0] + "Month'].value");
		dYear = eval("document.all['" + eval(ary)[j][0] + "Year'].value");
		if ((dDay!="") && (dMonth!="") && (dYear!="")) {
			if (dMonth!="") {
				if ((dMonth==4) || (dMonth==6) || (dMonth==9) || (dMonth==11)) {
					if (dDay>30) {
						bIsDate = false;
						break;
					}
				} else if (dMonth==2) {
					if ((dYear%4!=0) && (dDay>28)) {
						bIsDate = false;
						break;
					} else if ((dYear%4==0) && (dDay>30)) {
						bIsDate = false;
						break;
					}
				}
			} else {
				bIsDate = false;
				break;
			}
		} else if ((dDay=="") && (dMonth=="") && (dYear=="")) {
			bIsDate = true;
			break;
		} else if ((dDay=="") || (dMonth=="") || (dYear=="")) {
			bIsDate = false;
			break;
		}
	}
			
	if (bIsDate) {
		return true;
	} else {
		alert(eval(ary)[j][1]);
		return false;
	}
}

function wordCount(fieldName, totalWord, sMsg) {
	var fieldValue = new String(eval('document.form1.'+fieldName+'.value'));
	if (fieldValue!="") {
		splitString = fieldValue.split(" ");
		if (splitString.length>totalWord) {
			alert(sMsg);
			return false;
		} else {
			return true;
		}
	} else {
		return true;
	}
}
function characterCount(fieldName, totalChar, sMsg) {
	var fieldValue = new String(eval('document.form1.'+fieldName+'.value'));
	var i = 0;
	if (fieldValue!="") {
		while (fieldValue.length>0) {
			i++;
			fieldValue = fieldValue.substring(1, fieldValue.length);
		}
		if (i>totalChar) {
			alert(sMsg);
			return false;
		} else {
			return true;
		}
	} else {
		return true;
	}
}

function checkDisable(disableval){
	splitString = disableval.split("|")
	for(i=0; i<splitString.length; i++){
		if(splitString[i] != ""){
			document.all(splitString[i]).disabled = true;
		}
	}
}

function removeValue(fieldName) {
	eval('document.form1.'+fieldName+'.value = ""');
}

function loadReadOnly(form) {

	var iTField = form.elements.length;
	for (i=0; i<iTField; i++) {
		form.elements[i].disabled = true;
	}
	bFormDisabled = true;
	
}

function checktime(s, msg1, msg2) { 
	
	var i;
	var hr = s;
	var temp="";
	var min = s;
	var c;
    
	if (s.length<=0){
		return true;
	}

	if (s.length<5){
		alert(msg2);
		return false;
	}
	  
	min = min.substring(3);
	hr = hr.substring(0,2);
	for (i=0;i<hr.length;i++) {
		c = hr.charAt(i);
		if (c < "0" || c > "9") {
			alert(msg1);
			return false;
		}
	}

	for (i=0;i<min.length;i++) {
		c = min.charAt(i);
		if (c < "0" || c > "9"){
			alert(msg1);
			return false;
		}
	}

	if (hr>23){
		alert(msg2);
		return false;
	}

	if (min>59){
		alert(msg2);
		return false;
	}

	var colon = s;
	colon = colon.substring(3,2)
	if (colon!=":"){
		alert(msg1);
		return false;
	}
	return true;
}

function checkSpace(fieldName, sMsg) {
	var fieldValue = new String(eval('document.form1.'+fieldName+'.value'));
	var i = 0;
	if (fieldValue!="") {
		if (fieldValue.indexOf(" ")>-1) {
			alert(sMsg);
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
}