//
//   res_error.js
//
//   Written By Scott Walton   18/08/05
//   Modified by Scott Walton 31/12/2007 - adjust to cater correctly to leap year date check
//
//   Purpose : To contain the javascript validations for the 
//          reservation process
//
//

function dateOK(Y, M, D) { 
  return D>0 && (D<=[31,28,31,30,31,30,31,31,30,31,30,31][M] ||
    D==29 && M==1 && Y%4==0 && (Y%100>0 || Y%400==0) );
}


function checkstep1 () {
    v_errormsg="";
   v_errorstat = false;
   v_puloc="";
   v_dmonth="";
   
   // check pick up date has a value
   if (document.step1.PUDATE && document.step1.PUDATE.value == "") {
      v_errorstat = true;
      v_errormsg = "Must enter a Pick Up Date";
   }
   
   // check pick up date has a value
   if (document.step1.DODATE && document.step1.DODATE.value == "") {
      v_errorstat = true;
      v_errormsg = "Must enter a Drop Off Date";
   }
   
   //Check that the PU date is not after the DO date
   var puDate = new Date();
   var pudate_str = document.getElementById('PUDATE').value;
   var pudate_array = pudate_str.split('-');
   
   puDate.setFullYear(pudate_array[2],pudate_array[1]-1, pudate_array[0])
   
   var doDate = new Date();
   var dodate_str = document.getElementById('DODATE').value;
   var dodate_array = dodate_str.split('-');
   doDate.setFullYear(dodate_array[2],dodate_array[1]-1, dodate_array[0])
    
   if (doDate<puDate) {
      v_errorstat = true;
      v_errormsg = "Drop Off Date cannot be before Pick Up Date";      
   }
   
   if (document.step1.PULOC[document.step1.PULOC.selectedIndex].value == "") {
      v_errorstat = true;
      v_errormsg = "Please choose a Pick Up Location";
   }
   


   // return the message and status
   if (v_errorstat == true) {
      alert (v_errormsg);
      return false;
   } else {
      return true;
   }

} // END of checkstep1


//
//   Any online validation is done here for step3 input
//
function checkstep3 () {
   v_errmsg="";
   v_errorstat = false;


   if (document.step3.PHONENO.value == "") {
       v_errorstat=true;
       v_errormsg="Phone Number cannot be left blank";
   } 
   if (document.step3.EMAIL.value == "") {
       v_errorstat=true;
       v_errormsg="Email cannot be left blank";
   } 
   if (document.step3.LASTNAME.value == "") {
       v_errorstat=true;
       v_errormsg="Last Name cannot be left blank";
   } 
   if (document.step3.FIRSTNAME.value == "") {
       v_errorstat=true;
       v_errormsg="First Name cannot be left blank";
   } 

   //   return the message and status
   if (v_errorstat==true) {
      alert (v_errormsg);
      return false;
   } else {
     return true;
   }

} // END of step3 


//   END of res_error.js
