DOMAssistant.DOMReady(loadFunctionsAdditional);

var calendareventsdisable=1; var ajaxstatus; var pricerownumber=0;

function loadFunctionsAdditional() {
//if (!$$("bookbutton") && readCookie("fromday") && readCookie("frommonthyear")) { location.reload(); }
if ($$("largemap")) onLoad(); // keep it at the beginning or the map will not load correctly
if ($$("calendar"))
   {
   $$("calendar").style.position="static";
   $$("calendar").style.width="95%";
   $$("calendar").style.border=0;
   showElement("calendar");
   }
if ($$("fromday"))
   {
   $$("fromday").addEvent("change", changeToDay);
   $$("frommonthyear").addEvent("change", changeToMonthYear);
   $$("tomonthyear").addEvent("change", changeFromMonthYear);
   $$("fromday").addEvent("change", setDateCookies);
   $$("today").addEvent("change", setDateCookies);
   $$("frommonthyear").addEvent("change", setDateCookies);
   $$("tomonthyear").addEvent("change", setDateCookies);
   }
setupPriceTableEvents();
if (!window.location.hash)
   {
   $("fieldset[id]").each(function () { if (this.id!="description") { hideElement(this.id); hideElement(this.id+"tabs"); } });
   $("a").each(function () { if ($(this).href.indexOf("#")!=-1) $(this).addEvent("click", changeTab); } )
   }
else
   {
   hashpos=window.location.hash.indexOf("#");
   tabid=window.location.hash.substring(hashpos+1,window.location.hash.length);
   $("fieldset[id]").each(function () { if (this.id!=tabid) { hideElement(this.id); hideElement(this.id+"tabs"); } });
   $("a").each(function () { if ($(this).href.indexOf("#")!=-1) $(this).addEvent("click", changeTab); } )
   window.scrollTo(0,0);
   }
$(document.body).addEvent("unload",GUnload);
}

function setupPriceTableEvents()
{
$("span[id^=roomblock]").each(function () { hideElement(this.id); });
$("a[id^=roomlink]").each(function () { $(this).addEvent("click",checkRoomDescription); });
if ($$("bookform")) $$("bookform").addEvent("submit", changeProtocol);
rates=$("#prices td.rate span[title]")
rates.each( function () { $(this).style.cursor="help"; } );
rates.each( function () { $(this).addEvent("mouseover", showRateInfo); } );
rates.each( function () { $(this).addEvent("mouseout", hideRateInfo); } );
rows=$("#prices>tbody>tr");
if (rows.length>5)
   {
   if ($$("bookbutton")) $$("bookbuttoncell").rowSpan=4;
   for(i=5;i<rows.length;i++)
      {
      temprow=rows[i];
      hideElement(temprow);
      }
   showElement("morelink");
   }
if ($$("bookbutton")) $$("bookbutton").style.height=$$("bookbuttoncell").offsetHeight+"px";
if ($$("morelink"))
   {
   hiddenrows=rows.length-5;
   if (hiddenrows<0) hiddenrows=0;
   tempmorelink=morelink.replace(" &#8595;&#8595;"," ("+hiddenrows+") &#8595;&#8595;");
   $$("morelink").replaceContent(tempmorelink);
   $$("morelink").addEvent("click", toggleMorePriceRows);
   if (hiddenrows==0) hideElement("morelink");
   }
}

function toggleMorePriceRows()
{
if (rows.length>5 && rows[5].style.display=="none")
   {
   for(i=5;i<rows.length;i++)
      {
      temprow=rows[i];
      showElement(temprow,"");
      }
   if ($$("bookbutton"))
      {
      $$("bookbuttoncell").rowSpan=rows.length;
      $$("bookbutton").style.height=$$("bookbuttoncell").offsetHeight+"px";
      }
   $$("morelink").replaceContent(lesslink);
   }
else
   {
   for(i=5;i<rows.length;i++)
      {
      temprow=rows[i];
      hideElement(temprow);
      }
   if ($$("bookbutton"))
      {
      $$("bookbutton").style.height="1px";
      $$("bookbuttoncell").rowSpan=4;
      $$("bookbutton").style.height=$$("bookbuttoncell").offsetHeight+"px";
      }
   hiddenrows=rows.length-5;
   tempmorelink=morelink.replace(" &#8595;&#8595;"," ("+hiddenrows+") &#8595;&#8595;");
   $$("morelink").replaceContent(tempmorelink);
   if (hiddenrows==0) hideElement("morelink");
   }
}

function showRateInfo(event)
{
if (isHidden("infodesc"))
   {
   $$("infodesc").replaceContent($(this).title);
   $(this).title="";
   assignPosition("infodesc",event);
   showElement("infodesc");
   }
}

function hideRateInfo()
{
if (!isHidden("infodesc"))
   {
   $(this).title=$$("infodesc").innerHTML;
   hideElement("infodesc");
   $$("infodesc").replaceContent("");
   }
}

function changeTab() {
hashpos=$(this).href.indexOf("#");
tabid=$(this).href.substring(hashpos+1,$(this).href.length);
$("fieldset[id]").each(function () { if ($$(this.id)) hideElement(this.id); if ($$(this.id+"tabs")) hideElement(this.id+"tabs"); });
showElement($$(tabid)); showElement($$(tabid+"tabs"));
return false;
}

function checkRoomDescription() {
roomblock=this.id.replace(/roomlink/,"roomblock");
if (isHidden(roomblock)) showElement(roomblock,"inline");
else hideElement(roomblock);
return false;
}

function changeProtocol() {
allempty=1;
$("#bookform input[class=cc1]").each(function () { if ($(this).value!="") allempty=0; });
$$("bookform").action=$$("bookform").action.replace(/https/,"http");
$("#bookform input[class=cc1]").each(function () { if ($(this).value>0 || allempty==1) { $$("bookform").action=$$("bookform").action.replace(/https/,"http"); $$("bookform").action=$$("bookform").action.replace(/http/,"https"); } });
}

function fetchPriceTable() {
ajaxstatus=getBusyOverlay($$("prices"),{opacity:0.5});
$$("prices").get("js/ajaxhelper.php?command=2&hotelID="+$$("hotelID").value, displayPriceTable);
}

function displayPriceTable(response) {
$$("prices").replace(response);
setupPriceTableEvents();
ajaxstatus.remove();
flashNewInfo("prices");
}

function setDateCookies() {
setCookie("fromday",$$("fromday").selectedIndex+1);
setCookie("frommonthyear",$$("frommonthyear").value);
setCookie("today",$$("today").selectedIndex+1);
setCookie("tomonthyear",$$("tomonthyear").value);
fetchPriceTable();
}

function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++)
   {
   var c = ca[i];
   while (c.charAt(0)==' ') c = c.substring(1,c.length);
   if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
   }
return null;
}
