if (typeof Structura == "undefined") {
    var Structura = {};
}

if (typeof Structura.EstateDetail == "undefined") {
    Structura.EstateDetail = function(){
        var sUrl =
            window.location.protocol + 
            "//" + 
            window.location.hostname + 
            (window.location.port == "" ? "" : ":" + window.location.port) +
            window.location.pathname.substring(0,window.location.pathname.lastIndexOf("/")) +
            "/estateDetails.aspx?Mode=Text";


        Structura.EstateDetail.handleSuccess = function(o){
            if(o.responseText != undefined){
                Structura.EstateDetail.Panel.setHeader("Details for estate - Ref " + o.argument['estate']);
                Structura.EstateDetail.Panel.setBody(o.responseText);
            }
            
            Structura.EstateDetail.PositionPanel();
            Structura.EstateDetail.Panel.show();
        }

        Structura.EstateDetail.handleFailure = function(o){
            Structura.EstateDetail.Panel.setBody("An error occurred, please try again.<br> If this problem persists, please contact us at +32 (0)2 462 32 00.");
//            if(o.responseText !== undefined){
//	            div.innerHTML = "<li>Transaction id: " + o.tId + "</li>";
//	            div.innerHTML += "<li>HTTP status: " + o.status + "</li>";
//	            div.innerHTML += "<li>Status code message: " + o.statusText + "</li>";
//            }

            Structura.EstateDetail.PositionPanel();
            Structura.EstateDetail.Panel.show();
        }
        
        Structura.EstateDetail.PositionPanel = function()
        {
            var x = YAHOO.util.Dom.getX('ctl00_ContentPlaceHolder1_pnlOpacity') + 8;
            var y = YAHOO.util.Dom.getY('ctl00_ContentPlaceHolder1_pnlOpacity');
            Structura.EstateDetail.Panel.moveTo(x, y);
        }

        Structura.EstateDetail.RequestNewEstateDetails = function(estateID, searchType){
            var detailsCallback =
            {
              success: Structura.EstateDetail.handleSuccess,
              failure: Structura.EstateDetail.handleFailure,
              argument: { estate: estateID  }
            };    
            return YAHOO.util.Connect.asyncRequest('GET', sUrl + "&estateID=" + estateID + "&searchType=" + searchType, detailsCallback);
        }
        
        Structura.EstateDetail.InitializePanel = function(){
            Structura.EstateDetail.Panel = 
                new YAHOO.widget.Panel("detailsPanel", 
                    {
                        x: 421,
                        y: 325,
                        width:"612px", 
                        height: "380px",
                        draggable: false,
                        underlay: "none",
                        visible:false, 
                        fixedcenter:false, 
                        modal: false,
                        constraintoviewport: false, 
                        effect:[{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.35}],
                        zIndex: 10000
                    } 
                );
                
            Structura.EstateDetail.Panel.render();
        }
        
        Structura.EstateDetail.ShowPanel = function(estateID, searchType){
            Structura.EstateDetail.HiddenEstateElement.value = estateID;
            Structura.EstateDetail.Panel.setHeader('');
            Structura.EstateDetail.Panel.setBody('');
            Structura.EstateDetail.RequestNewEstateDetails(estateID, searchType);
            Structura.EstateDetail.Panel.innerElement.style.display = '';
        }
        
        Structura.EstateDetail.HidePanel = function(){
            Structura.ImagePanel.HidePanel();
            if(Structura.EstateDetail.Panel != null)
            {
                Structura.EstateDetail.Panel.hide();
            }
        }
        
        Structura.EstateDetail.HiddenEstateElement = null;
        
        Structura.EstateDetail.RegisterHiddenEstateElementInitializer = function(hiddenEstateElementID)
        {
            YAHOO.util.Event.onAvailable(hiddenEstateElementID, Structura.EstateDetail.RegisterHiddenEstateElement, hiddenEstateElementID)
        }
        
        Structura.EstateDetail.RegisterHiddenEstateElement = function(hiddenEstateElementID)
        {    
            Structura.EstateDetail.HiddenEstateElement = document.getElementById(hiddenEstateElementID);
        }
        
        Structura.EstateDetail.OpenPrintPopup = function(url)
        {
            var win = window.open(url,'ImmoStructuraPrint');
            if(win == null){
                alert('Your browser blocked a popup containing the print page, please allow popups for this site.');
            }
        }
    }
}

Structura.EstateDetail();
YAHOO.util.Event.addListener(window, "load", Structura.EstateDetail.InitializePanel);
