// JavaScript Document

startList = function() {

	//code only for IE
	if(!document.body.currentStyle) return;
	var subs = document.getElementsByName('submenu');
	for(var i=0; i<subs.length; i++) {
		var li = subs[i].parentNode;
		if(li && li.lastChild.style) {
			li.onmouseover = function() {
				this.lastChild.style.visibility = 'visible';
			}
			li.onmouseout = function() {
				this.lastChild.style.visibility = 'hidden';
			}
		}
	}
}
window.onload=startList;

function contactemail()
{
	if(document.emailForm.name.value == "")
	{
	   alert("Please Enter Your Name");
	   document.emailForm.name.focus();
	   return false;
	}
	if(document.emailForm.email.value == "")
	{
	   alert("Please Enter Email Address");
	   document.emailForm.email.focus();
	   return false;
	}
	if (!validateEmail(document.emailForm.email.value,1,1)) 
	 	{
		 document.emailForm.email.focus();
		 return false;
		 }
  
	if(document.emailForm.subject.value == "")
	{
	   alert("Please Enter Subject");
	   document.emailForm.subject.focus();
	   return false;
	}
	if(document.emailForm.message.value == "")
	{
	   alert("Please Enter Message");
	   document.emailForm.message.focus();
	   return false;
	}
	if(document.emailForm.security_code.value == "")
	{
	   alert("Please Enter Security code");
	   document.emailForm.security_code.focus();
	   return false;
	}
	
	/*var codetext = document.emailForm.codetext.value;
	var security_code = document.emailForm.security_code.value;
		
	     if(security_code != codetext)
			 {
				 alert("Please verify confirm Security Code");
				 document.emailForm.security_code.focus();
				 return false;
			 }*/
			 
		
}

function reservation_validate()
{
	if(document.form_reserve.txtname.value == "")
	{
	   alert("Please Enter Your Name");
	   document.form_reserve.txtname.focus();
	   return false;
	}
	if(document.form_reserve.txtemail.value == "")
	{
	   alert("Please Enter Email Address");
	   document.form_reserve.txtemail.focus();
	   return false;
	}
	if (!validateEmail(document.form_reserve.txtemail.value,1,1)) 
	 	{
		 document.form_reserve.txtemail.focus();
		 return false;
		 }
   if(document.form_reserve.txtphone.value == "")
	{
	   alert("Please Enter Telephone Number");
	   document.form_reserve.txtphone.focus();
	   return false;
	}
	txtphone = document.form_reserve.txtphone;
	if (checkInternationalPhone(txtphone.value)==false){
		alert("Please Enter a Valid Phone Number")
		txtphone.value=""
		txtphone.focus()
		return false
	}
	 if(document.form_reserve.txtadate.value == "")
	{
	   alert("Please Enter Arrival Date");
	   document.form_reserve.txtadate.focus();
	   return false;
	}
	 if(document.form_reserve.txtddate.value == "")
	{
	   alert("Please Enter Departure Date");
	   document.form_reserve.txtddate.focus();
	   return false;
	}
	if(document.form_reserve.txtadate.value != "" && document.form_reserve.txtddate.value!="")
	if (!date_valid(document.form_reserve.txtadate.value,document.form_reserve.txtddate.value)) 
		{
				alert ("Please enter the Arrival date is less than the Departure date.");
				document.form_reserve.txtddate.value == "";
				document.form_reserve.txtddate.focus();
				return false;
		}

	 if(document.form_reserve.txtnchild.value == "")
	{
	   alert("Please Enter No of Child");
	   document.form_reserve.txtnchild.focus();
	   return false;
	}
	if(isNaN(document.form_reserve.txtnchild.value))
	{
	   alert("No of Children must be a numeric value");
	   document.form_reserve.txtnchild.focus();
	   return false;
	}
	 if(document.form_reserve.txtachild.value == "")
	{
	   alert("Please Enter Ages of Children");
	   document.form_reserve.txtachild.focus();
	   return false;
	}
	if(isNaN(document.form_reserve.txtachild.value))
	{
	   alert("Ages of Children must be a numeric value");
	   document.form_reserve.txtachild.focus();
	   return false;
	}
	 if(document.form_reserve.txtna.value == "")
	{
	   alert("Please Enter No of Adults");
	   document.form_reserve.txtna.focus();
	   return false;
	}
	if(isNaN(document.form_reserve.txtna.value))
	{
	   alert("No of Adults must be a numeric value");
	   document.form_reserve.txtna.focus();
	   return false;
	}
	 if(document.form_reserve.txtpv.value == "")
	{
	   alert("Please Enter Preferred Villa");
	   document.form_reserve.txtpv.focus();
	   return false;
	}
	 if(document.form_reserve.txtcomment.value == "")
	{
	   alert("Please Enter Comments");
	   document.form_reserve.txtcomment.focus();
	   return false;
	}
	 if(document.form_reserve.security_code.value == "")
	{
	   alert("Please Enter Verification Code");
	   document.form_reserve.security_code.focus();
	   return false;
	}
	/*var codetext = document.form_reserve.codetext.value;
	var security_code = document.form_reserve.security_code.value;
		 {
	     if(codetext != security_code)
			 {
				 alert("Please verify confirm Security Code");
				 document.form_reserve.security_code.focus();
				 return false;
			 }
		 }*/
	
}
//script validation for date 
function date_valid(txtadate,txtddate){
	var stdate=txtadate.split("/");
	var enddate=txtddate.split("/");
	var prostdate = new Date();
	prostdate.setFullYear(stdate[2]);
	prostdate.setMonth(stdate[0]-1);
	prostdate.setDate(stdate[1]);
	
	var proenddate = new Date();
	proenddate.setFullYear(enddate[2]);
	proenddate.setMonth(enddate[0]-1);
	proenddate.setDate(enddate[1]);
	
	var startingdate = prostdate.getTime();
	var endingdate = proenddate.getTime();

	if(startingdate > endingdate)
	{
		return false;
	}
	return true;
}
///Function phone validation Script
// 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 = 10;

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.addimg_validate
        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);
}

//Email Validation Script
function validateEmail(addr,man,db) {
	if (addr == '' && man) {
	   if (db) alert('Email address is mandatory');
	   return false;
	}
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  if (db) alert('Email address contains invalid characters');
		  return false;
	   }
	}
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  if (db) alert("Email address contains non ascii characters.");
		  return false;
	   }
	}

	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   if (db) alert('Email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   if (db) alert('Email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   if (db) alert('Email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   if (db) alert('Email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   if (db) alert('period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   if (db) alert('period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	   if (db) alert('two periods must not be adjacent in email address');
	   return false;
	}
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   if (db) alert('invalid primary domain in email address');
	   return false;
	}
return true;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
