// JavaScript Document

//function validate(form)
//{
//	var errorText = "The fields listed below were either left blank or found to contain errors.\nPlease check them and try again.\n";
//	var returnObj = true;
//	
//	form.submitButton.disabled = true;
//	
//	if (form.contactName == null || !stringCheck(form.contactName.value)) {
//		errorText = errorText + "\n" + "Contact Name";
//		returnObj = false;
//	}
//	
//	if (form.company == null || !stringCheck(form.company.value)) {
//		errorText = errorText + "\n" + "Company";
//		returnObj = false;
//	}
//	
//	if (form.city == null || !stringCheck(form.city.value)) {
//		errorText = errorText + "\n" + "City";
//		returnObj = false;
//	}
//	
//	if (form.stateCode == null || form.stateCode.selectedIndex == 0) {
//		errorText = errorText + "\n" + "State";
//		returnObj = false;
//	}
//	
//	if (form.zipCode == null || !stringCheck(form.zipCode.value)) {
//		errorText = errorText + "\n" + "ZIP Code";
//		returnObj = false;
//	}
//	
//	if (form.email == null || !emailCheck(form.email.value)) {
//		errorText = errorText + "\n" + "E-mail";
//		returnObj = false;
//	}
//	
//	if (form.phone == null || !stringCheck(form.phone.value)) {
//		errorText = errorText + "\n" + "Phone";
//		returnObj = false;
//	}
	
//	if (!returnObj) { alert(errorText); form.submitButton.disabled = false; }
//	
//	return returnObj;
//}

/*******************************************************************************************************************************
stringCheck(obj):boolean

Description:
Test the given input value to determine if it is a valid string. Return 'true' if yes, 'false' if no.
*******************************************************************************************************************************/
function stringCheck(obj) {
	var obj = trim(obj);
	if (obj.length == 0) { return false; } else { return true; }
}

/*******************************************************************************************************************************
emailCheck(string):boolean

Description:
Test the given input value to determine if it is a valid e-mail address. Return 'true' if yes, 'false' if no.
*******************************************************************************************************************************/
function emailCheck (emailStr) {
	var checkTLD = 1;
	var knownDomsPat = /^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	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];
	
	for (i = 0; i < user.length; i++) { if (user.charCodeAt(i)>127) { return false; } }
	for (i = 0; i < domain.length; i++) { if (domain.charCodeAt(i) > 127) { return false; } }
	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 atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	
	for (i = 0; i < len; i++) {if (domArr[i].search(atomPat)==-1) { return false; } }
	if (checkTLD && domArr[domArr.length - 1].length != 2 && domArr[domArr.length - 1].search(knownDomsPat) == -1) { return false; }
	if (len < 2) { return false; }
	alert('TEST');
	return true;
}

/*******************************************************************************************************************************
trim(string):string

Description:
Remove any leading and trailing spaces from the input string, then return it to the caller.
*******************************************************************************************************************************/
function trim(string) {
	string = string.replace(/^\s+/,'').replace(/\s+$/,'');
	return string;
}

/*******************************************************************************************************************************
lTrim(string):string

Description:
Remove any leading spaces from the input string, then return it to the caller.
*******************************************************************************************************************************/
function lTrim(string) {
	string = string.replace(/^\s+/,'');
	return string;
}

/*******************************************************************************************************************************
rTrim(string):string

Description:
Remove any trailing spaces from the input string, then return it to the caller.
*******************************************************************************************************************************/
function rTrim() {
	string = string.replace(/\s+$/,'');
	return string;
}