// JavaScript Document
function validateFields()
{

     with (document.ContactForm) {

	if (first_name.value.length < 1) {
        first_name.focus();
        alert( "You must enter your first name." );
  	return false;
      }
	  
	if (last_name.value.length < 1) {
        last_name.focus();
        alert( "You must enter your last name." );
  	return false;
      }
	  
	 if (addressLine1.value.length < 1) {
        addressLine1.focus();
        alert( "You must enter your address." );
  	return false;
      }
	
	if (city.value.length < 1) {
        city.focus();
        alert( "You must enter your city." );
  	return false;
      }
	 
	if (state.value==0) {
        state.focus();
        alert( "You must enter your state." );
  	return false;
      }
	  
	if (zip.value.length < 1) {
        zip.focus();
        alert( "You must enter your zip code." );
  	return false;
      }
	  
	   
	  if (email.value.length < 1) {
        email.focus();
        alert( "You must enter your email address." );
  	return false;
      }
	  
	
	 for (var i = 0; i < sendinfo.length; i++) {
       if ( sendinfo[i].checked ) {
	   	var sendin_check = true;}
		}
	if(!sendin_check)
		{
		alert ("Please let us know if you would like a brochure.");
		
	 return false;
	 	}

	  }//end with
	
	if(formatPhone()==true)
		
	  	//return true; 
		{//alert("ok");
		return true;
		}
	else
		return false;

}

function formatPhone()
{
     
	  //alert("bob");
     
	 for(var j=8; j<10; j++) {
	//alert(document.ContactForm.elements[j].name);
	var theCount = 0;
	 var theString = document.ContactForm.elements[j].value;
     var newString = "";
     var myString = theString;
     var theLen = myString.length;
	
     for ( var i = 0 ; i < theLen ; i++ )
     {
     // Character codes for ints 1 - 9 are 48 - 57
          if ( (myString.charCodeAt(i) >= 48 ) && (myString.charCodeAt(i) <= 57) )
          newString = newString + myString.charAt(i);   
     }
// Now the validation to determine that the remaining string is 9 characters.
     if (newString.length == 10 )
     {
// Now the string has been stripped of other chars it can be reformatted to ###-##-#### 
          var newLen = newString.length;
          var newPhone = "";
          for ( var i = 0 ; i < newLen ; i++ )
          {
               if ( ( i == 2 ) || ( i == 5 ) )
               {
                    newPhone = newPhone + newString.charAt(i) + "-";
               }else{
                    newPhone = newPhone + newString.charAt(i);
               }
          }
          //document.ContactForm.FIELD.value = newPhone;
		  document.ContactForm.elements[j].value = newPhone;
          //return true;
     }else{
		 //blank phone is OK
		  if(theLen != 0 )
		  {
          alert("The phone number you entered "+newString+" does not contain the correct number of digits");
          document.ContactForm.elements[j].focus();
          return false;
		  }
     }
	 }//end for loop
	 return true;
}