﻿function CitybreakCalendar(l,n,u,z,o,b,p){var k=this;var x=n;var r=u;var v=z;var e=o;var y=[];var i=document.getElementById(l);var s=new Calendar(l,false,true,false,new Date());var h=b;var m=false;var a=p;this.ArrivalDate=new Date();this.OSD={StoreId:0,StoreItemId:0};this.DateSelected=new Date(1900,0,1);$(s).bind("OnDayRendered",d);$(s).bind("OnMonthChanged",c);$(s).bind("OnDayClicked",w);this.Init=function(){if(this.DateSelected>new Date(1900,0,1)){m=true}if(e){g(!m)}else{s.Render()}};this.Dispose=function(){s=null;k=null};function g(){$(i).loaderShow();var A=false;if(arguments.length>0&&arguments[0]==true){A=true}window.AjaxMgr.ReqJSON("/Ajax/CityBreak/Calendar.ashx",{a:"arrival",p:x,pl:r,f:A,d:s.GetDate().toFormat("y-m-d"),l:v,cbid:a},false,f,h)}function f(C,B){$(i).loaderHide();s.SetDate(new Date(C.First));y=C.Dates;k.OSD.StoreId=C.StoreId;k.OSD.StoreItemId=C.StoreItemId;var A=j(k.DateSelected);if(!A){k.DateSelected=new Date(1900,0,1)}$(k).trigger({type:"OnArrivalLoaded",Date:k.DateSelected,Osd:k.OSD,Available:A});s.Render()}this.Departure=q;function q(){if((k.OSD.StoreId>0&&y.length===0)){$(i).loaderShow();window.AjaxMgr.ReqJSON("/Ajax/CityBreak/Calendar.ashx",{a:"departure",sid:k.OSD.StoreId,siid:k.OSD.StoreItemId,d:k.ArrivalDate.toFormat("y-m-d"),l:v,cbid:a},false,t,h)}else{s.Render()}}function t(B){if(B.Dates.length==0){y=[];$(i).loaderHide();$.prompt(window.Translate.CBNoDepartureDate);$(k).trigger({type:"OnNoDates"});return}minDate=new Date().add("y",2);for(var A=0;A<B.Dates.length;A++){if(B.Dates[A]<minDate){minDate=B.Dates[A]}}s.SetDate(new Date(minDate));y=B.Dates;$(i).loaderHide();s.Render()}this.SetArrival=function(A,B){this.ArrivalDate=A;this.OSD=B;y=[]};this.GetDate=function(){return s.GetDate()};this.SetDate=function(A){s.SetDate(new Date(A))};this.ClearArrival=function(){this.ArrivalDate=new Date();this.OSD={StoreId:0,StoreItemId:0};this.DateSelected=new Date(1900,0,1)};this.Clear=function(){y=[];this.ArrivalDate=new Date();this.OSD={StoreId:0,StoreItemId:0};this.DateSelected=new Date(1900,0,1)};this.Render=function(){s.Render()};function c(A){if(e){g()}else{q()}$(k).trigger({type:"OnMonthChanged",CurrentDate:A.CurrentDate,PreviousDate:A.PreviousDate})}function d(A){if(k.DateSelected.compare("d",A.Date)){A.Div.addClass("CalDaySelected")}else{if(j(A.Date)){A.Div.addClass("CalDayAvailable")}}}function w(A){if(!j(A.Date)){A.Day.removeClass("CalDaySelected");return}if(!e&&k.OSD.StoreId===0){$.prompt(window.Translate.PromptNoDates)}k.DateSelected=A.Date;$(k).trigger({type:"OnDaySelected",Date:A.Date,Osd:k.OSD})}function j(A){if(A<new Date().setHours(0,0,0,0)){return false}var C=false;for(var B=0;B<y.length;B++){if(y[B].compare("d",A)){C=true;break}}return C}};
function CitybreakCalendarOther(b,m,d,o){var n=this;var f=m;var h=d;var p=[];var l=document.getElementById(b);var g=new Calendar(b,false,true,false,new Date());var j=o;this.DateSelected=new Date(1900,0,1);$(g).bind("OnDayRendered",q);$(g).bind("OnMonthChanged",a);$(g).bind("OnDayClicked",c);this.Init=function(){e()};this.Dispose=function(){g=null;n=null};this.GetDate=function(){return g.GetDate()};this.SetDate=function(r){g.SetDate(new Date(r))};function e(){$(l).loaderShow();window.AjaxMgr.ReqJSON("/Ajax/CityBreak/CalendarOther.ashx",{a:"arrival",p:f,d:g.GetDate().toFormat("y-m-d"),l:h},false,i,j)}function i(s,r){$(l).loaderHide();g.SetDate(new Date(s.First));p=s.Dates;$(n).trigger({type:"OnArrivalLoaded",Date:n.DateSelected});g.Render()}this.Render=function(){g.Render()};function a(r){e()}function q(r){if(k(r.Date)){r.Div.addClass("CalDayAvailable")}}function c(r){if(!k(r.Date)){r.Day.removeClass("CalDaySelected");return}n.DateSelected=r.Date;$(n).trigger({type:"OnDaySelected",Date:r.Date})}function k(r){if(r<new Date().setHours(0,0,0,0)){return false}var t=false;for(var s=0;s<p.length;s++){if(p[s].compare("d",r)){t=true;break}}return t}};
function RoomConfig(n){var r=[];var d="#"+n;var l=this;this.SetRooms=g;this.SetAdults=b;this.SetChildren=a;this.SetChildAge=s;this.ToString=o;this.Render=t;this.GetRoomCount=k;if(arguments.length>1&&arguments[1]!==""){var e=arguments[1];var u=e.split("|");for(var q=0;q<u.length;q++){r.push(f());var m=u[q].split("#");r[q][0]=parseInt(m[0]);var c=m[1].split(";");if(c.length>0&&c[0]!==""){for(var p=0;p<c.length;p++){r[q][1].push(c[p])}}}}else{r.push(f());r[0][0]=2}function k(){return r.length}function g(v){var w=Math.abs(r.length-v);if(r.length>v){r.splice(v,w)}else{for(var j=0;j<w;j++){r.push(f())}}this.Render()}function s(v){var j=(v.currentTarget)?v.currentTarget:v.srcElement;var i=j.options[j.options.selectedIndex].value;r[v.data.room][1][v.data.child]=i}function b(){if(arguments.length==1){var v=arguments[0];var j=(v.currentTarget)?v.currentTarget:v.srcElement;var i=parseInt(j.options[j.options.selectedIndex].value);r[v.data.room][0]=i}else{if(arguments.length==2){r[arguments[0]][0]=arguments[1]}}}function a(z){var y=(z.currentTarget)?z.currentTarget:z.srcElement;var A=y.options[y.options.selectedIndex].value;if(A==""){A="0"}var v=parseInt(A);var x=z.data.room;var w=Math.abs(r[x][1].length-v);if(v==0){r[x][1]=[]}else{if(r[x][1].length>v){r[x][1].splice(v,w)}else{for(var j=0;j<w;j++){r[x][1].push("1-3")}}}this.Render()}function o(){var x="";for(var w=0;w<r.length;w++){x+=r[w][0]+"#";for(var v=0;v<r[w][1].length;v++){x+=r[w][1][v]+";"}if(r[w][1].length>0){x=x.substr(0,x.length-1)}x+="|"}if(x.length>0){x=x.substr(0,x.length-1)}return x}function t(){var v=r;$(d).empty();for(var y=0;y<r.length;y++){var x=$(d).createAppend("div",{id:"BookingRoomConfig"+y,className:"BookingRoomConfig"},["span",{},window.Translate.RoomNo(y+1),"select",{id:"Room"+y+"_Adults"},["option",{value:1},"1 "+window.Translate.Adult,"option",{value:2},"2 "+window.Translate.Adults,"option",{value:3},"3 "+window.Translate.Adults,"option",{value:4},"4 "+window.Translate.Adults,"option",{value:5},"5 "+window.Translate.Adults,"option",{value:6},"6 "+window.Translate.Adults],"select",{id:"Room"+y+"_Children"},["option",{value:0},"0 "+window.Translate.Children,"option",{value:1},"1 "+window.Translate.Child,"option",{value:2},"2 "+window.Translate.Children,"option",{value:3},"3 "+window.Translate.Children,"option",{value:4},"4 "+window.Translate.Children,"option",{value:5},"5 "+window.Translate.Children,"option",{value:6},"6 "+window.Translate.Children]]).children("select");h(x.eq(0)[0],r[y][0]);h(x.eq(1)[0],r[y][1].length);x.eq(0).bind("change",{room:y},function(i){l.SetAdults(i)});x.eq(1).bind("change",{room:y},function(i){l.SetChildren(i)});for(var w=0;w<r[y][1].length;w++){x=$("#BookingRoomConfig"+y).createAppend("div",{},["span",{},window.Translate.ChildAge(w+1),"select",{id:"Room"+y+"_Child"+w+"_Age"},["option",{value:"1-3"},"1-3","option",{value:"4-6"},"4-6","option",{value:"7-10"},"7-10","option",{value:"11-13"},"11-13","option",{value:"14-16"},"14-16"]]).children();h(x.eq(1)[0],r[y][1][w]);x.eq(1).bind("change",{room:y,child:w},function(i){l.SetChildAge(i)})}}}function f(){var i=[];i.push(1);i.push([]);return i}function h(v,x){for(var w=0;w<v.options.length;w++){var j=(v.options[w].defaultValue)?v.options[w].defaultValue:v.options[w].value;if(j==x){v.options.selectedIndex=w;break}}}}RoomConfig.prototype.toString=function(){return this.ToString()};

