// 
//   errorcheck.js 
//
//   Written by Scott Walton - 14/08/06 
//   Modified by Owen O Doherty  07/07/09 - Added validation for Booking step
//   Modified by Liana Thomas    11/10/10 - Changed code to reflect current resbox fields
//
//   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"
   }
//Check that card is not Amex
  if (document.booking.PAYCCNUM.value.charAt(0)=='3')
   {
      v_errorstat = true
      v_errormsg = "Only Visa or Mastercard accepted."
   }

   //Check if agreed to T&Cs
   if (! document.booking.TERMS.checked) {
      v_errorstat = true
      v_errormsg = "Must agree to the Terms and Conditions";
   
   }

   //Check if the expire year is ok
   if (document.booking.PAYYEAR[document.booking.PAYYEAR.selectedIndex].value == "select") {
      v_errorstat = true;
      v_errormsg = "Please enter a Credit Card expiry year";
   }
   //Check if the expire month is ok
   if (document.booking.PAYMONTH[document.booking.PAYMONTH.selectedIndex].value == "select") {
      v_errorstat = true;
      v_errormsg = "Please enter a Credit Card expiry month";
   }   
   
   //   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,0,27); // 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
   if (document.step1.PUDATE) {
      var word = document.step1.PUDATE.value.split("-");
      var v_pday = parseFloat(word[0]);
      var v_pmonth = parseFloat(word[1]) - 1;
      var v_pyear = parseFloat(word[2]);
   } else if (document.step1.PUMTHYR) {
      // 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;       
   }
   //alert(v_pday + "-" + v_pmonth + "-" + v_pyear);
   
   // 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,0,27); // 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 Pick Up 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";
   }
   
   // 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 drop off date has a value
   if (document.step1.DODATE && document.step1.DODATE.value == "") {
      v_errorstat = true;
      v_errormsg = "Must enter a Drop Off Date";
   }
   
   // return the message and status
   if (v_errorstat == true) {
      alert (v_errormsg);
      return false;
   } else {
      return true;
   }

}//end check_resbox()


function check_resbox_v2() {
   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,0,27); // 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_v2.PUDAY.options.length; i++) {
     if (document.step1_v2.PUDAY.options[i].selected==true) {
        v_pday=parseFloat(document.step1_v2.PUDAY.options[i].text);
        break;
     }
   }
   for (var i = 0; i<document.step1_v2.PUMTHYR.options.length; i++) {
     if (document.step1_v2.PUMTHYR.options[i].selected==true) {
        v_pmonth=document.step1_v2.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,0,27); // 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_v2.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





function showSupps()
{

   document.getElementById("popout").style.display="inline";

} //showSupps


function hideSupps()
{
   document.getElementById("popout").style.display="none";
}



function showCats()
{

   document.getElementById("popout2").style.display="inline";

} 

function hideCats()
{
   document.getElementById("popout2").style.display="none";
}


function showTypes()
{

   document.getElementById("popout3").style.display="inline";

} 

function hideTypes()
{
   document.getElementById("popout3").style.display="none";
}




