/*
This file contains various input masks to use with text fields, as well as other related functions
To use any of the input masks put it in the onKeyPress event (e.g. onKeyPress="return maskDate(event)") -
Note, put "event" as the parameter.  To validate dates also use the validateDate(this) function in the text box's
onBlur event (e.g. onBlur="validateDate(this)").

=================================================
		Contents:
=================================================
caretPos function - used to return the position of the caret (cursor) within a text field
isLeapYear function - indicates whether a given year is a leap year
numOccurrences function - returns the number of times string searchFor appears in string inString
to UKDate(pDt) - converts a date object to a UK date format string (dd/mm/yyyy) with leading zeros
currentYear function - returns the current year in yyyy format
various boolean browser detection variables:
	isIE (indicates if Internet Explorer)
	isNS6 (indicates if Netscape 6)
	isNS4 (indicates if Netscape 4)
checkMaxLength function - use in textareas to limit maximum amount of text input
convertUpperCase function - converts a text entry field to uppercase
maskDate function - use on input boxes for date entry in the onKeyPress event (onKeyPress="return maskDate(event)")
validateDate function - use on input boxes for date entry in the onBlur event (onBlur="validateDate(this,false);")
maskMoney function - use on input boxes that permit money entry, including £ signs and that can include a decimal point
maskNumber function - use on input boxes that permit real numbers, i.e. those that can include a decimal point
maskPlanAppNo function - use on input boxes for entering Planning Application No (nn/nn/nnnn)
validatePlanAppNo function - use on input boxes that permit Planning Application No. entry
maskPosNumber function - use on input boxes that permit positive real numbers, i.e. those >=0 that can include a decimal point
maskInteger function - use on input boxes that permit integers
maskPosInteger function - use on input boxes that only permit positive integers (i.e. >=0)
*/

//-------------------------------------------------------------------------------------------------------------------
//caretPos function - used to return the position of the caret (cursor) within a text field
//-------------------------------------------------------------------------------------------------------------------
function caretPos(textEl) {
	var i=textEl.value.length+1;
	if (textEl.createTextRange) {
		theCaret = document.selection.createRange().duplicate();
		while (theCaret.parentElement()==textEl && theCaret.move("character",1)==1) {
			--i;
		}
		return i;
	}
	else return -1;
}

//-------------------------------------------------------------------------------------------------------------------
//isLeapYear function - indicates whether a given year is a leap year
//-------------------------------------------------------------------------------------------------------------------
function isLeapYear (Year) {
	if (((Year % 4)==0) && ((Year % 100)!=0) || ((Year % 400)==0)) {
		return (true);
	} else { return (false); }
}

//-------------------------------------------------------------------------------------------------------------------
//numOccurrences function - returns the number of times string searchFor appears in string inString
//-------------------------------------------------------------------------------------------------------------------
function numOccurrences(searchFor,inString) {
	count = 0;
	pos = inString.indexOf(searchFor);
	while ( pos != -1 ) {
	   count++;
	   pos = inString.indexOf(searchFor,pos+1);
	} 
	return count;
}

//-------------------------------------------------------------------------------------------------------------------
//to UKDate(pDt) - converts a date object to a UK date format string (dd/mm/yyyy) with leading zeros
//-------------------------------------------------------------------------------------------------------------------
function toUKDate(pDt) {
	return ((pDt.getDate()<10)?"0":"") + pDt.getDate() + "/" 
		+ ((pDt.getMonth()<9)?"0":"") + (pDt.getMonth()+1) + "/" 
		+ pDt.getFullYear();
}

//-------------------------------------------------------------------------------------------------------------------
//currentMonth function - returns the current month
//-------------------------------------------------------------------------------------------------------------------
function currentMonth(pad) {
	Today = new Date();
	var mth = Today.getMonth()+1
	if ((pad==true) && (mth < 10)) {
		return "0" + mth;
	} else {
		return mth;
	}
}

//-------------------------------------------------------------------------------------------------------------------
//currentYear function - returns the current year in yyyy format
//-------------------------------------------------------------------------------------------------------------------
function currentYear() {
	Today = new Date();
	return Today.getFullYear();
}

//-------------------------------------------------------------------------------------------------------------------
//set various browser detection variables
//-------------------------------------------------------------------------------------------------------------------
var strUserAgent = navigator.userAgent.toLowerCase();
var isIE = strUserAgent.indexOf("msie") > -1;
var isNS6 = strUserAgent.indexOf("netscape6") > -1;
var isNS4 = !isIE && !isNS6  && parseFloat(navigator.appVersion) < 5;

//-------------------------------------------------------------------------------------------------------------------
//checkMaxLength function - use on textareas to limit amount of text input
//-------------------------------------------------------------------------------------------------------------------
function checkMaxLength(field, maxlimit) {
	// if too long...trim it!
	if (field.value.length > maxlimit)
		field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
/*	else 
		countfield.value = maxlimit - field.value.length; */
}

//-------------------------------------------------------------------------------------------------------------------
//convertUpperCase function - converts a text entry field to uppercase
//-------------------------------------------------------------------------------------------------------------------
function convertUpperCase (obj) {
	obj.value = obj.value.toUpperCase();
}

//-------------------------------------------------------------------------------------------------------------------
//maskDate function - use on input boxes for date entry in the onKeyPress event (onKeyPress="return maskDate(event)")
//-------------------------------------------------------------------------------------------------------------------
function maskDate(objEvent) {
	var iKeyCode, strKey, objInput;
	
	//regular expressions
	var reValidChars = /[\d\x2F]/;	//123456789/
	var reKeyboardChars = /[\x00\x03\x08\x0D\x16\x18\x1A]/;

	 if (isIE) {
       iKeyCode = objEvent.keyCode;
       objInput = objEvent.srcElement;
  	} else {
       iKeyCode = objEvent.which;
       objInput = objEvent.target;
 	}

	strKey = String.fromCharCode(iKeyCode);

	if (!reValidChars.test(strKey) && !reKeyboardChars.test(strKey)) {
		return false;
	} else if (iKeyCode == 47) {	//Only allow slash / in position 3 and 6

		if (caretPos(objInput)==2) {
			objInput.value = "0" + objInput.value;
		} else if (caretPos(objInput)==5) {
			objInput.value = objInput.value.substring(0,3) + "0" + objInput.value.substring(3)
		} else if ((caretPos(objInput)!=3) && (caretPos(objInput)!=6)) {
			return false;
		}
	} else {						//Now deal with numbers - allow anywhere except position 3 and 6
		if ((caretPos(objInput)==3) || (caretPos(objInput)==6)) return false;
	}
}

//-------------------------------------------------------------------------------------------------------------------
//validateDate function - use on input boxes that permit date entry in the onBlur event (onBlur="validateDate(this,reqd);")
//the reqd paramater is true to indicate the input box must not be empty, false indicates it can be empty
//-------------------------------------------------------------------------------------------------------------------
function validateDate(objInput,reqd) {
//	var objInput;
	
//	 if (isIE) {
//       objInput = objEvent.srcElement;
//  	} else {
//       objInput = objEvent.target;
// 	}

	var sVal = objInput.value;
	
	//First, if the date isn't required a length of zero is valid so we may as well just exit the function
	if ((!reqd) && (sVal.length==0)) return true;
	
	//Next, we'll take what they've entered and try to make a date out of it - this can also save users some keystrokes
	switch (sVal.length) { 
		case 9 : 
			//If date entered is 9 chars and slashes in correct place, insert current milennium to make year a 4 digit year
			if (sVal.charAt(2)=="/" && sVal.charAt(5)=="/" && numOccurrences("/",sVal)==2) {
				sVal = sVal.substring(0,6) + currentMilennium() + sVal.substring(6);
			}
	      	break; 
		case 8 : 
			//If date entered is 8 chars and slashes in correct place, insert current century to make year a 4 digit year
			if (sVal.charAt(2)=="/" && sVal.charAt(5)=="/" && numOccurrences("/",sVal)==2) {
				sVal = sVal.substring(0,6) + currentCentury() + sVal.substring(6);
			}
	      	break; 
		case 7 : 
			//If dd/mm/y entered, insert current decade before the y entered to create correct 4-digit year
			if (sVal.charAt(2)=="/" && sVal.charAt(5)=="/" && numOccurrences("/",sVal)==2) {
				sVal = sVal.substring(0,6) + currentDecade() + sVal.substring(6);
			}
	      	break; 
	   	case 6 : 
			//If dd/mm/ entered, append current year to create dd/mm/yyyy
			if (sVal.charAt(2)=="/" && sVal.charAt(5)=="/" && numOccurrences("/",sVal)==2) {
				sVal = sVal.concat(currentYear());
			}
	      	break; 
	   	case 5 : 
			//If dd/mm entered, append "/" & the current year to create dd/mm/yyyy
			if (sVal.charAt(2)=="/" && numOccurrences("/",sVal)==1) {
				sVal = sVal.concat("/",currentYear());
			}
	      	break; 
	   	case 4 :
			//If dd/m entered, pad the month with a 0 and append "/" & the current year to create dd/mm/yyyy
			if (sVal.charAt(2)=="/" && numOccurrences("/",sVal)==1) {
				sVal = sVal.substring(0,3) + "0" + sVal.substring(3) + "/" + currentYear()
			}
	   	case 3 :
			//If dd/ entered, append the current month, "/" & the current year to create dd/mm/yyyy
			if (sVal.charAt(2)=="/" && numOccurrences("/",sVal)==1) {
				sVal = sVal.concat(currentMonth(true),"/",currentYear());
			}
	   	case 2 :
			//If dd entered, append "/", the current month, "/" & the current year to create dd/mm/yyyy
			if (numOccurrences("/",sVal)==0) {
				sVal = sVal.concat("/",currentMonth(true),"/",currentYear());
			}
	   	case 1 :
			//If d entered, pad the day with a 0 and append "/", the current month, "/" & the current year to create dd/mm/yyyy
			if (numOccurrences("/",sVal)==0) {
				sVal = "0".concat(sVal,"/",currentMonth(true),"/",currentYear());
			}
	}	//End switch (sVal.length)
	
	objInput.value = sVal;
	
	var blnValid;
	
	//First check the basic nn/nn/nnnn structure
	blnValid = (numOccurrences("/",sVal)==2)
		&& (sVal.length==10)
		&& (sVal.charAt(2)=="/")
		&& (sVal.charAt(5)=="/");
	
	if (!blnValid) alert("Please enter a valid date: dd/mm/yyyy");
	
	//If we pass the first test, now test the individual parts
	if (blnValid==true) {
		var daypart = parseInt(sVal,10);
		var monthpart = parseInt(sVal.substring(3),10);
		var yearpart = parseInt(sVal.substring(6),10);
		
		//First check the ranges for each part
		blnValid=(daypart > 0 && daypart <= 31)
			&& (monthpart > 0 && monthpart <=12)
			&& (yearpart > 1900);
		if (!blnValid) alert("Invalid Date Entered.\nDay must be 1-31\nMonth must be 1-12\nYear must be after 1900");
			
		//Finally check the max number of days for each month
		//We only need to worry about the non-31 day months
		if (blnValid) {
			switch (monthpart) {
				case 4 :	//April
				case 6 :	//June
				case 9 :	//September
				case 11 :	//November
					blnValid=(daypart<=30);
					if (!blnValid) alert("Invalid Date Entered.\nDay must be 1-30.");
					break;
				case 2 :	//February
					if (isLeapYear(yearpart)) {
						blnValid=(daypart<=29)
						if (!blnValid) alert("Invalid Date Entered.\nDay must be 1-29.");
					} else {
						blnValid=(daypart<=28)
						if (!blnValid) alert("Invalid Date Entered.\nDay must be 1-28.");
					}
					break;
			}	//Ends switch (monthpart)
		}	//Ends if (blnValid == true)
	}
	
	if (!blnValid) {
		objInput.focus();
		objInput.select();
	} else {
		//do nothing
	}
	return blnValid;
}

//-------------------------------------------------------------------------------------------------------------------
//validateEmail function - use on input boxes that permit email entry in the onBlur event (onBlur="validateEmail(this,reqd);")
//the reqd paramater is true to indicate the input box must not be empty, false indicates it can be empty
//-------------------------------------------------------------------------------------------------------------------
function validateEmail(objInput,reqd) {
	var sEmail = objInput.value;
	
	//First, if the email isn't required a length of zero is valid so we may as well just exit the function
	if ((!reqd) && (sEmail.length==0)) return true;
	
	var iAtPos = sEmail.indexOf("@") + 1
	var iDotPos = sEmail.lastIndexOf(".") + 1

	//Next, we simply check there is an @ sign and a dot that is after the @
	//Also, the entire length must be at least 8 chars, the @ cannot be first character, the . must be at
	//least character 4 and must have at least one character between the @ and the .
	if ((iAtPos < 2) || (iDotPos < 4) || (iDotPos <= (iAtPos+1)) || (sEmail.length < 8)) {
		alert("Invalid Email Address Entered.");
		objInput.focus();
		objInput.select();
		return false;
	} else {
		return true;
	}
}

//-------------------------------------------------------------------------------------------------------------------
//maskMoney function - use on input boxes that permit money entry, including £ signs and that can include a decimal point
//-------------------------------------------------------------------------------------------------------------------
function maskMoney(objEvent) {
	var iKeyCode, strKey, objInput;

	//regular expressions
	var reValidChars = /[\d\x2E\x2D\x2C\xA3]/;	//123456789.-,£
	var reKeyboardChars = /[\x00\x03\x08\x0D\x16\x18\x1A]/;

	 if (isIE) {
       iKeyCode = objEvent.keyCode;
       objInput = objEvent.srcElement;
  	} else {
       iKeyCode = objEvent.which;
       objInput = objEvent.target;
 	}
	
	//If user is pressing the £ key it must at the first position and no other £s already entered;
	//Or if user is pressing the . key, there mustn't be any others already, also, if it's the first character, insert a 0
	//(zero) before it
	switch(iKeyCode)
	{
		case 163 :	//£
			if ((caretPos(objInput)!=1) || (objInput.value.indexOf("£")>=0)) return false;
			break;
		case 46 :	//.
			if (objInput.value.indexOf(".")>=0) {
				return false;
			} else if ((caretPos(objInput)==2) && (objInput.value.charAt(0)=="£")) {
				objInput.value = "£0." + objInput.value.substring(1);
				return false;
			} else if (caretPos(objInput)==1) {
				objInput.value = "0." + objInput.value;
				return false;
			}
			break;
		default :		
			strKey = String.fromCharCode(iKeyCode);	
			if (!reValidChars.test(strKey) && !reKeyboardChars.test(strKey)) {
				//alert("Invalid Character Detected!\nKeyCode = " + iKeyCode + "\nCharacter =" + strKey);
				return false;
		}
	}
}

//-------------------------------------------------------------------------------------------------------------------
//maskNumber function - use on input boxes that permit real numbers, i.e. those that can include a decimal point
//-------------------------------------------------------------------------------------------------------------------
function maskNumber(objEvent) {
	var iKeyCode, strKey;

	//regular expressions
	var reValidChars = /[\d\x2E\x2D\x2C]/;	//123456789.-,
	var reKeyboardChars = /[\x00\x03\x08\x0D\x16\x18\x1A]/;

	if (isIE) {
	    iKeyCode = objEvent.keyCode;
	} else {
	    iKeyCode = objEvent.which;
	}

	strKey = String.fromCharCode(iKeyCode);

	if (!reValidChars.test(strKey) && !reKeyboardChars.test(strKey)) {
		//alert("Invalid Character Detected!\nKeyCode = " + iKeyCode + "\nCharacter =" + strKey);
		//alert("Sorry, this field is limited to numbers and the characters . , -");
		return false;
	}
}

//-------------------------------------------------------------------------------------------------------------------
//maskPlanAppNo function - use on input boxes for entering Planning Application No (nn/nn/nnnn)
//-------------------------------------------------------------------------------------------------------------------
function maskPlanAppNo(objEvent) {
	var iKeyCode, strKey, objInput;
	
	//regular expressions
	var reValidChars = /[\d\x2F]/;	//123456789/
	var reKeyboardChars = /[\x00\x03\x08\x0D\x16\x18\x1A]/;

	 if (isIE) {
       iKeyCode = objEvent.keyCode;
       objInput = objEvent.srcElement;
  	} else {
       iKeyCode = objEvent.which;
       objInput = objEvent.target;
 	}

	strKey = String.fromCharCode(iKeyCode);

	if (!reValidChars.test(strKey) && !reKeyboardChars.test(strKey)) {
		return false;
	} else if (iKeyCode == 47) {	//Only allow slash / in position 3 and 6

		if (caretPos(objInput)==2) {
			objInput.value = "0" + objInput.value;
		} else if (caretPos(objInput)==5) {
			objInput.value = objInput.value.substring(0,3) + "0" + objInput.value.substring(3)
		} else if ((caretPos(objInput)!=3) && (caretPos(objInput)!=6)) {
			return false;
		}
	} else {						//Now deal with numbers - allow anywhere except position 3 and 6
		if ((caretPos(objInput)==3) || (caretPos(objInput)==6)) return false;
	}
}

//-------------------------------------------------------------------------------------------------------------------
//validatePlanAppNo function - use on input boxes that permit Planning Application No. entry
//the reqd paramater is true to indicate the input box must not be empty, false indicates it can be empty
//-------------------------------------------------------------------------------------------------------------------
function validatePlanAppNo(objEvent,reqd) {
	var objInput;
	
	 if (isIE) {
       objInput = objEvent.srcElement;
  	} else {
       objInput = objEvent.target;
 	}

	var sVal = objInput.value;
	
	//First, if the date isn't required a length of zero is valid so we may as well just exit the function
	if ((!reqd) && (sVal.length==0)) return;
	
	//Next, we'll take what they've entered and try to make a valid num out of it - this can also save users some keystrokes
	switch (sVal.length) { 
		case 9 : 
			//If num entered is 9 chars and slashes in correct place, insert "0" to make final part 4 digits
			if (sVal.charAt(2)=="/" && sVal.charAt(5)=="/" && numOccurrences("/",sVal)==2) {
				sVal = sVal.substring(0,6) + "0" + sVal.substring(6);
			}
	      	break; 
		case 8 : 
			//If num entered is 8 chars and slashes in correct place, insert "00" to make year a 4 digit year
			if (sVal.charAt(2)=="/" && sVal.charAt(5)=="/" && numOccurrences("/",sVal)==2) {
				sVal = sVal.substring(0,6) + "00" + sVal.substring(6);
			}
	      	break; 
		case 7 : 
			//If num entered is 7 chars and slashes in correct place, insert "00" to make year a 4 digit year
			if (sVal.charAt(2)=="/" && sVal.charAt(5)=="/" && numOccurrences("/",sVal)==2) {
				sVal = sVal.substring(0,6) + "000" + sVal.substring(6);
			}
	      	break; 
	}	//End switch (sVal.length)
	
	objInput.value = sVal;

	var blnValid;
	
	//First check the basic nn/nn/nnnn structure
	blnValid = (numOccurrences("/",sVal)==2)
		&& (sVal.length==10)
		&& (sVal.charAt(2)=="/")
		&& (sVal.charAt(5)=="/");
	
	if (!blnValid) {
		alert("Please enter a valid Planning Application No: nn/nn/nnnn");
		objInput.focus();
		objInput.select();
	} else {
		//do nothing
	}
}

//-------------------------------------------------------------------------------------------------------------------
//addHDCRefSlashes function - use on input boxes for inputting the HDC Reference No, in the onBlur event.
//Used to add slashes (/) to the numbers input
//-------------------------------------------------------------------------------------------------------------------
function addHDCRefSlashes(objInput) {
	var s = objInput.value;
	//remove any slashes already there
	while (s.indexOf("/") >= 0) {
		s = s.replace('/','');
	}
	
	//add slashes in correct places
	if (s.length > 4)
		objInput.value = s.substr(0,1) + "/" + s.substr(1,1) + "/" + s.substr(2,2) + "/" + s.substr(4)
	else if (s.length > 2)
		objInput.value = s.substr(0,1) + "/" + s.substr(1,1) + "/" + s.substr(2)
	else if (s.length > 1)
		objInput.value = s.substr(0,1) + "/" + s.substr(1);
	else
		objInput.value = s;
}

//-------------------------------------------------------------------------------------------------------------------
//maskHDCReference function - use on input boxes for entering HDC Reference No (nn/nn/nnnn)
//Note:	This function is no longer being used as they now enter just numbers and we use the addHDCRefSlashes function
//		above to add the slashes in the onBlur event.
//-------------------------------------------------------------------------------------------------------------------
function maskHDCReference(objEvent) {
	var iKeyCode, strKey, objInput;
	
	//regular expressions
	var reValidChars = /[\d\x2F]/;	//123456789/
	var reKeyboardChars = /[\x00\x03\x08\x0D\x16\x18\x1A]/;

	 if (isIE) {
       iKeyCode = objEvent.keyCode;
       objInput = objEvent.srcElement;
  	} else {
       iKeyCode = objEvent.which;
       objInput = objEvent.target;
 	}

	strKey = String.fromCharCode(iKeyCode);

	if (!reValidChars.test(strKey) && !reKeyboardChars.test(strKey)) {
		return false;
	} else if (iKeyCode == 47) {	//Only allow slash / in position 3 and 6

		if (caretPos(objInput)==2) {
			objInput.value = "0" + objInput.value;
		} else if (caretPos(objInput)==5) {
			objInput.value = objInput.value.substring(0,3) + "0" + objInput.value.substring(3)
		} else if ((caretPos(objInput)!=3) && (caretPos(objInput)!=6)) {
			return false;
		}
	} else {						//Now deal with numbers - allow anywhere except position 3 and 6
		if ((caretPos(objInput)==3) || (caretPos(objInput)==6)) return false;
	}
}

//-------------------------------------------------------------------------------------------------------------------
//validateHDCReference function - use on input boxes that permit HDC Reference No. entry
//the reqd paramater is true to indicate the input box must not be empty, false indicates it can be empty
//-------------------------------------------------------------------------------------------------------------------
function validateHDCReference(objEvent,reqd) {
	var objInput;
	
	 if (isIE) {
       objInput = objEvent.srcElement;
  	} else {
       objInput = objEvent.target;
 	}

	var sVal = objInput.value;
	
	//First, if the date isn't required a length of zero is valid so we may as well just exit the function
	if ((!reqd) && (sVal.length==0)) return;
	
	//Next, we'll take what they've entered and try to make a valid num out of it - this can also save users some keystrokes
	switch (sVal.length) { 
		case 9 : 
			//If num entered is 9 chars and slashes in correct place, insert "0" to make final part 4 digits
			if (sVal.charAt(2)=="/" && sVal.charAt(5)=="/" && numOccurrences("/",sVal)==2) {
				sVal = sVal.substring(0,6) + "0" + sVal.substring(6);
			}
	      	break; 
		case 8 : 
			//If num entered is 8 chars and slashes in correct place, insert "00" to make year a 4 digit year
			if (sVal.charAt(2)=="/" && sVal.charAt(5)=="/" && numOccurrences("/",sVal)==2) {
				sVal = sVal.substring(0,6) + "00" + sVal.substring(6);
			}
	      	break; 
		case 7 : 
			//If num entered is 7 chars and slashes in correct place, insert "00" to make year a 4 digit year
			if (sVal.charAt(2)=="/" && sVal.charAt(5)=="/" && numOccurrences("/",sVal)==2) {
				sVal = sVal.substring(0,6) + "000" + sVal.substring(6);
			}
	      	break; 
	}	//End switch (sVal.length)
	
	objInput.value = sVal;

	var blnValid;
	
	//First check the basic nn/nn/nnnn structure
	blnValid = (numOccurrences("/",sVal)==2)
		&& (sVal.length==10)
		&& (sVal.charAt(2)=="/")
		&& (sVal.charAt(5)=="/");
	
	if (!blnValid) {
		alert("Please enter a valid Planning Application No: nn/nn/nnnn");
		objInput.focus();
		objInput.select();
	} else {
		//do nothing
	}
}

//-------------------------------------------------------------------------------------------------------------------
//maskPosNumber function - use on input boxes that permit positive real numbers, i.e. those >=0 that can include a decimal point
//-------------------------------------------------------------------------------------------------------------------
function maskPosNumber(objEvent) {
	var iKeyCode, strKey;

	//regular expressions
	var reValidChars = /[\d\x2E\x2C]/;	//123456789.,
	var reKeyboardChars = /[\x00\x03\x08\x0D\x16\x18\x1A]/;

	if (isIE) {
	    iKeyCode = objEvent.keyCode;
	} else {
	    iKeyCode = objEvent.which;
	}

	strKey = String.fromCharCode(iKeyCode);

	if (!reValidChars.test(strKey) && !reKeyboardChars.test(strKey)) {
		//alert("Invalid Character Detected!\nKeyCode = " + iKeyCode + "\nCharacter =" + strKey);
		//alert("Sorry, this field is limited to numbers and the characters . , -");
		return false;
	}
}

//-------------------------------------------------------------------------------------------------------------------
//maskInteger function - use on input boxes that permit integers
//-------------------------------------------------------------------------------------------------------------------
function maskInteger(objEvent) {
	var iKeyCode, strKey;

	//regular expressions
	var reValidChars = /[\d\x2D\x2C]/;	//123456789-,
	var reKeyboardChars = /[\x00\x03\x08\x0D\x16\x18\x1A]/;

	if (isIE) {
	    iKeyCode = objEvent.keyCode;
	} else {
	    iKeyCode = objEvent.which;
	}

	strKey = String.fromCharCode(iKeyCode);

	if (!reValidChars.test(strKey) && !reKeyboardChars.test(strKey)) {
		//alert("Invalid Character Detected!\nKeyCode = " + iKeyCode + "\nCharacter =" + strKey);
		//alert("Sorry, this field is limited to numbers and the characters . , -");
		return false;
	}
}

//-------------------------------------------------------------------------------------------------------------------
//maskPosInteger function - use on input boxes that only permit positive integers (i.e. >=0)
//-------------------------------------------------------------------------------------------------------------------
function maskPosInteger(objEvent) {
	var iKeyCode, strKey;

	//regular expressions
	var reValidChars = /[\d]/;	//123456789
	var reKeyboardChars = /[\x00\x03\x08\x0D\x16\x18\x1A]/;

	if (isIE) {
	    iKeyCode = objEvent.keyCode;
	} else {
	    iKeyCode = objEvent.which;
	}

	strKey = String.fromCharCode(iKeyCode);

	if (!reValidChars.test(strKey) && !reKeyboardChars.test(strKey)) {
		//alert("Invalid Character Detected!\nKeyCode = " + iKeyCode + "\nCharacter =" + strKey);
		//alert("Sorry, this field is limited to numbers and the characters . , -");
		return false;
	}
}

//-------------------------------------------------------------------------------------------------------------------
//currentMilennium function - used in validateDate function to insert current milennium into incomplete date
//-------------------------------------------------------------------------------------------------------------------
function currentMilennium() {
	/* Returns the first digit of the current year */
	var x = new Date();
	x = x.getYear()+'';
	x = x.substring(0,1);
	return x;
}

//-------------------------------------------------------------------------------------------------------------------
//currentCentury function - used in validateDate function to insert current century into incomplete date
//-------------------------------------------------------------------------------------------------------------------
function currentCentury() {
	/* Returns the first 2 digits of the current year */
	var x = new Date();
	x = x.getYear()+'';
	x = x.substring(0,2);
	return x;
}

//-------------------------------------------------------------------------------------------------------------------
//currentDecade function - used in validateDate function to insert current decade into incomplete date
//-------------------------------------------------------------------------------------------------------------------
function currentDecade() {
	/* Returns the first 3 digits of the current year */
	var x = new Date();
	x = x.getYear()+'';
	x = x.substring(0,3);
	return x;
}
