<!--

function browserName () {
	var ret;
	ret='N/A';

	if (navigator.appName.indexOf("Netscape")!=-1) {
		ret='NS';
	}
	else {
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			ret='MSIE';
		}	
	}
	
	return ret;
}

function browserVersion () {
	var ret;
	
	if (navigator.appVersion.indexOf("2.")!=-1) 
		return 2;
	if (navigator.appVersion.indexOf("3.")!=-1)
		return 3;
	if (navigator.appVersion.indexOf("4.")!=-1)
		return 4;
	if (navigator.appVersion.indexOf("5.")!=-1)
		return 5;
	
	return 0;
}

function isAlphaOnly(s) {
	var i,c;
	var bv; bv = browserVersion();	
		
	for (i = 0; i < s.length; i++) {
	   c = s.charAt(i);	   	   
	   if (!((c >= 'a' && c <='z') || (c >= 'A' && c <='Z') || (c == ' '))) {
			if (bv < 4)
				return false;
				
			/* only check if v4 browser or above */
			if ((c.charCodeAt(0) <= 128)) 	  
				return false;	
		}
	}
	
	return true;		
}

function isInteger(s) {
	var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

function checkEmail (s) {
	
	if (isEmpty(s)) return "";
    
	var posAt = s.indexOf('@');
	var err = false;
	var msg = '';

	if (s.indexOf(' ') > -1 ) {
		//msg += "The must be no spaces in your email address\n";
		err = true;
	}

	if (posAt == 0) {
       	//msg += "There must be a name before the @ symbol in your email address\n";
		err = true;
	} 
    
	if (posAt == -1) {
		//msg += "There must be an @ symbol in your email address\n";
		err = true;
	}

	if (s.indexOf('@', posAt +1) > -1) {
		//msg += "There must only be one @ symbol in your email address\n";
		err = true;
	}

	if (posAt == s.length -1) {
		//msg += "Something must follow the @ symbol in your email address\n";
		err = true;
	}
	

	var posDot = s.indexOf('.', posAt);

	if (posDot == -1) {
		//msg += "There must be a host containing a dot following the @ symbol in your email address\n";
		err = true;
	}

	if (posDot == posAt + 1) {
		//msg += "There must be a name between the @ and . symbols in your email address\n";
		err = true;
	}

	if (posDot == s.length-1) {
		//msg += "A dot cannot be the last character of your email address\n";
		err = true;
	}

	if (err) {
		return "Please enter a valid email address\n";
	} else {
		return "";
	}
}

function isEmpty(s) {
	return ((s == null) || (s.length == 0))
}

function isDigit(c) {
	return ((c >= "0") && (c <= "9"))
}

function isDigitsOnly(s) {
	var i,c;
	for (i = 0; i < s.length; i++) {
	   c = s.charAt(i);	   
	   if (!isDigit(c))
			return false;	
	}
	
	return true;		
}


function checkCase(o) {

	// ignore empty field
	if (o.value == '') return true;
	
	var wrk = new String (o.value);
	var wordList = wrk.split(" ");
	var ret = '';
	var i;

	for (i = 0; i < wordList.length; i++) {
		ret = ret + checkCaseWord(wordList[i]);
		if (i < wordList.length-1) ret = ret + ' ';
	}	
	
	o.value = ret;

	return true;
}

function checkCaseWord(s) {
	if (s.length < 2) return s.toUpperCase();

	var wrk;


	// caseify
	wrk = s.toLowerCase();
	var ret = wrk.substring(0,1);
	ret = ret.toUpperCase();
	ret = ret + wrk.substring(1, wrk.length);

	if (ret.substring(0,2) == "Mc") {
	wrk = ret.substring(2,3);
		ret = "Mc" + wrk.toUpperCase() + ret.substring(3, ret.length);
	}
	if (ret.substring(0,3) == "Mac") {
		wrk = ret.substring(3,4);
		ret = "Mac" + wrk.toUpperCase() + ret.substring(4, ret.length);
	}
	if (ret.substring(0,2) == "O\'") {
		wrk = ret.substring(2,3);
		ret = "O\'" + wrk.toUpperCase() + ret.substring(3, ret.length);
	}

	var dashOffset = ret.indexOf("-");
	if((dashOffset > -1) && (dashOffset < ret.length - 1)) {
		wrk = checkCaseWord(ret.substring(dashOffset + 1, ret.length));
		ret = ret.substring(0, dashOffset) + "-" + wrk;
	}

	return ret;		

}

function isAreaCode(a) {

	var i;
	for (i = 0; i < a.length; i++) {
		if ( !(( a.charCodeAt(i) >= 48 && a.charCodeAt(i) <= 57) ||
		        a.charCodeAt(i) == 40 || 
				a.charCodeAt(i) == 41 || 
				a.charCodeAt(i) == 32) )
			return false;
	}

	return true;

}

function isPhoneNo(p) {

	var i;
	for (i = 0; i < p.length; i++) {
		if ( !(( p.charCodeAt(i) >= 48 && p.charCodeAt(i) <= 57) ||
				p.charCodeAt(i) == 32) )
			return false;
	}

	return true;

}

// @name 		isDollar
// @param 		dollarAmount
// @param		stringName 
// @param		required 
// @description	Checks the dollarAmount to see if it is a valid dollar value or empty.
//				Checks required to see if empty string is valid.
// @pre			none
// @post		none
// @return		Returns an empty string if OK, else returns an error message

function isDollar(dollarAmount, stringName, required) {
	

	if (!required && isEmpty(dollarAmount)) {
		return "";
	}

	if (required && isEmpty(dollarAmount)) {
		return "Please enter a dollar value for the " + stringName + "\n";
	}

	if (dollarAmount.charCodeAt(0) == 45) {
			return "Please re-enter the amount for the " + stringName + " without a negative sign in front\n";
	} else {
		var i;
		var dotCount = 0;
		var errFound = false;

		for(var i = 0; i < dollarAmount.length; i++) {
			
			if (!((dollarAmount.charAt(i) >= '0' && dollarAmount.charAt(i) <= '9') ||
					dollarAmount.charAt(i) == '.' || dollarAmount.charAt(i) == ',')) {
					errFound = true;
					break;
			}
			if (dollarAmount.charAt(i) == '.') dotCount++;
		}

		if(errFound || (dotCount > 1)) {
			return "Please enter a valid amount for the " + stringName + "\n";
		}

	}

	return "";
	
}

// @name 		validCharsAndNumsOnly
// @param 		s in String
// @description	Checks the s parameter to see if it contains valid characters and numerics only.
//				Valid characters are a-z, A-Z, comma, space, hyphen, quote.
// @pre			none
// @post		none
// @return		Returns an empty string if OK, else returns an error message.

function validCharsAndNumsOnly(s) {

	var i;

	for (i=0; i< s.length; i++) {
		if (!( (s.charCodeAt(i) >= 65 && s.charCodeAt(i) <= 90) || 
		 	(s.charCodeAt(i) >= 97 && s.charCodeAt(i) <= 122) ||
			(s.charCodeAt(i) >= 48 && s.charCodeAt(i) <= 57) ||
			s.charAt(i) == "'" || s.charAt(i) == "-" || 
			s.charAt(i) == " " || s.charAt(i) == "," )) {
			return false;
		}

	}

	return true;

}

// @name 		validCharsOnly
// @param 		s in String
// @description	Checks the s parameter to see if it contains valid characters only.
//				Valid characters are a-z, A-Z, comma, space, hyphen, quote.
// @pre			none
// @post		none
// @return		Returns an empty string if OK, else returns an error message.

function validCharsOnly(s) {

	var i;

	for (i=0; i< s.length; i++) {
		if (!( (s.charCodeAt(i) >= 65 && s.charCodeAt(i) <= 90) || 
		       (s.charCodeAt(i) >= 97 && s.charCodeAt(i) <= 122) ||
			s.charAt(i) == "'" || s.charAt(i) == "-" || 
			s.charAt(i) == " " || s.charAt(i) == "," )) {
			return false;
		}

	}

	return true;

}

// @name 		addressCharsAndNumsOnly
// @param 		s in String
// @description	Checks the s parameter to see if it contains valid characters and numerics only.
//				This is used by the checkAddress Function. It differs from validCharsAndNumsOnly
//				in that it allows the forward slash character.
//				Valid characters are a-z, A-Z, comma, space, hyphen, quote, forward slash.
// @pre			none
// @post		none
// @return		Returns an empty string if OK, else returns an error message.

function addressCharsAndNumsOnly(s) {

	var i;

	for (i=0; i< s.length; i++) {
		if (!( (s.charCodeAt(i) >= 65 && s.charCodeAt(i) <= 90) || 
		 	(s.charCodeAt(i) >= 97 && s.charCodeAt(i) <= 122) ||
			(s.charCodeAt(i) >= 48 && s.charCodeAt(i) <= 57) ||
			s.charAt(i) == "'" || s.charAt(i) == "-" || 
			s.charAt(i) == " " || s.charAt(i) == "," ||
			s.charAt(i) == "/")) {
			return false;
		}

	}

	return true;

}

// @name 		addressCharsOnly
// @param 		s in String
// @description	Checks the s parameter to see if it contains valid characters only.
//				This is used by the checkAddress Function. It differs from validCharsOnly
//				in that it allows the forward slash character.
//				Valid characters are a-z, A-Z, comma, space, hyphen, quote.
// @pre			none
// @post		none
// @return		Returns an empty string if OK, else returns an error message.
// changes made to include numbers as a result of testing for the new site

function addressCharsOnly(s) {

	var i;

	for (i=0; i< s.length; i++) {
		if (!( (s.charCodeAt(i) >= 48 && s.charCodeAt(i) <= 57) ||
			   (s.charCodeAt(i) >= 65 && s.charCodeAt(i) <= 90) || 
		       (s.charCodeAt(i) >= 97 && s.charCodeAt(i) <= 122) ||
			s.charAt(i) == "'" || s.charAt(i) == "-" || 
			s.charAt(i) == " " || s.charAt(i) == "," ||
			s.charAt(i) == "/")) {
			return false;
		}

	}

	return true;

}

// @name 		checkText 
// @param 		checkString in String
// @param		stringName in String
// @param		required in Boolean
// @description	Checks the checkString parameter to see if it is a valid string or empty.
//				Checks required to see if empty string is valid.
// @pre			none
// @post		none
// @return		Returns an empty string if OK, else returns an error message.

function checkText(checkString, stringName, required) {


	// Check for empty and not required.
	if(isEmpty(checkString) && !required) {
		return "";
	}

	// Check for empty and required
	if(isEmpty(checkString) && required) {
		return "Please enter " + stringName + "\n";
	}

	// Now check for valid characters
	if(!validCharsOnly(checkString)) {
		return "Please enter a valid value for " + stringName + "\n";
	}
	else {
		return "";
	}
}

// @name 		checkTextAndNum 
// @param 		checkString in String
// @param		stringName in String
// @param		required in Boolean
// @description	Checks the checkString parameter to see if it is a valid string or empty.
//				Checks required to see if empty string is valid.
// @pre			none
// @post		none
// @return		Returns an empty string if OK, else returns an error message.

function checkTextAndNum(checkString, stringName, required) {


	// Check for empty and not required.
	if(isEmpty(checkString) && !required) {
		return "";
	}

	// Check for empty and required
	if(isEmpty(checkString) && required) {
		return "Please enter " + stringName + "\n";
	}

	// Now check for valid characters
	if(!validCharsAndNumsOnly(checkString)) {
		return "Please enter a valid value for " + stringName + "\n";
	}
	else {
		return "";
	}
}

// @name 		checkEmployerName 
// @param 		checkString in String
// @param		stringName in String
// @param		required in Boolean
// @description	Checks the checkString parameter to see if it is a valid employer name or empty.
//				Checks required to see if empty string is valid.
// @pre			none
// @post		none
// @return		Returns an empty string if OK, else returns an error message.

function checkDriversLicence(checkString, stringName, required) {

	if (isEmpty(checkString)) return "";
	if (checkString.length != 8) return "Drivers Licence is eight characters\n";
	var i,c;
	for (i = 0; i < 2; i++) {
	   c = checkString.charAt(i);	   	   
	   if (!((c >= 'a' && c <='z') || (c >= 'A' && c <='Z') || (c == ' '))) 

		return "Your driver licence should be in the form AA999999 - two letters and 6 numbers\n";
				
		}

	for (i = 3; i < checkString.length; i++) {
		// Check that current character is number.
		var s = checkString.charAt(i);
		if (!isDigit(s)) return "Your driver licence should be in the form AA999999 - two letters and 6 numbers\n";
	    }

	    // Correct format.
	    return "";

}
function checkDLVersion(checkString, stringName, required) {

	if(isEmpty(checkString)) return ""; 
	
	if (checkString.length != 3) return "Your Driver licence card version should be a number between 001 and 999\n";
	if(!isDigitsOnly(checkString)) {
				return "Your Driver licence card version should be a number between 001 and 999\n";
			}

	return "";

}
function checkBothDLPresent(checkString1, checkString2) {

	if(isEmpty(checkString1) && !isEmpty(checkString2)) return "Please enter both the Driver licence number (field 5a on your licence) and the driver licence card version (field 5b)\n"; 
	if(isEmpty(checkString2) && !isEmpty(checkString1)) return "Please enter both the Driver licence number (field 5a on your licence) and the driver licence card version (field 5b)\n"; 
	

	return "";

}
// @name 		checkTextAndNum 
// @param 		checkString in String
// @param		stringName in String
// @param		required in Boolean
// @description	Checks the checkString parameter to see if it is a valid string or empty.
//				Checks required to see if empty string is valid.
// @pre			none
// @post		none
// @return		Returns an empty string if OK, else returns an error message.


function checkEmployerName(checkString, stringName, required) {


	// Check for empty and not required.
	if(isEmpty(checkString) && !required) {
		return "";
	}

	// Check for empty and required
	if(isEmpty(checkString) && required) {
		return "Please enter " + stringName + "\n";
	}

	var i;

	for (i=0; i< checkString.length; i++) {
		if (!( (checkString.charCodeAt(i) >= 65 && checkString.charCodeAt(i) <= 90) || 
		 	(checkString.charCodeAt(i) >= 97 && checkString.charCodeAt(i) <= 122) ||
			(checkString.charCodeAt(i) >= 48 && checkString.charCodeAt(i) <= 57) ||
			checkString.charCodeAt(i) == 39 || checkString.charCodeAt(i) == 45 || 
			checkString.charCodeAt(i) == 32 || checkString.charCodeAt(i) == 44 ||
			checkString.charCodeAt(i) == 38)) {
			return "Please enter a valid value for " + stringName + "\n";
		}

	}

	return "";
}


// @name 		validateDate 
// @param 		d in 
// @param		m in
// @param		y in
// @param		stringName in String
// @param		required in Boolean
// @description	Checks the parameters to see if they form a valid date.
// @pre			none
// @post		none
// @return		Returns an empty string if OK, else returns an error message.

function validateDate(d, m, y, stringName, required) {

	var nanError = "";

	if ((isEmpty(d) || isEmpty(m) || isEmpty(y)) && !required) {
		return "";
	}

	if (isEmpty(d) || isEmpty(m) || isEmpty(y)) {
		return "Please enter a day, month, and year for " + stringName + "\n";
	}

	if(isNaN(d)) {
		nanError += "Day is not a number in " + stringName + "\n";
	}
	if(isNaN(m)) {
		nanError += "Month is not a number in " + stringName + "\n";
	}
	if(isNaN(y)) {
		nanError += "Year is not a number in " + stringName + "\n";
	}
	
	if(!isEmpty(nanError)) {
		return nanError;
	}

	if(y.length != 4) {
		return "Please use a four digit year for " + stringName + "\n";
	}

	if((m < 1) || (m > 12)) {
		return "Month needs to be between 1 and 12 for " + stringName + "\n";
	}

	var	daysInMonth = 31;

	if (m == 4 || m == 6 ||	m == 9 || m == 11) {
		daysInMonth = 30;
	}
	else if (m == 2)
	{
		if (y % 4 > 0)
			daysInMonth = 28;
		else if (y % 100 == 0 && y % 400 > 0)
			daysInMonth = 28
		else
			daysInMonth = 29
	}


	if((d < 1) || (d > daysInMonth)) {
		return "Day needs to be between 1 and " + daysInMonth + " for " + stringName + "\n";
	}

	return "";

}

// @name 		correctAge
// @param 		d in 
// @param		m in
// @param		y in
// @param		age in
// @description	Checks the age based on d, m, y, and determines if the customer is over 'age'.
// @pre			none
// @post		none
// @return		Returns an empty string if OK, else returns an error message.

function correctAge(d, m, y, age) {

	var dob	= new Date();
	var today = new Date();

	dob.setYear(y);
	dob.setMonth(m-1);
	dob.setDate(d);

	if(isNaN(age)) {
		return false;
	}

	// Y2K code to handle the fact that Netscape implement Date.getYear() differently to IE, and older browsers
	// don't support getFullYear()

	var fourDigitYearDOB = get4DigitYear(dob.getYear());
	var fourDigitYearNow = get4DigitYear(today.getYear());

	var diffMonths = (fourDigitYearNow - fourDigitYearDOB) * 12 + (today.getMonth()- dob.getMonth());

	if ((diffMonths < (parseInt(age) * 12) || (diffMonths == (parseInt(age) * 12) && (today.getDate() < dob.getDate())))) {
		return false;
	}

	return true;

}

// @name 		checkAddress
// @param		propertyName in
// @param 		streetNumber in 
// @param		streetName in
// @param		suburb in
// @param		city in
// @param		stringName in
// @param		required in
// @description	Checks the supplied address
// @pre			none
// @post		none
// @return		Returns an empty string if OK, else returns an error message.

function checkAddress(propertyName, streetNumber, streetName, suburb, city, stringName, required) {

	var errMsg = "";

	if (required) {

		if (!isEmpty(propertyName)) {
			if (!addressCharsOnly(propertyName)) {
				errMsg += "Please enter a valid " + stringName + " property name\n";
			}
		}

		if (!isEmpty(streetNumber)) {
			if (!addressCharsAndNumsOnly(streetNumber)) {
				errMsg += "Please enter a valid " + stringName + " street number\n";
			}
		}

		if (isEmpty(streetName)) {
			errMsg += "Please enter your " + stringName + " street name\n";
		} else if (!addressCharsOnly(streetName)) {
			errMsg += "Please enter a valid " + stringName + " street name\n";
		}

		if (!isEmpty(suburb)) {
			if (!addressCharsOnly(suburb)) {
				errMsg += "Please enter a valid " + stringName + " suburb\n";
			}
		}

		if (isEmpty(city)) {
			errMsg += "Please enter your " + stringName + " city\n";
		} else if (!addressCharsOnly(city)) {
			errMsg += "Please enter a valid " + stringName + " city\n";
		}

	}

	if (!required) {

		if (!isEmpty(streetName)) {
			if (!addressCharsOnly(streetName)) {
				errMsg += "Please enter a valid " + stringName + " street name\n";
			}
		}

		if (!isEmpty(city)) {
				if (!addressCharsOnly(city)) {
					errMsg += "Please enter a valid " + stringName + " city\n";
				}
		}

		if (!isEmpty(propertyName)) {
			if (!addressCharsOnly(propertyName)) {
				errMsg += "Please enter a valid " + stringName + " property name\n";
			}
		}

		if (!isEmpty(streetNumber)) {
			if (!addressCharsAndNumsOnly(streetNumber)) {
				errMsg += "Please enter a valid " + stringName + " street number\n";
			}
		}

		if (!isEmpty(suburb)) {
			if (!addressCharsOnly(suburb)) {
				errMsg += "Please enter a valid " + stringName + " suburb\n";
			}
		}
	}

	return errMsg;

}

// @name 		checkPhone
// @param		areaCode in
// @param 		phoneNumber in 
// @param		stringName in
// @param		required in
// @description	Checks the supplied phone number
// @pre			none
// @post		none
// @return		Returns an empty string if OK, else returns an error message.

function checkPhone(areaCode, phoneNumber, stringName, required) {

	var errMsg = "";

	if (!required) {

		if(isEmpty(areaCode) && isEmpty(phoneNumber)) {
			errMsg += "";
		} else if ((isEmpty(areaCode) && !isEmpty(phoneNumber)) || (!isEmpty(areaCode) && isEmpty(phoneNumber))) {
			errMsg += "Please provide both an area code and phone number for " + stringName + "\n";
		} else {
			if(!isPhoneNo(areaCode)) {
				errMsg += "Please enter a valid area code for " + stringName + "\n";
			}

			if(!isPhoneNo(phoneNumber)) {
				errMsg += "Please enter a valid phone number for " + stringName + "\n";
			}
		}

	} else {

		if(isEmpty(areaCode)) {
			errMsg += "Please enter an area code for " + stringName + "\n";
		} else if(!isPhoneNo(areaCode)) {
			errMsg += "Please enter a valid area code for " + stringName + "\n";
		}

		if(isEmpty(phoneNumber)) {
			errMsg += "Please enter a phone number for " + stringName + "\n";
		} else if(!isPhoneNo(phoneNumber)) {
			errMsg += "Please enter a valid phone number for " + stringName + "\n";
		}
	}

	return errMsg;

}

// @name 		checkAirPoints
// @param		airPointsNum in
// @param		stringName in
// @param		required in
// @description	Checks the supplied air points number to see if it is valid.
// @pre			none
// @post		none
// @return		Returns an empty string if OK, else returns an error message.

function checkAirPoints(airPointsNum, stringName, required) {

	if(!required) {
		if(isEmpty(airPointsNum)) { 
			return ""; 
		} else {
			if(!isDigitsOnly(airPointsNum)) {
				return "Please enter a valid " + stringName + " number\n";
			}
		}
	} else {
		if(!isDigitsOnly(airPointsNum) || isEmpty(airPointsNum)) {
			return "Please enter a valid " + stringName + " number\n";
		}
	}

	return "";

}
		

// New function (16SEP1998) to take care of getYear() anomalies for Y2K. Used in place of getFullYear() to provide support for
// older browsers.
function get4DigitYear(yrValue) {
	yrValue += (yrValue < 1900) ? 1900 : 0;
	return yrValue;
}

-->
