function checkformentries(frm){
   //check arrival date
  var arrivaldate=document.getElementById('arrival_date_c');
  if (arrivaldate.value==""){
    alert('Please Enter your Arrival Date');
    //note: when using document.getElementById you don't need to 
    //reference the form to set the focus, hence no frm.arrivaldate.focus();
    arrivaldate.focus();
    return false;
  }
  //check departure date
  var departuredate=document.getElementById('departure_date_c');
  if (departuredate.value==""){
    alert('Please Enter your Departure Date');
    departuredate.focus();
    return false;
  }  
 //check first name
  if (frm.first_name.value==""){
    alert('Please Enter your First Name');
    frm.first_name.focus();
    return false;
  }
  //check last name
  if (frm.last_name.value==""){
    alert('Please Enter your Last Name');
    frm.last_name.focus();
    return false;
  }
  //check street address
  if (frm.primary_address_street.value==""){
    alert('Please Enter your Address');
    frm.primary_address_street.focus();
    return false;
  }
  //check city
  if (frm.primary_address_city.value==""){
    alert('Please Enter your City');
    frm.primary_address_city.focus();
    return false;
  }
  //check state
//  if (frm.state.value==""){
//    alert('Please Enter your State');
//    frm.state.focus();
//    return false;
//  }
  //check zip
  if (frm.primary_address_postalcode.value==""){
    alert('Please Enter your Zip Code');
    frm.primary_address_postalcode.focus();
    return false;
  }
  /* skip country, there's always a value there
     we can't know if the user selected the right
     country or not  
  */
  //check email address for text entry
  if (frm.email1.value==""){
    alert('Please Enter your E-mail Address');
    frm.email1.focus();
    return false;
  }
  //check email address for validity
  if (isEmail(frm.email1.value)!=true){
    alert('Please Enter a VALID E-mail Address');
    frm.email1.focus();
    return false
  }
  //check phone for text input
  if (frm.phone_home.value==""){
    alert('Please Enter your Phone Number');
    frm.phone_home.focus();
    return false;
  }
  //check phone number is valid
  var phonenumberstatus=checkPhone(frm.phone_home.value);
  if (phonenumberstatus != 'OK'){
    alert(phonenumberstatus);
    frm.phone_home.focus();
    return false;
  }
  /* skip fax, not everyone has access to one */
  //check work phone for text input
  //var workphone=document.getElementById('00N30000000tsmJ');
  //if(workphone.value==""){
  //  alert('Please Enter your WORK Phone Number');
  //  workphone.focus();
  //  return false;
  //}
  //check work phone number is valid
  //phonenumberstatus=checkPhone(workphone.value);
  //if (phonenumberstatus != 'OK'){
  //  alert(phonenumberstatus);
  //  workphone.focus();
  //  return false;
  //}
  

  /* skip number of rooms, we can't know if the default value of 1 is correct or not */
  /* skip number of adults, we can't know if the default of 1 is correct or not */
  /* skip number of children, we can't know if the default value of 0 is correct or not */
  /* skip room type request, we can't know if the default value of Double is correct or not */
  /* skip smoking/non-smoking, we can't know if the default value of No Preference is correct or not */
  /* skip Rollaway, we can't know if the default value of 0 is correct or not */
  /* skip Crib, we can't know if the default value of 0 is correct or not */
  //
  //check type of credit card
  var creditcardtype=document.getElementById('credit_card_type_c');
  if (creditcardtype.selectedIndex==0){
    alert('Please Select the Type of Credit Card you will be Paying With');
    creditcardtype.focus();
    return false;
  }
  //check name on credit card
  var creditcardname=document.getElementById('name_on_card_c');
  if (creditcardname.value==""){
    alert('Please Enter the Your Name as it appears on Your Credit Card');
    creditcardname.focus();
    return false;
  }
  //check credit card number
  var creditcardnumber=document.getElementById('credit_card_number_c');
  if (creditcardnumber.value==""){
    alert('Please Enter Your Credit Card Number\n\n(Please enter Numbers Only, no dashes)');
    creditcardnumber.focus();
    return false;
  }  
  //check credit card validity
  if (LuhnCC(creditcardnumber.value) != true){
    alert('Please Enter a VALID Credit Card Number');
    creditcardnumber.focus();
    return false;
  }
  //check credit expiration month
  var creditcardexpirationmo=document.getElementById('exp_month_c');
  if (creditcardexpirationmo.selectedIndex==0){
    alert('Please Select the Expiration MONTH for Your Credit Card');
    creditcardexpirationmo.focus();
    return false;
  }
  //check credit expiration year
  var creditcardexpirationyr=document.getElementById('exp_year_c');
  if (creditcardexpirationyr.selectedIndex==0){
    alert('Please Select the Expiration YEAR for Your Credit Card');
    creditcardexpirationyr.focus();
    return false;
  } 
  //check credit card security code
  var creditcardsecuritycode=document.getElementById('credit_card_sec_code_c');
  if (creditcardsecuritycode.value==""){
    alert('Please Enter the 3 or 4 Digit Security Code for Your Credit Card');
    creditcardsecuritycode.focus();
    return false;
  } 
  //check cancellation acceptance checkbox
  var cancellationacceptance=document.getElementById('cancellation_c');
  if (cancellationacceptance.checked==false){
    alert('Please Check the Cancellation Acceptance Checkbox\n\nto show that you have read and understood our 48 hr. Cancellation Policy');
    cancellationacceptance.focus();
    return false;
  }
  /* if we made it this far, none of our data entry requirements 
     or data validity tests failed. So we're ready to submit the form: */
  frm.submit();
}

/* here's a different email validator that isn't quite as rigorous as the next one */
/*
function isValidEmail(emailstring){
  var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
  if (filter.test(emailstring)){
    return true;
  }else{
    return false;
    //alert("Please input a valid email address!")
  }
}
*/

function isEmail(str) {
  // are regular expressions supported?
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  // if they aren't supported
  if (!supported) return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  // if they are supported
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function checkPhone(strng) {
  //strip out acceptable non-numeric characters
  var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); 
  //alert(stripped);
  if (isNaN(parseInt(stripped))){
    return "The phone number contains illegal characters.";
  }
  if (!(stripped.length >= 10)){
    return "The phone number is the wrong length. Make sure you included an area code.\n";
  } 
  return 'OK';
}

function LuhnCC(s){
  var i, n, c, r, t;
  // First, reverse the string and remove any non-numeric characters.
  r = "";
  for (i = 0; i < s.length; i++) {
    c = parseInt(s.charAt(i), 10);
    if (c >= 0 && c <= 9)
      r = c + r;
  }
  // Check for a bad string.
  if (r.length <= 1)
    return false;
  // Now run through each single digit to create a new string. Even digits
  // are multiplied by two, odd digits are left alone.
  t = "";
  for (i = 0; i < r.length; i++) {
    c = parseInt(r.charAt(i), 10);
    if (i % 2 != 0)
      c *= 2;
    t = t + c;
  }
  // Finally, add up all the single digits in this string.
  n = 0;
  for (i = 0; i < t.length; i++) {
    c = parseInt(t.charAt(i), 10);
    n = n + c;
  }
  // If the resulting sum is an even multiple of ten (but not zero), the
  // card number is good.
  if (n != 0 && n % 10 == 0)
    return true;
  else
    return false;
}


