// JavaScript Document
// Common functions

function externalLinks() { 
if (!document.getElementsByTagName) return; 
var anchors = document.getElementsByTagName("a"); 
for (var i=0; i<anchors.length; i++) { 
	var anchor = anchors[i]; 
	if (anchor.getAttribute("href") && 
		anchor.getAttribute("rel") == "_blank") 
		anchor.target = "_blank"; 
	} 
} 

// Preload Images
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

// Open Pop-up Window
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// Validate Car Rental Reservation Form (rental-form.php)
function ValidateReservation(Form)
{	
  if ((Form.crr01a.value == "") && (Form.crr02a.value == "") && 
      (Form.crr01b.value == "") && (Form.crr02b.value == "") && 
      (Form.crr01c.value == "") && (Form.crr02c.value == ""))
  {
    alert("Please choose a Vehicle");
    Form.crr01a.focus();
    return (false);
 
  }
  
  if ((Form.crr01a.value == "") && (Form.crr01b.value == "") && (Form.crr01c.value == ""))
  {
    alert("Please choose a Vehicle");
    Form.crr01a.focus();
    return (false);
 
  }

  if ((Form.crr01a.value != "") || (Form.crr02a.value != ""))
  {
     if ((Form.crr01b.value != "") || (Form.crr02b.value != "") || 
         (Form.crr01c.value != "") || (Form.crr02c.value != ""))
     {
	alert("Please only choose vehicles from the same insurance category");
    	Form.crr01b.focus();
    	return (false);
     }
  }

  if ((Form.crr01b.value != "") || (Form.crr02b.value != ""))
  {
     if ((Form.crr01c.value != "") || (Form.crr02c.value != ""))
     {
	alert("Please only choose vehicles from the same insurance category");
    	Form.crr01a.focus();
    	return (false);
     }
  }
    
  if (Form.crr06.value == "")
  {
    alert("Please enter the date you want the vehicle");
    Form.crr06.focus();
    return (false);
  }
  
  if (Form.crr07.value == "")
  {
    alert("Please enter the month in which you want the vehicle");
    Form.crr07.focus();
    return (false);
  }
	
  if (Form.crr08.value == "")
  {
    alert("Please enter the year in which you want the vehicle");
    Form.crr08.focus();
    return (false);
  }
  
  if (Form.crr09.value == "")
  {
    alert("How many days do you want to hire the vehicle for");
    Form.crr09.focus();
    return (false);
  }
  
  var radioSelected = false;
  for (i = 0;  i < Form.crr09b.length;  i++)
    {
      if (Form.crr09b[i].checked)
          radioSelected = true;
  }
  if (!radioSelected)
    {
      alert("Please select a car delivery method");
      Form.crr09b[0].focus();
      return (false);
  }
  
  if (Form.crr09b[0].checked == true)
  {
     if (Form.crr10.value == "")
     {
	alert("Please indicate which airline you will be arriving on");
	Form.crr10.focus();
	return (false);
     }
     
     if (Form.crr11.value == "") 
     {
        alert("Where will you be flying from?");
        Form.crr11.focus();
        return (false);
     }
  }   
   
  if (Form.crr09b[1].checked == true)
  {
     if (Form.crr14.value == "")
     {
		alert("Please tell us where you want the vehicle delivering to");
		Form.crr14.focus();
		return (false);
     }
	 
	 if (Form.crr10.value != "")
	 {
	    alert("Please leave the Airline field blank when selecting delivery to your accommodation");
    	Form.crr10.focus();
    	return (false);
  	 }
  }  
  
  if (Form.crr09b[2].checked == true)
  {
     if (Form.crr10.value != "")
     {
		alert("Please leave the Airline field blank when specifying that you will collect the vehicle");
		Form.crr10.focus();
		return (false);
     }
	 
	 if (Form.crr14.value != "")
	 {
	    alert("Please leave the Hotel/Villa name blank when specifying that you will collect the car");
    	Form.crr14.focus();
    	return (false);
  	 }
  }  

  if ((Form.crr10.value == "3") && (Form.crr11.value == "POS") && (Form.crr12a.value == ""))
  {
	  alert("Please enter your Flight Number - this is vital in case of delay");
      Form.crr12a.focus();
   	  return (false);
  }
	  
  if (Form.crr16.value == "")
  {
    alert("Please enter the name of the person who will be driving the vehicle");
    Form.crr16.focus();
    return (false);
  }
  
  if (Form.crr17.value == "")
  {
    alert("Please enter the date of birth of the person who will be driving the vehicle");
    Form.crr17.focus();
    return (false);
  }
  
  if (Form.crr18.value == "")
  {
    alert("Please enter the month of birth of the person who will be driving the vehicle");
    Form.crr18.focus();
    return (false);
  }
  
  if (Form.crr19.value == "")
  {
    alert("Please enter the year of birth of the person who will be driving the vehicle");
    Form.crr19.focus();
    return (false);
  }
 
  if (Form.crr20.value == "")
  {
    alert("Please enter your licence number. If you want to enter licence details on arrival, enter 'on arrival'");
    Form.crr20.focus();
    return (false);
  }
  
  var v=Form.crr20.value;
  var y=v.toLowerCase(); 
  if ((y != "on arrival") && (y != "'on arrival'")) 
  {
  	  if (Form.crr24.value == "") 
  	  {
  		alert("Please enter the date your licence was issued");
    	Form.crr24.focus();
    	return (false);
  	  } 
  
  	  if (Form.crr25.value == "") 
   	  {
  		alert("Please enter the month your licence was issued");
    	Form.crr25.focus();
    	return (false);
  	  } 
  
  	 if (Form.crr26.value == "") 
  	  {
  		alert("Please enter the year your licence was issued");
    	Form.crr26.focus();
    	return (false);
  	  } 
  }
   
  if (Form.crr50.value == "")
  {
    alert("Please enter the first name of the person hiring the vehicle");
    Form.crr50.focus();
    return (false);
  }
  
  if (Form.crr51.value == "")
  {
    alert("Please enter the family name (surname) of the person hiring the vehicle");
    Form.crr51.focus();
    return (false);
  }
  
  if (Form.crr52.value == "")
  {
    alert("Please enter your address");
    Form.crr52.focus();
    return (false);
  }
  
  if (Form.crr54.value == "")
  {
    alert("Please enter the City or Town where you live");
    Form.crr54.focus();
    return (false);
  }
  
  if (Form.crr56.value == "Error")
  {
    alert("Please state the country of the above address");
    Form.crr56.focus();
    return (false);
  }
  
  if (Form.crr61.value == "")
  {
    alert("Please enter your email address");
    Form.crr61.focus();
    return (false);
  }
 
  var first, last, x;
  y = Form.crr61.value;
  if (y.indexOf(" ") != -1) { x = "X"; }
  if (y.indexOf(".@") != -1) { x = "X"; }
  if (y.indexOf("@.") != -1) { x = "X"; }
  if (y.indexOf(".") == y.length-1) { x = "X"; }
  first = y.indexOf("@");
  if (first == -1 || first == 0) { x = "X"; }
  if (first != y.lastIndexOf("@")) { x = "X"; }
  if (y.lastIndexOf(".") != -1 && (y.length - y.lastIndexOf(".")) < 6) { x = ""; } else { x = "X"; }
  if (x == "X")
  {
	alert("You appear to have entered an invalid email address");
    Form.crr61.focus();
    return (false);
  }
  
  if (Form.crr62.value == "")
  {
    alert("Please confirm your email address");
    Form.crr62.focus();
    return (false);
  }
  
  if (Form.crr61.value != Form.crr62.value)
  {
    alert("The address in the Email Confirmation box is not the same as in the Email field");
    Form.crr62.focus();
    return (false);
  }
  
  if (Form.crr63.value == "")
  {
     alert("Please tell us where you will be staying on Tobago (your privacy will be respected)");
     Form.crr63.focus();
     return (false);
  }
  
  if (Form.crr67.checked == false)
  {   
      alert("Please confirm acceptance of our Terms & Conditions");
      Form.crr67.focus();
      return (false);
  }
 
  return (true);  

}

// Validate General Enquiry Form (enquiry.php)
function ValidateEnquiries(Form)
{
  if ((Form.enq01.value == "") && (Form.enq02.value == "") && (Form.enq03.value == "") &&
	  (Form.enq04.value == "") && (Form.enq05.value == "") && (Form.enq06.value == "") &&
	  (Form.enq07.value == "") && (Form.enq08.value == "") && (Form.enq09.value == "") &&
	  (Form.enq10.value == "") && (Form.enq11.value == "") && (Form.enq12.value == "") && 
	  (Form.enq13.value == "") && (Form.enq14.value == "") && (Form.enq15.checked == false) && 
	  (Form.enq17.checked == false) && (Form.enq18.checked == false) && (Form.enq19.checked == false) && 
	  (Form.enq20.value == "") && (Form.enq21.checked == false) && (Form.enq22.checked == false) && 
	  (Form.enq23.checked == false) && (Form.enq24.checked == false) && (Form.enq25.checked == false) && 
	  (Form.enq26.checked == false) && (Form.enq27.value == "") &&  (Form.enq29.value == "") && 
	  (Form.enq32.value == "") && (Form.enq33.value == ""))													
  {
    alert("You do not appear to have completed any fields of the form");
    Form.enq01.focus();
    return (false);
  }	
  	
  if (Form.enq04.value == "")
  {
    alert("Please tell us when you will be coming to Tobago");
    Form.enq04.focus();
    return (false);
  }
  
  if (Form.enq05.value == "")
  {
    alert("Please enter the month of arrival");
    Form.enq05.focus();
    return (false);
  }
	
  if (Form.enq06.value == "")
  {
    alert("Please enter the year of arrival");
    Form.enq06.focus();
    return (false);
  }
 
  if (Form.enq07.value == "")
  {
    alert("Please tell us when you will be leaving Tobago");
    Form.enq07.focus();
    return (false);
  }
  
  if (Form.enq08.value == "")
  {
    alert("Please enter the month of departure");
    Form.enq08.focus();
    return (false);
  }
	
  if (Form.enq09.value == "")
  {
    alert("Please enter the year of departure");
    Form.enq09.focus();
    return (false);
  }
 
  var a = Form.enq06.value + Form.enq05.value + Form.enq04.value;
  var b = Form.enq09.value + Form.enq08.value + Form.enq07.value;
  var c = b - a;
  if (c < 0) {
  	alert ("Sorry: you appear to be leaving Tobago before you have arrived");
	Form.enq07.focus();
  	return (false);
  }
 
  if ((Form.enq11.value != "") && (Form.enq12.value != ""))
  {
    alert("Please select either a Featured Property or enter the name of a property, but not both");
    Form.enq12.focus();
    return (false);
  }
  
  if ((Form.enq10.value == "") && (Form.enq11.value == "") && (Form.enq12.value == "") &&
  	  (Form.enq13.value == "") && (Form.enq14.value == "") && (Form.enq15.checked == false) &&
  	  (Form.enq17.checked == false) && (Form.enq18.checked == false) && (Form.enq19.checked == false) &&
  	  (Form.enq20.value == "") && (Form.enq21.checked == false) && (Form.enq22.checked == false) && 
  	  (Form.enq23.checked == false)  && (Form.enq24.checked == false) && (Form.enq25.checked == false) && 
  	  (Form.enq25b.checked == false) && (Form.enq26.checked == false) && (Form.enq38.checked == false) && 		
  	  (Form.enq39.checked == false)  && (Form.enq40.checked == false) && (Form.enq41.checked == false) && 	
	  (Form.enq42.checked == false)  && (Form.enq43.checked == false) && (Form.enq44.checked == false) && 
	  (Form.enq45.checked == false)  && (Form.enq51.checked == false) && (Form.enq52.checked == false) && 
	  (Form.enq53.checked == false)  && (Form.enq54.checked == false) && (Form.enq55.checked == false) && 
	  (Form.enq58.checked == false)  && (Form.enq59.checked == false) && (Form.enq60.checked == false) && 
	  (Form.enq61.checked == false))
  {
    alert("You do not appear to have enquired about anything");
    Form.enq10.focus();
    return (false);
  }	

  if (Form.enq29.value == "")
  {
    alert("Please tell us your first name");
    Form.enq29.focus();
    return (false);
  }

  if (Form.enq30.value == "")
  {
    alert("Please tell us your family name (surname)");
    Form.enq30.focus();
    return (false);
  }
  
  if (Form.enq31.value == "Error")
  {
    alert("Please tell us where you are from");
    Form.enq31.focus();
    return (false);
  }

  if (Form.enq32.value == "")
  {
    alert("Please enter your email address");
    Form.enq32.focus();
    return (false);
  }

  var first, last, x;
  y = Form.enq32.value;
  if (y.indexOf(" ") != -1) { x = "X"; }
  if (y.indexOf(".@") != -1) { x = "X"; }
  if (y.indexOf("@.") != -1) { x = "X"; }
  if (y.indexOf(".") == y.length-1) { x = "X"; }
  first = y.indexOf("@");
  if (first == -1 || first == 0) { x = "X"; }
  if (first != y.lastIndexOf("@")) { x = "X"; }
  if (y.lastIndexOf(".") != -1 && (y.length - y.lastIndexOf(".")) < 6) { x = ""; } else { x = "X"; }
  if (x == "X")
  {
	alert("You appear to have entered an invalid email address");
    Form.enq32.focus();
    return (false);
  }
  
  if (Form.enq33.value == "")
  {
    alert("Please confirm your email address");
    Form.enq33.focus();
    return (false);
  }
  
  if (Form.enq32.value != Form.enq33.value)
  {
    alert("The address in the Email Confirmation box is not the same as in the Email field");
    Form.enq33.focus();
    return (false);
  }
  
  return (true);  

}
