function hideval() { 
if (document.getElementById) { // DOM3 = IE5, NS6 
document.getElementById('valcform').style.visibility = 'hidden'; 
} 
else { 
if (document.layers) { // Netscape 4 
document.valcform.visibility = 'hidden'; 
} 
else { // IE 4 
document.all.valcform.style.visibility = 'hidden'; 
} 
} 
} 

function showval() { 
if (document.getElementById) { // DOM3 = IE5, NS6 
document.getElementById('valcform').style.visibility = 'visible'; 
} 
else { 
if (document.layers) { // Netscape 4 
document.valcform.visibility = 'visible'; 
} 
else { // IE 4 
document.all.valcform.style.visibility = 'visible'; 
} 
} 
} 

function hideval2() { 
if (document.getElementById) { // DOM3 = IE5, NS6 
document.getElementById('valcform2').style.visibility = 'hidden'; 
} 
else { 
if (document.layers) { // Netscape 4 
document.valcform2.visibility = 'hidden'; 
} 
else { // IE 4 
document.all.valcform2.style.visibility = 'hidden'; 
} 
} 
} 

function showval2() { 
if (document.getElementById) { // DOM3 = IE5, NS6 
document.getElementById('valcform2').style.visibility = 'visible'; 
} 
else { 
if (document.layers) { // Netscape 4 
document.valcform2.visibility = 'visible'; 
} 
else { // IE 4 
document.all.valcform2.style.visibility = 'visible'; 
} 
} 
} 


function hideval3() { 
if (document.getElementById) { // DOM3 = IE5, NS6 
document.getElementById('valcform3').style.visibility = 'hidden'; 
} 
else { 
if (document.layers) { // Netscape 4 
document.valcform3.visibility = 'hidden'; 
} 
else { // IE 4 
document.all.valcform3.style.visibility = 'hidden'; 
} 
} 
} 

function showval3() { 
if (document.getElementById) { // DOM3 = IE5, NS6 
document.getElementById('valcform3').style.visibility = 'visible'; 
} 
else { 
if (document.layers) { // Netscape 4 
document.valcform3.visibility = 'visible'; 
} 
else { // IE 4 
document.all.valcform3.style.visibility = 'visible'; 
} 
} 
} 




function hideval4() { 
if (document.getElementById) { // DOM3 = IE5, NS6 
document.getElementById('valcform4').style.visibility = 'hidden'; 
} 
else { 
if (document.layers) { // Netscape 4 
document.valcform4.visibility = 'hidden'; 
} 
else { // IE 4 
document.all.valcform4.style.visibility = 'hidden'; 
} 
} 
} 

function showval4() { 
if (document.getElementById) { // DOM3 = IE5, NS6 
document.getElementById('valcform4').style.visibility = 'visible'; 
} 
else { 
if (document.layers) { // Netscape 4 
document.valcform4.visibility = 'visible'; 
} 
else { // IE 4 
document.all.valcform4.style.visibility = 'visible'; 
} 
} 
} 




function hideval_country() { 
if (document.getElementById) { // DOM3 = IE5, NS6 
document.getElementById('valcform_country').style.visibility = 'hidden'; 
} 
else { 
if (document.layers) { // Netscape 4 
document.valcform_country.visibility = 'hidden'; 
} 
else { // IE 4 
document.all.valcform_country.style.visibility = 'hidden'; 
} 
} 
} 

function showval_country() { 
if (document.getElementById) { // DOM3 = IE5, NS6 
document.getElementById('valcform_country').style.visibility = 'visible'; 
} 
else { 
if (document.layers) { // Netscape 4 
document.valcform_country.visibility = 'visible'; 
} 
else { // IE 4 
document.all.valcform_country.style.visibility = 'visible'; 
} 
} 
} 





function hideval_state() { 
if (document.getElementById) { // DOM3 = IE5, NS6 
document.getElementById('valcform_state').style.visibility = 'hidden'; 
} 
else { 
if (document.layers) { // Netscape 4 
document.valcform_state.visibility = 'hidden'; 
} 
else { // IE 4 
document.all.valcform_state.style.visibility = 'hidden'; 
} 
} 
} 

function showval_state() { 
if (document.getElementById) { // DOM3 = IE5, NS6 
document.getElementById('valcform_state').style.visibility = 'visible'; 
} 
else { 
if (document.layers) { // Netscape 4 
document.valcform_state.visibility = 'visible'; 
} 
else { // IE 4 
document.all.valcform_state.style.visibility = 'visible'; 
} 
} 
} 




function hideval6() { 
if (document.getElementById) { // DOM3 = IE5, NS6 
document.getElementById('valcform6').style.visibility = 'hidden'; 
} 
else { 
if (document.layers) { // Netscape 4 
document.valcform6.visibility = 'hidden'; 
} 
else { // IE 4 
document.all.valcform6.style.visibility = 'hidden'; 
} 
} 
} 

function showval6() { 
if (document.getElementById) { // DOM3 = IE5, NS6 
document.getElementById('valcform6').style.visibility = 'visible'; 
} 
else { 
if (document.layers) { // Netscape 4 
document.valcform6.visibility = 'visible'; 
} 
else { // IE 4 
document.all.valcform6.style.visibility = 'visible'; 
} 
} 
} 



function hideval_phone() { 
if (document.getElementById) { // DOM3 = IE5, NS6 
document.getElementById('valcform_phone').style.visibility = 'hidden'; 
} 
else { 
if (document.layers) { // Netscape 4 
document.valcform_phone.visibility = 'hidden'; 
} 
else { // IE 4 
document.all.valcform_phone.style.visibility = 'hidden'; 
} 
} 
} 

function showval_phone() { 
if (document.getElementById) { // DOM3 = IE5, NS6 
document.getElementById('valcform_phone').style.visibility = 'visible'; 
} 
else { 
if (document.layers) { // Netscape 4 
document.valcform_phone.visibility = 'visible'; 
} 
else { // IE 4 
document.all.valcform_phone.style.visibility = 'visible'; 
} 
} 
} 



function hideval_ext() { 
if (document.getElementById) { // DOM3 = IE5, NS6 
document.getElementById('valcform_ext').style.visibility = 'hidden'; 
} 
else { 
if (document.layers) { // Netscape 4 
document.valcform_ext.visibility = 'hidden'; 
} 
else { // IE 4 
document.all.valcform_ext.style.visibility = 'hidden'; 
} 
} 
} 

function showval_ext() { 
if (document.getElementById) { // DOM3 = IE5, NS6 
document.getElementById('valcform_ext').style.visibility = 'visible'; 
} 
else { 
if (document.layers) { // Netscape 4 
document.valcform_ext.visibility = 'visible'; 
} 
else { // IE 4 
document.all.valcform_ext.style.visibility = 'visible'; 
} 
} 
} 





function TrimAll(obj) {
      var startpos = 0, endpos = obj.value.length - 1;
      if (endpos == -1) { //--- null string 
        return;
      }
      while (startpos <= obj.value.length && obj.value.substring(startpos, startpos + 1) == " ") {
 	      startpos++; //-- find start position of string 
      }
      while (endpos >= 0 && obj.value.substring(endpos, endpos + 1) == " ") {
	      endpos--; //--- find end position of string 
      }
      if (startpos > endpos) { //--- trim the object ---
         obj.value = "";
      } else {
         obj.value = obj.value.substring(startpos, endpos + 1);
      }
   }

function IsAbsent(obj, objname) {
      var retval = -1;
      for (var i = 0; i < obj.value.length; i++) {
         if (obj.value.substring(i, i + 1) != " ") {
            retval = 0;
            break;
         }
      }
      if (retval && (objname != "")) {
         
		 obj.focus();
      }
      return retval;
   }



function validateContactForm()
  {
	var i1, i2, fld;
	var validated=true;
	hideval();
	hideval2();
	hideval3();
	hideval4();
	hideval_country();
	hideval_state();
	hideval6();	
	hideval_phone();
	hideval_ext();
	
 fld=document.contactForm.company;
     TrimAll(fld);
	 if(IsAbsent(fld," ")) 	{showval(); validated=false;}

 fld=document.contactForm.first_name;
     TrimAll(fld);
	 if(IsAbsent(fld," ")) 	{showval2(); validated=false;}
 if(validateName(document.contactForm.first_name.value, document.contactForm.first_name.name)==false) { validated=false; }
	 
 fld=document.contactForm.last_name;
     TrimAll(fld);
	 if(IsAbsent(fld," ")) 	{showval3(); validated=false;}
 if(validateName(document.contactForm.last_name.value, document.contactForm.last_name.name)==false) { validated=false; }
 
 fld=document.contactForm.city;
     TrimAll(fld);
	 if(IsAbsent(fld," ")) 	{showval4(); validated=false;}
 if(validateName(document.contactForm.city.value, document.contactForm.city.name)==false) { validated=false; }
 
 // Country
 if(document.contactForm.country.options[document.contactForm.country.selectedIndex].value=="") {showval_country(); validated=false;}
 
 // State
 if(document.contactForm.country.options[document.contactForm.country.selectedIndex].value=="United States of America") {
 	if(document.contactForm.state.options[document.contactForm.state.selectedIndex].value=="") {showval_state(); validated=false;}
 } else if(document.contactForm.country.options[document.contactForm.country.selectedIndex].value=="Canada") {
	if(document.contactForm.province.options[document.contactForm.province.selectedIndex].value=="") {showval_state(); validated=false;}
 }
 
 // Email
 fld=document.contactForm.email;
     TrimAll(fld);
	 if(IsAbsent(fld," ")) 	{showval6(); validated=false;}
    
 if (!validateEmail(document.contactForm.email.value)) { validated=false; }
 
 
 // Phone
 //if (!validatePhone(document.contactForm.phone.value)) { validated=false; }
 if (validatePhone(document.contactForm.phone.value, document.contactForm.phone.name)==false)  { validated=false; }
 
 
 // Phone Extension
 if (validatePhone(document.contactForm.ext.value, document.contactForm.ext.name)==false)  { validated=false; }
 
 // Send Form
 if (!validated) return false;	 
 document.contactForm.submit();

}

function validateName (nameStr, fieldName) {
	// Pattern incudes 0-9 ( ) < > @ ! ; : \ . { } [ ]
	var wrongChar = /[0-9\(\)\<\>@\!\;\:\\\"\.\{\}\[\]]/;
	var result = wrongChar.test(nameStr);
	// if variable matches wrongChar
	if ( result == true ) {
		if(fieldName == "first_name") { 
			showval2();
			return false;
		} else if (fieldName == "last_name") {
			showval3();	
			return false;
		} else if (fieldName == "city") {
			showval4();
			return false;
		} 
	} 
}

function validatePhone (phone, fieldName) {
	// Pattern NOT incudes 0-9 ( ) - +
	var rightChar = /[^0-9\(\)\-\+]/;
	var result = rightChar.test(phone);
	if( result == true ) {
		if (!phone == "" || !phone == null) {
			if (fieldName == "phone") {
				showval_phone();
				return false;
			} else if (fieldName == "ext") {
				showval_ext();
				return false;
			} 
		}
	}	
}

// Disable Return key if field are empty
function checkReturnKey(evt) {
	var evt  = (evt) ? evt : ((event) ? event : null);
	var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
	if ((evt.keyCode == 13) && (node.type=="text") && (node.parentNode.name=="contactForm")) { 
		validateContactForm();
		return false;	
	}
}
document.onkeypress = checkReturnKey;


// Disable State Field
function disableField() {
	document.contactForm.state.disabled=true;
	document.contactForm.state.selectedIndex = 0;
	document.getElementById('stateLabel').style.color = "#7f7f7f";
	document.getElementById('stateLabel').innerHTML = "State/Province:";
	
	document.getElementById('stateUs').style.display = "block";
	document.getElementById('stateCa').style.display = "none";
}

// Enable State Field
function enableField() {
	document.contactForm.state.disabled=false;
	document.getElementById('stateLabel').style.color = "#e68e1a";
}

// Switch State/Province and enable/disable
function switchField () {
	if (document.contactForm.country.options[document.contactForm.country.selectedIndex].value=="United States of America") {
		enableField();
		document.getElementById('stateLabel').innerHTML = "* State:";
		document.getElementById('stateUs').style.display = "block";
		document.getElementById('stateCa').style.display = "none";
	} else if (document.contactForm.country.options[document.contactForm.country.selectedIndex].value=="Canada") {
		enableField();
		document.getElementById('stateLabel').innerHTML = "* Province:";
		document.getElementById('stateUs').style.display = "none";
		document.getElementById('stateCa').style.display = "block";
		
	} else {
		disableField();	
	}
}


//window.onload = disableField;



function validateEmail (emailStr) {

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=1;

/* 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)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */

showval6();
//alert("Email address seems incorrect (check @ and .'s)");
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) {
showval6();
//alert("Ths username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
showval6();
//alert("Ths domain name contains invalid characters.");
return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid

showval6();
//alert("The username doesn't seem to be valid.");
return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
showval6();
//alert("Destination IP address is invalid!");
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) {
showval6();
//alert("The 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) {
showval6();
//alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
showval6();
//alert("This address is missing a hostname!");
return false;
}

// If we've gotten this far, everything's valid!
return true;
}

//  End -->
