﻿var maxRooms = 5 ;

function RenderRooms(controlclientid)
{
  var kidsInRoomValue;
  for ( var i=2 ; i<=maxRooms ; i++ )
  {
	document.getElementById("room"+i).style.display="none";	
  }

  var howManyRoomsToDisplay = document.getElementById(controlclientid + "ddlNumOfRooms").value ;  	 		  
  for( var j=1 ; j<=howManyRoomsToDisplay ; j++)
  {
	document.getElementById("room"+j).style.display="block";
	kidsInRoomValue = window.document.getElementById(controlclientid +"ddlChild" + j).value;
	RenderChildrenSection( j, kidsInRoomValue,controlclientid );
  }
}

function RenderChildrenSection(tableIndex , sumOfKids,controlclientid)
{
	switch(Number(sumOfKids))
	{
		case 0 :
			window.document.getElementById("lblFirstChild" +tableIndex).innerHTML = "&nbsp;";
			window.document.getElementById(controlclientid + "ddlFirstAge" +tableIndex).style.display="none";
			window.document.getElementById("lblSecondChild" +tableIndex).innerHTML = "&nbsp;";
			window.document.getElementById(controlclientid + "ddlSecondAge" +tableIndex).style.display="none";
		    break;
		
	    case 1 :
	         window.document.getElementById("lblFirstChild" +tableIndex).innerHTML = "גיל ילד 1";
			 window.document.getElementById(controlclientid + "ddlFirstAge" +tableIndex).style.display="block";
		     window.document.getElementById("lblSecondChild" +tableIndex).innerHTML = "&nbsp;";
			 window.document.getElementById(controlclientid + "ddlSecondAge" +tableIndex).style.display="none";
		     break; 
	    
	    case 2 :
	         window.document.getElementById("lblFirstChild"+tableIndex).innerHTML = "גיל ילד 1";
			 window.document.getElementById(controlclientid + "ddlFirstAge"+tableIndex).style.display="block";
			 window.document.getElementById("lblSecondChild"+tableIndex).innerHTML = "גיל ילד 2";
			 window.document.getElementById(controlclientid + "ddlSecondAge"+tableIndex).style.display="block";
			 break;
	
	 }
}

function RenderChildren(tableIndex,controlclientid)
{
	var sumOfKids = window.document.getElementById(controlclientid + "ddlChild" + tableIndex).value ; 
	RenderChildrenSection(tableIndex, sumOfKids,controlclientid );
}

function openHotelDestinationDialog(controlclientid)
{
	var ret = new Array();
	var style = "dialogHeight:400px; dialogWidth:250px;dialogTop:px;dialogLeft:px;edge:Raised;center:Yes;help:no;resizable:No;status:No;scroll:no;";

    if (window.showModalDialog) {
        _res = window.showModalDialog(DestinationUrl, "", style);
        if (_res != null)
        {
        document.getElementById(controlclientid+"txtDestination").value = _res[0]; 	
        document.getElementById(controlclientid+"inputDestination").value = _res[1]; 	
        }
    }
    else{
        window.open(DestinationUrl + "?codeid=" + controlclientid, "", 'left=300, height=400,width=250,toolbar=no,directories=no,status=no, menubar=no,scrollbars=no,resizable=no ,modal=yes');
    }
}


function CheckDates(controlclientid)
{
   var _fromdateStr = document.getElementById("fdt1").value;
   var _todateStr =document.getElementById("fdt2").value;
   if (_fromdateStr == "" || _todateStr == "")
   {
        alert("נא לבחור תאריכי כניסה ויציאה");
        return false;
   }
   
   var _fromDate  = parseDate2(_fromdateStr);	   
   var _toDate  = parseDate2(_todateStr);
   
   if (_toDate <= _fromDate)
   {
        alert("תאריך החזרה חייב להיות לאחר תאריך היציאה");
        return false;
   } 
   return true;
}

function parseDate2(date)
  {
     var d = new String(date);
     var slash = d.indexOf("/");
     var day = d.substr(0, slash);
     //alert(day);
     d = d.substr(slash+1, d.length-slash-1);
     slash = d.indexOf("/");
     var month = d.substr(0, slash);
     month = parseInt(month, 10) - 1;
     //alert(month);
     d = d.substr(slash+1, d.length-slash-1);
     var year = d;     
     //alert(year);
     var dateObj = new Date();
     dateObj.setFullYear(year, month, day);
    // alert(dateObj);
     return dateObj;
  }

