<!-- filename: villa_ck.js - updated: 2008/01/30 - 16:02 - baf -->
<!-- called by: state_result.php -->

<!-- comment out for browser --

//-- define variables --

var ret = false;

var charexp = /./
var letterexp = /[a-z]/i
var phonexp = /^\d{10}$/
var zipexp = /^\d{5}$|^\d{5}[\-\s]?\d{4}$/

function isValid(pattern, str) {
	return pattern.test(str)
}

function hasLetter(str) {
	return letterexp.test(str)
}

function hasChar(str) {
	return charexp.test(str)
}

function stripChars(patter, str) {
	return str.replace(pattern,"")
}

function stripNonDigits(str) {
	return str.replace(/[^0-9]/g,"")
}

//-- validate this form 
function validateForm(form) {
  //-- assign variables
  var fname = document.villaPurchase.fname.value;
  var lname = document.villaPurchase.lname.value;
  var address = document.villaPurchase.address.value;
  var city = document.villaPurchase.city.value;
  var state = document.villaPurchase.state.value;
  var zip = document.villaPurchase.zip.value;
  var homeph = document.villaPurchase.homeph.value;
  var email = document.villaPurchase.email.value;

  //-- check first name for an entry
  if (!hasLetter(fname)) {
	  alert("Please enter your first name. Thank You.")
	  document.villaPurchase.fname.focus()
	  return(ret);
  }
    
  //-- check last name for an entry
  if (!hasLetter(lname)) {
	  alert("Please enter your last name. Thank You.")
	  document.villaPurchase.lname.focus()
	  return(ret);
  }
    
  //-- check address line 1 for an entry
  if (!hasLetter(address)) {
	  alert("Please enter your first line address. Thank You.")
	  document.villaPurchase.address.focus()
	  return(ret);
  }
    
  //-- check city for an entry
  if (!hasLetter(city)) {
	  alert("Please enter your city. Thank You.")
	  document.villaPurchase.city.focus()
	  return(ret);
  }
    
  //-- check state for an entry
  if (!hasLetter(state)) {
	  alert("Please enter your state of residence. Thank You.")
	  document.villaPurchase.state.focus()
	  return(ret);
  }
    
  //-- check zip for an entry
  if (zip.length != 5) {
/*    document.write("<BR>zip: " + zip)*/
/*    document.write("<BR>zip.length: " + zip.length)*/
    
    alert("Please enter your zip-code in the following format:\n\n"
           +"   12345")
      document.villaPurchase.zip.focus()
      return(ret);
  }
  //-- end pattern match zip
  
  //-- blank e-mail
  if (!hasLetter(email)) {
	  alert("Please enter your email address. Thank You.")
	  document.villaPurchase.email.focus()
	  return(ret);
  }
  //-- end e-mail check
  
  if (document.villaPurchase.terms.checked) {
  }
  else
  {
	  alert("You must agree to the terms and conditions\n"
           +"before continuing with this offer.\n\n"
           +"Thank You.")
	  document.villaPurchase.terms.focus()
	  return(ret);
  }
  
  if (document.villaPurchase.permission.checked) {
  }
  else
  {
	  alert("We need your permission to contact you for the\n"
           +"purpose of securing a vacation package.\n\n"
           +"Thank You.")
	  document.villaPurchase.permission.focus()
	  return(ret);
  }
  
  //-- begin pattern match for homeph number
  if (homeph.length != 0) {
    var areaCode = Number(homeph.substring(0,3))
    var dash1 = homeph.substring(3,4)
    var exchange = Number(homeph.substring(4,7))
    var dash2 = homeph.substring(7,8)
    var line = Number(homeph.substring(8,12))

/* -- debug --  
    document.write("<BR>areaCode: " + areaCode)
    document.write("<BR>dash1: " + dash1)
    document.write("<BR>exchange: " + exchange)
    document.write("<BR>dash2: " + dash2)
    document.write("<BR>line: " + line)								
-- */
		
    if (
       (isNaN(areaCode)) ||
			 (dash1 != "-") ||
			 (isNaN(exchange)) ||
			 (dash2 != "-") ||
             (isNaN(line)) ||
			 (dayph.length != 12)
       ) {
           alert("Please enter your home phone number in the following format:\n\n"
                +"                          123-456-7890");
           document.villaPurchase.homeph.focus();
           return(ret);
    }
  }
  else
  {
    //-- blank ph#
    alert("Please enter your Home Phone number. Thank You.")
    document.villaPurchase.homeph.focus()
    return(ret);
  }
  //-- end pattern match homeph number

  //-- Passed everything
  ret = true; // OK to submit the form
  return(ret);
}  

// End -->
