// JavaScript Document

//global variable for error flag
var errfound = false;

//function to validate by length
function ValidLength(item, len) {
   return (item.length >= len);
}

//function to validate an email address
function ValidEmail(item) {
   if (!ValidLength(item, 5)) return false;
   if (item.indexOf ('@', 0) == -1) return false;
   return true;
}

// display an error alert
function error(elem, text) {
// abort if we already found an error
   if (errfound) return;
   window.alert(text);
   elem.select();
   elem.focus();
   errfound = true;
}

// main validation function
function Validate() {
   var temp = "";
   var flag=0;
   temp="*** Please Enter The Following ***\n\n";
   errfound = false;
   if (!ValidLength(document.booking.vehicle.value,1))
   {
     temp = temp + "Please Enter Your Type of Vehicle    \n";
	 flag=1;
   }
   if (!ValidLength(document.booking.name.value,1))
   {
     temp = temp + "Please Enter Your Name    \n";
	 flag=1;
   }
   if (!ValidLength(document.booking.phone.value,1) && !ValidLength(document.booking.phone_bh.value,1))
   {
     temp = temp + "Please Enter Your Phone Number    \n";
	 flag=1;
   }
   if (!ValidLength(document.booking.email.value,1))
   {
     temp = temp + "Please Enter Your Email Address    \n";
	 flag=1;
   }
   
   if (flag==1)
     error(document.booking.vehicle, temp);
   
   return !errfound; /* true if there are no errors */
}
