
var roomDtls= new Array(5);
for(var t=0;t<5;t++)
{
	var roomRec=new Array(3);
	roomRec[0]=1;	// for adults
	roomRec[1]=0;	// for children
	roomDtls[t]=roomRec;
}
function updatearray(val,val1,ele)
{
   roomDtls[val][val1]=ele.value;
}
/////////////////////////////////////////////////////////////////
function deleteTable(table)
{
	for (var count=table.rows.length-1;count>0;count--)
	{
		table.deleteRow(count);
	}
}

function createRooms()
{	
	var table = document.getElementById("gueststable");   
	deleteTable(table);	
	var rooms = document.getElementById("rooms").value; 

	for(var count=0;count<rooms; count++)
	{
		var row = table.insertRow(count + 1);		
		var cell0 = row.insertCell(0);
		var cell1 = row.insertCell(1);
		var cell2 = row.insertCell(2);
		var cell3 = row.insertCell(3);
		var cell4 = row.insertCell(4);

		cell0.innerHTML = ""; 
		cell1.innerHTML = "Room" + (count + 1) ;
		cell2.align = "left";
		cell4.align = "center";
		cell4.colSpan="2";

		cell2.innerHTML = "<select name='adults' onchange='updatearray("+count+",0,this)' style=\"FONT-SIZE: 11px\"> <option value='1'>1</option><option value='2'>2</option><option value='3'>3</option></select>";
		cell3.innerHTML = "<select name='children' onchange='createchildage(); updatearray("+count+",1,this)' style=\"FONT-SIZE: 11px\"> <option value='0' selected>0</option> <option value='1'>1</option>	<option value='2'>2</option></select>";
		cell4.innerHTML = "<table cellpadding='0' cellspacing='0' border='0' width='100%' id='agetable" + (count) +  "'></table>"
	}

	var adults = document.getElementsByName("adults");
	var children = document.getElementsByName("children");

	for ( count=0; count<rooms; count++)
	{
		adults[count].value		=	roomDtls[count][0];
		children[count].value	=	roomDtls[count][1];
	}
	
	createchildage();

  }


function createchildage()
{
	var childageth1 = document.getElementById("childageth1");
	var childageth2 = document.getElementById("childageth2");
	childageth1.innerHTML="&nbsp;";
	childageth2.innerHTML="&nbsp";
	
	var child1 = false;
	var child2 = false; 

	var rooms = document.getElementById("rooms").value;
	var children = document.getElementsByName("children");
		
	for (var count=0;count<rooms;count++)
	{
		var table=document.getElementById("agetable"+count);  
		if(table.rows.length==1)
        {
           table.deleteRow(0);	 
        }           

		var row = table.insertRow(0);                          
		var cell0 = row.insertCell(0);
		var cell1 = row.insertCell(1);
		cell0.width="30%";
		cell1.width="70%";
		cell0.align="left";
		cell1.align="left";
		
		var chAge1 = "<select name='childage1' style='FONT-SIZE: 11px'>";
		chAge1 = chAge1 + "<option value='-1' selected='selected'>--</option>"
		chAge1 = chAge1 + "<option value='1'>1</option><option value='2'>2</option><option value='3'>3</option>";
		chAge1 = chAge1 + "<option value='4'>4</option><option value='5'>5</option><option value='6'>6</option>";
		chAge1 = chAge1 + "<option value='7'>7</option><option value='8'>8</option><option value='9'>9</option>";
		chAge1 = chAge1 + "<option value='10'>10</option><option value='11'>11</option><option value='12'>12</option>";
		
		var chAge2 = "<select name='childage2' style='FONT-SIZE: 11px'>";
		chAge2 = chAge2 + "<option value='-1' selected='selected'>--</option>"
		chAge2 = chAge2 + "<option value='1'>1</option><option value='2'>2</option><option value='3'>3</option>";
		chAge2 = chAge2 + "<option value='4'>4</option><option value='5'>5</option><option value='6'>6</option>";
		chAge2 = chAge2 + "<option value='7'>7</option><option value='8'>8</option><option value='9'>9</option>";
		chAge2 = chAge2 + "<option value='10'>10</option><option value='11'>11</option><option value='12'>12</option>";
        
		if(parseInt(children[count].value)==1)
		{
			child1 = true;
			cell0.innerHTML = chAge1;	
			cell1.innerHTML ="&nbsp;";	
		}
		if(parseInt(children[count].value)==2)
		{			
			child2 = true;
			cell0.innerHTML = chAge1;	
			cell1.innerHTML = chAge2;
		}
	}
	
	if(child1 == true)
	{
		childageth1.innerHTML="Child 1<br/>(Age)";
	}
	if(child2 == true)
	{	
		childageth1.innerHTML="Child 1<br/>(Age)";
		childageth2.innerHTML="Child 2<br/>(Age)";
	}
			        
}


function validateForm()
{	
	//	alert("alam...........");	 	
	//	showProgressSpinner();
	//	return false;
	
	var rooms = document.getElementById("rooms").value;
	
	var adultsObj = document.getElementsByName("adults");
	var childrenObj = document.getElementsByName("children");
		
	for (var count=0;count<rooms;count++)
	{
		if(adultsObj[count].value==3 && childrenObj[count].value==2)
		{
			adultsObj[count].focus();
			alert("No of passengers can't be more than (2 adults and 2 children) OR (3 adults and 1 children) OR (3 adults) in a single room");
			return false;
		}
	
	}

	if(document.searchform.city.value=="dottedLine")
	{
		alert("Please Select a City name...");

		//document.
		
		document.searchform.city.focus(); return false;
	}	

	if(validateDates()==false)
	{
		return false;
	}

////////////////////////////////////////////////////////////////////////////////////////////////////	
////////////////  Difference of checkIn and checkOut date using JaVascript  ////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////	

	var days = 0;
	var difference = 0;
	

	
//	var currdate = "09/01/2011";
//	var strSeparator = currdate.substring(2,3);
//	var currdateArr = currdate.split(strSeparator);
//	var date_after_3days = new Date(currdateArr[1]+"/"+currdateArr[0]+"/"+currdateArr[2]);

	var date_after_3days = new Date(new Date().getTime() + parseInt(1000*60*60*24*0));
	
	var chkInDate = document.getElementById("check_in").value;	
	strSeparator = chkInDate.substring(2,3);
	var arrchkInDate = chkInDate.split(strSeparator);
	chkInDate = new Date(arrchkInDate[1]+"/"+arrchkInDate[0]+"/"+arrchkInDate[2]);

	var chkOutDate = document.getElementById("check_out").value;		
	strSeparator = chkOutDate.substring(2,3);
	var arrchkOutDate = chkOutDate.split(strSeparator);
	chkOutDate = new Date(arrchkOutDate[1]+"/"+arrchkOutDate[0]+"/"+arrchkOutDate[2]);	
	
	difference =  chkOutDate.getTime() - chkInDate.getTime();
	days = difference/(1000*60*60*24);

	if(chkInDate.getTime() < date_after_3days.getTime())
	{
		alert("Check-In date should be atleast 1 days later than current date... " + new Date()); 
		return false;
	}	
	if(days<0)
	{
		alert("The Check-in date cannot be after the Check-out date.");
		return false;
	}
	if(days==0)
	{
		alert("Check-In and Check-Out dates cannot be same....");
		return false;
	}

	if ( days>30 )
	{
		alert("The Check-out date needs to be within 30 days from the Check-in date.");
		return false;
	}

	
	var childage1 = document.getElementsByName("childage1");
	var childage2 = document.getElementsByName("childage2");

	for ( count=0; count<childage1.length; count++)
	{
		if( childage1[count].value == "-1")
		{
			childage1[count].focus();
			alert("Please Select age of child");
			return false;
		}
		if( childage2[count].value == "-1")
		{
			childage2[count].focus();
			alert("Please Select age of child");
			return false;
		}
	}
	
	showProgressSpinner();
	
//	grayOut(true);
//	showProgressSpinner("urlContent");  //Keep showing the spinner	
	
 //	return false;
}



var timeshow="", timehide="";
var h=5, mht=5, wrk=0;
var maxHt, cht, expandObj;

function expandLogin(height, id)
{	
	expandObj=document.getElementById(id);
	cht=parseInt(expandObj.style.height);
	maxHt=height;
	if(wrk==1){return}; 	
	if(expandObj.style.display=='none')
	{
		timeshow=window.setInterval("showdiv()",10);
	}
	else
	{
		timehide=window.setInterval("hidediv()",10);
	}
}
function showdiv()
{
	wrk=1;
	if(expandObj.style.display=='none') expandObj.style.display='';
	expandObj.style.height=cht+"px";
	if((parseInt(cht,10))<(parseInt(maxHt)))
	{
		cht =parseInt(cht);
		cht=cht+1;
	}
	else
	{
		expandObj.style.display='';
		window.clearInterval(timeshow);
		wrk=0;
	}
}
function hidediv()
{
	wrk=1;
	if((parseInt(cht,10))>(parseInt(mht,10)))
	{
		cht=parseInt(cht);
		cht=cht-1;
		expandObj.style.height=cht+"px";
	}
	else
	{
		expandObj.style.display='none';
		window.clearInterval(timehide);
		wrk=0;
	}
}

function chkUser(){
	 var txtUser=document.getElementById("TxtUsername").value;
	 if(txtUser=="username"){
	 document.getElementById("TxtUsername").value="";
	 }
	}

function chkUser1(){
	var txtUser=document.getElementById("TxtUsername").value;
	 if(txtUser==""){
	 document.getElementById("TxtUsername").value="username";
	 }
	}

function chkPass(){
	 var txtPassword=document.getElementById("TxtPass").value;
	 if(txtPassword=="password"){
	 document.getElementById("TxtPass").value="";
	 }
	}
function chkPass1(){
	var txtPassword=document.getElementById("TxtPass").value;
	 if(txtPassword==""){
	 document.getElementById("TxtPass").value="password";
	 }
	}

function chkBlank(){
	   var txtUser=document.getElementById("TxtUsername").value;
	   var txtPassword=document.getElementById("TxtPass").value;
	   
	    if(txtUser=="username" || txtUser==""  ){
	        alert("Enter Username");
	     return;
	    }
	    if(txtPassword=="password" || txtPassword.value==""){
	        alert("Enter Password");
	        return;
	    }
	//   ajxLogin('/customerprofile/Pages/Login.aspx?UserName='+ txtUser +'&password=' + txtPassword + '&date='+new Date().getTime()+'')  
		return;
	}


