
// isEmpty
	function isEmpty (strValue) {
		return (! strValue.replace (/^(\s*)/, "", strValue));
	}

// isValidEmail
	function isValidEmail (emailStr) {

		var emailPat=/^(.+)@(.+)$/; 
		var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
		var validChars="\[^\\s" + specialChars + "\]"; 
		var quotedUser="(\"[^\"]*\")";
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
		var atom=validChars + '+'; 
		var word="(" + atom + "|" + quotedUser + ")";
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

		var matchArray=emailStr.match(emailPat)
		if (matchArray==null) {
			return false;
		}
		
		var user=matchArray[1];
		var domain=matchArray[2];
		
		if (user.match(userPat)==null) {
			return false;
		}
		
		var IPArray=domain.match(ipDomainPat)
		if (IPArray!=null) {
			for (var i=1;i<=4;i++) {
				if (IPArray[i]>255) {
					return false;
				}
			}
			return true;
		}
		
		var domainArray=domain.match(domainPat)
		if (domainArray==null) {
		    return false;
		}

		var atomPat=new RegExp(atom,"g")
		var domArr=domain.match(atomPat)
		var len=domArr.length
		if (domArr[domArr.length-1].length<2 || 
			domArr[domArr.length-1].length>4) {
			return false;
		}
	
		if (len<2) {
			return false;
		}

		return true;
	}

	function isValidCurrency(strValue)  {
		var objRegExp = /(^\${0,1}\d{1,3}(,{0,1}\d{3})*(\.\d{2})*$)|(^\(\${0,1}\d{1,3}(,{0,1}\d{3})*(\.\d{2}\))*$)/;
		return objRegExp.test( strValue );
	}

// isValidDate
	function isValidDate (strValue) {
		var datePat = /^(\d{2})(\/|-)(\d{2})\2(\d{4})$/;
		var matchArray = strValue.match(datePat); 
		if (matchArray == null) { return false;	}
		day = matchArray[1]; month = matchArray[3]; year = matchArray[4];
		if (month < 1 || month > 12) { return false; }
		if (day < 1 || day > 31) { return false; }
		if ((month==4 || month==6 || month==9 || month==11) && day==31) { return false; }
		if (month==2) {
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			if (day>29 || (day==29 && !isleap)) { return false; }
		}
		return true;
	}

// reduceToDigits
	function reduceToDigits (strValue) {
		return (strValue.replace (/([^0-9])/g, "", strValue));
	}

// reduceToChars
	function reduceToChars (strValue) {
		return (strValue.replace (/([^a-zA-Z0-9\`\-\=\[\]\\\;\'\,\.\/\~\!\@\#\$\%\^\&\*\(\)\_\+\{\}\|\:\"\<\>\? \f\n\r\t\v])/g, "", strValue));
	}

// isDecimalNumber
	function isDecimalNumber (passedVal) {
		if(passedVal == "") {
			return false;
		}
			
		for (i=0; i<passedVal.length; i++) {
			if (passedVal.charAt(i) == ".") {
			}
			else if (passedVal.charAt(i) < "0") {
				return false;
			}
			else if (passedVal.charAt(i) > "9") {
				return false;
			}
		}
		return true;
	}
	
// reduceToDollars
	function reduceToDollars(strValue) {
		if (strValue.indexOf(".") == -1) {
			return ((strValue.replace (/([^0-9])/g, "", strValue) + "00") / 100);
		} else {
			return ((strValue.replace (/([^0-9])/g, "", strValue)) / 100);
		}
	}	

// clearKeys
function clearKeys(formFieldObj) {
	var keyArray = new Array('Title','First Name','Last Name','Area Code','Number');	
	for (j = 0; j < keyArray.length; j++) {
		if (formFieldObj.value == keyArray[j]) {
			formFieldObj.value = '';
		}
	}
}
	
// checkLogOnForm
function checkLogOnForm(formObj) {  

	cleanUpInput(formObj);

	var alert_message = "";
	if (!isValidEmail(formObj.usrIdentifierOne.value)) {
		alert_message = alert_message + "   Valid Email Address\n";
	}
	if (alert_message) {
		alert ("Your form is incomplete.\n" +
			   "You must supply the following information:\n" +
				alert_message);
		return false;
	} else {
		return true;
	}
}

// checkPasswordForm
function checkPasswordForm(formObj) {  

	cleanUpInput(formObj);

	var alert_message = "";
	if (isEmpty(formObj.usrIdentifierTwo.value)) {
		alert_message = alert_message + "   Your Current Password\n";
	}

	if (isEmpty(formObj.newPassword.value)) {
		alert_message = alert_message + "   Your New Password\n";
	}

	if (formObj.newPassword.value != formObj.confirmPassword.value) {
		alert_message = alert_message + "   Your confirmation and new passwords do not match.\n";
	}


	if (alert_message) {
		alert ("Your form is incomplete.\n" +
			   "You must supply the following information:\n" +
				alert_message);
		return false;
	} else {
		return true;
	}
}

// checkContactForm
function checkContactForm(formObj) {  

	cleanUpInput(formObj);

	var alert_message = "";
	if (isEmpty(formObj.from_name.value)) {
		alert_message = alert_message + "   Your Name\n";
	}
	if (!isValidEmail(formObj.from_email.value)) {
		alert_message = alert_message + "   Valid Email Address\n";
	}
	if (alert_message) {
		alert ("Your form is incomplete.\n" +
			   "You must supply the following information:\n" +
				alert_message);
		return false;
	} else {
		return true;
	}
}

// checkAddProjectForm
function checkAddProjectForm(formObj) {  

	cleanUpInput(formObj);

	var alert_message = "";
	if (isEmpty(formObj.prjTitle.value)) {
		alert_message = alert_message + "   Title\n";
	}
	if (isEmpty(formObj.prjDescription.value)) {
		alert_message = alert_message + "   Description\n";
	}
	if (isEmpty(formObj.prjLocation.value)) {
		alert_message = alert_message + "   Place\n";
	}
	if (alert_message) {
		alert ("Your form is incomplete.\n" +
			   "You must supply the following information:\n" +
				alert_message);
		return false;
	} else {
		return true;
	}
}


// checkAddPlanForm
function checkAddPlanForm(formObj) {  

	cleanUpInput(formObj);

	var alert_message = "";
	if (isEmpty(formObj.plnTitle.value)) {
		alert_message = alert_message + "   Title\n";
	}

	if (!isDecimalNumber(formObj.plnInternalSize.value)) {
		alert_message = alert_message + "   A numeric internal size\n";
	}
	if (!isDecimalNumber(formObj.plnExternalSize.value)) {
		alert_message = alert_message + "   A numeric external size\n";
	}
	if (alert_message) {
		alert ("Your form is incomplete.\n" +
			   "You must supply the following information:\n" +
				alert_message);
		return false;
	} else {
		return true;
	}
}


// checkPurchaseForm
function checkPurchaseForm(formObj) {  

	cleanUpInput(formObj);

	var alert_message = "";

	if (isEmpty(formObj.usrCompanyName.value)) {
		alert_message = alert_message + "   Your Company Name\n";
	}
	if (isEmpty(formObj.usrTitle.value) || isEmpty(formObj.usrFirstName.value) || isEmpty(formObj.usrLastName.value)) {
		alert_message = alert_message + "   Your FULL Name\n";
	}
	if (isEmpty(formObj.usrPhoneWork.value)) {
		alert_message = alert_message + "   Your Work Phone\n";
	}
	if (!isValidEmail(formObj.usrEmail.value)) {
		alert_message = alert_message + "   Your Email\n";
	}

	if (isEmpty(formObj.pchOneTitle.value) || isEmpty(formObj.pchOneFirstName.value) || isEmpty(formObj.pchOneLastName.value)) {
		alert_message = alert_message + "   Purchaser's FULL Name\n";
	}
	if (isEmpty(formObj.pchOneAddressOne.value)) {
		alert_message = alert_message + "   Purchaser's Address\n";
	}
	if (isEmpty(formObj.pchOneSuburb.value)) {
		alert_message = alert_message + "   Purchaser's Suburb\n";
	}
	if (isEmpty(formObj.pchOneState.value)) {
		alert_message = alert_message + "   Purchaser's State\n";
	}
	if (isEmpty(formObj.pchOnePostcode.value)) {
		alert_message = alert_message + "   Purchaser's Postcode\n";
	}
	if (isEmpty(formObj.pchOnePhoneWork.value)) {
		alert_message = alert_message + "   Purchaser's Work Phone\n";
	}
	if (!isValidEmail(formObj.pchOneEmail.value)) {
		alert_message = alert_message + "   Purchaser's Email\n";
	}

	if (isEmpty(formObj.slcName.value)) {
		alert_message = alert_message + "   Solicitor's Name\n";
	}
	if (isEmpty(formObj.slcAddressOne.value)) {
		alert_message = alert_message + "   Solicitor's Address\n";
	}
	if (isEmpty(formObj.slcSuburb.value)) {
		alert_message = alert_message + "   Solicitor's Suburb\n";
	}
	if (isEmpty(formObj.slcState.value)) {
		alert_message = alert_message + "   Solicitor's State\n";
	}
	if (isEmpty(formObj.slcPostcode.value)) {
		alert_message = alert_message + "   Solicitor's Postcode\n";
	}
	if (isEmpty(formObj.slcPhoneWork.value)) {
		alert_message = alert_message + "   Solicitor's Phone\n";
	}
	if (isEmpty(formObj.slcFaxWork.value)) {
		alert_message = alert_message + "   Solicitor's Facsimile\n";
	}
	if (!isValidEmail(formObj.slcEmail.value)) {
		alert_message = alert_message + "   Solicitor's Email\n";
	}
//	if (!formObj.agreeToPrivacy.checked) {
//		alert_message = alert_message + "   Agree to the Privacy Statement\n";
//	}

	if (alert_message) {
		alert ("Your form is incomplete.\n" +
			   "You must supply the following information:\n" +
				alert_message);
		return false;
	} else {
//		confirmMessage = '                         PURCHASING PROCEDURES\n\n';
//		confirmMessage = confirmMessage + 'This referral will be processed within 24 hours and on\nacceptance will require a completed PAMD Form 27b to trigger\nthe issue of contracts.\n\n';
//		confirmMessage = confirmMessage + 'Purchasers will then have 10 days to complete, sign and return\nto secure their purchase.\n\n';
//		confirmMessage = confirmMessage + 'Australasian Developments Pty Ltd reserves the right to cancel any sale outside\nthis time frame.\n\n';
//		alert(confirmMessage);
		return true;
	}
}


// checkReferralForm
function checkReferralForm(formObj) {  

	cleanUpInput(formObj);

	var alert_message = "";

	if (isEmpty(formObj.usrCompany.value)) {
		alert_message = alert_message + "   Your Company Name\n";
	}
	if (isEmpty(formObj.usrFirstName.value) || isEmpty(formObj.usrLastName.value)) {
		alert_message = alert_message + "   Your FULL Name\n";
	}
	if (isEmpty(formObj.usrPhone.value)) {
		alert_message = alert_message + "   Your Phone\n";
	}
	if (!isValidEmail(formObj.usrEmail.value)) {
		alert_message = alert_message + "   Your Email\n";
	}

	
	if (isEmpty(formObj.pchName.value)) {
		alert_message = alert_message + "   Purchaser's Name\n";
	}
	if (isEmpty(formObj.pchAddress.value)) {
		alert_message = alert_message + "   Purchaser's Address\n";
	}

	
	if (isEmpty(formObj.slcCompany.value)) {
		alert_message = alert_message + "   Solicitor's Name\n";
	}
	if (isEmpty(formObj.slcPhone.value)) {
		alert_message = alert_message + "   Solicitor's Phone\n";
	}
	if (!formObj.agreeToPrivacy.checked) {
		alert_message = alert_message + "   Agree to the Privacy Statement\n";
	}

	if (alert_message) {
		alert ("Your form is incomplete.\n" +
			   "You must supply the following information:\n" +
				alert_message);
		return false;
	} else {
//		confirmMessage = '                         PURCHASING PROCEDURES\n\n';
//		confirmMessage = confirmMessage + 'This referral will be processed within 24 hours and on\nacceptance will require a completed PAMD Form 27c to trigger\nthe issue of contracts.\n\n';
//		confirmMessage = confirmMessage + 'Purchasers will then have 10 days to complete, sign and return\nto secure their purchase.\n\n';
//		confirmMessage = confirmMessage + 'Property Navigator reserves the right to cancel any sale outside\nthis time frame.\n\n';
//		alert(confirmMessage);
		return true;
	}
}

/*
// checkReferralForm
function checkReferralForm(formObj) {  

	cleanUpInput(formObj);

	var alert_message = "";

	if (isEmpty(formObj.usrCompanyName.value)) {
		alert_message = alert_message + "   Your Company Name\n";
	}
	if (isEmpty(formObj.usrTitle.value) || isEmpty(formObj.usrFirstName.value) || isEmpty(formObj.usrLastName.value)) {
		alert_message = alert_message + "   Your FULL Name\n";
	}
	if (isEmpty(formObj.usrPhoneWork.value)) {
		alert_message = alert_message + "   Your Work Phone\n";
	}
	if (!isValidEmail(formObj.usrEmail.value)) {
		alert_message = alert_message + "   Your Email\n";
	}

	if (isEmpty(formObj.pchOneTitle.value) || isEmpty(formObj.pchOneFirstName.value) || isEmpty(formObj.pchOneLastName.value)) {
		alert_message = alert_message + "   Purchaser's FULL Name\n";
	}
	if (isEmpty(formObj.pchOneAddressOne.value)) {
		alert_message = alert_message + "   Purchaser's Address\n";
	}
	if (isEmpty(formObj.pchOneSuburb.value)) {
		alert_message = alert_message + "   Purchaser's Suburb\n";
	}
	if (isEmpty(formObj.pchOneState.value)) {
		alert_message = alert_message + "   Purchaser's State\n";
	}
	if (isEmpty(formObj.pchOnePostcode.value)) {
		alert_message = alert_message + "   Purchaser's Postcode\n";
	}
	if (isEmpty(formObj.pchOnePhoneWork.value)) {
		alert_message = alert_message + "   Purchaser's Work Phone\n";
	}
	if (!isValidEmail(formObj.pchOneEmail.value)) {
		alert_message = alert_message + "   Purchaser's Email\n";
	}

	if (isEmpty(formObj.slcName.value)) {
		alert_message = alert_message + "   Solicitor's Name\n";
	}
	if (isEmpty(formObj.slcAddressOne.value)) {
		alert_message = alert_message + "   Solicitor's Address\n";
	}
	if (isEmpty(formObj.slcSuburb.value)) {
		alert_message = alert_message + "   Solicitor's Suburb\n";
	}
	if (isEmpty(formObj.slcState.value)) {
		alert_message = alert_message + "   Solicitor's State\n";
	}
	if (isEmpty(formObj.slcPostcode.value)) {
		alert_message = alert_message + "   Solicitor's Postcode\n";
	}
	if (isEmpty(formObj.slcPhoneWork.value)) {
		alert_message = alert_message + "   Solicitor's Phone\n";
	}
	if (isEmpty(formObj.slcFaxWork.value)) {
		alert_message = alert_message + "   Solicitor's Facsimile\n";
	}
	if (!isValidEmail(formObj.slcEmail.value)) {
		alert_message = alert_message + "   Solicitor's Email\n";
	}
	if (!formObj.agreeToPrivacy.checked) {
		alert_message = alert_message + "   Agree to the Privacy Statement\n";
	}

	if (alert_message) {
		alert ("Your form is incomplete.\n" +
			   "You must supply the following information:\n" +
				alert_message);
		return false;
	} else {
		confirmMessage = '                         PURCHASING PROCEDURES\n\n';
		confirmMessage = confirmMessage + 'This referral will be processed within 24 hours and on\nacceptance will require a completed PAMD Form 27b to trigger\nthe issue of contracts.\n\n';
		confirmMessage = confirmMessage + 'Purchasers will then have 10 days to complete, sign and return\nto secure their purchase.\n\n';
		confirmMessage = confirmMessage + 'Property Navigator reserves the right to cancel any sale outside\nthis time frame.\n\n';
		alert(confirmMessage);
		return true;
	}
}
*/

// checkContactForm
function checkGuestEntryForm(formObj) {  

	cleanUpInput(formObj);

	var alert_message = "";
	if (isEmpty(formObj.usrFirstName.value) || isEmpty(formObj.usrLastName.value)) {
		alert_message = alert_message + "   Your First and Last Name\n";
	}

	if (isEmpty(formObj.usrPhone.value) && isEmpty(formObj.usrMobile.value)) {
		alert_message = alert_message + "   At Least One Phone Number\n";
	}

	if (!isValidEmail(formObj.usrEmail.value)) {
		alert_message = alert_message + "   Valid Email Address\n";
	}

	if (formObj.usrProfession.selectedIndex == 0) {
		alert_message = alert_message + "   Who You Are\n";
	}	

	if (alert_message) {
		alert ("Your form is incomplete.\n" +
			   "You must supply the following information:\n" +
				alert_message);
		return false;
	} else {
		return true;
	}
}


// checkAddProjectForm
function checkCopyProjectForm(formObj) {  

	var alert_message = "";
	if (formObj.prjCurrentTitle.value == formObj.prjNewTitle.value) {
		alert_message = alert_message + "   A Differnt Title\n";
	}
	if (alert_message) {
		alert ("Your form is incomplete.\n" +
			   "You must supply the following information:\n" +
				alert_message);
		return false;
	} else {
		return true;
	}
}



function cleanUpInput(formObj) {
	for (i = 0; i < formObj.elements.length; i++) {
		clearKeys(formObj.elements[i]);
		switch(formObj.elements[i].type) {
			case "textarea":
				formObj.elements[i].value = reduceToChars(formObj.elements[i].value);
			break;
			case "text":
				formObj.elements[i].value = reduceToChars(formObj.elements[i].value);
			break;
		}
	}

}


