// JavaScript Document
var digits = "0123456789";
var phoneNumberDelimiters = "()- ";
var validWorldPhoneChars = phoneNumberDelimiters + "+";
var minDigitsInIPhoneNumber = 10;
function validation(theForm)
{
if(theForm.nametxt.value=="")
{
  alert("Please enter your name");
  theForm.nametxt.focus();
  return false;
}
if(theForm.addresstxt.value=="")
{
  alert("Please enter your address");
  theForm.addresstxt.focus();
  return false;
}
if(theForm.country.value=="")
{
  alert("Please select your country");
  theForm.country.focus();
  return false;
}
if(theForm.phone.value=="")
{
  alert("Please enter your phone number");
  theForm.phone.focus();
  return false;
}
if (checkInternationalPhone(theForm.phone.value)==false){
		alert("Please enter a valid phone number");
		theForm.phone.value="";
		theForm.phone.focus();
		return false;
	}
if(theForm.email.value=="")
	{
		alert("Please enter your email address");
		theForm.email.focus();
		return false;
	}
	if(!checkEmail(theForm))
	{
		alert("Invalid email address");
		theForm.email.focus();
		return false;
	}
	if(theForm.arrival.value=="")
{
  alert("Please select the arrival date");
  theForm.arrival.focus();
  return false;
}
if(theForm.departure.value=="")
{
  alert("Please select the departure date");
  theForm.departure.focus();
  return false;
}
if(theForm.roomcategory.value=="")
{
  alert("Please select the room category");
  theForm.roomcategory.focus();
  return false;
}
if(theForm.adults.value=="")
{
  alert("Please select no. of adults");
  theForm.adults.focus();
  return false;
}
if(theForm.children.value=="")
{
  alert("Please select no. of children");
  theForm.children.focus();
  return false;
}
if(theForm.message.value=="")
{
  alert("Please enter your message");
  theForm.message.focus();
  return false;
}	
	return true;
}
function checkEmail(theForm) 
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(theForm.email.value)){
		return (true)
	}
	return (false)
}
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++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}
function ResetForm(theform) 
{
theform.reset();
//theform.hdnValue.value=0;
return false;
}	