// JavaScript Document

/***********************************************************************************

*	(c) Firecast Web Solutions 2003 version 1.01 28 February 2003	          *

*	For info write to info@firecast.co.uk		          *

*	You may remove all comments for faster loading	          *		

***********************************************************************************/

function validateForm(form)

{ 

// beacuse the date is passed in as a string  it needs to be converted to a date data type. 
// there is no simple way to do this in javascript so the following method should be used.

//get form variables for dates
var datevalue1=form.sel_arrival_date.value;
var datevalue2=form.sel_departure_date.value;

//cut the arrival variables into composit parts
//note this is working with the date format DD/MM/YYY
var day1=datevalue1.substring(0,2);
var month1=datevalue1.substring(3,5);
var year1=datevalue1.substring(6,10);
//cut the depart variables into composit parts
//note this is working with the date format DD/MM/YYY
var day2=datevalue2.substring(0,2);
var month2=datevalue2.substring(3,5);
var year2=datevalue2.substring(6,10);

//month1=changeFormatStringtoNumber(month1);
//month2=changeFormatStringtoNumber(month2);

//create the usable date variables from the compiste parts created above
var dateArrival=new Date(year1,month1-1,day1);
var dateDepart=new Date(year2,month2-1,day2);


	if (form.sel_property_refernce.value == "")

	{ 

	   alert("Please select a property name."); 

	   form.sel_property_refernce.focus( ); 

	   return false; 

	}

//now compare date variables for validation, stop a later arrivle date than depateure date being selected
	else if ((dateArrival >= dateDepart))

	{ 

	   alert("Your arival date cannot be set later than or the same as your departure date."); 
	   return false; 

	}

	else if (form.sel_how_heard.value == "")

	{ 

	   alert("Please tell us how you heard about the site."); 

	   form.sel_how_heard.focus( ); 

	   return false; 

	}
	else if (form.txt_name.value == "")

	{ 

	   alert("Please tell enter your name."); 

	   form.txt_name.focus( ); 

	   return false; 

	}
	else if ((form.txt_email.value==null)||(form.txt_email.value=="")){

		alert("Please enter your Email address")

		form.txt_email.focus()

		return false

	}

	else if (echeck(form.txt_email.value)==false){

		form.txt_email.value=""

		form.txt_email.focus()

		return false

	}
	

}



//email validation function, called from within above validateForm function

function echeck(str) {



		var at="@"

		var dot="."

		var lat=str.indexOf(at)

		var lstr=str.length

		var ldot=str.indexOf(dot)

		if (str.indexOf(at)==-1){

		   alert("The E-mail that you have entered is not valid")

		   return false

		}



		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){

		   alert("The E-mail that you have entered is not valid")

		   return false

		}



		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){

		    alert("The E-mail that you have entered is not valid")

		    return false

		}



		 if (str.indexOf(at,(lat+1))!=-1){

		    alert("The E-mail that you have entered is not valid")

		    return false

		 }



		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){

		    alert("The E-mail that you have entered is not valid")

		    return false

		 }



		 if (str.indexOf(dot,(lat+2))==-1){

		    alert("The E-mail that you have entered is not valid")

		    return false

		 }

		

		 if (str.indexOf(" ")!=-1){

		    alert("The E-mail that you have entered is not valid")

		    return false

		 }



 		 return true					

	}

function changeFormatStringtoNumber(monthval){
if(monthval=="JAN"){
monthval=0;
}
else if (monthval=="FEB") {
monthval=1;
}
else if (monthval=="MAR") {
monthval=2;
}
else if (monthval=="APR") {
monthval=3;
}
else if (monthval=="MAY") {
monthval=4; 
}
else if (monthval=="JUN") {
monthval=5; 
}
else if (monthval=="JUL") {
monthval=6; 
}
else if (monthval=="AUG") {
monthval=7;  
}
else if (monthval=="SEP") {
monthval=8;  
}
else if (monthval=="OCT") {
monthval=9; 
}
else if (monthval=="NOV") {
monthval=10; 
}
else if (monthval=="DEC") {
monthval=11; 
}
return(monthval);
}
