// For Mandatory Validationfunction getCorrespondingLabels(fieldNames, delimiter){var fields = new Array();var fieldLabels = new Array();fields = fieldNames.split(delimiter);for (i=0;i<fields.length;i++){fieldLabels[i] = eval("document.forms[0].lbl"+fields[i]+".value");}return fieldLabels.join(delimiter);}function trimString (str) {  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');}function validateDateValue( strValue ) {  var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/  //check to see if in correct format  if(!objRegExp.test(strValue))    return false; //doesn't match pattern, bad date  else{    var arrayDate = strValue.split(RegExp.$1); //split date into month, day, year	var intDay = parseInt(arrayDate[0],10); 	var intYear = parseInt(arrayDate[2],10);    	var intMonth = new Number(parseInt(arrayDate[1],10));	//check for valid month	if(intMonth > 12 || intMonth < 1) {		return false;	}	    //create a lookup for months not equal to Feb.    var arrayLookup = { '1' : 31,'3' : 31, '4' : 30,'5' : 31,'6' : 30,'7' : 31,                        '8' : 31,'9' : 30,'10' : 31,'11' : 30,'12' : 31}      //check if month value and day value agree    if(arrayLookup[intMonth] != null) {      if(intDay <= arrayLookup[intMonth] && intDay != 0)        return true; //found in lookup table, good date    }		    //check for February	var booLeapYear = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0));    if( ((booLeapYear && intDay <= 29) || (!booLeapYear && intDay <=28)) && intDay !=0)      return true; //Feb. had valid number of days  }  return false; //any other values, bad date}function validateTime(timeStr){var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?$/;var matchArray = timeStr.match(timePat);if (matchArray == null) {return false;   //Time is not in a valid format}hour = matchArray[1];minute = matchArray[2];second = matchArray[4];if (second=="") { second = null; }if (hour < 0  || hour > 23) {return false;     //Hour must be between 1 and 23}if (minute<0 || minute > 59) {return false;   //Minute must be between 0 and 59.}if (second != null && (second < 0 || second > 59)) {return false;    //Second must be between 0 and 59.}return true;}function validateText(strValue){	if (trimString(strValue)=="" )	{		return false	}	else	{		return true     	}}function  validateNumeric( strValue ) {/******************************************************************************DESCRIPTION: Validates that a string contains only valid numbers.PARAMETERS:   strValue - String to be tested for validity   RETURNS:   True if valid, otherwise false.******************************************************************************/  var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;    //check for numeric characters   return objRegExp.test(strValue);}function validateEmail( strValue) {	var objRegExp  = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/i;	return objRegExp.test(strValue);}function validateWhole( strValue ) {/************************************************DESCRIPTION: Validates that a string contains only     valid whole numbers ( 0 , 1, 2, )    PARAMETERS:   strValue - String to be tested for validity   RETURNS:   True if valid, otherwise false.******************************************************************************/  var objRegExp  = /(^\d\d*$)/;   //check for integer characters  return objRegExp.test(strValue);}function  validatePositive( strValue ) {/******************************************************************************DESCRIPTION: Validates that a string contains only Positive (non zero ) numbers(1.0, 2.0 )PARAMETERS:   strValue - String to be tested for validity   RETURNS:   True if valid, otherwise false.******************************************************************************/  var objRegExp  =  /(^[1-9][1-9]*\.[1-9]*$)|(^[1-9][1-9]*$)|(^\.[1-9][1-9]*$)/;    //check for numeric characters   return objRegExp.test(strValue);}function validatefields ( fieldnamelist , errortypelist , errorcodelist ) {	var frm = document.forms[0];	var fieldnames = fieldnamelist.split("^");	var errortypes = errortypelist.split("^");	var errorcodes = errorcodelist.split("^");	var strfieldvalue = "";	for (i=0;i<fieldnames.length;i++)	{		switch(errortypes[i])		{			case "T":			{				// Check for null for the text value				 strfieldvalue = eval("frm." + fieldnames[i] + ".value");//Check the field type (combo box, listbox, checkbox, radiobutton) and get the value accordingly(use.selectedIndex for combo...)				 if (!validateText(strfieldvalue) )				 {					// Call the function to get the error msg for the error code					alert(getErrorMsg (errorcodes[i])) ;					return false;								 }				 break;			}			case "N":			{				// Check for Number (- , 0 , + ) 				 strfieldvalue = eval("frm." + fieldnames[i] + ".value")	;				 if (!validateNumeric(strfieldvalue) )				 {					// Call the function to get the error msg for the error code					tmp = errorcodes[i].split("~");					alert(getErrorMsg (tmp[0]) + " for " + tmp[1]) ;					return false;				 }				 break;			}			case "Z":			{				// Check for whole numbers ( 0, 1,2, 3 ...)				 strfieldvalue = eval("frm." + fieldnames[i] + ".value")	;				 if (!validateWhole(strfieldvalue) )				 {					// Call the function to get the error msg for the error code					alert(getErrorMsg (errorcodes[i])) ;					return false;				 }				 break;			}			case "P":			{				// Check for Positive (1.0 ,2.0 , 3 ...)				 strfieldvalue = eval("frm." + fieldnames[i] + ".value")	;				 if (!validatePositive(strfieldvalue) )				 {					// Call the function to get the error msg for the error code					alert(getErrorMsg (errorcodes[i])) ;					return false;				 }				 break;			}			case "E":			{				// Check for Email				 strfieldvalue = eval("frm." + fieldnames[i] + ".value");				 if (!validateEmail(strfieldvalue) )				 {					// Call the function to get the error msg for the error code					alert(getErrorMsg (errorcodes[i])) ;					return false;				 }				 break;			}			case "D":			{				// Check for Date				 strfieldvalue = eval("frm." + fieldnames[i] + ".value");				 if (!validateDateValue(strfieldvalue) )				 {					// Call the function to get the error msg for the error code					alert(getErrorMsg (errorcodes[i])) ;					return false;				 }				 break;			}						case "TM":			{				// Check for Time				 strfieldvalue = eval("frm." + fieldnames[i] + ".value");				 if (!validateTime(strfieldvalue) )				 {					// Call the function to get the error msg for the error code					alert(getErrorMsg (errorcodes[i])) ;					return false;				 }				 break;			}		}	}	return true;}function isSomethingSelected( obj ){	for (var r=0; r < obj.length; r++){		if ( obj[r].checked ) return true;	}}function validateBulkMandatory ( fieldnamelist , fieldlabellist) {		var frm = document.forms[0]	var fieldnames = fieldnamelist.split("^");	var fieldlabels = fieldlabellist.split("^");	var strfieldvalue = "";	var allerrorlabels = "";		var mandatorymsg = "";	var gotofld = "";	for (i=0;i<fieldnames.length;i++)	{		// Check for null for the text value		e=eval("frm." + fieldnames[i]);						switch (e.type) {			case "text": 					strfieldvalue = e.value;				if (!validateText(strfieldvalue) )					 {					gotofld = gotofld + "^" + fieldnames[i];							                        allerrorlabels = allerrorlabels + fieldlabels[i]  + "\n";									 }				break;					case "hidden": 					strfieldvalue = e.value;				if (!validateText(strfieldvalue) )					 {					gotofld = gotofld + "^" + fieldnames[i];							                        allerrorlabels = allerrorlabels + fieldlabels[i]  + "\n";									 }				break;				case "textarea": 				strfieldvalue = e.value;				if (!validateText(strfieldvalue) )					 {									gotofld = gotofld + "^" + fieldnames[i];			                        allerrorlabels = allerrorlabels + fieldlabels[i]  + "\n";									 }				break;					case "select-one":			   	 if(e.options[e.selectedIndex].text =="--Select--" || e.options[e.selectedIndex].text=="--No Records--") 					{					gotofld = gotofld + "^" + fieldnames[i];			                        allerrorlabels = allerrorlabels + fieldlabels[i]  + "\n";								}				/*if (e.selectedIndex == 0 ) 					 {						gotofld = gotofld + "^" + fieldnames[i];			                        allerrorlabels = allerrorlabels + fieldlabels[i]  + "\n";									 }				if(e.options[e.selectedIndex].value =="--Select--")					{					gotofld = gotofld + "^" + fieldnames[i];			                        allerrorlabels = allerrorlabels + fieldlabels[i]  + "\n";								}*/				break;				case "select-multiple":				if ( e.selectedIndex == -1 )					 {										gotofld = gotofld + "^" + fieldnames[i];			                        allerrorlabels = allerrorlabels + fieldlabels[i]  + "\n";									 }				break;				case "password":				if ( trim(e.value) == "" )					 {										gotofld = gotofld + "^" + fieldnames[i];			                        allerrorlabels = allerrorlabels + fieldlabels[i]  + "\n";									 } 				break;			default:				//must be a checkbox or a radio group if non of above				switch (e[0].type) {					case "checkbox":					if ( !isSomethingSelected( e ) )						{						gotofld = gotofld + "^" + fieldnames[i];						allerrorlabels = allerrorlabels + fieldlabels[i]  + "\n";							}									break;					case "radio":					if ( !isSomethingSelected( e ) )  						{						gotofld = gotofld + "^" + fieldnames[i];						allerrorlabels = allerrorlabels + fieldlabels[i]  + "\n";							}					break;					}				}	}	////mandatorymsg = getErrorMsg("E001");	mandatorymsg = "The following fields are mandatory:";	if (allerrorlabels != "")	{		alert (mandatorymsg + "\n\n" + allerrorlabels) ;		var problemflds = gotofld.split("^")		//eval("document.forms[0]."+problemflds[1]+".focus()");   //change to non comment // commented by nitin 		return false	}	else	{		return true	}}// To populate the field values without refreshingfunction FindCorrespondingEntries(viewName,objSourceFld,ObjDestinationFld){	var strCategory = objSourceFld[objSourceFld.selectedIndex].text	var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");	xmlDoc.async="false";	xmlDoc.load(dburl+'/'+viewName+'?Readviewentries&restricttocategory='+strCategory);     if(xmlDoc.xml.length=="") return ""//   var nodeResult = xmlDoc.selectNodes("/viewentries/viewentry/entrydata/textlist")[0];	var nodeResult = xmlDoc.selectNodes("/viewentries/viewentry/entrydata")[0];//	alert(nodeResult.childNodes[0].nodeName)	objMainChilds = nodeResult.childNodes[0].childNodes	var arrTemp=new Array(objMainChilds.length+1)			for(var intIndex=0;intIndex<objMainChilds.length;intIndex++){				arrTemp[intIndex] = objMainChilds(intIndex).text				}		     updateValues(arrTemp,ObjDestinationFld)     }function updateValues(arrTemp,objDestinationFld){var strTextvar strValueobjDestinationFld.length =0objDestinationFld.length +=1if( objDestinationFld.type == "select-one"){		objDestinationFld[objDestinationFld.length-1].text = "--Select--"		for(iCount=0;iCount<arrTemp.length;iCount++)		{			objDestinationFld.length +=1			strText=arrTemp[iCount]  //new String(RegExp.$1)			strValue=arrTemp[iCount] //strValue.replace(/^[\s]+/g,"");			objDestinationFld[objDestinationFld.length-1].text = strText		}		}else{	objDestinationFld.value = ""	for(iCount=0;iCount<arrTemp.length-1;iCount++)	{		strValue=arrTemp[iCount] 		objDestinationFld.value = objDestinationFld.value+strValue	}}}// To allow only numbers to be entered in the field created by Don Livingstonfunction validateNumber(){ if((window.event.keyCode>47) && (window.event.keyCode<58) || (window.event.keyCode==46)) {  return true } else {   alert("Enter numbers only")   return false  }}function getCurrentDate(){	var date = new Date()		var curDate=parseInt(date.getMonth())+1+"-"+ date.getDate()+"-"+date.getFullYear()	return curDate}function getCurrentDateTime(){	var date = new Date()		var curDate=parseInt(date.getMonth())+1+"-"+ date.getDate()+"-"+date.getYear()+" "+date.getHours()+":"+date.getMinutes()	return curDate}function checkDuplicate(){	material = doc.Material_1.value.split("~^")	for(i=0;i<material.length;i++)	{	if(material[i] == doc.Material.value)	{	alert("Material Name already exists")	return false	}	}}//----- for validating number fields to hav only numbers with decimal allowed---------//function numberWithDecimal(){if (event.keyCode<48  || event.keyCode > 57){ if (event.keyCode!=46) {  alert("Please enter Numbers only")  event.returnValue=false  }}}//----- for validating number fields to hav only numbers with decimal, not allowed---------//function numberWithoutDecimal(){if (event.keyCode<48  || event.keyCode > 57){  alert("Please enter Numbers only")  event.returnValue=false  }}