	function isDefined(arg) {
		return typeof(arg) != "undefined"
	}

	function validateEmailAddress(obj,aFriendlyName) {
		if (!isDefined(aFriendlyName)) {
			aFriendlyName = "Email"
		}
		sEmail = obj.value;
		if (sEmail.search( /\w+((-\w+)|(\.\w+)|(\_\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z]{2,5}/ ) == -1) {
			alert('Invalid ' + aFriendlyName + '.');
			obj.focus();
			return false;
		}
		return true;
	}

	function CheckPostCode(objStr)	{
		var strPostCode = objStr.value;
		var bValid = true;
		if (strPostCode.length != 4) {
			alert("Invalid PostCode");
			objStr.focus();
			return false;
		} else {
			for (i = 0; i <= strPostCode.length - 1; i++) {
				// Grab each character of the string
				var chrCurr = strPostCode.charCodeAt(i);

				// if the character is a letter [0-9]
				if ((parseInt(chrCurr) != 0) && ((parseInt(chrCurr) < 48)  || (parseInt(chrCurr) > 57))) {
					bValid = false;
					break;
				}
			}
			if (! bValid) {
				alert("Invalid PostCode");
				objStr.focus();
				return false;
			} else {
				return true;
			}
		}
	}

	function CheckPostCodeOrSpace(objStr)	{
		var strPostCode = TrimString("" + objStr.value);
		var bValid = true;
		if (strPostCode.length != 0) {
			if (strPostCode.length != 4) {
				alert("Invalid PostCode");
				objStr.focus();		
				return false;
			} else if (strPostCode.length > 0)	{
				for (i = 0; i <= strPostCode.length - 1; i++) {
					// Grab each character of the string
					var chrCurr = strPostCode.charCodeAt(i);
					
					// if the character is a letter [0-9]
					if ((parseInt(chrCurr) != 0) && ((parseInt(chrCurr) < 48)  || (parseInt(chrCurr) > 57))) {
						bValid = false;
					}
				}
				if (! bValid) {
					alert("Invalid PostCode");
					objStr.focus();		
					return false;
				}		
			} else {
				return true;
			}
		} else {
			//string length 0
			return true;
		}
	}
	
	function validMobileNumber(aObject) {
		var mobile = aObject.value.toLowerCase()
		var validMobile = false
		if(mobile.length==10) {
			if(mobile.indexOf("04")==0) {
				validMobile = true
				aObject.value = "614" + aObject.value.substring(2)
			}
		} else if (mobile.length==11) {
			if(mobile.indexOf("614")==0) {
				validMobile = true
			}
		}
		
		if(!validMobile) {
			alert("Invalid mobile number")
			aObject.focus()
			return false
		}
					
		return true
	}

	function CheckNumber(objNum, blnZeroAllowed, blnDecimalAllowed)	{
		var intLen = objNum.value.length;	// the length of the number
		var strCurrNum = objNum.value;	// the value of the number
		var strNewNum = '';
		var blnZero = true;
		// if the length of the number is greater than 0
		if (intLen > 0)	{
			for (i = 0; i <= intLen - 1; i++) {
				// Grab each character of the string
				var chrCurr = strCurrNum.charAt(i);
				
				// if the character is a valid number then we have a number that is not zero
				if ((parseInt(chrCurr) != 0) && (!isNaN(parseInt(chrCurr)))) {
					blnZero = false;
				}

				if ((isNaN(parseInt(chrCurr))) && (chrCurr != '.') && (chrCurr != ',')) {
					// if the character is not a decimal place and not a number then we have an error
					return null;
				} else if ((chrCurr == '.') && (!blnDecimalAllowed)) {
					// if the character is a decimal and we aren't allowing them then we have an error
					return null;	
				} else {
					// otherwise we add it to the valid number string
					strNewNum = strNewNum + chrCurr;
				}
			}

			// after going through the number string if we have no valid numbers and we aren't allowing zeroes then error
			if ((blnZero) && (!blnZeroAllowed)) {
				return null;
			}
		}
		// return the valid number string
		return strNewNum;
	}

	function validateReal(objNum, aOptErrorMsg) {
		var integer	= CheckNumber(objNum, true, true);
		if ((integer == null) || (integer.length == 0))	{
			if (typeof(aOptErrorMsg) == "undefined") {
				alert('Invalid value.');
			} else {
				alert(aOptErrorMsg);
			}
			objNum.focus();
			return false;
		}
		return true;
	}

	function validateRealOrSpace(objNum)	{
		var integer	= CheckNumber(objNum, true, true);
		var nowhitespace = (new String(objNum.value)).replace(/ /g,'');

		if (((integer == null) || (integer.length == 0)) && (nowhitespace.length != 0))	{
			alert('Invalid value.');
			objNum.focus();
			return false;
		}
		return true;
	}

	function validateIntegerOrSpace(objNum,aFriendlyName)	{
		var integer	= CheckNumber(objNum, true, false);		
		var nowhitespace = (new String(objNum.value)).replace(/ /g,'');
		if ((integer == null) && (nowhitespace.length != 0))	{
			alert('Invalid integer value.\n\nOn field:' + aFriendlyName);
			objNum.focus();
			return false;
		}
		return true;
	}

	function validateIntegerOrSpaceNoAlert(objNum)	{
		var integer	= CheckNumber(objNum, true, false);		
		var nowhitespace = (new String(objNum.value)).replace(/ /g,'');
		if ((integer == null) && (nowhitespace.length != 0))	{
			objNum.focus();
			return false;
		}
		return true;
	}

	function validateInteger(objNum,aFriendlyName,aCustomMsg)	{
		var integer	= CheckNumber(objNum, true, false);
		if ((integer == null) || (integer.length == 0))	{
			if (typeof(aCustomMsg) == "undefined") {
				alert('Invalid integer value.\n\nOn field:' + aFriendlyName);
			} else {
				alert(aCustomMsg);
			}
			objNum.focus();
			return false;
		}
		return true;
	}

	function validateMoney(objNum) {
		var money	= CheckNumber(objNum, true, true);
		var	dec		= true;

		if (money != null) {
			dec = money.indexOf('.');
			if (dec == -1) {
				dec = true;
			} else {
				dec = ((money.indexOf('.', dec + 1)) == -1 && (money.length - dec == 3));
			}
		}
		if ((money == null) || (money.length == 0) || !dec)	{
			alert('Invalid currency value.');
			objNum.focus();
			return false;
		}
		return true;
	}

	function validateMoneyOrSpace(objNum) {
		var nowhitespace = (new String(objNum.value)).replace(/ /g,'');
		if (nowhitespace.length != 0)	{
			var money	= CheckNumber(objNum, true, true);
			var	dec		= true;
	
			if (money != null) {
				dec = money.indexOf('.');
				if (dec == -1) {
					dec = true;
				} else {
					dec = ((money.indexOf('.', dec + 1)) == -1 && (money.length - dec == 3));
				}
			}
			if ((money == null) || (money.length == 0) || !dec)	{
				alert('Invalid currency value.');
				objNum.focus();
				return false;
			}
		}
		return true;
	}

	function validatePercentage(objNum) {
		var money	= CheckNumber(objNum, true, true);
		var	dec		= true;

		if (money != null) {
			dec = money.indexOf('.');
			if (dec == -1) {
				dec = true;
			} else {
				dec = ((money.indexOf('.', dec + 1)) == -1);
			}
		}
		if ((money == null) || (money.length == 0) || !dec)	{
			alert('Invalid percentage value.');
			objNum.focus();
			return false;
		}
		return true;
	}
	
	function TrimString(aString) {
		var aSource = new String(aString)
		return (aSource.replace(/^\s*/,"")).replace(/\s*$/,"")	
	}
	
	function CustomHTMLDecode(str) {
		s = str.replace(/\&#34;/gi, '"');
		s = s.replace(/\&#39;/gi, "'");
		return s;
	}
