//validation of date field
			var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : dd/mm/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear){
		alert("Please enter a valid 4 digit year")
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}










function validate()
{

		var firstname=document.Reservations.FirstName.value;
		var lastname=document.Reservations.LastName.value;
		/*var title=document.Reservations.Title.value;
		var Organization=document.Reservations.Organization.value;*/
		var workphone=document.Reservations.WorkPhone.value;
	  /* var homephone=document.Reservations.HomePhone.value;*/
	   var email=document.Reservations.Email.value;
	     var accommodation=document.Reservations.Accommodation.value;
		 var passengers=document.Reservations.Pax.value;
		 var dt=document.Reservations.TourDate;
		 
		 
	
		
			
		 
					
		if(firstname=="")
			{
			
			//error=error+"\nInvalid Name";
			alert("Please enter your first name");
			document.Reservations.FirstName.focus();
			return false;
			
			}
			
		if(lastname=="")
			{
			
			//error=error+"\nInvalid Name";
			alert("Please enter your last name");
			document.Reservations.LastName.focus();
			return false;
			
			}
			
	/*	if(title=="")
			{
			
			//error=error+"\nInvalid Name";
			alert("Please enter the title");
			document.Reservations.Title.focus();
			return false;
			
			}
			
			if(Organization=="")
			{
			
			//error=error+"\nInvalid Name";
			alert("Please enter the organization name");
			document.Reservations.Organization.focus();
			return false;
			
			}*/
			
			
	if(workphone=="")
			{
			alert("Please enter phone no.");
			document.Reservations.WorkPhone.focus();
			return false;
			}
			
			var c;
		if(workphone.length <7)
		{
		alert("Invalid Phone No.Enter minimum 7 digits.");
		workphone="";
		document.Reservations.WorkPhone.focus();
		return false;
		}	
		for(var s=0;s<workphone.length;s++)
		{
			 c=workphone.charAt(s);
			 
			 if (c>0 || c<9)
				 {
				
				 }
				 else{
				 alert("Enter Valid Phone No.");
				 workphone="";
				 document.Reservations.WorkPhone.focus();
				 return false;
				 }
		}	
		

		
	
		
		/* if(homephone=="")
			{
			alert("Please enter phone no.");
			document.Reservations.HomePhone.focus();
			return false;
			}
		
		var d;
		if(homephone.length <7)
		{
		alert("Invalid Phone No.Enter minimum 7 digits.");
		homephone="";
		document.Reservations.HomePhone.focus();
		return false;
		}	
		for(var e=0;e<homephone.length;e++)
		{
			 d=homephone.charAt(e);
			 
			 if (d>0 || d<9)
				 {
				
				 }
				 else{
				 alert("Enter Valid Phone No.");
				 homephone="";
				 document.Reservations.HomePhone.focus();
				 return false;
				 }
		}	
		*/
			
			
		
		//email address validation
		if(email=="")
			{
			alert("Please enter Email ID");
			document.Reservations.Email.focus();
			return false;
			}
		if(email!="")
  {
 var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;


      if (filter.test(email))
        {

        }
       else
        {
        	alert("Your email address is not valid!");
        	document.Reservations.Email.focus();
			return false;
			
        }
  }
		
	
			
		if(accommodation=="")
			{
			
			//error=error+"\nInvalid Name";
			alert("Please enter your where will you be staying.");
			document.Reservations.Accommodation.focus();
			return false;
			
			}
			
			if(passengers=="")
			{
			
			//error=error+"\nInvalid Name";
			alert("Please enter number of passengers field.");
			document.Reservations.Pax.focus();
			return false;
			
			}
			
			for(var p=0;p<passengers.length;p++)
		{
			 v=passengers.charAt(p);
			 
			 if (v>0 || v<9)
				 {
				
				 }
				 else{
				 alert("Enter Valid data.Only numbers allowed.");
				 passengers="";
				 document.Reservations.Pax.focus();
				 return false;
				 }
		}	
		
		
		
		if(dt.value=="")
			{
			alert("Please enter the date.");
			dt.focus();
			return false;
			
			}
			
			
			 if (isDate(dt.value)==false){
		dt.focus();
		return false;
	}
   
			
			
}


function validate_2()
{
	var firstname=document.Enquiries.FirstName.value;
		var lastname=document.Enquiries.LastName.value;
		//var title=document.Enquiries.Title.value;
	//	var Organization=document.Enquiries.Organization.value;
		var workphone=document.Enquiries.WorkPhone.value;
	 //  var homephone=document.Enquiries.HomePhone.value;
	   var email=document.Enquiries.Email.value;
	   
	   
	   				
		if(firstname=="")
			{
			
			//error=error+"\nInvalid Name";
			alert("Please enter your first name");
			document.Enquiries.FirstName.focus();
			return false;
			
			}
			
		if(lastname=="")
			{
			
			//error=error+"\nInvalid Name";
			alert("Please enter your last name");
			document.Enquiries.LastName.focus();
			return false;
			
			}
			
	/*	if(title=="")
			{
			
			//error=error+"\nInvalid Name";
			alert("Please enter the title");
			document.Enquiries.Title.focus();
			return false;
			
			}
			
			if(Organization=="")
			{
			
			//error=error+"\nInvalid Name";
			alert("Please enter the organization name");
			document.Enquiries.Organization.focus();
			return false;
			
			}*/
			
			
			if(workphone=="")
			{
			alert("Please enter phone no.");
			document.Enquiries.WorkPhone.focus();
			return false;
			}
		

		
		var c;
		if(workphone.length <7)
		{
		alert("Invalid Phone No.Enter minimum 7 digits.");
		workphone="";
		document.Enquiries.WorkPhone.focus();
		return false;
		}	
		for(var s=0;s<workphone.length;s++)
		{
			 c=workphone.charAt(s);
			 
			 if (c>0 || c<9)
				 {
				
				 }
				 else{
				 alert("Enter Valid Phone No.");
				 workphone="";
				 document.Enquiries.WorkPhone.focus();
				 return false;
				 }
		}	
		
		/* if(homephone=="")
			{
			alert("Please enter phone no.");
			document.Enquiries.HomePhone.focus();
			return false;
			}
		
		
		var d;
		if(homephone.length <7)
		{
		alert("Invalid Phone No.Enter minimum 7 digits.");
		homephone="";
		document.Enquiries.HomePhone.focus();
		return false;
		}	
		for(var e=0;e<homephone.length;e++)
		{
			 d=homephone.charAt(e);
			 
			 if (d>0 || d<9)
				 {
				
				 }
				 else{
				 alert("Enter Valid Phone No.");
				 homephone="";
				 document.Enquiries.HomePhone.focus();
				 return false;
				 }
		}	
			*/
			
		
		//email address validation
		if(email=="")
			{
			alert("Please enter Email ID");
			document.Enquiries.Email.focus();
			return false;
			}
		if(email!="")
  {
 var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;


      if (filter.test(email))
        {

        }
       else
        {
        	alert("Your email address is not valid!");
        	document.Enquiries.Email.focus();
			return false;
			
        }
  }
  
}
