function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }		 		

 		 return true					
	}


// 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 = 7;

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 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 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){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("-")!=-1)bracket=bracket+1
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
var brchr=strPhone.indexOf("(")
if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function checkform(doc,code_length) 
{	
	
	if (doc.name.value==null || doc.name.value=="")
    {
	    alert("Please fill the information with your name");
	    return false;
    }
    if ((doc.from.value==null || doc.from.value=="") && (doc.phone.value==null || doc.phone.value==""))
    {
	    alert("Please fill the information with your email or telephone");
	    return false;
    }
    if (doc.from.value!=null && doc.from.value!="")
    {
	    if(echeck(doc.from.value)==false)
	    {
		    return false;
	    }
    }
    if (doc.phone.value!=null && doc.phone.value!="")
    {
	    if(checkInternationalPhone(doc.phone.value)==false)
	    {
		    alert("Please enter a valid phone number");
		    return false;
	    }
    }                
       
    if (doc.adult.value!=null && doc.adult.value!="")
    {
	    if(isInteger(trim(doc.adult.value))==false)
	    {
		    alert("Please enter roman character for number of adults");
		    return false;
	    }	    
    }            
    if (doc.children.value!=null && doc.children.value!="")
    {
	    if(isInteger(trim(doc.children.value))==false)
	    {
		    alert("Please enter romain character for number of children");
		    return false;
	    }
    }            
    if (doc.dayin.value==null || doc.dayin.value=="")
    {
	    alert("Please fill the CheckIn Date");
	    return false;
    }
    
    Date.prototype.toMMDDYYYYString = function () {return isNaN (this) ? 'NaN' : [this.getDate() > 9 ? this.getDate() : '0' + this.getDate(), this.getMonth() > 8 ? this.getMonth() + 1 : '0' + (this.getMonth() + 1), this.getFullYear()].join('/')}
    var today_date = (new Date().toMMDDYYYYString());        
    if (compareDates(today_date,'dd/MM/yyyy',doc.dayin.value,'dd/MM/yyyy')==1)
    {
        alert("CechkIn day "+ doc.dayin.value+" already past, today: "+today_date);
	    //alert("CechkIn day is already in the past, today: "+today_date);
	    return false;
    }                      
    if (doc.dayout.value==null || doc.dayin.value=="")
    {
	    alert("Please fill the CheckOut Date");
	    return false;
    }                
    if (isDate(doc.dayin.value,'dd/MM/yyyy')==false)
    {
	    alert("CheckIn date is not a valid date");
	    return false;
    }          
    if (isDate(doc.dayout.value,'dd/MM/yyyy')==false)
    {
	    alert("CheckOut date is not a valid date");
	    return false;
    }              
    if (doc.dayin.value == doc.dayout.value)
    {
	    alert("CheckIn date is same as CheckOut date ?");
	    return false;
    }
    if (compareDates(doc.dayin.value,'dd/MM/yyyy',doc.dayout.value,'dd/MM/yyyy')==1)
    {
	    alert("CheckIn date is greater than CheckOut date ?");
	    return false;
    }     
    if (doc.vcode.value==null || doc.vcode.value=="")
    {
	    alert("Please enter verification code inorder to proceed");
	    return false;
    }   
    
    if (doc.vcode.value.length != code_length || isInteger(trim(doc.vcode.value))==false )
    {
	    
	    alert("Please double check verification code you entered is correct");
	    return false;
    }
    return true;	
}

function checkform_gbook(doc)
{
	
	
	if (doc.name1.value == null || doc.name1.value=="")
	{
		alert("Please enter your name");
		return false;
	}
	if (doc.body1.value == null || doc.body1.value=="")
	{
		alert("Please enter comments before click submit");
		return false;
	}
	
	return true;
	
}


/*
http://www.smartwebby.com/DHTML/phone_no_validation.asp
http://www.smartwebby.com/DHTML/email_validation.asp
function ValidateForm(){
	var Phone=document.frmSample.txtPhone
	
	if ((Phone.value==null)||(Phone.value=="")){
		alert("Please Enter your Phone Number")
		Phone.focus()
		return false
	}
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please Enter a Valid Phone Number")
		Phone.value=""
		Phone.focus()
		return false
	}
	return true
 } 
*/

/*
function isDate(val,format) {
	var date=getDateFromFormat(val,format);
	if (date==0) { return false; }
	return true;
	}
http://www.yourhtmlsource.com/javascript/formvalidation.html
http://www.isolani.co.uk/articles/simpleJavascriptAndForms.html

 function validate(f) {
  if(f.q.value=="") {
   return false;
  }
  return true;
 }
*/	
