var maxRooms=3;var maxRoomsSelected=0;var maxAdults=5;var maxChildren=5;var maxChildAge=18;var cmbRoomPerAdults="roomPerAdults";var cmbRoomPerChildren="roomPerChildren";var cmbRoomTotalAmount="roomTotalAmount";var tblRoomsAndPersonsSelection="tblRoomsAndPersonsSelection";var tblBottomChildrenInRooms="tblBottomChildrenInRooms";var tblChildrenInRoom="tblChildrenInRoom";var tableRowGuestsInRooms="tableRowGuestsInRooms";var tableRowChildrenInRoom="tableRowChildrenInRoom";var cmbChildAgeNameStart="room_";var cmbChildGuestNameStart="_childGuest_";$().ready(function(){InitRoomCombos()});function InitRoomCombos(){ChangeVisibility("#"+tblBottomChildrenInRooms,false);$("#"+cmbRoomTotalAmount).change(function(){maxRoomsSelected=parseInt($("#"+cmbRoomTotalAmount).val());ShowRooms()});FillAgeCombos();GetValuesForPermanentCombos();ShowRooms()}function GetValuesForPermanentCombos(){var h=[];var c=[];var d=maxAdults+maxChildren;for(var b=0;b<maxRooms;b++){for(var f=0;f<d;f++){var e="room_"+b.toString()+"_guest_"+f.toString()+"_ischild";var j="room_"+b.toString()+"_guest_"+f.toString()+"_age";var a=getURLParameterByName(e);if(a!=null){if(a.toLowerCase()=="false"){if(h[b]==null){h[b]=new Array()}h[b][h[b].length]=31}else{if(a.toLowerCase()=="true"){if(c[b]==null){c[b]=new Array()}var g=getURLParameterByName(j);if(g!=null){c[b][c[b].length]=g}else{c[b][c[b].length]=1}}}}}}if(h.length>0){$("#"+cmbRoomTotalAmount).attr("value",h.length-1);$("#"+cmbRoomTotalAmount).change()}for(var b=0;b<h.length;b++){var k=h[b];if(k==null){continue}$("#"+cmbRoomPerAdults+b.toString()).attr("value",k.length);$("#"+cmbRoomPerAdults+b.toString()).change()}for(var b=0;b<c.length;b++){var k=c[b];if(k==null){continue}$("#"+cmbRoomPerChildren+b.toString()).attr("value",k.length);$("#"+cmbRoomPerChildren+b.toString()).change();for(var f=0;f<c[b].length;f++){$("#"+cmbChildAgeNameStart+b.toString()+cmbChildGuestNameStart+f.toString()).attr("value",c[b][f])}}}function GetChildrenValueInCombo(a){return parseInt($("#"+cmbRoomPerChildren+a.toString()).val())}function FillChildrenInRoomsCombos(){for(var d=0;d<maxRooms;d++){var f=[];for(var h=0;h<maxChildren;h++){var e=GetChildrenValueInCombo(d);var a="#"+tblChildrenInRoom+d.toString()+" span:eq("+h.toString()+")";var c=$(a);if(h>=e&&c.length>0){f[f.length]=$(a)}else{if(c.length==0&&e>0){if(h>=e){continue}$("#"+tblChildrenInRoom+d.toString()).append('<span style="white-space:nowrap"></span> ');var g=cmbChildAgeNameStart+d.toString()+cmbChildGuestNameStart+h.toString();$(a).append(childStr+"&nbsp;"+(h+1).toString()+':&nbsp;<select id="'+g+'" name="'+g+'"></select>');for(var b=1;b<=maxChildAge;b++){$("#"+g).append($("<option style='width:2em'></option>").attr("value",b.toString()).text(b.toString()))}}}}jQuery.each(f,function(){this.remove()})}}function ShowRooms(){for(var a=0;a<maxRooms;a++){if(a<=maxRoomsSelected){ChangeVisibility("#"+tableRowGuestsInRooms+a.toString(),true)}else{ChangeVisibility("#"+tableRowGuestsInRooms+a.toString(),false)}}ChildrenAmountChanged()}function FillAgeCombos(){for(var a=0;a<maxRooms;a++){for(var b=1;b<=maxAdults;b++){$("#"+cmbRoomPerAdults+a.toString()).append($("<option></option>").attr("value",b.toString()).text(b.toString()))}for(var b=1;b<=maxChildren;b++){$("#"+cmbRoomPerChildren+a.toString()).append($("<option></option>").attr("value",b.toString()).text(b.toString()))}$("#"+cmbRoomPerChildren+a.toString()).change(function(){ChildrenAmountChanged()})}}function GetMaxValueFromCombos(f,b){var a=-1;var c=-1;for(var e=0;e<=f;e++){var d=parseInt($("#"+b+e.toString()).val());if(a<d){a=d}if(d>0){c=e}}return[a,c]}function ChildrenAmountChanged(){var b=GetMaxValueFromCombos(maxRoomsSelected,cmbRoomPerChildren);if(b[1]>-1){ChangeVisibility("#"+tblBottomChildrenInRooms,true)}else{ChangeVisibility("#"+tblBottomChildrenInRooms,false)}for(var a=0;a<maxRooms;a++){if(GetChildrenValueInCombo(a)>0&&b[1]>=a){ChangeVisibility("#"+tableRowChildrenInRoom+a.toString(),true)}else{ChangeVisibility("#"+tableRowChildrenInRoom+a.toString(),false)}}FillChildrenInRoomsCombos()}function ChangeVisibility(b,a){if(a){$(b).show()}else{$(b).hide()}}function GetAdultChildQueryStringToSend(){var d=$("select");var a=[];var c=[];jQuery.each(d,function(){if(this.id.substr(0,cmbChildAgeNameStart.length)==cmbChildAgeNameStart){a[a.length]=$("#"+this.id)}if(this.id.substr(0,cmbRoomPerAdults.length)==cmbRoomPerAdults){c[c.length]=$("#"+this.id)}});var l="";var b=[];for(var g=0;g<a.length;g++){var h=a[g].selector.substr(cmbChildAgeNameStart.length+1,1);if(parseInt(h)>maxRoomsSelected){continue}var k=a[g].selector.substr(cmbChildAgeNameStart.length+1+cmbChildGuestNameStart.length+1,1);if(isNaN(b[parseInt(h)])){b[parseInt(h)]=0}var j="room_"+h+"_guest_"+k+"_";l+=j+"ischild=True&"+j+"age="+a[g].val()+"&";b[parseInt(h)]=b[parseInt(h)]+1}for(var g=0;g<=maxRoomsSelected;g++){var f=$("#"+cmbRoomPerAdults+g.toString());var e=parseInt(f.val());for(y=0;y<e;y++){if(isNaN(b[g])){b[g]=0}var j="room_"+g.toString()+"_guest_"+b[g].toString()+"_";l+=j+"ischild=False&"+j+"age=31&";b[g]=b[g]+1}}return l};