RateCalendar=new Class({Binds:["jsonResponse","getAvailabilities","setDayRates","renderMonth","confirm","removeSelection","setFrom","setTo","markDay","checkSelection","showLoader","hideLoader","show","hide","setOptions","actionPrevMonth","actionNextMonth"],initialize:function(e,c){this.div=$(e);this.setOptions(c);this.dayRatesDiv=$(this.prefix+"dayRates");this.today=new Date();m=this.today.getMonth();y=this.today.getFullYear();this.today.setHours(0,0,0,0);this.prevMonth=m;this.nextMonth=m+2;this.curMonth=m+1;this.curYear=y;this.btnPrevMonth=$(this.prefix+"prevMonth");this.btnPrevMonth.addEvent("click",this.actionPrevMonth.bind(this));this.btnNextMonth=$(this.prefix+"nextMonth");this.btnNextMonth.addEvent("click",this.actionNextMonth.bind(this));this.dayRates=new Hash({});this.cached(this.curMonth,this.curYear)},jsonResponse:function(f,c){this.hideLoader();if(checkJSON(f)){try{key="ibeRc";val=c;obj=JSON.decode(val);obj.avs=null;Cookie.write(key,JSON.encode(obj),{path:"/",duration:0,domain:window.location.host})}catch(e){}this.setDayRates(f);this.renderMonth(f)}else{if(($defined(f)&&$defined(f.ERR))&&($type(f.ERR)=="object")){}}},getAvailabilities:function(f,e){if(!this.cached(f,e)){this.showLoader()}opt={url:window.location.protocol+"//"+document.domain+"/json/ratecalendaravailabilities/",link:"cancel",onComplete:this.jsonResponse.bind(this)};data={month:f,year:e};if(this.jsonRequest){try{this.jsonRequest.cancel()}catch(c){}}this.jsonRequest=new Request.JSON(opt).send("json="+JSON.encode(data))},setDayRates:function(c){this.curMonth=c.from.mon;this.curYear=c.from.year;this.prevMonth=this.curMonth-1;this.nextMonth=this.curMonth+1;if(!$chk(c.avs.DP)){return}arr=c.avs.DP;if(!this.dayRates.has(this.curYear)){this.dayRates.set(this.curYear,new Hash())}y=this.dayRates.get(this.curYear);if(!y.has(this.curMonth)){y.set(this.curMonth,new Hash())}m=y.get(this.curMonth);i=0;arr.each(function(g,f,e){i++;m.set(i,new Hash(g))});m.set("wday",c.from.wday);this.checkSelection(this.resFrom)},renderMonth:function(c){dr=this.dayRatesDiv.getChildren(".dayRate");drID=""+this.prefix+"dayRate";dr.each(function(h,g,e){if(h.get("id")!==(drID)){h.dispose()}});$(this.prefix+"curMonth").set("html",this.monthNames[this.curMonth-1]);$(this.prefix+"curYear").set("html",this.curYear);if(c.from.wday==0){c.from.wday=7}for(i=0;i<(c.from.wday-1);i++){d=new Element("div",{"class":"dayRate"});d.inject(this.dayRatesDiv);d.setStyle("visibility","hidden")}t=new Date(this.curYear,this.nextMonth,0);tt=this.today.getTime();dr=$(this.prefix+"dayRate");if(dr){for(i=1;i<32;i++){try{dayObj=this.dayRates.get(this.curYear).get(this.curMonth).get(i)}catch(f){return}dayTime=new Date(this.curYear,this.curMonth-1,i);if((!$chk(c.avs.DP[i-1]))||((dayTime.getFullYear()==t.getFullYear())&&(dayTime.getMonth()==t.getMonth())&&(dayTime.getDate()==t.getDate()))){break}d=dr.clone(true,false).inject(this.dayRatesDiv);d.setStyle("display","block");d.set("id",this.prefix+"date_"+i);if(this.drWrap){dwrap=d.getChildren("."+this.drWrap)[0];day=dwrap.getChildren(".day")[0];price=dwrap.getChildren(".price")[0]}else{day=d.getChildren(".day")[0];price=d.getChildren(".price")[0]}day.set("html",i);ez=(c.avs.DP[i-1].P[1]>0)?c.avs.DP[i-1].P[1]:"&nbsp;";dz=(c.avs.DP[i-1].P[2]>0)?c.avs.DP[i-1].P[2]:"&nbsp;";price.set("html",ez+"<br />"+dz);if((!this.options)||(!this.options.disable)){if(this.options.dayClick){d.addEvent("click",this.options.dayClick.bindWithEvent(this,day))}else{d.addEvent("click",function(g,e){g.stop();this.markDay(this.curYear,this.curMonth,e.get("html"))}.bindWithEvent(this,day))}}fr=Math.max(c.avs.DP[i-1].FR[1],c.avs.DP[i-1].FR[2]);if((dayTime.getTime()>tt)||((dayTime.getTime()==tt)&&(dayTime.getHours()<18))){popup_tip="";popup_text="";if(c.avs.DP[i-1].R==2){d.addClass("hotdeal");if(this.popup&&this.popup.hotdeal&&this.popup.hotdeal.title&&this.popup.hotdeal.text){d.addClass("popup");if(popup_tip){popup_text+="<h4>"+this.popup.hotdeal.title+"</h4>"+this.popup.hotdeal.text}else{popup_tip=this.popup.hotdeal.title;popup_text=this.popup.hotdeal.text}}}else{d.removeClass("hotdeal")}if(fr>0){dayObj.set("available",true);d.addClass("available");d.removeClass("noav");if(fr==3){d.addClass("last3");if(this.popup&&this.popup.last3&&this.popup.last3.title&&this.popup.last3.text){d.addClass("popup");if(popup_tip){popup_text+="<h4>"+this.popup.last3.title+"</h4>"+this.popup.last3.text}else{popup_tip=this.popup.last3.title;popup_text=this.popup.last3.text}}}if(fr==5){d.addClass("last5");if(this.popup&&this.popup.last5&&this.popup.last5.title&&this.popup.last5.text){d.addClass("popup");if(popup_tip){popup_text+="<h4>"+this.popup.last5.title+"</h4>"+this.popup.last5.text}else{popup_tip=this.popup.last5.title;popup_text=this.popup.last5.text}}}if(fr==10){d.addClass("last10");if(this.popup&&this.popup.last10&&this.popup.last10.title&&this.popup.last10.text){d.addClass("popup");if(popup_tip){popup_text+="<h4>"+this.popup.last10.title+"</h4>"+this.popup.last10.text}else{popup_tip=this.popup.last10.title;
popup_text=this.popup.last10.text}}}}else{dayObj.set("available",false);d.removeClass("available");d.addClass("noav")}if(popup_tip&&popup_text){d.store("tip:title",popup_tip);d.store("tip:text",popup_text)}}else{dayObj.set("available",false);d.removeClass("available");d.removeClass("noav")}}if(this.popup&&this.popup.hotdeal&&this.popup.hotdeal.title&&this.popup.hotdeal.text){cssfilter="#"+this.div.id+".rateCalendar .dayRate.popup";this.podcastTips=new Tips(cssfilter,{className:"rcHotDealTip"})}}this.renderSelection()},renderSelection:function(){if((this.resFrom==null)||(this.resTo==null)){chkOut=false;for(i=0;i<32;i++){d=$(this.prefix+"date_"+i);if($chk(d)){d.removeClass("marked");d.removeClass("arrival");d.removeClass("departure");d.removeClass("depAllowed");dd=new Date(this.curYear,this.curMonth-1,i);ddt=dd.getTime();if((!chkOut)&&((this.resFrom!=null))&&(ddt>=this.resFrom.getTime())){try{dr=this.dayRates.get(dd.getFullYear()).get(dd.getMonth()+1).get(dd.getDate())}catch(c){dr=null}if(!$chk(dr)||dr.FR<1){chkOut=true;d.addClass("depAllowed")}}}}}else{rft=this.resFrom.getTime();rtt=this.resTo.getTime();for(i=0;i<32;i++){d=$(this.prefix+"date_"+i);if($chk(d)){ddt=(new Date(this.curYear,this.curMonth-1,i)).getTime();d.removeClass("arrival");d.removeClass("departure");if((ddt>=rft)&&(ddt<=rtt)){d.addClass("marked")}else{d.removeClass("marked")}}}}if(this.resFrom!=null){if((this.curMonth==this.resFrom.getMonth()+1)&&(this.curYear==this.resFrom.getFullYear())){d=$(this.prefix+"date_"+this.resFrom.getDate());if($chk(d)){d.addClass("arrival")}}}if(this.resTo!=null){if((this.curMonth==this.resTo.getMonth()+1)&&(this.curYear==this.resTo.getFullYear())){d=$(this.prefix+"date_"+this.resTo.getDate());if($chk(d)){d.addClass("departure")}}}},removeSelection:function(){this.resFrom=null;this.resTo=null;this.checkSelection(null);this.renderSelection()},setFrom:function(e,f,c){d=new Date(e,f-1,c);tt=this.today.getTime();if(!((d.getTime()>tt)||((d.getTime()==tt)&&(d.getHours()<18)))){if(this.resFrom==null){d=new Date()}else{return false}}rF=this.resFrom;this.resFrom=d;if(!(this.resTo!=null)||(this.resFrom.getTime()>=this.resTo.getTime())){this.setTo(d.getFullYear(),d.getMonth()+1,d.getDate()+1)}this.checkSelection(rF)},setTo:function(e,f,c){d=new Date(e,f-1,c);tt=this.today.getTime();if(!((d.getTime()>tt)||((d.getTime()==tt)&&(d.getHours()<18)))){return false}this.resTo=d;if(!(this.resFrom!=null)||(this.resFrom.getTime()>=this.resTo.getTime())){this.setFrom(d.getFullYear(),d.getMonth()+1,d.getDate()-1)}this.checkSelection(this.resFrom)},markDay:function(e,f,c){d=new Date(e,f-1,c);tt=this.today.getTime();if(!((d.getTime()>tt)||((d.getTime()==tt)&&(d.getHours()<18)))){return}rF=this.resFrom;if((this.resFrom!=null)&&(d.getTime()==this.resFrom.getTime())){this.resFrom=null}else{if((this.resTo!=null)&&(d.getTime()==this.resTo.getTime())){this.resTo=null}else{if((this.resFrom==null)||(d.getTime()<this.resFrom.getTime())){this.resFrom=d}else{if((this.resTo==null)||(d.getTime()>this.resTo.getTime())){this.resTo=d}}}}this.checkSelection(rF)},checkSelection:function(f){if((this.resFrom!=null)&&(this.resTo!=null)&&(this.resFrom.getTime()>this.resTo.getTime())){this.resTo.setTime(this.resFrom.getTime()+(24*60*60*1000))}if((this.resFrom!=null)&&(this.resTo!=null)){a=this.resFrom;b=this.resTo;while(a.getTime()<=b.getTime()){try{tdayRate=this.dayRates.get(a.getFullYear()).get(a.getMonth()+1).get(a.getDate())}catch(c){return}if(!$chk(tdayRate)||(tdayRate.FR<1)){if((a.getTime()<this.resTo.getTime())&&(this.div.getStyle("display")=="block")){alert("FC<r die Dauer Ihres Aufenthalts stehen leider nicht ausreichend freie Zimmer zur VerfC<gung.")}if(a.getTime()==this.resFrom.getTime()){this.resFrom=null;this.resTo=null}else{this.resTo=a}break}else{a=new Date(a.getFullYear(),a.getMonth(),a.getDate()+1)}}}else{if((this.resFrom!=null)&&!(this.resTo!=null)){tdayRate=null;try{tdayRate=this.dayRates.get(this.resFrom.getFullYear()).get(this.resFrom.getMonth()+1).get(this.resFrom.getDate())}catch(c){}if(!$chk(tdayRate)||(tdayRate.FR<1)){this.resFrom=f}}}this.renderSelection();if($chk(this.divArr)){m=(this.resFrom!=null)?lz(this.resFrom.getDate())+"."+lz(this.resFrom.getMonth()+1)+"."+this.resFrom.getFullYear():"";this.divArr.set("html",m)}if($chk(this.divDep)){m=(this.resTo!=null)?lz(this.resTo.getDate())+"."+lz(this.resTo.getMonth()+1)+"."+this.resTo.getFullYear():"";this.divDep.set("html",m)}},confirm:function(){try{if($chk(this.resFrom)){document.forms.bookingSearchForm.elements["date-from-d"].value=lz(this.resFrom.getDate());document.forms.bookingSearchForm.elements["date-from-m"].value=lz(this.resFrom.getMonth()+1);document.forms.bookingSearchForm.elements["date-from-y"].value=this.resFrom.getFullYear()}else{document.forms.bookingSearchForm.elements["date-from-d"].value="";document.forms.bookingSearchForm.elements["date-from-m"].value="";document.forms.bookingSearchForm.elements["date-from-y"].value=""}}catch(c){}try{if($chk(this.resTo)){document.forms.bookingSearchForm.elements["date-to-d"].value=lz(this.resTo.getDate());
document.forms.bookingSearchForm.elements["date-to-m"].value=lz(this.resTo.getMonth()+1);document.forms.bookingSearchForm.elements["date-to-y"].value=this.resTo.getFullYear()}else{document.forms.bookingSearchForm.elements["date-to-d"].value="";document.forms.bookingSearchForm.elements["date-to-m"].value="";document.forms.bookingSearchForm.elements["date-to-y"].value=""}}catch(c){}},showLoader:function(){if(!$chk(this.loaderDiv)){this.loaderDiv=new Element("div",{"class":"loader"}).inject(this.div,"top");this.loaderImg=new Element("img",{src:"/portal/images/loader.gif"}).inject(this.loaderDiv);this.loaderDiv.addEvent("click",function(c){this.getAvailabilities(this.curMonth,this.curYear)}.bind(this))}this.loaderDiv.setStyle("display","block")},hideLoader:function(){if($chk(this.loaderDiv)){this.loaderDiv.setStyle("display","none")}},show:function(){this.div.setStyle("display","block");if($chk(this.overlay)){this.overlay.setStyle("display","block")}this.getAvailabilities(this.curMonth,this.curYear)},hide:function(){this.div.setStyle("display","none");if($chk(this.overlay)){this.overlay.setStyle("display","none")}},setOptions:function(c){this.options=c;this.monthNames=($chk(c)&&$chk(c.monthNames))?c.monthNames:new Array("Januar","Februar","M&auml;rz","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember");if(($chk(c)&&$chk(c.overlay))){this.overlay=$(c.overlay);this.overlay.addEvent("click",function(f){f.stop();this.hide()}.bind(this))}else{this.overlay=null}this.divArr=(($chk(c)&&$chk(c.divArr)))?$(c.divArr):null;this.divDep=(($chk(c)&&$chk(c.divDep)))?$(c.divDep):null;this.prefix=(($chk(c)&&$chk(c.prefix)))?c.prefix:"";this.drWrap=(($chk(c)&&$chk(c.drWrap)))?c.drWrap:null;this.popup=(($chk(c)&&$chk(c.popup)))?c.popup:null},actionPrevMonth:function(c){c.stop();m=this.today.getMonth();y=this.today.getFullYear();if((this.curYear>y)||((this.curYear==y)&&(this.prevMonth>m))){this.getAvailabilities(this.prevMonth,this.curYear)}},actionNextMonth:function(c){c.stop();this.getAvailabilities(this.nextMonth,this.curYear)},cached:function(c,f){try{key="ibeRc";n=Cookie.read(key);if(n){obj=JSON.decode(n);this.setDayRates(obj);this.renderMonth(obj);return((obj.from.mon===c)&&(obj.from.year===f))}}catch(e){}return false}});function lz(c){return(c<10)?"0"+c:c}function checkJSON(c){return($defined(c)&&!$defined(c.ERR))};
