
//Variables to hold error message
	var msg = "";
	var empty_fields = "";
	var toolong_fields = "";
	
// Function that returns true if a string contains only white space
function isblank(s) {
	for (var i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if ((c != " ") && (c != '\n') && (c != '\t')) return false;
	}
	return false;
}

// Function to determine whether a string contains numeric characters
function isNumeric(aString) {
	if (aString.length == 0) {
		return (false);
	}
	var refString = "1234567890";
	for (count=0; count < aString.length; count++) {
		chkChar = aString.substring (count, count+1);
		if (refString.indexOf (chkChar, 0) == -1)
			return (false);
	}
	return (true)
}

// Function to determine whether a string contains numeric characters or whitespace
function isNumericOrWhitespace(aString) {
	if (aString.length == 0) {
		return (false);
	}
	var refString = "1234567890 ";
	for (count=0; count < aString.length; count++) {
		chkChar = aString.substring (count, count+1);
		if (refString.indexOf (chkChar, 0) == -1)
			return (false);
	}
	return (true)
}

// Function to determine whether a string contains numeric characters or Alpha chars
function isNumericOrAlpha(aString) {
	if (aString.length == 0) {
		return (false);
	}
	var refString = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	for (count=0; count < aString.length; count++) {
		chkChar = aString.substring (count, count+1);
		if (refString.indexOf (chkChar, 0) == -1)
			return (false);
	}
	return (true)
}

// Function to check a Text box
function chkText(e, eValue, minLength) {
	// check if the text line is empty
	if ((e.value == null) || (e.value == "") || isblank(e.value) || (e.value.length <=  minLength - 1 ) ) {
		if  (eValue == "" ) {
			eValue = e.name;
		}
		empty_fields += "\n        " + eValue;
		return empty_fields;
	}
}

// Function to check the length of a Text box
function chkMaxLen(e, eValue, maxLength) {
	// check if the text line is empty
	if ((e.value.length >  maxLength ) ) {
		if  (eValue == "" ) {
			eValue = e.name;
		}
		toolong_fields += "\n        " + eValue;
		return toolong_fields;
	}
}

// Function to check a Textarea
function chkTextArea(e, eValue) {
	if ((e.value == null) || (e.value == "") || isblank(e.value) )
	{
		// Check if a name was specified to use (IE 3 fix)
		if  (eValue == "" ) {
			if (browser.name == "MSIE" && browser.version <= 3) {
				eValue = "Text Area";
			}
			else {
				eValue = e.name;
			}
		}
		empty_fields += "\n        " + eValue;
		return empty_fields;
	}
}

// Function to check an option has been selected in a Select list
function chkSelect (e, eValue) {
	if (( e.selectedIndex < 1) || (e.value == "") || (e.value == "NULL")) {
		if  (eValue == "" ) {
			eValue = e.name;
		}
		empty_fields += "\n        " + eValue;
		return empty_fields;
	}
}

// Function to check if one of a group of radio buttons has been selected
function chkRadio(e, eValue) {
	for (i = 0; i < e.length; i++) {
		if (e[i].checked) {
			return true;
		}		
	}
	if  (eValue == "" ) {
		eValue = e[0].name;
	}
	empty_fields += "\n        " + eValue;
	return empty_fields;
}

// Function to check that a CheckBox has been selected
function chkCheckBox (e, eValue) {
		if (!e.checked) {
			if  ( eValue == "" ) {
				eValue = e.name;
			}
			empty_fields += "\n        " + eValue;
			return empty_fields;			
		}		
}

// Function to check if email is valid - must contain an '@' symbol
function chkEmail (e, eValue) {
	if ((e.value.length > 0) && e.value.indexOf("@") < 0) {
		if  (eValue == "" ) {
			eValue = e.name;
		}
		empty_fields += "\n        " + eValue;
		return empty_fields;
	}
}

// Function to check if a telephone number is valid
function chkTelephone(e, eValue) {
	if ((e.value == null) || (e.value == "") || isblank(e.value) || (isNumericOrWhitespace(e.value) == 0)) 	{
		if  ( eValue == "" ) {
			eValue = e.name;
		}
		empty_fields += "\n        " + eValue;
		return empty_fields;
	}
}

// Function to check if a serial number is valid
function chkSerialNumber(e, eValue, minLength) {
	if ((e.value == null) || (e.value == "") || isblank(e.value) || (isNumericOrAlpha(e.value) == 0) || (e.value.length <=  minLength - 1 ))	{
		if  ( eValue == "" ) {
			eValue = e.name;
		}
		empty_fields += "\n        " + eValue;
		return empty_fields;
	}
}

// Function to check a numeric field including a maximum value and minimum length
function chkNumber(e, eValue, minLength, maxValue, minValue) {
	// check if the text line is empty
	if ((e.value == null) || (e.value == "") || isblank(e.value) || (isNumeric(e.value) == 0) || (e.value.length <=  minLength - 1 )) {
		if  (eValue == "" ) {
			eValue = e.name;
		}
		empty_fields += "\n        " + eValue;
		return empty_fields;
	}
	if (maxValue != ""){
		if (e.value > maxValue){
			if  (eValue == "" ) {
				eValue = e.name;
			}
			empty_fields += "\n        " + eValue;
			return empty_fields;
		}
	}
}

// Show the Errors built up into the error string
function showErr(empty_fields) {
					
	// If errors display messages and return false to stop form submission.
	if (!empty_fields) return true;

	msg = "==================================================\n"
	msg += " Before your form can be sent you must enter\n";
	msg += " (acceptable) values in the following fields.\n";
	msg += "==================================================\n"
	
	if (empty_fields) {
		msg += empty_fields + "\n";
		msg += "\nPlease correct these fields and send the form again.\n";
		msg += "==================================================\n"
		alert(msg);
		return false;
	}
}


function popup(varURL) 
{
	window.open(varURL,"popup","toolbar=0,status=0,menubar=0,scrollbars=0,resizable=no,maximisable=no,width=820,height=410");
}



