// isDecimalNumber
	function isDecimalNumber (passedVal) {
		if(passedVal == "") {
			return false;
		}
			
		for (z=0; z<passedVal.length; z++) {
			if (passedVal.charAt(z) == ".") {
			}
			else if (passedVal.charAt(z) == "-") {
			}
			else if (passedVal.charAt(z) < "0") {
				return false;
			}
			else if (passedVal.charAt(z) > "9") {
				return false;
			}
		}
		return true;
	}


// isSelected
	function isSelected (strValue) {
		if (strValue == "")
			return false;
		else
			return true;
	}


// isEmpty
	function isEmpty (strValue) {
		return (! strValue.replace (/^(\s*)/, "", strValue));
	}
	
// isInteger
	function isInteger (passedVal) {
		if(passedVal == "") {
			return false;
		}
			
		for (z=0; z<passedVal.length; z++) {
			if (passedVal.charAt(z) < "0") {
				return false;
			}
			else if (passedVal.charAt(z) > "9") {
				return false;
			}
		}
		return true;
	}
	
// isRadioSelected
	function isRadioSelected (radioObject) {
		eventOption = -1;
	
		if (radioObject[0]) {			
			for ( z=0; z < radioObject.length; z++) {
				if (radioObject[z].checked) {
					eventOption = z;
				}
			}
		} 
		else {
			if (radioObject.checked) { eventOption = 1; }
		}
			
		if(eventOption == -1) {
			return false;
		} else {
			return true;
		}
	}
	
// isSelected
	function isSelected (strValue) {
		if (strValue == "0" || strValue == "")
			return false;
		else
			return true;
	}
	
	
// Return "true" if "monthnum" and "yearnum" constitute a valid credit card date.
//
// Created (16 Oct 2000) Raymond Woo
// Modified (24 May 2001) Raymond Woo -- optimised code for checking : 2 digits only for month/year each
	function isValidCCDate(monthnum, yearnum) {
		var now = new Date();
		var futureexpiry = (now.getYear() + 10); // within x years
		// Must be 2 digits each
		if ((! /^\d{2}$/.test(monthnum)) || (! /^\d{2}$/.test(yearnum))) return false;
		// Cannot have expired and must be within x years.
		if (monthnum > 12 || monthnum < 1) return false;
		if (yearnum > (futureexpiry%100) || yearnum < (now.getYear()%100)) return false;
		if (yearnum == (now.getYear()%100) && monthnum <= now.getMonth()) return false; 
		return true;
	}
	
	
// Return "true" if "numbertocheck" is a valid credit card number, as defined by the Luhn algorithm.
//
// Created (16 Oct 2000) Raymond Woo
// Modified (24 May 2001) Raymond Woo -- optimised code for checking : 16-19 digits only
// Modified (20 Aug 2001) Raymond Woo -- doh, AMEX is 15 digits. have now dropped the lowerbound to 5, in case of proprietry cards
	function isValidCCNumber(numbertocheck) {
		var weight = 1;
		var checktotal = 0;
		//Characters can only be (5 to 19) digits.
		if (! /^\d{5,19}$/.test(numbertocheck)) return false;
		//LUHN check.
		if (numbertocheck.length % 2 == 0) {weight = 2}  
		else {weight = 1}
		for (z=0; z <= numbertocheck.length-1; z++) 
		{
			digit = numbertocheck.substring(z, z+1);
			val = digit * weight;
			if (val > 9) {val = val - 9}
			checktotal = checktotal + val;
			weight = (weight == 2) ? 1 : 2;
		}
		if (checktotal %10 == 0) {return true}  
		else {return false}
	}
	
	
	// Returns an error message if there is an error with the credit card, returns null otherwise.
	// This requires the isValidCCNumber and isValidCCDate javascript functions.
	// Input:	numbertocheck = the credit card number - digits ONLY, no spaces
	//			monthnum, yearnum = the expiry month and year (2-digit year)
	//			cardtype = one of "VISA", "MAST","BANK", "DINE", "AMEX", "JCB", "PROP"
	// 
	// Created (24 May 2001) Raymond Woo
	
	function validateCCard (numbertocheck, monthnum, yearnum, cardtype) {
		if (!isValidCCNumber(numbertocheck)) return "Credit Card Number is not valid";
		if (!isValidCCDate(monthnum, yearnum)) return "Expiry Date is not valid";
		
		switch (cardtype) {
			case "VISA" :
				if (! /4\d+/.test(numbertocheck))
					return "Card number does not appear to be valid for a VISA";
				break;
			case "MAST" :
				if (! /5[12345]\d+/.test(numbertocheck))
					return "Card number does not appear to be valid for a Mastercard";
				break;
			case "BANK" :
				if ((! /56022[12345]\d+/.test(numbertocheck)) && (! /56105\d+/.test(numbertocheck)))
					return "Card number does not appear to be valid for a Bankcard";
				break;
			case "DINE" :
				if (! /3[0689]\d+/.test(numbertocheck))
					return "Card number does not appear to be valid for a Diners Club";
				break;
			case "AMEX" :
				if (! /3[47]\d+/.test(numbertocheck))
					return "Card number does not appear to be valid for an American Express";
				break;
			case "JCB" :
				if ((! /1800\d+/.test(numbertocheck)) && (! /2131\d*/.test(numbertocheck)) && (! /35(28|29|[345678])\d+/.test(numbertocheck)))
					return "Card number does not appear to be valid for a JCB";
				break;
			case "PROP" :
				if (! /5[078]\d+/.test(numbertocheck))
					return "Card number does not appear to be valid for a Proprietry Card";
				break;
			default : return "Card Type is not valid";
		}

		return null; // validated
	}
	
	
// Checks the date input for a valid format.
// This code accepts the date formats: DD/MM/YYYY or DD-MM-YYYY
// To alter the format checked for, change the datePat (date pattern) -
//    d{2} requires 2 digits, d{1,2} requires either 1 or 2 digits etc.
//    \/|- requires / or - as a separator etc.
//
// Created (16 Oct 2000) Raymond Woo
	function isValidDate (strValue) {
		var datePat = /^(\d{2})(\/)(\d{2})\2(\d{4})$/; // Change this to check for a different format
		var matchArray = strValue.match(datePat); // is the format ok?
		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;  // date is valid
	}
	
// 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>3) {
			return false;
		}
			
		if (len<2) {
			return false;
		}
		
		return true;
	}

	
	
// Returns "true" if the "strValue" is in a valid 12 hour time format, eg. HH:MM or H:MM 
// P or PM or A or AM are optional at the end, and are case insensitive.
//
// Created (16 Oct 2000) Raymond Woo
// Modified (27 Nov 2000) Raymond Woo "AM" matching corrected. Doh.
	function isValidTime ( strValue ) {
		var objRegExp = /^(0{0,1}[1-9]|1[0-2]):[0-5]\d\s*([A]|[P])M*$/i;
		return objRegExp.test( strValue );
	}
	
	
// isValidURL
	function isValidURL (strValue) {
		
		// CHECK IF HAS VALID URL PREFIX
		var urlPrefixArray = new Array();
		urlPrefixArray[0] = "file";
		urlPrefixArray[1] = "ftp";
		urlPrefixArray[2] = "gopher";
		urlPrefixArray[3] = "http";
		urlPrefixArray[4] = "https";
		urlPrefixArray[5] = "telnet";
		urlPrefixArray[6] = "wais";
		urlPrefixArray[7] = "mailto";
		urlPrefixArray[8] = "news";
		
		
		hasPrefix = false;
		stringAddress = "";
		var stringArray = strValue.split(":");
		stringPrefix = stringArray[0];
		
		if (stringArray.length >= 2) stringAddress = stringArray[1];
		
		
		var addressArray = stringAddress.split("//");
		if (addressArray.length >= 2) stringAddress = addressArray[1];
		
		
		for (i = 0; i < urlPrefixArray.length; i++) {
			if(urlPrefixArray[i] == stringPrefix) {
				hasPrefix = true;
			}
		}
		
		// IF NO VALID PREFIX - RETURN FALSE
		if (!hasPrefix) return false;
		
		
		// are regular expressions supported?
	    var supported = 0;
	    if (window.RegExp) {
	        var tempStr = "a";
	        var tempReg = new RegExp(tempStr);
	        if (tempReg.test(tempStr)) supported = 1;
	    }
		
		// check if right format
	    if (supported) {
			var r1 = new RegExp(/^[a-z0-9\-]+(\.[a-z0-9\-]+)*(\.[a-z]{2,3})+$/);
			
			return (r1.test(stringAddress));
			
	    } else {
			return true;
		}
	}
	
	
// Eliminates everything apart from digits (0 through 9) from a string.
//
// Created (16 Oct 2000) Raymond Woo
	function reduceToDigits (strValue) {
		return (strValue.replace (/([^0-9])/g, "", strValue));
	}

// Compare two dates (dd/mm/yyyy) 
// return 0 if 'end' is greater than 'start'
	function compareTwoDate(start, end)
	{
		// start date comparison
		var startDateArray = start.split("/");
		var startDate = new Date;
		startDate.setDate(startDateArray[0]);
		startDate.setMonth(startDateArray[1]-1);
		startDate.setFullYear(startDateArray[2]);
		
		var endDateArray = end.split("/");
		var endDate = new Date;
		endDate.setDate(endDateArray[0]);
		endDate.setMonth(endDateArray[1]-1);
		endDate.setFullYear(endDateArray[2]);
		
		if (endDate < startDate)
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}

	
//////////////////////////////////////////////////////////////////////////////////////
//////																			//////
//////							FORM CHECKING									//////
//////																			//////
//////////////////////////////////////////////////////////////////////////////////////


//interestCheckComplete
	function checkRegistrationForm(formObj) {  
		var alert_message = ""; 
	
		if (isEmpty(formObj.tradingName.value)) {
			alert_message = alert_message + "   Trading Name\n";
		}

		if (isEmpty(formObj.abn.value)) {
			alert_message = alert_message + "   ABN\n";
		}

		if (isEmpty(formObj.streetAddress.value)) {
			alert_message = alert_message + "   Street Address\n";
		}

		if (isEmpty(formObj.suburb.value)) {
			alert_message = alert_message + "   Suburb\n";
		}

		if (isEmpty(formObj.city.value)) {
			alert_message = alert_message + "   City\n";
		}

		if (isEmpty(formObj.postcode.value)) {
			alert_message = alert_message + "   Postcode\n";
		}

		if (!isEmpty(formObj.email.value)) {
			if (!isValidEmail(formObj.email.value)) {
				alert_message = alert_message + "   Valid Email\n";
			}
		}
		else
		{
			alert_message = alert_message + "   Valid Email\n";
		}

		if (isEmpty(formObj.phoneno.value)) {
			alert_message = alert_message + "   Phone No.\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 checkAddProductSeason(formObj)
	{
		var alert_message = ""; 
	
		if (formObj.seaID.value == 0) {
			alert_message = alert_message + "   Season Name\n";
		}

		if (isEmpty(formObj.seasonStartDate.value)) {
			alert_message = alert_message + "   Season Start Date\n";
		}
		else
		{
			if (!isValidDate(formObj.seasonStartDate.value))
			{
				alert_message = alert_message + "   Valid Season Start Date\n";
			}
		}

		if (isEmpty(formObj.seasonEndDate.value)) {
			alert_message = alert_message + "   Season End Date\n";
		}
		else
		{
			if (!isValidDate(formObj.seasonEndDate.value))
			{
				alert_message = alert_message + "   Valid Season End Date\n";
			}
		}

		if (!alert_message)
		{
			if (compareTwoDate(formObj.seasonStartDate.value,formObj.seasonEndDate.value) == 1)
			{
				alert_message = alert_message + "   End date must be greater than the start date\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 checkAddProductComment(formObj)
	{
		var alert_message = ""; 
	
		if (formObj.commentType.value == 0) {
			alert_message = alert_message + "   Comment Type\n";
		}

		if (isEmpty(formObj.commentText.value)) {
			alert_message = alert_message + "   Comment Text\n";
		}

		if (!isEmpty(formObj.commentDate.value)) {
			if (!isValidDate(formObj.commentDate.value))
			{
				alert_message = alert_message + "   Valid Comment Date\n";
			}
		}

		if (!isEmpty(formObj.commentFollowUpDate.value)) {
			if (!isValidDate(formObj.commentFollowUpDate.value))
			{
				alert_message = alert_message + "   Valid Comment Follow Up Date\n";
			}
		}

		if (!isEmpty(formObj.commentDate.value) && !isEmpty(formObj.commentFollowUpDate.value)) {
			if (compareTwoDate(formObj.commentDate.value,formObj.commentFollowUpDate.value) == 1)
			{
				alert_message = alert_message + "   Follow up date must be greater than the comment date\n";			
			}
		}

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" + 
				   alert_message )
			return false;
		} else { 
			return true;
		}
	}	
	
	

// checkPostcodeSearchFormComplete
	function checkPostcodeSearchFormComplete(formObj) {
		var alert_message = "";
		
		if (isEmpty(formObj.txtLocation.value) && isEmpty(formObj.txtPostCode.value)) {
			alert_message = alert_message + "You must provide Suburb and Postcode\n" + 
				"to submit this form.";
		}

		if (alert_message) {
			alert (alert_message);
			return false;
		} else {
			return true;
		}
	}

//checkContactComplete
	function checkContactComplete(formObj) {
		var alert_message = ""; 
	
		if (isEmpty(formObj.contactName.value)) {
			alert_message = alert_message + "   Your name\n";
		}
		if (!isValidEmail(formObj.contactEmail.value)) {
			alert_message = alert_message + "   Your email address\n";
		}
		if (isEmpty(formObj.contactPhone.value)) {
			alert_message = alert_message + "   Your phone number\n";
		}
		if (!isSelected(formObj.contactType.value)) {
			alert_message = alert_message + "   Inquiry type\n";
		}
		if (isEmpty(formObj.contactDetails.value)) {
			alert_message = alert_message + "   Your inquiry details\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 checkAdvertiseComplete(formObj) {
		var alert_message = ""; 
	
		if (isEmpty(formObj.businessName.value)) {
			alert_message = alert_message + "   Your business name\n";
		}
		if (isEmpty(formObj.contactName.value)) {
			alert_message = alert_message + "   Your contact name\n";
		}
		if (!isValidEmail(formObj.contactEmail.value)) {
			alert_message = alert_message + "   Your email address\n";
		}
		if (isEmpty(formObj.businessAddress.value)) {
			alert_message = alert_message + "   Your business address\n";
		}
		if (isEmpty(formObj.businessCategory.value)) {
			alert_message = alert_message + "   Your business category\n";
		}

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" + 
				   alert_message )
			return false;
		} else { 
			return true;
		}
	}
	
//doRestrictCity
	//Only allow searching on BRISBANE - Q1 20050506
	// BS 20051003
	function doRestrictCity(value) {
		var allowedCities = new Array("Brisbane","Sydney","Melbourne","Darwin","Canberra","Adelaide","Hobart","Perth");
//		var allowedCities = new Array("Brisbane");
		var cityCounter = 0;
		var allowed = false;
		for ( i = 0; i < allowedCities.length; i++) {
			if (value == allowedCities[i]) {
				allowed = true;
			}
			if (value == "") {
				allowed = true;
			}
		}
		if (!allowed ) {
			alert("Searching in " + value + " is not currently available.");
			return false;
		} else {
			return true;
		}

	}