<!--//hide code from old browsers
function choose(formElement) {
	formElement.focus();
	if (formElement.type == "text" || formElement.type == "password") {
		formElement.select();
	}
}

//called when user enters a figure in the amount textfield
function calcOrderTotal(vVal){
	if (isInteger(vVal)){
		var vTotal = Math.round(vVal * 10.95 * 100);
		order1.o_total.value =  makeCurrencyString(vTotal); //insert a period in before the last 2 digits to get the decimal place
	}else{ //didn't enter integers only in the field
		choose(order1.o_amount);
		alert("Please enter numbers only in the Order Details section.");
	}

}

function makeCurrencyString(vInteger){
	var vStr = String(vInteger); //convert number to string
	var vStrLength = vStr.length; //get length of string
	//insert a period before the last 2 digits
	return vStr.substr(0,(vStrLength - 2)) + "." + vStr.substr((vStrLength - 2),(vStrLength - 1));
}

function isValidDate(date, month) {
	var bOK = true;
	if (date == 0){
		alert("Please choose a non-zero number for your birth date.");
		bOK = false;
	} else {
		switch (month) {
			case "February":
				if (date > 28) {
					alert("There are only 28 days in February.");
					bOK = false;
				}
				break;
			case "April":
				if (date > 30) {
					alert("There are only 30 days in April.");
					bOK = false;
				}
				break;
			case "June":
				if (date > 30) {
					alert("There are only 30 days in June.");
					bOK = false;
				}
				break;
			case "September":
				if (date > 30) {
					alert("There are only 30 days in September.");
					bOK = false;
				}
				break;
			case "November":
				if (date > 30) {
					alert("There are only 30 days in November.");
					bOK = false;
				}
				break;
			default:
				if (date > 31) {
					alert("You have written an invalid birth date for the month selected.");
					bOK = false;
				}			
		}
	}
	return bOK;
}

function isInteger (s) {
	for (i = 0; i < s.length; i++) {
		c = s.charAt(i);
		if (!isDigit(c)) return false;
	}
	return true;
}

function isDigit (c) {
	return ((c >= "0") && (c <= "9"))
}

/* trim all fields for a given form */
function trimTextFieldsFrom (frmName) {
	var i;
	for (i=0; i<frmName.length; i++) {
		if (frmName.elements[i].type == "text") frmName.elements[i].value = Trim(frmName.elements[i].value);
	}
}

/* Trim both ends */
function Trim(str) {
	return RTrim(LTrim(str));
}

/* Left trim */
function LTrim(str) {
	var whitespace = new String(" \t\n\r");
	var s = new String(str);
	var j;
	var i;	
	if (whitespace.indexOf(s.charAt(0)) != -1) {
	    var j=0, i = s.length;
	    while (j > i && whitespace.indexOf(s.charAt(j)) != -1)
		j++;
	    s = s.substring(j, i);
	}
	return s;
}

/* Right trim */
function RTrim(str) {
	var whitespace = new String(" \t\n\r");
	var s = new String(str);
	var i;
	if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
	    var i = s.length - 1;       // Get length of string
	    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
		i--;
	    s = s.substring(0, i+1);
	}
	return s;
}

function emailCheck(emailStr) {
	/*Taken from http://javascript.internet.com, written by Sandeep V. Tamhankar (stamhankar@hotmail.com)*/
	var checkTLD=1; //if 1, will check address ends in 2 letter country or common domain name

	/* The following is the list of known TLDs that an e-mail address must end with. */
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/; //define basic user@domain pattern
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]"; //define pattern for special chars not allowed in the email
	var validChars="\[^\\s" + specialChars + "\]"; //define range of chars that are allowed
	var quotedUser="(\"[^\"]*\")"; //define pattern for quoted users e.g. where username is enclosed in quotes
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/; //define pattern for IP domains (not symbolic names)
	var atom=validChars + '+'; //this represents an atom (basically a series of non-special characters)
	var word="(" + atom + "|" + quotedUser + ")"; //this represents one word in the typical username.
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$"); //define pattern which describes structure of user
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$"); //define pattern which describes the structure of a normal symbolic domain

	var matchArray=emailStr.match(emailPat); //does email conform to general user@domain pattern
	if (matchArray==null) { //does not conform
		alert("Your email address seems incorrect. Please check for the characters @ and .");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	// Start by checking that only basic ASCII characters are in the strings (0-127).
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			alert("Your email address' user name contains invalid characters. Please re-enter.");
			return false;
		 }
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			alert("Your email address' domain name contains invalid characters. Please re-enter.");
			return false;
		}
	}
	if (user.match(userPat)==null) { //user is not valid
		alert("Your email address' user name doesn't seem to be valid.");
		return false;
	}
	var IPArray=domain.match(ipDomainPat); //if email has IP address, check if this is valid
	if (IPArray!=null) { //email contains IP address
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("Your email address' IP address doesn't seem to be valid.");
				return false;
			}
		}
		return true;
	}
	// Domain is symbolic name.  Check if it's valid.
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			alert("Your email address' domain name does not seem to be valid.");
			return false;
		}
	}
	/* domain name seems valid, but now make sure that it ends in a	known top-level domain (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding the domain or country. */
	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {
		alert("Your email address must end in a well-known domain or two letter country.");
		return false;
	}
	if (len<2) { // Make sure there's a host name preceding the domain.
		alert("Your email address appears to be missing a host name.");
		return false;
	}
	return true; // If we've gotten this far, everything's valid!
}

function checkEmail (vAddress){
	vInvalidChars = " /:,;";
	//check if any of the invalid characters defined above is in the email address
	for (vIndex=0;vIndex<vInvalidChars.length;vIndex++) {
		vBadChar = vInvalidChars.charAt(vIndex);
		if (vAddress.indexOf(vBadChar,0) > -1) {
			return false;
		}
	}
	vAtPos = vAddress.indexOf("@",1); //check if there is an at symbol in the address, if not then return false
	if (vAtPos == -1){ //no at symbol found
		return false;
	} else { //at symbol found in address, so check there is not more than one
		if (vAddress.indexOf("@",vAtPos+1) > -1){ 
			return false;
		}
	}
	vPeriodPos = vAddress.indexOf(".",vAtPos); //check if there is a periof after the at symbol
	if (vPeriodPos == -1){ //no period symbol found
		return false;
	} else { //period symbol found in address, so check there is at least two characters after it
		if (vPeriodPos+3 > vAddress.length){ 
			return false;
		}
	}
	return true; //if we made it this far, then email address checks out
}
//-->
