function NumOfAdults(){
var AdultIndex = document.forms["abstravel"].NumAdults.selectedIndex;
var AdultValue = document.forms["abstravel"].NumAdults.options[AdultIndex].value;

if (AdultValue == 2){
document.abstravel.PaxType2.value = "ADT"
}
if (AdultValue == 3){
document.abstravel.PaxType2.value = "ADT"
document.abstravel.PaxType3.value = "ADT"
}
if (AdultValue == 4){
document.abstravel.PaxType2.value = "ADT"
document.abstravel.PaxType3.value = "ADT"
document.abstravel.PaxType4.value = "ADT"
}
if (AdultValue == 5){
document.abstravel.PaxType2.value = "ADT"
document.abstravel.PaxType3.value = "ADT"
document.abstravel.PaxType4.value = "ADT"
document.abstravel.PaxType5.value = "ADT"
}
if (AdultValue == 6){
document.abstravel.PaxType2.value = "ADT"
document.abstravel.PaxType3.value = "ADT"
document.abstravel.PaxType4.value = "ADT"
document.abstravel.PaxType5.value = "ADT"
document.abstravel.PaxType6.value = "ADT"
}
if (AdultValue == 7){
document.abstravel.PaxType2.value = "ADT"
document.abstravel.PaxType3.value = "ADT"
document.abstravel.PaxType4.value = "ADT"
document.abstravel.PaxType5.value = "ADT"
document.abstravel.PaxType6.value = "ADT"
document.abstravel.PaxType7.value = "ADT"
}
if (AdultValue == 8){
document.abstravel.PaxType2.value = "ADT"
document.abstravel.PaxType3.value = "ADT"
document.abstravel.PaxType4.value = "ADT"
document.abstravel.PaxType5.value = "ADT"
document.abstravel.PaxType6.value = "ADT"
document.abstravel.PaxType7.value = "ADT"
document.abstravel.PaxType8.value = "ADT"
}
if (AdultValue == 9){
document.abstravel.PaxType2.value = "ADT"
document.abstravel.PaxType3.value = "ADT"
document.abstravel.PaxType4.value = "ADT"
document.abstravel.PaxType5.value = "ADT"
document.abstravel.PaxType6.value = "ADT"
document.abstravel.PaxType7.value = "ADT"
document.abstravel.PaxType8.value = "ADT"
document.abstravel.PaxType9.value = "ADT"
}
}
//
var rmonthi = -1;
var rdayi   = -1;
//
function toMonthString (i) {
   if (i == 0)       return ("January");
   else if (i == 1)  return ("February");
   else if (i == 2)  return ("March");
   else if (i == 3)  return ("April");
   else if (i == 4)  return ("May");
   else if (i == 5)  return ("June");
   else if (i == 6)  return ("July");
   else if (i == 7)  return ("August");
   else if (i == 8)  return ("September");
   else if (i == 9)  return ("October");
   else if (i == 10) return ("November");
   else              return ("December");
   }
//
function toYearMonthString (y, m) {
   if (m < 10)
      return (String(y) + "0" + String(m));
   else
      return (String(y) + String(m));
   }
//
function onLoad () {
// document.forms["abstravel"].D_City.value        = "";
// document.forms["abstravel"].A_City.value        = "";
   document.forms["abstravel"].TripType[0].checked = false;
   document.forms["abstravel"].TripType[1].checked = true;
   
   today    = new Date();
   
   depart   = new Date(today.valueOf() + (96 * 60 * 60 * 1000));
   depart_y = depart.getFullYear();
   depart_m = depart.getMonth();
   depart_d = depart.getDate();
   
   rtn      = new Date(today.valueOf() + (144 * 60 * 60 * 1000));
   rtn_y    = rtn.getFullYear();
   rtn_m    = rtn.getMonth();
   rtn_d    = rtn.getDate();
   
   for (i = 0; i < 10; ++i) {
      document.forms["abstravel"].D_Month.options[i].text  = toMonthString((depart_m + i) % 12) + " " + Math.floor(depart_y + ((depart_m + i) / 12));
      document.forms["abstravel"].D_Month.options[i].value = toYearMonthString(Math.floor(depart_y + ((depart_m + i) / 12)),(((depart_m + i) % 12) + 1));
      document.forms["abstravel"].R_Month.options[i].text  = toMonthString((rtn_m + i) % 12) + " " + Math.floor(rtn_y + ((rtn_m + i) / 12));
      document.forms["abstravel"].R_Month.options[i].value = toYearMonthString(Math.floor(rtn_y + ((rtn_m + i) / 12)),(((rtn_m + i) % 12) + 1));
      }
      
   document.forms["abstravel"].D_Month.options[0].selected          = true;
   document.forms["abstravel"].D_Day.options[depart_d - 1].selected = true;
   document.forms["abstravel"].R_Month.options[0].selected          = true;
   document.forms["abstravel"].R_Day.options[rtn_d - 1].selected    = true;
   
   rmonthi = 0;
   rdayi   = rtn_d - 1;
   
            
   document.forms["abstravel"].D_City.focus();
   }
//
function dateValidator (year, month, day) {
   leap_year = parseInt(year) % 4;
   comp1     = ((month == "02") || (month == "04") || (month == "06") || (month == "09") || (month == "11"));
   comp2     = (day == "31");

   if ((month == "02") && ((day == "30") || ((day == "29") && leap_year != 0)))
      return (false);
   
   if (comp1 && comp2)
      return (false);
      
   return (true);
   }
//
function formValidator (theForm) {
NumOfAdults();

 checkstr = "";
if (theForm.D_City.value.length == 0) {
      alert("Please enter a city name for the \"From\" field.");
      theForm.D_City.focus();
      return (false);
      }
      
   if (theForm.A_City.value.length == 0) {
      alert("Please enter a city name for the \"To\" field.");
      theForm.A_City.focus();
      return (false);
      }
      
   if (theForm.TripType[0].checked == false && theForm.TripType[1].checked == false) {
      alert("Please select either \"One Way\" or \"Round Trip\"");
      theForm.TripType.focus();
      return (false);
      }
      
   if (theForm.D_Month.selectedIndex < 0) {
      alert("Please select a \"Departing Month\"");
      theForm.D_Month.focus();
      return (false);
      }
      
   if (theForm.D_Day.selectedIndex < 0) {
      alert("Please select a \"Departing Day\"");
      theForm.D_Day.focus();
      return (false);
      }
      
   
      
   year  = (theForm.D_Month.options[theForm.D_Month.selectedIndex].value).substr(0,4);
   month = (theForm.D_Month.options[theForm.D_Month.selectedIndex].value).substr(4,2);
   day   = theForm.D_Day.options[theForm.D_Day.selectedIndex].value;
   if (!dateValidator(year,month,day)) {
      alert("Invalid \"Departure Date\"");
      theForm.D_Day.focus();
      return (false);
      }
      
   if (theForm.TripType[1].checked == true) {
      if (theForm.R_Month.selectedIndex < 0 || theForm.R_Month.selectedIndex >= (theForm.R_Month.options.length - 1)) {
         alert("Please select a \"Returning Month\"");
         theForm.R_Month.focus();
         return (false);
         }
      
      if (theForm.R_Day.selectedIndex < 0 || theForm.R_Day.selectedIndex >= (theForm.R_Day.options.length - 1)) {
         alert("Please select a \"Returning Day\"");
         theForm.R_Day.focus();
         return (false);
         }
      
      
   
      year  = (theForm.R_Month.options[theForm.R_Month.selectedIndex].value).substr(0,4);
      month = (theForm.R_Month.options[theForm.R_Month.selectedIndex].value).substr(4,2);
      day   = theForm.R_Day.options[theForm.R_Day.selectedIndex].value;
      if (!dateValidator(year,month,day)) {
         alert("Invalid \"Return Date\"");
         theForm.R_Day.focus();
         return (false);
         }
         
      if ((theForm.D_Month.options[theForm.D_Month.selectedIndex].value +
           theForm.D_Day.options[theForm.D_Day.selectedIndex].value) >=
          (theForm.R_Month.options[theForm.R_Month.selectedIndex].value +
           theForm.R_Day.options[theForm.R_Day.selectedIndex].value)) {
         alert("\"Departure Date\" must be before \"Return Date\" [" +
               (theForm.D_Month.options[theForm.D_Month.selectedIndex].value +
                theForm.D_Day.options[theForm.D_Day.selectedIndex].value) + "," +
               (theForm.R_Month.options[theForm.R_Month.selectedIndex].value +
                theForm.R_Day.options[theForm.R_Day.selectedIndex].value) + "]");
         theForm.R_Month.focus();
         return (false);
         }
      }
   else {
      theForm.R_Month.selectedIndex = (theForm.R_Month.options.length - 1);
      theForm.R_Day.selectedIndex   = (theForm.R_Day.options.length - 1);
      }
      
   if (theForm.ClassOfService.selectedIndex < 0) {
      alert("Please select a \"Fare Type\"");
      theForm.ClassOfService.focus();
      return (false);
      }
}
//
function roundTrip () {
   document.forms["abstravel"].R_Month.options[rmonthi].selected = true;
   document.forms["abstravel"].R_Day.options[rdayi].selected     = true;
   }
//
function onewayTrip () {
   lengthMonth = document.forms["abstravel"].R_Month.length;
   lengthDay   = document.forms["abstravel"].R_Day.length;
   
   
   if (!((document.forms["abstravel"].R_Month.selectedIndex == (lengthMonth-1)) && 
         (document.forms["abstravel"].R_Day.selectedIndex   == (lengthDay-1)))) {
      rmonthi = document.forms["abstravel"].R_Month.selectedIndex;
      rdayi   = document.forms["abstravel"].R_Day.selectedIndex;
      
      
      document.forms["abstravel"].R_Month.options[lengthMonth-1].selected = true;
      document.forms["abstravel"].R_Day.options[lengthDay-1].selected     = true;
      }
   }

