

	/*
	 *  Name      : OREvalidatelib.js
	 *  Purpose   :  Used for client side validations
	 *  Author    : Girish A.
	 *  Created On: 12th Nov 2005
	 */




function FormatDate(i, delKey,direction) {
  if (i.value.length < 11) {
  	if (delKey!=9) { /*tab*/
	  	if(delKey!=8 && delKey!=46 && delKey!=16 &&  !(delKey>36 && delKey<41)){ /*if the delete, backspace, shift, are not the keys that caused the keyup event.*/
  			var fieldLen = i.value.length
   			if ((delKey >= 48 && delKey <= 57) || (delKey >= 96 && delKey <=105) || (delKey >= 65 && delKey <= 90)) {
   				if (fieldLen == 2 || fieldLen == 6) {
      				i.value = i.value + "-";
		     	}
   			} else {
   				if (direction == "up") {
     				if (i.value.length == 0) {
      					i.value = ""
	     			} else {
		      			i.value = i.value.substring(0,i.value.length-1)
	   				}
    			}
	 		}
  			i.focus()
	  	}
 	} else {
 		if (direction == "down") {
	 		CheckDate(i)
  		}
  	}
  }
};



function CheckDate(THISDATE) {
	//alert("Inside checkDate .input dt = " +  THISDATE.value);
	var err=0;
	a=THISDATE.value;
	if(a == null || a == '') {
		return true;
	}
	if (a.length != 11) err=1
	monthMap = new Array(12)
	monthMap[0] = "JAN"
	monthMap[1] = "FEB"
	monthMap[2] = "MAR"
	monthMap[3] = "APR"
	monthMap[4] = "MAY"
	monthMap[5] = "JUN"
	monthMap[6] = "JUL"
	monthMap[7] = "AUG"
	monthMap[8] = "SEP"
	monthMap[9] = "OCT"
	monthMap[10] = "NOV"
	monthMap[11] = "DEC"

	d = a.substring(0, 2)/* day */
	c = a.substring(2, 3)/* '-' */
	b = a.substring(3, 6)/* month */
	e = a.substring(6, 7)// '-'
	f = a.substring(7, 11)/* year */

	if (isNaN(d)) {
			err=1
	}

	if (!isNaN(b)) {
			err=1
	}
	
	if (isNaN(f)) {
			err=1
	}

	if (d<1 || d>31) err = 1	
	b = b.toUpperCase()	
	var flg = 0
	for(var i = 0; i < monthMap.length; i++) {
	    if(b == monthMap[i]) {
		flg = 1;
		break;
	    }
	}
	if(flg == 0) err = 1
	if (f<1900) err = 1
	if (b==monthMap[3] || b==monthMap[5] || b==monthMap[8] || b==monthMap[10]){
		if (d==31) err=1
	}
	if (b==monthMap[1]){
		var g=parseInt(f/4)
		if (isNaN(g)) {
			err=1
		}
		if (d>29) err=1
		if (d==29 && ((f/4)!=parseInt(f/4))) err=1
	}
	if (err==1) {
		//alert(THISDATE.value + ' is not a valid date.Please re-enter in dd-mon-yyyy format.\n \t\teg 25-May-1981');
	    alert('Please enter Date in dd-mon-yyyy format.\n  eg. 25-May-1981 \n or use calendar');
		THISDATE.value = "";
		THISDATE.focus();
		THISDATE.select();
		return false;
	}
	return true;
};

function dateInterface(source,keyUpDown) {
	FormatDate(source, window.event.keyCode,keyUpDown);
};

function validateInt(fieldName) {
	//alert("Inside validate int");
	if (fieldName.value != '') {
		for(var i = 0; i < fieldName.value.length; i++) {
			var myChar = fieldName.value.charAt(i);
			if ( myChar >= '0' && myChar <= '9') { 			
			} 
			else {
				alert('Invalid Character for ' + fieldName.name +
					'. Valid characters are Numbers(0-9)');
				fieldName.focus();
				return false;
			}					
		}
	}
	//alert("Everything is ok!!!!");
return true;
};

function validateFloat(fieldName) {

	if (fieldName.value != '') {
		for(var i = 0; i < fieldName.value.length; i++) {
			var myChar = fieldName.value.charAt(i);
			if ( (myChar >= '0' && myChar <= '9' ) ||
				myChar == '.') { 			
			} 
			else {
				alert('Invalid Character for ' + fieldName.name +
				'. Valid characters are Numbers(0-9) and .');
				fieldName.focus();
				return false;
			}					
		}
	}
	
	/* Check for Multiple Decimal Points */
	if (fieldName.value != '') {
		var cnt='0';
		for(var i = 0; i < fieldName.value.length; i++) {
			var myChar = fieldName.value.charAt(i);
			if (myChar == '.' && cnt == '0') {
				cnt = '1';
			} else if (myChar == '.' && cnt == '1') {
				alert('Multiple Decimal Points Specified at ' + fieldName.name +
				'. Only one Decimal Point should be specified.');
				fieldName.focus();
				return false;
			}
		}
	}

	/* Check if only Decimal Point is specified */
	if (fieldName.value != '') {
		var cnt='0';
		for(var i = 0; i < fieldName.value.length; i++) {
			var myChar = fieldName.value.charAt(i);
			if (myChar == '.' && fieldName.value.length == 1) {
				alert('Invalid Number at ' 
				+ fieldName.name + '. Kindly Enter Proper Number(s).');
				fieldName.focus();
				return false;
			}
		}
	}
	return true;
};

function validateTelOrFaxNo(fieldName) {
		
	if (fieldName.value != '') {
		for(var i = 0; i < fieldName.value.length; i++) {
			var myChar = fieldName.value.charAt(i);
			if ( (myChar >= '0' && myChar <= '9') || 
			    myChar == "(" || myChar == ")" || 
			    myChar == "/" || myChar == "-" ||
			    myChar == ' ') {
			} 
			else {
				alert('Invalid Character for Telephone/Fax Number.Valid ' +
					'characters are Numbers(0-9),space,-,(,),/');
				fieldName.focus();
				return false;
			}					
		}
	}
	return true;
};

function validateEmailAdd(fieldName) {
	var atRate = 0;
	var dot = 0;
	if (fieldName.value != '') {
		for(var i = 0; i < fieldName.value.length; i++) {
			var myChar = fieldName.value.charAt(i);

			if ((myChar >= '0' && myChar <= '9') 	||
				(myChar >= 'a' && myChar <= 'z') 	|| 
				(myChar >= 'A' && myChar <= 'Z') 	||
				myChar == '_' 	|| myChar == '@' ||
				myChar == '.' || myChar == '-') {


				if(myChar == '@')
				    atRate++;
				if(myChar == '.')
				    dot++;
			}else {
				alert('Invalid Character at Email Address. Valid Characters ' +
					'are Numbers(0-9),space,underscore,hyphen, a-z, A-Z,@ and .(period)');
				fieldName.focus();
				return false;
			}					
		}
	}
    if (atRate == 1 && dot >= 1){
	   // return true;
	} else {
	     alert('Invalid Email Address.Pls check');
	 	 fieldName.focus();
		 return false;
	}
	return true;
};

function validateCharWithSpace(fieldName) {
		
	if (fieldName.value != '') {
		for(var i = 0; i < fieldName.value.length; i++) {
		var myChar = fieldName.value.charAt(i);
				
		if ((myChar >= "a" && myChar <= "z") || 
			    (myChar >= "A" && myChar <= "Z") || 
			    myChar == ' ') {
		} 
		else {

			/*if(fieldName.name != "PrefTestCenterTextBox"){
			alert('Invalid Preffered Test Center +
				' .Valid characters are a-z, A-Z and space.');
		    }else {*/
			alert('Invalid Character at field : '+ fieldName.name +
				' .Valid characters are a-z, A-Z and space.');
			//}
			//fieldName.value = "";
			fieldName.focus();
			return false;
			}					
		}
	}
	return true;
};

function validateUserID(fieldName) {
     //alert(fieldName);
	if (fieldName.value != '') {
		for(var i = 0; i < fieldName.value.length; i++) {
		var myChar = fieldName.value.charAt(i);

		if ((myChar >= "0" && myChar <= "9") ||
		    (myChar >= "a" && myChar <= "z") ||
			(myChar >= "A" && myChar <= "Z") ||
			 myChar == '-' || myChar == '_' ) {
		}
		else {
			alert('Invalid Character at User ID field : '+ fieldName.name +
				' .Valid characters are 0-9, a-z, A-Z, underscore and hyphen.');
			//fieldName.value = "";
			fieldName.focus();
			return false;
			}
		}
	} else return false;
	return true;
};

function validateCharWithSpaceAndPeriod(fieldName) {
		
	if (fieldName.value != '') {
	
		for(var i = 0; i < fieldName.value.length; i++) {
		var myChar = fieldName.value.charAt(i);
				
		if ((myChar >= "a" && myChar <= "z") || 
			    (myChar >= "A" && myChar <= "Z") || 
			    myChar == ' ' || myChar == "." ) {
		} 
		else {
			alert('Invalid Character at field : '+ fieldName.name +
				' .Valid characters are a-z, A-Z and space and .(period)');
			fieldName.focus();
			return false;
			}					
		}
	}
	return true;
};

function validateCharWithSpaceAndHyphen(fieldName) {
		
	if (fieldName.value != '') {
		for(var i = 0; i < fieldName.value.length; i++) {
		var myChar = fieldName.value.charAt(i);
				
		if ((myChar >= "a" && myChar <= "z") || 
			    (myChar >= "A" && myChar <= "Z") || 
			    (myChar == ' ') || (myChar == '-') ) {
		} 
		else {
			alert('Invalid Character at field : '+ fieldName.name +
				' .Valid characters are a-z, A-Z , space and hyphen(-).');
			fieldName.focus();
			return false;
			}					
		}
	}
	return true;
};

function validateChar(fieldName) {
		
	if (fieldName.value != '') {
		for(var i = 0; i < fieldName.value.length; i++) {
			var myChar = fieldName.value.charAt(i);
			if ((myChar >= "a" && myChar <= "z") || 
			    (myChar >= "A" && myChar <= "Z")) {
		
			} 
			else {
				alert('Invalid Character at field : '+ fieldName.name +
					'. Valid characters are a-z and A-Z.');
				fieldName.focus();
				return false;
			}					
		}
	}
	return true;
};

function validateAlphaNumeric(fieldName) {
	
	if (fieldName.value != '') {
		for(var i = 0; i < fieldName.value.length; i++) {
			var myChar = fieldName.value.charAt(i);
			if ((myChar >= 0 && myChar <= 9) || 
			    (myChar >= "a" && myChar <= "z") || 
			    (myChar >= "A" && myChar <= "Z")) {
			} 
			else {
				alert('Invalid Character at field : '+ fieldName.name +
					'. Valid characters are Numbers(0-9), a-z and A-Z.');
				fieldName.focus();
				return false;
			}					
		}
	}
	return true;
};


function validateUserId(fieldName) {
	
	if (fieldName.value != '') {
	
		for(var i = 0; i < fieldName.value.length; i++) {
		
			var myChar = fieldName.value.charAt(i);
			
			if (	(myChar >= '0' && myChar <= '9')|| 
				(myChar >= 'a' && myChar <= 'z')|| 
				(myChar >= 'A' && myChar <= 'Z')||
				 myChar == '_') {		
			} 
			else {
				alert('Invalid Characters.Valid Characters are 0-9, a-z, ' +
					'A-Z and underscore.');
				fieldName.focus();
				return false;
			}
		}
	}
	return true;
};



/* Added by Shilpa Tanksale on 18-Apr-2002. */
function validateTstdefName(formElement) {		
	
		var val = formElement.value;
		if (val != '') {
			for(var i = 0; i < val.length; i++) {
				var myChar = val.charAt(i);
				if ( (myChar >= 0 && myChar <= 9)     || 
				     (myChar >= 'a' && myChar <= 'z') || 
				     (myChar >= 'A' && myChar <= 'Z') ||
				      myChar == ' ' || myChar == '-'  ||
				      myChar == '(' || myChar == ')'  ||
				      myChar == '.' || myChar == ','  ||
				      myChar == '_') {
				} 
				else {
					alert('Invalid Character for name. '+ 
					'Valid characters are Numbers(0-9), a-z, ' +
					'A-Z, "-", ".", "(", ")", "_" and  ",".');
					formElement.focus();
					return false;
				}					
			}
		}
		return true;
	}

	/* Added by Shilpa Tanksale on 18-Apr-2002. */
	/* The first argument for the foll.  function is the formElement.
	 * The second & the third arguments are the size of the float as specified
	 * in the database. For e.g. if database size for passPercntg is number(5,2)
	 * then the 2nd & the 3rd arguments are 5 & 2 respectively.
	 * Note - This function does not check for -ve values or invalid chars. So in 
	 * addition to this func, u need to use the validateFloat() func defined above. 
	 */
	 
	function validateFloatValue(i, totLen, lenAfterDecimalPt) {		

		//alert("Inside validatefloatValue............");
		
		var lenBeforDecPt = totLen - lenAfterDecimalPt; 	
		var decPtIndex = lenBeforDecPt;
		var strLen = i.value.length;
		var val = i.value;

		if (val == null || val == '') {
			return true;
		}
		if(val.charAt(0) == '-') {
			val = val.substring(1,strLen);
		}

		var decPtIndexInInput = val.indexOf(".");
		var valBeforDecPt = 0;
		if (decPtIndexInInput != -1) {
			var tmp1 = val.substring(decPtIndexInInput + 1, strLen);
			var tmp2 = tmp1.indexOf(".");

			if (tmp2 != -1) {
				alert("Invalid float. Enter a valid value.");
				i.focus();
				return false;
			}

			valBeforDecPt = val.substring(0, decPtIndexInInput); 
		}

		if (valBeforDecPt != 0 && valBeforDecPt.length > lenBeforDecPt) {
			//alert("11111111Dec pt found at " + decPtIndexInInput + " i = " + val);	
			alert("A maximum of " + lenBeforDecPt + 
				" digits is allowed before the decimal point.");
			i.focus();
			return false;
		}
		
		var valAfterDecPt = 0;
		if (decPtIndexInInput != -1) {
			//alert("222222Dec pt found at " + decPtIndexInInput + " i = " + val);	
			valAfterDecPt = val.substring(decPtIndexInInput + 1, strLen); 
			if (valAfterDecPt.length > lenAfterDecimalPt) {
				alert("A maximum of " + lenAfterDecimalPt +
					" digits is allowed after the decimal point.");
				i.focus();
				return false;
			}
		}

		if (decPtIndexInInput == -1) {
			//alert("No dec pt found. i = " + val);
			if(strLen > lenBeforDecPt) {
				alert("A maximum of " + lenBeforDecPt + 
					" digits is allowed before the decimal point.");
				i.focus();
				return false;
			}
		}
				
		return true;
	}

function validateAttribute(fieldName) {
	
	if (fieldName.value != '') {
		for(var i = 0; i < fieldName.value.length; i++) {
		
			var myChar = fieldName.value.charAt(i);
			
			if (	(myChar >= '0' && myChar <= '9')|| 
				(myChar >= 'a' && myChar <= 'z')|| 
				(myChar >= 'A' && myChar <= 'Z')||
				 myChar == '_') {		
			} 
			else {
				alert("Invalid Characters for Attribute, " + fieldName.value +
					"Valid Characters are 0-9, a-z, A-Z and underscore.");
				fieldName.focus();
				return false;
			}
		}
	}
	return true;
};

/*Added by Shilpa T. on 29-Jul-2002. */
function isDt1GreaterThanOrEqualToDt2(dt1, dt2) {
	
	/* Input dates should be in the format 'dd-mon-yyyy'. */
	
	if(dt1.substring(7, 11) > dt2.substring(7, 11)) {
		return true;
	} else if (dt1.substring(7, 11) < dt2.substring(7, 11)) {
		return false;
	} else {					//year is same in both dates.

		var retVal = isMon1SameAsOrAfterMon2(dt1.substring(3, 6),
							dt2.substring(3, 6));
		if (retVal == 1) {
			return true;
		} else if (retVal == -1) {
			return false;
		} else if (retVal == 0) {	//month is same 
			if(dt1.substring(0, 2) < dt2.substring(0, 2)) {
				return false;
			} else {
				return true;
			}
		}

	}//else
}//end of method isDt1GreaterThanOrEqualToDt2


function isMon1SameAsOrAfterMon2(mon1, mon2) {	

	/*Input months should be one of the foll.*/

	monthArr = new Array("JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL",
			"AUG", "SEP", "OCT", "NOV", "DEC");

	var indMon1 = 0;
	var indMon2 = 0;

	for (var i = 0; i < monthArr.length; i++) {
		if (mon1.toLowerCase() == monthArr[i].toLowerCase()) {
			indMon1 = i;	
			break;
		}		
	}

	for (var i = 0; i < monthArr.length; i++) {
		if (mon2.toLowerCase() == monthArr[i].toLowerCase()) {
			indMon2 = i;	
			break;
		}		
	}

	if (indMon1 > indMon2) {		
		return 1;
	} else if (indMon1 < indMon2) {		
		return -1;
	} else if (indMon1 == indMon2) {
		return 0;
	}
}//end of isMon1SameAsOrAfterMon2


/*Added by Shilpa T. on 12-Aug-2002. */
function validateSLDesc(formElement) {
	
	var val = formElement.value;
	if (val == '') {
		return true;
	}
	
	if (val.charAt(0) == ' ')
	{
		
		alert("Subledger name cannot start with a blank space.");
		formElement.focus();
		return false;
	}
		
	for(var i = 0; i < val.length; i++) {

		var myChar = val.charAt(i);
		if(myChar == '\n') {
			alert('Invalid Character for name. Enter character is not allowed.');
			formElement.focus();
			return false;
		}//end of if

		if ( (myChar >= 0 && myChar <= 9)		||
		     (myChar >= 'a' && myChar <= 'z')	||
		     (myChar >= 'A' && myChar <= 'Z')	||
		      myChar == ' ' || myChar == '-'	||
		      myChar == '(' || myChar == ')'	||
		      myChar == '.' || myChar == ','	||
		      myChar == '_' || myChar == '\''	||
		      myChar == '/' || myChar == '&') {

		} else {
			alert('Invalid Character for name. '+ 
			'Valid characters are Numbers(0-9), a-z, ' +
			'A-Z, "-", ".", "(", ")", "_", ",", "\'", "/" and "&"');
			formElement.focus();
			return false;
		}//end of if

	}//end of for
		
	return true;
}//end of validateSLDesc

/*Added by Shilpa T. on 14-Aug-2002. */
function validateExamineeIdChars(fieldName) {
	
	if (fieldName.value != '') {
		for(var i = 0; i < fieldName.value.length; i++) {
			var myChar = fieldName.value.charAt(i);
			if ((myChar >= 0 && myChar <= 9)		|| 
			    (myChar == "n" || myChar == "N")	|| 
			    (myChar == "c" || myChar == "C")	||
				(myChar == "f" || myChar == "F")	|| 
				(myChar == "m" || myChar == "M")	|| 
				myChar == "-") {
			} 
			else {
				alert('Invalid Character at field : '+ fieldName.name +
				'. Valid characters are Numbers(0-9), hyphon and "N","C","F","M".');
				fieldName.focus();
				return false;
			}					
		}
	}
	return true;
};

/*Added by Shilpa T. on 15-Aug-2002. */
function validateAlternativeOrCondition(fieldName, maxSrNo) {

	var value = fieldName.value;
	if (value == '') {
		return true;
	}

	arrayOfStrings = value.split(";");	
	for (var k = 0; k < arrayOfStrings.length; k++) {
		
		value = arrayOfStrings[k];
		//alert("value = " + value);
		
		/* Check for valid characters. Only the foll. characters are allowed.*/
		for(var i = 0; i < value.length; i++) {
			var myChar = value.charAt(i);
			if ( (myChar >= '0' && myChar <= '9') 	||
					myChar == 'a' || myChar == 'c' 	||
					myChar == 't' || myChar == 'V' 	||
					myChar == 'l' || myChar == '<' 	||
					myChar == '>' || myChar == '=' 	||
					myChar == '[' || myChar == ']' 	||
					myChar == '.' || myChar == '_' 	||
					myChar == '-' || myChar == '+' 	||
					myChar == '*' || myChar == '/' 	||
					myChar == '@' || myChar == '^' 	||
					myChar == '(' || myChar == ')'	||
					myChar == ';' || myChar == '~') {
			
			} else {
				alert('Invalid Character at field : '+ fieldName.name +
				'. Valid characters are Numbers(0-9), "a", "c", "t", "V", "a", "l", ' +
				'"<", ">", "=", "[", "]", period, underscore, hyphon, "+", "-", "*", ' +
				'"/", "@", "^", "~" and round brackets.');
	
				fieldName.focus();
				return false;
			}					
		}//end of for

		//alert("Valid chatSet");
	
		if (!isMatchingRoundBrackets(fieldName, value)) {
			return false;
		}
		//alert("Matching (");
	
		if (!isMatchingSquareBrackets(fieldName, value)) {
			return false;
		}

		//alert("Matching [");
	
		/*Check for existence of occurrence of actVal[n] and with valid index.*/
		if (!validateActValPart(fieldName, value, maxSrNo)) {
			return false;
		}

		//alert("actVal present, valid index");

		/* Check if every start bracket '(' is preceded with a '+' sign. */
		if (!checkBracketPrecededByPlus(fieldName, value)) {
			return false;
		}

		//alert("+ sign b4 (");
	
		/*Check for underscores.*/
		if (!checkForUnderscores(fieldName, value)) {
			return false;
		}
		//alert("valid underscores");
	}//end of for

	return true;
}//end of validateAlternativeOrCondition

function extractNoFromString(strVal) {

	//alert("In extractNoFromString");
	var val = strVal;
	var tmpStr = "";
	var myChar;
	var flag = true;
	var i = 0;
	var j = 0;

	while (true) {

			myChar = strVal.charAt(i);
			j = i;
			if (j > strVal.length) {
				//alert("returning ''");
				return "";
			}
			if ( (myChar >= '0' && myChar <= '9') ||
					myChar == '.') {
				tmpStr = tmpStr + myChar;
				while (true) {
					j = eval(j + " + 1");
					myChar = strVal.charAt(j);
					//alert("j = " + j + " myChar = " + myChar);
					if ((myChar >= '0' && myChar <= '9') || myChar == '.') {
						tmpStr = tmpStr + myChar;
					} else {
						//alert("returning" + tmpStr);
						return tmpStr;
					}
				}
			} else {
				i = eval(i + " + 1");
				continue;
			}
	}//end of while	
}//end of extractNoFromString


/* Check if an underscore preceeds and follows every number in the input string. */
function checkForUnderscores(fieldName, strVal) {
	
	//alert("Inside checkForUnderscores.");
	var flag = true;
	var tmp = strVal;
	var str2 = "";

	while (flag) {

		idx = tmp.indexOf("_");
		if (idx == -1) {	//no underscore present in the string.	
			//alert("No underscore present");
			var ind1 = 0;
			var ind2 = 0;
			var ind3 = 0;
			while (true) {

				str2 = extractNoFromString(tmp);
				if (str2 == "") {
					return true;
				}
				ind1 = tmp.indexOf(str2);
				if (ind1 == 0) {
					alert("Invalid value for : " + fieldName.name +
						". Every number should be preceded and followed " +
						"by an underscore.");
					fieldName.focus();
					return false;
				}

				ind2 = eval(ind1 + " + " + str2.length);
				ind3 = eval(ind1 + "- 1");
				
				if ( (tmp.charAt(ind3) != '[' && tmp.charAt(ind2) != ']') ) {
						
					alert("Invalid value for : " + fieldName.name +
						". Every number should be preceded and followed " +
						"by an underscore.");
					fieldName.focus();
					return false;	
				}

				tmp = tmp.substring(eval(ind2 + "+ 1"), tmp.length);
				if (tmp.length == 0) {
					flag = false;
					//alert("breaking while");
					break;
				}
			}//end of while(true)
			//alert("after while");
		} else { //if (idx == -1) 
				//underscore present in the string.	
			//alert("underscore present");
			idx2 = tmp.indexOf("_", idx + 1);
			if (idx2 == -1) {
				alert("Invalid value for : " + fieldName.name +
					" There is just one occurrence of underscore. There should " +
					"be an underscore preceding and following every number." );
				fieldName.focus();
				return false;
			} else {
				str = tmp.substring(idx + 1, idx2);
				//alert("str = " + str + " floatParsed = " + parseFloat(str));	
				if ( isNaN(parseFloat(str)) ) {
					alert("Invalid value for : " + fieldName.name +
						". Only a number should be preceded and followed " +
						"by an underscore.");
					fieldName.focus();
					return false;
				}
			}
			tmp = tmp.substring(idx2 + 1, tmp.length);
			if (tmp.length == 0) {
				flag = false;
			}

		}//end of else
	
	}//end of while(flag)

	return true;
}//end of checkForUnderscores


/*Check for existence of occurrence of actVal[n] and with valid index.*/
function validateActValPart(fieldName, value, maxSrNo) {
	
	//alert('in actval part field name '+fieldName.name);
	var flag = true;
	var idx;
	var value2;
	var idx2;
	var tmp = value;
	var value = new Array();
	var i = 0;
	idx = tmp.indexOf("actVal[");	
	if (idx == -1) {
			alert("'" + fieldName.name  +
				"' must contain the occurrence of actVal[n]," +
				"which is to be replaced by dynamic variable value.");
			fieldName.focus();
			return false;
	}

	while (flag) {
	
		idx = tmp.indexOf("actVal[");
		value2 = tmp;	
		if (idx == -1) {
			break;
		}

		idx = value2.indexOf("[");
		idx2 = value2.indexOf("]");
		//alert("1value = " + value2 + " idx =" + idx + " idx2=" + idx2);
		var n = eval(idx + " + 1");
		var str = value2.substring(n, idx2);
	

		if (isNaN(parseInt(str))) {
			alert("The index value defined for actVal, '" + str + "' is not valid." +
				" An integer is expected.");
			fieldName.focus();	
			return false;
		}
		else {
			//alert("The str is "+str);
			value[i] = parseInt(str);
			i = i + 1;
		}
			
		if(eval(str + " >= " + maxSrNo) || eval(str + " < 0")) {
			alert("Value for the index of actVal is not valid. " +
				"Valid values are 0 to " + eval(maxSrNo + " - 1"));
			fieldName.focus();
			return false;
		}

		tmp = tmp.substring(eval(idx2 + " + 1"), tmp.length);
		if (tmp.length == 0) {
			flag = false;
		}
	}//end of while
	
	//alert("After while");	
	if( fieldName.name == "Condition" ) {
		
		i = 0;
		
		for (var j = 1; j < value.length; j++) {
		
			if( value[i] < value[j] ) {
			
				alert(" The index of Left Hand Side Variable ("+value[i]+
				") should always be greater than the indices of right hand side variable ("+
				value[j]+
				"). Please check the Condition. ");
				fieldName.focus();
				return false;
			}
		}
	}
	
	//alert("Before returning true in actValPart");
	
	return true;
	
}//end of validateActValPart


function isMatchingRoundBrackets(fieldName, value) {

	var val = value;
	var cnt = 0;
	var myChar;

	

	for (var i = 0; i < val.length; i++) {

		myChar = val.charAt(i);		
		if (myChar == '(') {
			cnt = eval(cnt + " + 1");
		} else if (myChar == ')') {
			cnt = eval(cnt + " - 1");
		}
	}//end of for

	if (cnt != 0) {
		alert("Mismatch in the no. of round brackets, '('. Please check.");
		fieldName.focus();
		return false;
	}

	return true;
}//end of isMatchingRoundBrackets


function isMatchingSquareBrackets(fieldName, value) {

	var val = value;
	var cnt = 0;
	var myChar;

	for (var i = 0; i < val.length; i++) {

		myChar = val.charAt(i);
		if (myChar == '[') {
			cnt = eval(cnt + " + 1");
		} else if (myChar == ']') {
			cnt = eval(cnt + " - 1");
		}
	}//end of for

	if (cnt != 0) {
		alert("Mismatch in the no. of square brackets, '['. Please check.");
		fieldName.focus();
		return false;
	}

	return true;
}//end of isMatchingSquareBrackets


/* Checks if every start bracket '(' is preceded with a '+' sign. */
function checkBracketPrecededByPlus(fieldName, value1) {

	var val = value1;
	//alert("val = " + val);

	var tmp1 = val.indexOf('(');

	/*Should include iequality signs too when the system starts supporting them.*/
	var id = val.indexOf("=");
	if (id != -1) {
		id = eval(id + " + 1");
		var str = val.substring(id , val.length);
		tmp1 = str.indexOf('(');
	}	
	if (tmp1 == -1) {
			return true;
	}
	if (tmp1 == 0) {
		alert("Start bracket '(', in the Condition string " +
			"should be preceded by a '+' sign.");
		fieldName.focus();
		return false;
	}

	var tmp2;
	while (true) {
		//alert("val = " + val);
		tmp1 = val.indexOf('(');
		if (tmp1 == -1) {
			return true;
		}
		tmp2 = val.charAt(eval(tmp1 + "- 1"));
		if (tmp2 == "+" || tmp2 == '-' || tmp2 == '*' || tmp2 == '/' 
			|| tmp2 == '@' || tmp2 == '~' || tmp2 == '^') {
		}
		else {
			alert("Every start bracket '(', in the Condition string " +
				"should be preceded by arithmatic operator or atleast a '+' sign.");
			fieldName.focus();
			return false;
		}
		val = val.substring(eval(tmp1 + " + 1"));		
		if (val.length == 0) {
			return true;
		}		
	}//end of while
	return true;
}//end of function checkBracketPrecededByPlus

function validateNegativeFloat(fieldName) {
	
	//alert("Validate Neg float "+fieldName.name);
	if (fieldName.value != '') {
		for(var i = 0; i < fieldName.value.length; i++) {
			var myChar = fieldName.value.charAt(i);
			if ( (myChar >= '0' && myChar <= '9' ) ||
				myChar == '.' || myChar == '-') { 			
			} 
			else {
				alert('Invalid Character for ' + fieldName.name +
					'. Valid characters are Numbers(0-9), -ve sign and .');
				fieldName.focus();
				return false;
			}					
		}
	}
	return true;
};


/* Added by Shilpa T. on 13-Sep-2002.
 *
 * The foll. function checks that for a condition, the variable appearing on the
 * left side of 'equal to' sign (=) does not appear on the right side. For e.g.,
 * the condition 'actVal[1]=actVal[1]+3' is invalid. Right hand side should
 * contain other variables, and only those that are already evaluated (i.e. having
 * index less than the LHS variable).
 */

function checkRHSVariables(conditionField, noAltr) {

	//alert("Inside checkRHSVariables. condition = " +
	//								conditionField.value);

	var condVal = conditionField.value;

	arrayOfStrings = condVal.split(";");	
	for (var k = 0; k < arrayOfStrings.length; k++) {

		condVal = arrayOfStrings[k];
		var ind = condVal.indexOf("[");
		var ind2 = condVal.indexOf("]=");
		if (ind2 == -1) {
			return true;
		}
		var searchIndex = condVal.substring(ind, ind2 + 1);
		var lhsIndex = condVal.substring(ind + 1, ind2);
		//alert("SearchIndex = " + searchIndex);

		condVal = condVal.substring(ind2 + 1, condVal.length);	
		ind = condVal.indexOf(searchIndex);
		//alert("condVal = " + condVal + " ind = " + ind);

		/*if (ind != -1) {
			alert("A variable cannot appear on both sides " +
						"of the '=' sign in the condition.");
			conditionField.focus();
			return false;
		}
		*/
	

		for (var i = lhsIndex; i < noAltr; i++) {
		
			var tmp = "[" + i + "]";
			if (condVal.indexOf(tmp) != -1) {

				if (i == lhsIndex) {
					alert("A variable cannot appear on both sides " +
						"of the '=' sign in the condition.");
					conditionField.focus();
					return false;
				} else {

					alert("Condition value is invalid. The index of Left Hand side " +
					"variable should always be greater than the indices of the " +
					"variables on the right hand side. ");
					conditionField.focus();
					return false;
				}
			}//if (condVal
		}//end of for(var i = 

	}//end of for(var k = 0
	return true;
}//end of checkRHSVariables


/* Added by Shilpa T. on 17-Sep-2002. */
function checkEqualityInequality(conditionField) {

	/* Currently only equality condition is supported.
	 * This function will be required to be modified when the system
	 * starts supporting inequality conditions too.
	 */

	var val = conditionField.value;
	if(val == null ||val == "") {
		return true;
	}

	arrayOfStrings = val.split(";");

	for (var k = 0; k < arrayOfStrings.length; k++) {
		val = arrayOfStrings[k];

		if (val.indexOf("=") == -1) {
			alert("Condition does not contain the equality clause. Please check.");
			conditionField.focus();
			return false;
		}
	}//end of for

	return true;
}

/* Added Shilpa T. on  - 26-Nov-2002
 * The foll. function accepts a number and generates an id out of it, defined by prefix &
 * separator.
 * e.g. NCFM-00000000003 where prefix is 'NCFM', separator is '-' and Id length is 16.
 */

	function getId(idAsNum, prefix, separator, finalIdLen) {

		if(idAsNum == "") {
			return idAsNum;
		}		
		
		var idReturn = "";	
		var index = idAsNum.indexOf(separator);
		var str =  idAsNum.substring(index + 1);
		var lengthOfStr = str.length();
		var noOfZerosReq = finalIdLen - lengthOfStr;
		for (var i = 0; i < noOfZerosReq; i++) {
			str = "0" + str;
		}

		idReturn = prefix + separator + str;	
		
		return idReturn.toString();
	}

	/* Added By Prachi K. on 02-Dec-2002 */
	function getCurrentSystemDateInStringFormat() {

	 	month = new Array ( 'Jan','Feb', 'Mar','Apr','May','Jun','Jul','Aug',
							'Sep','Oct','Nov','Dec');
		var dt = new Date();
		var mydt = dt.getDate();
		myVarName = new String(mydt);
		if (myVarName.length < 2)
			myVarName = '0' + myVarName;	
		var curYear = Math.round(dt.getTime() / 31556952000) + 1970
		curYear = curYear + (dt.getYear()- curYear)%100
		var strDate = myVarName + '-' + month[dt.getMonth()] + '-' +curYear;	
		return strDate;
	}
/* Added by SwatiG on 16-jan2003 */

function validateRemarksLength(fieldName){
	
	var len = fieldName.value.length;
	
	if (eval(len + " > 1000 ")){
		alert("Length of 'Remarks' can not exceed 1000 characters.");
		fieldName.focus();
		return false;
	}
	return true;
}

/* Added by Swati G. on 20-jan-2003 */
function validFloatAmount(fieldName, totLen, lenAfterDecimalPt) {

	if (!validateFloat(fieldName)) {
		return false;
	}
	if(!validateFloatValue(fieldName, totLen, lenAfterDecimalPt)) {
			return false;
	}
	return true;
}

	/*Added by Shilpa T. on 23-Jan-2003.*/
	function validateExamineeId(fieldName) {
		
		var id = fieldName.value;
		var prefix = 'NCFM';
		var exmIdLength = "16";
		var separator = "-";

		if (id.indexOf('dummy') != -1)	{
			return true;
		}

		//alert("prefix = " + prefix + " separator = " + separator +
		//	" len = " + exmIdLength);

		var idLen = eval(exmIdLength + " - " + prefix.length + " - " +
								separator.length);
		//alert("idLen = " + idLen);

		/* Check for any invalid characters i.e.
		 * characters other than alphabets, hyphen and digits.
		 */
		if (!validateExamineeIdChars(fieldName)) {
			return false;
		}

		
		var val = "";

		/* Validate if value contains alphabets as well as digits.*/
		if (isNaN(id)) {

			var myChar = "";
			var isDigit = "false";

			for(var i = 0; i < id.length; i++) {
				myChar = id.charAt(i);
				if (myChar >= 0 && myChar <= 9) {
					isDigit = "true";
					break;
				} 
			}
			
			if (isDigit == "false") {
				alert("Invalid value for examinee id. Please check");
				fieldName.focus();
				return false;
			}

			var temp = 0;
			if (id.indexOf('-') == -1) {

				alert("Invalid value for examinee id. Please check");
				fieldName.focus();
				return false;
			}

			//alert("charAt(4) = " + id.charAt(4) + " 0-4 = " + id.substring(0, 4));

			if (	eval(id.length + " > 12")) {
				
				var tmp = id.substring(0, 4);

				if (tmp.toLowerCase() != prefix.toLowerCase()	||
						id.charAt(4) != separator)	 {

					alert("Invalid value for examinee id. Please check");
					fieldName.focus();
					return false;
				}
				
				val = id.substring(5, id.length);
			}

			if (eval(id.length + " > 5")) {
				
				var tmp = id.substring(0, 4);

				if (tmp.toLowerCase() == prefix.toLowerCase()	||
						id.charAt(4) == separator)	 {

					val = id.substring(5, id.length);
				}
			}

			if (id.charAt(0) == separator) {
				/*if (eval(id.length + " > 12")) {
					alert("Invalid value for examinee id2. Please check");
					fieldName.focus();
					return false;
				}*/

				if (eval(id.length + " <= 12")) {					
					val = id.substring(1, id.length);
				}	
			}
		} else {							//if value contains only digits
			if (eval(id.length + " > " + idLen)) {
				alert("Value for id is too long. Length of digits should not exceed" +
					idLen + " characters.");
				fieldName.focus();
				return false;
			}
			val = id;
		}

		if (isNaN(val) ||(parseInt(val,10)==0)) {
			alert("Invalid value for examinee id. Please check");
			fieldName.focus();
			return false;
		}

		return true;

	}//end of vaidateExamineeId
/* Added be Swati G. */
/*Returns double from a String that contains a comma separated number.*/
function getDoubleFromCommaSepStr(val) {
	
		var myChar;
		var finalVal = "";
		for (var i = 0; i< val.length ; i++){
			myChar = val.charAt(i);
			if(myChar != ','){
				finalVal = finalVal + myChar;
			}
		}
		
		return finalVal;
}
/* Added by SwatiG on 16-jan2003 */

function validateConditionLength(fieldName){
	
	var len = fieldName.value.length;
	
	if (eval(len + " > 2000 ")){
		alert("Length of 'Condition' can not exceed 2000 characters.");
		fieldName.focus();
		return false;
	}
	return true;
}

/* Added by Swati G. by 06-feb-2003 */
function validateIdChars(fieldName) {
	
	if (fieldName.value != '') {
		for(var i = 0; i < fieldName.value.length; i++) {
			var myChar = fieldName.value.charAt(i);
			if ((myChar >= 0 && myChar <= 9)		|| 
			    (myChar == "c" || myChar == "C")	|| 
			    (myChar == "o" || myChar == "O")	||
				(myChar == "r" || myChar == "R")	|| 
				(myChar == "p" || myChar == "P")	|| 
				myChar == "-") {
			} 
			else {
				alert('Invalid Character at field : '+ fieldName.name +
				'. Valid characters are Numbers(0-9), hyphon and alphabets "C","O","R","P".');
				fieldName.focus();
				return false;
			}					
		}
	}
	return true;
};
/*Added by Swati G. on 06-Jan-2003.*/
function validateCorporateId(fieldName) {
		
		var id = fieldName.value;
		var prefix = 'CORP';
		var exmIdLength = "16";
		var separator = "-";

		

		//alert("prefix = " + prefix + " separator = " + separator +
		//	" len = " + exmIdLength);

		var idLen = eval(exmIdLength + " - " + prefix.length + " - " +
								separator.length);
		//alert("idLen = " + idLen);

		/* Check for any invalid characters i.e.
		 * characters other than alphabets, hyphen and digits.
		 */
		if (!validateIdChars(fieldName)) {
			return false;
		}

		
		var val = "";

		/* Validate if value contains alphabets as well as digits.*/
		if (isNaN(id)) {

			var myChar = "";
			var isDigit = "false";

			for(var i = 0; i < id.length; i++) {
				myChar = id.charAt(i);
				if (myChar >= 0 && myChar <= 9) {
					isDigit = "true";
					break;
				} 
			}
			
			if (isDigit == "false") {
				alert("Invalid value for Corporate id. Please check");
				fieldName.focus();
				return false;
			}

			var temp = 0;
			if (id.indexOf('-') == -1) {

				alert("Invalid value for Corporate id. Please check");
				fieldName.focus();
				return false;
			}

			//alert("charAt(4) = " + id.charAt(4) + " 0-4 = " + id.substring(0, 4));

			if (	eval(id.length + " > 12")) {
				
				var tmp = id.substring(0, 4);

				if (tmp.toLowerCase() != prefix.toLowerCase()	||
						id.charAt(4) != separator)	 {

					alert("Invalid value for Corporate id. Please check");
					fieldName.focus();
					return false;
				}
				
				val = id.substring(5, id.length);
			}

			if (eval(id.length + " > 5")) {
				
				var tmp = id.substring(0, 4);

				if (tmp.toLowerCase() == prefix.toLowerCase()	||
						id.charAt(4) == separator)	 {

					val = id.substring(5, id.length);
				}
			}

			if (id.charAt(0) == separator) {
				/*if (eval(id.length + " > 12")) {
					alert("Invalid value for examinee id2. Please check");
					fieldName.focus();
					return false;
				}*/

				if (eval(id.length + " <= 12")) {					
					val = id.substring(1, id.length);
				}	
			}
		} else {							//if value contains only digits
			if (eval(id.length + " > " + idLen)) {
				alert("Value for id is too long. Length of digits should not exceed" +
					idLen + " characters.");
				fieldName.focus();
				return false;
			}
			val = id;
		}

		if (isNaN(val)	||	parseInt(val) == 0) {
			alert("Invalid value for Corporate id. Please check");
			fieldName.focus();
			return false;
		}

		return true;

	};//end of vaidateCorporateid
/*Added by Swati G. on 11-jan-2003 */
function validateNameCharWithSpace(fieldName) {
		
	if (fieldName.value != '') {
		for(var i = 0; i < fieldName.value.length; i++) {
		var myChar = fieldName.value.charAt(i);
				
		if ((myChar >= "a" && myChar <= "z") || 
			    (myChar >= "A" && myChar <= "Z") || 
			    myChar == ' ' || myChar == '\'') {
		} 
		else {
			alert('Invalid Character at field : '+ fieldName.name +
				' .Valid characters are a-z, A-Z, space and \' .');
			//fieldName.value = "";
			fieldName.focus();
			return false;
			}					
		}
	}
	return true;
};


function showStates () { 

var states  ='<option value="Select" selected > --Select State-- </option>';

states +='<option value="Andaman & Nicobar">Andaman & Nicobar</option>';

states += '<option value="Andhra Pradesh">Andhra Pradesh</option>';

states += '<option value="Arunachal Pradesh">Arunachal Pradesh</option>';

states += '<option value="Assam">Assam </option>';

states += '<option value="Bihar">Bihar</option>';

states += '<option value="Chandigarh">Chandigarh</option>';

states += '<option value="Chhattisgarh">Chhattisgarh</option>';

states += '<option value="Dadra & Nagar Haveli">Dadra & Nagar Haveli</option>';

states += '<option value="Daman & Diu">Daman & Diu </option>';

states += '<option value="Delhi">Delhi</option>';

states += '<option value="Goa">Goa</option>';

states += '<option value="Gujarat">Gujarat</option>';

states += '<option value="Haryana">Haryana</option>';

states += '<option value="Himachal Pradesh">Himachal Pradesh</option>';

states += '<option value="Jammu & Kashmir">Jammu & Kashmir </option>';

states += '<option value="Jharkhand">Jharkhand</option>';

states += '<option value="Karnataka">Karnataka</option>';

states += '<option value="Kerala">Kerala</option>';

states += '<option value="Lakshadweep">Lakshadweep</option>';

states += '<option value="Madhya Pradesh">Madhya Pradesh</option>';

states += '<option value="Maharashtra">Maharashtra</option>';

states += '<option value="Manipur">Manipur</option>';

states += '<option value="Meghalaya">Meghalaya</option>';

states += '<option value="Mizoram">Mizoram</option>';

states += '<option value="Nagaland">Nagaland</option>';

states += '<option value="Orissa">Orissa</option>';

states += '<option value="Pondicherry">Pondicherry</option>';

states += '<option value="Punjab">Punjab</option>';

states += '<option value="Rajasthan">Rajasthan</option>';

states += '<option value="Sikkim">Sikkim</option>';

states += '<option value="Tamil Nadu">Tamil Nadu</option>';

states += '<option value="Tripura">Tripura</option>';

states += '<option value="Uttar Pradesh">Uttar Pradesh</option>';

states += '<option value="Uttaranchal">Uttaranchal</option>';

states += '<option value="West Bengal">West Bengal</option>';

states += '<option value="Other">Other</option>';

document.write(states);

};

function showMonths () {
//alert("alertttttttttttttt");
//	var dt = new Date();
//alert("---"+dt.getTime());
var month  ='<option value="Select" selected >Month</option>';

month  +='<option value="Jan">Jan</option>';

month  +='<option value="Feb">Feb</option>';

month  +='<option value="Mar">Mar</option>';

month  +='<option value="Apr">Apr</option>';

month  +='<option value="May">May</option>';

month  +='<option value="Jun">Jun</option>';

month  +='<option value="Jul">Jul</option>';

month  +='<option value="Aug">Aug</option>';

month  +='<option value="Sep">Sep</option>';

month  +='<option value="Oct">Oct</option>';

month  +='<option value="Nov">Nov</option>';

month  +='<option value="Dec">Dec</option>';

document.write(month);
};

function showDays () {

var day  ='<option value="Select" selected >Day</option>';

		day  +='<option value="01">01</option>';
		day  +='<option value="02">02</option>';
		day  +='<option value="03">03</option>';
		day  +='<option value="04">04</option>';
		day  +='<option value="05">05</option>';
		day  +='<option value="06">06</option>';
		day  +='<option value="07">07</option>';
		day  +='<option value="08">08</option>';
		day  +='<option value="09">09</option>';
		day  +='<option value="10">10</option>';
		day  +='<option value="11">11</option>';
		day  +='<option value="12">12</option>';
		day  +='<option value="13">13</option>';
		day  +='<option value="14">14</option>';
		day  +='<option value="15">15</option>';
		day  +='<option value="16">16</option>';
		day  +='<option value="17">17</option>';
		day  +='<option value="18">18</option>';
		day  +='<option value="19">19</option>';
		day  +='<option value="20">20</option>';
		day  +='<option value="21">21</option>';
		day  +='<option value="22">22</option>';
		day  +='<option value="23">23</option>';
		day  +='<option value="24">24</option>';
		day  +='<option value="25">25</option>';
		day  +='<option value="26">26</option>';
		day  +='<option value="27">27</option>';
		day  +='<option value="28">28</option>';
		day  +='<option value="29">29</option>';
		day  +='<option value="30">30</option>';
		day  +='<option value="31">31</option>';
		

document.write(day);
};

/*function showBirthYears () {

var dt = new Date();
var curYear = dt.getYear();
//curYear += 2000;
if (dt.getMonth() == 11)
     curYear++;
var year  ='<option value="Select" selected >Year</option>';

for (var i=1910; i<curYear ; i++){
    year  +='<option value="'+i+'">'+i+'</option>';
 }
document.write(year);
};*/

function showBirthYears () {

var dt = new Date();
//var curYear = dt.getYear();
var curYear = Math.round(dt.getTime() / 31556952000) + 1970
	curYear = curYear + (dt.getYear()- curYear)%100
var year  ='<option value="Select" selected >Year</option>';
if (dt.getMonth() == 11)
     curYear++;
var year  ='<option value="Select" selected >Year</option>';

//for (var i=1910; i<=curYear-1 ; i++){
for (var i=curYear-1; i>=1910 ; i--){
    year  +='<option value="'+i+'">'+i+'</option>';
 }
document.write(year);
};

function showYears () {

var dt = new Date();
//var curYear = dt.getYear();
//alert (dt.getTime());
var curYear = Math.round(dt.getTime() / 31556952000) + 1970
//curYear = currYear + (D.getYear()-YE)%100
//alert (dt.getYear());
//alert (curYear);

curYear = curYear + (dt.getYear() - curYear) % 100;
//alert (curYear);

var year  ='<option value="Select" selected >Year</option>';

for (var i=curYear; i<=curYear+1 ; i++){
    year  +='<option value="'+i+'">'+i+'</option>';
 }
document.write(year);
};

//added for FireFox browser
/*function getFY(D) { var YE 
          YE = Math.round(D.getTime() / 31556952000) + 1970 
          return YE + (D.getYear()-YE)%100 } */

  

function isZeroPreffixed(fieldName) {

	if (fieldName.value != '') {
		//for(var i = 0; i < fieldName.value.length; i++) {
		var myChar = fieldName.value.charAt(0);

		/*if ((myChar >= "a" && myChar <= "z") ||
			    (myChar >= "A" && myChar <= "Z") ||
			    myChar == ' ') {
		}*/
		if (myChar != "0") {
		} else {
			alert('Pls Do Not Preffix Zero in STD and Country Code');
			fieldName.value = "";
			fieldName.focus();
			return false;
		}
	}
	return true;
};

function validateAlphaNumeric(fieldName,msgField) {

	if (fieldName.value != '') {
		for(var i = 0; i < fieldName.value.length; i++) {
			var myChar = fieldName.value.charAt(i);
			if ((myChar >= 0 && myChar <= 9) ||
			    (myChar >= "a" && myChar <= "z") ||
			    (myChar >= "A" && myChar <= "Z")) {
			}
			else {
				alert('Invalid Character at field : '+ msgField +
					'. Valid characters are Numbers(0-9), a-z and A-Z.');
				fieldName.focus();
				return false;
			}
		}
	}
	return true;
};

function validateCharWithSpace(fieldName,msgField) {

	if (fieldName.value != '') {
		for(var i = 0; i < fieldName.value.length; i++) {
		var myChar = fieldName.value.charAt(i);

		if ((myChar >= "a" && myChar <= "z") ||
			    (myChar >= "A" && myChar <= "Z") ||
			    myChar == ' ') {
		}
		else {
			alert('Invalid  '+ msgField +
				' .Valid characters are a-z, A-Z and space.');
			//fieldName.value = "";
			fieldName.focus();
			return false;
			}
		}
	}
	return true;
};

function validateInt(fieldName,msgField) {
	//alert("Inside validate int");
	if (fieldName.value != '') {
		for(var i = 0; i < fieldName.value.length; i++) {
			var myChar = fieldName.value.charAt(i);
			if ( myChar >= '0' && myChar <= '9') {
			}
			else {
				alert('Invalid ' + msgField +
					'. Valid characters are Numbers(0-9)');
				fieldName.focus();
				return false;
			}
		}
	}
	//alert("Everything is ok!!!!");
return true;
};

function ConfirmPasswd(passwd,confirmPasswd) {
	//alert('in Password  matching');
    if ((passwd.value != '' && confirmPasswd.value != '') && (passwd.value.length == confirmPasswd.value.length)) {

        if((passwd.value.length >= 6) && (passwd.value.length <= 15)){

            for(var i = 0; i < passwd.value.length; i++) {

                var myCharP = passwd.value.charAt(i);
                var myCharC = confirmPasswd.value.charAt(i);

                /*if (	(myChar >= '0' && myChar <= '9')||
                    (myChar >= 'a' && myChar <= 'z')||
                    (myChar >= 'A' && myChar <= 'Z')||
                     myChar == '_') {
                } */
                if(myCharP == myCharC){
                } else {
                    alert("Password and confirm password are not matching");
                    passwd.value = "";
                    confirmPasswd.value = "";
                    passwd.focus();
                    return false;
                }
            }
        }else {
          alert('Password should be minimum of 6 and maximum of 15 characters');
          passwd.value = "";
          confirmPasswd.value = "";
          passwd.focus();
          return false;
        }
     }
   return true;
};

function ConfirmEmailID(eid,confirmEid) {
	//alert('in Password  matching');
    if ((eid.value != '' && confirmEid.value != '') && (eid.value.length == confirmEid.value.length)) {

       // if((eid.value.length >= 6) && (eid.value.length <= 15)){

            for(var i = 0; i < eid.value.length; i++) {

                var myCharP = eid.value.charAt(i);
                var myCharC = confirmEid.value.charAt(i);

                /*if (	(myChar >= '0' && myChar <= '9')||
                    (myChar >= 'a' && myChar <= 'z')||
                    (myChar >= 'A' && myChar <= 'Z')||
                     myChar == '_') {
                } */
                if(myCharP == myCharC){
                } else {
                    alert("Email ID and confirm Email ID are not matching");
                    /*eid.value = "";
                    confirmEid.value = "";*/
                    eid.focus();
                    return false;
                }
            }
       /* }else {
          alert('Password should be minimum of 6 and maximum of 15 characters');
          eid.value = "";
          confirmEid.value = "";
          eid.focus();
          return false;
        }*/
     }else {
          alert('Email ID and confirm Email ID are not matching');
          /*eid.value = "";
          confirmEid.value = "";*/
          eid.focus();
          return false;
	 }
   return true;
};

function validatePinCode(fieldName,country) {
	//alert("Inside validatePinCode   fieldName.value="+fieldName.value+" country.value"+country.value);
	if (fieldName.value != '' && country.value == 'India') {
	    if(fieldName.value.length != 6){
             alert('Invalid Pin Code pls check');
             return false;
          }
	} 
	//alert("Everything is ok!!!!");
return true;
};

function isAgeAllowed(THISDATE) {
	var birthDt = THISDATE;
	var currDt = getCurrentSystemDateInStringFormat();
	//alert("currDt----"+currDt);
	if(birthDt == null || birthDt == "" || birthDt == " "){
		alert('Please enter the Birth Date date.');
		return false;
	}
//	alert("isDt1GreaterThanOrEqualToDt2(currDt,birthDt)"+isDt1GreaterThanOrEqualToDt2(currDt,birthDt));
	if (!isDt1GreaterThanOrEqualToDt2(currDt,birthDt)) {
			alert("Invalid Birth Date.");
			return false;			
		}
	var diff = eval(currDt.substring(7)- birthDt.substring(7));
	var mon;
	if(diff < 15){
		return confirm("The Age is less than 15 years . Do you want to continue");
	}else if(diff == 15){
		mon = isMon1SameAsOrAfterMon2(currDt.substring(3, 6),
							birthDt.substring(3, 6));
			if(mon == 0){
				if(birthDt.substring(0,2) > currDt.substring(0,2)){
				return confirm("The Age is less than 15 years . Do you want to continue");
				}else 
					return true;
			}else if(mon == -1){
				return confirm("The Age is less than 15 years . Do you want to continue");
			}else
				return true;

	}
	if(diff > 90){
			return confirm("The Age is greater than 90 years . Do you want to continue");
	}else if(diff== 90){
		mon = isMon1SameAsOrAfterMon2(currDt.substring(3, 6),
							birthDt.substring(3, 6));
			if(mon == 0){
				if(birthDt.substring(0,2) < currDt.substring(0,2)){
				return confirm("The Age is greater than 90 years . Do you want to continue");
				}else 
					return true;
			}else if(mon == 1){
				return confirm("The Age is greater than 90 years . Do you want to continue");
			}else
				return true;
	}
	return true;
/*        a=THISDATE;
        //alert(a);
        f = a.substring(7, 11)// year 
//        alert(f);
        if (f>1990) {
            alert("SORRY U are not allowed to Register with NCFM. For Registration U should be atleast 15 years old");
            return false;
        }
      return true;*/
	}//End of isAgeAllowed.


function LeapYear(intYear) {
if (intYear % 100 == 0) {
if (intYear % 400 == 0) { return true; }
}
else {
if ((intYear % 4) == 0) { return true; }
}
return false;
}

function doDateCheck(from, to) {
if (Date.parse(from) <= Date.parse(to)) {
//alert("The dates are valid.");
return true; ///////  09-DEc-2004
}
else {
if (from == "")
alert("From date must be entered.");
else
alert("To date must occur after the from date.");
return false;
   }
}

function checkdate(objName,msg) {
var datefield = objName;
if (chkdate(objName) == false) {
//datefield.select();
alert(msg+" is invalid.  Please check.");
//datefield.focus();
return false;
}
else {
return true;
   }
}
function chkdate(objName) {
//var strDatestyle = "US"; //United States date style
var strDatestyle = "EU";  //European date style
var strDate;
var strDateArray;
var strDay;
var strMonth;
var strYear;
var intday;
var intMonth;
var intYear;
var booFound = false;
var datefield = objName;
var strSeparatorArray = new Array("-"," ","/",".");
var intElementNr;
var err = 0;
var strMonthArray = new Array(12);
strMonthArray[0] = "Jan";
strMonthArray[1] = "Feb";
strMonthArray[2] = "Mar";
strMonthArray[3] = "Apr";
strMonthArray[4] = "May";
strMonthArray[5] = "Jun";
strMonthArray[6] = "Jul";
strMonthArray[7] = "Aug";
strMonthArray[8] = "Sep";
strMonthArray[9] = "Oct";
strMonthArray[10] = "Nov";
strMonthArray[11] = "Dec";
strDate = datefield;
if (strDate.length < 1) {
return true;
}
for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
strDateArray = strDate.split(strSeparatorArray[intElementNr]);
if (strDateArray.length != 3) {
err = 1;
return false;
}
else {
strDay = strDateArray[0];
strMonth = strDateArray[1];
strYear = strDateArray[2];
}
booFound = true;
   }
}
if (booFound == false) {
if (strDate.length>5) {
strDay = strDate.substr(0, 2);
strMonth = strDate.substr(2, 2);
strYear = strDate.substr(4);
   }
}
if (strYear.length == 2) {
strYear = '20' + strYear;
}
// US style
if (strDatestyle == "US") {
strTemp = strDay;
strDay = strMonth;
strMonth = strTemp;
}
intday = parseInt(strDay, 10);
if (isNaN(intday)) {
err = 2;
return false;
}
intMonth = parseInt(strMonth, 10);
if (isNaN(intMonth)) {
for (i = 0;i<12;i++) {
if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
intMonth = i+1;
strMonth = strMonthArray[i];
i = 12;
   }
}
if (isNaN(intMonth)) {
err = 3;
return false;
   }
}
intYear = parseInt(strYear, 10);
if (isNaN(intYear)) {
err = 4;
return false;
}
if (intMonth>12 || intMonth<1) {
err = 5;
return false;
}
if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
err = 6;
return false;
}
if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
err = 7;
return false;
}
if (intMonth == 2) {
if (intday < 1) {
err = 8;
return false;
}
if (LeapYear(intYear) == true) {
if (intday > 29) {
err = 9;
return false;
}
}
else {
if (intday > 28) {
err = 10;
return false;
}
}
}
if (strDatestyle == "US") {
datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
}
else {
        if(intday < 10){
        datefield.value = "0" + intday + " " + strMonthArray[intMonth-1] + " " + strYear;
        }
        else{
        datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear;
        }

}
return true;
}

function validateCharForCertName(fieldName) {

	if (fieldName.value != '') {
		for(var i = 0; i < fieldName.value.length; i++) {
		var myChar = fieldName.value.charAt(i);

		if ((myChar >= "a" && myChar <= "z") ||
				    (myChar >= "A" && myChar <= "Z") ||
				    myChar == ' ' || myChar == '.' || myChar == '\'') {

		} else {

			alert('Invalid Name to be Printed on Certificate : Valid characters are a-z, A-Z, space, dot and apostrophe');
			fieldName.focus();
			return false;
			}
		}
	}
	return true;
};

function showPrefTstCntrs () {

var prefTstCntr  ='';

		prefTstCntr  +='<option value="Allahabad -  Civil Lines">Allahabad -  Civil Lines</option>';
		prefTstCntr  +='<option value="Amritsar -  The Mall">Amritsar -  The Mall</option>';
		prefTstCntr  +='<option value="Bangalore - Malleshwaram">Bangalore - Malleshwaram</option>';
		prefTstCntr  +='<option value="Baroda - Meghdhanush">Baroda - Meghdhanush</option>';
		prefTstCntr  +='<option value="Bhubneshwar - Fortune Towers">Bhubneshwar - Fortune Towers</option>';
		prefTstCntr  +='<option value="Chandigarh - Sector 9 D">Chandigarh - Sector 9 D</option>';
		prefTstCntr  +='<option value="Cochin - Palarivattom">Cochin - Palarivattom</option>';
		prefTstCntr  +='<option value="Coimbatore - Gandhipuram">Coimbatore - Gandhipuram</option>';
		prefTstCntr  +='<option value="Gandhinagar - Sector 11">Gandhinagar - Sector 11</option>';
		prefTstCntr  +='<option value="Goa - Miramar">Goa - Miramar</option>';
		prefTstCntr  +='<option value="Hubli - Hubli">Hubli - Hubli</option>';
		prefTstCntr  +='<option value="Hyderbad - Himayatnagar">Hyderbad - Himayatnagar</option>';
		prefTstCntr  +='<option value="Jaipur - Vaishali Nagar">Jaipur - Vaishali Nagar</option>';
		prefTstCntr  +='<option value="Jamnagar - Shivam Apartment">Jamnagar - Shivam Apartment</option>';		
		prefTstCntr  +='<option value="Kanpur - Mall Road">Kanpur - Mall Road</option>';
		prefTstCntr  +='<option value="Lucknow - Tulsi,Hajaratganj">Lucknow - Tulsi,Hajaratganj</option>';
		prefTstCntr  +='<option value="Ludhiana - Mall Road">Ludhiana - Mall Road</option>';
		prefTstCntr  +='<option value="Mangalore - Bunts Hostel Circle">Mangalore - Bunts Hostel Circle</option>';
		prefTstCntr  +='<option value="Nashik - Sharanpur Road">Nashik - Sharanpur Road</option>';
		prefTstCntr  +='<option value="NSE Office - Mumbai">NSE Office - Mumbai</option>';
		prefTstCntr  +='<option value="NSE Office - Kolkata">NSE Office - Kolkata</option>';
		prefTstCntr  +='<option value="NSE Office - Delhi">NSE Office - Delhi</option>';
		prefTstCntr  +='<option value="NSE Office - Ahmedabad">NSE Office - Ahmedabad</option>';
		prefTstCntr  +='<option value="NSE Office - Chennai">NSE Office - Chennai</option>';
		prefTstCntr  +='<option value="NSE Office - Hyderabad">NSE Office - Hyderabad</option>';		
		prefTstCntr  +='<option value="Patna -  Fraser Road">Patna -  Fraser Road</option>';
		prefTstCntr  +='<option value="Pune - Dhole Patil Raod">Pune - Dhole Patil Raod</option>';
		prefTstCntr  +='<option value="Pune - F C Raod">Pune - F C Raod</option>';
		prefTstCntr  +='<option value="Raipur - Krishna Complex">Raipur - Krishna Complex</option>';
		prefTstCntr  +='<option value="Salem - Agraharam">Salem - Agraharam</option>';
		prefTstCntr  +='<option value="Surat - Parle Point">Surat - Parle Point</option>';
		prefTstCntr  +='<option value="Trichure - Sun Tower Thrissur">Trichure - Sun Tower Thrissur</option>';
		prefTstCntr  +='<option value="Trichy - Thillainagar">Trichy - Thillainagar</option>';
		prefTstCntr  +='<option value="Udaipur - Udaipur">Udaipur - Udaipur</option>';
		prefTstCntr  +='<option value="Vijaywada - Surya Towers">Vijaywada - Surya Towers</option>';
		prefTstCntr  +='<option value="Vizag - Dwarakanagar">Vizag - Dwarakanagar</option>';
		prefTstCntr  +='<option value="Others">Others</option>';
		prefTstCntr  +='<option value="Outside India">Outside India</option>';
		prefTstCntr  +='<option value="Mauritius - Port Louis">Mauritius - Port Louis</option>';
//Dwarakanagar</option>';

document.write(prefTstCntr);
};
