// JavaScript Document

function validateForm(){
var thisform=window.document.resform;
var name=thisform.name.value;
var phone=thisform.telephone.value;
var email=thisform.email.value;
var pax=thisform.pax.selectedIndex;
var occasion=thisform.occasion.selectedIndex;
var q1=thisform.q1.selectedIndex;
var q2=thisform.q2.selectedIndex;
var q3=thisform.q3.selectedIndex;
var limo1=thisform.limo1.selectedIndex;
var limo2=thisform.limo2.selectedIndex;
var limo3=thisform.limo3.selectedIndex;
var hours1=thisform.hours1.selectedIndex;
var hours2=thisform.hours2.selectedIndex;
var hours3=thisform.hours3.selectedIndex;

if ((name=="")||(name.length<2)||(name==" ")){alert("Please enter your name."); document.resform.name.focus();  return false}
if (phone==""){alert("Please enter your contact number."); document.resform.telephone.focus();  return false}
if (phone.length<10){alert("Please enter your full contact number including 3 digit area code."); document.resform.telephone.focus();  return false}

var theat=email.indexOf("@")
var thedot=email.indexOf(".")
var aspace=email.indexOf(" ")

if (email==""){alert ("Please enter your email address for contact."); document.resform.email.focus(); return false}
else if (theat==0 || thedot==-1 || thedot==0 || thedot==email.length-1 || aspace>-1 || theat==email.length-1){alert ("Invalid Email address"); document.resform.email.focus(); return false}
else if (theat==-1){alert ("Your Email is missing an \"@\" sign"); document.resform.email.focus(); return false}

if (occasion==0){alert ("What is the occasion for this request?"); document.resform.occasion.focus(); return false;}
if (limo1==0){alert ("Please select at least 1 limousine."); document.resform.limo1.focus(); return false;}
if (hours1==0){alert ("How many hours will you need limousine type 1 for?"); document.resform.hours1.focus(); return false;}

var month=thisform.month.options[thisform.month.selectedIndex].text;
var day=thisform.day.options[thisform.day.selectedIndex].text;
var year=thisform.year.options[thisform.year.selectedIndex].text;

if (month=="Month"){alert("Please select a month for your pickup."); document.resform.month.focus(); return false;}
if (day=="Day"){alert("Please select a day for your pickup."); document.resform.day.focus(); return false;}

var hour=thisform.hour.options[thisform.hour.selectedIndex].text;
var minute=thisform.minute.options[thisform.minute.selectedIndex].text;
var ampm=thisform.ampm.options[thisform.ampm.selectedIndex].text;


if (hour=="Hour"){alert("Please select an hour for your pickup."); document.resform.hour.focus(); return false;}

thisform.datentime.value=month+" "+day+", "+year+" "+hour+":"+minute+":00 "+ampm;
var tripdate=month+" "+day+", "+year+" "+hour+":"+minute+":00 "+ampm;
tripdate=new Date(tripdate);
tripdate=tripdate.getTime();

var today=new Date();
var present=today.getTime();
var twodayslater =new Date(present+172800000);

twodayslater=twodayslater.getTime();

if (tripdate<present){
alert("The date you entered has already passed."); document.resform.month.focus(); return false;}
else if (tripdate<twodayslater){alert("It appears that the date and time you've selected is less than 48 hours from now. Therefore, to ensure that your request is processed in time, please call our offices at 877-7MONTEGO from the US, or 888-991-4519 from Jamaica."); document.resform.month.focus(); return false;}


var pickup=thisform.pickup.value;
var dropoff=thisform.dropoff.value;

if ((pickup=="")||(pickup.length<3)||(pickup==" ")){alert("Please enter the address or specify a location name for your pickup."); document.resform.pickup.focus();  return false}
if ((dropoff=="")||(dropoff.length<3)||(pickup==" ")){alert("Please enter the address or specify a location name for your drop off."); document.resform.dropoff.focus();  return false}

var cardnumber=thisform.cardnumber.value
var cardtype=thisform.cardtype.selectedIndex
var expmonth=thisform.expmonth.selectedIndex
var expyear=thisform.expyear.selectedIndex
var billingaddress=thisform.billingaddress.value

if (cardnumber==""){alert ("Please enter the \"credit card number\" you want to use to pay for your trip.");document.resform.cardnumber.focus(); return false}

else if (isNaN(cardnumber)){alert ("Please enter a valid \"credit card number\" to pay for your trip."); document.resform.cardnumber.focus(); return false}

if (cardtype==0){if (cardnumber.length!=15) {alert ("Please ensure that you entered the correct amount of numbers for the card type you selected. Enter no spaces."); return false} else if (cardnumber.charAt(0)!=3){alert ("The number you entered does not match the card type you selected"); return false}}

if (cardtype==1){if (cardnumber.length!=16) {alert ("Please ensure that you entered the correct amount of numbers for the card type you selected. Enter no spaces."); return false} else if (cardnumber.charAt(0)!=5){alert ("The number you entered does not match the card type you selected"); return false}}

if (cardtype==2){if (cardnumber.length!=16) {alert ("Please ensure that you entered the correct amount of numbers for the card type you selected. Enter no spaces."); return false} else if (cardnumber.charAt(0)!=4){alert ("The number you entered does not match the card type you selected"); return false}}

if (expmonth==0){alert ("Please select your card's expiration month"); document.resform.expmonth.focus(); return false}
if (expyear==0){alert ("Please select your card's expiration year"); document.resform.expyear.focus(); return false}
if (billingaddress==""){alert ("Please enter the credit card's billing address.");document.resform.billingaddress.focus(); return false}
if (billingaddress.length<5){alert ("Please enter the credit card's billing address.");document.resform.billingaddress.focus(); return false}


if (thisform.cancellationpolicy.checked==false){alert ("You must \"read and agree\" to the terms and conditions of our \"cancellation policy\" in order to complete your reservation."); return false}


return true
}

function test(){
tripdate=document.form1.date.value;
tripdate=new Date(tripdate);
tripdate=tripdate.getTime();
var today=new Date();
var present=today.getTime();
var tomorrow =new Date(present+86400000);

tomorrow=tomorrow.getTime();

if (tripdate<present){
alert("The date you entered has already passed.");}
else if (tripdate<tomorrow){alert("Internet reservations must be made at least 24 hours in advance.");}
else alert("OK");


}

function doDisable(){
	if(document.resform.q2.selectedIndex==0){document.resform.limo2.disabled=true; document.resform.hours2.disabled=true; document.resform.limo2.options[0].selected=true; document.resform.hours2.options[0].selected=true;}
	else if (document.resform.q2.selectedIndex!=0){document.resform.limo2.disabled=false; document.resform.hours2.disabled=false;};
	
	if(document.resform.q3.selectedIndex==0){document.resform.limo3.disabled=true; document.resform.hours3.disabled=true; document.resform.limo3.options[0].selected=true; document.resform.hours3.options[0].selected=true;}
	else if (document.resform.q2.selectedIndex!=0){document.resform.limo3.disabled=false; document.resform.hours3.disabled=false;};

	}
	
