var rmonthi = -1;
var rdayi   = -1;
var rtimei  = -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"].P_City.value        = "";
   
   today    = new Date();
   
   pickup   = new Date(today.valueOf() + (48 * 60 * 60 * 1000));
   pickup_y = pickup.getFullYear();
   pickup_m = pickup.getMonth();
   pickup_d = pickup.getDate();
   
   rtn      = new Date(today.valueOf() + (72 * 60 * 60 * 1000));
   rtn_y    = rtn.getFullYear();
   rtn_m    = rtn.getMonth();
   rtn_d    = rtn.getDate();
   
   for (i = 0; i < 10; ++i) {
      document.forms["abstravel"].P_Month.options[i].text  = toMonthString((pickup_m + i) % 12) + " " + Math.floor(pickup_y + ((pickup_m + i) / 12));
      document.forms["abstravel"].P_Month.options[i].value = toYearMonthString(Math.floor(pickup_y + ((pickup_m + i) / 12)),(((pickup_m + i) % 12) + 1));
      document.forms["abstravel"].D_Month.options[i].text  = toMonthString((rtn_m + i) % 12) + " " + Math.floor(rtn_y + ((rtn_m + i) / 12));
      document.forms["abstravel"].D_Month.options[i].value = toYearMonthString(Math.floor(rtn_y + ((rtn_m + i) / 12)),(((rtn_m + i) % 12) + 1));
      }
      
   document.forms["abstravel"].P_Month.options[0].selected          = true;
   document.forms["abstravel"].P_Day.options[pickup_d - 1].selected = true;
   document.forms["abstravel"].D_Month.options[0].selected          = true;
   document.forms["abstravel"].D_Day.options[rtn_d - 1].selected    = true;
   
   rmonthi = 0;
   rdayi   = rtn_d - 1;
   
   for (i = 0; i < document.forms["abstravel"].D_Time.length; i++)
      if (document.forms["abstravel"].D_Time.options[i].defaultSelected == true)
         rtimei = i;
         
   document.forms["abstravel"].P_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) {
if (theForm.P_City.value.length == 0) {
      alert("Please enter a city name for the \"Pick up airport\" field.");
      theForm.P_City.focus();
      return (false);
      }
      
   if (theForm.P_Month.selectedIndex < 0) {
      alert("Please select a \"Pick up Month\"");
      theForm.P_Month.focus();
      return (false);
      }
      
   if (theForm.P_Day.selectedIndex < 0) {
      alert("Please select a \"Pick up Day\"");
      theForm.P_Day.focus();
      return (false);
      }
      
   if (theForm.P_Time.selectedIndex < 0) {
      alert("Please select a \"Pick up Time\"");
      theForm.P_Time.focus();
      return (false);
      }
      
   year  = (theForm.P_Month.options[theForm.P_Month.selectedIndex].value).substr(0,4);
   month = (theForm.P_Month.options[theForm.P_Month.selectedIndex].value).substr(4,2);
   day   = theForm.P_Day.options[theForm.P_Day.selectedIndex].value;
   if (!dateValidator(year,month,day)) {
      alert("Invalid \"Pick up Date\"");
      theForm.P_Day.focus();
      return (false);
      }
      
         
      if (theForm.D_Day.selectedIndex < 0 || theForm.D_Day.selectedIndex >= (theForm.D_Day.options.length - 1)) {
         alert("Please select a \"Returning Day\"");
         theForm.D_Day.focus();
         return (false);
         }
      
      if (theForm.D_Time.selectedIndex < 0 && theForm.D_Time.selectedIndex >= (theForm.D_Time.options.length - 1)) {
         alert("Please select a \"Returning Time\"");
         theForm.D_Time.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 \"Return Date\"");
         theForm.D_Day.focus();
         return (false);
         }
         
      if ((theForm.P_Month.options[theForm.P_Month.selectedIndex].value +
           theForm.P_Day.options[theForm.P_Day.selectedIndex].value) >=
          (theForm.D_Month.options[theForm.D_Month.selectedIndex].value +
           theForm.D_Day.options[theForm.D_Day.selectedIndex].value)) {
         alert("\"Pick up Date\" must be before \"Return Date\" [" +
               (theForm.P_Month.options[theForm.P_Month.selectedIndex].value +
                theForm.P_Day.options[theForm.P_Day.selectedIndex].value) + "," +
               (theForm.D_Month.options[theForm.D_Month.selectedIndex].value +
                theForm.D_Day.options[theForm.D_Day.selectedIndex].value) + "]");
         theForm.D_Month.focus();
         return (false);
         }
      }

