﻿var NPADD             = "";
var NPDEL             = "";
var DetailAdd         = "";
var DetailDel         = "";    
var ACCMDP            = "";
var ACCTTL            = "";
var MXCMP             = 0;
var IDPRT             = 0;
var IDLNG             = 0;
var IDTHM             = 0;
var IDCAT             = 0;
var STARS             = 0;
var IDCTY             = 0;
var IDRGN             = 0;
var ACTN              = '';
var CPAGE             = 0;
var ACCLOAD           = false;
var Stars             = 0;
var Category          = 0;
var City              = 0;
var Theme             = 0;
var SearchValue       = "";
var PageSize          = 0;
var GotoFirstPage     = true;
var CurrentOpacity    = 0;
var AdditionalOpacity = 0.1;
var MaximumOpacity    = 0.5;
var Reloop            = false;
var LoadingPanel;
var CurrentTimeout;
var Container; 
function ShowRow( ID ){
    var Row = document.getElementById( "Row_" + ID );
    var Link = document.getElementById( "Link_" + ID )    
        if ( Row.className == "HiddenRow" ) {
            Row.className = "VisibleRow";
            Link.innerHTML = DetailDel;
        } else {
            Row.className = "HiddenRow";
            Link.innerHTML = DetailAdd;
        }
}
function InitAccommodationList(){
    if(!$("SearchValue")) { return false; }
    new Ajax.Autocompleter("SearchValue", "AutoCompleterValues", "/SharedR/Portale/Accomodations/AutoCompleter.asp", {
      paramName: "value",
      parameters: 'P=' + IDPRT + '&L=' + IDLNG + '&T=' + IDTHM
    });
}
function AddNotePaper( ID ){
    var NPUP    = document.getElementById( "NPUP" );
    var NPCT    = NPUP ? parseInt(NPUP.innerHTML) : 0;
    var SP      = document.getElementById( "Sp_" + ID );
    var SPHTML  = SP.innerHTML;
    var IMG     = document.getElementById( "Img_" + ID );
    var IMGF    = document.getElementById( "NPFILE" );
    var RND     = Math.random();
    var ACT     = document.getElementById("Action").value;
    if (( SPHTML.indexOf("zum") != -1) || (SPHTML.indexOf("agg") != -1) || (SPHTML.indexOf("add") != -1) ) {
        SP.innerHTML    = NPDEL;
        IMG.src         = "/SharedR/Portale/Images/Icons/Notepaper_delete.gif";
        IMGF.src        = "/SharedR/Portale/Notepaper/Session.asp?IDCompanyCategory=" + ID + "&RND=" + RND;
        NPUP ? NPUP.innerHTML  = NPCT + 1 : false;
    } else {
        SP.innerHTML    = NPADD;
        IMG.src         = "/SharedR/Portale/Images/Icons/Notepaper.gif";
        IMGF.src        = "/SharedR/Portale/Notepaper/Session.asp?IDCompanyCategory=" + ID + "&RND=" + RND;
        NPUP ? NPUP.innerHTML  = NPCT - 1 : false;
        if(ACT != "") {
            document.getElementById("Row_" + ID ).style.display = "none";
            document.getElementById("NameRow_" + ID ).style.display = "none";
        }
    }    
    if(NPUP) { NPCT  = parseInt(NPUP.innerHTML); }
    var BTNSD;
    if(document.getElementById("SendSiForm")) { BTNSD = document.getElementById("SendSiForm");}
    if( BTNSD && document.getElementById("NPWRN") ) {
        if( NPCT > MXCMP ) {
            BTNSD.disabled = true;
        } else {
            BTNSD.disabled = false;
            document.getElementById("NPWRN").innerHTML = ACCTTL;
        }
    }
}
function StarList_onChange( sender ){
    if( document.ListForm.sterne && document.ListForm.sterne != sender ) { return false; }    
    Stars = sender.value;    
    SearchValue = "";
    if( document.SVForm.betrieb ) { document.SVForm.betrieb.value = ""; }
    Listbox_onChange();
}
function CategoryList_onChange( sender ){
    if( document.ListForm.kategorie && document.ListForm.kategorie != sender ) { return false; }
    Category = sender.value;
    SearchValue = "";
    if( document.SVForm.betrieb ) { document.SVForm.betrieb.value = ""; }
    Listbox_onChange();
}
function CityList_onChange( sender ){
    if( document.ListForm.ort && document.ListForm.ort != sender ) { return false; }
    City = sender.value;
    SearchValue = "";
    if( document.SVForm.betrieb ) { document.SVForm.betrieb.value = ""; }
    Listbox_onChange();
}
function SearchButton_onClick( DefaultValue ){
    SearchValue = $("SearchValue") ? ($("SearchValue").value).replace("&","{and}") : "";
    Stars = 0; Category = 0; City = 0;    
    if( document.ListForm.ort )       { document.ListForm.ort.selectedIndex  = 0; }
    if( document.ListForm.kategorie ) { document.ListForm.kategorie.selectedIndex  = 0; }
    if( document.ListForm.sterne )    { document.ListForm.sterne.selectedIndex  = 0; }
    if( SearchValue == DefaultValue ) { SearchValue = ""; }    
    Listbox_onChange();
}
function PageSize_onChange(){
    PageSize = $("PageSize") ? $("PageSize").value : 0;
    GotoFirstPage = false; 
    if( PageSize != 0 )
        Listbox_onChange();
}
function ThemeButton_onClick( Value, Element ){
    if( !parseInt(Value) ) { return false };
    if( Element && Element.innerHTML && document.getElementById("Phrase1") ) { document.getElementById("Phrase1").innerHTML = Element.innerHTML; };
    Theme = Value;
    Stars = 0; Category = 0; City = 0;    
    if( document.ListForm.ort )       { document.ListForm.ort.selectedIndex  = 0; }
    if( document.ListForm.kategorie ) { document.ListForm.kategorie.selectedIndex  = 0; }
    if( document.ListForm.sterne )    { document.ListForm.sterne.selectedIndex  = 0; }
    SearchValue = "";
    if( document.SVForm.betrieb ) { document.SVForm.betrieb.value = ""; }
    Listbox_onChange();
}
function SubmitButton_onClick() {
    Listbox_onChange();
}
function GetCompanyCount(){
    if( !$("CompanyContainer") ){
    var Url = "/SharedR/Portale/Accomodations/CompanyCountRequest.asp?PortalId=" + IDPRT + "&LanguageId=" + IDLNG + "&ThemeId=" + IDTHM
        if( Stars != 0 ){ Url += "&Stars=" + Stars; }
        if( Category != 0 ){ Url += "&CategoryId=" + Category ; }
        if( City != 0 ){ Url += "&CityId=" + City ; }
        new Ajax.Request(Url, { onSuccess: function(transport) { $("CompanyTable").innerHTML = transport.responseText; } });
    }
}
function Listbox_onChange(){
    if(!Container)    { Container    = $("CompanyContainer"); }  
    if(!LoadingPanel) { LoadingPanel = $("LoadingPanel"); }
    if(!Container) { return false; }
    switch( parseInt(IDLNG) ) {
            case 1:  Url = "/de/"; break;
            case 2:  Url = "/it/"; break;
            case 3:  Url = "/en/"; break;
            default: return false;
        }   Url += "data/includes/accommodation-ax.asp?PortalId=" + IDPRT;        
        if( document.ListForm.ort && document.ListForm.ort.selectedIndex == 0 ){ City = 0; IDCTY = 0; IDRGN = 0; }
        if( document.ListForm.sterne && document.ListForm.sterne.selectedIndex == 0 ){ Stars = 0; STARS = 0; }
        if( document.ListForm.kategorie && document.ListForm.kategorie.selectedIndex == 0 ){ Category = 0; IDCAT = 0; }
        if( Stars != 0 ) { Url += "&sterne=" + Stars; } 
        if( Stars == 0 && STARS != 0 && Url.indexOf("sterne") < 0 ) { Url += "&sterne=" + STARS; }
        if( Category != 0 ) { Url += "&kategorie=" + Category ; }
        if( Category == 0 && IDCAT != 0 && Url.indexOf("kategorie") < 0 ) { Url += "&kategorie=" + IDCAT; }
        if( City != 0 ) { Url += "&ort=" + City ; }
        if( IDCTY != 0 && Url.indexOf("&ort") < 0  ) { Url += "&ort=" + IDCTY; }
        if( City == 0 && IDRGN != 0 && Url.indexOf("region") < 0 ) { Url += "&region=" + IDRGN; }        
        if( SearchValue != "" ) { Url += "&betrieb=" + SearchValue; }
        if( PageSize != 0 ) { Url += "&PageSize=" + PageSize; }
        if( Theme != 0 ) { Url += "&thema=" + Theme; }
        if( IDTHM != 0 && Url.indexOf("thema") < 0 )     { Url += "&thema=" + IDTHM; }
        if( !GotoFirstPage ) { Url += "&Page=" + CPAGE; GotoFirstPage = true }
        ShowLoadingPanel();
        new Ajax.Request(encodeURI(Url), {
        onSuccess: function(transport) {
            Container.innerHTML = transport.responseText;
            HideLoadingPanel();
            }
        });
}
function GetLeft(Object) { return (Object.offsetParent)? Object.offsetLeft + GetLeft(Object.offsetParent) : Object.offsetLeft; }
function GetTop(Object)  { return (Object.offsetParent)? Object.offsetTop + GetTop(Object.offsetParent) : Object.offsetTop; }
function ChangePage(QueryString,Page){
    var Url = "";        
        scroll(0,0);
        switch( parseInt(IDLNG) ) {
            case 1:  Url = "/de/"; break;
            case 2:  Url = "/it/"; break;
            case 3:  Url = "/en/"; break;
            default: return false;
        }   Url += "data/includes/accommodation-ax.asp" + QueryString;
        if( IDTHM != 0 && Url.indexOf("thema") < 0 )     { Url += "&thema=" + IDTHM; }
        if( IDCAT != 0 && Url.indexOf("kategorie") < 0 ) { Url += "&kategorie=" + IDCAT; }
        if( IDCTY != 0 && Url.indexOf("ort") < 0  )      { Url += "&ort=" + IDCTY; }
        if( IDRGN != 0 && Url.indexOf("region") < 0 )    { Url += "&region=" + IDRGN; }
        if( STARS != 0 && Url.indexOf("sterne") < 0 )    { Url += "&sterne=" + STARS; }
        if( ACTN  != '' && Url.indexOf("Action") < 0 )   { Url += "&Action=" + ACTN; }
        if( Page && Page != 0 ) { CPAGE = Page; }
        if(!Container)    { Container    = $("CompanyContainer"); } 
        if(!LoadingPanel) { LoadingPanel = $("LoadingPanel"); }        
            ShowLoadingPanel();        
        new Ajax.Request(Url, {
            onSuccess: function(transport) {
                Container.innerHTML = transport.responseText;
                HideLoadingPanel();
                }
            });
        return false;        
}
function ShowLoadingPanel(){
    LoadingPanel.style.width      = Container.getStyle("width");
    LoadingPanel.style.height     = parseInt(Container.getStyle("height")) - 50 + "px";        
    LoadingPanel.style.left       = GetLeft(Container) + "px";
    LoadingPanel.style.top        = GetTop(Container)  + 20 + "px";
    LoadingPanel.style.visibility = "visible";
    LoadingPanel.style.display    = "";
    LoadingPanel.setOpacity(0);
    clearTimeout(CurrentTimeout);
    CurrentTimeout = setTimeout( 'FadeIn()', 50 );      
}
function HideLoadingPanel(){
    clearTimeout(CurrentTimeout);    
    CurrentTimeout = setTimeout( 'FadeOut()', 50 );
}
function FadeIn(){
    Reloop = false;    
    CurrentOpacity += AdditionalOpacity;
    if( CurrentOpacity <= MaximumOpacity ){
        LoadingPanel.setOpacity( CurrentOpacity );
        Reloop = true;
    }
    if( Reloop )
        CurrentTimeout = setTimeout( 'FadeIn()', 50 );
}
function FadeOut(){
    Reloop = false;    
    CurrentOpacity -= AdditionalOpacity;
    if( CurrentOpacity >= 0 ){
        LoadingPanel.setOpacity( CurrentOpacity );
        Reloop = true;
    }
    if( Reloop ){
        CurrentTimeout = setTimeout( 'FadeOut()', 50 );
    } else {
        LoadingPanel.style.visibility = "hidden";
        LoadingPanel.style.display    = "none";
    }
}
