// JavaScript Document

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 1;

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 trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
function checkInternationalPhone(strPhone){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf(")")==-1)return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}



function checkForm(formName)
{
	
	if(formName.fname.value == "")
	{
		alert ("Please Enter Your Name");
		formName.fname.focus();
		return false;
	}
	
	
	if(formName.sname.value == "")
	{
		alert ("Please Enter Your Surname");
		formName.sname.focus();
		return false;
	}
	
	
	if ((formName.phone.value == null) || (formName.phone.value == ""))
	{	
		alert ("Please Enter Your Telephone Number!");
		formName.phone.focus();
		return false;
	}
	if (checkInternationalPhone(formName.phone.value) == false)
	{	
		alert ("Please Enter a Valid Telephone Number!");
		formName.phone.focus();
		formName.phone.value = "";
		return false;
	}
	
	
	if ((formName.mobile.value == null) || (formName.mobile.value == ""))
	{	
		alert ("Please Enter Your Mobile Number!");
		formName.mobile.focus();
		return false;
	}
	if (checkInternationalPhone(formName.mobile.value) == false)
	{	
		alert ("Please Enter a Valid Mobile Number!");
		formName.mobile.focus();
		formName.mobile.value = "";
		return false;
	}
	
	
	if(formName.email.value == "")
	{
		alert ("Please Enter Your Email!");
		formName.email.focus();
		return false;
	}
	if (!formName.email.value.match(/^[\w\.-]+@(?:[A-Za-z0-9-]+\.)*[A-Za-z0-9-]{1,}\.[a-z]{2,9}$/))
	{
		alert ("Please Enter a Valid Email!");
		formName.email.focus();
		formName.email.value = "";
		return false;
	}
	
	
	if(formName.arrival.value == "" || formName.arrival.value == "yy-mm-dd")
	{
		alert ("Please Enter Your Date of Arrival");
		formName.arrival.focus();
		return false;
	}
	
	
	if(formName.departure.value == "" || formName.departure.value == "yy-mm-dd")
	{
		alert ("Please Enter Your Date of Departure");
		formName.departure.focus();
		return false;
	}
	
	
	if(formName.guests.value == "")
	{
		alert ("Please Enter the number of Guests");
		formName.guests.focus();
		return false;
	}
	
	
	return;
}



