var SECOND = 1000;
var MINUTE = SECOND * 60;
var HOUR = MINUTE * 60;
var DAY = HOUR * 24;
var WEEK = DAY * 7;

var days = new Array();
days[0] = "Sun";
days[1] = "Mon";
days[2] = "Tue";
days[3] = "Wed";
days[4] = "Thurs";
days[5] = "Fri";
days[6] = "Sat";

function validDate()
{
 if ((document.form.arrivedate.selectedIndex!=0)&&(document.form.arrivemonth.selectedIndex!=0)&&(document.form.arriveyear.selectedIndex!=0))
 {
  now = new Date();
  todaydate = now.getDate();
  todaymonth = now.getMonth();
  todayyear = now.getFullYear();
  if (((document.form.arrivemonth.options[document.form.arrivemonth.selectedIndex].value-1) < todaymonth)&&(document.form.arriveyear.options[document.form.arriveyear.selectedIndex].value <= todayyear))
  {
   alert('You have entered a date that has already passed');
   document.form.arrivedate.selectedIndex=0;
   document.form.arrivemonth.selectedIndex=0;
   document.form.arriveyear.selectedIndex=0;
   return(false);
  }
  if ((document.form.arrivedate.options[document.form.arrivedate.selectedIndex].value < todaydate)&&((document.form.arrivemonth.options[document.form.arrivemonth.selectedIndex].value-1)==todaymonth)&&(document.form.arriveyear.options[document.form.arriveyear.selectedIndex].value <= todayyear))
  {
   alert('You have entered a date that has already passed');
   document.form.arrivedate.selectedIndex=0;
   document.form.arrivemonth.selectedIndex=0;
   document.form.arriveyear.selectedIndex=0;
   return(false);
  }
 }
 if ((document.form.arrivedate.selectedIndex!=0)&&(document.form.arrivemonth.selectedIndex!=0)&&(document.form.arriveyear.selectedIndex!=0)&&(document.form.departdate.selectedIndex!=0)&&(document.form.departmonth.selectedIndex!=0)&&(document.form.departyear.selectedIndex!=0))
 {
  arrived = parseInt(document.form.arrivedate.options[document.form.arrivedate.selectedIndex].value);
  arrivem = parseInt(document.form.arrivemonth.options[document.form.arrivemonth.selectedIndex].value);
  arrivey = parseInt(document.form.arriveyear.options[document.form.arriveyear.selectedIndex].value);
  departd = parseInt(document.form.departdate.options[document.form.departdate.selectedIndex].value);
  departm = parseInt(document.form.departmonth.options[document.form.departmonth.selectedIndex].value);
  departy = parseInt(document.form.departyear.options[document.form.departyear.selectedIndex].value);

  if (departy < arrivey)
  {
   alert('You have entered a departure date that is before the arrival date');
   document.form.departdate.selectedIndex = 0;
   document.form.departmonth.selectedIndex = 0;
   document.form.departyear.selectedIndex = 0;
   document.form.departday.value = '';
   return(false);
  }
  if ((departm < arrivem)&&(departy <= arrivey))
  {
   alert('You have entered a departure date that is before the arrival date');
   document.form.departdate.selectedIndex = 0;
   document.form.departmonth.selectedIndex = 0;
   document.form.departyear.selectedIndex = 0;
   document.form.departday.value = '';
   return(false);
  }
  if ((departd < arrived)&&(departm == arrivem)&&(departy <= arrivey))
  {
   alert('You have entered a departure date that is before the arrival date');
   document.form.departdate.selectedIndex = 0;
   document.form.departmonth.selectedIndex = 0;
   document.form.departyear.selectedIndex = 0;
   document.form.departday.value = '';
   return(false);
  }
 }
 if ((document.form.arrivedate.selectedIndex!=0)&&(document.form.arrivemonth.selectedIndex!=0)&&(document.form.arriveyear.selectedIndex!=0))
 {
  Now = new Date();
  Now.setDate(document.form.arrivedate.options[document.form.arrivedate.selectedIndex].value)
  Now.setMonth((document.form.arrivemonth.options[document.form.arrivemonth.selectedIndex].value)-1)
  Now.setYear(document.form.arriveyear.options[document.form.arriveyear.selectedIndex].value)

  aday = Now.getDay();

  document.form.arriveday.value=days[aday];
 }
 else
 {
  document.form.arriveday.value='Day';
 }

 if ((document.form.departdate.selectedIndex!=0)&&(document.form.departmonth.selectedIndex!=0)&&(document.form.departyear.selectedIndex!=0))
 {
  Now = new Date();
  Now.setDate(document.form.departdate.options[document.form.departdate.selectedIndex].value)
  Now.setMonth((document.form.departmonth.options[document.form.departmonth.selectedIndex].value)-1)
  Now.setYear(document.form.departyear.options[document.form.departyear.selectedIndex].value)

  dday = Now.getDay();

  document.form.departday.value=days[dday];
 }
 else
 {
  document.form.departday.value='Day';
 }
}

function CheckMonth()
{
 dateval = 0;
 monthval = 0;
 yearval = 0;

 if ((document.form.arrivedate.selectedIndex!=0)&&(document.form.arrivemonth.selectedIndex!=0)&&(document.form.arriveyear.selectedIndex!=0))
 {
  dateval = parseInt(document.form.arrivedate.options[document.form.arrivedate.selectedIndex].value);
  monthval = parseInt((document.form.arrivemonth.options[document.form.arrivemonth.selectedIndex].value)-1);
  yearval = parseInt(document.form.arriveyear.options[document.form.arriveyear.selectedIndex].value);

  if (yearval % 4 != 0)
  {
   if (monthval == 1)
   {
    if (dateval > 28)
    {
     window.alert('Wrong number of days for this month');
     return(false);
    }
   }
   if ((monthval == 3)||(monthval == 5)||(monthval == 8)||(monthval == 10))
   {
    if (dateval > 30)
    {
     window.alert('Wrong number of days for this month');
     return(false);
    }
   }
  }
  if (yearval % 4 == 0)
  {
   if (monthval == 1)
   {
    if (dateval > 29)
    {
     window.alert('Wrong number of days for this month');
     return(false);
    }
   }
   if ((monthval == 3)||(monthval == 5)||(monthval == 8)||(monthval == 10))
   {
    if (dateval > 30)
    {
     window.alert('Wrong number of days for this month');
     return(false);
    }
   }
  }
 }
}

function openCalender(url)
{
  var params="menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,dependent,top=0,left=0,width=670,height=190";
  popupWin = window.open(url, 'calender',params);
  popupWin.focus();
}

function validDate2()
{
 if ((document.form.arrivedate.selectedIndex!=0)&&(document.form.arrivemonth.selectedIndex!=0)&&(document.form.arriveyear.selectedIndex!=0))
 {
  now = new Date();
  todaydate = now.getDate();
  todaymonth = now.getMonth();
  todayyear = now.getFullYear();
  if (((document.form.arrivemonth.options[document.form.arrivemonth.selectedIndex].value-1) < todaymonth)&&(document.form.arriveyear.options[document.form.arriveyear.selectedIndex].value <= todayyear))
  {
   alert('You have entered a date that has already passed');
   document.form.arrivedate.selectedIndex=0;
   document.form.arrivemonth.selectedIndex=0;
   document.form.arriveyear.selectedIndex=0;
   return(false);
  }
  if ((document.form.arrivedate.options[document.form.arrivedate.selectedIndex].value < todaydate)&&((document.form.arrivemonth.options[document.form.arrivemonth.selectedIndex].value-1)==todaymonth)&&(document.form.arriveyear.options[document.form.arriveyear.selectedIndex].value <= todayyear))
  {
   alert('You have entered a date that has already passed');
   document.form.arrivedate.selectedIndex=0;
   document.form.arrivemonth.selectedIndex=0;
   document.form.arriveyear.selectedIndex=0;
   return(false);
  }
 }
 if ((document.form.arrivedate.selectedIndex!=0)&&(document.form.arrivemonth.selectedIndex!=0)&&(document.form.arriveyear.selectedIndex!=0))
 {
  Now = new Date();
  Now.setDate(document.form.arrivedate.options[document.form.arrivedate.selectedIndex].value)
  Now.setMonth((document.form.arrivemonth.options[document.form.arrivemonth.selectedIndex].value)-1)
  Now.setYear(document.form.arriveyear.options[document.form.arriveyear.selectedIndex].value)

  aday = Now.getDay();

  document.form.arriveday.value=days[aday];
 }
 else
 {
  document.form.arriveday.value='Day';
 }
}
