// TRIM THE INPUT FIELDS FOR SPACES

function trim(s)
{
   var temp = s;
   return temp.replace(/^\s+/,'').replace(/\s+$/,'');
}
function validate_emailaddress(arg){
	var str = arg;
	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
	if (!reg1.test(str) && reg2.test(str)) { // if syntax is valid
	   return true;
	}
	else{
		return false;
	}
}
function IsNumber(source)
{
  var ValidChars = "0123456789";
  var Char;  
  for (i = 0; i < source.length; i++) 
  { 
    Char = source.charAt(i); 
    if (ValidChars.indexOf(Char) == -1){
     return false;
    }
  }
  return true;
}
function IsCharacter(source)
{
	var ValidChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";
	var Char;
	for (i=0; i < source.length; i++)
	{
		Char = source.charAt(i);
		if (ValidChars.indexOf(Char) == -1) {
			return false;
		}
	}
	return true;
}

//validate owner regsitration
function validate_enquiry(frm){
	
	if(trim(frm.contact_email.value) == "") {
		alert("Please enter the Email address!!!");
		frm.contact_email.focus();
		frm.contact_email.value = "";
		return false;
	}
	else{
		if(!validate_emailaddress(frm.contact_email.value)){
			alert("Please enter a valid email address");
			frm.contact_email.focus();
			return false;
		}
	}
	if(trim(frm.firstname.value) == "") {
		alert("Please enter the Firstname!!!");
		frm.firstname.focus();
		frm.firstname.value = "";
		return false;
	}else{
		if(!IsCharacter(trim(frm.firstname.value))){
			alert("Please Enter Only Character!!!");
			frm.firstname.focus();
			frm.firstname.value = "";
			return false;
		}
	}
	/*
	if(trim(frm.NameLast.value) == "") {
		alert("Please enter the Lastname!!!");
		frm.NameLast.focus();
		frm.NameLast.value = "";
		return false;
	}else{
		if(!IsCharacter(trim(frm.NameLast.value))){
			alert("Please Enter Only Character!!!");
			frm.NameLast.focus();
			frm.NameLast.value = "";
			return false;
		}
	}
	*/
	
	/*
	if(trim(frm.phone.value) == "")
	{
		alert("Please enter the Phone Number!!!");
		frm.phone.focus();
		frm.phone.value = "";
		return false;
	}
	else{
		if(!IsNumber(frm.phone.value)){
			alert('Please Enter The Numeric Values In Phone \n');
			frm.phone.focus();
			return false;
		}
	}
	*/
	if(trim(frm.contact_tel.value) != ""){
	if(!IsNumber(frm.contact_tel.value)){
			alert('Please Enter The Numeric Values In Phone \n');
			frm.contact_tel.focus();
			return false;
		}
	}
	/*
	if(trim(frm.Adults.value) == "")
	{
		alert("Please enter the No Of Adults!!!");
		frm.Adults.focus();
		frm.Adults.value = "";
		return false;
	}
	else{
		if(!IsNumber(frm.Adults.value)){
			alert('Please Enter The Numeric Values In No Of Adults \n');
			frm.Adults.focus();
			return false;
		}
	}
	if(trim(frm.Children.value) == "")
	{
		alert("Please enter the No Of Children!!!");
		frm.Children.focus();
		frm.Children.value = "";
		return false;
	}
	else{
		if(!IsNumber(frm.Children.value)){
			alert('Please Enter The Numeric Values In No Of Children \n');
			frm.Children.focus();
			return false;
		}
	}
	
	
	
	if(trim(frm.PriceMax.value) == "")
	{
		alert("Please enter the Max Price Range!!!");
		frm.PriceMax.focus();
		frm.PriceMax.value = "";
		return false;
	}	
	if(trim(frm.PriceMin.value) == "")
	{
		alert("Please enter the Min Price Range!!!");
		frm.PriceMin.focus();
		frm.PriceMin.value = "";
		return false;
	}
	
	if(frm.user_code.value != frm.security_code.value)
	{
		alert("Please enter the Correct Security Code!!!");
		frm.user_code.focus();
		frm.user_code.value = "";
		return false;
	}
	
	
	if(frm.FlightDateOut.value == "")
	{
		alert("Please select  Flight Date to Kerala!!!");
		return false;
	}
	
	if(frm.FlightDateRtn.value == "")
	{
		alert("Please select Flight Date Return !!!");
		return false;
	}
	
	if (frm.FlightDateOut.value > frm.FlightDateRtn.value)
	{
		alert("The 'Flight Date to Kerala' date should be lesser than the 'Flight Date Return' date!!!");
		return false;
	}
	*/
	if(trim(frm.user_code.value) == "") {
		alert("Please enter the Code!!!");
		frm.user_code.focus();
		frm.user_code.value = "";
		return false;
	}else{
		if(trim(frm.user_code.value) != frm.security_code.value){
			alert("Please Enter Correct Code!!!");
			frm.user_code.focus();
			frm.user_code.value = "";
			return false;
		}
	}
	return true;
}

