//SuckerTree Vertical Menu 1.1 (Nov 8th, 06)
//By Dynamic Drive: #/style/

var menuids=["suckertree1"] //Enter id(s) of SuckerTree UL menus, separated by commas

function buildsubmenus(){
for (var i=0; i<menuids.length; i++){
  var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
    for (var t=0; t<ultags.length; t++){
    ultags[t].parentNode.getElementsByTagName("a")[0].className="subfolderstyle"
		if (ultags[t].parentNode.parentNode.id==menuids[i]) //if this is a first level submenu
			ultags[t].style.left=ultags[t].parentNode.offsetWidth+"px" //dynamically position first level submenus to be width of main menu item
		else //else if this is a sub level submenu (ul)
		  ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px" //position menu to the right of menu item that activated it
    ultags[t].parentNode.onmouseover=function(){
    this.getElementsByTagName("ul")[0].style.display="block"
    }
    ultags[t].parentNode.onmouseout=function(){
    this.getElementsByTagName("ul")[0].style.display="none"
    }
    }
		for (var t=ultags.length-1; t>-1; t--){ //loop through all sub menus again, and use "display:none" to hide menus (to prevent possible page scrollbars
		ultags[t].style.visibility="visible"
		ultags[t].style.display="none"
		}
  }
}

if (window.addEventListener)
window.addEventListener("load", buildsubmenus, false)
else if (window.attachEvent)
window.attachEvent("onload", buildsubmenus)


// JavaScript Document
function poplinks(url)
{
	newwindow=window.open(url,'ImageDisplay','height=400,width=600,left=0,top=0,resizable=yes,scrollbars=yes');
	if (window.focus) {newwindow.focus()}
}

function showimage(){
		if (document.form_otherset.imgresize[0].checked){
		ap1=document.getElementById("showattrib");
		    if(ap1){
			ap1.style.display="block";
			ap1.style.visibility="visible";
				}				
		}
		else
		{
			ap1=document.getElementById("showattrib");
			if(ap1){
			ap1.style.display="none";
			ap1.style.visibility="hidden";
				}
		}
	}
	
	function showshopsubcat(x,y){
	window.location.href = "step3reservation.php?catname="+x+"&c_id="+y;
}
var lists=new Array();
function changeList(box) 
{
	//alert(box.options[box.selectedIndex].value);
	//alert(lists[box.options[box.selectedIndex].value]);
	list = lists[box.options[box.selectedIndex].value];
	//alert(list);
	if(box.options[box.selectedIndex].value != "select" && box.options[box.selectedIndex].value != "Choose" && box.options[box.selectedIndex].value != "")
	{
		
		emptyList(box.form.int_roomid);
		fillList(box.form.int_roomid, list );
	}
}
function emptyList(box) 
{
	while (box.options.length) box.options[0] = null;
}

function fillList( box, arr ) 
{
	//alert(arr);
	for ( i = 0; i < arr[0].length; i++ ) 
	{
		opton = new Option( arr[0][i], arr[0][i+1] );
		box.options[box.length] = opton;
		i=i+1;
	}
	box.selectedIndex=0;
}



	function shodetails(){
	if(document.frmoccupancy.pickup[1].checked) 
	{
		shipname=document.getElementById("secondapplicant");
		if(shipname){
		shipname.style.display="block";
		shipname.style.visibility="visible";
		}
		shipname11=document.getElementById("firstapplicant");
		if(shipname11){
		shipname11.style.display="none";
		shipname11.style.visibility="hidden";
		}
			
	}
	else if (document.frmoccupancy.pickup[0].checked) 
	{
	   shipname1=document.getElementById("secondapplicant");
		if(shipname1){
		shipname1.style.display="none";
		shipname1.style.visibility="hidden";
		}
		shipname11=document.getElementById("firstapplicant");
		if(shipname11){
		shipname11.style.display="block";
		shipname11.style.visibility="visible";
		}
		
	}
		else
	{
	   shipname1=document.getElementById("secondapplicant");
		if(shipname1){
		shipname1.style.display="none";
		shipname1.style.visibility="hidden";
		}
		shipname11=document.getElementById("firstapplicant");
		if(shipname11){
		shipname11.style.display="none";
		shipname11.style.visibility="hidden";
		}
		
	}
}

function confirmMsg(msg){
if(!confirm(msg)){
	return false;

} else {
	return true;

}
}

function openreservation(){
document.frmreservation.action="reservation.php";
document.frmreservation.submit();
}


function openmail(){
document.frmreservation.action="reservationmail.php";
document.frmreservation.submit();
}




//Change Reg type
function showpaydetail(){
		if (document.frm_member.regtype.value == "SELLER"){
		ap1=document.getElementById("showattrib");
		    if(ap1){
			ap1.style.display="block";
			ap1.style.visibility="visible";
				}				
		}
		else
		{
			ap1=document.getElementById("showattrib");
			if(ap1){
			ap1.style.display="none";
			ap1.style.visibility="hidden";
				}
		}
	}


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 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.
        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 reservation_validate()
{
	     var roomid = document.frmreservation.roomid.value;
		 if (roomid == "" )
		 { 
			 alert ("Please select Room Name");
			 document.frmreservation.roomid.focus();
			 return false;
		 }
             var start_date = document.frmreservation.start_date.value;
		 if (start_date == "" )
		 { 
			 alert ("Please select Arrival Date");
			 document.frmreservation.start_date.focus();
			 return false;
		 }
		currentdate= new Date();

		curmonth = currentdate.getMonth() + 1;
		curdate = currentdate.getDate() ;

		var curdate =  currentdate.getFullYear() + "-" +curmonth + "-" + curdate ;		
		//alert(start_date);

//alert(curdate);
		deldate=document.frmreservation.start_date.value;
	/*	//alert(deldate);
		if(start_date < curdate)
		{
			   alert("Arrival date must be later than today's date.");
		   document.frmreservation.start_date.focus();
		   return false;
		}*/
		if ( !date_valid(curdate,deldate) )
		{
		   alert("Arrival date must be later than today's date.");
		   document.frmreservation.start_date.focus();
		   return false;
		}
        
}


function bookingvalidate()
{
	     var txtname = document.frmoccupancy.txtname.value;
		 if (txtname == "" )
		 { 
			 alert ("Please enter First Name");
			 document.frmoccupancy.txtname.focus();
			 return false;
		 }
             var lastname = document.frmoccupancy.lastname.value;
		 if (lastname == "" )
		 { 
			 alert ("Please enter the Last Name");
			 document.frmoccupancy.lastname.focus();
			 return false;
		 }
		       var contactemail = document.frmoccupancy.contactemail.value;
               if (!validateEmail(document.frmoccupancy.contactemail.value,1,1)) 
		 {
			 document.frmoccupancy.contactemail.focus();
			 return false;
		 }
	
		      var nopeople = document.frmoccupancy.nopeople.value;
		 if (nopeople == "" )
		 { 
			 alert ("Please enter No of Adults in the party");
			 document.frmoccupancy.nopeople.focus();
			 return false;
		 }
             var nochild = document.frmoccupancy.nochild.value;
		 if (nochild == "" )
		 { 
			 alert ("Please enter No of Children in the party");
			 document.frmoccupancy.nochild.focus();
			 return false;
		 }
         
}


function calendarCallbackleft(date, month, year)
	{

		if(date<10) date="0"+date;
		if(month<10) month="0"+month;
		date = year + '-' + month + '-' + date;
		
		document.frmreservation.start_date.value = date;
	
	}
	
		function date_valid1(txt_Disfrom,txt_Disto){

	var stdate=txt_Disfrom;

	var enddate=txt_Disto;

	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 date_valid(txt_Disfrom,txt_Disto){

	var stdate=txt_Disfrom.split("-");

	var enddate=txt_Disto.split("-");

	var prostdate = new Date();

	prostdate.setFullYear(stdate[0]);

	prostdate.setMonth(stdate[1]-1);

	prostdate.setDate(stdate[2]);

	var proenddate = new Date();

	proenddate.setFullYear(enddate[0]);

	proenddate.setMonth(enddate[1]-1);

	proenddate.setDate(enddate[2]);

	var startingdate = prostdate.getTime();

	var endingdate = proenddate.getTime();
	//alert(startingdate);

	if(startingdate > endingdate)
	{
		return false;
	}
	return true;
}

