/******************************************************************************
		File Name	: globalValidator.js		
		Track		: FRAMEWORK
		Functional	: GLOBAL
		Description : Javascript Validation functions used GLOBALLY
		Function List:	function getLabel(elem)
						function alertMe()
						function formulateMessage(msg, argsArr)
						function getOccurences(str, charac)
						function getErrorMessage(errCode)
						function parseFunctionName(func)
						function preValidate(inputForm) 
						function validateForm(thisForm)
						function enableAllFields(frm) 
						function isDataComplete(field) 
						function isAlphaNumericSpecialChar()
						function isAlphaNum()
						function isDigit (c)  
						function isInteger (s)   
						function isCaseNum(field)
						function isAlphaChar(c)
						function isAlphaNumericData(field,val)
						function isNumberValid(char,num,field)
						function isOptionExists(elem, val)
						function doTrim(val) 
						function handleEnterKey()
						function advance(thisField, nextField) 
						function formatDate(field1, field2, field3, targetField)
						function getMonthNumber(month) 
						function clearMonthDayYear(field) 
						function openPopupWindow(theURL,winName,features)  //v2.0
						function setFocus(field)
						function doSubmit(formName, field, val) 
						function submitForm(formId)
						function doReset(formName)
						function setSelectFlag() 
						function setSelectFlagFalse()
						function doAddAll(from,to) 
						function doRemoveAll(from) 
						function doSelectAll(from) 
						function rowsRemove(from) 
						function rowsMove(doc,from,to,decide) 
						function addList(txt, val, listObj)
						function toCaps(field) 
						function trimSpaces(obj)
						function CompareAlpha(a, b) 
						function CompareAlphaIgnore(a, b) 
						function CompareDate(a, b) 
						function CompareDateEuro(a, b) 
						function CompareNumeric(a, b) 
						function changeImage(table,colNo)
						function sortTable(table,colNo)
						function refreshSort(table)
						function sortData(table,colNo,dataType,isSortDesc)
						function changeImageById(table,tableNo,colNo)
						function sortTableById(table,tableNo,colNo)
						function openCloseWindow() 
						function setLogout()
						function validateMailingAddr(thisForm) 
						function setActionAndSubmit(frm,value)
						function disableElements(flag,oids)
						function disableMailAddr(combo,thisForm)    
						function disableFieldsOnSpace()						
						function disableFieldsOnYes()
						function disableFieldsOnNo()						
						function enableFields()
						function enableFieldsOnSpace()
						function enableFieldsOnYes()
						function enableFieldsOnNo()
						function clearFields()
						function checkboxCount(field, size)
						function getRadioButtonValue (radio)   
						function displayMessages(errorMessage,message) 
						function resetElement(elem) 
						function runValidations(thisForm)
						function setActionFieldAndSubmit(frm,value,validate)   
						function setRequestedPageIdAndSubmit(frm,value,validate)   
						function initScrollTable(oElement) 
						function resizeScrollTable(oElement) 
						function setTarget(form1)
						function showPageHelp()
						function openModalDialog(URL,winName,features)
						function closeWarning(fieldName) 
						function loginWarning(frm,action,validateFlag) 
						function reformattime(time) 
						function setFieldValue(field,val)
						function selVal(selfield,hidCombo1,filteredCombo,hidCombo2)
						function clearMessages()
						function cancelLink ()
						function disableTabs(tab)
						function enableTabs(tab)
						function getLinkByID(tab)
						function getListText(valu,selobj)
						function resetInnerHTML()
						function disableAddr()
						function getToday()
						function textAreaEnter()
						function textAreaBreak(tArea)
						function replaceTilda(tArea)
						function validateDates(month,day,year)
						function createErrorMessages(month,day,year)
						function checkZip(field)
						function formDate(aDate,aTime,tgt)
						function setFocusOnFirstField()
						function deSelectAll(selObj)
						function getDefaultValues(elem)
						function initiateListCascade(trigElemId, refElemId, setElemId, refArr, emptySpace)
						function doListCascade(valArr, refObj, setObj,emptySpace)
						function getArrayValue(arrObj,arrKey)
						function setCheckBoxValue(selectedCheckbox)
						function getElementValueOrValue(elem)
						function preValidateElements(elemIDArray)
						function validateElements(elemIDArray)
						function prepareElementRequestParams(elementIds)
						function prepareFormRequestParams(frm)
						function isEachElementEqualsEachValue(elemIdArr, valArr)
						function isAnyElementEqualsValue(elemIdArr, val)
						function isElementEqualsAnyValue(elemId, valArr)
						function setFormTarget(frm,val)
						function setAllFirstCaps(frmObj)
						function setTable(tabId)
						function isGroupChecked(grpElem, chkNum)
						function setDateValue(beanId, dateVal)
						function jsForTabsNoValidate()
						function jsForTabs()
						function setSelected(combo,val)
						function isCompleteForm(thisfrm)
						function getMandatoryFields(frm)
						function getElementValidations(elem)
						function addtoUniqueElementArray(arrObj,valtoAdd)
						function getElementLabels(aErrElemIds)
						function getElementFormName(frm)
						function enableDisableImage(flag,img)
						function hideImages(oids,flag)
						function isNumeric(field)
						function isEmail(field)
						function isComplete(field)   
						function isAlphaNumeric(field) 
						function isStrictlyAlphaNumeric(field) 
						function isAlpha(field) 
						function isFraction(field)
						function isMaxSet(field)
						function isCurrency(FieldName)
						function isValidNumber(char,num,label,field)
						function isAtleastOneComplete() 
						function isOneComplete(field1,field2,label1,label2)
						function joinFields(field1, field2, field3, targetField)
						function joinFourFields(field1, field2, field3,field4, targetField)
						function mergetime(hours,minutes,ampm,newlocation) 						
						function joinZip(field1, field2)
						function validateName(field)
						function isDateComplete(month,date,year)						
						function validateDate(month,day,year)
						function validateMonth(month) 
						function validateDay(day) 
						function validateYear(year) 
						function createErrorMessage(month,day,year) 
						function pastDate(month, day, year, targetField,dateString)
						function pastDateInclusive(month, day, year, targetField,dateString)
						function futureDate(month, day, year, targetField,dateString)
						function compareDates(month1, day1, year1,month2,day2,year2,targetField,dateString1,dateString2)
						function compareDatesInclusive(month1, day1, year1,month2,day2,year2,targetField,dateString1,dateString2)
						function openHelpWindow()
						function doAdd(from,to,msg) 
						function doRemove(from) 
						function flZero(field)
						function noSpace(field)
						function edgNumValidator(fieldName)
						function caseNumValidator(fieldName)
						function checkMaxLength(FieldName,maxLimit) 
						function comparetime(t1, t2) 
						function isZero(field)
						function textToList(txtobj, selobj)
						function checkSpecialChars(FieldName,maxLength,validChars,enter)
						function chkAddress(str,frac,dir,stname,sttype,dweltype,dwelnum,adline2,county,city,state,country,zip5,region)
						function validateListSize(list,num)  
						function checkMaxAllowed(field,maxVal)
						function confirmEntry(field1,field2)
						function loadURL(frm,url,tgt)
						function chkAddrLine2(StrNum,StrName,AddrLine2,flag)
						function computeAge(mm, dd, yy,num)
						function validateSSCN(field)
						function preventSpecialChars(FieldName,maxLength,inValidChars,enter)
						function validateSSN(fld)
						function isTimeComplete(hr,mn,ampm,tgt)
						function isDecimal(field,dec,maxVal)
						function isCompleteFields(elemIdArr,lOperator)
						function isNumeric(field)
						function isEmail(field)
						function isComplete(field)   
						function isAlphaNumeric(field) 
						function isStrictlyAlphaNumeric(field) 
						function isAlpha(field) 
						function isFraction(field)
						function isMaxSet(field)
						function isCurrency(FieldName)
						function isValidNumber(char,num,label,field)
						function isAtleastOneComplete() 
						function isOneComplete(field1,field2,label1,label2)
						function joinFields(field1, field2, field3, targetField)
						function joinFourFields(field1, field2, field3,field4, targetField)
						function mergetime(hours,minutes,ampm,newlocation) 						
						function joinZip(field1, field2)
						function validateName(field)
						function isDateComplete(month,date,year)						
						function validateDate(month,day,year)
						function validateMonth(month) 
						function validateDay(day) 
						function validateYear(year) 
						function createErrorMessage(month,day,year) 
						function pastDate(month, day, year, targetField,dateString)
						function pastDateInclusive(month, day, year, targetField,dateString)
						function futureDate(month, day, year, targetField,dateString)
						function compareDates(month1, day1, year1,month2,day2,year2,targetField,dateString1,dateString2)
						function compareDatesInclusive(month1, day1, year1,month2,day2,year2,targetField,dateString1,dateString2)
						function openHelpWindow()
						function doAdd(from,to,msg) 
						function doRemove(from) 
						function flZero(field)
						function noSpace(field)
						function edgNumValidator(fieldName)
						function caseNumValidator(fieldName)
						function checkMaxLength(FieldName,maxLimit) 
						function comparetime(t1, t2) 
						function isZero(field)
						function textToList(txtobj, selobj)
						function checkSpecialChars(FieldName,maxLength,validChars,enter)
						function chkAddress(str,frac,dir,stname,sttype,dweltype,dwelnum,adline2,county,city,state,country,zip5,region)
						function validateListSize(list,num)  
						function checkMaxAllowed(field,maxVal)
						function confirmEntry(field1,field2)
						function loadURL(frm,url,tgt)
						function chkAddrLine2(StrNum,StrName,AddrLine2,flag)
						function computeAge(mm, dd, yy,num)
						function validateSSCN(field)
						function preventSpecialChars(FieldName,maxLength,inValidChars,enter)
						function validateSSN(fld)
						function isTimeComplete(hr,mn,ampm,tgt)
						function isDecimal(field,dec,maxVal)
						function isCompleteFields(elemIdArr,lOperator)
						filterValues(selfield,obj1,obj2,obj3)
						isCompleteConditionally(depField,depValue,targetField)
						isNumericConditionally(depField,depValue,targetField)
						validateEmail(depField, depValue, field)
						function isStreetNumber(field)
						function isStreetNumberConditionally(field)												
/****************************************************************************************/

/****************************************************************************************/
var isValidateON = false;			//Global flag that denotes whether validateForm is ON or OFF
var validationErrors = new Array();	//Global Array that holds all the error messages during submit validations
var glInnerHTMLArray = new Array(); //GLobal Array that holds the values of innerHTMLs
var glInnerHTMLIDArray = new Array();//GLobal Array that holds the values of innerHTML IDs
var overrideResults = false;//Global value that will be set to true when user clicks on Override Results in Eligibility screens
var dateVal = false;
var selectFlag=false;
var loginwarn = true;
var frmTarget = "";//Global variable to capture the target of the form
var enterKey = false;
var m = "";//Variable to store the value of the name of the date field.
/*****************************************************************************************/
function getLabel(elem){
	if(elem.type==null||elem.type=="undefined"){
		return elem;
	}
	else{
		var lbl="";
		var lblname = elem.lblDesc;
		if(lblname==null||lbl=="undefined"){
			lbl = elem.name;
		}
		else{
			lbl = lblname;
		}
		return lbl;
	}
}

function alertMe(){
	var args = alertMe.arguments;
	var errMsg = getErrorMessage(args[0]);
	if(errMsg.indexOf("~")>=0){
		var msg = formulateMessage(errMsg, args);
		errMsg = msg;
	}		
	if(args[0]==errMsg){		
		//If the call does not contain any Error code or if
		// the error code is not defined.
		var tmp = "Error Code Not Defined "+args[0];
			if(isValidateON){
				validationErrors.push(tmp);		
			}else{
				displayMessages(tmp," ");
			}	
	}
	else{
		if(isValidateON){
			validationErrors.push(args[0]+": "+errMsg);		
		}else{
			displayMessages(args[0]+": "+errMsg," ");
		}	
	}
	return true;
}

function formulateMessage(msg, argsArr){
	if(argsArr.length<=1){
		return msg;
	}
	else{
		var plHold = getOccurences(msg,'~');
		var argsLen = parseInt(argsArr.length,10);
		var plArgsLen = argsLen-1;
		var valn1 = (plArgsLen==plHold);
		if(valn1){
			var retMsg = "";
			var cnt=1;
			for(k=0;k<msg.length;k++){
				if(msg.charAt(k)=='~'){
					var lbl = getLabel(argsArr[cnt]);
					retMsg=retMsg+lbl;
					cnt = cnt+1;
				}
				else{
					retMsg = retMsg+msg.charAt(k);
				}
			}
			return retMsg;
		}
		else {			
			return msg;
		}
	}
}

function getOccurences(str, charac){
	var cnnt = 0;
	for(h=0;h<str.length;h++){
		if(str.charAt(h)==charac){
			cnnt = cnnt+1;
		}
	}
	return cnnt;
}


function getErrorMessage(errCode){
	var errArray;
	var desc = errCode;
	var temp = errCode.substring(0,1);
	temp = temp.toLowerCase();
	try{
		errArray = eval(temp+"ErrorCodes");
	}catch(e){
		return errCode;
	}		
	for(j=0;j<errArray.length;j++){
		if(errArray[j][0]==errCode){
			desc = errArray[j][1];
			break;
		}
	}
	return desc;
}

function parseFunctionName(func){
	if(func.indexOf("~")>=0){//Specially for DC
		pos0 = 0;
		pos1 = func.indexOf("(");
		pos2 = func.indexOf("~");
		temp1 = func.substring(0,pos1+1);
		temp2 = func.substring(pos2+1,func.length);
		temp = temp1+temp2;		
		return temp;
	}
	else{	// Standard calls
		return func;
	}
}


/*
 * This function is used to submit the form if there are no client side errors
 * If you do not want this function to submit the form pass the form and  0 
 * ie., preValidate(frm,0)
 */


function preValidate(inputForm) {
	messageArray = new Array();
	messageString = "";
	var args = preValidate.arguments;		
	var ret = validateForm(inputForm);
	len = validationErrors.length;
	if(ret)  {		    
		if(args.length>1&&args[1]==0){
			return true;
		}		
		clearMessages();
		enableAllFields(inputForm);
		//inputForm.method = "POST";
	  //  inputForm.submit();
	   // return false;
	}
	else 
	{
		var num = inputForm.length;	
		for(var i = 0; i<num; i++){
			var field = inputForm.elements[i];
			var name = field.name;
			var aType = field.type;
			if(aType == "textarea"){
				replaceTilda(field);
			}
		}
	  	if(len>0) {
	  	  for(i=0;i<len;i++)  {	        
		      messageArray.push(validationErrors[i]);
			}
			errorString = messageArray.join("<br>");
						
			displayMessages(errorString," ");
	   	}	 
	    return false;
	}
}

/*
 * This function is used to validate the client side errors
 */

function validateForm(thisForm){
	var num = thisForm.length;	
	isValidateON = true;
	validationErrors = new Array();
	var chek = true;	
	var doValidate = true;
	var ret;
	for(var i = 0; i<num; i++){
		var field = thisForm.elements[i];
		var name = field.name;
		var validate=field.validate;
		var refQuestionId = field.REFQUESTIONID;	
		
		
		if((refQuestionId !=null) && (refQuestionId!="undefined")&&(refQuestionId!="null") ){
			for(var j=0;j<num;j++){
				var tempField = thisForm.elements[j];
				var tempName = tempField.name;
				if(tempName == refQuestionId){					
					break;
				}
			}
			
			if(tempField.value != 'Y'){				
				doValidate = false; 	
			}
		}
		if ((validate !=null) && (validate!="undefined")&&(validate!="null") && doValidate){									
			var startPos;
			do{
				startPos=0;
				var fun;
				var endPos=validate.indexOf(";");
				if(endPos > 0){
					fun=validate.substring(startPos,endPos);				
					startPos=endPos+1;
					validate=validate.substring(startPos,validate.length);						
				}else{
					fun=validate;
				}
				var spcs = doTrim(fun);		
				if(spcs!=null&&spcs!="null"&&spcs!=""){
					var netfunc = parseFunctionName(fun);						
					//dummy alert method written here...........................................................................
					ret=eval(netfunc);				
					if(ret!=null&&ret!="null"&&ret!="undefined"&&!ret) {						
						chek = false;
					}// 
				}								
			}while(endPos != -1);
		}
	}
	isValidateON = false;		
	return chek;
  }
//This function is used if certian fields have been disabled on the page and the name/value pair has to sent to the server side.
function  enableAllFields(frm) {
	if(overrideResults == true) 
	{
	}
	else
	{
		for(var i=0; i< frm.length; i++){
			frm.elements[i].disabled= false;
		}
	}
}

//Function added by Malathi on Jun 12, 2002
//Function to check for mandatory fields - without popping the alerts
function isDataComplete(field) {
	if(field.type =="radio" || field.type =="checkbox"){
   	 	if(field.checked == true){
   	 		return true;
   	 	}
   	 	else return false;
   	}
	else
	{
    var val = field.value;  
    var thisval = null;
    if (val!=null) {
	   var vallen= val.length;
	   thisval = doTrim(val);	
	   if (thisval== null) {
	     thisvallen = 0;
	   } else {thisvallen = thisval.length;}
	   if (vallen >0 & thisvallen<=0) {	      
	     return false;
	   }
	} else {
		thisval = val;
	}
   if (thisval==null || thisval.length<=0) {
      return false; 
   }
   return true;
   }
}

//Function added by Malathi on May 17, 2002
//This function takes 2 arguments - first is a field name and the next is a 'SpecialChar'
//Checks to see that the value entered is AlphaNumeric or 'SpecialChar'
function isAlphaNumericSpecialChar(){
	var val = arguments[0].value;
	var specialChar = arguments[1];
	for (var i = 0; i < val.length; i++) {
		var ch = val.substring(i, i + 1);
		if (ch != specialChar && !isAlphaNum(ch,arguments[1])){
			//arguments[0].focus();
			return false;
		}
	}
}

/*
Function added by Malathi on May 17, 2002
This function takes 2 arguments - first is a 'SingleChar' and the next is a 'SpecialChar'
Checks to see that the char entered is AlphaNumeric or 'SpecialChar'
Function is called by isAlphaNumericSpecialChar()
*/
function isAlphaNum(){
	var val = arguments[0];
	if(val < "0" || val > "9"){
		if (val < "a" || val > "z"){
			if (val < "A" || val > "Z"){
				return false;
			}
   		}
   	}
   	return true;
}	

/*
Function to check if the given character is a Digit or not
param1		: the character that needs to be checked.
returns		:  true  - if it is a Digit
			   false - if it is not a digit
Function added by Malathi for Ram on May 31, 2002				   
*/
	function isDigit (c){  
		return ((c >= "0") && (c <= "9"))
	}
	
/*
Function to Return true if all characters in string s are numbers.
param1		: The String that needs to be validated
returns		: true -if value contains only numbers;
			  false -if a non-numeric charecter is found.
Function added by Malathi for Ram on May 31, 2002				   
*/
	function isInteger (s){   
		
		for (i = 0; i < s.length; i++)
		{           
			var c = s.charAt(i);
			if (!isDigit(c)) return false;
		}
	    
		return true;
	}


/*
Function to check if the given value is a valid Case Number
param1		: The txt value that needs to be validated
returns		: boolean
Function added by Malathi for Ram on May 31, 2002	
Function modified by Malathi on Jun 5, 2002			   
*/
function isCaseNum(field){
	txt = field.value;
	var intCaseNum =0;
	var caseNumber = field.value; 
	if (isInteger(field.value) ){
		//intCaseNum = parseInt(caseNumber);
		intCaseNum = parseInt(caseNumber,10);//Modified by Malathi - to set base 10
		if(intCaseNum < 1 || caseNumber.length > 10){				
			return false;
		}
	}
	else{
		return false;
	}	
	return true;//Added by Malathi on Jun 5, 2002	
}	

/*Function added by Malathi on Jun 5, 2002
//Function checks if the char passed is a Capital Alpha char
//Functions name changed from isAlphaCaps(c) to isAlphaChar(c)
*/
function isAlphaChar(c){
	 return ((c >= "A" && c <= "Z") || (c >= "a" && c <= "z"))
}

//Function to check if the given value is Alphanumeric
function isAlphaNumericData(field,val) {
  	var rep2 = /[A-Za-z0-9]+([a-z]|[0-9])*\s*[A-Za-z0-9]*/;
  	var rep = /[^A-Za-z0-9\s]+/;
  	var test = val.match(rep);
  	var test2 = val.match(rep2);
  	var leng = val.length;

	/*for(var i=0;i<leng;i++){
		if(val.charAt(0)== " "){
  	    	val= val.substring(1);
  	    }
  	}*/
  	field.value=val;
	if ((test == null) && (test2!=null) && (val.charAt(0)!= " ") && val.charAt(leng-1) !== " ") {       
		return true; 
  	} else { 
    	return false;
  	}
}


//Function isValidNumber split to 2 functions isValidNumber() and isNumberValid() by Malathi on Jun11, 2002
//This is done to handle situations where alert is not required
//Changed function isAlphaCaps() to isAlphaChar()
function isNumberValid(char,num,field){
		txt = field.value;
		if(txt == null || txt == "") return true;
		
		var apptxt;
		var firstChar = txt.charAt(0);
		var secondChar = txt.charAt(1);
		var flag;
		var flag1=false;
		
		if(char=="2Alpha"){
			apptxt = txt.substring(2,txt.length);
		}
		else
		{
			apptxt = txt.substring(1,txt.length);
		}
		
		if(char=="0Alpha"){
			flag = ((txt.length==num)&& isInteger(txt));                 
		}
		else if(char=="Alpha"){
			flag = (isAlphaChar(firstChar) && (txt.length==num+1)&& isInteger(apptxt));                 
		}
		else if(char=="2Alpha"){
			flag= (isAlphaChar(firstChar) && isAlphaChar(secondChar) && (txt.length==num+2) && isInteger(apptxt));	
		}
		else if(char=="6Alpha"){
			var a = txt.substring(0,3);
			var b = txt.substring(6);
			var c = a+b;
			var d = txt.charAt(3);
			var e = txt.charAt(4);
			var f = txt.charAt(5);
			flag= (isAlphaNum(d) && isAlphaNum(e) && isAlphaNum(f) && (txt.length==num) && isInteger(c));	
	}

		else
		{
			flag= ((firstChar==char)&&(txt.length==num+1)&&isInteger(apptxt));	
		}
		
		if(!flag)
		{
			return false;
		}
		else{
			return true;
		}
}

/********************************************************************************
	*	Name		: isOptionExists()
	*	author		: Ramkishan Sadasivam
	*	Created Dt	: May,30 2002	
	*	Modified Dt	: 
	*	Description : Function to check if the Option already exists in the List Box
	*	param1		: The List Box Object which has to be checked 
	*	param2		: The value that needs to be checked for existence(duplication)
	*	returns		:  boolean
	*   Moved from sh.js by Malathi on Sep 11, 2002 for Krishna
*************************************************************************************/
	function isOptionExists(elem, val){		
		for(i=0;i<elem.length;i++)	{
			v = elem.options[i].value;		
			if(v==val)		{
				return true;
			}			
		}
		return false;
	}

//Trims the spaces from the value being sent
function doTrim(val) {
	var len = val.length;
	var result = null;
   	for (var i=0;i<len;i++) {
   	var curchar = val.charAt(i);
		if (curchar!=" ") {
	   		if (result == null) {
	     		result = curchar;
	   		} else {
	     		result = result + curchar;
	   		}
	 	}
   	}
   return result;
}

/* The following method is added to provide the functionality for submitting the form 
   when Enter key is pressed.
*/ 
function handleEnterKey(){
	if(event.keyCode==13){
		//var coll = document.all.tags("input");
		var inp = document.getElementsByTagName("INPUT");
		if (inp!=null) {
	    	for (i=0; i<inp.length; i++) {
  		    	if ( inp[i].name.toUpperCase() == "SUBMIT")  {
		  			inp[i].click();
					break;
			    }
			}
		}
		return false;
 	}
   	return true;
}

/* Calling this method from the onKeyUp event select the nextField as soon as the user enters the final character in this
// field, however shift+tab is disabled.  Calling it from onKeyPress selects the nextField after the user exceeds the 
//	maxLength attribute.
*/ 

function advance(thisField, nextField) {
	var val = thisField.value;
	val=val.toLowerCase();
  	var code=event.keyCode;    	
	var length = thisField.value.length;
	var maxxed = thisField.maxLength;
  
  	if(code==16 || code==9 || code==37 || code==39 || code==8) return;
  	if (selectFlag && (val=="mm" || val=="dd" || val=="yyyy")) {
		thisField.value = '';
		setFocus(thisField);
		selectFlag=false;
		return;
	}
	if(length==maxxed){
		if(val =="mm" || val=="dd" || val=="yyyy"){
		} else {
			setFocus(nextField);
			nextField.select();
			selectFlag=false;
		}	
		//clearMonthDayYear(nextField);
	}
}	

// This function formats a date (passed as three fields) into one hidden field using the format "yyyy-mm-dd"
//and also validates the date
//Function modified by Malathi for Raji on Jun 6, 2002 - for handling situations where the date field will not be displayed
function formatDate(field1, field2, field3, targetField){
	var value1 = field1.value;
	var value2 = field2.value;
	var value3 = field3.value;
	if((value1 == null || value1 == "") || (value2 == null || value2 == "") || (value3 == null || value3 == "")){
  	  		alertMe("M0013",field1);
  	  		return false;
	}
	if( (value1 == "mm" || value1 == "MM") && (!(value2 == "dd" || value2 == "DD" || value2 == "disableDay") && !(value3 == "yyyy" || value3 == "YYYY"))){
  	  		alertMe("M0013",field1);
  	  		return false;
	}
	if( (value2 == "dd" || value2 == "DD") && (!(value1 == "mm" || value1 == "MM") && !(value3 == "yyyy" || value3 == "YYYY"))){
  	  		alertMe("M0013",field1);
  	  		return false;
	}
	if( (value3 == "yyyy" || value3 == "YYYY") && (!(value2 == "dd" || value2 == "DD" || value2 == "disableDay") && !(value1 == "mm" || value1 == "MM"))){
  	  		alertMe("M0013",field1);
  	  		return false;
	}
	if( (value1 != "mm" && value1 != "MM") || (value2 != "dd" && value2 != "DD" && value2 != "disableDay") || (value3 != "yyyy" && value3 != "YYYY")){
		if( (value1 == "mm" || value1 == "MM") || (value2 == "dd" || value2 == "DD" ) || (value3 == "yyyy" || value3 == "YYYY")){
  	  		alertMe("M0013",field1);
  	   		return false;
		}
	}
	for (i=0; i<value1.length; i++) {
  	  	var curchar = value1.charAt(i);
  	  	if(curchar == null || curchar == " " || curchar == "" || curchar == "-"){
  	  		alertMe("M0013",field1);
  	  		return false;
	   }
    }	
	
	for (i=0; i<value2.length; i++) {
  	   	var curchar = value2.charAt(i);
  	   	if(curchar == null || curchar == " " || curchar == "" || curchar == "-"){
  	  		alertMe("M0013",field1);
  	   		return false;
	    }
	}	
	for (i=0; i<value3.length; i++) {
  	   	var curchar = value3.charAt(i);
  	   	if(curchar == null || curchar == " " || curchar == "" || curchar == "-"){
  	  		alertMe("M0013",field1);
  	   		return false;
	    }
	}
	
	var args = formatDate.arguments;
	if((value1==null && value2==null && value3==null) || (value1=="mm" && (value2=="dd" ||value2=="disableDay") && value3=="yyyy") || (value1=="" && ( value2=="" || value2=="disableDay") && value3=="")){
		targetField.value="";
		return true;
	}
	if(value2=="disableDay") value2="01";
	if(validateDate(field1,field2,field3)==false) {
		if( (value1 != "mm" && value1 != "MM") || (value2 != "dd" && value2 != "DD" && value2 != "disableDay") || (value3 != "yyyy" && value3 != "YYYY")){
  			alertMe("M0013",field1);
  		}	
		return false;
	}	
	if(value1.length==1) value1 ="0"+value1;
	if(value2.length==1) value2 ="0"+value2;
	
	if(args.length > 4 && arguments[4]!= null && arguments[4] == "true"){
		targetField.value = value1+value2+value3;
	}
	else
	{
		targetField.value = value3+"-"+value1+"-"+value2;
	}
	return true;
}
//Added rvalluru on 12/15/2004 for defect number IER00003321 
//Date check for dependent question type is checkbox or radio button
function formatDateForCheckBox(field1, field2, field3, targetField){
	var value1 = field1.value;
	var value2 = field2.value;
	var value3 = field3.value;
	var args = formatDate.arguments;
	//if((value1==null && value2==null && value3==null) || (value1=="mm" && (value2=="dd" ||value2=="disableDay") && value3=="yyyy") || (value1=="" && ( value2=="" || value2=="disableDay") && value3=="")){
	//	targetField.value="";
	//	return true;
	//}
	if(value2=="disableDay") value2="01";
	if(validateDate(field1,field2,field3)==false) return false;
	if(value1 != null && value1.length==1) value1 ="0"+value1;
	if(value2 != null && value2.length==1) value2 ="0"+value2;
	
	if(args != null && args.length > 4 && arguments[4]!= null && arguments[4] == "true"){
		targetField.value = value1+value2+value3;
	}
	else
	{
		targetField.value = value3+"-"+value1+"-"+value2;
	}
	return true;
}
//End
//This function is used by function validateDate() to get the month numbers 
function getMonthNumber(month) {
	var retval = 0;
	if (month == "Jan") {
		retval = 1;
	} else if (month == "Feb") {
    	retval = 2;
	} else if (month == "Mar") {
    	retval = 3;
	} else if (month == "Apr") {
    	retval = 4;
	} else if (month == "May") {
    	retval = 5;
	} else if (month == "Jun") {
    	retval = 6;
	} else if (month == "Jul") {
    	retval = 7;
	} else if (month == "Aug") {
    	retval = 8;
	} else if (month == "Sep") {
    	retval = 9;
	} else if (month == "Oct") {
    	retval = 10;
	} else if (month == "Nov") {
    	retval = 11;
	} else if (month == "Dec") {
    	retval = 12;
	}
	return retval;
}

/* added by corey for Data Collection */
//Clears the field if it is a Date field
function clearMonthDayYear(field) {
	if(event.keyCode==8) return true;
 	var thisValue = field.value;
 	
 	//RAV
	if(selectFlag || thisValue=="mm" || thisValue=="dd" || thisValue=="yyyy"){
   		field.value = '';
   		selectFlag=false;
	}
	
	var len = thisValue.length;
	var maxlen = field.maxLength;
	//Modified by Ram , not to clear the year filed if user enter fifth character
	if(maxlen != 4) {
		if (len == maxlen)
		{
		   if(selectFlag && (thisValue=="mm" || thisValue=="dd" || thisValue=="yyyy")) {	
			 field.value = '';
		   }
		}
	}	
	
}

//Function used to open a pop up window - given the required parameters
//Function modified by Malathi for Prasad on Jun 21, 2002
function openPopupWindow(theURL,winName,features) { //v2.0
  var win = window.open(theURL,winName,features);
  return win;
}

//Function used to setFocus on a given field - returns true if the field is disabled - Comment added by Malathi Jun 21, 2002
function setFocus(field){
	if(field == "undefined") return;
	try{
		if(field.disabled) return;
			field.focus();
	}catch(e) {}
}

//Sets value to the field and then submits the form
function doSubmit(formName, field, val) {
	field.value = val;	
	return preValidate(formName);
}

//Function used to submit the form
//Function moved by Malathi on Jun 21, 2002 - from di.js
function submitForm(frm){
frm.method = "POST";
frm.submit();
}

//Resets the form
function doReset(formName){
	displayMessages(" "," ");
	resetInnerHTML();
	formName.reset();
	return false;
}

//Sets the value of 'selectFlag' to true
//In date fields if values mm/dd is available then it will clear the fields and not advance to the next field
function setSelectFlag() {
selectFlag=true;
}

//Function to set the selectFlag as false
function setSelectFlagFalse() {
selectFlag=false;
}

//Following 5 functions are used to validate moving the contents of one list box to another
//1. Function to add all the values from list1 to list2
function doAddAll(from,to,msg) {
  if(msg == null || msg == ""){
  	msg = 'add';
  }
  doSelectAll(from);
  doAdd(from,to,msg);
  return false;
}

//2. Function to remove all the values from listbox
function doRemoveAll(from) {
  doSelectAll(from);
  doRemove(from);
  return false;
}

//3. Function to select all the values in listbox
function doSelectAll(from) {
 for (var i=0;i<from.options.length;i++) {
    from[i].selected = true;
  }
}

//4. Function to remove the selected rows from listbox
function rowsRemove(from) {
	var objfrom = from;
  	for (var i=0;i<objfrom.options.length;i++) {
    	if (objfrom.options[i].selected) {
	  		objfrom.options[i] = null;
	  		i--;	  
		}	
  	}  
}

//5. Function to move the selected rows from list1 to list2
function rowsMove(doc,from,to,decide) {
	var objfrom = from;
  	var objto = to;
 
 	for (var i=0;i<objfrom.options.length;i++) {
    var toval,totext;
    var flag = false;
    	if (objfrom.options[i].selected) {
		var val = objfrom.options[i].value;
		var textval = objfrom.options[i].text;
			for (var j=0;j<objto.options.length;j++) {
	    	var toval = objto.options[j].value;
			var totext = objto.options[j].text;
				if (toval == val && totext == textval) {
		  			flag = true;
			  		break;
				}
	  		}	   
	  		if (!flag) {
	  			var newopt = new Option(textval,val)
	  			objto.options[objto.options.length] = newopt;
	  		}
		}
	}
	if (decide) {
		rowsRemove(from);
	}
}

//6. Function to move a text value to a list box
//Function added by Malathi from sh.js on Sep 17, 2002
function addList(txt, val, listObj){		
	n = listObj.length;			
	if(!isOptionExists(listObj, val)){					
		listObj.options[n] = new Option(txt,val);
		return true;
	}
	return false;
}

//7. Function to move a text value to a list box
//Function added by Malathi from sh.js on Sep 17, 2002
//Function modified, renamed to textToList and moved to globalErrors.js by Malathi on Sep 25, 2002
/*function addToList(txtobj, selobj){	
	trimSpaces(txtobj);
	if(isComplete(txtobj)){
		txt = txtobj.value;
		addList(txt, txt, selobj);
	}
	return false;
}
*/

	
//Function to convert the field value to Upper Case
function toCaps(field) {
	if(field!=null&&field.value!=null&&field.value!=""){
		field.value = (new String(field.value)).toUpperCase();
	}
}

//Function to remove the leading and trailing spaces
function trimSpaces(obj){
	while(''+obj.value.charAt(obj.value.length-1)==' ')obj.value=obj.value.substring(0,obj.value.length-1);
	while(''+obj.value.charAt(0)==' ')obj.value=obj.value.substring(1,obj.value.length);
}

// Sorting functions - start
currentCol = 0
previousCol = -1

function CompareAlpha(a, b) {
	if (a[currentCol] < b[currentCol]) { return -1; }
	if (a[currentCol] > b[currentCol]) { return 1; }
	return 0;
}

function CompareAlphaIgnore(a, b) {
	strA = a[currentCol].toLowerCase();
	strB = b[currentCol].toLowerCase();
	if (strA < strB) { return -1; }
	else {
		if (strA > strB) { return 1; }
		else { return 0; }
	}
}

function CompareDate(a, b) {
	datA = new Date(a[currentCol]);
	datB = new Date(b[currentCol]);
	
	if(isNaN(datA) && isNaN(datB))return 0;
	else if(isNaN(datA)) return -1;
	else if(isNaN(datB)) return 1;
	
	if (datA < datB) { return -1; }
	else {
		if (datA > datB) { return 1; }
		else { return 0; }
	}
}

function CompareDateEuro(a, b) {
	strA = a[currentCol].split(".");
	strB = b[currentCol].split(".")
	datA = new Date(strA[2], strA[1], strA[0]);
	datB = new Date(strB[2], strB[1], strB[0]);
	if (datA < datB) { return -1; }
	else {
		if (datA > datB) { return 1; }
		else { return 0; }
	}
}

function CompareNumeric(a, b) {
	numA = a[currentCol]
	numB = b[currentCol]
	if(isNaN(numA) && isNaN(numB))return 0;
	else if(isNaN(numA)) return -1;
	else if(isNaN(numB)) return 1;
	else return (numA - numB);
}

function changeImage(table,colNo){
	var cols=table.rows(0).cells.length;
	var currImg="document.sortImage"+colNo+".src";
	var imgSrc=eval(currImg);
	var otherImg;
	var imgName;
	var isDesc=false;
	var pos=imgSrc.lastIndexOf("/");
	
	imgName=imgSrc.substring(pos+1,imgSrc.length);
	if(imgName=="bulletUnselected.gif"){
		imgSrc="/images/bulletRotated.gif";
	}else if(imgName=="bulletRotated.gif"){
		isDesc=true;
		imgSrc="/images/bulletDescending.gif";
	}else if(imgName=="bulletDescending.gif"){
		imgSrc="/images/bulletRotated.gif";
	}
	eval(currImg+"='"+imgSrc+"'");
	
	if(previousCol >=0 && previousCol!=colNo){
		otherImg="document.sortImage"+previousCol+".src='/images/bulletUnselected.gif'";
		eval(otherImg);
	}
	return isDesc;
}

function sortTable(table,colNo){
	var rowCount;
	var colCount;
	var isSortDesc=false;
	if(table!=null){//Added by Malathi on July 18, 2002 for Ram
		rowCount=table.rows.length;
		if(rowCount <=0 || rowCount > 100) return false;

		colCount = table.rows(0).cells.length;
		if(colCount <=0 || colNo >=colCount) return false;

		isSortDesc=changeImage(table,colNo);
		dataType=eval("document.sortImage"+colNo+".dataType");
		
		sortData(table,colNo,dataType,isSortDesc);
	}//Added by Malathi on July 18, 2002
	return false;
}

function refreshSort(table){
	var colCount;
	var rowCount;
	
	rowCount=table.rows.length;
	if(rowCount <=0) return false;
	
	colCount = table.rows(0).cells.length;
	if(colCount <=0) return false;
	
	var currImg;
	var imgSrc;
	var pos;
	var imgName;
	var dataType;
	var isDesc=false;
	
	for(i=0;i < colCount;i++){
		if(eval("parent.document.sortImage"+i) !="[object]") continue
		
		currImg="parent.document.sortImage"+i+".src";
		imgSrc=eval(currImg);
		pos=imgSrc.lastIndexOf("/");
		imgName=imgSrc.substring(pos+1,imgSrc.length);
		if(imgName=="bulletUnselected.gif"){
			continue;
		}else if(imgName=="bulletDescending.gif"){
			isDesc=true;
		}
		dataType=eval("parent.document.sortImage"+i+".dataType");
		sortData(table,i,dataType,isDesc);
		break;
	}
	return;
}

function sortData(table,colNo,dataType,isSortDesc){
	var rowCount;
	var colCount;
	var bArray;
	var oldIndex;
	var bSort;

	rowCount=table.rows.length;
	if(rowCount <=0) return false;

	colCount = table.rows(0).cells.length;
	if(colCount <=0 || colNo >=colCount) return false;
	
	bArray=new Array();
	oldIndex = new Array();
	bSort = false;
	
	currentCol = colNo;
	sortArray = new Array(rowCount);
	htmlArray=new Array(rowCount);

	
	for (i=0; i < rowCount; i++) {
		sortArray[i] = new Array(colCount);
		htmlArray[i]=new Array(colCount);
		for (j=0; j < colCount; j++) {
			sortArray[i][j] = table.rows(i).cells(j).innerText;
			htmlArray[i][j] = table.rows(i).cells(j).innerHTML;
		}
	}
	
   for (i=0; i < sortArray.length; i++){
	   bArray[i] = sortArray[i][currentCol];
   }
	  
	switch (dataType) {
		case "A":
			sortArray.sort(CompareAlpha);
			break;
		case "AI":
			sortArray.sort(CompareAlphaIgnore);
			break;
		case "D":
			sortArray.sort(CompareDate);
			break;
		case "DE":
			sortArray.sort(CompareDateEuro);
			break;
		case "N":
			sortArray.sort(CompareNumeric);
			break;
		default:
			sortArray.sort()
	}
	
	if(isSortDesc) sortArray.reverse();
	
 	for (i=0; i < sortArray.length; i++) { 
        for(j=0; j < bArray.length; j++) {
            if (sortArray[i][currentCol] == bArray[j]) {
                for (c=0; c<i; c++)  if (oldIndex[c] == j) bSort=true;
                if (!bSort) oldIndex[i] = j;
	            bSort = false;
            }
        }
    }

	for (i=0; i < rowCount; i++) {
		for (j=0; j < colCount; j++) {
			table.rows(i).cells(j).innerHTML = htmlArray[oldIndex[i]][j]
		}
	}
	previousCol = colNo;
	
	return
}

/********************************************************************************
	*	Name		: changeImageById()
	*	author		: Ramkishan Sadasivam
	*	Created Dt	: Jul,09 2002
	*	Modified Dt	: 
	*	Description : Function to change the images using ID while Sorting the table
	*	param1		: table	 - Id for the table that has to be sorted
	*	param1		: tableNo- table Number(Unique number for that table, if more than one table
	*								occurs in page) for the table that has to be sorted
	*	param1		: colNo	 - The sequence Number (in that table) for column which has to be sorted
	*	returns		: false
	*   Function added by Malathi from sh.js on Sep 17, 2002
	*********************************************************************************/
	function changeImageById(table,tableNo,colNo){		
	var cols=table.rows(0).cells.length;
	currObj = document.getElementById("sortImage"+tableNo+colNo);	
	currSrc = currObj.src;
	var isDesc=false;
	if(currSrc.indexOf("bulletUnselected.gif")>=0){	
		currObj.src="/images/bulletRotated.gif";
	}
	else if(currSrc.indexOf("bulletRotated.gif")>=0){
		isDesc=true;
		currObj.src="/images/bulletDescending.gif";
	}	
	else if(currSrc.indexOf("bulletDescending")>=0){
		currObj.src="/images/bulletRotated.gif";
	}	
	for(k=0;k<cols;k++){			
		oObj = document.getElementById("sortImage"+tableNo+k);		
		if(oObj!=null&k!=colNo){
			oObj.src = "/images/bulletUnselected.gif";
		}	
	}	
	return isDesc;
}
 /********************************************************************************
	*	Name		: sortTableById()
	*	author		: Ramkishan Sadasivam
	*	Created Dt	: Jul,09 2002
	*	Modified Dt	: 
	*	Description : Function to sort the table when more than one table occurs in a page and require
	*				  sorting
	*	param1		: table	 - Id for the table that has to be sorted
	*	param1		: tableNo- table Number(Unique number for that table, if more than one table
	*								occurs in page) for the table that has to be sorted
	*	param1		: colNo	 - The sequence Number (in that table) for column which has to be sorted
	*	returns		: false
	*	USAGE		: The Image should have the ID (and name) of format sortImage+'tableNo'+'columnNo'
	*					ie., SortImage10 for the zeroth column of the first table and
	*					SortImage46  for the 6th column of the 4th table in the page
	*   Function added by Malathi from sh.js on Sep 17, 2002	
	*********************************************************************************/
	function sortTableById(table,tableNo,colNo){
		var rowCount;
		var colCount;
		var isSortDesc=false;
		
		rowCount=table.rows.length;
		if(rowCount <=0) return false;

		colCount = table.rows(0).cells.length;
		if(colCount <=0 || colNo >=colCount) return false;

		isSortDesc=changeImageById(table,tableNo,colNo);	
		dataType=eval("document.sortImage"+tableNo+colNo+".dataType");
		
		sortData(table,colNo,dataType,isSortDesc);
		
		return false;
	}

//sorting functions end

//To open a logout window on browser close
//Function modified by Malathi for Prasad on Jun 21, 2002
function openCloseWindow() {
	try{
		if(document.form1.TIERSCONTROL!=null){
			var control = document.form1.TIERSCONTROL.value;
			if (control == 0) {
				var closeWin = openPopupWindow("jsp/fw/FWCloseWindow.jsp","TIERSCloseWindow","HEIGHT=400,WIDTH=400");
				closeWin.focus();    
			}
		}		
	}catch(Exception){}
}

	
//Sets the value of the flag 'TIERSCONTROL' to 1 on logout - to differentiate if logout is done using the logout button or
// the browser is being closed
function setLogout(){
    parent.document.form1.TIERSCONTROL.value = "1";
	parent.document.form1.method = "POST";
	parent.document.form1.submit();
}

//Function to validate the Mailing Address
/* Added by Corey O for Mahesh 03-12-2002 */
//Modified by Malathi for Mahesh on Apr 24, 2002 .
function validateMailingAddr(thisForm){   

	if ( !(thisForm.sameMailAndPhysicalAddress.value=="Y") ){
		if (! isComplete(thisForm.streetNumber2) ) return false ;
		if (! isAlphaNumeric(thisForm.streetNumber2)) return false ;
		if (! isFraction(thisForm.fraction2)) return false;
		if (! isComplete(thisForm.streetName2) ) return false ;
		//if (! isAlphaNumeric(thisForm.number2)) return false;//Removed by Malathi for Mahesh on Jun 5, 2002
		if (! noSpace(thisForm.addressLine22)) return false;
		if (! isComplete(thisForm.city2) ) return false ;
		if (! isNumeric(thisForm.zipCode52)) return false;
		if (! isMaxSet(thisForm.zipCode52)) return false;
		if (! isNumeric(thisForm.zipCode42)) return false;
		if (! isMaxSet(thisForm.zipCode42)) return false;
		//The method needs modification, to accomodate the changes in DwellingNumber page element bean.
		//Added on Apr 24, 2002
		//if (! isAlphaNumeric(thisForm.number2)) return false;//Removed by Malathi for Mahesh on Jun 5, 2002
		if (! isAlphaNumeric(thisForm.dwellingNumber2)) return false;
	}  
	return true ;
}

//Functionto set the ACTION field value and then return validateForm
function setActionAndSubmit(frm,value) {  
   frm.ACTION.value = value;
   if (frmTarget !=null && frmTarget !=""){
   	frm.target = frmTarget;
   }
   return preValidate(frm);
}

/********************************************************************************
		*	Name		: disableElements()
		*	author		: Ramkishan Sadasivam
		*	Created Dt	: Jun,26 2002	- To replace the setEmps() function
		*	Modified Dt	: Jul,07 2002	 - To load Grayed images while disabling the images
		*	Description : Function to set the selective Objects as disabled /enabled
		*	param1		: boolean (true - to disable elements; false - to enable elements) 
		*	param2		: oids  - Array of ids of the objects	to be disabled/enabled
		*	
		*	returns		: 
		* Function added by Malathi from sh.js on Sep 17, 2002
*********************************************************************************/
function disableElements(flag,oids){		
	for(i=0;i<oids.length;i++){
		e = document.getElementById(oids[i]);	
		if(e.type=="image"){
		var v = e.src;
			if(flag){	
			n =v.indexOf("Gray");
				if(n<0){
					var k =  v.substring(0,v.indexOf(".gif"));					
					k = k+"Gray.gif";							
					e.src = k;
				}
			}
			else
			{
			n =v.indexOf("Gray");
				if(n>=0){
					var k =  v.substring(0,v.indexOf("Gray.gif"));					
					k = k+".gif";							
					e.src = k;
				}						
			}
		}
		e.disabled = flag;			
	}			
}

//Function disables the second set of Address fields if the deciding combo (Is Address1 same as Address2? ) has a value of 'Yes'
//Function added by Malathi on Jun 13, 2002
//Function modified by Malathi on Sep 5, 2002
function disableMailAddr(combo,thisForm){ 
var addressArray = new Array();
	if (thisForm.locationType_2 != null && thisForm.locationType_2 != "undefined")  
	{
		addressArray = new Array(thisForm.streetName2_2,thisForm.streetNumber_2,thisForm.strType_2,thisForm.fraction_2,thisForm.direction_2,thisForm.locationType_2,thisForm.aptNumber_2,thisForm.addressLine2_2,thisForm.city_2,thisForm.state_2,thisForm.zipCode4_2,thisForm.zipCode5_2,thisForm.county_2);
	}
	else if (thisForm.dwellingType2 != null && thisForm.dwellingType2 != "undefined") 
	{
		addressArray = new Array(thisForm.streetName2,thisForm.streetNumber2,thisForm.strType2,thisForm.fraction2,thisForm.direction2,thisForm.dwellingType2,thisForm.dwellingNumber2,thisForm.addressLine22,thisForm.city2,thisForm.state2,thisForm.zipCode42,thisForm.zipCode52);
	} 
	var addressLen = addressArray.length
	for(var j=0;j<addressLen;j++){
		disableFieldsOnYes(combo,addressArray[j]);
	}
}

//This function always takes first field as a dropdown. It clears and disables all the other fields if the value of the 
//dropdown is equal to " ".

function disableFieldsOnSpace()
{
var cmbValArray = new Array(" ");
var count = arguments.length;
flag=true;
	for(var j=0;j<cmbValArray.length;j++){
		//if(arguments[0].value == cmbValArray[j] ){
		if(getElementValueOrValue(arguments[0]) == cmbValArray[j] ){
			for(i=1;i<count;i++){
				flag=false;
				if(arguments[i].type == "select-one"){
					arguments[i].selectedIndex=0;
				}					
				else if (arguments[i].defaultValue =="mm" || arguments[i].defaultValue =="dd" || arguments[i].defaultValue =="yyyy"){
					arguments[i].value= arguments[i].defaultValue;
				}
				else{
					arguments[i].value="";
				}
				arguments[i].disabled = true;
			}
		}
		else{
			if(flag){
				for(i=1;i<count;i++){
					arguments[i].disabled = false;
				}
			}	 
		} 
	}
}

//Function added by Malathi on May 09, 2002
//This function always takes first field as a dropdown. It clears and disables all the other fields if the value of the 
//dropdown is equal to one value in the given Array.
function disableFieldsOnYes()
{
var cmbValArray = new Array("Y","Yes","SS","9","AN","IR","RA","KE","CD","ID","BS","E");
var count = arguments.length;
flag=true;
   	for(var j=0;j<cmbValArray.length;j++){
   		//if(arguments[0].value == cmbValArray[j] ){
		if(getElementValueOrValue(arguments[0]) == cmbValArray[j] ){
     		for(i=1;i<count;i++){
				flag=false;
				if(arguments[i].type == "select-one"){
					arguments[i].selectedIndex=0;
				}
				else if(arguments[i].type == "checkbox"){
					arguments[i].checked=false;
				}
				//else condition added by Malathi on  May 30, 2002 - to set default values to date fields before disabling
				else if (arguments[i].defaultValue =="mm" || arguments[i].defaultValue =="dd" || arguments[i].defaultValue =="yyyy")
				{
					arguments[i].value= arguments[i].defaultValue;
				}
				else
				{
					arguments[i].value="";
				}
				arguments[i].disabled = true;
       		}
    	}
		else
		{
			if(flag){
       			for(i=1;i<count;i++){
       				arguments[i].disabled = false;
       			}
			}
 
		} 
  	}
}

//This function always takes first field as a dropdown. It clears and disables all the other fields if the value 
//of the dropdown is an element in the Array cmbValArray
function disableFieldsOnNo()
{
var cmbValArray = new Array("N","No","Not Enrolled","RR","NR","PR","HO","VQ","HL","FR","AB","CS","TC","LH");
var count = arguments.length;
flag=true;
   	for(var j=0;j<cmbValArray.length;j++){
   		//if(arguments[0].value == cmbValArray[j] ){
		if(getElementValueOrValue(arguments[0]) == cmbValArray[j] ){
			for(i=1;i<count;i++){
				flag=false;
				if(arguments[i].type == "select-one"){
					arguments[i].selectedIndex=0;
				}
				else if(arguments[i].type == "checkbox"){
					arguments[i].checked=false;
				}
				//else condition added by Malathi on  May 30, 2002 - to set default values to date fields before disabling
				else if (arguments[i].defaultValue =="mm" || arguments[i].defaultValue =="dd" || arguments[i].defaultValue =="yyyy")
				{
					arguments[i].value= arguments[i].defaultValue;
				}
				else
				{
					arguments[i].value="";
				}
				arguments[i].disabled = true;
       		}
    	}
		else
		{
			if(flag){
       			for(i=1;i<count;i++){
       				arguments[i].disabled = false;
       			}
			}
 
		} 
  	}
}

//Function added by Malathi on Jun 24, 2002
//This function always takes first field as a dropdown. It enables all the other fields if the value 
//of the dropdown is equal to one of the Array elements
//Should be renamed to enableFieldsOnNo later
function enableFields()
{
var cmbValArray = new Array("TC","JU","N","No","CO","MR","VQ","OAG","TF","RM");
var count = arguments.length;
flag=true;
   	for(var j=0;j<cmbValArray.length;j++){
		if(getElementValueOrValue(arguments[0]) == cmbValArray[j] || (arguments[0].type == "checkbox" && arguments[0].checked == false) ){
			for(i=1;i<count;i++){
				flag=false;
				arguments[i].disabled = false;
       		}
    	}
		else
		{
			if(flag){
       			for(i=1;i<count;i++){
					if (arguments[i].type == "select-one"){
						arguments[i].selectedIndex = 0;
					}
					else if(arguments[i].type == "checkbox"){
						arguments[i].checked=false;
					}
					else if (arguments[i].defaultValue=="mm" || arguments[i].defaultValue =="dd" || arguments[i].defaultValue=="yyyy"){
						arguments[i].value=arguments[i].defaultValue;
					}
					else{
						arguments[i].value = "";
					}
       				arguments[i].disabled = true;
       			}
			}
 
		} 
  	}
}

// FUNCTION MODIFIED BY RAM to include getElementValueOrValue()
function enableFieldsOnSpace(){
var tmpValArray = new Array();
var cmbValArray = new Array(" ");
var count = arguments.length;
for(var k=1;k<count;k++) {
	tmpValArray[k] = arguments[k].value;
}
flag=true;
	for(var j=0;j<cmbValArray.length;j++){
		//if(arguments[0].value == cmbValArray[j] ){
		if(getElementValueOrValue(arguments[0]) == cmbValArray[j] ){
			for(i=1;i<count;i++){
				flag=false;
				arguments[i].value= tmpValArray[i];
				arguments[i].disabled = false;
			}
		}
		else{
			if(flag){
				for(i=1;i<count;i++){						
					if (arguments[i].type == "select-one"){
						arguments[i].selectedIndex = 0;
					}
					else if(arguments[i].type == "checkbox"){
						arguments[i].checked=false;
					}
					else if (arguments[i].defaultValue=="mm" || arguments[i].defaultValue =="dd" || arguments[i].defaultValue=="yyyy"){
						arguments[i].value=arguments[i].defaultValue;
					}
					else{
						arguments[i].value="";
					} 						
					arguments[i].disabled = true;
				}
			}	 
		} 
	}
}
	
//Function added by Malathi on July 25, 2002
//This function always takes first field as a dropdown. It enables all the other fields if the value 
//of the dropdown is equal to one of the Array elements
function enableFieldsOnYes()
{
var tmpValArray = new Array();
var cmbValArray = new Array("1","Y","AN","BA","BC","DA","IR","PA","RA","DO","Granted","OG","O","HL","CO","SA","E","CD","TF","RR","RS","MA");
var count = arguments.length;
for(var k=1;k<count;k++) {
	tmpValArray[k] = arguments[k].value;
}
flag=true;
   	for(var j=0;j<cmbValArray.length;j++){
   		//if(arguments[0].value == cmbValArray[j] ){
		if(getElementValueOrValue(arguments[0]) == cmbValArray[j] ){
			for(i=1;i<count;i++){
				flag=false;
				arguments[i].value= tmpValArray[i];
				arguments[i].disabled = false;
       		}
    	}
		else
		{
			if(flag){
       			for(i=1;i<count;i++){
					if (arguments[i].type == "select-one"){
						arguments[i].selectedIndex = 0;
					}
					else if(arguments[i].type == "checkbox"){
						arguments[i].checked=false;
					}
					else if (arguments[i].defaultValue=="mm" || arguments[i].defaultValue =="dd" || arguments[i].defaultValue=="yyyy"){
						arguments[i].value=arguments[i].defaultValue;
					}
					else{
						arguments[i].value = "";
					}
       				arguments[i].disabled = true;
       			}
			}
		} 
  	}
}

// FUNCTION MODIFIED BY RAM to include getElementValueOrValue()
function enableFieldsOnNo(){
var tmpValArray = new Array();
var cmbValArray = new Array("N","No","MR","TC","JU","CO","VQ","OAG","TF","DC","OT","3");
var count = arguments.length;
for(var k=1;k<count;k++) {
	tmpValArray[k] = arguments[k].value;
}
flag=true;
	for(var j=0;j<cmbValArray.length;j++){
		//if(arguments[0].value == cmbValArray[j] ){
		 if(getElementValueOrValue(arguments[0]) == cmbValArray[j] ){
			for(i=1;i<count;i++){
				flag=false;
				arguments[i].value= tmpValArray[i];
				arguments[i].disabled = false;
			}
		}
		else{
			if(flag){
				for(i=1;i<count;i++){									
					if (arguments[i].type == "select-one"){
						arguments[i].selectedIndex = 0;
					}
					else if(arguments[i].type == "checkbox"){
						arguments[i].checked=false;
					}
					else if (arguments[i].defaultValue=="mm" || arguments[i].defaultValue =="dd" || arguments[i].defaultValue=="yyyy"){
						arguments[i].value=arguments[i].defaultValue;
					}
					else{
						arguments[i].value="";
					} 
					arguments[i].disabled = true;
				}
			}	 
		} 
	}
}

//Function to clear all the fields that are passed as parameters to the function
//Function added by Malathi on July 9, 2002
function clearFields(){
	for (i=0;i<arguments.length;i++){
		if(arguments[i].type=="radio" || arguments[i].type=="checkbox"){
			arguments[i].checked = false;
		}
		else if(arguments[i].type=="select-one") {
			arguments[i].selectedIndex=0;
		}
		else
			arguments[i].value = "";
	}
}

//Function to return how many checkboxes are checked.
//Function added by Malathi for Jayanta Deb on May 16, 2002
//size = Number of checkboxes displayed
function checkboxCount(field, size){
	var count  = 0;
	var checkCount = 0;

	for(count = 0; count < size; count++)
		{
			if (field[count].checked)
			{
				checkCount += 1;
			}
			if (checkCount > 1)
				return checkCount;
		}
	return checkCount;
}

/*
Description : Function to get the Radio Button Value
param1		: The radio button object
returns		: The Value of the selected radio button
Function added by Malathi for Ram on May 31, 2002
*/
function getRadioButtonValue (radio){ 
	if(radio.length!=null){
    	for (i = 0; i < radio.length; i++){   
        	if (radio[i].checked) {
				return radio[i].value;
			}
		}
		return null;
	}
    else
	{
    	return radio.value;
	} 
}

//Function used to display the error messages in messageDisplay.jsp
	function displayMessages(errorMessage,message) {
		 var frameName = window.name;		
		if ( (frameName == "searchResults") || (frameName == "updateResult") ){ 
			return displayAppendMessages(errorMessage,message);
		}
		var newErrorMessage = doTrim(errorMessage);
		var newMessage = doTrim(message);
		if (newErrorMessage == null) {
			errorMessage =  null;
		}
		if (newMessage == null) {
			message = null;
		}			
		if (errorMessage != null) { 
			document.all.spaceTableClient.style.display='none';   
			document.all.errorTableClient.style.display='inline';
			document.all.errorSpanClient.innerHTML=errorMessage;
		} 
		else {
			document.all.errorSpanClient.innerHTML="";
			document.all.errorTableClient.style.display='none';
		}
	/*	if (message != null) {
			document.all.spaceTableClient.style.display='none';   
			document.all.messageTableClient.style.display='inline';
			document.all.messageSpanClient.innerHTML=message;  
		}  
		else {
			document.all.messageSpanClient.innerHTML ="";    
			document.all.messageTableClient.style.display='none';
		}	*/
		if (errorMessage == null && message == null) {
			document.all.spaceTableClient.style.display='inline'; 
		}       
		
	}
	// New function added by Ram on 01/05/2004 to display 
	// messages from one or more Iframes.
	function displayAppendMessages(errorMessage,message) {	
		var prevErrMsg="";
		var prevMsg="";
		var newErrorMessage = doTrim(errorMessage);
		var newMessage = doTrim(message); 
		
		if (newErrorMessage == null) {     
			errorMessage =  null;   
		}   
		if (newMessage == null) {     
			message = null;   
		}	
		var frameName = window.name;  	
		if ( (frameName == "searchResults") || (frameName == "updateResult") ){   
			document.all.spaceTableClient.style.display='none';  
			document.all.errorTableClient.style.display='none';  
			document.all.errorSpanClient.style.display='none';     
			if(errorMessage=="&nbsp;"){
				return;
			}
			if (errorMessage != null&&errorMessage!="") {    
				var preErrHTML = parent.document.all.errorSpanClient.innerHTML;   
				if(preErrHTML!=null&&preErrHTML!=""){        
					prevErrMsg=preErrHTML+"<BR>";   
				}   
				else{   
					prevErrMsg=preErrHTML;   
				}        
				
				parent.document.all.spaceTableClient.style.display='none';         
				parent.document.all.errorTableClient.style.display='inline';     
				parent.document.all.errorSpanClient.innerHTML=prevErrMsg+errorMessage;     
			} 
			else{   
				parent.document.all.errorSpanClient.innerHTML="";     
				parent.document.all.errorTableClient.style.display='none';     
			}  
			
			if (message != null&&message!="") {   
				var preMsgHTML = parent.document.all.messageSpanClient.innerHTML;   
				if(preMsgHTML!=null&&preMsgHTML!=""){        
					prevMsg=preMsgHTML+"<BR>";   
				}   
				else{    
					prevMsg=preMsgHTML;   
				}           
				
				parent.document.all.spaceTableClient.style.display='none';      
				parent.document.all.messageTableClient.style.display='inline';     
				parent.document.all.messageSpanClient.innerHTML =prevMsg+message ;        
			} 
			else{      
				parent.document.all.messageSpanClient.innerHTML ="";          
				parent.document.all.messageTableClient.style.display='none';  
			}    
			
			if (errorMessage == null && message == null) {     
				parent.document.all.spaceTableClient.style.display='inline';   
			} 
		} 
		else {      
			if (errorMessage != null&&errorMessage!="") {    
				var preErrHTML = document.all.errorSpanClient.innerHTML;   
				if(preErrHTML!=null&&preErrHTML!=""){        
					prevErrMsg=preErrHTML+"<BR>";   
				}   
				else{    
					prevErrMsg=preErrHTML;   
				}      
				
				document.all.spaceTableClient.style.display='none';            
				document.all.errorTableClient.style.display='inline';      
				document.all.errorSpanClient.innerHTML=prevErrMsg+errorMessage;  
			}   
			else {      
				document.all.errorSpanClient.innerHTML="";     
				document.all.errorTableClient.style.display='none';     
			}   
			
			if (message != null&&message!="") {   
				var preMsgHTML = document.all.messageSpanClient.innerHTML;   
				if(preMsgHTML!=null&&preMsgHTML!=""){        
					prevMsg=preMsgHTML+"<BR>";   
				}   
				else{    
					prevMsg=preMsgHTML;   
				}         
				document.all.spaceTableClient.style.display='none';         
				document.all.messageTableClient.style.display='inline';      
				document.all.messageSpanClient.innerHTML=prevMsg+message ;      
			}    
			else{      
				document.all.messageSpanClient.innerHTML ="";          
				document.all.messageTableClient.style.display='none';  
			}   
			
			if ((errorMessage == null||errorMessage=="") && (message == null||message=="")) {     
				document.all.spaceTableClient.style.display='inline';   
			}        
		}
	}
//Function used for field level security
//Function added by Malathi for Prasad on Jun 4, 2002 for Field level security
function resetElement(elem) {
	myType = elem.type;

    if (myType == 'hidden' || myType == 'password' || myType == 'text' || myType == 'textarea') {
    	elem.value = elem.defaultValue;
    }
        
    if (myType == 'select-one' || myType == 'select-multiple') {
		if(elem.options.length != null && elem.options.length != 0){
		var flag = false;
			for (var k=0, l=elem.options.length; k<l; k++) {				
				if (elem.options[k].defaultSelected) {
					flag = true;
					break;
				}
			}
			
			if (!flag) {
				elem.options[0].selected = true;
			} 
			else  
			{
				for (var k=0, l=elem.options.length; k<l; k++) {				
            		elem.options[k].selected =elem.options[k].defaultSelected;
            	}
			}
		}			
	}
}

//Function used to handle parameter passing using dynamic includes
//New function added by Malathi for Prasad on Jun 6, 2002
function runValidations(thisForm){
	return preValidate(thisForm,0);
}


//Function used to handle parameter passing using dynamic includes
//New function added by Malathi for Prasad on Jun 6, 2002
function setActionFieldAndSubmit(frm,value,validate) {  
   try{
   var validateFlag = false;
   //frm.ACTION.value = value;
   if (frmTarget !=null && frmTarget !=""){
   	frm.target = frmTarget;
   }
   if (validate == 'N') {
      frm.method = "POST";
      frm.submit();
	  return true;
   } else {
   	  return preValidate(frm);
   }
   }catch(e){}
}   

// This function is used when TABs are used to navigate through the system
function setRequestedPageIdAndSubmit(frm,value,validate) {  
   var validateFlag = false;
   var tgt = frm.target;
   frm.ACTION.value="PROCESS";
   if (tgt !=null && tgt !=""){
   		frmTarget = tgt;
   }
   frm.target="";
   frm.REQUESTED_PAGE_ID.value = value;
   if (validate == 'N') {
     frm.method = "POST";
     frm.submit();
	 return true;
   } else {
	 return preValidate(frm);
   }
}

//Function added by Malathi on Jun 11, 2002, for Scrollable Table
//1. Function to initialize scroll table

function initScrollTable(oElement) {
   resizeScrollTable(oElement);
   oElement.firstChild.syncTo = oElement.lastChild.uniqueID;
   oElement.firstChild.syncDirection = "horizontal";
}

//Function added by Malathi on Jun 11, 2002, for Scrollable Table
//2. Functions to resize Scroll table
function resizeScrollTable(oElement) {
   var head = oElement.firstChild;
   var headTable = head.firstChild;
   var body = oElement.lastChild;
   var bodyTable = body.firstChild;
   
   var bodyTableHeight = Math.max(0, oElement.clientHeight - head.offsetHeight);
   body.style.height = bodyTableHeight;
   var scrollBarWidth = body.offsetWidth - body.clientWidth;
  
   // set width of the table in the head
   var headTableWidth = Math.max(0, Math.max(bodyTable.offsetWidth + scrollBarWidth, oElement.clientWidth));
   headTable.style.width = headTableWidth;

   // go through each cell in the head and resize
   var headCells = headTable.rows[0].cells;
   var bodyCells = bodyTable.rows[0].cells;
   
   for (var i = 0; i < bodyCells.length; i++)
      headCells[i].style.width = bodyCells[i].offsetWidth;
}

//This function is used in JSPs with iframe.
//Function moved from ar.js to global.js by Malathi on Jun 17, 2002
//The outer form's target is set to the iframe 'searchResults'.
//When the ACTION is one of the Array elements, the target should be set to self. 
function setTarget(form1){
var targetArray = new Array("Next","Previous","AddWithArrow","Submit","Add","ConvertCase","ConvertIndividual","SelectAll","PROCESS");
	for(var j=0;j<targetArray.length;j++){
    	if(form1.ACTION.value== targetArray[j] ){
        	form1.target = '_self';
        }
	}
    return false;
}

//Function to open the help pop up
//Function added by Malathi for Harish on Jun 25, 2002
function showPageHelp()
{
	//var pageId = document.forms[0].PAGE_ID.value;	
	var pageId = document.getElementById("PAGE_ID").value;	
	var url = '/HelpController?action=onlinehelp&PAGE_ID=' + pageId;
	window.open(url,'PageLevelHelp','resizable=yes,width=700,height=400');
}

//Function to open a modal dialog
//Function added by Malathi on July 18, 2002
function openModalDialog(URL,winName,features){
	features = features+";scroll:no;center=yes;help:no;status=no";
	var modalVal = showModalDialog(URL,winName,features);
	return modalVal;
}

//Function to close the warning dialog
//Function added by Malathi on July 18, 2002
function closeWarning(fieldName) {
   window.returnValue=fieldName;
   window.close();
}

//Function to open the login warning dialog
//Function added by Malathi on July 18, 2002
function loginWarning(frm,action,validateFlag) {
	if (runValidations(frm)){
    	if (loginwarn){
    		modalValue=openModalDialog('/jsp/fw/FWLIWLoginWarning.jsp','WARNING!','dialogWidth:400px;dialogHeight:406px;edge:sunken;help:no;scroll:no;resizable:no');
			loginwarn = false;
		}
		if(modalValue == "Yes"){
			setActionFieldAndSubmit(frm,action,validateFlag);
		}
		else
		{ 
			loginwarn = true;
			return false;
		}
	}
	else
	{
		return false;
	}
}
//Function to reformat the Time and set it back to the Object
//Function moved from sh.js to global.js by Malathi on July 25, 2002
function reformattime(aTime) {
	if(aTime.value != ""){
		newdate = new Date(aTime.value);
		tosubmit = "2000" + "-" + "12" + "-" + "12" + " " + newdate.getHours() + ":" + newdate.getMinutes() + ":00.000000000";
	}
	else
	{
		tosubmit = "2000" + "-" + "12" + "-" + "12" + " " + "00" + ":" + "00" + ":00.100000000";
	}
	aTime.value = tosubmit;	
}

//Function to set a given value to a field
//Function added by Malathi on Aug 1, 2002
function setFieldValue(field,val){
	field.value = val;
}

/*This function is used to filter the options of one dropdown depending on the value selected in another drowdown(options of first dropdown should be related to the values of second dropdown ).
/It takes four parameters.
1.selected value of the first dropdown(filter criteria).
2.dropdown with same values as dropdown to be filtered(it should be hidden object)
3.dropdown to be filtered(second dropdown).
4.dropdown contains the all the corresponding values (common values same type of first dropdown) of the second dropdown.
//Function added by Malathi on July 30, 2002 for Rajababu 
*/
function selVal(selfield,hidCombo1,filteredCombo,hidCombo2){
var progfilter = selfield;
var dreason = hidCombo1;
var denialReason = filteredCombo;
var creason = hidCombo2;
var dval ;
var dtext ;
var count =  denialReason.options.length;
	for(var j=count-1;j>-1;j--){
		denialReason.options[j] = null;
	}
	for(var i=0;i<creason.options.length;i++){
		if(progfilter == creason.options[i].value){
			dval = dreason.options[i].value;
			dtext = dreason.options[i].text;
			var newopt = new Option(dtext,dval)
			denialReason.options[denialReason.options.length] = newopt;
		}
	}
}

// Function to clear the messages from the Message Display zone
function clearMessages(){
	displayMessages("","");
}
//Function called by disable and enable tabs
//Function added by Malathi on August 15, 2002
function cancelLink () {
	return false;
}

//Function to disable tabs
//Function added by Malathi on August 15, 2002
function disableTabs(tab) {
 link = getLinkByID(tab);
 if (link == null) {
   return false;
 }  
 if (link.onclick) {
  link.oldOnClick = link.onclick;
  link.onclick = cancelLink;
 }
 if (link.style){
   link.style.cursor = 'default';
   link.style.color = '#555555';  
 }  
}


//Function to enable tabs
//Function added by Malathi on August 15, 2002
function enableTabs(tab) {
  link = getLinkByID(tab);
   if (link == null) {
	   return false;
  }  
  link.onclick = link.oldOnClick ? link.oldOnClick : null;
  if (link.style){
	link.style.cursor = document.all ? 'hand' : 'pointer';
	link.style.color = 'black';
  }
}


//Function to get a handle to an Anchor Tag
//Used by disableTabs() and enableTabs()
//Function added by Malathi on August 15, 2002
function getLinkByID(tab) {
 if (!document.all) {
   return false;
 }
 var link = null;
 links = document.getElementsByTagName('a');
 for (var i=0;i<links.length;i++) {
	  link =  links[i];
	 if (tab == link.id) {
	   break;
	 }
 }
 return link;
}

/********************************************************************************
	*	Name		: getListText
	*	author		: Ramkishan Sadasivam
	*	Created Dt	: May,30 2002	
	*	Modified Dt	: 
	*	Description : Function called from redoList to get the Text for the given value of an Option
	*   param1		: valu - Value of Option
	*	param2		: selobj - Source List object
	*	returns		: Text of the Option 				  
	*********************************************************************************/
	function getListText(valu,selobj)	{		
		ret = "";		
		elem = selobj;			
		for(j=0;j<elem.length;j++){
			if(valu==elem.options[j].value){
				ret = elem.options[j].text;
				break;
			}
		}
		if(ret==""){
			ret = "N/A";
		}
		return ret;
	}

//Function to reset the innerHTML values when reset button is clicked. Called by doReset()
function resetInnerHTML() {
	var t = "";
	var args = glInnerHTMLArray.length;
	if(args!= null){
		for (i=0;i<args;i++){
			test = glInnerHTMLIDArray[i];
			t = document.getElementById(test);
			t.innerHTML = glInnerHTMLArray[i];
		}
	}
}

//Function added by Malathi on October 10, 2002 to disable Address Group Custom Tag
function disableAddr(combo,thisForm){ 
    var addressArray = new Array();
    if (thisForm.locationType2 != null && thisForm.locationType2 != "undefined") 
    {
		addressArray = new Array  (thisForm.streetName2,thisForm.streetNumber,thisForm.strType,thisForm.fraction,thisForm.direction,thisForm.locationType,thisForm.aptNumber,thisForm.addressLine2,thisForm.city,thisForm.state,thisForm.zipCode4,thisForm.zipCode5,thisForm.county);
    }
    else if (thisForm.dwellingType != null && thisForm.dwellingType != "undefined") 
    {
    	addressArray = new Array(thisForm.streetName2,thisForm.streetNumber,thisForm.strType,thisForm.fraction,thisForm.direction,thisForm.dwellingType,thisForm.aptNumber,thisForm.addressLine2,thisForm.city,thisForm.state,thisForm.zipCode4,thisForm.zipCode5);
    } 
    var addressLen = addressArray.length
    for(var j=0;j<addressLen;j++){
    	disableFieldsOnYes(combo,addressArray[j]);
 	}
}

//Function to get todays date from the Server and not from the client machine
function getToday(){
	try{
		var sysDate = new Date(document.form1.SysDate.value);
		var today;
		if(sysDate!= null && sysDate != ""){
			today = sysDate;
		}
		else{
			today = new Date();
		}
		return today;		
	}
	catch (Exception){return new Date();}
}

//Function to allow enter key inside a text area
//Function added by Malathi on Oct 28, 2002
function textAreaEnter(){
	enterKey = true;
}

//Function to save the carriage returns entered in a textArea.
function textAreaBreak(tArea){
	var len = tArea.value.length;
	var val="";
	var a = 1;
	for(i=0;i<len;i++)
	{
		var t = tArea.value.charAt(i);
		var b;
		if(t == "\r" || t=="\n"){
			a=a+1;
			b = a%2;
			if(b != 0){
				val=val+"~";
			}
		}
		else
		{
			val = val+t;
		}
	}
	tArea.value = val;
}

//Function to replace ~ with carriage returns in a textArea.
function replaceTilda(tArea){
	var len = tArea.value.length;
	var val="";
	for(i=0;i<len;i++)
	{
		var t = tArea.value.charAt(i);
		if(t == "~"){
			val=val+"\r\n";
		}
		else
		{
			val = val+t;
		}
	}
	tArea.value = val;
}

//Functions added by Malathi on Nov 25, 2002 to avoid duplicate(date) error messages
function validateDates(month,day,year) {
	var monthVal=month.value;
	var dayVal=day.value;
	if (dayVal=="disableDay") dayVal="01";
	var yearVal=year.value;
	var test = "";
	
  	if (validateMonth(month) && validateDay(day) && validateYear(year)) {
		var thisDateStr = monthVal + "/ " + dayVal + "/ " + yearVal;

		var thisDate = new Date( thisDateStr );
	
		var thisDateGMTString = thisDate.toGMTString();
		var thisDatefinalarray = thisDateGMTString.split( " " );
		var thisMonthNum = getMonthNumber(thisDatefinalarray[2]);
		
		if ( thisMonthNum == monthVal ) {
			return true;
		} else {
			return createErrorMessages(month,day,year);
		}
		return true;
  	}else{
			if (! validateMonth(month) || ! validateDay(day) || ! validateYear(year)){
				if(month.name != m.name){
				dateVal = true;
				}
			}
		return false;
	}
} 

//Functions added by Malathi on Nov 25, 2002 to avoid duplicate(date) error messages
function createErrorMessages(month,day,year) {
	var monthVal=month.value;
	var dayVal=day.value;
	var yearVal=year.value;
  	if(monthVal==2) {
    	if (yearVal%4 ==0 && dayVal>29) {
    		 dateVal = true;
			 return false;
	    } else if (yearVal%4 !=0 && dayVal>28) {
    		 dateVal = true;
			 return false;
	    }     
	}else if ((monthVal==4 || monthVal == 6 || monthVal==9 || monthVal==11) && dayVal>30) {
	 	dateVal = true;
		return false;
	}
	return true;
}

//Function to validate the zip code
function checkZip(field){
	if(isZipCodeZero(field)){
		if(isZipCodeMaxSet(field)){
			return isZipCodeMaxSet(field);
		}
		else return false;		
	}
	else return false;
}

//Function to concatenate date(from date customtag) and time (from time customtag)
function formDate(aDate,aTime,tgt){
	var val = aTime.value;
	var pos = val.indexOf(" ");
	var a = val.substring(pos);
	var newDt = aDate.value +""+ a;
	tgt.value = newDt;
}

//Function to set the focus on the first field in a page
function setFocusOnFirstField(){
	if (document.forms.length > 0)
  	{
	var a = document.forms[0];
	var b = a.length;

	for(i=0;i<b;i++){
		try{
			if(a.elements[i].type != null && a.elements[i].type != "hidden" && a.elements[i].disabled != true && a.elements[i].style.visibility != "hidden" && a.elements[i].style.display != "none"){
				a.elements[i].focus();
				return false;
			}
		}catch(Exception){}  
	}
	}
}

/***********************************************************************
	*	Name		: deSelectAll()
	*	author		: Ramkishan Sadasivam
	*	Created Dt	: Jan,20 2003
	*	Modified Dt	: 
	*	Used in		:  dc Functions
	*	Description :  Function to deselect all the options
	*	param1		:	selObj - The select object whose options have to
	*					be deselcted
	***********************************************************************/
	function deSelectAll(selObj){
		for(var e=0;e<selObj.length;e++){
			selObj.options[e].selected=false;
		}
	}


	/***********************************************************************
	*	Name		: getDefaultValues()
	*	author		: Ramkishan Sadasivam
	*	Created Dt	: Jan,20 2003
	*	Modified Dt	: 
	*	Used in		: dc Functions
	*	Description : Function to get the default value of a form element
	*	param1		: elem  - Element whose default value needs to be
	*				  obtained
	*	returns		: Array of default values.
	***********************************************************************/
	function getDefaultValues(elem){
		var defArr = new Array();
		myType = elem.type;
		if (myType == 'hidden' || myType == 'password' || myType == 'text' || myType == 'textarea') {
			defArr.push( elem.defaultValue);
		}        
		if (myType == 'select-one' || myType == 'select-multiple') {
		var flag = false;
			for (var k=0, l=elem.options.length; k<l; k++) {				
				if (elem.options[k].defaultSelected) {
					flag = true;
					break;
				}
			}			
			if (!flag){
				;
			} 
			else{
				for (var k=0, l=elem.options.length; k<l; k++) {				
					if(elem.options[k].defaultSelected){
						defArr.push(elem.options[k].value);
					}
				}
			}
		}					
		return defArr;
	}

	/********************************************************************
	*	Name		:	initiateListCascade()
	*	author		:	Ramkishan Sadasivam
	*	Created Dt	:	Feb,07 2003
	*	Modified Dt	:	
	*	Used in		:	general
	*	param1		:	trigElemId	- The Id of the element that triggers the event
	*	param2		:	refElemId	- The Id of the element used as a reference
	*	param3		:	setElemId	- The Id of the destination element
	*	param4		:	emptySpace	- "Y" to set an empty space as an Option in the
	*					setElemId object
	*	Description :	Function to intiate the list cascading process			
	*	returns		:	boolean
	*********************************************************************/
	function initiateListCascade(trigElemId, refElemId, setElemId, refArr, emptySpace){
		var trigElem =document.getElementById(trigElemId);
		var listVals = getArrayValue(refArr,trigElem.value);
		var refObja = document.getElementById(refElemId);
		var setObja = document.getElementById(setElemId);
		doListCascade(listVals,refObja,setObja,emptySpace);
	}

  /********************************************************************
	*	Name		:	doListCascade()
	*	author		:	Ramkishan Sadasivam
	*	Created Dt	:	Feb,07 2003
	*	Modified Dt	:	
	*	Used in		:	general
	*	Description :	Function to set the description in the
	*					select object based on the codes supplied in valArr
	*					and the reference object which contains the code
	*					and the description
	*	param1		:	valArr - the Array/String that contains the codes
	*	param2		:	refObj - The reference object that holds the 
	*					code and the descriptions
	*	param3		:	setObj - the Object in which the codes
	*					supplied in the valArr and the corresponding
	*					descriptions have to be set
	*	param3		:	emptySpace - to create an empty space
	*					option in the setObj if the setObj is a select box
	*********************************************************************/
	function doListCascade(valArr, refObj, setObj,emptySpace){
		if(setObj.type=="select-one"||setObj.type=="select-multiple"){	
			setObj.length=0;
			if(emptySpace=="Y"){
				addList("","",setObj);
			}			
		}
		if(valArr!=null){		
			if(typeof(valArr)=="object"){			
				for(var g=0;g<valArr.length;g++){
					var desc = getListText(valArr[g],refObj);
					if(setObj.type=="select-one"||setObj.type=="select-multiple"){
						var bl = addList(desc,valArr[g], setObj);			
					}
					else{
						setObj.value=desc;
					}
				}
			}
			else{
				var desc = getListText(valArr,refObj);
				if(setObj.type=="select-one"||setObj.type=="select-multiple"){					
					var bl = addList(desc,valArr,setObj);		
				}
				else{
					setObj.value=desc;
				}				
			}
		}	
	}

   /********************************************************************
	*	Name		:	getArrayValue()
	*	author		:	Ramkishan Sadasivam
	*	Created Dt	:	Feb,07 2003
	*	Modified Dt	:	
	*	Used in		:	general
	*	Description :	Function to get the values of an array based 
	*					the matching key value and return an array of
	*					values or a string value depending upon the
	*					number of keys that match the arrKey
	*	param1		:	arrObj - the 2 dim Array object that contains 
	*					the keys(1st Pos) and values(2nd Pos)					
	*	param2		:	arrKey - the key that has to be searched 
	*	returns		:	retArr - the array of matching keys
	*********************************************************************/
	function getArrayValue(arrObj,arrKey){
		var retArr = new Array();
		if(arrObj!=null){
			for(var i=0;i<arrObj.length;i++){
				if(arrKey==arrObj[i][0]){
					retArr.push(arrObj[i][1]);
				}			
			}		
		}
		if(retArr.length==0){
			return null;
		}
		else if(retArr.length==1){
			return retArr[0];
		}
		else{
			return retArr;
		}
	}

// Set value of Checkbox to "Y" (if checked) or "N"
function setCheckBoxValue(selectedCheckbox){		
	if(selectedCheckbox.checked){
		selectedCheckbox.value = "Y";		
	}
	else{
		selectedCheckbox.value = "N";			
	}	
}
	
/*
 * Function used to return the element value if the 
 * given parameter  is a valid object/element in the
 * form or return the parameter as a value otherwise
 */
 function getElementValueOrValue(elem){
		try{
			if(elem.name!=null&&elem.value!=null&&elem.value!="undefined"){
				return elem.value;
			}
			else{
				return elem;
			}
		}catch(Exception){
			return elem;
		}
	}

/*
 * This function is used to preValidate the 
 * elements specified in the elemIDArray
 */
function preValidateElements(elemIDArray) {
messageArray = new Array();
messageString = "";
var args = preValidate.arguments;
var ret = validateElements(elemIDArray);
len = validationErrors.length;
	if(ret)  {		    
		return true;
	}
	else 
	{
		var num = elemIDArray.length;	
		for(var i = 0; i<num; i++){
			var field = document.getElementById(elemIDArray[i]);
			var name = field.name;
			var aType = field.type;
			if(aType == "textarea"){
				replaceTilda(field);
			}
		}
		if(len>0) {
			for(i=0;i<len;i++)  {	        
				messageArray.push(validationErrors[i]);
			}
			errorString = messageArray.join("<br>");						
			displayMessages(errorString," ");
		}	 
		return false;
	}
}

/*
 * This function is used to validate the 
 * client side errors for the  elements
 * specified in the elemIDArray
 */

function validateElements(elemIDArray){
var num = elemIDArray.length;	
isValidateON = true;
validationErrors = new Array();
var chek = true;	
var ret;
	for(var i = 0; i<num; i++){
		var field =document.getElementById(elemIDArray[i]);
		var name = field.name;
		var validate=field.validate;	
		if ((validate !=null) && (validate!="undefined")&&(validate!="null")){			
			var startPos;
			do{
				startPos=0;
				var fun;
				var endPos=validate.indexOf(";");
				if(endPos > 0){
					fun=validate.substring(startPos,endPos);				
					startPos=endPos+1;
					validate=validate.substring(startPos,validate.length);						
				}else{
					fun=validate;
				}
				var spcs = doTrim(fun);		
				if(spcs!=null&&spcs!="null"&&spcs!=""){
					var netfunc = parseFunctionName(fun);				
					ret=eval(netfunc);				
					if(ret!=null&&ret!="null"&&ret!="undefined"&&!ret) {						
						chek = false;
					}// 
				}				
			}while(endPos != -1);
		}
	}
	isValidateON = false;		
	return chek;
}

// TO PREPARE QUERY STRING FOR ELEMENTS specified in the Element ID Array Input
function prepareElementRequestParams(elementIds){
var requestString = "";
	for(var i=0;i<elementIds.length;i++){
		var elem = document.getElementById(elementIds[i]);
		if(elem!=null){
			if(requestString==""){
				requestString+=elementIds[i]+"="+elem.value;
			}
			else{
				requestString+="&"+elementIds[i]+"="+elem.value;
			}
		}
	}
	return requestString;
}

// TO PREPARE QUERY STRING FOR THE GIVEN FORM frm
function prepareFormRequestParams(frm){
var requestString = "";
	for(var i=0;i<frm.length;i++){
		var elem = frm.elements[i];
		if(elem!=null){
			if(elem.name!=null&&elem.name!="undefined"){
				if(requestString==""){
					requestString+=elem.name+"="+elem.value;
				}
				else{
					requestString+="&"+elem.name+"="+elem.value;
				}
			}
			else if(elem.id!=null&&elem.id!="undefined"){
				if(requestString==""){
					requestString+=elem.name+"="+elem.value;
				}
				else{
					requestString+="&"+elem.name+"="+elem.value;
				}
			}
		}
	}
	return requestString;
}

/*
 * Function used check if the value of each element specified 
 * in the elemIdArr is equal to the coressponding value specified
 * in the valArr.
 * Note : the length of elemIdArr and valArr should be equal else
 *         the return value would be false;
 */
function isEachElementEqualsEachValue(elemIdArr, valArr){
var retFlag = true;
	if(elemIdArr.length!=valArr.length){		
		return false;
	}
	for(var i=0;i<elemIdArr.length;i++){		
		var elem = document.getElementById(elemIdArr[i]);		
		if(elem!=null){
			if(elem.value!=valArr[i]){				
				retFlag = false;
			}
		}
	}
	return retFlag;
}

/*
 * Function used check if the value of atleast one of the elements
 * specified in the elemIdArr is equal to the given value val.
 * 
 */
function isAnyElementEqualsValue(elemIdArr, val){	
	for(var i=0;i<elemIdArr.length;i++){		
		var elem = document.getElementById(elemIdArr[i]);		
		if(elem!=null){
			if(elem.value==val){					
				return true;
			}
		}
	}
	return false;
}
/*
 * Function used to check if the Element specified is equal
 * to any of the values specified in the given valArr
 */
function isElementEqualsAnyValue(elemId, valArr){	
var elem = document.getElementById(elemId);		
	if(elem!=null){
		for(var i=0;i<valArr.length;i++){					
			if(elem.value==valArr[i]){					
				return true;
			}
		}
	}
	return false;
}

//Function to set the value of the TARGET of the given form
function setFormTarget(frm,val){
   	frm.target = val;
    return true;
}

//Function to set all the first letters in a given string to Caps
function setAllFirstCaps(frmObj) {
	var index, tmpStr, tmpChar, preString, postString, strLen;

	tmpStr = frmObj.value.toLowerCase();
	strLen = tmpStr.length;
	if (strLen > 0)  {
		for (index = 0; index < strLen; index++)  {
			if (index == 0)  {
				tmpChar = tmpStr.substring(0,1).toUpperCase();
				postString = tmpStr.substring(1,strLen);
				tmpStr = tmpChar + postString;
			}
			else 
			{
				tmpChar = tmpStr.substring(index, index+1);
				if (tmpChar == " " && index < (strLen-1))  {
					tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
					preString = tmpStr.substring(0, index+1);
					postString = tmpStr.substring(index+2,strLen);
					tmpStr = preString + tmpChar + postString;
         		}
      		}
   		}
	}
	frmObj.value = tmpStr;
}

//Function to fix table allignments
function setTable(tabId){
     var tabElem = document.getElementById(tabId);
     if(tabElem!=null){
          tabElem.style.tableLayout ="fixed";
     }
}

/********************************************************************
*	Name		:	isGroupChecked()
*	author		:	Ramkishan Sadasivam
*	Created Dt	:	Feb,10 2003
*	Modified Dt	:	
*	Used in		:	ar/ARRPR
*	Description :	Function to validate the Program selection
*					and ensure that atleast one programs is selected
*	param1		:	grpElem
*	param2		:	chkNum - the number of elements(radio/checkbox) 
*					that should be checked
*	returns		:	boolean
*********************************************************************/
	function isGroupChecked(grpElem, chkNum){
		var cnt = 0;
		if(grpElem==null){
			return false;
		}
		if(grpElem.length>0){
			for(var i=0;i<grpElem.length;i++){					
				if(grpElem[i].checked){				
					cnt++;					
				}					
			}			
		}
		else{
			if(grpElem.checked){				
				cnt++;		
			}			
		}
		if(cnt>=chkNum){
			return true;
		}
		else{
			return false;
		}
	}

/*****************************************************************
 * Name    		: setDateValue()
 * author   	: Ramkishan Sadasivam
 * Created Dt  	: Jun,02 2003
 * Modified Dt  : 
 * Used in   	: General
 * Description  : Function to set the values for Date fields
 * param1   	: beanId - the Bean Id of the Date field 
 * dateVal      : date Value in the format 'mm/dd/yyyy'
 *****************************************************************/
function setDateValue(beanId, dateVal){

try{

	var dateObj = new Date(dateVal);

	var monthElem = document.getElementById("month"+beanId);

	var dateElem = document.getElementById("date"+beanId);

	var yearElem = document.getElementById("year"+beanId);

		monthElem.value=dateObj.getMonth() + 1;

		dateElem.value=dateObj.getDate();

		yearElem.value=dateObj.getYear();

}catch(Exception){}

}

//Empty function added - to add JS to tabsNoValidate.jsp
function jsForTabsNoValidate(){
	;
}

//Empty function added - to add JS to tabs.jsp
function jsForTabs(){
	;
}

//Function to set the selected value of a dropdown
function setSelected(combo,selVal){
	for(i=0;i<combo.length;i++){
		if(combo.options[i].value==selVal){
			combo.options[i].selected = true;
		}
	}
}

function isCompleteForm(thisfrm){	
	var manFields = getMandatoryFields(thisfrm);	
	if(manFields!=null&&manFields.length>0){
		return true;
	}
	else{		
		var frmElemIds = new Array();
		for(var i=0;i<thisfrm.length;i++){
			var elem = thisfrm.elements[i];
			if(elem.name=="dynaLoad"){
				break;
			}
			if(elem!=null&&elem.lblDesc!=null&&elem.lblDesc!=""){
				//&&(elem.type=="text"||elem.type=="select-one"||
				//elem.type=="select-multiple"||elem.type=="text-area")){
				if(elem.HELPID!=null){
					addtoUniqueElementArray(frmElemIds,elem.HELPID);					
				}
				else if(elem.helpid!=null){
					addtoUniqueElementArray(frmElemIds,elem.helpid);							
				}				
				else if(elem.name!=null){
					addtoUniqueElementArray(frmElemIds,elem.name);						
				}	
				else if(elem.id!=null){
					addtoUniqueElementArray(frmElemIds,elem.id);							
				}	
			}
		}		
		var ret =  isCompleteFields(frmElemIds,'OR');
		return ret;
	}
	return true;
}


function getMandatoryFields(frm){
	var manElemIdArr = new Array();
	for(var i=0;i<frm.length;i++){		
		var vals = getElementValidations(frm.elements[i]);		
		if(vals!=null&&vals.length>0){
			for(var j=0;j<vals.length;j++){
				if(vals[j]!=null&& vals[j]!=""&&(vals[j].indexOf("isComplete(")>=0||vals[j].indexOf("isDateComplete(")>=0)){					
					if(frm.elements[i].helpid!=null){
						manElemIdArr.push(frm.elements[i].HELPID);	
					}
					else if(frm.elements[i].name!=null){
						manElemIdArr.push(frm.elements[i].name);	
					}	
					else if(frm.elements[i].id!=null){
						manElemIdArr.push(frm.elements[i].id);	
					}	
				}
			}
		}
	}
	return manElemIdArr;
}

function getElementValidations(elem){
	var valFunctions = new Array();
	var validate =elem.validate;
	if ((validate !=null) && (validate!="undefined")&&(validate!="null")){			
		var startPos;
		do{
			startPos=0;
			var fun;
			var endPos=validate.indexOf(";");
			if(endPos > 0){
				fun=validate.substring(startPos,endPos);				
				startPos=endPos+1;
				validate=validate.substring(startPos,validate.length);						
			}else{
				fun=validate;
			}
			var spcs = doTrim(fun);		
			if(spcs!=null&&spcs!="null"&&spcs!=""){
				var netfunc = parseFunctionName(fun);				
				valFunctions.push(netfunc);
			}				
		}while(endPos != -1);
	}
	return valFunctions;
}

function addtoUniqueElementArray(arrObj,valtoAdd){
	var ret = true;
	for(var k=0;k<arrObj.length;k++){
		if(arrObj[k]==valtoAdd){
			ret = false;
			break;
		}
	}
	if(ret){
		arrObj.push(valtoAdd);
	}
	return ret;
}

function getElementLabels(aErrElemIds){
	var dispMsg = "";
	for(var j=0;j<aErrElemIds.length;j++){
		var elem = document.getElementById(aErrElemIds[j]);	
		if(elem!=null){
			if(dispMsg!=""){
				dispMsg = dispMsg+" , ";
			}
			dispMsg = dispMsg + getLabel(elem);
		}
	}		
	return dispMsg;
}	

//Function to get the form name given the field name. Default is form1.
function getElementFormName(elem){
		var formNm = document.getElementById(elem);
		if(formNm!=null){
			var eFrm = formNm.form.name;				
			return eFrm;
		}
		else{
			return "form1";
		}		
	}

//Function to disable a given image	
//If flag is true enable image else disable
function enableDisableImage(flag,img){	
	if(img.type=="image"){
		var s = img.src;
		if(!flag){
			ind =s.indexOf("Gray");
			if(ind<0){
				var k =  s.substring(0,s.indexOf(".gif"));					
				k = k+"Gray.gif";							
				img.src = k;
			}
		}
		else{
			ind =s.indexOf("Gray");
			if(ind>=0){
				var k =  s.substring(0,s.indexOf("Gray.gif"));					
				k = k+".gif";							
				img.src = k;
			}						
		}
	}
	if(flag){
		img.disabled = false;			
	}else{
		img.disabled = true;
	}
}
//Function to hide an array of images if flag is true
function hideImages(oids,flag){ 
	for (var i=0;i<oids.length;i++){
		var a = document.getElementById(oids[i]);
		if(flag){
			a.style.visibility = "hidden";
		}
		else{
			a.style.visibility = "visible";
		}
 	}
}

// Function to Add a certain # of days to the Current Date;
function addDaysToCurrentDate(daysToAdd){
	try{
		var currDate = getToday();	
		return addDaysToGivenDate(currDate,daysToAdd);
	}catch(Exception){}
}

// Function to Add a certain # of days to the given date object.
// Note the givenDate should be a Date object and not a String in Date format.
function addDaysToGivenDate(givenDate, daysToAdd){
	try{
		if(givenDate instanceof Date ){
			givenDate.setDate(givenDate.getDate()+daysToAdd);
			return givenDate;
		}
		else{			
			return new Date();
		}
	}catch(Exception){}
}

	//Function to convert the field value to Lower Case
	function toLower(field) {
		if(field!=null&&field.value!=null&&field.value!=""){
			field.value = (new String(field.value)).toLowerCase();
		}
	}

	
	 /********************************************************************
		*	Name		:	disableGroup()
		*	author		:	Ramkishan Sadasivam
		*	Created Dt	:	Jan,09 2004
		*	Modified Dt	:	
		*	Used in		:	global
		*	Description :	Function to disable or enable group form elements
		*					 like radio group and check box group
		*	param1		:	disableFlag - boolean value to disable or enable 
		*	param2		:	checkedFlag	- boolean value to check or uncheck 
		*	param2		:	grpElem - the element or element group to be disabled
		*	returns		:	boolean
		*********************************************************************/
	function disableGroup(disableFlag, checkedFlag, grpElem){
		if(grpElem==null){
			return false;
		}
		if(grpElem.length>0){
			for(var i=0;i<grpElem.length;i++){   
				grpElem[i].checked = checkedFlag;
				grpElem[i].disabled = disableFlag;				 
			}
			return false;
		}
		else{
			grpElem.checked = checkedFlag;
			grpElem.disabled = disableFlag;					
			return false;
		}		
	}
	
	/********************************************************************
		*	Name		:	displayBannerMessages()
		*	author		:	Ramkishan Sadasivam
		*	Created Dt	:	Jan,28 2004
		*	Modified Dt	:	
		*	Used in		:	bannerMessage.jsp
		*	Description :	Function to display the message as a banner
		*	param1		:	bMsg - message to display as banner		
		*	returns		:
		*********************************************************************/
	function displayBannerMessages(bMsg){
		try{
			if(bMsg!=null&&bMsg!=""){
				document.all.bannerTableClientTop.style.display='inline';  
				document.all.bannerTableClientBottom.style.display='inline'; 
				document.all.bannerSpanClientTop.innerHTML=bMsg;  
				document.all.bannerSpanClientBottom.innerHTML=bMsg;  
			}
		}catch(Exception){
			document.all.bannerTableClientTop.style.display='none';  
			document.all.bannerTableClientBottom.style.display='none'; 
		}
	}
	
// Validates the form field for the numeric value. 
function isNumeric(field){
	var thisValue = field.value;
	if (!isInteger(thisValue)){
			alertMe('M0009',field);
			return false;
	}
	return true;
}

// Validates the form field for the numeric value. 
function isNumericZipCode(field){
	var thisValue = field.value;
	if (!isInteger(thisValue)){
			alertMe('M0011',field);
			return false;
	}
	return true;
}

// Validates the form field for the zip code. 
function isZipCodeNumeric(field){
	var thisValue = doTrim(field.value);	
	if (thisValue != null && !isInteger(thisValue)){			
			alertMe('M0011',field);
			return false;
	}
	return true;
}

//Validates the e-mail id 
function isEmail(field){
	var value = field.value;
   	if (value==null || value.length==0) return true;
   
   	var at = value.indexOf("@");
   	var lastChar = value.length-1;
   	if ((at<1)||(at==lastChar)){
		alertMe('GL002',field);
		return false;
   	}else{
		field.value = doTrim(value);
		return true;
	}  
}

//Function to validate that the Mandatory fields are complete
function isComplete(field){ 
	if(field.disabled) return true;  
	if( field.length>1){
		if(field[0].type =="radio" || field[0].type =="checkbox"){
			var num = 1;
			if(field.length > 1){
				if(field[0].type =="checkbox"){
					var args = isComplete.arguments;
					if(args!=null&&args.length>1&&args[1]!=null&&args[1]>1){
					num = args[1];
					}
				}
			}
			var flg = isGroupChecked(field,num);
				if(!flg){
				alertMe('M0002',field[0]);
				return false;
			}
		}
		else if(field.type == "select-one" || field.type == "select-multiple" ){
			if (!isDataComplete(field)) {
				alertMe('M0003',field);
				return false;
			}
		}
	}
	else if (!isDataComplete(field)) {
 		alertMe('M0007',field);
	 	return false;
   	}
	return true;  
}

//Function added by Malathi on Jun 12, 2002
//Function to check for mandatory fields - without popping the alerts
function isDataComplete(field) {	
	if(field.type =="radio" || field.type =="checkbox"){
   	 	if(field.checked == true){
   	 		return true;
   	 	}
   	 	else return false;
   	}
	else
	{
    var val = field.value;  
    var thisval = null;
    if (val!=null) {
	   var vallen= val.length;
	   thisval = doTrim(val);	
	   if (thisval== null) {
	     thisvallen = 0;
	   } else {thisvallen = thisval.length;}
	   if (vallen >0 & thisvallen<=0) {	      
	     return false;
	   }
	} else {
		thisval = val;
	}
   if (thisval==null || thisval.length<=0) {
      return false; 
   }
   return true;
   }
}

//Validates the form field element for alpha numeric value. Allows spaces.
function isAlphaNumeric(field) {
	var val = field.value;
	//val = doTrim(val);	
	val = trimstr(val);
  	if (val==null || val.length==0) return true;
	if (isAlphaNumericData(field,val)) {       
		return true; 
  	} else { 
    	alertMe('M0045',field );
    	return false;
  	}
}
//Validates the form unit,suffix and pobox for alpha numeric value. Allows spaces and do not allow "/".
function isUnit(field) {
	var val = field.value;
	//val = doTrim(val);	
	val = trimstr(val);
  	if (val==null || val.length==0) return true;
	if (isUnitData(field,val)) {       
		return true; 
  	} else { 
    	alertMe('M0045',field );
    	return false;
  	}
}
//Function to check if the given value is Alphanumeric and donot allow "/"
function isUnitData(field,val) {
  	var rep2 = /[A-Za-z0-9\/]+([a-z]|[0-9])*\s*[A-Za-z\/0-9]*/;
  	var rep = /[^A-Za-z0-9\s]+/;
  	
  	var test = val.match(rep);
  	var test2 = val.match(rep2);
  	var leng = val.length;

	/*for(var i=0;i<leng;i++){
		if(val.charAt(0)== " "){
  	    	val= val.substring(1);
  	    }
  	}*/
  	field.value=val;
	if ((test == null) && (test2!=null) && (val.charAt(0)!= " ") && val.charAt(leng-1) !== " ") {       
		return true; 
  	} else { 
    	return false;
  	}
}

//Validates the form field element for alpha numeric value and '/'. Allows spaces.
function isStreetNumber(field) {
	var val = field.value;
	//val = doTrim(val);	
	val = trimstr(val);
  	if (val==null || val.length==0) return true;
	if (isStreetNumberData(field,val)) {       
		return true; 
  	} else { 
    	alertMe('M0138',field );
    	return false;
  	}
}
//Function to check if the given value is Alphanumeric
function isStreetNumberData(field,val) {
  	var rep2 = /[A-Za-z0-9\/]+([a-z]|[0-9])*\s*[A-Za-z\/0-9]*/;
  	var rep = /[^A-Za-z0-9\/\s]+/;
  	var test = val.match(rep);
  	var test2 = val.match(rep2);
  	var leng = val.length;

	/*for(var i=0;i<leng;i++){
		if(val.charAt(0)== " "){
  	    	val= val.substring(1);
  	    }
  	}*/
  	field.value=val;
	if ((test == null) && (test2!=null) && (val.charAt(0)!= " ") && val.charAt(leng-1) !== " ") {       
		return true; 
  	} else { 
    	return false;
  	}
}

//To adhere to only Alphabets and numeric. No spaces.
function isStrictlyAlphaNumeric(field) {
	var val = field.value;
  	if (val==null || val.length==0) return true;
	
  	var rep2 = /[A-Za-z0-9]+([a-z]|[0-9])*\s*[A-Za-z0-9]*/;
  	var rep = /[^A-Za-z0-9]+/;
  	var test = val.match(rep);
  	var test2 = val.match(rep2);
  	if ((test == null) && (test2!=null) && (val.charAt(0)!= " ")) {
		return true; 
  	} else { 
    	alertMe('GL005',field );
    	return false;
  	}
}

//Validates the form field element for alpha values. Allows spaces.
function isAlpha(field) {
	var lbl = field.name;
  	var val = field.value;
	val = doTrim(val);	
  	if (val==null || val.length==0) return true;
	
  	var rep2 = /[A-Za-z]+[a-z]*\s*[A-Za-z]*/;
  	var rep = /[^A-Za-z\s]+/;
  	var test = val.match(rep);
  	var test2 = val.match(rep2);
  	if ((test == null) && (test2!=null) && (val.charAt(0)!= " ")) {
		return true; 
  	} else { 
    	alertMe('M0008',field);
    	return false;
  	}
}

//To ensure the value is a fraction
function isFraction(field){
	var thisValue = field.value;
	var thisLength = field.value.length;
	for (var i = 0; i != thisLength; i++){
		aChar = thisValue.charAt(i);
		if (!isDigit(aChar) && aChar!="/"){
			alertMe('GL007',field);
			return false;
		}
	}
	return true;
}

// This function checks if the value entered is equal to the maxLength specified. 
function isMaxSet(field){
	var val=field.value;
	if(val==null || val.length <= 0) return true;
	var maxLen=field.maxLength;
	if(val.length < maxLen){
		alertMe('GL008',field);
		return false;
	}
	return true;
}


// This function checks if the value entered is equal to the maxLength specified for ZipCode 
function isZipCodeMaxSet(field){

	var val=doTrim(field.value);
	if(val==null || val.length <= 0) return true;
	var maxLen=field.maxLength;
	if(val.length < maxLen){
		alertMe('M0011',field);
		return false;
	}
	return true;
}

//Function ensures that the field entry is in the standard format for currency
//Function added by Malathi Manivannan on May 3, 2002
function isCurrency(FieldName){
		var val = FieldName.value;
		var disp = "currency";
		flag=true;
		if(arguments[1]!= null){
			disp = arguments[1];
		}
		if(val.length==1){
				var chkforperiod= val.substring(0,1);
				if (chkforperiod=="."){
            		alertMe('M0005',FieldName);
            		return false;
            	}
        }		
		for (var i=0, len=val.length, valid='0123456789.' ; i<len ; i++) {
		var substr = val.substring(i,i+1);
		var substr1 = val.indexOf(substr);
		var substr2 = len - substr1;
			if (valid.indexOf(substr) == -1 || (substr=="." && flag==false) || (substr=="." && substr2>3) ){
            	alertMe('M0005',FieldName);
            	return false;
       	 	}
       	 	if(substr == "."){
       	 		flag=false; 
       	 		if(substr2==1){
       	 		FieldName.value = val+"00";
       	 		}
       	 		if(substr2==2){
       	 		FieldName.value = val+"0";
       	 		}
				if(substr1==0){
       	 		FieldName.value = "0"+val;
       	 		}
       	 		if(substr1==0 && substr2==2){
       	 		FieldName.value = "0"+val+ "0";
       	 		}
       	 	 		
       	 	} 
       	 	if(FieldName.value==0){
       	 	FieldName.value="0.00";
       	 	}
       	 	if(val.indexOf(".") == -1){
       	 	FieldName.value= val+".00";
       	 	}
	   	}
		return true;//Added by Malathi for Marlin on May 28, 2002
    }
//Function ensures that the field entry is in the standard format for Hours
//Function added by Ramesh Valluru on Jan 18, 2005
function isHours(FieldName){
		var val = FieldName.value;
		var disp = "currency";
		flag=true;
		if(arguments[1]!= null){
			disp = arguments[1];
		}
		if(val.length==1){
				var chkforperiod= val.substring(0,1);
				if (chkforperiod=="."){
            		alertMe('M0083',FieldName);
            		return false;
            	}
        }
		for (var i=0, len=val.length, valid='0123456789.' ; i<len ; i++) {
		var substr = val.substring(i,i+1);
		var substr1 = val.indexOf(substr);
		var substr2 = len - substr1;
			if (valid.indexOf(substr) == -1 || (substr=="." && flag==false) || (substr=="." && substr2>3) ){
            	alertMe('M0083',FieldName);
            	return false;
       	 	}
       	 	if(substr == "."){
       	 		flag=false; 
       	 		if(substr2==1){
       	 		FieldName.value = val+"00";
       	 		}
       	 		if(substr2==2){
       	 		FieldName.value = val+"0";
       	 		}
				if(substr1==0){
       	 		FieldName.value = "0"+val;
       	 		}
       	 		if(substr1==0 && substr2==2){
       	 		FieldName.value = "0"+val+ "0";
       	 		}
       	 	 		
       	 	} 
       	 	if(FieldName.value==0){
       	 	FieldName.value="0.00";
       	 	}
       	 	if(val.indexOf(".") == -1){
       	 	FieldName.value= val+".00";
       	 	}
	   	}
		return true;
    }
	
/*Function created by Malathi on May 31, 2002
This is a generic function which validates the different numbers in the System
char - can be a SingleChar ('T') - where first letter has to be 'T'
		OR 'Alpha' - where first letter can be ant 'Alpha' char
		OR '2Alpha' - where first 2 chars jhave to be Alpha
num - number of digits allowed after the 'Alpha' chars
label - label of the field - used for alertMes
*/
function isValidNumber(char,num,label,field){
		flag =isNumberValid(char,num,field);
		if(!flag)
		{
			if(char == "0Alpha"){
				alertMe('GL010',label,label,num);
			}
			else if(char == "6Alpha"){
				alertMe("GL055",label,label,num);
			}
			else
			{
				if(char=="2Alpha"){
					char = "2 Alpha";
				}
				alertMe('GL011',label,label,char,num);
			}
			field.focus();
			return false;
		}
		else{

			val = field.value;
			firstChar = val.charAt(0);
			firstChar = firstChar.toUpperCase();

			secondChar = val.charAt(1);
			fourthChar = val.charAt(3);
			fifthChar = val.charAt(4);
			sixthChar = val.charAt(5);
			
			var a = val.substring(0,3);
			var b = val.substring(6);
					
			if(char=="Alpha"){
				num = val.substring(1,val.length);
				field.value = firstChar + num;
			}
			else if(char=="2Alpha"){
				secondChar = secondChar.toUpperCase();
				num = val.substring(2,val.length);
				field.value = firstChar + secondChar + num;
			}
			else if(char=="6Alpha"){
				fourthChar = fourthChar.toUpperCase();
				fifthChar = fifthChar.toUpperCase();
				sixthChar = sixthChar.toUpperCase();
				field.value = a + fourthChar+fifthChar+sixthChar + b;
			}
			
			return true;
		}
}
//This function validates that atleast one of the fields passed as arguments should be entered.
function isAtleastOneComplete() {
   var count = arguments.length;
   var msg = "";
   	for(i=0;i<count;i++){
   		if (i < count-1){ 
   			msg = msg +"'" +arguments[i].lblDesc+"', ";	
   		}
   		else if (i == count-1){
   			msg = msg + "or '"+arguments[i].lblDesc+"' ";
   		}
   		if ( isDataComplete(arguments[i]) == true ) {
	   		return true ;	
		}
   	}
    alertMe('GL012',msg);
	return false;
}  

// Given 2 fields, this function validates that atleast one field needs to be filled.
function isOneComplete(field1,field2,label1,label2){

	if (field1.type == "radio"){
		flag = ((!field1.checked) && (!field2.checked));
	}
	else
	{
		flag = (field1.value =="" && field2.value =="");
	}

	if(flag){
    	alertMe('GL013',label1,label2);
    	return false;
    }else{
        return true;
    }
}

// This function joins the three fields passed to it into one field in the order that they are passed.
//validates for the date,if the text is entered in one box
function joinFields(field1, field2, field3, targetField,flag){
	var value1 = field1.value;
	var value2 = field2.value;
	var value3 = field3.value;
	targetField.value = "";
	var len=value1.length+value2.length+value3.length;	

	if(arguments[4] == null){
		flag = "N";
	}
	if(arguments[5] == null){
		flag = "N";
	}
	if(flag =="Y"){
		if(value1 == "" && value2 =="" && value3 ==""){
   		alertMe('M0003',targetField); 
		return false;		
		}
	}
	if (len > 0 ){
		if( (value1.length < field1.maxLength) || (value2.length < field2.maxLength) || (value3.length < field3.maxLength) ){
			alertMe('GL014',field1);
			return false;
		}
	}
	if(len >= 9){
		targetField.value = value1+value2+value3;
	}
	return true;
}


// This function joins the three fields passed to it into one field in the order that they are passed.
//validates for the date,if the text is entered in one box
function joinSSNFields(field1, field2, field3, targetField,flag){
	var value1 = field1.value;
	var value2 = field2.value;
	var value3 = field3.value;
	targetField.value = "";
	var len=value1.length+value2.length+value3.length;	

	if(arguments[4] == null){
		flag = 'N';
	}
	
	if(flag =='Y'){
		if(value1 == "" && value2 =="" && value3 ==""){
   		alertMe('M0007',targetField); 
		return false;		
		}
	}
	if (len > 0 ){
		if( (value1.length < field1.maxLength) || (value2.length < field2.maxLength) || (value3.length < field3.maxLength) ){
			alertMe('M0015',field1);
			return false;
		}
	}
	if(len >= 9){
		targetField.value = value1+value2+value3;
	}
	return true;
}



function joinPhoneFields(field1, field2, field3, targetField,flag){
	if(field1 == null || field1 == "undefined")
	return true;;
	var value1 = field1.value;
	var value2 = field2.value;
	var value3 = field3.value;
	targetField.value = "";
	var len=value1.length+value2.length+value3.length;	

	if(arguments[4] == null){
		flag = 'N';
	}	
	if(flag =='Y'){
		if(value1 == "" && value2 =="" && value3 ==""){
   		alertMe('M0007',targetField); 
		return false;		
		}
	}
	if (len > 0 ){
		if( (value1.length < field1.maxLength) || (value2.length < field2.maxLength) || (value3.length < field3.maxLength) ){
			alertMe('M0012',field1);
			return false;
		}
	}
	if(len >= 9){
		targetField.value = value1+value2+value3;
	}
	return true;
}

function joinFieldsConditionally(depField,depValue,field1, field2, field3, targetField,flag){
	if(depField.value == depValue){	
		return joinFields(field1, field2, field3, targetField,flag);
	}
	return true;
}
function joinSSNFieldsConditionally(depField,depValue,field1, field2, field3, targetField,flag){
	if(depField.value == depValue){	
		return joinSSNFields(field1, field2, field3, targetField,flag);
	}
	return true;
}


function joinPhoneFieldsConditionally(depField,depValue,field1, field2, field3, targetField,flag){
	if(depField.value == depValue){	
		return joinPhoneFields(field1, field2, field3, targetField,flag);
	}
	return true;
}


// This function joins the three fields passed to it into one field in the order that they are passed.
//validates for the date,if the text is entered in one box
function isGroupComplete(field1, field2, field3){
	var value1 = field1.value;
	var value2 = field2.value;
	var value3 = field3.value;		

	if(flag =="Y"){
		if(value1 == "" && value2 =="" && value3 ==""){
   		alertMe('GL003',targetField);
		return false;		
		}
	}

	return true;
}
// This function joins the three fields passed to it into one field in the order that they are passed.
//validates for the date,if the text is entered in one box
function joinGroupFields(field1, field2, field3){
	var value1 = field1.value;
	var value2 = field2.value;
	var value3 = field3.value;
	targetField.value = "";
	var len=value1.length+value2.length+value3.length;	

	if (len > 0 ){
		if( (value1.length < field1.maxLength) || (value2.length < field2.maxLength) || (value3.length < field3.maxLength) ){
			alertMe('GL014',field1);
			return false;
		}
	}
	if(len >= 9){
		targetField.value = value1+value2+value3;
	}
	return true;
}
 
/* 	add the following attribute to each field that neads to be joined (Three total). Replace targetField with the name of the hidden field.
//	Replace textfield1, textfield2 and textfield3 with the name of the fields that need to be joined. Replace form1 with the
//	name of the form which contains the fields.
*/

function joinFourFields(field1, field2, field3,field4,targetField,flag){
	var value1 = field1.value;
	var value2 = field2.value;
	var value3 = field3.value;
	var value4 = field4.value;
	targetField.value = "";

	var len=value1.length+value2.length+value3.length+value4.length;
	
	if(arguments[5] == null){
		flag = "N";
	}
	if(flag =="Y"){
		if(value1 == "" && value2 =="" && value3 =="" && value4 ==""){
   		alertMe('GL003',targetField);
		return false;		
		}
	}
	if (len > 0 ){
		if( (value1.length < field1.maxLength) || (value2.length < field2.maxLength) || (value3.length < field3.maxLength) ){
			alertMe('GL014',field1);
			return false;
		}
	}
	if(len > 9 ){
		targetField.value = value1+value2+value3+value4;
	}
	return true;
}

//Function to merge time
function mergetime(hours,minutes,ampm,newlocation) {
	var val= "";
	if(hours.value==" " && minutes.value==" " && ampm.value == " ")
	{
		newlocation.value = "";
		return true;
	}
	
	if ( (hours.value != null && hours.value != "" && minutes.value==" " || ampm.value == " ") || (minutes.value != null && minutes.value != "" && hours.value==" " || ampm.value == " ") || (ampm.value != null && ampm.value != "" && hours.value==" " || minutes.value == " ")){
		alertMe("GL014",hours);
		return false;
	}
	
	if (ampm.value=="AM"||ampm.value=="0"){
 		val="0";
	}	
	else if (ampm.value=="PM"||ampm.value=="1"){
		val="1";
	} 
	addvalue = parseInt(val,10) * 12;//Modified by Malathi - to set base 10
	newhour = parseInt(hours.value,10);//Modified by Malathi - to set base 10
	if (newhour == 12) {
		if (addvalue == 0) {
			newhour = 0;
		}
	} else {
		newhour = addvalue + newhour;
	}
	newdate = new Date(2001, 0, 1, newhour,parseInt(minutes.value,10),0,0);//Modified by Malathi - to set base 10
	newlocation.value = newdate.toLocaleString();
}

/* 	Add the following attribute to each field that needs to be joined (Three total). Replace targetField with the name of the hidden field.
//	Replace textfield1, textfield2 and textfield3 with the name of the fields that need to be joined. Replace form1 with the
//	name of the form which contains the fields.
*/

function joinZip(field1, field2){
	var value1 = field1.value;
	var value2 = field2.value;
	var len=value1.length+value2.length;	
	if (len == 4 && value1.length < field1.maxLength){
		alertMe('GL015');
		return false;
	}
	return true;
}

//Validates that the value entered is in a valid 'Name' format
function validateName(field){
	var val = field.value;
	if (val==null || val.length==0) return true;
	var rep2 = /[A-Za-z]*([a-z.\-\']|[0-9\-\'])*\s*[A-Za-z0-9\-\'.]*/;
	var rep = /[^A-Za-z0-9\s\-\'.]+/;
	var test = val.match(rep);
	var test2 = val.match(rep2);
	if ((test == null) && (test2!=null) && (val.charAt(0)!= " ")) {
		var val1= val.substring(0,1);
		val1= val1.toUpperCase();
		var val2= val.substring(1);
		field.value = val1+val2;
		return true; 
	} 
	alertMe('GL016',field);
	return false;
}

//Function to check that date is mandatory
function isDateComplete(month,date,year){
if(month.disabled && date.disabled && year.disabled)
	return true;
monthval = doTrim(month.value);
dateval = doTrim(date.value);
yearval = doTrim(year.value);
	//Ram: If any one of the fields is entered(space also OK) , then dont check for mandatoryness
	dateEntered = "false";
	if( (monthval != "mm" && monthval != "MM") || (dateval != "dd" && dateval != "DD" && date != "disableDay") || (yearval != "yyyy" && yearval != "YYYY")){
		dateEntered = "true";
	}
	
	if( dateEntered == "true"){ 
		return true;
	}
	
var mm = "";
	if ((monthval != null && monthval == "mm")||(monthval==null)) {
		mm = mm+"month,";
	}
	if ((dateval != null && dateval == "dd")||(dateval==null)) {
		mm = mm+"date,";
	}
	if ((yearval != null && yearval == "yyyy")||(yearval==null)) {
		mm = mm+"year";
  	}
	if(mm!=""){
			var args = isDateComplete.arguments;
			if(args.length>3&&args[3]!=null&&!args[3]){
				;
			}
			else{
			    alertMe("M0007",month);
			}
			m = month;
  			dateVal = true;
		return false;
  	}else{
		m = "";
  		dateVal = false;
		return true;
  	}
  	return true;
} 

//Works to make function createErrorMessage to put the date together to make the createErrorMessage function work.
function validateDate(month,day,year) {
	var monthVal=month.value;
	var dayVal=day.value;
	if (dayVal=="disableDay") dayVal="01";
	var yearVal=year.value;
	var test = "";
  	if (validateMonth(month) && validateDay(day) && validateYear(year)) {
		var thisDateStr = monthVal + "/ " + dayVal + "/ " + yearVal;
		var thisDate = new Date( thisDateStr );
		var thisDateGMTString = thisDate.toGMTString();
		var thisDatefinalarray = thisDateGMTString.split( " " );
		var thisMonthNum = getMonthNumber(thisDatefinalarray[2]);
		
		if ( thisMonthNum == monthVal ) {
			return true;
		} else {
			return createErrorMessage(monthVal,dayVal,yearVal);
		}
		return true;
  	}else{
			//if (! validateMonth(monthVal) || ! validateDay(dayVal) || ! validateYear(yearVal)){			
				//if(monthVal.name != m.name){
			//	alertMe("M0013",month);
			//	dateVal = true;
			//	}
			//}
		return false;
	}
}

//Validates the month.  Makes sure the month is within 1-12.  
//Works with function createErrorMessage to show appropriate error message.
function validateMonth(month) {
	//var monthval=doTrim(month.value);
	var monthval=month.value;
	for (i=0; i<monthval.length; i++) {
  	   	var curchar = monthval.charAt(i);
  	   	if(curchar == null || curchar == " "){
  	   		return false;
	    }
	}	
	
	var monthrep = /\D{1,2}/;
	var test = monthrep.test(monthval);
	if (test ||(monthval <=0 || monthval>12)) {
		return false;
	}
	return true;
}

//This function validates the day from 1-31.  
//This function works with createErrorMessage to pop the correct error message based on the amount of days in a certain month.
//Function modified by Malathi for handling situations where the date field will not be displayed
function validateDay(day) {
	//var dayval=doTrim(day.value);
	var dayval= day.value;
	for (i=0; i<dayval.length; i++) {
  	   	var curchar = dayval.charAt(i);
  	   	if(curchar == null || curchar == " "){
  	   		return false;
	    }
	}	
	
	var dayrep = /\D{1,2}/;
	var test = dayrep.test(dayval);
	if(dayval != "disableDay")
	{
	if (test ||(dayval <=0 || dayval>31)) {
	    return false;
	  }
   }

	return true;
}

//This function validates the year from 1001 to 5000.  
function validateYear(year) {
	//var yearval=doTrim(year.value);
	var yearval= year.value;
	for (i=0; i<yearval.length; i++) {
  	   	var curchar = yearval.charAt(i);
  	   	if(curchar == null || curchar == " "){
  	   		return false;
	    }
	}	
	var yearrep = /\D{1,4}/;
	var test = yearrep.test(yearval);
	if (test ||(yearval <1000 || yearval>5000)) {
	    return false;
	}
	return true;
}

//This displays the correct error message, based on whether the month., day, or year is incorrect.
function createErrorMessage(month,day,year) {
	var monthVal=month.value;
	var dayVal=day.value;
	var yearVal=year.value;
  	if(monthVal==2) {
    	if (yearVal%4 ==0 && dayVal>29) {
    		 dateVal = true;
		 	 alertMe("M0013",month);
			 return false;
	    } else if (yearVal%4 !=0 && dayVal>28) {
    		 dateVal = true;
			  	alertMe("M0013",month);
			 return false;
	    }     
	}else if ((monthVal==4 || monthVal == 6 || monthVal==9 || monthVal==11) && dayVal>30) {
	 	dateVal = true;
		alertMe("M0013",month);
		return false;
	}
	return true;
}

/*The following 5 Generic Date functions were added by Malathi Manivannan on May 08, 2002
1.Function to ensure that date cannot be past date. Today allowed.
  targetField - is a hidden field used to combine the date fields to a single field for formatting and validating the date
  dateString - is the label of the date field - is used for popping field specific alertMes
  Date functions modified by Malathi on May 09, 2002 - to handle exception when dateString is undefined
  Date functions modified by Malathi on May 14, 2002 - to handle exception when date is not mandatory
*/
function pastDate(month, day, year, targetField,dateString){
	if(formatDate(month,day,year,targetField)==false) return false;
	
	var monthVal =month.value;
	var dayVal = day.value;
   	var yearVal = year.value;
	var Calendar = new Date();      
	var today = getToday();  
	/*var sysDate = getToday();
	if(sysDate!= null && sysDate != ""){
		today = sysDate;
	}
	else
	{
    	today = new Date(Calendar.getYear(), Calendar.getMonth(), Calendar.getDate());
    }*/
	if ((monthVal ==null && dayVal ==null && yearVal ==null) || (monthVal =="" && dayVal =="" && yearVal =="")) {
		return true;
  	} else {
	  	var dateOne = new Date(yearVal, monthVal - 1, dayVal);
  	}

	if (today > dateOne){
		if(dateString == undefined){
			alertMe('GL018',month);
		}
		else
		{
			alertMe('GL018',dateString);
		}
		return false;
	}
	return true;
}

//2. Function to ensure that date cannot be past date. Today not allowed
function pastDateInclusive(month, day, year, targetField,dateString){
	if(formatDate(month,day,year,targetField)==false) return false;
	
	var monthVal =month.value;
	var dayVal = day.value;
   	var yearVal = year.value;
	var Calendar = new Date();      
	var today = getToday();  
	/*var sysDate = getToday();
	if(sysDate!= null && sysDate != ""){
		today = sysDate;
	}
	else
	{
    	today = new Date(Calendar.getYear(), Calendar.getMonth(), Calendar.getDate());
    }*/
	if ((monthVal ==null && dayVal ==null && yearVal ==null) || (monthVal =="" && dayVal =="" && yearVal =="")) {
		return true;
  	} else {
	  	var dateOne = new Date(yearVal, monthVal - 1, dayVal);
  	}
	
	if (today >= dateOne){
		if(dateString == undefined){
			alertMe('GL019',month);
		}
		else
		{
			alertMe('GL019',dateString);
		}
		return false;
	}
	return true;
}

//3. Function to ensure that date cannot be future date. Today allowed
function futureDate(month, day, year, targetField,dateString){
	if(formatDate(month,day,year,targetField)==false) return false;
	
    var monthVal = month.value;
    var dayVal = day.value;
    var yearVal = year.value;
	var Calendar = new Date();      
	var today = getToday();  
	/*var sysDate = getToday();
	if(sysDate!= null && sysDate != ""){
		today = sysDate;
	}
	else
	{
    	today = new Date(Calendar.getYear(), Calendar.getMonth(), Calendar.getDate());
    }*/
	
	if ((monthVal ==null && dayVal ==null && yearVal ==null) || (monthVal =="" && dayVal =="" && yearVal =="")) {
		return true;
  	} else {
	  	var dateOne = new Date(yearVal, monthVal - 1, dayVal);
  	}
	
  	if (today < dateOne){
		if(dateString==undefined){
			alertMe('GL020',month);
		}
		else
		{
			alertMe('GL020',dateString);
		}
		return false;
	}
	return true;
}

//4.Function to compare 2 dates. Not Inclusive
function compareDates(month1, day1, year1,month2,day2,year2,targetField,dateString1,dateString2){
	var tempTargetField = targetField.value;
	var date1 = validateDates(month1, day1, year1,targetField);
	var date2 = validateDates(month2,day2,year2,targetField);
	if(dateVal == false){
		if(date1==false){
			dateVal = true;
			alertMe("GL017",month1);
		}
  		if(date2==false){
			dateVal = true;
			alertMe("GL017",month2);
		}
	}
	targetField.value = tempTargetField;
	
	if (date1 && date2)
	{
  	var month1Val = month1.value;
  	var day1Val = day1.value;
  	var year1Val = year1.value;
  	var month2Val = month2.value;
  	var day2Val = day2.value;
  	var year2Val = year2.value;
  
  	if ((month1Val ==null && day1Val ==null && year1Val ==null) || (month1Val =="" && day1Val =="" && year1Val =="")) {
		return true;
  	} else {
	  	var dateOne = new Date(year1Val, month1Val - 1, day1Val);
  	}
	
  	if ((month2Val ==null && day2Val ==null && year2Val ==null) || (month2Val =="" && day2Val =="" && year2Val =="")) {
		return true;
  	} else {
	  	var dateTwo = new Date(year2Val, month2Val - 1, day2Val);
  	}
    

 	if(dateOne < dateTwo){
  		alertMe('GL021',dateString1,dateString2);
    return false;
 	} 
	}
return true;
}

//5.Function to compare 2 dates. Inclusive
function compareDatesInclusive(month1, day1, year1,month2,day2,year2,targetField,dateString1,dateString2){
	var tempTargetField = targetField.value;
	var date1 = validateDates(month1, day1, year1,targetField);
	var date2 = validateDates(month2,day2,year2,targetField);
	if(dateVal == false){
		if(date1==false){
			dateVal = true;
			alertMe("GL017",month1);
		}
  		if(date2==false){
			dateVal = true;
			alertMe("GL017",month2);
		}
	}
	targetField.value = tempTargetField;	

	if (date1 && date2)
	{
  	var month1Val = month1.value;
  	var day1Val = day1.value;
  	var year1Val = year1.value;
  	var month2Val = month2.value;
  	var day2Val = day2.value;
  	var year2Val = year2.value;
  
  	if ((month1Val ==null && day1Val ==null && year1Val ==null) || (month1Val =="" && day1Val =="" && year1Val =="")) {
		return true;
  	} else {
	  	var dateOne = new Date(year1Val, month1Val - 1, day1Val);
  	}
	
  	if ((month2Val ==null && day2Val ==null && year2Val ==null) || (month2Val =="" && day2Val =="" && year2Val =="")) {
		return true;
  	} else {
	  	var dateTwo = new Date(year2Val, month2Val - 1, day2Val);
  	}
  
 	if(dateOne <= dateTwo){
  		alertMe('GL022',dateString1,dateString2);
		return false;
 	} 
	}
return true;
}

//Function used to open a Help pop up window when the user presses CTRL + SHIFT+H
function openHelpWindow(){
	if (document.all&&event.keyCode==8){
		if (event.srcElement.name != null){
			if(event.srcElement.type != 'button' && event.srcElement.type != 'image' && event.srcElement.type != 'submit') {	
				val=event.srcElement.HELPID;
				var nam = event.srcElement.name;
				var frmName = getElementFormName(nam);
				/*var pageId1 = "document."+frmName+".PAGE_ID.value"; 
				var pageId = eval (pageId1);*/ 
				var pageId = document.getElementById("PAGE_ID").value;
				
				/*****************************************************************************/
				if( this.frames.name == "searchResults" || this.frames.name == "updateResult"){
					try{
						pageId = document.getElementById("PARENT_PAGE_ID").value;
					}catch(e){}
				}
				/*****************************************************************************/
				var url = '/HelpController?action=onlinehelp&PAGE_ID=' + pageId + '&FIELD_NAME=' + val;	  			
				window.open(url,'FieldHelpPage','resizable=yes,width=300,height=400');
			}else{
				alertMe('GL023');
			}
		}else{
			alertMe('GL024');
		}
	}
	if(handleEnterKey() == false && enterKey == false){  
		return false;
	}
	else
	{
		return true; 
	}
}
document.onkeypress=openHelpWindow

//Following 2 functions are used to validate moving the contents of one list box to another
//1. Function to validate that atleast one value is selected in the 'from' list box
function doAdd(from,to,msg) {
  if (from.selectedIndex < 0) {
    alertMe('GL025',msg);
	return false;  
  } else {
	  clearMessages();
	  rowsMove('document.form1',from,to,true); 
  	return false;    
  } 
}

//2. Function to remove the selected values from listbox
function doRemove(from) {
	if (from.selectedIndex < 0) {
    	alertMe('GL026');
		return false;  
  	} else {
   		rowsRemove(from); 
   		return false;
  	}
}

//Function to validate that Phone number can't start with zero
function flZero(field){
	var thisValue = field.value;
	var name = field.name;
	var thisLength = field.value.length;
	for (var i = 0; i != thisLength; i++){
		aChar = thisValue.charAt(0);
		if(aChar == "0"){
		alertMe('GL027',field);
		return false;
		}
	}
	return true;
  }

//Function to validate that the field value doesn't have leading spaces
function noSpace(field){
	var val = field.value;
	if (val.charAt(0)==" ") {
	alertMe('GL028',field);
	return false;}
	else return true;
}

//Function validates that the field value is a valid EDG number
function edgNumValidator(fieldName){
	var intEdgNum =0;
	var edgNumber = fieldName.value;
	if(edgNumber == null || edgNumber == ""){
			return true;
	}
	if (isNumeric(fieldName)){
		intEdgNum = parseInt(edgNumber,10);//Modified by Malathi - to set base 10
	  	if(intEdgNum <= 0 || edgNumber.length > 9){
			alertMe('GL029');	
			return false;	
	  	}
	}
	else
	{
		return false;
	}
}

//Function validates that the field value is a valid Case number
function caseNumValidator(fieldName){
	var caseNumber = fieldName.value;
	if(caseNumber == null || caseNumber == ""){
			return true;
	}
	if(!(isCaseNum(fieldName))){
		alertMe('GL030');	
		return false;
	}
	else
	{
	   return true;
	}
}

//Function checks the MaxLength of the textArea.
function checkMaxLength(FieldName,maxLimit) {
	var val = FieldName.value;
		if (FieldName.value.length > maxLimit) 
		{
			alertMe('GL031',maxLimit,FieldName);
			return false;
		}
		return true;//Added by Malathi on Jun 21, 2002
}

//Function compares 2 times
function comparetime(t1, t2) {
	if ( (t1.value != null && t1.value != "" && t2.value == "") || (t2.value != null && t2.value != "" && t1.value == "") ){
		alertMe("GL046",t1,t2);
	}
		
	if (t1.value != null && t1.value != "" && t2.value != null && t2.value !== ""){
		date1 = new Date(t1.value);
		date2 = new Date(t2.value);
		if(date2.getDate() != date1.getDate()){
			alertMe('GL032');		
			return false;
		}else if (date2.getTime() < date1.getTime()) {
			alertMe('GL033');		
			return false;
		}else if (date2.getTime() == date1.getTime()) {
			alertMe('GL034');		
			return false;
		}
	}
}
	
//Function to validate that field value can't be zero
function isZero(field) {
	if(field.value == "") return true;
	thisValue = field.value;
	ret = isNumeric(field);
	if(!ret) {
		return false;
	}
	else
	{
		res = parseInt(thisValue, 10)
		if(res == "0") {
			alertMe('GL035',field);
			return false;
		}
	} 
	return true;
}

//Function to validate that field value can't be zero
function isZipCodeZero(field) {
	if(field.value == "") return true;
	thisValue = field.value;
	ret = isZipCodeNumeric(field);
	if(!ret) {
		return false;
	}
	else
	{
		res = parseInt(thisValue, 10)
		if(res == "0") {
			alertMe('M0011',field);
			return false;
		}
	} 
	return true;
}


//Function to move a text value to a list box
function textToList(txtobj, selobj){	
	objlen = selobj.length;			
	trimSpaces(txtobj);
	if(isComplete(txtobj)){
		txt = txtobj.value;			
		if(isOptionExists(selobj, txt)){ 
			alertMe('GL037');	
			txtobj.value="";
		}
		else{//If Option does not exist
			selobj.options[objlen] = new Option(txt, txt);
			txtobj.value="";
		}
	}
	return false;
}

//Function used to ensure that the characters entered in the textarea are either AlphaNumeric or
// the special characters given.If 'enter' = 'Y' then enter will be allowed.
function checkSpecialChars(FieldName,maxLength,validChars,enter) {
	var val = FieldName.value;
	for (var i=0, len= FieldName.value.length, valid=validChars ; i<len ; i++) {
	var substr = val.substring(i,i+1);
		if (valid.indexOf(substr) == -1){
			if(substr < "0" || substr > "9" ){
				if (substr < "a" || substr > "z"){
					if (substr < "A" || substr > "Z"){
						if(enter == "Y"){
							if(substr != '\r' && substr != '\n'){
								alertMe('GL038',FieldName);
       							return false;
							}
						}
						else
						{
							alertMe('GL038',FieldName);
       						return false;
       					}
           			}
          		}
           	}
   	 	}
  	}
  	return checkMaxLength(FieldName,maxLength);
}

/*
This function validates the address tag.If any one of the fields other than street name, city,state and zip is 
entered it will throw error.
If none of the fields are entered in the address tag it will not throw any error.
*/

function chkAddress(str,frac,dir,stname,sttype,dweltype,dwelnum,adline2,county,city,state,country,zip5,region) {

var str1       = doTrim(str.value);
var frac1      = doTrim(frac.value);
var dir1       = doTrim(dir.value); 
var stname1    = doTrim(stname.value);
var sttype1    = doTrim(sttype.value);
var dweltype1  = doTrim(dweltype.value);
var dwelnum1   = doTrim(dwelnum.value);
var adline21   = doTrim(adline2.value);
var county1    = doTrim(county.value);
if(county1 == 'noSuchField') county1="";
var city1      = doTrim(city.value);
var state1     =  doTrim(state.value);
var country1   =  doTrim(country.value);
if(country1 == 'noSuchField') country1="";
var zip51       = doTrim(zip5.value);
var region1       = doTrim(region.value);
if(region1 == 'noSuchField') region1="";

if ( (str1==""  || str1==null)        &&  (frac1==""  || frac1==null) &&  (dir1==""  || dir1==null)  &&(sttype1==""  || sttype1== null) &&  
	(dweltype1=="" || dweltype1==null) && (dwelnum1=="" ||dwelnum1==null )&&  (adline21=="" || adline21== null) &&  (county1=="" || county1== null ) && 
	(country1=="" || country1==null) && (stname1=="" || stname1==null ) &&  (city1=="" || city1==null)&& (state1=="" || state1== null) && 
	(zip51==""  || zip51== null) && (region1==""  || region1== null)) {
		return true;
}
else if ( str1  != null  || frac1    != null || dir1     != null || sttype1 != null || dweltype1 != null || dwelnum1 != null || adline21 != null ||
	county1 != null || country1  != null || stname1  != null|| city1    != null || state1  != null || zip51     != null || region1 != null) {
		if(stname1 != null && city1 != null && state1 != null && zip51 != null) {
	    	return true;
		}
		else 
		{
			alertMe('GL039');
			return false;
		}
}

} 

/********************************************************************************
	*	Name		: validateListSize()
	*	Description : Function to do validate the number of Items selected in a Multiselect
	*				  Select Box
	*	param1		: list - List Box Object
	*	param2		: num  - Number of options that are alllowed to be chosen
	*	returns		: boolean
*********************************************************************************/
	function validateListSize(list,num){		
		var Counter = 0;
		var val = "Values";			
			if(num==1){
				val= "Value";
			}			
			// Loop through the select box to see how many are selected;
			for (i=0; i<list.length; i++){// If an element is selected, increment the counter
				if (list[i].selected == true){
					Counter++;
				}
			}
			// If the counter is greater than num, display an alertMe message.
			if (Counter > num){
				alertMe("GL040",num,val);
				return false;
			}
		return true;
	}

//Function to check that the field value does not exceed the max value specified
function checkMaxAllowed(field,maxVal){
var val = field.value;
var ret = isNumeric(field);
	if (! ret) return false;
	if(ret && val>maxVal){
		alertMe("GL041",field,maxVal);
		return false;
	}
	return true;
}

//Function to check if values entered in 2 fields viz: 'SSN' and 'Confirm SSN' are same
function confirmEntry(field1,field2){
	var val1 = field1.value;
	var val2 = field2.value;
	if(val1 != val2){
		alertMe('GL042',field1,field2);
		return false;
	}
	return true;
}

//Function to load the given URL
function loadURL(frm,url,tgt){ 
	try
	{
		var fr = top.document.getElementById(tgt); 
 		if(fr==null||fr == "undefined"){
    		fr = this.parent.document.getElementById(tgt);    
    		if(fr==null||fr == "undefined"){
       			fr = document.getElementById(tgt);       
    		}
		}
		if(fr!=null&&fr!="undefined"){
			fr.src = url;
		}
		else
		{
			alertMe('GL043',tgt);
		}
    }
	catch(Exception){
    	alertMe('GL043',tgt);
	}
}

//Function to check Address Line2 validations
function chkAddrLine2(StrNum,StrName,AddrLine2,flag){
	var addr2Val = AddrLine2.value;
	var strNumVal = StrNum.value;
	var strNameVal = StrName.value;

	if(flag != "Y" && (strNumVal == null || strNumVal == "") && (strNameVal == null || strNameVal == "") && (addr2Val == null || addr2Val == "")){
		return true;
	}
	if(StrNum.disabled == true && StrName.disabled == true && AddrLine2.disabled == true){
		return true;
	}	
	if(strNumVal != null && strNumVal != "" && strNameVal == ""){
		alertMe('GL044');
		return false;
	}
	return isOneComplete(StrName,AddrLine2,"Str. Name/Rural Addr","Address Line 2");
}

//Function to validate that age cannot be greater than 120 years
function computeAge(mm, dd, yy,num){
  var t, mon, day, year, DD, MM, YY, age;
  if(validateDates(mm,dd,yy))
  {
  	YY   = parseInt(yy.value);	// year of birth (4 digits)
  	MM   = parseInt(mm.value);	// month of birth (1-12)
  	DD   = parseInt(dd.value);	// date of birth (1-31)
  	t    = getToday();	// get current date
  	year = t.getFullYear();	
  	mon  = t.getMonth() + 1;
  	day  = t.getDate();	
  
  	age = year - YY;
  	if ((MM > mon) || (MM == mon && day < DD)) age --;
  	if(age > 120){
  		alertMe("GL047",mm,num);
  		return false;
  	}
  }
  return true;
}

//Function to validate SSCN
function validateSSCN(field){
	var val = field.value;
	var sub1, sub2, flag1, flag2;
	var res = parseInt(val, 10);

	if(res == "0"){
		alertMe('GL035',field);
		return false;
	}
	if(val != "" && val.length > 9){
		sub1 = val.substring(0,9);
		sub2 = val.substring(9);
		flag1 = isInteger(sub1);
		flag2 = isAlphaNumericData(field,val);
		if( flag1 == true && flag2 == true){
			return true;
		}
		else
		{
			alertMe("GL048",field);
			return false;
		}
	}
}

//Function to prevent the occurence of the given special chars in the field
function preventSpecialChars(FieldName,maxLength,inValidChars,enter) {
	var val = FieldName.value;
	for (var i=0, len= FieldName.value.length, inValid=inValidChars ; i<len ; i++) {
	var substr = val.substring(i,i+1);
		if (inValid.indexOf(substr) != -1){
			alertMe('GL049',inValidChars,FieldName);
			return false;
		}
 	}
  	return checkMaxLength(FieldName,maxLength);
}

//Function to validate SSN
function validateSSN(fld,mn,yr){
	var res, first, firstInt, sec, secInt, last, lastInt;
	var val = fld.value;
	var args = validateSSN.arguments.length;
	if(val == "") return true;
		
	if(isNumeric(fld) == true && val.length == 9 ){
		res = parseInt(val, 10);
		first = val.substring(0,3);
		firstInt = parseInt(first, 10);
		sec = val.substring(3,5);
		secInt = parseInt(sec, 10);
		last = val.substring(5);
		lastInt = parseInt(last, 10);	

		if(res =="0"){
			alertMe('M0015',fld);
			return false;
		}
		if(firstInt < 0 || firstInt > 772 || firstInt == 588 || secInt == 0 || lastInt == 0 || val == "111111111" || val == "333333333" || val == "666666666" || val == "010101010" || val == "123456789"){
			alertMe('M0015',fld);
			return false;
		}
		
		if(yr != "" && mn != ""){
			if((val == "222222222" && mn != "1" && yr != "1937") || (val == "444444444" && mn != "0" && yr != "1914") || (val == "555555555" && mn != "11" && yr != "1976") ){
				alertMe('M0015',fld);
				return false;
			}
		}
				
		if(args > 3 && arguments[3] != null){
			return confirmEntry(fld,arguments[3]);
		}
	}
	else
	{
		return false;
	}
	return true;
}


function validateSSNConditionally(depField,depValue,fld,mn,yr){
	if(depField.value == depValue){				
		return validateSSN(fld,mn,yr);		
	}
	return true;

}
//Funtion to check if time is complete
function isTimeComplete(hr,mn,ampm,tgt){
	if(hr.disabled && mn.disabled && ampm.disabled) return true;
	if(hr.value == " " && mn.value == " " && ampm.value == " "){
		alertMe('GL003',tgt);
		return false;
	}
	return true;
}

/*
Function to check if the given number is a decimal.
dec - number of decimal places allowed
maxVal - Max value allowed
*/
function isDecimal(field,dec,maxVal){
	var val = field.value;
	
	for (var i=0, len=val.length, valid='0123456789.' ; i<len ; i++) {
		var substr = val.substring(i,i+1);
		var substr1 = val.indexOf(substr);
		var substr2 = len - substr1;
			if (valid.indexOf(substr) == -1 || (substr=="." && substr2>dec+1) || (val>maxVal) ){
            	alertMe('GL001',field);
            	return false;
       	 	}
	   	}
}

	function isCompleteFields(elemIdArr,lOperator){	
	var errElemIds = new Array();	
	var alertOr = false;
	for(var j=0;j<elemIdArr.length;j++){		
		if(document.getElementById(elemIdArr[j])==null){			
			return false;
		}
		var flag = isDataComplete(document.getElementById(elemIdArr[j]));		
		if(lOperator=="AND"){//All fields			
			if(!flag){
				errElemIds.push(elemIdArr[j]);
			}
		}
		else if(lOperator=="OR"){//Atleast one field			
			if(flag){
				return true;	
			}
			else{
				alertOr =true;
			}
		}
	}	
		if(lOperator=="OR"&&alertOr){
			errElemIds = elemIdArr;
		}
		if(errElemIds.length>1){
			var msg = getElementLabels(errElemIds);
			if(lOperator=="OR"){
				alertMe("GL053", msg);
			}
			else if(lOperator=="AND"){
				alertMe("GL054", msg);
			}

			return false;
		}
		return true;
}


function filterValues(selfield,obj1,obj2,obj3){   
	try{
		var filter = selfield;
		var hidden1 = obj1;
		var displayObj = obj2;
		var hidden2 = obj3;
		var dval ;
		var dtext ;  
		var count =  displayObj.options.length; 
		for(var j=count-1;j>-1;j--){  
			displayObj.options[j] = null;
		}
		dval = " ";
		dtext = " ";
		var newopt = new Option(dtext,dval)
		displayObj.options[displayObj.options.length] = newopt;
		
		for(var i=0;i<hidden2.options.length;i++){			
			if(filter.value == hidden2.options[i].value){
				dval = hidden1.options[i].value;    
				dtext = hidden1.options[i].text;
				var newopt = new Option(dtext,dval)
				displayObj.options[displayObj.options.length] = newopt;
			}
			 
		}
			hidden2.style.display='none';
			hidden1.style.display='none';
	}catch(e){
	}
}	
function isCompleteConditionally(depField,depValue,targetField){	
	if(depField.type =="radio" || depField.type =="checkbox"){
   	 	if(depField.checked == true){
   	 		return isComplete(targetField);			
   	 	}
   	 }
   	 else{	
		if(depField.value == depValue){		
			return isComplete(targetField);		
		}
	}
	return true;
}

function isNumericConditionally(depField,depValue,targetField){	
	if(depField.type =="radio" || depField.type =="checkbox"){
   	 	if(depField.checked == true){
   	 		return isNumeric(targetField);			
   	 	}
   	 }
   	 else{	
		if(depField.value == depValue){				
			return isNumeric(targetField);		
		}
	}
	return true;
}

function isZipCodeNumericConditionally(depField,depValue,targetField){	
	if(depField.type =="radio" || depField.type =="checkbox"){
   	 	if(depField.checked == true){
   	 		return isZipCodeNumeric(targetField);		
   	 	}
   	 }
   	 else{	
		if(depField.value == depValue){				
			return isZipCodeNumeric(targetField);		
		}
	}
	return true;
}



function isAlphaNumericConditionally(depField,depValue,targetField){	
	if(depField.type =="radio" || depField.type =="checkbox"){
   	 	if(depField.checked == true){
   	 		return isAlphaNumeric(targetField);
   	 	}
   	 }
   	 else{
		if(depField.value == depValue){				
			return isAlphaNumeric(targetField);		
		}
	}
	return true;
}
function isStreetNumberConditionally(depField,depValue,targetField){	
	if(depField.type =="radio" || depField.type =="checkbox"){
   	 	if(depField.checked == true){
   	 		return isStreetNumber(targetField);
   	 	}
   	 }
   	 else{
		if(depField.value == depValue){				
			return isStreetNumber(targetField);		
		}
	}
	return true;
}
function isUnitConditionally(depField,depValue,targetField){	
	if(depField.type =="radio" || depField.type =="checkbox"){
   	 	if(depField.checked == true){
   	 		return isUnit(targetField);
   	 	}
   	 }
   	 else{
		if(depField.value == depValue){				
			return isUnit(targetField);		
		}
	}
	return true;
}
function formatDateConditionally(depField,depValue,targetField1,targetField2,targetField3,actualField){	
	if(depField.type =="radio" || depField.type =="checkbox"){
   	 	if(depField.checked == true){
   	 		//return formatDateForCheckBox(targetField1,targetField2,targetField3,actualField);		
   	 		return formatDate(targetField1,targetField2,targetField3,actualField);		
   	 	}
   	 }
   	 else{
		if(depField.value == depValue){				
			return formatDate(targetField1,targetField2,targetField3,actualField);		
		}
	}
	return true;
}


function isDateCompleteConditionally(depField,depValue,targetField1,targetField2,targetField3){	
	if(depField.type =="radio" || depField.type =="checkbox"){
   	 	if(depField.checked == true){
   	 		return isDateComplete(targetField1,targetField2,targetField3);		
   	 	}
   	 }
   	 else{
		if(depField.value == depValue){	
			return isDateComplete(targetField1,targetField2,targetField3);		
		}
	}
	return true;
}


function isAlphaConditionally(depField,depValue,targetField){	
	if(depField.type =="radio" || depField.type =="checkbox"){
   	 	if(depField.checked == true){
   	 		return isAlpha(targetField);	
   	 	}
   	 }
   	 else{
		if(depField.value == depValue){				
			return isAlpha(targetField);		
		}
	}
	return true;
}


function isCurrencyConditionally(depField,depValue,targetField){	
	if(depField.type =="radio" || depField.type =="checkbox"){
   	 	if(depField.checked == true){
   	 		return isCurrency(targetField);		
   	 	}
   	 }
   	 else{
		if(depField.value == depValue){				
			return isCurrency(targetField);		
		}
	}
	return true;
}
//Ramesh Added on 01/18/2005 for hours worked in ICEMI page
 function isHoursConditionally(depField,depValue,targetField){	
	if(depField.type =="radio" || depField.type =="checkbox"){
   	 	if(depField.checked == true){
   	 		return isHours(targetField);		
   	 	}
   	 }
   	 else{
		if(depField.value == depValue){				
			return isHours(targetField);		
		}
	}
	return true;
}

function isChecked(field) {
  	if(!field.checked) {
  		alertMe('M0027',field);
  		return false;	
  	}
  	return true;
}  	

function isCheckedConditionally(depField,depValue,targetField){	
  	if(depField.value == depValue){				
  		return isChecked(targetField);	
  	}
  	return true;
}  

function checkZipConditionally(depField,depValue,targetField){	
  	if(depField.value == depValue){				
  		return checkZip(targetField);	
  	}
  	return true;
}  

function findFirst()
{
	if(!focusFieldExists())
	{	
		for(var i=0;i<document.all.length;i++)
		{
			
			var sTag = document.all[i].tagName.toUpperCase();
			if((sTag == "SELECT" || sTag == "TEXTAREA" || 
				(sTag == "INPUT" && document.all[i].type.toUpperCase() != "HIDDEN" &&
				 !document.all[i].disabled)))
			{
				document.all[i].focus();
				break;
			}						
		}
	}
	
	return;				
}

function focusFieldExists()
{
	if(!document.all.focusField)return false;
	
	var fullValue = document.all.focusField.value
	var fieldName = fullValue;
	var fieldIdx;
	var idx = fullValue.indexOf("[");
	if(idx > 0)
	{
		 fieldName = fullValue.substring(0, idx);
		 fieldIdx =  fullValue.substr(idx + 1,1) ; 
	}
	
	var which = document.all[fieldName];
	if(!which)return false;
	
	if(!isNaN(which.length))
		which = which[fieldIdx];
		
	if(!which || which.type.toUpperCase() == "HIDDEN")return false;
	which.focus();		
	return true;
}
//Validates the name and it allows alpha values,hypens,apostrophe and spaces.
function isNameValid(field) {

  	var val = field.value;
	val = doTrim(val);	
  	if (val==null || val.length==0) return true;
  	//var rep2 = /[A-Za-z]+[a-z]*\s*[A-Za-z]*/;
  	//var rep = /[^A-Za-z\s]+/;
	var rep2 = /[A-Za-z]+([a-z.\-\']|[\-\'])*\s*[A-Za-z\-\']*/;
	var rep = /[^A-Za-z\s\-\']+/;
  	
  	var test = val.match(rep);
  	var test2 = val.match(rep2);
  	if ((test == null) && (test2!=null) && (val.charAt(0)!= " ")) {
		return true; 
  	} else { 
    	alertMe('M0082',field);
    	return false;
  	}
}
function isNameValidConditionally(depField,depValue,targetField){	
	if(depField.type =="radio" || depField.type =="checkbox"){
   	 	if(depField.checked == true){
   	 		return isNameValid(targetField);	
   	 	}
   	 }
   	 else{
		if(depField.value == depValue){				
			return isNameValid(targetField);		
		}
	}
	return true;
}
//This method uses in assetinfo.jsp
function checkVehicleManYear(){
	try{
		var var1 = document.form1.asinrVehicleYear.value;
		var field = document.form1.asinrVehicleYear;
		var valCon = form1.asinrAssetCategory.value;
		if(valCon == "M"){
			if(var1.length == "0"){
				return true;
			}
			if (var1.length == "4"){
				var thisValue = document.form1.asinrVehicleYear.value;
				if (!isInteger(thisValue)){							
					return false;
				}						
			}else{
				alertMe('M0014',field);
				return false;
			}		
		}
																	
	}catch(e){
	}
}
//Ram : To set the focus on first hyperlink for all summary pages --- Start
function findFirstForSummary() {
try{
	 var str;
	 for(i=0;i<document.links.length;i++)
	 {
		 str = document.links[i].innerText;
		 str = trimstr(str);
		 str = str.toUpperCase();	
		 if( str == "ADD ANOTHER" || str == "DELETE" || str == "EDIT" || str == "CHANGE" || str == "REMOVE" || str == "VIEW"){
		   document.links[i].focus();
		   break;
		 }  
	 }
 }catch(e){
 }
 return;	
}

function trimstr(str){
try{
   var tmp = ""
   var count = 0
   var newArray = str.split(" ")
   for (var i=0;i<newArray.length;i++){
      if (newArray[i]!=""){
         if (count == 0)
            tmp = newArray[i]
         else
            tmp = tmp + " " + newArray[i]
         count++
      }
   }
 }catch(e){
 }
   return tmp
}
//Method to set the focus on top of the page if any javascript error 
function setFocusOnTop() {
//document.form1.isJavascriptEnabled.value = 'Y';
try{
	 var str;
	 for(i=0;i<document.links.length;i++)
	 {
		 str = document.links[i].innerText;
		 str = trimstr(str);
		 str = str.toUpperCase();	
		 if( str == "HEALTH AND HUMAN SERVICES"){
		   document.links[i].focus();
		   break;
		 }  
	 }
	 //set the focus on first field
	 findFirst();
 }catch(e){
 }
 return;	
}
//Ram : To set the focus on first hyperlink for all summary pages ---- End

//Ram: This code makes Enter key to work on buttons  -- start
 function kH(e){
 }
 document.onkeypress = kH;
 if (document.layers) document.captureEvents(Event.KEYPRESS);
  function disableEnterClick(){
  	if (window.event.keyCode == 13) {
 		window.event.keyCode =0;
 	} 
  } 

//Ram: This code makes Enter key to work on buttons  -- end

//Sucharit
//function isAlphaNumericData(field,val) {
function isStreetNameData(field,val) {
  	
  	var rep = /[^A-Za-z0-9\s.]+/;
  	var rep2 = /[A-Za-z0-9.]+([a-z]|[0-9].)*[.]*\s*[A-Za-z0-9]*/;
  	var test = val.match(rep);
  	var test2 = val.match(rep2);
  	var leng = val.length;
	if ((test == null) && (test2!=null) && (val.charAt(0)!= " ") && val.charAt(leng-1) !== " ") {
		return true; 
  	} else { 
    	return false;
  	}
}

function isStreetNameConditionally(depField,depValue,targetField){	
	if(depField.type =="radio" || depField.type =="checkbox"){
   	 	if(depField.checked == true){
   	 		return isStreetName(targetField);
   	 	}
   	 }
   	 else{
		if(depField.value == depValue){				
			return isStreetName(targetField);		
		}
	}
	return true;
}

function isStreetName(field) {
	var val = field.value;
	val = trimstr(val);
  	if (val==null || val.length==0) return true;
	if (isStreetNameData(field,val)) {       
		return true; 
  	} else { 
    	alertMe('M0081',field );
    	return false;
  	}
}

function isEmployerNameData(field,val) {
	//var rep = /[a-zA-Z\s@,-]/
	var rep = /[a-zA-Z&'\s@,-]/
	var rep2 = /[^a-zA-Z&'\s@,-]/
	var test1 = (val.match(rep));
	var test2 = val.match(rep2);
  	var leng = val.length;
  	field.value=val;
	if ((test2== null) && (test1 != null) && (val.charAt(0)!= " ") && val.charAt(leng-1) !== " ") {       
		return true; 		
  	} else { 
    	return false;
  	}
}

function isEmployerNameConditionally(depField,depValue,targetField){	
	if(depField.type =="radio" || depField.type =="checkbox"){
   	 	if(depField.checked == true){
   	 		return isEmployerName(targetField);
   	 	}
   	 }
   	 else{
		if(depField.value == depValue){				
			return isEmployerName(targetField);		
		}
	}
	return true;
}

function isEmployerName(field) {
	var val = field.value;
	val = trimstr(val);
  	if (val==null || val.length==0) return true;
	if (isEmployerNameData(field,val)) {       
		return true; 
  	} else { 
    	//alertMe('M0078',field );
    	alertMe('M0128',field );
    	return false;
  	}
}

function isCityNameData(field,val) {
	var rep = /[a-zA-Z-\.\s]/
	var rep2 = /[^a-zA-Z-\.\s]/
	var test1 = (val.match(rep));
	var test2 = val.match(rep2);
  	var leng = val.length;
  	field.value=val;
	if ((test2== null) && (test1 != null) && (val.charAt(0)!= " ") && val.charAt(leng-1) !== " ") {       
		return true; 		
  	} else { 
    	return false;
  	}
}

function isCityNameConditionally(depField,depValue,targetField){	
	if(depField.type =="radio" || depField.type =="checkbox"){
   	 	if(depField.checked == true){
   	 		return isCityName(targetField);
   	 	}
   	 }
   	 else{
		if(depField.value == depValue){				
			return isCityName(targetField);		
		}
	}
	return true;
}

function isCityName(field) {
	var val = field.value;
	val = trimstr(val);
  	if (val==null || val.length==0) return true;
	if (isCityNameData(field,val)) {       
		return true; 
  	} else { 
    	alertMe('M0131',field );
    	return false;
  	}
}
function validateEmailConditionally(depField,depValue,targetField){	
	if(depField.type =="radio" || depField.type =="checkbox"){
   	 	if(depField.checked == true){
   	 		return validateEmail(targetField);
   	 	}
   	 }
   	 else{
		if(depField.value == depValue){				
			return validateEmail(targetField);		
		}
	}
	return true;
}
//Email validation
function validateEmail(field){
	emailStr = field.value;
	emailStr = emailStr.toLowerCase();
	if (emailStr==null || emailStr.length==0) return true;	
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><\@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) {
		alertMe('M0133',field);
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			alertMe('M0133',field );
			return false;
	   }
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			alertMe('M0133',field);
			return false;
	   }
	}
	if (user.match(userPat)==null) {
		alertMe('M0133',field);
		return false;
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alertMe('M0133',field );
				return false;
			}
		}

	}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			alertMe('M0133',field);
			return false;
	   }
	}
	if (checkTLD && domArr[domArr.length-1].length!=2 &&
		domArr[domArr.length-1].search(knownDomsPat)==-1) {
		alertMe('M0133',field );
		return false;
	}
	if (len < 2) {
		alertMe('M0133',field);
		return false;
	}
	return true;
}


