<!-- Hide Script from old browsers
// **************************************************************
//VALIDATION ADAPTED BY ALEX MESSINGER, JULY 04
// **************************************************************


//changes the country field to US or Canada if a US State or Canadian Province is selected from the State drop-down menu
function StateSelected(selectedIndex) {
  //window.alert(document.RequestForm.STATE.options[selectedIndex].text);
  var provinces = new Array("AB","BC","MB","NB","NL","NS","NT","NU","ON","PE","QC","SK","YT");
  var apos = new Array("APO AA 34xxx","FPO AA 34xxx","APO AE 09xxx","FPO AE 09xxx","APO AP 96xxx","FPO AP 96xxx");
  var isProvince = false;
  var isAPO = false;

  for (i=0; i<provinces.length ; i++) {
    if (provinces[i] == document.RequestForm.STATE.options[selectedIndex].value) {
      isProvince = true;
      break;
    }
  }
  if (!isProvince) {
    for (i=0; i<apos.length ; i++) {
      if (apos[i] == document.RequestForm.STATE.options[selectedIndex].text) {
        isAPO = true;
        break;
      }
    }
    var city = new String(apos[i]);
    city = city.substr(0,3);
  }
  if (isProvince == true) {
    document.RequestForm.COUNTRY_.text = "CANADA";
    document.RequestForm.COUNTRY_.value = "034";
  } else {
    document.RequestForm.COUNTRY_.text = "USA";
    document.RequestForm.COUNTRY_.value = "001";
  }
  if (isAPO == true) {
    document.RequestForm.CITY.value = city;
  }
}


function makeCaps(txtBox) {
  txtBox.value = txtBox.value.toUpperCase();
}

// **************************************************************
/*the function doValZip is called by request_internal.asp and and request_CRMI.asp. These forms have 
a button that shows or hides the name-address-city-state-zip fields. The valZip function gets called only if the name-address-city-state-zip
fields are visible*/
// **************************************************************
function doValZip(theForm)  
{
	if (theForm.packet[0].checked == true)//are the name-address-city-state-zip fields visible?
		{
			if ((requestValZip(theForm.ZIP,theForm.STATE,'request')) == false) //if the name-address-city-state-zip fields are visible, validate the zip
			{
				return false;
			}
			else
			{
				return true;
			}
		}
	else
		{
			return true;
		}
}

// **************************************************************
//THE FUNCTION BELOW FORMATS THE ZIPCODE LIKE THIS: XXX XXX  THIS FUNCTION IS USED BY SURVEY.HTML 
//(VERMONT VACATION.COM VISITORS SURVEY) AND THE MANY PERMUTATIONS OF INFO REQUEST FORM. THE VISITORS SURVEY FORM 
//DETERMINES IF THE ZIP CODE IS CANADIAN BY THE FIRST CHARACTER. THE INFO REQUEST FORMS USE THE VALUE OF THE STATE FIELD
// **************************************************************


function sepZipSelect(zipField,state,source) //determines whether the visitors survey or the info request form is calling the function
{
	if (source = 'survey')
	{
		sepZipProcess(zipField,state);
	}
	else
	{
		alert('ready-to-sep the zip by province selected');
		var theState= state.value;
		var canProvs = new Array("AB","BC","MB","NB","NL","NS","NT","NU","ON","PE","QC","SK","YT")
		var currentProv = "";
		for (currentProv in canProvs) //cycles through postal codes, sees if one matches the value of the state field
			{
				if (theState == canProvs[currentProv])  //determines if the zip code is a canadian postal code
				{
					sepZipProcess(zipField,state);
				}
			}
	}
	
				
}

function sepZipProcess(zipField,state) //adds a space between canadian postal codes
{
	var theZip = zipField.value; //sets theZip equal to the value of the zip field
	var endPoint = theZip.length;  //finds out how long the postal code is
	var secondSet = endPoint - 3;  //finds the spot that 3 places before the end of the postal code
	var firstThree = theZip.substring(0,3);  //finds the first 3 char in the postal code
	var lastThree = theZip.substring(secondSet,endPoint);  //finds the last 3 char in the postal code
	zipField.value = (firstThree + " " + lastThree);  //adds a space between the two sets of chars
	
}


// **************************************************************
//CHECK FOR VALID US ZIP OR CANADIAN POSTAL CODE
// **************************************************************


function valZip(theField,theState,theSource)
	{
		/*alert(theSource);
		if (theSource == 'request')
			{
			sepZipSelect(theField,theState,theSource);
			}
		else
			{
			*/
			var field = theField.value;
			var firstChar = field.charAt(0);	
			if(firstChar <= 9) {
				//check for valid US Zip code
				var objRegExp = /(^\d{5}$)|(^\d{5}-\d{4}$)/; 
				var theResult = objRegExp.test(field);
				if (theResult == false) {
					alert("Please enter a valid US zip code in the format 99999 or 99999-9999");
					theField.focus();
					return objRegExp.test(field);
					} 
				}
			else {
				//check for valid Canadian Postal code
				var objRegExp = /^\D{1}\d{1}\D{1}\-?\s?\d{1}\D{1}\d{1}$/; 
				var theResult = objRegExp.test(field);
				if (theResult == false) {
					alert("Please enter a valid Canadian postal code in the format XXX XXX, XXX-XXX or XXXXXX");
					theField.focus();
					return objRegExp.test(field);
					}
				else {
					sepZipProcess(theField,theState); //calls the function to separate the Postal Code into the format XXX XXX
					 }
				
				}
			//}
	return true;
	}
	

function requestValZip(theField,theState,theSource)
	{
		var theSelectedState= theState.value;
		var field = theField.value;
		var firstChar = field.charAt(0);
		
		var isItCan = "";
		var canProvs = new Array("AB","BC","MB","NB","NL","NS","NT","NU","ON","PE","QC","SK","YT")
		var currentProv = "";
		for (currentProv in canProvs) //cycles through postal codes, sees if one matches the value of the state field
			{
				if (theSelectedState == canProvs[currentProv])  //determines if the zip code is a canadian postal code
				{
					var isItCan = "true";
					break;
				}
			}
		
		
		if (theSelectedState  == "") 
			{
				return true;
			}
		
		else if (isItCan  == "true") 
			{
				var objRegExp = /^\D{1}\d{1}\D{1}\-?\s?\d{1}\D{1}\d{1}$/; 
				var theResult = objRegExp.test(field);
				if (theResult == false) {
					alert("Please enter a valid Canadian postal code in the format XXX XXX, XXX-XXX or XXXXXX");
					theField.focus();
					return objRegExp.test(field);
					}
				else {
					sepZipProcess(theField,theState); //calls the function to separate the Postal Code into the format XXX XXX
					 }
				
			}
		else
			{
				//check for valid US Zip code
				var objRegExp = /(^\d{5}$)|(^\d{5}-\d{4}$)/; 
				var theResult = objRegExp.test(field);
				if (theResult == false) {
					alert("Please enter a valid US zip code in the format 99999 or 99999-9999");
					theField.focus();
					return objRegExp.test(field);
					} 
				
			}			

	}



// ************************************************************************************
//CHECK FOR VALID EMAIL ADDRESS- IF THERE'S ANYTHING IN THERE, IT NEEDS TO BE CORRECT
// ************************************************************************************

function blankEmail(theField)
	{
	  ckEmail = theField.value;
	  checkEmailField = theField;
	
	  if (ckEmail == "") {// OK to be empty
		return true ;
	  }
	  else { //make sure that if something is entered that its entered correctly
	  	return checkEmail(checkEmailField);
	  }
	}
	  
	  
function checkEmail(field)
	{
	  invalidEmail = " /:,;!#$%^&*()+={}[]<>?~" ;
	
	  for (i=0; i<invalidEmail.length; i++) { // does it contain any invalid characters?
		badChar = invalidEmail.charAt(i) ;
		if (ckEmail.indexOf(badChar,0) > -1) {
		  alert("Please Enter a Valid E-Mail Address. Contains an invalid character.");     
		  field.focus();
		  field.select();
		  return false;
		}
	  }
	
	  atPos = ckEmail.indexOf("@",1) ; // there must be one "@" symbol
	
	  if (atPos == -1) {
		alert("Please Enter a Valid E-Mail Address. No @ sign present.");     
		field.focus();
		field.select();
		return false;
	  }
	
	  if (ckEmail.indexOf("@",atPos+1) != -1) { // and only one "@" symbol
		alert("Please Enter a Valid E-Mail Address. Multiple @ signs present.");    
		field.focus();
		field.select();
		return false;
	  }
	
	  var periodPos = ckEmail.indexOf(".",atPos) ;
	
	  if (periodPos == -1) { // and at least one "." after the "@"
		alert("Please Enter a Valid E-Mail Address. There must be at least one \".\" after the \"@\" ");    
		field.focus();
		field.select();
		return false;
	  }
	
	  if (periodPos+3 > ckEmail.length) { // must be at least 2 characters after the "."
		alert("Please Enter a Valid E-Mail Address. There must be at least 2 characters after the \".\" ");    
		field.focus();
		field.select();
		return false;
	  }
	return true;  
	}


function All_Val(theForm)
{

  invalidChars = " $#/:,;%-.~@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" ;

// **************************************************************
// Q1 Validation Checks
// **************************************************************
    if (theForm.q1.selectedIndex<=0)
    	{
		  alert("Please select one of the \"Question 1\" options.");
		  theForm.q1.focus();
		  return false;
	    }

// **************************************************************
// Q2 Validation Checks
// **************************************************************
	// set var radio_choice to false
	var radio_choice = false;
	
	// Loop from zero to the one minus the number of radio button selections
	for (counter = 0; counter < theForm.q2.length; counter++)
	{
	// If a radio button has been selected it will return true
	// (If not it will return false)
	if (theForm.q2[counter].checked)
	radio_choice = true; 
	}
	
	if (radio_choice == false)
	{
	// If there were no selections made display an alert box 
	alert("Please select one of the \"Question 2\" options.");
	theForm.q2[0].focus();
	return (false);
	}

// **************************************************************
// Q2_1 Validation Checks
// **************************************************************
    	
	if (theForm.q2[0].checked)
	{
		 if (theForm.q2_2.selectedIndex<=0)
		{
		  alert("Please select a response to Question 2: \" I visited this site for..\"");
		  theForm.q2_2.focus();
		  return false;
		}
	}

// **************************************************************
// Q2_2 Validation Checks
// **************************************************************
    	
	if (theForm.q2[1].checked)
	{
		 if (theForm.q2_1.selectedIndex<=0)
		{
		  alert("Please select a response to Question 2: \" When will you visit?\"");
		  theForm.q2_1.focus();
		  return false;
		}
	}

// **************************************************************
// Q3 Validation Checks
// **************************************************************
	// set var radio_choice to false
	var radio_choice = false
	
	// Loop from zero to the one minus the number of radio button selections
	for (counter = 0; counter < theForm.q3.length; counter++)
	{
	// If a radio button has been selected it will return true
	// (If not it will return false)
	if (theForm.q3[counter].checked)
	radio_choice = true; 
	}
	
	if (radio_choice == false)
	{
	// If there were no selections made display an alert box 
	alert("Please select one of the \"Question 3\" options.");
	theForm.q3[0].focus();
	return (false);
	}

// **************************************************************
// q3c_ad (Adults) Validation Checks
// **************************************************************
  ckqq3c_ad = theForm.q3c_ad.value;
  for (i=0; i<invalidChars.length; i++) 
     {  // does it contain any invalid characters?
    badChar = invalidChars.charAt(i) ;
    if (ckqq3c_ad.indexOf(badChar,0) > -1) 
      {
      alert("Please Enter only digit values for Question 3 (Adults)."); 
      theForm.q3c_ad.focus();
      theForm.q3c_ad.select();
      return false;
      }
     }


// **************************************************************
// q3c_ch (Children) Validation Checks
// **************************************************************
  ckqq3c_ch = theForm.q3c_ch.value;
  for (i=0; i<invalidChars.length; i++) 
     {  // does it contain any invalid characters?
    badChar = invalidChars.charAt(i) ;
    if (ckqq3c_ch.indexOf(badChar,0) > -1) 
      {
      alert("Please Enter only digit values for Question 3 (Children)."); 
      theForm.q3c_ch.focus();
      theForm.q3c_ch.select();
      return false;
      }
     }

//**************************************************************
// Q3f Validation Checks
// **************************************************************
//    if (theForm.q3f_1.selectedIndex<=0)
//   {
// 	alert("Please select one of the \"Question 3f\" First State options.");
//	theForm.q3f_1.focus();
//      return false;
//    }


// **************************************************************
// Q3f Validation Checks
// **************************************************************
//    if (theForm.q3f_2.selectedIndex<=0)
//    {
//      alert("Please select one of the \"Question 3f\" Second State options.");
//      theForm.q3f_2.focus();
//      return false;
//    }


// **************************************************************
// Q11ad (Adults) Validation Checks
// **************************************************************
  ckqq11_ad = theForm.q11_ad.value;
  for (i=0; i<invalidChars.length; i++) 
     {  // does it contain any invalid characters?
    badChar = invalidChars.charAt(i) ;
    if (ckqq11_ad.indexOf(badChar,0) > -1) 
      {
      alert("Please Enter only digit values for Question 11 (Adults)."); 
      theForm.q11_ad.focus();
      theForm.q11_ad.select();
      return false;
      }
     }


// **************************************************************
// Q11ch (Children) Validation Checks
// **************************************************************
  ckqq11_ch = theForm.q11_ch.value;
  for (i=0; i<invalidChars.length; i++) 
     {  // does it contain any invalid characters?
    badChar = invalidChars.charAt(i) ;
    if (ckqq11_ch.indexOf(badChar,0) > -1) 
      {
      alert("Please Enter only digit values for Question 11 (Children)."); 
      theForm.q11_ch.focus();
      theForm.q11_ch.select();
      return false;
      }
     }

//**************************************************************
// Q14 Validation Checks
// **************************************************************
    if (theForm.q14.value =="")
   { //required field
 	alert("Please enter your zip code or postal code for Question14.  All other demographic information is optional.");
	theForm.q14.focus();
      return false;
    }

//**************************************************************
// Zip Code Validation Checks 
// **************************************************************

	if (!valZip(theForm.q14,'','survey'))
		{
		theForm.q14.focus();
		return false;
		}

		
//**************************************************************
// Q8 Email Validation Checks 
// **************************************************************

	if (!blankEmail(theForm.q8_email))
		{
		theForm.q8_email.focus();
		return false;
		}		
				
//**************************************************************
// Q9 Email Validation Checks 
// **************************************************************

	if (!blankEmail(theForm.q9_email))
		{
		theForm.q9_email.focus();
		return false;
		}				
//**************************************************************
// Email Validation Checks 
// **************************************************************

	if (!blankEmail(theForm.email))
		{
		theForm.email.focus();
		return false;
		}		

	
  return true ;
  form1.submit(form);
}


// End hiding script from old browsers -->
