// Date Stuff


// Set todays date in the form
//var now = new Date();
//document.form.amonth.options.selectedIndex = now.getMonth();
//document.form.adom.options.selectedIndex = now.getDate() - 1;

 // document.form.ayear.options.selectedIndex = 0;

// And a week after that...
// var nextWeek = new Date();
// var nextWeekUNIX = now.getTime();
// nextWeekUNIX = nextWeekUNIX + 1000 * 60 * 60 * 24 * 7;
// nextWeek.setTime(nextWeekUNIX);
//document.form.dmonth.options.selectedIndex = nextWeek.getMonth();
//document.form.ddom.options.selectedIndex = nextWeek.getDate() - 1;
//document.form.dyear.options.selectedIndex = 0;

// Update days field
function update_days() {
  var aday = new Date(document.form.ayear[document.form.ayear.options.selectedIndex].value,document.form.amonth.options.selectedIndex,document.form.adom[document.form.adom.options.selectedIndex].value);
  var dday = new Date(document.form.dyear[document.form.dyear.options.selectedIndex].value,document.form.dmonth.options.selectedIndex,document.form.ddom[document.form.ddom.options.selectedIndex].value);
  var adayUNIX = aday.getTime();
  var ddayUNIX = dday.getTime();
  var daydiff = (ddayUNIX - adayUNIX)/1000/60/60/24;

  if (daydiff > 10) { alert("Your trip is longer than 10 days, please make it shorter."); }
  else{
 
    document.form.total.value = daydiff;
 
    var string = "";
  
    for (i=0;i<daydiff;i++) {
  
      var day = new Date();
      day.setTime((adayUNIX + 1000 * 60 * 60 * 24 * i));
      string += "document.form.day" + (i + 1) + ".options.selectedIndex = " + day.getDay() + ";\n"; 
      string += "document.form.date" + (i + 1) + ".value = \"" + day.getMonth() + "/" + day.getDate() + "/" + day.getYear() + "\";\n"; 
      string += "document.form.day" + (i + 1) + ".disabled = false;\n";
      string += "document.form.date" + (i + 1) + ".disabled = false;\n";
      string += "document.form.no" + (i + 1) + ".disabled = false;\n";
  
    }
    for (i=(daydiff + 1);i<=10;i++) { 

      string += "document.form.day" + i + ".disabled = true;\n";
      string += "document.form.date" + i + ".disabled = true;\n";
      string += "document.form.no" + i + ".disabled = true;\n";

    }
 
    eval(string);

  }

}

//update_days();
function Validate_Form() {
  if (document.form.submit.value == "Cancel") {
    return true;
  }
  var missing = "";
  if ( ! document.form.fname.value ) { missing += "\n  - First Name" }
  if ( ! document.form.lname.value ) { missing += "\n  - Last Name" }
  if ( ! document.form.oname.value ) { missing += "\n  - Company Name" }
  if ( ! document.form.email.value ) { missing += "\n  - E-mail" }
  if ( ! document.form.phone.value ) { missing += "\n  - Phone Number" }
  if ( missing ) {
    alert ("Missing entries for " + missing )
    return false;
  }
  if (document.form.email.value ) {
    if ( document.form.email.value.indexOf("@") <= 0 ||
        document.form.email.value.indexOf("@") == document.form.email.value.length - 1 ||
        document.form.email.value.lastIndexOf(".") == document.form.email.value.length - 1 ||
        document.form.email.value.indexOf(".") <= 0 ||
        document.form.email.value.indexOf("@") > document.form.email.value.lastIndexOf(".") ||
        document.form.email.value.indexOf("@") != document.form.email.value.lastIndexOf("@") ) {
      alert ("\nYou must enter a valid Internet\ne-mail address to send to.")
      return false;
    }
  }
  else {
    return true;
        }
}


