// JavaScript General Validation Scripts

var gblnSilentValidation = false;

/************************************************************
	Validation Functions (in order):
		isWhiteSpace(strInput)
		isValidChar(str,req,nType,strInfo,strExtraValidChar)
		isValidNumber(numb, cnt, IFC, req, strInfo, blnStrComp)
		isValidFullName(first, mi, last, req)
		isValidDate(vmth,vday,vyr,req)
		isDateGreater(objFromMM, objFromDD, objFromYYYY, strFromName, blnRequired, blnSingleDate,
							  objToMM, objToDD, objToYYYY, strToName)
		isValidTime(vhour,vmin)
		isValidUSZip(zip1,zip2,req)
		isValidUSAddress(add1,city,state,zip1,zip2,req)
		isValidForeignAddress(add1,city,state,zip1,zip2,req,foreign)
		isIllegalSSN(SSN)
		isValidSSN(SSN3,SSN2,SSN4,req)
		isValidFedID(FedID2,FedID7,req)
		isValidEmail(strEmail, req)
		isValidUSPhone(AreaCode,Excha,Phone,phType,req)	
		isValidUSBusPhone(AreaCode,Excha,Phone,Ext,phType,req)
		isValidMoney(objCurrTxtbx,req,dblMinAmt,dblMaxAmt,blnEqualToAmt)//unformats the money
		isValidRadio(radioControl, strAppendMsg)
		isValidTextareaLength(objTextArea,len,blnOnSubmit)
		isValidTextareaKeypress(objTextArea,len,key)
		isPositiveNumber(objMoney)
		
		isValidClaimNumber(objClaimNum, req)
		isValidPolicyNumber(objPolicyNum, req, objBusSeqNum, req2)
		isTimeGreater(objFirstHH, objFirstMI, objFirstAMPM, strFirstName, objSecondHH, objSecondMI, 
						objSecondAMPM, strSecondName)

	Functions used to format/control form fields
		textarea_onkeypress(e) //private function called by generateTextareaEvents
		textarea_onfocus(e) //private function called by generateTextareaEvents
		generateTextareaEvents(objTextarea,intLen)

		FormatMoney(objMoney, blnFormatCents) 	//formats only valid values
		UnformatMoney(objMoney) //unformats for database
		CleanMoney(strMoney)
		DeleteLeadingZeros(strNum) //Delete uncessary leading zeros

		getDropValue(objCombo)
		setDropValue(objControlName, strDropValue)
		getRadioValue(radioControl)
		setRadioValue(radioControl, radioValue)
		

	Event Functions
		getkey(e)
		autoMove(objFrom, objTo, intNumCharBeforeMove)
		setFocus(objField)
		trimStr(strText)		
		zeroBufferNum(intNumToPad, intNumOfDigits)
		EnterKeyPostBack(eventTarget, eventArgument)

	Date Functions
		dateDiff(strInterval, dtDate1, dtDate2)
		dateAdd(strInterval, dNumber, dtDateValue)
	Other Functions
		y2k(intYear)
		showBWCMsg(strMsg, blnSetFocus, objFocusTo)
************************************************************/

/************************************************************
Name:		isWhiteSpace
Purpose:	Validates to see if the string only contains white space
Input:	strInput -	The string to check for white space
Output:	True/False if the input is just spaces
************************************************************/       
function isWhiteSpace(strInput)
{	var re = /\s/g; 
	var	strWithoutSpaces = strInput.replace(re,''); 
	if (strWithoutSpaces.length == 0) 
	{	
		return true;
	}
	else
	{	
		return false;
	}
} //End of isWhiteSpace

/************************************************************
Name:		isValidChar
Purpose:	To validate (depending on the type of field) 
			what are the valid characters

Input:		str - The field that is being validated
			req - Required (0 = not required, 1 = required)			
			nType - (=0) A-Z, a-z, white space, and single quote
					(=1) A-Z, a-z
					(=2) A-Z, a-z, "-", "'", or whitespace
					(=3) A-Z, a-z, "-", "'", ".", or whitespace
					(=4) 0-9, A-Z, a-z, "-", "'", ".", or whitespace (Street address)
					(=5) V3 valid characters
					(=6) A-Z, a-z, 0-9, "-", or whitespace(policy number)
					(=7) A-Z, a-z, 0-9, "-"(policy number)
					(=8) A-Z, a-z, 0-9, "_" "-", ".", "@" Valid Email Characters
			strExtraValidChar - A string of characters that can be added to the list of valid characters (This should be used as a last resort).
			strInfo - the action of the item (enter/select/click) + the item's name (your First Name)
Output:		True/False if the characters are valid
************************************************************/      
function isValidChar(str,req,nType,strInfo,strExtraValidChar) 
{
	str.value = trimStr(str.value); // Remove any trailing spaces
	var strValidChar="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	if(strExtraValidChar !== void 0)
		strValidChar+=strExtraValidChar;

	var gchar=str.value;
	var blnCharIsValid = true;
	if((req==0) && (str.value=="")) return true;
	if((req==1) && (isWhiteSpace(gchar)))
	{
		showBWCMsg("Please " + strInfo + ".",1,str);
		return false;
	}
	
	switch(nType) //Validate A-Z, a-z and any other special chars specified below
	{
		case 0:
			strValidChar+="' ";
			break;
		case 1:
			break;
		case 2:
			strValidChar+="-' ";
			break;
		case 3:
			strValidChar+=" .'-"
			break;
		case 4:
			strValidChar+="0123456789 .'-/#"
			break;
		case 5:
			strValidChar+="1234567890-.'`,/&() " + unescape("%0a") + unescape("%0d");
			break;
		case 6:
			strValidChar+="1234567890- ";
			break;
		case 7:
			strValidChar+="1234567890-";
			break;
		case 8:
			strValidChar+="0123456789 _-.@"
			break;			
	}
	for (var i=0; i < gchar.length; i++) 
	{
		temp = "" + gchar.substring(i, i+1);
		if (strValidChar.indexOf(temp) == "-1") 
		{
			blnCharIsValid=false; break;
		}
	}
	if(blnCharIsValid) 
		return true;
	else
		showBWCMsg("Invalid characters used, please " + strInfo + " correctly.",1,str);
	return false;

} //End of isValidChar()


/************************************************************
Name:		isValidNumber
Purpose:	To validate the form field given for numbers only
Input:	numb -	Form field that contains the numerical value
		cnt -	The number of digits required 
				(=0 is there isn't a specific number of digits required)
		IFC -	The character flag to determine if the value is to be a 
				float ("f") or integer ("i") value
		req -	Required (0 = not required, 1 = required)
		strInfo - The action of the item (enter/select/click) + the item's name (your First Name)
		blnStrComp - true - does a string compare of number
Output:	True/False if the email is valid
************************************************************/       
function isValidNumber(numb, cnt, IFC, req, strInfo, blnStrComp)
{	
	numb.value = trimStr(numb.value); // Remove any trailing spaces
	var strValue=new String(numb.value);

	IFC = IFC.toUpperCase()
	if((req==0) && (numb.value=="")) return true;

	if((req==1) && (isWhiteSpace(numb.value)))
	{
		showBWCMsg("Please " + strInfo + ".",1,numb);
		return false;
	}

	if((IFC=="I") && (strValue.indexOf(".") >= 0))
		strValue="decimal"; //Since a decimal was found set strValue to non-numeric string
	if((IFC!="C") && (strValue.indexOf("$") >= 0))
		strValue="decimal"; //Since a $ was found in a non-currency # set strValue to non-numeric string

	if((cnt!=0) && (strValue.length!=cnt))
	{
		showBWCMsg("Please " + strInfo + ", using a " + cnt + "-digit number.",1,numb);
		return false;
	}
	if((blnStrComp !== void 1) && (blnStrComp))
	{
		var strValidChar;
		var strTemp;
		if(IFC=="F"){
			strValidChar="1234567890."; //add a decimal as a valid character for a float number
		}else{
			strValidChar="1234567890";
		}	
		for (var i=0; i < strValue.length; i++) 
		{
			strTemp = "" + strValue.substring(i, i+1);
			if (strValidChar.indexOf(strTemp) == "-1") 
			{
				showBWCMsg("Invalid characters, please " + strInfo + " using numbers only.",1,numb);
				return false; break;
			}
		}
	}
	else 
	if(isNaN(strValue))
	{
		showBWCMsg("Invalid characters, please " + strInfo + " using numbers only.",1,numb);
		return false;
	}
	return true;
} //End of isValidNumber()

/************************************************************
Name:		isValidFullName
Purpose:	Validate the full name inputted
Input:	first, mi, last - fields that contain parts of the full name
		req - Required (0 = not required, 1 = required)

Output:	True/False if the full name is valid
************************************************************/      
function isValidFullName(first, mi, last, req)
{
	if(req==0)
	{
		if(first.value=="" && mi.value=="" && last.value=="")
			return true;
	}
    if(!isValidChar(first,1,3,"enter your first name"))
		return false;
	if(!isValidChar(mi,0,1,"enter your middle initial"))
		return false;
	if(!isValidChar(last,1,2,"enter your last name")) 
		return false;
	return true;
} //End of isValidFullName() 

/************************************************************
Name:		isValidDate
Purpose:	To validate if there is a valid number of days, 
			month and the year is not before 1850

Input:	vmth - Month (Object not value
		vday - Day (Object not value)
		vyear - Year (Object not value)
		req - Required (0 = not required, 1 = required)

Output:	True/False if the date is valid
************************************************************/      
function isValidDate(vmth,vday,vyr,req) 
{
	var mon = new Array()
	mon = ["January","February","March","April","May","June","July","August","September","October","November","December"];
	var dateStr;
	var strMth=vmth.value;
	var strDay=vday.value;
	var strYr=vyr.value;

	if(req==0)
	{
		dateStr=strMth + strDay + strYr;
		if(dateStr=="") return true;
		else if(dateStr=="MMDDYYYY") return true;
	}
  
	// make sure that the MMDDYYYY is not in use
	if(!isValidNumber(vmth, 0, "I", 1, "enter a valid month",true)) return false;
	if(!isValidNumber(vday, 0, "I", 1, "enter a valid day",true)) return false;
	if(!isValidNumber(vyr, 0, "I", 1, "enter a valid year",true)) return false;
	
	if(strYr <= 1850)
	{
		showBWCMsg("The year must be greater than 1850.",1,vyr);
		return false;
	}
    
	// put the strings together
	dateStr = strMth + "/" + strDay + "/" + strYr;
	// To require a 2 digit year entry, use this line:
	// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
	// To require a 4 digit year entry, use this line instead:
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null) 
	{
		var objField

		if(strMth.length==0)
			objField = vmth;
		else if(strDay.length==0)
			objField = vday;
		else if(strYr.length!=4)
			objField = vyr;

		showBWCMsg("Date is not in a valid format.",1,objField)
		return false;
	}

	month = matchArray[1]; // parse date into variables
	day = matchArray[3];
	year = matchArray[4];
	if (month < 1 || month > 12) 
	{ 
		// check month range
		showBWCMsg("Month must be between 1 and 12.",1,vmth);
		return false;
	}
	if (day < 1 || day > 31) 
	{
		showBWCMsg("Day must be between 1 and 31.",1,vday);
		return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) 
	{
		showBWCMsg("Month "+month+" ("+mon[month-1]+") doesn't have 31 days.",1,vday)
		return false;
	}
	if (month == 2) 
	{ // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) 
		{
			showBWCMsg("February " + year + " doesn't have " + day + " days.",1,vday);
			return false;
		}
	}
  
	if(month.length < 2) vmth.value="0"+month;
	if(day.length < 2) vday.value="0"+day;
 
	return true;  // date is valid
} // End of isValidDate()

/************************************************************
Name:		isDateGreater
Purpose:	To compare a date with either the current date or a second date entered by caller(ToDate)

Input:	objFromMM		form field representing the month to check
		objFromDD		form field representing the day to check
		objFromYYYY		form field representing the day to check
		strFromName		text description of the type of date ex. "birthday" or "renewal date"
		blnRequired		From date required ( 0 - non-required;  1 - required )
		blnSingleDate	compare against current date or To Date ( 0 - current date; 1 - To date)
		objToMM			form field representing the ToDate month
		objToDD			form field representing the ToDate day
		objToYYYY		form field representing the ToDate year
		strToName		text description of the ToDate ex. "date of injury" or "renewal date"

Output:	returns false if the FromDate is greater than the ToDate or CurrentDate, etc
		showBWCMsg("The " + strFromName + " must be less than or equal to the " + strToName + " .");
************************************************************/

function isDateGreater(objFromMM, objFromDD, objFromYYYY, strFromName, blnRequired, blnSingleDate,
							  objToMM, objToDD, objToYYYY, strToName)
{
	if ( !isValidDate(objFromMM, objFromDD, objFromYYYY, blnRequired) ) return false;
		
	// if nothing has been entered and the date is valid but not required return true
	if(blnRequired == 0)
	{
		if((objFromMM.value == "") || (objFromMM.value == "MM")){return true;}
	}
	
	//Set the dateFrom to the valid data from the user or the current date
	if(blnSingleDate==0)
	{
		// if single date, load todays date for To
		//getMonth() returns index 0-11 add 1 for actual month
		d = new Date();
		dateTo = d.getMonth() + 1 + "/" + d.getDate() + "/" + y2k(d.getYear());
		strToName = "current date";
	} 
	else 
	{
		// check To date and set to a temporary variable
		if ( !isValidDate(objToMM,objToDD,objToYYYY,1) ) return false;
		dateTo = objToMM.value + "/" + objToDD.value + "/" + objToYYYY.value;
	}
	
	// check From date and set to a temporay variable
	if( !isValidDate( objFromMM, objFromDD, objFromYYYY, 1) ) return false;
	dateFrom = objFromMM.value + "/" + objFromDD.value + "/" + objFromYYYY.value;
	
	// set To and From to valid dates
	d1 = new Date(dateTo);
	d2 = new Date(dateFrom);
	
	// compare dates and return true if To date is greater than the From date and false if not
	if(d1 >= d2) 
	{
		return true;
	}
	else 
	{
		showBWCMsg("The " + strFromName + " must be less than or equal to the " + strToName + " .",0,"");
		if(objFromMM.type == "text")
			setFocus(objFromMM);
		return false;
	}
}// End of isDateGreater()

/************************************************************
Name:		isValidTime
Purpose:	To validates the time

Input:	vhour,vmin - Form field that contains the hour and 
					 minutes of the time to validate
Output:	True/False if the time is valid
************************************************************/   
function isValidTime(vhour,vmin)
{
	//timestr = vhour + ":" + vmin
	if (vhour < 1 || vhour > 12)
	{
		showBWCMsg("Hour must be between 1 and 12.");
		return false;
	}
	if(vmin.length != 2)
	{
		showBWCMsg("Minute must be 2 digits.");
		return false;
	}	
	if (vmin < 00 || vmin > 59)
	{
		showBWCMsg("Minute must be between 00 and 59.");
		return false;
	}
	return true;
} //End of isValidTime

/************************************************************
Name:		isValidUSZip
Purpose:	To validate the ZIP code
Input:	zip1 -	Form field representing the 5 digit zip code
		zip2 - 	Form field representing the +4 zip code
		req -	Required (0 = not required, 1 = required)
Output:	True/False if the ZIP code is valid
************************************************************/      
function isValidUSZip(zip1,zip2,req) 
{
	if(req==0)
	{	//if both are blank return true
		if((zip1.value=="") && (zip2.value==""))
			return true;
	}
	
	if(!isValidNumber(zip1,5,"I",1, "enter the ZIP code",true))
		return false;
	  
	if(!isValidNumber(zip2,4,"I",0, "enter the ZIP+4 code",true))
		return false;
	
	return true;
} //End of isValidUSZip()

function isValidAddress(add1,city,state,zip1,zip2,req)
{
	return isValidUSAddress(add1,city,state,zip1,zip2,req);
}

/************************************************************
Name:		isValidUSAddress
Purpose:	To validate the address
Input:	add1 -	Form field for the address line 1
		city -	Form field representing the city
		state -	Form field representing the state
		zip1 -	Form field representing the 5 digit zip code
		zip2 - 	Form field representing the +4 zip code
		req -	Required (0 = not required, 1 = required)
Output:	True/False if the address is valid
************************************************************/  
function isValidUSAddress(add1,city,state,zip1,zip2,req)
{
	if(req==0)
	{
		if(add1.value=="" && city.value=="" &&
			zip1.value=="" && zip2.value=="") return true;
	}
	if(!isValidChar(add1,1,4,"enter the street address"))
		return false;
	
	if(!isValidChar(city,1,3,"enter the city name"))
		return false;
		
	if(state.selectedIndex==0)
	{
		showBWCMsg("Please select a state.",0,"");
		state.focus();
		return false;
	}
	return isValidUSZip(zip1,zip2,1);
} //End of isValidUSAddress()

/************************************************************
Name:		isValidForeignAddress
Purpose:	To validate either a US address or a foreign address.  The functions
			checks to see if the foreign address text box exists and if has empty.
			If the foreign address is not empty then the add1 must be entered and 
			all other fields must be blank.
			
Input:	add1 -	Form field for the address line 1
		city -	Form field representing the city
		state -	Form field representing the state
		zip1 -	Form field representing the 5 digit zip code
		zip2 - 	Form field representing the +4 zip code
		req -	Required (0 = not required, 1 = required)
		
Output:	True/False if the address is valid
************************************************************/  
function isValidForeignAddress(add1,city,state,zip1,zip2,req,foreign)
{
	var objInvalidField;
	if (foreign.value == "")
	{
		return isValidUSAddress(add1,city,state,zip1,zip2,req);
	}

	if (! city.value == "")
		objInvalidField=city;
	else if (!state.selectedIndex == 0)
		objInvalidField="";
	else if (!zip1.value == "")
		objInvalidField=zip1;
	else if (!zip2.value == "")
		objInvalidField=zip2;
	else if (isWhiteSpace(add1.value))
	{
		showBWCMsg("Please enter the street of the foreign address.",1,add1);
		return false;
	}
	else
		return true;
		
	if(objInvalidField=="")
	{
		showBWCMsg ("When entering a foreign address, enter only the Street Address and the Foreign Address.",0,"");
		state.focus();
	}
	else
		showBWCMsg ("When entering a foreign address, enter only the Street Address and the Foreign Address.",1,objInvalidField);
	return false;

} //End of isValidForeignAddress()

/************************************************************
Name:		isIllegalSSN
Purpose:	To check any invalid sequences of SSN's 
			SHOULD MATCH V3 VALIDATION
Input:	SSN - The SSN in the format without -'s
Output:	True/False if the SSN is valid
************************************************************/      
function isIllegalSSN(SSN3, SSN2, SSN4)
{
	var SSN = SSN3 + SSN2 + SSN4;
	if (isNaN(SSN))	return true;

	if (SSN=="123456789" || SSN=="000000000" || SSN=="111111111" || 
	    SSN=="222222222" || SSN=="333333333" || SSN=="444444444" ||
	    SSN=="555555555" || SSN=="666666666" || SSN=="777777777" ||
        SSN=="888888888" || SSN=="999999999" || SSN=="012345678")
	{
		return true
	}
	if (SSN3=="000" || SSN3=="666" || (SSN3 >= 734 && SSN3 <= 749) || SSN3 > 772)
	{
		return true;
	}
	if (SSN2=="00" || SSN4=="0000")
	{
		return true;
	}
	return false;	 
} //End of isIllegalSSN()

/************************************************************
Name:		isValidSSN
Purpose:	To validate the SSN for invalid sequences or characters
Input:	SSN3,SSN2,SSN4 -	Form fields representing the SSN
		req -				Required (0 = not required, 1 = required)
		
Output:	True/False if the SSN is valid
************************************************************/      
function isValidSSN(SSN3,SSN2,SSN4,req)
{	
	var strSSN3 = SSN3.value = trimStr(SSN3.value)
	var strSSN2 = SSN2.value = trimStr(SSN2.value)
	var strSSN4 = SSN4.value = trimStr(SSN4.value)
	
	var SSN=strSSN3 + strSSN2 + strSSN4;
	if((req==0) && (SSN=="")) return true;
	
	if(isIllegalSSN(strSSN3,strSSN2,strSSN4))
	{
		showBWCMsg ( strSSN3 + "-" + strSSN2 + "-" + strSSN4 + " \nis NOT a valid Social Security Number.\nPlease try again.",1,SSN3);
		return false;
	}
	else if(SSN.length != 9)
	{
		showBWCMsg("The Social Security Number you \nentered is not 9 digits long.\nPlease try again.",0,"");
		if(strSSN3.length != 3)
		{
			setFocus(SSN3);
		}
		else if(strSSN2.length != 2)
		{
			setFocus(SSN2);
		}
		else if(strSSN4.length != 4)
		{
			setFocus(SSN4);
		}
		return false;
	}
	return  true	
} // End of isValidSSN()

/************************************************************
Name:		isValidFedID
Purpose:	To validate the Fed ID for invalid characters
Input:	FedID2,FedID7 -	Form fields representing the Fed ID
		req	- Required (0 = not required, 1 = required)
		
Output:	True/False if the Fed ID is valid
************************************************************/      
function isValidFedID(FedID2,FedID7,req)
{	
	if((FedID2.value + FedID7.value == "") && (req==0)) return true;
	if(!isValidNumber(FedID2, 2, "I", 1, "enter Federal ID",true))
		return false;
	if(!isValidNumber(FedID7, 7, "I", 1, "enter Federal ID",true))
		return false;
	return true;
} // End of isValidFedID()

/************************************************************
Name:		isValidEmail
Purpose:	To validate the email address for invalid characters
Input:	Email -	Form field representing the email address
		req -	Required (0 = not required, 1 = required)
Validation Rules:
			The only valid characters are A-Z, a-z,0-9, '_', '-', '.' , '@'.
			no more than one "@" in an address.
			allow multiple "." but not consecutively ("..").
			not allow "@."  ".@" or "_@" "@_" or  "-@" "@-"
			not allow spaces.
			not allow the ampersand or "." or "-" or "_"  in the first position or the last position.
			not allow double dashes, double underscores but does allow single dashes and single underscores		

Output:	True/False if the email is valid

************************************************************/       
function isValidEmail(Email,req)
{
	if((req==0) && (Email.value=="")) return true;
	
	//must be a valid character 
	if(!isValidChar(Email,req,8,"enter a valid email address"))
	{
		return false;
	}

	var re = /^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$/
	
	if (!(Email.value.match(re)))
	{
		showBWCMsg("Please enter a valid email address.", 1, Email);
		return false;	
	}
	if (Email.value.indexOf("--") > 0)
	{
		showBWCMsg("Please enter a valid email address.", 1, Email);
		return false;
	}
	if (Email.value.indexOf("@_") > 0)
	{
		showBWCMsg("Please enter a valid email address.", 1, Email);
		return false;
	}
	if (Email.value.indexOf("__") > 0)
	{
		showBWCMsg("Please enter a valid email address.", 1, Email);
		return false;
	}
        
	
	return true;
}

/************************************************************
Name:		isValidUSPhone
Purpose:	To validate the business phone

Input:	AreaCode -	Form field representing the area code
		Excha - Form field representing exchange portion of the phone #
		Phone	- Form field representing line of the phone #
		Ext - Form field representing extension of the phone #
		phType -  Phone Type (0 = "Phone", 1 ="Fax")
		req -	Required (0 = not required, 1 = required)
		
Output:	True/False if the phone is valid
************************************************************/      
function isValidUSPhone(AreaCode,Excha,Phone,phType,req) 
{
	// all values must be passed as objects
	var ptype;
	if(phType == 0) ptype="phone";
	else if(phType == 1) ptype="fax";
   
	PhoneNum = AreaCode.value + Excha.value + Phone.value;
	if((req==0) && (PhoneNum.length==0))
		return true;
 
	// Area Code
	if(!isValidNumber(AreaCode, 3, "I", 1, "enter the area code for the " + ptype + " number",true)) return false;
	if(!isValidNumber(Excha, 3, "I", 1, "enter the exchange for the " + ptype + " number",true)) return false;
	if(!isValidNumber(Phone, 4, "I", 1, "enter the line number for the " + ptype + " number",true)) return false;

	return true;
} //End of isValidUSPhone()

/************************************************************
Name:		isValidUSBusPhone
Purpose:	To validate the business phone

Input:	AreaCode -	Form field representing the area code
		Excha - Form field representing exchange portion of the phone #
		Phone	- Form field representing line of the phone #
		Ext - Form field representing extension of the phone #
		phType -  Phone Type (0 = "Phone", 1 ="Fax")
		req -	Required (0 = not required, 1 = required)
		
Output:	True/False if the business phone is valid
************************************************************/      
function isValidUSBusPhone(AreaCode,Excha,Phone,Ext,phType,req)
{
	var ptype;
	if(phType == 0) ptype="phone";
	else if(phType == 1) ptype="fax";

	if(isValidUSPhone(AreaCode,Excha,Phone,phType,req))
	{
		if(AreaCode.value != "") //If user filled out a correct phone number
		{
			if(Ext.value != "")
				return(isValidNumber(Ext,0,"I",0,"enter the extension for the " + ptype + " number",true));
		}
		else //if user left the phone number empty
		{
			if(trimStr(Ext.value) != "")
			{
				showBWCMsg("Please enter the " + ptype + " number completely.",true,AreaCode);
				return false;
			}
		}
		
		return true;
	}
	return false;
} // End of isValidUSBusPhone()

/************************************************************
Name:		isValidMoney
Purpose:	To validate money

Input:	objCurrTxtbx -	Form field representing the currency
		req -	Required (0 = not required, 1 = required)
		
Output:	True/False if money is valid
************************************************************/      
function isValidMoney(objCurrTxtbx,req,dblMinAmt,dblMaxAmt,blnEqualToAmt)
{
	
	var strCurr = new String(objCurrTxtbx.value);
	var strTemp = strCurr; 
	
	//regula expression to validate money
	var re = /^(-|\()?[\$]?[0-9][0-9,\,]*[\.]?[0-9]{0,2}(-|\))?$/
	
	if (strCurr.length > 0)
	{
		if(strCurr.match(re))
		{
			if(strCurr.indexOf("-") == strCurr.lastIndexOf("-") && strCurr.lastIndexOf(")") >= strCurr.indexOf("(") && strCurr.lastIndexOf(")") * strCurr.indexOf("(") >= 0)
			{
				//if	"-" (minus) is at only one place	and 
				//		")" comes in after "("				and
				//		"(" and ")" both present or both not present
				//		expression is VALID. Keep going...
			}
			else
			{
				showBWCMsg("Please enter valid value for money", 1, objCurrTxtbx);
				return false;
			}
		}
		else
		{
			showBWCMsg("Please enter valid value for money", 1, objCurrTxtbx);
			return false;
		}
	}
	
	strCurr = CleanMoney(strCurr);
	objCurrTxtbx.value = strCurr;
	
	if(!isValidNumber(objCurrTxtbx, 0, "C", req, "enter an amount", false)) return false;
	
	objCurrTxtbx.value = strTemp;
	
	if(strCurr == "") return true;
	
	//Default scenario since developer specified == then compare properly
	if(blnEqualToAmt === (void 0) || (blnEqualToAmt))
	{
		//If the Min Amt is defined compare it to the Amt inputted
		if((dblMinAmt !== (void 0)) && (dblMinAmt > strCurr))
		{
			showBWCMsg("Please enter an amount equal to or larger than $" + parseFloat(dblMinAmt) + ".",1,objCurrTxtbx);
			return false;
		}

		//If the Max Amt is defined compare it to the Amt inputted
		if((dblMaxAmt !== (void 0)) && (dblMaxAmt < strCurr))
		{
			showBWCMsg("Please enter an amount equal to or smaller than $" + parseFloat(dblMaxAmt) + ".",1,objCurrTxtbx);
			return false;
		}
	}
	else //If developer didn't specify for the amount to be ==, use > <
	{
		//If the Min Amt is defined compare it to the Amt inputted
		if((dblMinAmt !== (void 0)) && (dblMinAmt >= strCurr))
		{
			showBWCMsg("Please enter an amount larger than $" + parseFloat(dblMinAmt) + ".",1,objCurrTxtbx);
			return false;
		}

		//If the Max Amt is defined compare it to the Amt inputted
		if((dblMaxAmt !== (void 0)) && (dblMaxAmt <= strCurr))
		{
			showBWCMsg("Please enter an amount smaller than $" + parseFloat(dblMaxAmt) + ".",1,objCurrTxtbx);
			return false;
		}
	}
	return true;	
} // End of isValidMoney()

/************************************************************
Name:		isValidRadio
Purpose:	To find out is a radio button was selected

Input:	radioControl - The Form field for the Radio buttons
		strAppendMsg - The message to append to the showBWCMsg
Output:	True/False if a radio button was selected is valid
************************************************************/      
function isValidRadio(radioControl, strAppendMsg)
{
	if(getRadioValue(radioControl) == "")
	{ 
		showBWCMsg("Please select " + strAppendMsg + ".",0,""); 
		return false;
	}
	return true;
} 

/************************************************************
Name:		isValidTextareaLength
Purpose:	To validate that the textarea length has maxed
Input:	objTextArea - The form field object for the textarea
		len	- The maxlength of the text area
Output:	True/False if the textarea length has been met
************************************************************/      
function isValidTextareaLength(objTextArea,len,blnOnSubmit)
{
	var x = Math.abs(objTextArea.value.length);
	if(!blnOnSubmit) x=x+1;
	if(x > len)
	{
		showBWCMsg("Too many characters. Maximum allowable length is " + len + " characters.",0,"");
		return false;
	} 
	return true;
} 

/************************************************************
Name:		isValidTextareaKeypress
Purpose:	To trap the keys raised by the onKeypress event.  
			If the backspace character was pressed return true 
			any other character count
Input:	objTextArea - The form field object for the textarea
		len	- The maxlength of the text area
		key - The ASCII key that was pressed
Output:	True/False if the textarea length has been met 
		True if backspace was pressed
************************************************************/      
function isValidTextareaKeypress(objTextArea,len,key)
{
	//If a backspace is pressed don't count the length because NN and IE handle it differently
	if(key != 8)
	{
		return(isValidTextareaLength(objTextArea, len));
	}
	else  //Return True because Netscape traps backspace characters
	{
		return(true);
	}
} //End of isValidTextareaKeypress

/************************************************************
Name:		isPositiveNumber
Purpose:	To ensure the textfild amount is greater than 0
Input:		objMoney
Output:		True/False  if the objMoney value exists
			True if amount is greater than 0
************************************************************/      
function isPositiveNumber(objMoney)
{
	//change the CR sign to negative number "-" sign
	var TempMoney=CleanMoney(objMoney.value);
	if (TempMoney.search("-")>=0)
	{
		return(false); 
	}
	else  //Return true, the amount is greater than 0
	{
		return(true);
	}
} //End of isPositiveNumber

/************************************************************
Name:		textarea_onkeypress
Purpose:	If browser is IE then just check the length otherwise
			trap the keys raised by the onKeypress event by calling 
			isValidTextKeypress  
Input:	e - is a browser event that the developer doesn't need to specify
Output:	True/False if the key pressed goes over the specfied length
		True if backspace was pressed
************************************************************/    
function textarea_onkeypress(e)
{
	if(e === void 1)
	{
		return(isValidTextareaLength(this,this.textlength));
	}
	else
	{
		return(isValidTextareaKeypress(this,this.textlength,e.which));
	}
}

/************************************************************
Name:		textarea_onfocus
Purpose:	If browser is NN then setup the onKeypress event to call 
			isValidTextareaKeypress, because NN has to have the onKeypress 
			event reset everytime it receives focus.
Input:	e - is a browser event that the developer doesn't need to specify
Output:	N/A
************************************************************/    
function textarea_onfocus(e)
{
	if(!(e === void 1))
	{
		this.onkeypress=textarea_onkeypress;
	}
}

/************************************************************
Name:		generateTextareaEvents
Purpose:	Function sets the length permissible for the input 
			field.  Also sets up the events for the textarea.
Input:	objTextarea - the Textarea that has events setup for limitations.
		intLen - the length permissible for the input box.
Output:	N/A
************************************************************/    
function generateTextareaEvents(objTextarea,intLen)
{
	objTextarea.textlength=intLen;
	objTextarea.onfocus=textarea_onfocus;
	objTextarea.onkeypress=textarea_onkeypress;
}

/************************************************************
Name:		FormatMoney
Purpose:	To validate/format the money

Input:	objMoney -	Form field that contains the money value
		blnFormatCents - (0 = format cents, 1 = don't format cents)
Output:	True/False if the currency/money is valid
************************************************************/      
function FormatMoney(objMoney, blnFormatCents) 
{
	var dblTempAmt;
	var intCurrAmt;
	var strCurrAmt;
	var intCommaAmt;
	var intCommaPos;
	var intTempDlrs, strDlrs, strCents
	gblnSilentValidation = true;
	
	if(isWhiteSpace(objMoney.value)) 	
	{
		gblnSilentValidation = false;
		return false;
	}
	if(isValidMoney(objMoney,0))
	{
		//If user typed "$" without any number, we use default number 0.00
		if(objMoney.value=="$NaN.00" || objMoney.value=="$"){
			objMoney.value=0.00;
		}
		
		//Strip off the $ sign and then clean off the leading zeros of the 
		//money or currency. 
		objMoney.value=DeleteLeadingZeros(CleanMoney(objMoney.value));
		
		dblTempAmt=objMoney.value;
		intCurrAmt=Math.abs((Math.round(dblTempAmt*100)/100));
		strCurrAmt=""+intCurrAmt;
			
		if (strCurrAmt.indexOf(".")==-1){strCurrAmt+=".00";}
		strDlrs=strCurrAmt.substr(0,strCurrAmt.indexOf("."));
		intTempDlrs=strDlrs-0;

		if((blnFormatCents === void(0)) || (blnFormatCents==0))
		{
			strCents=strCurrAmt.substr(strCurrAmt.indexOf("."));
			while (strCents.length<3){strCents+="0";}
		}
		else //cents aren't supposed to be formatted so clear the string
		{	strCents = "";	}
		
		intCommaAmt=1000;
		intCommaPos=3;

		//Increment through the amt to place commas	
		while(intTempDlrs>=intCommaAmt)
		{
		  	dLen=strDlrs.length;
			strDlrs=parseInt(""+(intTempDlrs/intCommaAmt))+","+strDlrs.substring(dLen-intCommaPos,dLen);
			intCommaAmt = intCommaAmt*1000
			intCommaPos +=4
		}

		retval = strDlrs + strCents ;
		//-- Put numbers in parentheses if negative.
		if (dblTempAmt<0) {retval="("+retval+")"}
		
		gblnSilentValidation = false;
		objMoney.value = "$"+retval;
		return true
	}
	gblnSilentValidation = false;
	return false;
}

/************************************************************
Name:		UnformatMoney
Purpose:	To unformats/validates the money value so that it can be 
			saved to the database properly

Input:	objMoney -	Form field that contains the money value
		
Output:	True/False if the currency/money is valid
************************************************************/      
function UnformatMoney(objMoney)
{
	objMoney.value = CleanMoney(objMoney.value);
} //End of UnformatMoney


/************************************************************
Name:		CleanMoney
Purpose:	To unformats the money value so that it can be 
			saved to the database properly

Input:	money -	Form field that contains the money value
		req -	Required (0 = not required, 1 = required)
		
Output:	Returns currency/money in a two decimal format stripped 
		of all non-numeric characters except(.)
************************************************************/   
function CleanMoney(strMoney)
{
	var re = /[\$\,\)]/g; 			//Strip out "$,)" from input string 
	strMoney = strMoney.replace(re , ""); 
	
	var reneg = /[\(\-]/g; 				//Replace first "(" with "-" 
	if(strMoney.search(reneg)>=0)
		return "-" + strMoney.replace(reneg , ""); 
	return strMoney; 
} //End of CleanMoney

/************************************************************
Name:	getDropValue
Purpose:	To get the combo box's (Drop-down box's) current value
Input:	objCombo - The form field's combo box
Output:	returns the values of the combo box
************************************************************/      
function getDropValue(objCombo)
{
	return(objCombo.options[objCombo.selectedIndex].value);
} //End of getDropValue()

/************************************************************
Name:		setDropValue
Purpose:	Set the value of the combo box 
Input:	objControlName - The form field's combo box
		strDropValue -	 The value to set the combo box to
Output:	None
************************************************************/      
function setDropValue(objControlName, strDropValue)
{
	for (intOptCntr = 0; intOptCntr < objControlName.length; intOptCntr++)
	{
		if (objControlName.options[intOptCntr].value == strDropValue)
		{
			objControlName.options[intOptCntr].selected = true;
		}
	}
} //End of setDropValue()

/************************************************************
Name:		getRadioValue
Purpose:	To get the radio buttons value
Input:	radioControl - The radio button form field object
Output:	returns the value set of the radio control, returns "" 
		if one doesn't exist
************************************************************/      
function getRadioValue(radioControl)
{
  for (i=0; i<radioControl.length; i++) 
  {  
    if (radioControl[i].checked == true)
    {
      return radioControl[i].value;
    }
  }
  return "";
} // End of getRadioValue

/************************************************************
Name:		setRadioValue
Purpose:	Set the value of the radio buttons
Input:	radioControl - The radio button form field object
		radioValue -	 The value to set the radio buttons to
Output:	None
************************************************************/      
function setRadioValue(radioControl, radioValue)
{
  for (i=0; i<radioControl.length; i++) 
  {  
    if (radioControl[i].value == radioValue)
    {
      radioControl[i].checked = true;
    }
  }
} // End of setRadioValue

/************************************************************
Name:		getkey
Purpose:	Event that gets the key entered
Input:	e - Event captured
Output:	Returns the character entered
************************************************************/      
function getkey(e)
{
	if (window.event)
		return window.event.keyCode;
	else if (e)
		return e.which;
	else
		return null;
}

/************************************************************
Name:		autoMove
Purpose:	Once a user has entered intNumCharBeforeMove characters in the
			objFrom, the function sets the users focus to the objTo

Input:	objFrom - the input text object that the user is moved From
		objTo	- the input text object that the user is moved To	
		intNumCharBeforeMove -	the number of characters that need 
								to be filled by objFrom before moving to objTo

Output:	Sets focus to the objTo Input field.
************************************************************/      
function autoMove(objFrom, objTo, intNumCharBeforeMove)
{ 
	var strFrom = objFrom.value;
	
	if(strFrom.length >= intNumCharBeforeMove)
	{
		if(objLastToHaveFocus == objFrom.name)
		{
			objLastToHaveFocus = "";
			objTo.value="";
			objTo.focus();
		}
	}
	else 
		objLastToHaveFocus = objFrom.name;
}

/************************************************************
Name:	setFocus
Purpose:	To set focus to the specified form element
Input:	objField - Form field to have focus
Output:	Sets focus to the inputted field
************************************************************/      
function setFocus(objField)
{
	objField.focus();
	objField.select();
}

/************************************************************
Name:	trimStr
Purpose:	To trim off any leading or trailing spaces
Input:	strText - String that needs to be trimmed
Output:	Returns the string without leading/trialing spaces
************************************************************/      
function trimStr(strText)
{
	while (strText.substring(0,1) == ' ') 
		{strText = strText.substring(1);}
	while (strText.substring(strText.length-1, strText.length) == ' ')
		{strText = strText.substring(0, strText.length-1);}
	return(strText);
}

/************************************************************
Name:	zeroPadNum
Purpose:	To add zeros to a n-digit number
Input:	intNumToPad - Number that needs to be padded
		intNumOfDigits - Number of digits to be to
Output:	Returns the number padded with zeros to satisfy the number of digits
************************************************************/      
function zeroBufferNum(intNumToPad, intNumOfDigits)
{
	while (intNumToPad.length < intNumOfDigits)
		{intNumToPad="0"+intNumToPad;}
	return(intNumToPad);
}

/************************************************************
Name:		y2k
Purpose:	To return a valid year
Input:	intYear - year
Output:	returns a 4 digit year
************************************************************/      
function y2k(intYear) 
{ 
	return (intYear < 1000) ? intYear + 1900 : intYear;
}

/************************************************************
Name:		showBWCMsg
Purpose:	To show the alert message when needed
Input:	strMsg - the message that needs to be displayed
Output:	returns msg in alert box when appropriate
************************************************************/  
function showBWCMsg(strMsg, blnSetFocus, objFocusTo)
{
	if(gblnSilentValidation == false)
	{
		alert(strMsg);
		if(blnSetFocus==1) setFocus(objFocusTo)
	}
}
/************************************************************
Name:		DeleteLeadingZeros
Purpose:	Identify uncessary leading zero(s) of the currency/money and 
			delete them
Input:		objMoney.value
Output:		return current money string without leading zeros
************************************************************/  
function DeleteLeadingZeros(strNum)
{	
	var newNumNoLeadingZeros;
	  
    while (strNum.charAt(0) == "0") {
	newNumNoLeadingZeros = strNum.substring(1, strNum.length);
	strNum = newNumNoLeadingZeros;
	}
	if (strNum == "")
	strNum = "0";
	return strNum;
}

/************************************************************
Name:		isValidClaimNumber
Purpose:		Validates a claim number
Input:		objClaimNumber, req
Output:		returns formatted claim number
************************************************************/  
function isValidClaimNumber(objClaimNumber, req)
{
	var strClaimNumber = objClaimNumber.value;
	strClaimNumber = strClaimNumber.toUpperCase()
	
	if((req==0) && (strClaimNumber.length==0)) return true;
	if((req==1) && (isWhiteSpace(strClaimNumber)))
	{
		showBWCMsg("Please enter a claim number.",1,objClaimNumber);
		return false;
	}

	//1 EX: 99[-Q-1][345678\9:1]99999
	var pattern1 = new RegExp("^[0-9]{2}[-]{0,1}[3-9]{1}[0-9]{5}$")
	if(pattern1.test(strClaimNumber)){
		return true;
	}
	
	//2 EX: [9:1-6]
	var pattern1 = new RegExp("^[0-9]{1,6}$")
	if(pattern1.test(strClaimNumber)){
		return true;
	}
	//3 EX: [9:1-6]-2[27:1]
	var pattern1 = new RegExp("^[0-9]{1,6}-2[2,7]$")
	if(pattern1.test(strClaimNumber)){
		return true;
	}  
	//4 EX: [12:1]-[9:1-6]
	var pattern1 = new RegExp("^[1,2]-[0-9]{1,6}$")
	if(pattern1.test(strClaimNumber)){
		return true;
	} 

	//5 EX: 6[78\9:1]-[9:1-6]
	var pattern1 = new RegExp("^6[7,8,9]-[0-9]{1,6}$")
	if(pattern1.test(strClaimNumber)){
		return true;
	} 
	
	//6 EX: [78:1][9:1]-[9:1-6]
	var pattern1 = new RegExp("^[7,8][0-9]-[0-9]{1,6}$")
	if(pattern1.test(strClaimNumber)){
		return true;
	} 
		
	//7 EX: [\9:1][0123456:1]-[9:1-6]
	var pattern1 = new RegExp("^9[0-6]{1}-[0-9]{1,6}$")
	if(pattern1.test(strClaimNumber)){
		return true;
	} 
	
 	//8 EX: APP[9:1-6]
	var pattern1 = new RegExp("^APP[0-9]{1,6}$")
	if(pattern1.test(strClaimNumber)){
		return true;
	} 

 	//9 EX: CD[F:0-1][9:1-6]
	var pattern1 = new RegExp("^CD[F]{0,1}[0-9]{1,6}$")
	if(pattern1.test(strClaimNumber)){
		return true;
	}
	
 	//10 EX: [LM:1][9:1-6]-2[27:1]
	var pattern1 = new RegExp("^[L,M][0-9]{1,6}-2[2,7]$")
	if(pattern1.test(strClaimNumber)){
		return true;
	}
 	//11 EX: M[ABCDEFGHJKLMPRTV:0-1][9:1-6]
	var pattern1 = new RegExp("^M[A,B,C,D,E,F,G,H,J,K,L,M,P,R,T,V]{0,1}[0-9]{1,6}$")
	if(pattern1.test(strClaimNumber)){
		return true;
	}
 	//12 EX: OD[9:1-6]
	var pattern1 = new RegExp("^OD[0-9]{1,6}$")
	if(pattern1.test(strClaimNumber)){
		return true;
	}	
 	//13 EX: OD[9:1-5]-2[27:1]
	var pattern1 = new RegExp("^OD[0-9]{1,5}-2[2,7]$")
	if(pattern1.test(strClaimNumber)){
		return true;
	}			
 	//14 EX: ODPE[9:1-6]
	var pattern1 = new RegExp("^ODPE[0-9]{1,6}$")
	if(pattern1.test(strClaimNumber)){
		return true;
	}			
 	//15 EX: ONG[9:1-6]
	var pattern1 = new RegExp("^ONG[0-9]{1,6}$")
	if(pattern1.test(strClaimNumber)){
		return true;
	}			
 	//16 EX: PE[9:1-6]
	var pattern1 = new RegExp("^PE[0-9]{1,6}$")
	if(pattern1.test(strClaimNumber)){
		return true;
	}			
 	//17 EX: PE[9:1-5]-2[27:1]
	var pattern1 = new RegExp("^PE[0-9]{1,5}-2[2,7]$")
	if(pattern1.test(strClaimNumber)){
		return true;
	}			
 	//18 EX: PE[LM:1][9:1-6]
	var pattern1 = new RegExp("^PE[L,M][0-9]{1,6}$")
	if(pattern1.test(strClaimNumber)){
		return true;
	}			
 	//19 EX: PWRE[9:1-6]
	var pattern1 = new RegExp("^PWRE[0-9]{1,6}$")
	if(pattern1.test(strClaimNumber)){
		return true;
	}			
 	//20 EX: R[LM:1][9:1-6]
	var pattern1 = new RegExp("^R[L,M][0-9]{1,6}$")
	if(pattern1.test(strClaimNumber)){
		return true;
	}			
 	//21 EX: YC[9:1-6]")
	var pattern1 = new RegExp("^YC[0-9]{1,6}$")
	if(pattern1.test(strClaimNumber)){
		return true;
	}		
	
	objClaimNumber.value = strClaimNumber;
	showBWCMsg("The claim number you have entered is in an incorrect format.",1,objClaimNumber);
	return false;	
}
/*******************************************************************************
Name:		isValidPolicyNumber
Purpose:		Checks to see that the field contains a valid policy number
Input:		txtField: The field to check ('PolicyNumber)
			txtField2: The field to check ('BusSeqNumber)
			req: A '0' or '1' value to determine if the field is required or not
			strInfo: 'The message to return if 
Output:		None
*******************************************************************************/
function isValidPolicyNumber(objPolicyNum, req, objBusSeqNum, req2) 
{
	var strPolicy		= objPolicyNum.value;
	var strBusSeq		= objBusSeqNum.value;

	if((req==0) && (strPolicy=="")) return true;
	if((req==1) && (strPolicy=="")){
		showBWCMsg('Please provide Policy Number',1,objPolicyNum);
		return false;
	}
	if(strPolicy==0){
		showBWCMsg('Please enter a non-zero value for policy number.',1,objPolicyNum);
		return false;
	}
	
	if((req2==0) && (strBusSeq=="")) return true;
	if((req2==1) && (strBusSeq=="")){
		showBWCMsg('Please provide Business Sequence Number',1,objBusSeqNum);
		return false;
	}
      
	if(!isValidNumber(objPolicyNum, 0, "I", req, "enter Policy Number", true)) return false;
	if(!isValidNumber(objBusSeqNum, 0, "I", req2, "enter Business Sequence Number", true)) return false;

	return true;
}
// isValidPolicyNumber - End
/************************************************************
Name:		isTimeGreater
Purpose:	compares two time fields where one must be greater than the other
			in this case the First Time needs to be "before" (less than or equal to) the Second Time
Input:	objFirstHH		form field representing the hour to check
		objFirstMI		form field representing the minute to check
		objFirstAMPM	form field representing the meridiem to check
		strFirstName	text description of the from time
		objSecondHH		form field representing the hour month
		objSecondMI		form field representing the minute day
		objSecondAMPM	form field representing the meridiem year
		strSecondName	text description of the to time
Output:	returns false if the First Time is greater than the Second Time and displays message:	
************************************************************/
function isTimeGreater(objFirstHH, objFirstMI, objFirstAMPM, objSecondHH, objSecondMI, objSecondAMPM)
{	

	// check validity of times, both must be present to do the comparison check
	if ( !isValidTime(objFirstHH.value,objFirstMI.value) ) {return false;}
	if ( !isValidTime(objSecondHH.value,objSecondMI.value) ) {return false;}	
	
	FirstHours	= objFirstHH.value;
	SecondHours	= objSecondHH.value;
	FirstMinutes	= objFirstMI.value;
	SecondMinutes	= objSecondMI.value;
	FirstMeridiem	= getDropValue(objFirstAMPM);
	SecondMeridiem	= getDropValue(objSecondAMPM);
	
	if (FirstMeridiem == "PM" && FirstHours != 12)		{FirstHours = parseInt(FirstHours) + 12;}
	if (SecondMeridiem == "PM" && SecondHours != 12)	{SecondHours = parseInt(SecondHours) + 12;}
	
	dateStub	= "01/01/2000";
	FirstTime	= dateStub + " " + FirstHours + ":" + FirstMinutes + ":00";
	SecondTime	= dateStub + " " + SecondHours + ":" + SecondMinutes + ":00";

	d1 = new Date(FirstTime);
	d2 = new Date(SecondTime);

	if(d1 <= d2){
		return true;
	}
	else 
	{
		objFirstHH.focus();
		return false;
	}
}// End of isTimeGreater()


/*********************************************************************
Name: dateAdd() 
Purpose: Should work just like VBScript dateAdd function.
Creator: Saibaba Korada
Input: strInterval (String expression representing the time interval you want to add.)
				yyyy (year)
				q    (quarter)
				m    (month)
				y    (day of year)
				d    (day)
				w    (weekday)
				ww   (week of year)
				h    (hour)
				n    (minute)
				s    (seconds)
				ms   (milliseconds)
	   dNumber     (Floating-point expression representing the number of intervals you want to add.) 	
	   dtDateValue (An expression representing the date and time to which the interval is to be added. 
Output: Returns a Date value containing a date and time value to which a specified time interval has been added.
*********************************************************************/
function dateAdd(strInterval, dNumber, dtDateValue){
	dNumber = new Number(dNumber);
	var dt = new Date(dtDateValue);
	switch(strInterval.toLowerCase()){
		case "yyyy": {// year
			dt.setFullYear(dt.getFullYear() + dNumber);
			break;
		}
		case "q": {		// quarter
			dt.setMonth(dt.getMonth() + (dNumber*3));
			break;
		}
		case "m": {		// month
			dt.setMonth(dt.getMonth() + dNumber);
			break;
		}
		case "y":		// day of year
		case "d":		// day
		case "w": {		// weekday
			dt.setDate(dt.getDate() + dNumber);
			break;
		}
		case "ww": {	// week of year
			dt.setDate(dt.getDate() + (dNumber*7));
			break;
		}
		case "h": {		// hour
			dt.setHours(dt.getHours() + dNumber);
			break;
		}
		case "n": {		// minute
			dt.setMinutes(dt.getMinutes() + dNumber);
			break;
		}
		case "s": {		// second
			dt.setSeconds(dt.getSeconds() + dNumber);
			break;
		}
		case "ms": {		// second
			dt.setMilliseconds(dt.getMilliseconds() + dNumber);
			break;
		}
		default: {
			return "invalid interval: '" + strInterval + "'";
		}
	}
	return dt;
}

/*********************************************************************
Name: dateDiff() 
Purpose: Should work just like VBScript dateDiff function. Unlike VBscript
		 dateDiff function it doesn't support firstdayofweek and firstweekofyear.
Creator: Saibaba Korada
Input: strInterval (String expression representing the time interval you want to add.)
				yyyy (year)
				q    (quarter)
				m    (month)
				y    (day of year)
				d    (day)
				w    (weekday)
				ww   (week of year)
				h    (hour)
				n    (minute)
				s    (seconds)
				ms   (milliseconds)
	   dtDate1 & dtDate2  (Two dates you want to use in the calculation)
	   
Output: Returns the number of intervals between two dates.
*********************************************************************/
function dateDiff(strInterval, dtDate1, dtDate2){
	var dt1 = new Date(dtDate1);
	var dt2 = new Date(dtDate2);

	// get ms between dates (UTC) and make into "difference" date
	var iDiffMS = dt2.valueOf() - dt1.valueOf();
	var dtDiff = new Date(iDiffMS);

	// calc various diffs
	var nYears  = dt2.getUTCFullYear() - dt1.getUTCFullYear();
	var nMonths = dt2.getUTCMonth() - dt1.getUTCMonth() + (nYears!=0 ? nYears*12 : 0);
	var nQuarters = parseInt(nMonths/3);	//<<-- different than VBScript, which watches rollover not completion
	
	var nMilliseconds = iDiffMS;
	var nSeconds = parseInt(iDiffMS/1000);
	var nMinutes = parseInt(nSeconds/60);
	var nHours = parseInt(nMinutes/60);
	var nDays  = parseInt(nHours/24);
	var nWeeks = parseInt(nDays/7);


	// return requested difference
	var iDiff = 0;		
	switch(strInterval.toLowerCase()){
		case "yyyy": return nYears;
		case "q": return nQuarters;
		case "m": return nMonths;
		case "y": 		// day of year
		case "d": return nDays;
		case "w": return nDays;
		case "ww":return nWeeks;		// week of year	// <-- inaccurate, WW should count calendar weeks (# of sundays) between
		case "h": return nHours;
		case "n": return nMinutes;
		case "s": return nSeconds;
		case "ms":return nMilliseconds;	// millisecond	// <-- extension for JS, NOT available in VBScript
		default: return "Invalid interval: '" + strInterval + "'";
	}
}

/************************************************************
Name:		EnterKeyPostBack
Purpose:	To submit the form while choosing which button 
			event handler gets fired on the form
************************************************************/   
function EnterKeyPostBack(eventTarget, eventArgument)
{
	if(window.event.srcElement.type == 'text')
	{
		window.event.keyCode = 10 // must make this something other than 13 <enter> so put in 10 <line feed>

		var theform = window.document.forms[0];
		theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
		theform.__EVENTARGUMENT.value = eventArgument;
		theform.submit();
	}
}
