// 
//   errorcheck.js 
//
//   Written by Scott Walton - 14/08/06 
//   Modified by Owen O Doehrty 07/07/09 - Added validation for booking vehicle
//
//   Purpose : top provide front end validation for the input resbox.
//
//

function check_payment()
{
    v_errormsg="";
   v_errorstat = false;  

//check expiry date

userMonth = document.booking.PAYMONTH.value
userYear = document.booking.PAYYEAR.value

var userDate = new Date(userYear, userMonth,0,0,0,0,0)
var currDate = new Date()

   if (userDate < currDate)
   {
       v_errorstat = true
       v_errormsg = "Expiry Date not valid"
   } 

//Check that Name has been filled
 if (document.booking.PAYNAME.value=='')
  {
     v_errorstat = true
     v_errormsg = "Please enter Name on Card"
  }

//Check Card Number
  if (document.booking.PAYCCNUM.value=='')
   {
      v_errorstat = true
      v_errormsg = "Please enter a Credit Card Number"
   }  

   //   return the message and status
   if (v_errorstat==true) {
      alert (v_errormsg);
      return false;
   } else {
     return true;
   }



} //check payment


function check_resbox() {
   v_errormsg="";
   v_errorstat = false;
   var myDays=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"];
   
   // get todays day and time, if it is on a sat after 4pm they can't request a quote for pickup on sunday (tomorrow)
   var today=new Date(); // get todays date
   //today.setFullYear(2007,1,3); // set the date object to a date y/m/d TAKE THIS LINE OUT AFTER TESTING
   todaysDay=today.getDay(); // get the number of the day ie wed is 3
   todaysMonth=today.getMonth(); // get the number of the month ie january is 0
   todaysYear=today.getFullYear(); // get the year in 4 digits
   thisDay=myDays[todaysDay]; // find the name of that day number from the array
   
  
   // get the time now
   var Mins;
   var Hours;
   Stamp = new Date();
   Hours = Stamp.getHours();
   Mins = Stamp.getMinutes();


   // Get the pickup date
   //v_pday=document.step3.PUDAY.value;
   //v_pmonth=document.step3.PUMONTH.value - 1; // minus one as its a php month ie jan is 01 but jan in javascript is 0
   //v_pyear=document.step3.PUYEAR.value;
   
   
      // Get the pickup date
   for (var i = 0; i<document.step1.PUDAY.options.length; i++) {
     if (document.step1.PUDAY.options[i].selected==true) {
        v_pday=parseFloat(document.step1.PUDAY.options[i].text);
        break;
     }
   }
   for (var i = 0; i<document.step1.PUMTHYR.options.length; i++) {
     if (document.step1.PUMTHYR.options[i].selected==true) {
        v_pmonth=document.step1.PUMTHYR.options[i].value;
        break;
     }
   }      
      // split the month and year 
      var word=v_pmonth.split("-");
      var v_pyear=parseFloat(word[0]);
      var v_pmonth=parseFloat(word[1]) -1; 
   
   
  
   // If today is a sat after 4pm (16:00) and the pickup date is for sunday we don't want to give them a quote
   // CHANGE BACK TO 16 AFTER TESTING AND DON'T SET THE DATE OF TOMORROW INITALLY
   if (todaysDay == 6 && Hours >= 16) {

   var tomorrow=new Date(); // get todays date for making it tomorrow
   //tomorrow.setFullYear(2007,1,03); // set the date object to a date y/m/d TAKE THIS LINE OUT AFTER TESTING

      //get tomorrows date
      tomorrow.setDate(tomorrow.getDate() +1);
      
      tomorrowDay=tomorrow.getDate();
      tomorrowMonth=tomorrow.getMonth();
      tomorrowYear=tomorrow.getFullYear();

   // alert(tomorrow);
   // alert(today);
    
      if (v_pday == tomorrowDay && v_pmonth == tomorrowMonth && v_pyear == tomorrowYear) {
            
         v_errorstat = true;
         v_errormsg = "Our office is currently unattended, please ammend pickup day to Monday.";
      } 
         

   }
      
   //   validate the user has selected a location 
   if (document.step1.PULOC.value=="select") {
     v_errorstat = true;
     v_errormsg = "Must select a Pick Up Location";
   }
   
   //   return the message and status
   if (v_errorstat==true) {
      alert (v_errormsg);
      return false;
   } else {
     return true;
   }
   
   

} // check_resbox
