
// 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));
	}

// isValidAcnAbnNumber	 
	function isValidAcnAbnNumber(numberToCheck) {
	
		numberToCheck = reduceToDigits(numberToCheck);
		
		// if we have a nine digit number than we have an ACN number
		if (numberToCheck.length == 9) {
	
			// set vars required for calculations
			weight = 0;
			checkTotal = 0;
	
			// checkDigit is always the last number in the ACN
			checkDigit = numberToCheck.substring(numberToCheck.length - 1, numberToCheck.length);
	
			// counting down from the last digit to the first digit
			// the check works as follows: sum the 1st digit * 8; 2nd digit * 7; 3rd * 6 etc...
			for (i = (numberToCheck.length - 1); i >= 0; i--) {
				digit = numberToCheck.substring(i, i+1);
				// the total is the sum of each digit multiplied by the weight
				// the checkDigit multiplys by a weight of zero therefor excluding it from the sum 
				checkTotal = checkTotal + (digit * weight);				
				// up the weight multiple by one
				weight++;
			}
	
			// once we have the sumed total from above
			// find its modulus of 10: (ie reaminder left when you divied by 10)
			remainder = checkTotal % 10;
			
			// if the remainder is 10 set it to 0
			if (remainder == 0) {
				caluclatedCheckDigit = 0;
			// if not then subtract it from 10
			} else	{
				caluclatedCheckDigit = 10 - remainder;
			}
	
			// the calculated check digit and the actual check digit should match
			if (caluclatedCheckDigit == checkDigit) {
				return true;
			} else {
				return false;
			} 
		
	
		// if we have an eleven digit number than we have an ABN number
		} else if (numberToCheck.length == 11) {
			
			// the weight multiples for an ABN check is as follows
			weightArray = new Array(10,1,3,5,7,9,11,13,15,17,19);
			// set vars required for calculations
			checkTotal = 0;
	
			// first thing for the check is to take 1 from the first digit
			firstNumber = numberToCheck.substring(0, 1);
			firstNumber = firstNumber - 1;
			// use this to create a NEW eleven digit number
			newNumber = firstNumber + numberToCheck.substring(1, numberToCheck.length);
		
			// loop over all the digits in the new number
			for (i = 0; i <= newNumber.length - 1 ; i++) {
				digit = newNumber.substring(i, i+1);
				// the total is the sum of each digit multiplied by its weighting
				checkTotal = checkTotal + (digit * weightArray[i]);				
			}
	
			// once we have the sumed total from above
			// find its modulus of 89: (ie reaminder left when you divied by 89)
			remainder = checkTotal % 89;
		
			// if the remainder is 0 then its a valid abn number
			if (remainder == 0) {
				return true;
			} else {
				return false;
			} 
	
		// if it is not 9 or 11 digits long then its all wrong buddy
		} else {
			return false;
		}
	}
		 
// checkCostCalculatorFormOne	 
	function checkCostCalculatorFormOne(formObj) {
		var alert_message = "";
		if (isEmpty(formObj.usrName.value)) {
			alert_message = alert_message + "   Your Name\n";
		}
		if (!isValidEmail(formObj.usrEmail.value)) {
			alert_message = alert_message + "   A Valid Email Address\n";
		}	
		if (isEmpty(formObj.cmpName.value)) {
			alert_message = alert_message + "   Your Company Name\n";
		}
//		if (!isValidAcnAbnNumber(formObj.cmpABNACN.value)) {
//			alert_message = alert_message + "   A Valid ABN or ACN\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) {
		var alert_message = "";
		if (isEmpty(formObj.usrName.value)) {
			alert_message = alert_message + "   Your Name\n";
		}
		if (!isValidEmail(formObj.usrEmail.value)) {
			alert_message = alert_message + "   A 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;
		}
	}