﻿
function showRoomoptions()
{

var rooms =document.getElementById("rooms").value;

var rowCount = document.getElementById("myTable").getElementsByTagName("TR").length;

for (var i=rowCount;i<=rooms;i++)
{
var x=document.getElementById("myTable").insertRow(-1);

var r=x.insertCell(0);
var a=x.insertCell(1);
var b=x.insertCell(2);
var c1=x.insertCell(3);
var c2=x.insertCell(4);
//var c3=x.insertCell(4);
//var c4=x.insertCell(5);
//var c5=x.insertCell(6);

c1.style.visibility='hidden';
c2.style.visibility='hidden';
//c3.style.visibility='hidden';
//c4.style.visibility='hidden';
//c5.style.visibility='hidden';
//d.style.visibility='hidden';
r.innerHTML="Room" +" "+ i + "";
a.innerHTML="<select name=number_of_adults" + i + " id=number_of_adults" + i + "  onchange=changeAdults(" + i + ",'adults');  class=graytext10 ><option value=\"1\">1</option>" + " <option value=\"2\">2</option><option value=\"3\">3</option><option value=\"4\">4</option></select>";
b.innerHTML="<select name=number_of_children" + i + " id=number_of_children" + i + " onchange=changeMultiRoomOptions(" + i + ");  class=graytext10><option value=0 selected=selected>0</option><option value=1>1</option><option value=2>2</option></select>";
c1.innerHTML="<select name=room"+i+"_child1 id=room"+i+"_child1   class=graytext10><option >1</option> <option >2</option><option >3</option><option >4</option><option >5</option><option >6</option><option >7</option><option >8</option><option >9</option><option >10</option><option >11</option><option >12</option></select>";
c2.innerHTML="<select name=room"+i+"_child2 id=room"+i+"_child2  class=graytext10><option >1</option> <option >2</option><option >3</option><option >4</option><option >5</option><option >6</option><option >7</option><option >8</option><option >9</option><option >10</option><option >11</option><option >12</option></select>";
//c3.innerHTML="<select name=room"+i+"_child3 id=room"+i+"_child3  class=graytext10><option >1</option> <option >2</option><option >3</option><option >4</option><option >5</option><option >6</option><option >7</option><option >8</option><option >9</option><option >10</option><option >11</option><option >12</option></select>";
//c4.innerHTML="<select name=room"+i+"_child4 id=room"+i+"_child4  class=graytext10><option >1</option> <option >2</option><option >3</option><option >4</option><option >5</option><option >6</option><option >7</option><option >8</option><option >9</option><option >10</option><option >11</option><option >12</option></select>";
//c5.innerHTML="<select name=room"+i+"_child5 id=room"+i+"_child5  class=graytext10><option >1</option> <option >2</option><option >3</option><option >4</option><option >5</option><option >6</option><option >7</option><option >8</option><option >9</option><option >10</option><option >11</option><option >12</option></select>";
}
rowCount=rowCount-1;
//alert(rowCount +">" +rooms )

if(rowCount>rooms)
{var tbl = document.getElementById('myTable');

for(var r=0;r<rowCount-rooms;r++)
{
var lastRow = tbl.rows.length;
 tbl.deleteRow(lastRow - 1);
 }


}
var temp=0;


for(var r=1;r<=rooms;r++)
    {

    var colNumber=document.getElementById('number_of_children' + r).value;
    if(colNumber>temp)
        {
        temp=colNumber;

        }


    }
    if(temp>0)
    {
    for(var p=1;p<=temp;p++)
    {
    document.getElementById('hchild'+ p).style.visibility='visible';
    }
    
    
    }



}

/*BY SHASHI BLOCK CHILD */

function changeAdults(row, type)
{
debugger;

 var Adults=document.getElementById('number_of_adults'+row);
  if(Adults!=null)
    var Adults_Count=Adults.options[Adults.selectedIndex].value;  
 
 if(Adults_Count=='3')
 {
         var select = document.getElementById('number_of_children'+row);
         select.options[0].selected=true;
         select.options[2].disabled=true;
         select.options[2].title = '3 Adult and 2 child search result is not available';
         
         //document.getElementById("room"+row+"_child2").visibility='hidden';
         //document.getElementById("room"+row+"_child1").visibility='hidden';
         
        var tbl = document.getElementById('myTable');
        var colIndex=document.getElementById('number_of_children' + row).value;
        var tempcol= (new Number(colIndex)+2);

        
        document.getElementById('hchild1').style.visibility='hidden';
        document.getElementById('hchild2').style.visibility='hidden';
        
        tbl.rows[row].cells[3].style.visibility='hidden';
        tbl.rows[row].cells[4].style.visibility='hidden';
         
         
 }
 if(Adults_Count=='4')
 {
         var select = document.getElementById('number_of_children'+row);
         //alert(select.options[2].value);
         select.options[0].selected=true;
         select.options[1].disabled=true;
         select.options[1].title = '4 Adult and 1 child search is not available';
         select.options[2].disabled=true;
         select.options[2].title = '4 Adult and 2 child search is not available';
         
         //document.getElementById("room"+row+"_child1").visibility='hidden';
         //document.getElementById("room"+row+"_child2").visibility='hidden';
         
        var tbl = document.getElementById('myTable');
        var colIndex=document.getElementById('number_of_children' + row).value;
        var tempcol= (new Number(colIndex)+2);

        document.getElementById('hchild1').style.visibility='hidden';
        document.getElementById('hchild2').style.visibility='hidden';
        
        tbl.rows[row].cells[3].style.visibility='hidden';
        tbl.rows[row].cells[4].style.visibility='hidden';
         
                
         
 }
 if(Adults_Count=='1' || Adults_Count=='2')
 
 {
 var select = document.getElementById('number_of_children'+row);
         //alert(select.options[2].value);
         select.options[1].disabled=false;
         select.options[2].disabled=false;
         
         
 
 }

}
/**/











// ******************************************************function changeMultiRoomOptions **********************************
function changeMultiRoomOptions(row)
{

var tbl = document.getElementById('myTable');
var colIndex=document.getElementById('number_of_children' + row).value;
var tempcol= (new Number(colIndex)+2);

tbl.rows[row].cells[3].style.visibility='hidden';
tbl.rows[row].cells[4].style.visibility='hidden';
//tbl.rows[row].cells[4].style.visibility='hidden';
//tbl.rows[row].cells[5].style.visibility='hidden';
//tbl.rows[row].cells[6].style.visibility='hidden';


for(var i=2;i<=tempcol;i++)
{

tbl.rows[row].cells[i].style.visibility='visible';
}
document.getElementById('hchild1').style.visibility='hidden';
document.getElementById('hchild2').style.visibility='hidden';
//document.getElementById('hchild3').style.visibility='hidden';
//document.getElementById('hchild4').style.visibility='hidden';
//document.getElementById('hchild5').style.visibility='hidden';

var rooms =document.getElementById("rooms").value;
var temp=0;


for(var r=1;r<=rooms;r++)
    {

    var colNumber=document.getElementById('number_of_children' + r).value;
    if(colNumber>temp)
        {
        temp=colNumber;

        }


    }
    if(temp>0)
    {
    for(var p=1;p<=temp;p++)
    {
    document.getElementById('hchild'+ p).style.visibility='visible';
    }
    
    
    }


}


//*************************************************************************************************************************

function getBoardType()
{
  if(!document.getElementById("allBoard").checked) 
   
    {
    
    
    //************ Check for Board Type ***********************
    var strBoard="";
     var cnt=document.getElementsByName("board").length; 
            for (i=1 ; i <= cnt ; i++) 
            {
        str=document.getElementById("chk"+ (new Number(i))).checked;
                if (str==true)
                {
                    if(strBoard=="")
                    {
                     //strBoard=document.getElementById("chk" + (new Number(i))).value;
                        strBoard=" Meal_Code='" +document.getElementById("chk" + (new Number(i))).value+ "'";
                        
                     }//if
                    else{
                            strBoard=strBoard+" or Meal_Code='"+ document.getElementById("chk" + (new Number(i))).value+ "'";
                            //strBoard=strBoard+","+document.getElementById("chk" + (new Number(i))).value;
                            }
                
                }//if
             }//for 

       //***********************************************************
  document.getElementById("hBoardType").value=strBoard;
   
}


}


//////////////////////////////Manage child options////////////


//function manageChild(obj)
//  {
//  
//  var lastchar=obj.substring(obj.length-1,obj.length)
//  deleteOptions(lastchar);
////  if(document.getElementById(obj).value==2)
////   
////   {
//   for(var i=0;i<2;i++)
//   {
//   myOption=new Option();
//   myOption.text=i;
//   myOption.value=i;
//   if (document.getElementById('number_of_children'+lastchar).selectedIndex>0)
//    insertIndex=document.getElementById('number_of_children'+lastchar).selectedIndex;
//   else
//    insertIndex=document.getElementById('number_of_children'+lastchar).options.length;

//   document.getElementById('number_of_children'+lastchar).options[insertIndex]=myOption;	
//   }//end for 
////   }//end if
//   else{
//   
//     myOption=new Option();
//   myOption.text=0;
//   myOption.value=0;
//   if (document.getElementById('number_of_children'+lastchar).selectedIndex>0)
//    insertIndex=document.getElementById('number_of_children'+lastchar).selectedIndex;
//   else
//    insertIndex=document.getElementById('number_of_children'+lastchar).options.length;

//   document.getElementById('number_of_children'+lastchar).options[insertIndex]=myOption;	
//   
//   
//   
//   
//   }
//   
//   
//   changeMultiRoomOptions(lastchar);
//  }//End function
//  
//  
//  function deleteOptions(lastchar)
//  { 
//  var i=document.getElementById('number_of_children'+lastchar).options.length;

//   while (i>0)
//    {
//	i--;
//	var a=document.getElementById('number_of_children'+lastchar);
//	a.remove(i);   

//	}
//  }  

  
