<!--

//isFilled
	function isFilled(element) {
		return !(element.value == "" || element.value == " " || element.value == null)
	} //end function
	

//isNum (will change all to isNumeric someday - 08/29/2007)
	function isNum(element)	{
		if (isFilled(element) ==  false) {
			return false;
		} //end if
		for (i = 0; i < element.value.length; i++)	{
			if (element.value.charAt(i) < "0" || element.value.charAt(i) > "9"){
				return false;
			} //end if
		} //end for
		return true;
	} //end function


//isNumeric	
	function isNumeric(argArray) {
		var obj 					= argArray.obj;
		var decimalPlaces = argArray.decimalPlaces;
		var allowNegative = argArray.allowNegative;
		var minLength 		= argArray.minLength;
		var maxLength 		= argArray.maxLength;
		var minValue 			= argArray.minValue;
		var maxValue 			= argArray.maxValue;
		var errMsg 				= argArray.errMsg;
		
		if (isFilled(obj) ==  false) {
			argArray.errMsg = '\n\n\The value must be >= ' + minValue + ' and <= ' + maxValue + '!'
			return false; 
		} //end if	
		
		var temp = obj.value;	
		
		// remove commas
		temp = temp.replace(/,/g, '');  

		// avoid changing things if already formatted correctly
		var reg0Str = '[0-9]*';
		if (decimalPlaces > 0) {
			reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
		} 
		else if (decimalPlaces < 0) {
			reg0Str += '\\.?[0-9]*';
		} //end if	
		reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
		reg0Str = reg0Str + '$';
		var reg0 = new RegExp(reg0Str);
		if (reg0.test(temp) == false) {
			argArray.errMsg = '\n\n\Negative values are not allowed!'
			return false;
		} //end if
		
		// first replace all non numbers
		var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
		var reg1 = new RegExp(reg1Str, 'g');
		temp = temp.replace(reg1, '');
		if (allowNegative) {
			// replace extra negative
			var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
			var reg2 = /-/g;
			temp = temp.replace(reg2, '');
			if (hasNegative) {
				temp = '-' + temp;
			} //end if
		} //end if
		
		if (decimalPlaces != 0) {
			var reg3 = /\./g;
			var reg3Array = reg3.exec(temp);
			if (reg3Array != null) {
				// keep only first occurrence of .
				// and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
				var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
				reg3Right = reg3Right.replace(reg3, '');
				reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
				temp = temp.substring(0,reg3Array.index) + '.' + reg3Right;
			} //end if
		} //end if	
		
		if ((temp.length < minLength) || (temp.length > maxLength)) {
			argArray.errMsg = '\n\n\The length must be >= ' + minLength + ' characters and <= ' + maxLength + ' characters!'
			return false;
		} //end if
		if ((temp < minValue) || (temp > maxValue)) {
			argArray.errMsg = '\n\n\The value must be >= ' + minValue + ' and <= ' + maxValue + '!'
			return false;
		}
		else {
			obj.value = temp;		
			return true;
		} //end if
	} //end function
	
	
/*-------------------------------------------------------------------------------------------
		example from function calling isNumeric....
					function doValidate(Form) {
						var argArray = new Array();
									argArray.obj = document.Form.txtField;		//form object to validate
									argArray.decimalPlaces = 0;								//number of decimal places
									argArray.allowNegative = false;						//allow negative values
									argArray.minLength = 4;										//minimum length
									argArray.maxLength = 4;										//maximum length
									argArray.minValue = 2001;									//minimum value
									argArray.maxValue = 2050;									//miximum value
									argArray.errMsg = "";
							if (isNumeric(argArray) == false) {		
								//isNumeric(document.Form.txtField,0,false,4,4,2001,2050)
								//isNumeric(obj, decimalPlaces, allowNegative, minLength, maxLength, minValue, maxValue)
								alert("Error Message #003\n\nPlease enter the Budget Fiscal Year." + argArray.errMsg);
								document.Form.txtField.focus();
								document.Form.txtField.select();	
								return false;
							}	
							else {
								//alert("TESTING Message #005\n\ndocument.Form[1].element[35].focus() = " + document.forms[1].elements[35].value);
								document.forms[1].elements[35].focus() 
								return true;
							} // end if
						} //end function
-------------------------------------------------------------------------------------------*/
	

//isMyDate
	function isMyDate(dtStr){
		// Declaring valid date character, minimum year and maximum year
		var dtCh= "/";
		var minYear=1900;
		var maxYear=2100;
		
		var daysInMonth = daysArray(12);
		var pos1=dtStr.indexOf(dtCh);
		var pos2=dtStr.indexOf(dtCh,pos1+1);
		var strMonth=dtStr.substring(0,pos1);
		var strDay=dtStr.substring(pos1+1,pos2);
		var strYear=dtStr.substring(pos2+1);
		strYr=strYear;
		if (strDay.charAt(0)=="0" && strDay.length>1) {
			strDay=strDay.substring(1);
		}
		if (strMonth.charAt(0)=="0" && strMonth.length>1) {
			strMonth=strMonth.substring(1);
		}
		for (var i = 1; i <= 3; i++) {
			if (strYr.charAt(0)=="0" && strYr.length>1) {
				strYr=strYr.substring(1);
			}
		}
		month=parseInt(strMonth);
		day=parseInt(strDay);
		year=parseInt(strYr);
		if (pos1==-1 || pos2==-1){
			alert("The date format should be : mm/dd/yyyy");
			return false;
		}
		if (strMonth.length<1 || month<1 || month>12){
			alert("Please enter a valid month");
			return false;
		}
		if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
			alert("Please enter a valid day");
			return false;
		}
		if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
			alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear);
			return false;
		}
		if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
			alert("Please enter a valid date");
			return false;
		}
		return true
	}
	
/*-------------------------------------------------------------------------------------------
	example from function calling isMyDate....
					function ValidateForm(Form){
						if (isMyDate(document.Form.txtBeginingDate.value)==false) {
							document.Form.txtBeginingDate.select();
							document.Form.txtBeginingDate.focus();
							return false;
						}
						if (isMyDate(document.Form.txtEndingDate.value)==false) {
							document.Form.txtEndingDate.select();
							document.Form.txtEndingDate.focus();
							return false;
						}
						return true;
					}
-------------------------------------------------------------------------------------------*/
	
//isMyDate helper functions	
					function isInteger(s){
						var i;
						for (i = 0; i < s.length; i++){   
							// Check that current character is number.
							var c = s.charAt(i);
							if (((c < "0") || (c > "9"))) {
								return false;
							}
						}
						// All characters are numbers.
						return true;
					}
					
					function stripCharsInBag(s, bag){
						var i;
						var returnString = "";
						// Search through string's characters one by one.
						// If character is not in bag, append to returnString.
						for (i = 0; i < s.length; i++){   
							var c = s.charAt(i);
							if (bag.indexOf(c) == -1) {
								returnString += c;
							}
						}
						return returnString;
					}
					
					function daysInFebruary (year){
						// February has 29 days in any year evenly divisible by four,
						// EXCEPT for centurial years which are not also divisible by 400.
						return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
					}
					
					function daysArray(n) {
						for (var i = 1; i <= n; i++) {
							this[i] = 31;
							if (i==4 || i==6 || i==9 || i==11) {
								this[i] = 30;
							}
							if (i==2) {
								this[i] = 29;
							}
						} 
						return this;
					}
//End isMyDate helper functions


//textCounter
	function textCounter(field, countfield, maxlimit) {
		if (field.value.length > maxlimit) { // if too long...trim it!
			field.value = field.value.substring(0, maxlimit);
		} //end if
	} //end function
	
/*-------------------------------------------------------------------------------------------
		example from function calling textCounter....
						onKeyDown="textCounter(this.form.txtComments,this.form.remLen,750);" 
						onKeyUp="textCounter(this.form.txtComments,this.form.remLen,750);"
-------------------------------------------------------------------------------------------*/


//addCommas
	function addCommas(nStr) {
		nStr += '';
		x = nStr.split('.');
		x1 = x[0];
		x2 = x.length > 1 ? '.' + x[1] : '';
		var rgx = /(\d+)(\d{3})/;
		while (rgx.test(x1)) {
			x1 = x1.replace(rgx, '$1' + ',' + '$2');
		} //end while
		return x1 + x2;
	} //end function
	
/*-------------------------------------------------------------------------------------------
		example from function calling addCommas....
						document.Form.txtTotalFilterCost.value = addCommas(iwsTotalCostFilters.toFixed(2));
-------------------------------------------------------------------------------------------*/

//trim function
	function Trim(TRIM_VALUE) {
		if (TRIM_VALUE.length < 1 ) {
			return "";
		} //end if
		TRIM_VALUE = RTrim(TRIM_VALUE);
		TRIM_VALUE = LTrim(TRIM_VALUE);
		if (TRIM_VALUE == "") {
			return "";
		}
		else{
			return TRIM_VALUE;
			} //end if
	} //end function

	function RTrim(VALUE) {
		var w_space = String.fromCharCode(32);
		var v_length = VALUE.length;
		var strTemp = "";
		if(v_length < 0){
			return "";
		} //end if
		var iTemp = v_length -1;
		while(iTemp > -1) {
			if (VALUE.charAt(iTemp) == w_space) {
			}
			else{
				strTemp = VALUE.substring(0,iTemp +1);
				break;
			} //end if
			iTemp = iTemp-1;
		} //end while
		return strTemp;
	} //end function
	
	function LTrim(VALUE) {
		var w_space = String.fromCharCode(32);
		if(v_length < 1) {
			return"";
		} //end if
		var v_length = VALUE.length;
		var strTemp = "";
		var iTemp = 0;
		while (iTemp < v_length) {
			if (VALUE.charAt(iTemp) == w_space) {
			}
			else {
				strTemp = VALUE.substring(iTemp,v_length);
				break;
			} //end If
			iTemp = iTemp + 1;
		} //end while
		return strTemp;
	} //end function
	

//doCompareDates
	function doCompareDates(fromDate, toDate) {
			if (Date.parse(fromDate) > Date.parse(toDate)) {
				return false;
			} //end if	
		} //end function

/*-------------------------------------------------------------------------------------------
		example from function calling doCompareDates....
						if (doCompareDates(document.Form.txtBegDate.value, document.Form.txtEndDate.value) == false) {
-------------------------------------------------------------------------------------------*/

//-->
