// last updated 09.04.2011
var pCIsOpera=(window.opera)?true:false;
var pCIsIE=(document.all&&!pCIsOpera)?true:false;
var pCIsIE5=(pCIsIE&&/MSIE 5\.0/.test(navigator.appVersion))?true:false;
var pCIsIE55=(pCIsIE&&/MSIE 5\.5/.test(navigator.appVersion))?true:false;
var pCIsIE6=(pCIsIE&&/MSIE 6\.0/.test(navigator.appVersion))?true:false;
var pCIsIE7=(pCIsIE&&/MSIE 7\.0/.test(navigator.appVersion))?true:false;
var pCIsIElte55=(pCIsIE&&(pCIsIE5||pCIsIE55)&&!pCIsIE7);
var pCIsIElte6=(pCIsIE&&(pCIsIElte55||pCIsIE6)&&!pCIsIE7);
var pCIsMac=(/Mac/.test(navigator.appVersion))?true:false;
var cDOM={isParentOf:function(A,B){while(B&&(B!=A)){B=B.parentNode}return(B==A)},cGetParentOrSelf:function(B,A){A=A.toLowerCase();while(B.nodeName.toLowerCase()!=A&&B.parentNode){B=B.parentNode}return B},addClass:function(B,A){B.className+=" "+A},removeClass:function(C,B){var A=new RegExp("\\b"+B+"\\b","g");if(A.test(C.className)){C.className=C.className.replace(A," ")}}};
var tdCal;
Date.prototype.MILLISECONDS_PER_DAY=86400000;

function cGetDimensions(F){var C={x:0,y:0,w:0,h:0};if(document.getBoxObjectFor){var A=document.getBoxObjectFor(F);C.x=A.x;C.y=A.y;C.w=A.width;C.h=A.height}else{if(F.getBoundinpClientRect){var B=/MSIE 5\.0/g;var A=F.getBoundinpClientRect();C.x=A.left;C.y=A.top;C.w=(A.right-A.left);C.h=(A.bottom-A.top);if(document.compatMode&&document.compatMode!="BackCompat"){var D=(document.body.scrollTop==0)?(window.pageYOffset)?window.pageYOffset:(document.body.parentElement)?document.body.parentElement.scrollTop:0:document.body.scrollTop;C.x+=document.documentElement.scrollLeft-2;C.y+=D-2}else{if(!pCIsIE5){C.x+=document.body.scrollLeft-2;C.y+=document.body.scrollTop-2}}}else{C.w=F.offsetWidth;C.h=F.offsetHeight;while(F){C.x+=F.offsetLeft;C.y+=F.offsetTop;if(F.offsetParent){F=F.offsetParent}else{break}}}}var E;if(E=document.getElementById("bodyconstraint")){C.x-=E.offsetLeft}return C}
function cBuildCal(K,E,J){var B=[31,0,31,30,31,30,31,31,30,31,30,31];tdCal=new Date();tdCal.setDate(trCal.currentDay);if(!K){K=tdCal.getFullYear()}if(!E){E=tdCal.getMonth()+1}if(!J){J=tdCal.getDate}var D=calendar.caldt;var C=new Date(K,E-1,1);var G=C.getDay();B[1]=(((C.getFullYear()%100!=0)&&(C.getFullYear()%4==0))||(C.getFullYear()%400==0))?29:28;var O='<table class="caltable" border="0" cellspacing="0"><tr>';O+='<td class="calheader monthYear" colspan="4">';O+='<select name="ym" class="ym_month" onchange="cGoYearMonth( this.options[this.selectedIndex].value );">';var F=tdCal.getMonth()+1;var N=tdCal.getFullYear();var I=0;for(n=0;n<=11;n++){O+='<option value="'+N+"-"+F+'"';if(F==E&&N==K){O+=' selected="selected"';I=1}else{I=0}O+=">"+months[F-1]+" "+N+"</option>";F++;if(F>12){F=1;N++}}O+=" </select>";O+='</td><td class="calheader monthYear" colspan="2">';if(K==tdCal.getFullYear()&&E==tdCal.getMonth()+1){O+='<a class="calPrevMonth" href="javascript:void(0)"><img src="'+trCal.icons+trCal.iconPrevMonth2+'" width="16" height="24" alt="'+trCal.prevMonth+'" /></a>'}else{O+='<a class="calPrevMonth" href="" onclick="cPrevMonth( '+K+","+E+' ); return false;" title="'+trCal.prevMonth+'"><img src="'+trCal.icons+trCal.iconPrevMonth+'" width="16" height="24" alt="'+trCal.prevMonth+'" /></a>'}if(I==1){O+='<a class="calNextMonth" href="javascript:void(0);"><img src="'+trCal.icons+trCal.iconNextMonth2+'" width="16" height="24" alt="'+trCal.nextMonth+'" /></a>'}else{O+='<a class="calNextMonth" href="" onclick="cNextMonth( '+K+","+E+' ); return false;" title="'+trCal.nextMonth+'"><img src="'+trCal.icons+trCal.iconNextMonth+'" width="16" height="24" alt="'+trCal.nextMonth+'" /></a>'}O+='</td><td class="calheader monthYear">';O+='<a class="calCloseLink" href="#" onclick="cCloseCal(); return false;"><img src="'+trCal.icons+'delete.gif" width="16" height="24" alt="" title="'+trCal.closeCalendar+'" /></a>';O+="</td></tr>";O+='<tr class="dayNames">';var M;for(dn=0;dn<7;dn++){M="";if((dn%7==5)||(dn%7==6)){M+=" weekend"}O+='<td class="'+M+'">'+days[dn]+"</td>"}O+='</tr><tr class="days">';for(i=1;i<=42;i++){var L=i-(G+6)%7;if(L>B[E-1]||L<1){L="&nbsp;"}M="";var A=0;if((i%7==0)||(i%7==6)){M+=" weekend"}if(L>0){var H=new Date(K,E-1,L);if((H.getFullYear()==K)&&(H.getMonth()+1==E)&&(H.getDate()==J)){M+=" selected";A=1}if((H.getFullYear()==tdCal.getFullYear())&&(H.getMonth()==tdCal.getMonth())&&(H.getDate()==tdCal.getDate())){M+=" today";A=1}else{if(H>tdCal){M+=" future";A=1}else{if(H<tdCal){M+=" past"}}}}O+='<td class="'+M+'">';if(A){O+='<a href="#" onclick="cPickDate( '+K+","+E+","+L+",'"+D+"' ); return false;\">"+L+"</a>"}else{O+=L}O+="</td>";if(((i)%7==0)&&(i<36)){O+='</tr><tr class="days">'}}O+='</tr></table>';document.getElementById("calendar").innerHTML=O}
function cShowCalendar(G,J,A){cGetDimensions(G);if(document.getElementById){var F=document.getElementById(J);var C=cGetChildImage(G);var E=cDOM.cGetParentOrSelf(G,"form");calendar.cal=F;calendar.caldt=A;calendar.calf=E;var I=E[A+"_year_month"].value.split("-");y=I[0];m=I[1];d=E[A+"_monthday"].value;if(y==="0"){y=new Date().getFullYear()};cBuildCal(y,m,d);var D=cGetDimensions(C);var B=D.x,H=(D.y+C.offsetHeight);F.style.left=(B+24)+"px";F.style.top=H+"px";F.style.display="block";}}
function cCloseCal(){calendar.cal.style.display="none"}
function cPrevMonth(B,A){if(new Date(B,A-1,1)<tdCal){return }if(A>1){A--}else{A=12;B--}cBuildCal(B,A)}
function cNextMonth(B,A){if(A<12){A++}else{A=1;B++}cBuildCal(B,A)}
function cGoYearMonth(A){var B=A.split("-");cBuildCal(B[0],B[1])}
function cPickDate(E,A,D,B){var C=calendar.calf;var B=calendar.caldt;C[B+"_year_month"].value=E+"-"+A;C[B+"_monthday"].value=D;if(B=="checkin"){cCheckDateOrder(C,"checkin_monthday","checkin_year_month","checkout_monthday","checkout_year_month")}cCloseCal();}
function cUpdateDaySelect(J){if(pCIsIE5&&pCIsMac){return }var M=cDOM.cGetParentOrSelf(J,"form");if(M.getAttribute("id")!=="frm"&&M.className!=="availForm"){return }if(!M.checkin_monthday||!M.checkout_monthday||!M.checkin_year_month||!M.checkout_year_month){return }if(M.checkin_monthday.value==="0"&&M.checkout_monthday.value==="0"&&M.checkin_year_month.value==="0"&&M.checkout_year_month.value==="0"){return }var H=M.checkin_monthday,O=M.checkout_monthday,G,N,Q;if(M.checkin_year_month.value!=="0"){G=M.checkin_year_month.value.split("-")}if(M.checkout_year_month.value!=="0"){N=M.checkout_year_month.value.split("-")}var I=Math.max(H.selectedIndex,0),B=Math.max(O.selectedIndex,0),E=H[I].value,L=O[B].value,K=[],A,F;H.innerHTML="";O.innerHTML="";if(!pCIsIE5){var P=function(){};}
function cD(Y,U,R,X,W){var V,T,S;for(V=0;V<Y;V++){S=document.createElement("option");T=V+1;if(U.value!=="0"){T=R[V]+" "+T}S.innerHTML=T;S.value=(V+1);if(V>0&&W==V+1){S.defaultSelected=S.selected=true}X.appendChild(S)}}K=cBuildDaysForMonth(G[0],G[1]);var C=31;if(M.checkin_year_month.value!=="0"){C=K.length}cD(C,M.checkin_year_month,K,H,E);K=cBuildDaysForMonth(N[0],N[1]);C=31;if(M.checkout_year_month.value!=="0"){C=K.length}cD(C,M.checkout_year_month,K,O,L);if(pCIsIElte6){H.value=E;O.value=L}}
function cBuildDaysForMonth(D,G){var B=new Date(D,G-1);var E=B.getMonth();var A=[],C;while(B.getMonth()==E){C=(B.getDay()==0)?6:(B.getDay()-1);A.push(days[C]);var F=B.getDate();B.setDate(B.getDate()+1);if(B.getDate()==F){B.setDate(B.getDate()+1)}}return A}
function cCheckDateOrder(G,C,B,H,E){var one_day=1000*60*60*24;var J=cDOM.cGetParentOrSelf(G,"form"),K,L=new Date(0),I=new Date(0),A,F=new Date();if(J[C].value!=="0"){L.setDate(J[C].value);}if(J[B].value!=="0"){K=J[B].value.split("-");L.setFullYear(K[0]);L.setMonth(K[1]-1);}L.setHours(12);L.setMinutes(0);L.setSeconds(0);if(J[H] != undefined && J[H].value!=="0"){I.setDate(J[H].value);}if(J[E] != undefined && J[E].value!=="0"){K=J[E].value.split("-");I.setFullYear(K[0]);I.setMonth(K[1]-1);}I.setHours(12);I.setMinutes(0);I.setSeconds(0);if(J[B].value!=="0"){while(L.getMonth()!=J[B].value.split("-")[1]-1){L.setDate(L.getDate()-1);J[C].value=L.getDate();}var D=L.getMonth()+1;J[B].value=L.getFullYear()+"-"+D;}var days_diff = ((L-I)/one_day);if(days_diff >= (1-minimum_nights)){I.setTime(L.getTime()+minimum_nights*Date.prototype.MILLISECONDS_PER_DAY);A=I.getMonth()+1;if(J[C].value!=="0"){if(J[H] != undefined) J[H].value=I.getDate();}if(J[B].value!=="0"){if(J[E] != undefined) J[E].value=I.getFullYear()+"-"+A;}}cUpdateDaysInDDL();}
function cGetChildImage(A){A=A.firstChild;while(A.nodeName.toLowerCase()!="img"&&A.nextSibling){A=A.nextSibling}return A}
function cUpdateDaysInDDL(){var current_day = document.getElementById("checkin_day").value;var checkin_year_month = document.getElementById("checkin_year_month").value;if(checkin_year_month == trCal.currentYearMonth){for(i = 1; i < trCal.currentDay; i++){document.getElementById("checkin_day").options[i].disabled = true;}}else{for(i = 0; i < document.getElementById("checkin_day").length; i++){ document.getElementById("checkin_day").options[i].disabled = false;}}}