	var message = "";
	function trimString (str) {
		str = this != window? this : str;
		return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
	}
	function validate_field()
	{
		var result = true;
		message = "Please enter these fields:\r\n";
		var theform=document.forms[0];
		for (i=0; i<theform.elements.length; i++) {
		    var chkRequired = theform.elements[i].getAttribute('required');
			if (chkRequired != null && chkRequired == '1') {
				if (theform.elements[i].type == 'text' || theform.elements[i].type == 'select-one' || theform.elements[i].type == 'textarea') {
					if (trimString(theform.elements[i].value) == '' || trimString(theform.elements[i].value) == ' ') {
						message += theform.elements[i].name + "\r\n"
						result = false
					}
				}
			}
		}
		
		if (result)	result = emailCheck(theform.email.value);
		
		if (result)	result = verifyphone(theform);
		
		if (result)	result = verify_zipcode(theform);

		if (!result) {
			alert (message);
		}
		//if (result) result = verify_name(theform);
		
		return result;
	}
	
	function verify_name(myForm)
	{
		if (myForm.field_9.value == "" && myForm.field_11.value == "")
		{
			//return confirm("It is important for your spouse, fiance or domestic partner to visit the DirectBuy Showroom with you. Please press cancel and enter his or her name in the Spouse's Name field, or press OK if you are single.");
			//document.src.location("checkspouse.asp");
			myForm.action = "checkspouse.aspx";
			myForm.submit();
			
		}
	}

	function verify_zipcode(myForm)
	{
		var result1 = true;
		
		if (myForm.postal_code.value == "00000")
		{message += " Valid Zip/Postcode \r\n"; result1 = false;}
		return result1;
	}
	function verifyphone(myForm)
	{
		var result1 = true;

		if (!IsValidPhoneNumber(myForm.phone1.value,myForm.phone2.value,myForm.phone3.value))
		{message += " Valid Phone Number \r\n"; result1 = false;}
		
		
		if (myForm.cell1 != null && myForm.cell1.value.length > 0 && !IsValidPhoneNumber(myForm.cell1.value, myForm.cell2.value, myForm.cell3.value) )
		{message += " Alternate Phone Number \r\n";result1 = false;}

		if (myForm.fax1 != null && myForm.fax1.value.length > 0 && !IsValidPhoneNumber(myForm.fax1.value, myForm.fax2.value, myForm.fax3.value) )
		{message += " Fax Number \r\n";result1 = false; }
		
		return result1;
		
	}

    var InValidPhoneArray = new Array("0000000000", "1111111111", "2222222222", "3333333333", "44444444444", "55555555555", "6666666666", "7777777777", "8888888888", "9999999999", "1234567890", "0123456789");
    var InValidPhoneArray2 = new Array("0000000", "1111111", "2222222", "3333333", "44444444", "5555555", "6666666", "7777777", "8888888", "9999999");
	function IsValidPhoneNumber(sPhone1, sPhone2, sPhone3)
	{
		var sPhone = sPhone1 + sPhone2 + sPhone3;
		result = true;
		if (sPhone.length != 10)
			result = false;
		else
		{
			// check phone2 -- not 555
			if (sPhone2 == '555')
				result = false;
			else if (!CheckInvalidFormat2(sPhone2 + sPhone3))
				result = false;
			else
				result = CheckInvalidFormat(sPhone);
		}
		return result;
	}
	
    function CheckInvalidFormat2(sPhone)
	{
		for (var i = 0; i < InValidPhoneArray2.length; i++)
		{
			if (sPhone == InValidPhoneArray2[i])
				return false;
		}
		return true;
	}
	

	function CheckInvalidFormat(sPhone)
	{
		for (var i = 0; i < InValidPhoneArray.length; i++)
		{
			if (sPhone == InValidPhoneArray[i])
				return false;
		}
		return true;
	}
	function cat_click(cat_id)
	{
		prod_count=document.forms[0].elements["prod_count_" + cat_id].value
		if (document.forms[0].elements["cat_" + cat_id].checked == true) {
			for (i = 0; i<(prod_count); i++)
			{
				document.forms[0].elements["prod_" + cat_id + "_" + i].checked = true
			}
		} else {
			for (i = 0; i<(prod_count); i++)
			{
				document.forms[0].elements["prod_" + cat_id + "_" + i].checked = false
			}
		}
	}
	/*
Auto tabbing script- By JavaScriptKit.com
http://www.javascriptkit.com
This credit MUST stay intact for use
per erin request -- take out 
*/
	function autotab(original,destination){
		//if (original.getAttribute&&original.value.length==original.getAttribute("maxlength"))
		//destination.focus()
	}

	function prod_click(cat_id, prod_id)
	{
		if (document.forms[0].elements["prod_" + cat_id + "_" + prod_id].checked == true) {
			document.forms[0].elements["cat_" + cat_id].checked = true
		}
		else
		{
			prod_count=document.forms[0].elements["prod_count_" + cat_id].value
			cat_checked = false;
			for (i = 0; i<(prod_count); i++)
			{
				if (document.forms[0].elements["prod_" + cat_id + "_" + i].checked == true)
					cat_checked = true;
			}
			document.forms[0].elements["cat_" + cat_id].checked = cat_checked;
		}
	}
	function emailCheck (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) {
		message += "Email address seems incorrect (check @ and .'s)\r\n";
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	if (user.match(userPat)==null) {
    	message += "The username doesn't seem to be valid.\r\n";
    	return false
	}
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
	    	if (IPArray[i]>255) {
	        	message += "Destination IP address is invalid!\r\n";
	        	return false
	    	}
    	}
    	return true
	}

	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		message += "The domain name doesn't seem to be valid.\r\n";
		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) {
  		message += "The address must end in a three-letter domain, or two letter country.\r\n";
  		return false
	}

	if (len<2) {
   		message  += "This address is missing a hostname!\r\n";
   		return false
	}
	return true;
}
