/************************************************************
	Validation Functions (in order):
		isWhiteSpace(strInput)
		isValidChar(str,req,nType,strInfo)
		isValidNumber(numb, cnt, IFC, req, strInfo)
		isValidDate(vmth,vday,vyr,req)
		isDateGreater(objFromMM, objFromDD, objFromYYYY, strFromName, blnRequired, blnSingleDate,
							  objToMM, objToDD, objToYYYY, strToName)
		isValidUSZip(zip1,zip2,req)
		isValidUSPhone(AreaCode,Excha,Phone,phType,req)	
		isValidUSBusPhone(AreaCode,Excha,Phone,Ext,phType,req)
		isIllegalSSN(SSN)
		isValidSSN(SSN3,SSN2,SSN4,req)
		isValidEmail(strEmail, req)
		isValidMoney(objCurrTxtbx,req,dblMinAmt,dblMaxAmt,blnEqualToAmt)//unformats the money
		isValidRadio(radioControl, strAppendMsg)
		isValidTextareaLength(objTextArea,len,blnOnSubmit)
		CheckFTE(number)
		countChar(objField,intMaxLength)
		
	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) 	//formats only valid values
		UnformatMoney(objMoney) //unformats for database
		CleanMoney(strMoney)

		getDropValue(objCombo)
		getMultiSelectValues(objCombo)
		getDropText(objCombo)
		setDropValue(objControlName, strDropValue)
		setMultiSelectValues(objCombo, strSelectedValues)
		setSingleMultiSelectValue(objCombo, strSelectedValues)
		getRadioValue(radioControl)
		setRadioValue(radioControl, radioValue)
		readonlyCheckbox(objControlName)
		addElement(list, text_in, value_in) //adds a new line to a dropdown box
		clearList(list) //removes all the options from a dropdown box
		ConvertToNum(numNumber,strIntFloat) //converts a string to a number (integer or float)
		dropDecimalPlaces(intNumber, intDecimalPlaces)
		getNumOfDaysInMonth(intYearNo, intMonthNo)
		populateDays(year, field, changeField, end)
		
	Event Functions
		setFocus(objField)
		trimStr(strText)		
		launchPopup(url, width, height, top, left)
		
************************************************************/

/************************************************************
Purpose:	Gets information about the browser that is 
			critical to code other scripts correctly
Output:	Creates a browser object that has 3 items
		isNN, isIE, version 
************************************************************/
var gobjBrowser = new Object();

//Setup the default values of the object
gobjBrowser.isNN = false;
gobjBrowser.isIE = false;

//Set the appropriate value depending on the appName
if(navigator.appName.indexOf("Netscape") != -1)
{
	gobjBrowser.isNN = true;
	gobjBrowser.version = navigator.appVersion.indexOf("Netscape");
	gobjBrowser.version = parseFloat(navigator.appVersion.substring(gobjBrowser.version+8, gobjBrowser.version+12));
}
else if(navigator.appName.indexOf("Microsoft") != -1)
{
	gobjBrowser.isIE = true;
	gobjBrowser.version = navigator.appVersion.indexOf("MSIE");
	gobjBrowser.version = parseFloat(navigator.appVersion.substring(gobjBrowser.version+5, gobjBrowser.version+10));
}

var gOS
var detect = navigator.userAgent.toLowerCase();

if (!gOS)
{
	if (checkIt('linux')) gOS = "Linux";
	else if (checkIt('x11')) gOS = "Unix";
	else if (checkIt('mac')) gOS = "Mac"
	else if (checkIt('win')) gOS = "Windows"
	else gOS = "an unknown operating system";
}

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}



/************************************************************
Name:		PopupWindow
Purpose:	To popup new window where developer specifies

Input:	strURL - the url where the pop-ups source resides
		strWinName - the name of the window
		strHortAlign ("l","c" or "r") left, center, right
		strVertAlign ("t","c" or "b") top, center, bottom
		blnRelativeSizeToParent
						0 -	Inputted width / Inputted height
						1 - Inputted width + parent's width / Inputted height
						2 - Inputted width / Inputted height + parent's width
						3 - Inputted width + parent's width / Inputted height + parent's width
		intWinWidth	 - Inputted Width
		intWinHeight - Inputted Height
		blnShowToolbars	 - Should the pop-up have a toolbar true/false
Output:	Window Handle
************************************************************/    
function PopupWindow(strURL, strWinName, strHortAlign, strVertAlign, intRelativeToParent, intWinWidth, intWinHeight, blnShowToolbars)
{
	var parent	= new Array(4);	// array to hold our parent window coordinates
	var child	= new Array(4);	// array to hold our help window coordinates
	var childWindow = null;		// window handle for pop-up window							
	var strAttributes = ""			// string that states if a toolbar is needed for the pop-up
	var intNNOffset =0;
	if (document.all)										// Internet Explorer
	{
		parent[0] = window.screenLeft;						// main window X coordinate

		parent[1] = window.screenTop;						// main window Y coordinate
		parent[2] = window.document.body.clientWidth;		// main window Width
		parent[3] = window.document.body.clientHeight;		// main window Height
		if(blnShowToolbars){parent[3] -= 95;}
	}
	else if (document.layers)								// Netscape Navigator
	{
		parent[0] = window.screenX;							// main window X coordinate
		parent[1] = window.screenY;							// main window Y coordinate
		parent[2] = window.innerWidth;						// main window Width
		parent[3] = window.innerHeight;						// main window Height
		if(blnShowToolbars)
		{
			parent[3] -= 50;
			intNNOffset = window.outerHeight - parent[3]-95;
		}
		else
		{intNNOffset=window.outerHeight - parent[3]-24	}
	}
	
	if (intRelativeToParent==1 || intRelativeToParent==3)
	{	//Make sure that the width is a positive and viewable size	
		if((intWinWidth+parent[2]) > 100) 
			intWinWidth+=parent[2];	//Add the specified width to the parent window
	}
	if (intRelativeToParent>=2)
	{	//Make sure that the height is a positive and viewable size
		if((intWinHeight+parent[3]) > 100)
			intWinHeight+=parent[3];//Add the specified height to parent window
	}
	child[2] = intWinWidth;		// Assign the window width
	child[3] = intWinHeight;	// Assign the window height
		
	child[0] = parent[0]; 
	//If win centered horizontally
	if(strHortAlign=="c") 
		child[0] += (parent[2]/2 - intWinWidth/2);
		
	//If win right aligned horizontally
	else if (strHortAlign=="r")
		child[0] += (parent[2] - intWinWidth);
	
	child[1] = parent[1];
	//If win centered vertically
	if(strVertAlign=="c")
		child[1] += (parent[3]/2 - intWinHeight/2);
		
	//If win aligned vertically to the bottom of the parent
	else if(strVertAlign=="b")
		child[1] += (parent[3] - intWinHeight -5);
	
	if (document.all)	// Internet Explorer
	{	// Adjusting child window width
		child[2] +=10;
		child[3] -=10;
	}
	else
	{	//Making adjustments X-Coord, Y-Coord, Width and Height
		child[0] += 5; child[1] += intNNOffset;
		child[2] -= 10;	child[3] -= 10;
	}
	
	if(childWindow)
		childWindow.close();
	
	if((blnShowToolbars !== void(0)) && (blnShowToolbars))
		{strAttributes="toolbar=yes,location=yes, menubar=yes";}
	else {strAttributes="toolbar=no,location=no, menubar=no";}
	childWindow = window.open(strURL, strWinName, 'width='+child[2]+',height='+child[3]+',top='+child[1]+',screenY='+child[1]+',left='+child[0]+',screenX='+child[0]+',resizable,scrollbars,' + strAttributes);
	return childWindow;
}

/************************************************************
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:		isMaxLength
Purpose:	Validates to see if the length of field is within the maxlength of the table 
Input:		fieldname -	the name of the field on the form (document.form.fieldname)
			maxnumber - the max length of what can be in the form field
			strInfo - error message
Output:		True/False if the input is length of the input is OK
************************************************************/       
function isMaxLength(fieldname, maxnumber, strInfo)
{	

	fieldname.value = trimStr(fieldname.value)

	if (fieldname.value.length <= maxnumber) 
	{	
		return true;
	}
	else
	{	
		showMsg("Please shorten " + strInfo + ".  " + fieldname.value.length + " characters were used; " + maxnumber + " are allowed.", 0, fieldname);
		return false;
	}
} //End of isMaxLength


/************************************************************
Name:		isMaxLengthOtherTextArea
Purpose:	Validates to see if the length of field is within the maxlength of the table 
Input:		fieldname -	the name of the field on the form (document.form.fieldname)
			strInfo - error message
Output:		True/False if the input is length of the input is OK
************************************************************/       
function isMaxLengthOtherTextArea(fieldname,strInfo)
{	

	fieldname.value = trimStr(fieldname.value)

	if (fieldname.value.length <= 5000) 
	{	
		return true;
	}
	else
	{	
		showMsg("Please shorten " + strInfo + ".  " + fieldname.value.length + " characters were used; " + 5000 + " are allowed.",1,fieldname);
		return false;
	}
} //End of isMaxLengthOtherTextArea

/************************************************************
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, "-" (policy number)
					(=7) "N","n","P","p"  (public or non-public)
			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) 
{
	str.value = trimStr(str.value); // Remove any trailing spaces
	var strValidChar="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	var gchar=str.value;
	var blnCharIsValid = true;
	if((req==0) && (str.value=="")) return true;
	if((req==1) && (isWhiteSpace(gchar)))
	{
		showMsg("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="NnPp";
			break;
		case 8:
			strValidChar="YyNn";
			break;
		case 9:
			strValidChar+="0123456789";
			break;
		case 10:
			strValidChar="0123456789";
	}
	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
	{
		showMsg("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 - Set to ""
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)))
	{
		showMsg("Please " + strInfo + ".", 1, numb);
		return false;
	}

	if((IFC=="I") && (strValue.indexOf(".") > -1))
		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

	strValue = cleanNumber(strValue);
	strValue = String(strValue);

	if((cnt!=0) && (strValue.length!=cnt))
	{
		showMsg("Please " + strInfo + ", using a " + cnt + "-digit number.", 1, numb);
		return false;
	}
	if((blnStrComp !== void 1) && (blnStrComp))
	{
		var strValidChar="1234567890";
		var strTemp;
		for (var i=0; i < strValue.length; i++) 
		{
			strTemp = "" + strValue.substring(i, i+1);
			if (strValidChar.indexOf(strTemp) == "-1") 
			{
				showMsg("Invalid characters, please " + strInfo + " using numbers only.", 1, numb);
				return false; 
			}
		}
	}
	else 
		if(isNaN(strValue))
		{
			if (IFC == "I")
			{
				if (strInfo.length == 0)
				{
					showMsg("Invalid characters, please enter a valid whole number.",1,numb);
				}
				else
				{
					showMsg("Invalid characters, please " + strInfo + " using numbers only.",1,numb);
				}
			}
			else
			{
				if (strInfo.length == 0)
				{
					showMsg("Invalid characters, please enter a valid number.",1,numb);
				}
				else
				{
					showMsg("Invalid characters, please " + strInfo + " using numbers only.",1,numb);
				}			
			}
			return false;
		}
	return true;
} //End of isValidNumber()

/************************************************************
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.length == 2)
	{
		//do nothing
	}
	else if(strYr.length == 4)
	{
		if(strYr <= 1850)
		{
			showMsg("The year must be greater than 1850.",1,vyr);
			return false;
		}
    }
    else
    {
		showMsg("Please enter a valid year.",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{2,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) || (strYr.length!=2)) objField = vyr;

		showMsg("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
		showMsg("Month must be between 1 and 12.", 1, vmth);
		return false;
	}
	if (day < 1 || day > 31) 
	{
		showMsg("Day must be between 1 and 31.",1,vday);
		return false;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) 
	{
		showMsg("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)) 
		{
			showMsg("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:		isValidDateX1
Purpose:	To validate if there is a valid number of days, 
			and that month and year are populated.

Input:	strMonth - Month
		strDay - Day
		strYear - Year
		strEmptyValue - How the form field indicates no value was selected (likely empty string or zero)
		strInputName - How to refer to input field in error message
		blnAllowEmpty - indicates if blank is allowed

Output:	True/False if the date is valid
************************************************************/      
function isValidDateX1(strMonth,strDay,strYear,strEmptyValue,strInputName,blnAllowEmpty) 
{

	if ((strMonth != strEmptyValue && strDay == strEmptyValue) || (strMonth != strEmptyValue && strYear == strEmptyValue) || 
		(strDay != strEmptyValue && strMonth == strEmptyValue) || (strDay != strEmptyValue && strYear == strEmptyValue) ||
		(strYear != strEmptyValue && strMonth == strEmptyValue) || (strYear != strEmptyValue && strDay == strEmptyValue))
	{
		if (blnAllowEmpty)
		{
			alert("Please fill out the " + strInputName + " field in its entirety or leave it completely blank.");
		}
		else
		{
			alert("Please fill out the " + strInputName + " field in its entirety.");
		}		
		return false;
	}
	else if (strMonth == strEmptyValue && strDay == strEmptyValue && strYear == strEmptyValue)
	{
		return true;
	}
	
	// at this point we know date field has been completely filled out
	// make sure that the values sent in are valid
	var intMonth = new Number(strMonth);
	var intDay = new Number(strDay);
	var intYear = new Number(strYear);
	
	if (intMonth < 1 || intMonth > 12)
	{
		alert("Please select a valid month for the " + strInputName + ".");
		return false;
	}
	
	if (intDay < 1 || intDay > 31)
	{
		alert("Please select a valid day for the " + strInputName + ".");
		return false;
	}
	
	if (intYear < 2002 || intYear > 9999)
	{
		alert("Please select a valid year for the " + strInputName + ".");
		return false;
	}
	
	// we know date is generally valid, now just check day number against month and year
	
	if ((intMonth==4 || intMonth==6 || intMonth==9 || intMonth==11) && intDay == 31) 
	{
		alert("The selected month has only 30 days.");
		return false;
	}
	
	if (intMonth == 2) 
	{ // check for february 29th
		var isleap = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0));
		if (intDay > 29 || (intDay == 29 && !isleap)) 
		{
			if(isleap) alert("February " + intYear + " has only 29 days.");
			else alert("February " + intYear + " has only 28 days.");
			return false;
		}
	}
 
	return true;  
	
} // End of isValidDateX1()

/************************************************************
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 year 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
		showMsg("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 + "/" + y2k(objToYYYY.value);
	}
	
	// check From date and set to a temporay variable
	if( !isValidDate( objFromMM, objFromDD, objFromYYYY, 1) ) return false;
	dateFrom = objFromMM.value + "/" + objFromDD.value + "/" + y2k(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 
	{
		showMsg("The " + strFromName + " must be less than or equal to the " + strToName + ".", 0, "");
		if(objFromMM.type == "text")
		{
			setFocus(objFromMM);
			objFromMM.value = "";
		}
		return false;
	}
}// End of isDateGreater()

/************************************************************
Name:		addDays
Purpose:	To add a certain number of days to a date

Input:	myDate	field representing the date to add days to
		days	number of days to add to the date

Output:	returns date with days added
************************************************************/
function addDays(myDate,days)
{
	var objDate = new Date(myDate);
    return new Date(objDate.getTime() + days*24*60*60*1000);
}

/************************************************************
Name:		isYearGreater
Purpose:	To compare a year with another year

Input:	objFromYear		form field representing the year to check
		objToYear		form field representing the "to year"
		strFromName		text description of the FromYear ex. "effective year"
		strToName		text description of the ToYear ex. "end year"

Output:	returns false if the FromYear is greater than the ToYear, etc
		showMsg("The " + strFromName + " must be less than or equal to the " + strToName + " .");
************************************************************/
function isYearGreater(objFromYear, objToYear, strFromName, strToName)
{
	//if objToYear is null then return True
	if (objToYear.value == "")
	{
		return true;
	}
	
	//compare years
	if (objFromYear.value > objToYear.value)
	{
		showMsg("The " + strToName + " must be greater than or equal to the " + strFromName + ".", 0, objFromYear);
		return false;
	}
	else
	{
		return true;
	}	
}// End of isYearGreater()

/************************************************************
Name:		isYearChangeValid
Purpose:	Check if the year change made by the user is valid
			based on the Original Effective Year, New Effective 
			Year, and the Current Fiscal Year

Input:	objOrigEffYear		form field representing the original eff. year
		objNewEffYear		form field representing the new eff. year
		objCurrentFiscalYear		form field representing the current fiscal year

Output:	True/False if the year change is valid.
************************************************************/
function isYearChangeValid(objOrigEffYear, objNewEffYear, objCurrentFiscalYear)
{
	//retrieve current fiscal year
	var strCurrentFiscalYear = objCurrentFiscalYear.value
	
	//check if attribute has been used in any grant applications
	if (objOrigEffYear.value <= strCurrentFiscalYear)
		//attribute has already been used in a plan, cannot move Eff Year forward
		{
		if (objOrigEffYear.value < objNewEffYear.value)
			//user moved the eff year forward, this is not allowed because the
			//attribute has been applied to a grant application
			{
				showMsg("The Effective Year cannot be removed from any current plans.");
				return false;
			}
		}
		
	return true;
}// End of isYearChangeValid()

/************************************************************
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, 0, "I", 1, "enter the ZIP code", true))
	{
		//no need to clear coz isValidNumber will do it.	
		return false;
	}
	if(zip1.value.length != 5)
	{
		showMsg("Please enter the ZIP code, using a 5-digit number.", 1, zip1);
		return false;
	} 
	
	if(!isValidNumber(zip2, 0, "I", 0, "enter the ZIP+4 code", true))
	{
		//no need to clear coz isValidNumber will do it.
		return false;
	}
	if((zip2.value.length > 0) && zip2.value.length != 4)
	{
		showMsg("Please enter the ZIP+4 code, using a 4-digit number.", 1, zip2);
		return false;
	}
	return true;
} //End of isValidUSZip()

/************************************************************
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 #
		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;
	}
	//not checking length for line number because is valid number truncates leading zeros
	if(!isValidNumber(Phone, 0, "I", 1, "enter the line number for the " + ptype + " number",true)) 
	{
		return false;
	}
	if(Phone.value.length != 4)
	{
		showMsg("Please enter the line number for the " + ptype + " number, using a 4-digit number.", 1, Phone);
		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 != "")
			{
				//no need to setFocus, isValidNumber will do it
				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) != "")
			{
				showMsg("Please enter the " + ptype + " number completely.", true, AreaCode);
				return false;
			}
		}
		return true;
	}
	return false;
} // End of isValidUSBusPhone()

/************************************************************
Name:		isIllegalSSN
Purpose:	To check any invalid sequences of SSN's
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=='987654321' ||
	    SSN=='012345678' )
	{
		return true
	}
	if (SSN3=="000" || (SSN3 >= 650 && SSN3 <=699) ||
		(SSN3 >= 729 && SSN3 <=999))
	{
		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 SSN=trimStr(SSN3.value) + trimStr(SSN2.value) + trimStr(SSN4.value);
	if((req==0) && (SSN=="")) return true;
	
	if (isIllegalSSN(SSN3.value, SSN2.value, SSN4.value))
	{
		showMsg ( SSN3.value + "-" + SSN2.value + "-" + SSN4.value + " \nis NOT a valid Social Security Number.\nPlease try again.",1,SSN3);
		return false;
	}
	else if (SSN.length != 9)
	{
		showMsg("The Social Security Number you \nentered is not 9 digits long.\nPlease try again.",0,"");
		var tmp=SSN3.value;
		if (tmp.length != 3)
		{
			setFocus(SSN3);
			SSN3.value = "";
			return false;
		}
		tmp=SSN2.value;
		if (tmp.length != 2)
		{
			setFocus(SSN2);
			SSN2.value = "";
			return false;
		}
		tmp=SSN4.value;
		if(tmp.length != 4)
		{
			setFocus(SSN4);
			SSN4.value = "";
			return false;
		}
	}
	return  true	
} // End of isValidSSN()


/************************************************************
Name:		isValidEmail
Purpose:	To validate the email address for invalid characters
Input:	strEmail -	Form field representing the email address
		req -	Required (0 = not required, 1 = required)
		
Output:	True/False if the email is valid
************************************************************/       
function isValidEmail(strEmail, req) 
{
	if((req==0) && (strEmail.value=="")) return true;
	str=strEmail.value;
	// are regular expressions supported?
	var supported = 0;
	if (window.RegExp) 
	{
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}
	if (!supported) 
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	
	//1. There should only be one @
	//2. There can't be two periods side-by-side
	//3. There can't be a "." next to the @ symbol
	//4. There can't be just a "." in addr
	var email1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	
	//1. Email must start with a non-whitespace char
	//2. Email must have an @ symbol followed by a character [a-z0-9]
	//3. Email must have . followed 2-3 alpha chars or 1-3 numbers
	//4. There can be [] around the server/url destination
	var email2 = new RegExp("^\\S+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,9}|[0-9]{1,9})(\\]?)$");
	
	if(!email1.test(str) && email2.test(str) == false) 
	{
		showMsg("Please correct the email address.",1,strEmail);
		return false;
	}
	// setup for true or false return
	//return (!email1.test(str) && email2.test(str));
	return true;
} //End of isValidEmail()

/************************************************************
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);
		
	strCurr = CleanMoney(strCurr)
	
	if(!isValidNumber(objCurrTxtbx, 0, "C", req, "enter an amount", false)) return false;
	
	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))
		{
			showMsg("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))
		{
			showMsg("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))
		{
			showMsg("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))
		{
			showMsg("Please enter an amount smaller than $" + parseFloat(dblMaxAmt) + ".",1,objCurrTxtbx);
			return false;
		}
	}
	return true;	
} // End of isValidMoney()

/************************************************************
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)
	{
		showMsg("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:		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:	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:		getMultiSelectValues
Purpose:	To get the selected values of a multi-select list
Input:		objCombo - The form field's combo box
Output:		returns a comma-delimited string of selected values
************************************************************/  
function getMultiSelectValues(objCombo)
{
	var i;
	var strSelected = new String("");

	for(i = 0; i < objCombo.length; i++)
	{
		if (objCombo.options[i].selected)
		{
			strSelected = strSelected + objCombo.options[i].value + ",";
		}
	}	
	
	// remove the last comma from the string
	if (strSelected != "")
	{
		strSelected = strSelected.substr(0, strSelected.length - 1);
	}
	
	return strSelected;
	
} // End of getMultiSelectValues

/************************************************************
Name:		setMultiSelectValues
Purpose:	To set the selected values of a multi-select list. Clears out any options previously set to selected.
Input:		objCombo - The form field's combo box
			strSelected - A comma-delimited list of selected values
				with no space between the previous comma and the start of the next value
Output:		true
************************************************************/  
function setMultiSelectValues(objCombo, strSelected)
{
	var i;
	var j;
	var strInput = new String(strSelected);
	var arrInput = new Array();		
	arrInput = strInput.split(",");
	
	//clear out any existing values
	
	removeMultiSelectValues(objCombo)
	
	for(i = 0; i < arrInput.length; i++)
	{
		for (j = 0; j < objCombo.length; j++)
		{
			if (objCombo.options[j].value == arrInput[i])
			{
				objCombo.options[j].selected = true;
			}
		}	
	}	
	
	return true;
	
} // End of setMultiSelectValues


/************************************************************
Name:		setSingleMultiSelectValue
Purpose:	To set the selected value of one option in a multi-select list, preserves previously selected options.
Input:		objCombo - The form field's combo box
			strSelected - The option value to set as selected
Output:		true
************************************************************/  
function setSingleMultiSelectValue(objCombo, strSelected)
{
	var i;
	var j;
	var strInput = new String(strSelected);
	var arrInput = new Array();		
	arrInput = strInput.split(",");
	
	for(i = 0; i < arrInput.length; i++)
	{
		for (j = 0; j < objCombo.length; j++)
		{
			if (objCombo.options[j].value == arrInput[i])
			{
				objCombo.options[j].selected = true;
			}
		}	
	}	
	
	return true;
	
} // End of setSingleMultiSelectValue

/************************************************************
Name:		removeMultiSelectValues
Purpose:	To remove all selected values of a multi-select list
Input:		objCombo - The form field's combo box
Output:		true
************************************************************/  
function removeMultiSelectValues(objCombo)
{
	var i;
	var o;
	
	for (i = 0; i < objCombo.length; i++)
	{
		o = objCombo.options[i];
		if (o.selected)
		{
			objCombo.options[i].selected = false;
		}
	}
	return true;
	
} // End of setMultiSelectValues

/************************************************************
Name:	getDropText
Purpose:	To get the combo box's (Drop-down box's) current text
Input:	objCombo - The form field's combo box
Output:	returns the text of the selected item in the combo box
************************************************************/      
function getDropText(objCombo) {
	return(objCombo.options[objCombo.selectedIndex].text);
} //End function getDropText

/************************************************************
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 (var 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 (var i=0; i<radioControl.length; i++) 
  {  
    if (radioControl[i].value == radioValue)
    {
      radioControl[i].checked = true;
    }
  }
} // End of setRadioValue

/************************************************************
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 showMsg
Output:	True/False if a radio button was selected is valid
************************************************************/      
function isValidRadio(radioControl, strAppendMsg)
{
	if(getRadioValue(radioControl) == "")
	{ 
		showMsg("Please select " + strAppendMsg + ".",0,""); 
		return false;
	}
	return true;
} 

/************************************************************
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:		FormatMoney
Purpose:	To validate/format the money. This is different 
			from FormatMoneyWithCommas in the sense this does
			not put the commas in the string. 

Input:	objMoney -	Form field that contains the money value
		blnFormatCents - (0 = format cents, 1 = don't format cents)
		blnDollarSign - (0 = no $, 1 = $)
Output:	True/False if the currency/money is valid
************************************************************/   
function FormatMoney(objMoney, blnFormatCents, blnDollarSign) 
{
	return FormatMoneyWithCommas(objMoney, blnFormatCents, blnDollarSign, 1);
}

/************************************************************
Name:		FormatMoneyWithCommas
Purpose:	To validate/format the money

Input:	objMoney -	Form field that contains the money value
		blnFormatCents - (0 = format cents, 1 = don't format cents)
		blnDollarSign - (0 = no $, 1 = $)
		blnCommas - (0 - put commas, 1 -- no commas)
Output:	True/False if the currency/money is valid
************************************************************/   
function FormatMoneyWithCommas(objMoney, blnFormatCents, blnDollarSign, blnCommas)
{
	var dblTempAmt;
	var intCurrAmt;
	var strCurrAmt;
	var intCommaAmt;
	var intCommaPos;
	var intTempDlrs, strDlrs, strCents
	
	
	if(isWhiteSpace(objMoney.value)) 	
	{
		return false;
	}
	if(isValidMoney(objMoney,0))
	{
		dblTempAmt=CleanMoney(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 = "";	}
		
		if((blnCommas === void(0)) || (blnCommas==0))
		{
			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+")"}
		
		if((blnDollarSign === void(0)) || (blnDollarSign==0))
		{
			objMoney.value = retval;
		}
		else
		{
			objMoney.value = "$"+retval;
		}
		return true
	}
	return false;
}


/************************************************************
Name:		FormatWholeMoney
Purpose:	To validate/format the money

Input:	objMoney -	Form field that contains the money value
Output:	True/False if the currency/money is valid
************************************************************/      
function FormatWholeMoney(objMoney) 
{
	var dblTempAmt;
	var intCurrAmt;
	var strCurrAmt;
	var intCommaAmt;
	var intCommaPos;
	var intTempDlrs, strDlrs
	
	if(isWhiteSpace(objMoney.value)) 	
	{
		return false;
	}
	if(isValidMoney(objMoney,0))
	{
		dblTempAmt=CleanMoney(objMoney.value);
		dblTempAmt=eval(dblTempAmt);
		intCurrAmt=Math.abs((Math.round(dblTempAmt*100)/100));
		strCurrAmt=""+intCurrAmt;
		
		if (strCurrAmt.indexOf(".")==-1){strCurrAmt+=".";}
		strDlrs=strCurrAmt.substr(0,strCurrAmt.indexOf("."));
		intTempDlrs=strDlrs-0;

		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;
		//-- Put numbers in parentheses if negative.
		if (dblTempAmt<0) {retval="("+retval+")"}
		
		objMoney.value = retval;
		return true
	}
	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
		req -	Required (0 = not required, 1 = required)
		
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:	addElement
Purpose:	Adds a line to the the option list of a dropdown box
Input:	list - the name of the dropdown box
		text_in - the text the user will see in the dropdown box
		value_in - the value of the selection being added
Output:	
************************************************************/   
function addElement(list, text_in, value_in) {
    var o = list.options;
    var nIdx;
    
	nIdx = o.length;
                
	o[nIdx] = new Option(text_in, value_in);
}

/************************************************************
Name:	clearList
Purpose:	Deletes all of the options in a dropdown box
Input:	list - the name of the dropdown box
Output:	
************************************************************/
function clearList(list) {
    var i = 0;
    var o = list.options;

    for (i = o.length; i >= 0; --i)
		o[i] = null;
}

/************************************************************
Name:		trimStr
Purpose:	To trim off any leading or trailing spaces
Input:		str - String that needs to be trimmed
Output:		Returns the string without leading/trailing spaces
************************************************************/      
function trimStr(str) {

    var whitespace = new String(" \t\n\r");
    var s = new String(str);
	
    if (whitespace.indexOf(s.charAt(0)) != -1) {
        // We have a string with leading blank(s)...
        var j=0, i = s.length;

        // Iterate from the far left of string until we
        // don't have any more whitespace...
        while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
            j++;

        // Get the substring from the first non-whitespace
        // character to the end of the string...
        s = s.substring(j, i);
    }
    
    if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
        // We have a string with trailing blank(s)...
        var i = s.length - 1;       // Get length of string

        // Iterate from the far right of string until we
        // don't have any more whitespace...
        while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
            i--;

        // Get the substring from the front of the string to
        // where the last non-whitespace character is...
        s = s.substring(0, i+1);
    }

	return s;    
}

/************************************************************
Name:		showMsg
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 showMsg(strMsg, blnSetFocus, objFocusTo)
{
	alert(strMsg);
	if(blnSetFocus==1) 
	{
		setFocus(objFocusTo);
		//new design, we blank out the field.
		objFocusTo.value = "";
	}
}

/************************************************************
Name:		y2k
Purpose:	To return a valid year
Input:	intYear - year
Output:	returns a 4 digit year
************************************************************/
function y2k(intYear)
{ 
	intYear = parseInt(intYear);
	return (intYear < 1000) ? intYear + 2000 : intYear;
}

/************************************************************
Name:		readonlyCheckbox
Purpose:	Makes individual checkbox readonly
Input:		control
Output:		
************************************************************/
function readonlyCheckbox(objControlName)
{
	if(objControlName.checked)
	{
		//alert("Set Checkbox to false");
		objControlName.checked = false;
	}
	else
	{
		//alert("Set Checkbox to true");
		objControlName.checked = true;
	}
	objControlName.blur();
}

/************************************************************
Name:		isDateMoreRecent
Purpose:	Concatenates MM/DD/YYYY values to create dates, then compares them.  This function 
			differs from the isDateGreater function above because it accepts values, not objects,
			so it can be used for dropdown boxes, variables, etc; the above function assumes it 
			is receiving a textbox object.  This function assumes that the values are valid and
			does not validate them, only compares the dates
Input:		strFromMM - the from month value
			strFromDD - the from day value
			strFromYYYY - the from year value
			strToMM - the to month value
			strToDD - the to day value
			strToYYYY - the to year value
Output:		false if from date is later than to date; true otherwise
************************************************************/  
function isDateMoreRecent(strFromMM, strFromDD, strFromYYYY, strToMM, strToDD, strToYYYY) {
	
	var fromDate = new Date(strFromMM + "/" + strFromDD + "/" + strFromYYYY);
	var toDate = new Date(strToMM + "/" + strToDD + "/" + strToYYYY);
	
	if (toDate >= fromDate) {
		return true;
	}
	else {
		return false;
	}
}

/************************************************************
Name:		ConvertToNum
Purpose:	Converts a string to an integer or float number
Input:		numNumber - String to convert
			strIntFloat - i = integer, f = float
Output:		the converted number
************************************************************/  
function ConvertToNum(numNumber, strIntFloat)
{
	var intNewNumber;
	var intNumClean;
	
	if(isWhiteSpace(numNumber))
	{
		intNewNumber = 0;
	}
	else
	{
		//cut out any commas and $
		intNumClean = numNumber.replace(/,/g,"");
				
		intNumClean = intNumClean.replace("$","");
		
		if(strIntFloat == "i")
		{
			intNewNumber = parseInt(intNumClean);
		}
		else
		{
			intNewNumber = parseFloat(intNumClean);
		}
	}
	
	return intNewNumber;
}


/************************************************************
Name:		launchPopup
Purpose:	Launch a resizable Javascript popup window with a menubar and scrollbars
Input:		url - the address of the window
			height - how tall, in pixels, the window should be
			width - how wide, in pixels, the window should be
			top - how far, in pixels, the window should be from the top of the screen
			left - how far, in pixels, the window should be from the left of the screen
Output:		None
************************************************************/  
function launchPopup(url, height, width, top, left) {
	var Screen;
	var wScreen;
	
	Screen = url;
	wScreen = window.open(Screen,"wScreen","height=" + height + ",width=" + width + ",top=" + top + ",left=" + left + ",resizable,scrollbars"); 
	wScreen.focus();
} // end function launchPopup

/************************************************************
Name:		dropDecimalPlaces
Purpose:	Removes numbers after a specified number of decimal places
Input:		Number and number of decimal places
Output:		None			
************************************************************/ 
function dropDecimalPlaces(intNumber, intDecimalPlaces)
{
	var intDecimalPosition;
	var intEndOfString;
	var outNumber;
	
	intNumber = "" + intNumber;
	
	intDecimalPosition = intNumber.indexOf('.');
	
	if (intDecimalPosition != -1)
	{
		//if num decimal places is 0 set the end of the string to the decimal position - 1
		if(intDecimalPlaces == 0)
		{
			intEndOfString = parseInt(intDecimalPosition);
		}
		//else add 1 to the decimal places and set end position to the decimal position plus the number of decimal places
		else
		{
			intDecimalPlaces = intDecimalPlaces + 1;
			intEndOfString = parseInt(intDecimalPosition) + intDecimalPlaces;
		}
		
		if (intNumber.length != intEndOfString)
		{
			outNumber = intNumber.substring(0, intEndOfString);
		}
		else
		{
			outNumber = intNumber;
		}
	}
	else
	{
		outNumber = intNumber;
	}
	
	return outNumber;
}

//*******************************************************
// Name:	formatCurrency(num)
// Purpose: Formats number to currency
// Input:	Number to format
//*******************************************************
function formatCurrency(num)
{
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*100+0.50000000001);
		cents = num%100;
		num = Math.floor(num/100).toString();
	if(cents<10)
		cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+
		num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num);
}

//*******************************************************
// Name:	roundNumber(number,X) 
// Purpose: Rounds number to X decimal places
// Input:	Number to format
//*******************************************************
function roundNumber(x,places) {
	if(isWhiteSpace(x.value)) 	
	{
		return false;
	}
	
	if(!isValidNumber(x,0,"F",0, "enter a valid value",""))
	{
		return false;		
	}
	
	x.value = cleanNumber(x.value);
	
	var result;
	
	result = (Math.round(x.value*Math.pow(10,places)))/Math.pow(10,places);
    
    x.value = result;
    return true;
}

//*******************************************************
// Name:	confirmDelete() 
// Purpose: Displays a pop up window with the message
//			"Click OK to delete record." and Ok/Cancel.
//			Similar to calling showConfirmDialog with 
//			the same message.
//*******************************************************
function confirmDelete() 
{
	return showConfirmDialog("Click OK to delete record.");	
}

//*******************************************************
// Name:	showConfirmDialog(strMsg) 
// Purpose: Displays a pop up window with the message
//			and Ok/Cancel.
// Input:	The message to be displayed
//*******************************************************
function showConfirmDialog(strMsg) 
{
	// Display popup window for user to confirm action
	var varOK;
	varOK = window.confirm(strMsg)
	if (!varOK) return false;
	else return true;
}

/************************************************************
Name:		isNumberInRange
Purpose:	To validate taht a number is within a given range
Input:	number		-	Form field 
		max			- 	Max number
		message		-	Message
		inclusive	-	0 = noninclusive; 1 = inclusive
Output:	True/False if the the number is eblow the max
************************************************************/      
function isNumberInRange(number,max,min,message,inclusive) 
{
	if(!isValidNumber(number, 0, "f", 0, message, ""))
	{
		//no need to reset the focus and clear coz showMsg call in 
		//isValidNumber will do it.
		return false;
	}
	
	var numValue;
	numValue = cleanNumber(number.value);
	
	if (inclusive==0)
	{
		if(!(numValue < max))
		{
			showMsg("Number must be lower than " + max + ". Please re" + message + ".", 0, number);
			setFocus(number);
			number.value = "";
			return false;
		}
		if(!(numValue > min))
		{
			showMsg("Number must be greater than " + min + ". Please re" + message + ".", 0, number);
			setFocus(number);
			number.value = "";
			return false;
		}
	}
	else
	{
		if(numValue > max)
		{
			showMsg("Number exceeds the maximum value: " + max + ". Please re" + message + ".", 0, number);
			setFocus(number);
			number.value = "";
			return false;
		}
		if(numValue < min)
		{
			showMsg("Number is below the minimum value: " + min + ". Please re" + message + ".", 0, number);
			setFocus(number);
			number.value = "";
			return false;
		}
	}
	
	return true;
} 

/************************************************************
Name:		isIntegerInRange
Purpose:	To validate that an integer is within a given range
Input:	number		-	Form field 
		max			- 	Max number
		message		-	Message
		inclusive	-	0 = inclusive; 1 = noninclusive
Output:	True/False if the the number is eblow the max
************************************************************/      
function isIntegerInRange(number,max,min,message,inclusive) 
{
	if(!isValidNumber(number,0,"i",0, message,""))
	{
		return false;
	}
	
	var numValue;

	numValue = cleanNumber(number.value);
	
	if (inclusive==0)
	{
		if(!(numValue < max))
		{
			alert("Number must be lower than " + max + ". Please re" + message + ".");
			setFocus(number);
			return false;
		}
		if(!(numValue > min))
		{
			alert("Number must be greater than " + min + ". Please re" + message + ".");
			setFocus(number);
			return false;
		}
	}
	else
	{
		if(numValue > max)
		{
			alert("Number exceeds the maximum value: " + max + ". Please re" + message + ".");
			setFocus(number);
			return false;
		}
		if(numValue < min)
		{
			alert("Number is below the minimum value: " + min + ". Please re" + message + ".");
			setFocus(number);
			return false;
		}
	}
	
	return true;
} 

/******************************************************************
Name:	 PopupHelp()

******************************************************************/
function PopupHelp(strPage)
{
	var objHandle = PopupWindow(strPage, 'CCIP_Help','r','t',0,550,460,0);
}

//*******************************************************
// Name:	cleanNumber(number) 
// Purpose: Changes a number with parenthesis around it 
//			to a negative number i.e. (10) to -10
// Input:	Number to format
// Output:  Clean number is float format
//*******************************************************
function cleanNumber(number)
{
	var re = /[\$\,\)\(]/g; 			//Strip out "$,)" from input string
	var re1 = /[\(]/g;
	var strValue = String(number);

	strValue = strValue.replace(re1 , "-"); 
	strValue = strValue.replace(re , "");	
	
	//remove leading zeros
	while (strValue.charAt(0)=="0" && strValue.length>1) // if has leading zero (but not just "0")
		strValue = strValue.substring(1, strValue.length); // remove any leading zeros (otherwise assumes octal)
    
	return strValue;
}

//*******************************************************
// Name:	CheckFTE(form object) 
// Purpose: Validate an FTE input field
// Input:	Form object
// Output:  true/false
//*******************************************************
function CheckFTE(number)
{
	if(!isNumberInRange(number,9999.99,0,"enter a valid number",1))
	{
		number.value = "";
		setFocus(number);
		document.forms[document.forms.length - 1].hdnErrorFlag.value = "true";
		return false;
	}
	document.forms[document.forms.length - 1].hdnErrorFlag.value = "false";
	return true;
}

//*******************************************************
// Name:	CheckNeedsAssessment(form object) 
// Purpose: Validate a numeric input field
// Input:	Form object
// Output:  true/false
//*******************************************************
function CheckNeedsAssessment(number)
{
	if(!isNumberInRange(number,999999,0,"enter a valid number",1))
	{
		number.value = "";
		setFocus(number);
		document.forms[document.forms.length - 1].hdnErrorFlag.value = "true";
		return false;
	}
	roundNumber(number,2);
	document.forms[document.forms.length - 1].hdnErrorFlag.value = "false";
	return true;
}

//*******************************************************
// Name:	countChar(form object, max length)
// Purpose: Retrieve length and display message
// Input:	objField (form object) 
//			intMaxLength (max length of text area)
// Output:  none
//*******************************************************
function countChar(objField,intMaxLength)
{
	objField.value = trimStr(objField.value)
	alert("You have used " + objField.value.length + " character(s).  The maximum number of characters available is " + intMaxLength + ".");
}

//*******************************************************
// Name:	chkdate(objName) 
// Output:  true/false
//*******************************************************
function chkdate(objName) 
{
	var strDatestyle = "US"; //United States date style
	//var strDatestyle = "EU";  //European date style
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	var datefield = objName;
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementNr;
	var err = 0;
	var strMonthArray = new Array(12);
	strMonthArray[0] = "Jan";
	strMonthArray[1] = "Feb";
	strMonthArray[2] = "Mar";
	strMonthArray[3] = "Apr";
	strMonthArray[4] = "May";
	strMonthArray[5] = "Jun";
	strMonthArray[6] = "Jul";
	strMonthArray[7] = "Aug";
	strMonthArray[8] = "Sep";
	strMonthArray[9] = "Oct";
	strMonthArray[10] = "Nov";
	strMonthArray[11] = "Dec";
	strDate = datefield.value;
	
	if (strDate.length < 1) 
	{
		return true;
	}
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) 
	{
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) 
		{
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3) 
			{
				err = 1;
				return false;
			}
			else 
			{
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
			}
			booFound = true;
		}
	}
	if (booFound == false) 
	{
		if (strDate.length>5) 
		{
			strDay = strDate.substr(0, 2);
			strMonth = strDate.substr(2, 2);
			strYear = strDate.substr(4);
		}
	}
	if (strYear.length == 2) 
	{
		strYear = '20' + strYear;
	}
	// US style
	if (strDatestyle == "US") 
	{
		strTemp = strDay;
		strDay = strMonth;
		strMonth = strTemp;
	}
	intday = parseInt(strDay, 10);
	if (isNaN(intday)) 
	{
		err = 2;
		return false;
	}
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) 
	{
		for (i = 0;i<12;i++) 
		{
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) 
			{
				intMonth = i+1;
				strMonth = strMonthArray[i];
				i = 12;
			}
		}
		if (isNaN(intMonth)) 
		{
			err = 3;
			return false;
		}
	}
	intYear = parseInt(strYear, 10);
	if (isNaN(intYear)) 
	{
		err = 4;
		return false;
	}
	if (intMonth>12 || intMonth<1) 
	{
		err = 5;
		return false;
	}
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) 
	{
		err = 6;
		return false;
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) 
	{
		err = 7;
		return false;
	}
	if (intMonth == 2) 
	{
		if (intday < 1) 
		{
			err = 8;
			return false;
		}
		if (LeapYear(intYear) == true) 
		{
			if (intday > 29) 
			{
				err = 9;
				return false;
			}
		}
		else 
		{
			if (intday > 28) 
			{
				err = 10;
				return false;
			}
		}
	}
	return true;
}


// determines the number of days in a given month and year
function getNumOfDaysInMonth(intYearNo, intMonthNo) {

	var intDayNo = 0;
	
	if (intMonthNo == 2) 
	{
		if (LeapYear(intYearNo) == true)
		{ 
			intDayNo = 29;
		}
		else
		{
			intDayNo = 28;
		}
	}	
	else if (intMonthNo == 4 || intMonthNo == 6 || intMonthNo == 9 || intMonthNo == 11)
	{ 
		intDayNo = 30;
	}	
	else
	{ 
		intDayNo = 31;	
	}
	
	return intDayNo;

}  // end function getNumOfDaysInMonth


// populates days dropdown With correct number of days depending on month selected
function populateDays(year, field, changeField, end) {

	var intYearNo = 0;
	var intMonthNo = 0;
	var intDayNo = 0;
	var intNoDays = 0;
	var blnLeapYear = false;
	var i = 0;

	// gets the value of the option selected
	intYearNo = parseFloat(getDropValue(year));
	intMonthNo = parseFloat(getDropValue(field));
	intDayNo = parseFloat(getDropValue(changeField));
		
	intNoDays = getNumOfDaysInMonth(intYearNo, intMonthNo);	
	
	clearList(changeField);
	
	// if either the month or year is not set, set the day to blanks. 
	if (intYearNo == 0 || intMonthNo == 0)
	{
		intDayNo = 0;
		addElement(changeField, "", 0);
	}
	
	for (i = 1; i <= intNoDays; i++) 
	{
		addElement(changeField, i, i);
	}

	// if user specifies that day should be Set to last day of the month, Set it to that
	//  otherwise, if the current day is not greater than the # of days in the month, Set the 
	//	to today, otherwise, Set it to the first day of the month
	if (end) 
	{
		setDropValue(changeField, intNoDays);
	}
	else 
	{
		if (intDayNo <= intNoDays) 
		{
			setDropValue(changeField, intDayNo);
		}
		else 
		{
			setDropValue(changeField, 1);
		}
	}
} // end function populateDays

function populateDueDateDays(year, field, changeField, end) {

	var intYearNo = 0;
	var intMonthNo = 0;
	var intDayNo = 0;
	var intNoDays = 0;
	var blnLeapYear = false;
	var i = 0;

	// gets the value of the option selected
	intYearNo = (year - 1)
	intMonthNo = parseFloat(getDropValue(field));
	intDayNo = parseFloat(getDropValue(changeField));
		
	intNoDays = getNumOfDaysInMonth(intYearNo, intMonthNo);	
	
	clearList(changeField);
	
	// if either the month or year is not set, set the day to blanks. 
	if (intYearNo == 0 || intMonthNo == 0)
	{
		intDayNo = 0;
		addElement(changeField, "", 0);
	}
	
	for (i = 1; i <= intNoDays; i++) 
	{
		addElement(changeField, i, i);
	}

	// if user specifies that day should be Set to last day of the month, Set it to that
	//  otherwise, if the current day is not greater than the # of days in the month, Set the 
	//	to today, otherwise, Set it to the first day of the month
	if (end) 
	{
		setDropValue(changeField, intNoDays);
	}
	else 
	{
		if (intDayNo <= intNoDays) 
		{
			setDropValue(changeField, intDayNo);
		}
		else 
		{
			setDropValue(changeField, 1);
		}
	}
} // end function populateDays
	
	
function LeapYear(intYear) 
{
	if (intYear % 100 == 0) 
	{
		if (intYear % 400 == 0) { return true; }
	}
	else 
	{
		if ((intYear % 4) == 0) { return true; }
	}
	return false;
}

