function checkForm(form) {
form.form_from.value = document.referrer
if (form.first_name.value == "") {
	alert("Please enter your first name.")
	return false
	}
if (form.last_name.value == "") {
	alert("Please enter your last name.")
	return false
	}
if (form.email.value == "") {
	alert("Please enter your email address.")
	return false
	}
if (form.employees.selectedIndex < 1) {
	alert("Please select the number of employees at your location.")
	return false
	}
if (form.organization.value == "") {
	alert("Please enter the name of your company or organization.")
	return false
	}
if (form.address1.value == "") {
	alert("Please enter your mailing address.")
	return false
	}
if (form.address1.value == form.city.value) {
	alert("The address and city cannot be the same.  Please be sure your mailing address is correct.")
	return false
	}
if (form.city.value == "") {
	alert("Please enter the name of your city.")
	return false
	}
if (form.zip.value == "") {
	alert("Please enter your zip or postal code.  If you do not have a postal code, please enter xxx.")
	return false
	}
if (form.zip.value.length < 3) {
	alert("US Zip Codes must have at least five digits.  Other postal codes must have at least three digits. If you do not have a postal code, please enter XXX.")
	return false
	}
if (form.country.selectedIndex == 39) {
		if (form.state.selectedIndex < 53) {
			alert ("Please select the appropriate Canadian province.")
			return false
		}
	}
if (form.state.selectedIndex < 52 && form.state.selectedIndex > 0) {
		if (form.country.selectedIndex > 0 && form.country.selectedIndex != 227) {
			alert ("If a U.S. state is selected, then the U.S. must be selected as the country.  If you are not in the U.S., please leave the 'State or Province' selection set to '-None Selected-'.  Otherwise please select the U.S. as your country.")
		return false
		}
	}

if (form.country.selectedIndex == 0 || form.country.selectedIndex == 227) {
		if (form.state.selectedIndex < 1) {
			alert ("Please select the appropriate state.")
			return false
		}
		if (form.state.selectedIndex > 51) {
			alert ("Please select the appropriate state.")
			return false
		}

		var valid = "0123456789-"
		var hyphencount = 0
		if (form.zip.value.length != 5 && form.zip.value.length != 10) {
			alert("US Zip Codes must have at least 5 digits or 5+4 numbers (12345-1234).")
			return false 
		}

		for (var i=0; i < form.zip.value.length; i++) {
			temp = "" + form.zip.value.substring(i, i+1);
				if (temp == "-") hyphencount++;
				if (valid.indexOf(temp) == "-1") {
					alert("Invalid characters in your zip code.  Please try again.");
					return false;
				}
				if ((hyphencount > 1) || ((form.zip.value.length==10) && ""+form.zip.value.charAt(5)!="-")) {
					alert("A 5 digit+four zip code should included a hyphen.");
				return false;
   			}
		} 
}

	if (form.country.selectedIndex == 39) { // CHECK CANADIAN POSTAL CODES
		var checkCanadaCode = 0;
		strlen=form.zip.value.length;
		entry = form.zip.value;
		if(strlen == 7) {
			entry = form.zip.value.substr(0,3) + form.zip.value.substr(4,3);
			form.zip.value = entry
		}

		strlen=entry.length;
		if(strlen!=6) {
			alert("Please enter a valid Canadian postal code. The postal code you entered is not the right length.");
			return false;
		}
		entry=entry.toUpperCase();    // in case of lowercase characters
		// Check for legal characters in string - note index starts at zero
		if('ABCEGHJKLMNPRSTVXY'.indexOf(entry.charAt(0))<0) {checkCanadaCode = 1;}
		if('0123456789'.indexOf(entry.charAt(1))<0) {checkCanadaCode = 1;}
		if('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(entry.charAt(2))<0) {checkCanadaCode = 1;}
		if('0123456789'.indexOf(entry.charAt(3))<0) {checkCanadaCode = 1;}
		if('ABCDEFGHJKLMNPQRSTUVWXYZ'.indexOf(entry.charAt(4))<0) {checkCanadaCode = 1;}
		if('0123456789'.indexOf(entry.charAt(5))<0) {checkCanadaCode = 1;}
		if(checkCanadaCode == 1) {
			alert("Please enter a valid Canadian postal code.");
			return false;
		}
	}


/* ===============Beginning Custom section=============== */

/*  ================== End - Custom Section ===========*/


emailStr = form.email.value
	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) {
  		alert("Email address seems to have an error (check @ and .'s)")
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	if (user.match(userPat)==null) {
    	alert("The email username doesn't seem to be valid.")
    	return false
	}

	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
	  	for (var i=1;i<=4;i++) {
	    	if (IPArray[i]>255) {
	        	alert("Email destination IP address is invalid!")
			return false
	    	}
    	}
		form.send.value = "Processing, Please Wait"
    	return true
	}

	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("The email domain name doesn't seem to be valid.")
    	return false
	}

	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if ((domArr[domArr.length-1].indexOf("info") == 0) && (domArr[domArr.length-1].indexOf("coop") == 0)) {
			if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) {
	   			alert("The email address must end in a three-letter domain, or two letter country.")
   				return false
			}
	}
	
	if (len<2) {
   		var errStr="The email address is missing a hostname!"
   		alert(errStr)
   	return false
	}
form.send.value = "Processing, Please Wait"
return true
}
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

/* ===============Pop-up Notes=============== */

function prepareInputsForHints() {
	var inputs = document.getElementsByTagName("input");
	for (var i=0; i<inputs.length; i++){
		if (inputs[i].parentNode.getElementsByTagName("span")[0]) {
			inputs[i].onfocus = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
			}
			inputs[i].onblur = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";
			}
		}
	}
	var selects = document.getElementsByTagName("select");
	for (var k=0; k<selects.length; k++){
		if (selects[k].parentNode.getElementsByTagName("span")[0]) {
			selects[k].onfocus = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
			}
			selects[k].onblur = function () {
				this.parentNode.getElementsByTagName("span")[0].style.display = "none";
			}
		}
	}
}
addLoadEvent(prepareInputsForHints);