// JavaScript Document
function allfieldsvalidation()
{
    var msg="";
	var name=document.book.name.value; 
	var stay=document.book.stay.value; 
	var date=document.book.date.value; 
	var comments=document.book.comments.value; 
    var mobile=document.book.mobile.value;
	var mobile2=check_mobile(mobile,"Please enter the valid Phone Number");
	var email=document.book.email.value;
    var email2=checkemail(email,"Email Id seems to be incorrect");
	if(name=='')
    {
	msg+="Please enter the Name\n";
	
	}
	if(email=="")
	{
	msg+="Please enter the Email\n";
	
	}
	else if(email2!="")
	{
	alert(email2);
	return false;
	}
	if(mobile=="")
	{
	msg+="Please enter the Phone Number\n";
	
	}
	else if(mobile2!="")
	{
	alert(mobile2);
	return false;
	}
	if(stay=='')
    {
	msg+="Please enter the Length Of Stay\n";
	
	}
	if(date=='')
    {
	msg+="Please select the Date\n";
	
	}
	if(comments=='')
    {
	msg+="Please enter the Comments";
	
	}
	if(msg!="")
	{
		alert(msg);
		return false;
	}
	else
	{
		document.book.submit();
	    return true;
	}
}
//for email
function checkemail(x,y)
{
if(x==0)
return y;
else
return IsEmailValid(x);
}
function IsEmailValid(formObj)
{
var emailStr=formObj
var emailPat=/^(.+)@(.+)$/
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
var validChars="\[^\\s" + specialChars + "\]"
var quotedUser="(\"[^\"]*\")"
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
var atom=validChars + '+'
var word="(" + atom + "|" + quotedUser + ")"
var userPat=new RegExp("^" + word + "(\\." + word+ ")*$")
var domainPat=new RegExp("^" + atom + "(\\." +atom +")*$")
var matchArray=emailStr.match(emailPat)
	if (matchArray==null)
	{
	return "Email address seems incorrect (check@ and .'s).\n"
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	
	// See if "user" is valid
	if (user.match(userPat)==null)
	{
	// user is not valid
	return "The username doesn't seem to be valid.\n"
	
	}
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null)
	{
	// this is an IP address
	for (var i=1;i<=4;i++)
	{
	if (IPArray[i]>255)
	{
	return "Destination IP address appears to be invalid!\n"
	
	}
	}

}
var domainArray=domain.match(domainPat)
if (domainArray==null)
{
return "The domain name doesn't appear to be valid.\n"

}
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3)
{
// the address must end in a two letter or three letter word.
return "The address must end in a three-letter domain, or two letter country.\n"

}
// Make sure there's a host name preceding the domain.
if (len<2)
{
var errStr="This address is missing a hostname!\n"
return errStr
}
// If we've gotten this far, everything looks great!
return "";
}
function check_mobile(x,y)
{
	
	if(x=="")
		return y;
	else
	{
		chk=x.charAt(0);
		start2=x.substr(0,2);
		snd=x.substr(1,1);
		trd=x.substr(2,1);
		len=x.length;
		
		
		if(len==12)
		{
			if(start2!=91)
				return y;
				
			if(trd!=9 && trd!=8 && trd!=7)
			{
				return y;
			}
		}
		else if(len==11)
		{
			if(chk!=0)
				return y;
			
			if(snd!=9 && snd!=8 && snd!=7)
			{
				return y;
			}
		}
		else if(len==10)
		{
			if(chk!=9 && chk!=8 && chk!=7)
			{
				return y;
			}
			
		}
		else
		{
			return y;
		}
		
		return "";
		
	}
}



