﻿var mouseOutColor = '#FFFFFF';
var eventAvailable = false;
var poiFrameVisible = false;
var poiFound = false;
var eventClientX = null;
var eventClientY = null;
var pageClientClickX = null;
var pageClientClickY = null;
var poiFrameInitialX = null;
var poiFrameInitialY = null;
var timerShowLoadID = null;
var errorPageLocation = 'ZPL/controls/FatalErrorPage.aspx?aspxerrorpath=' 
    
var areaIdentifier = 'MapImage_area_'
var poiDisplayIdentifier = 'ctl00_POIDisplay';

var theIFrame = null;

var lastAreaCallBackX = -999999999;
var lastAreaCallBackY = -999999999;

function initZHPlan()
{
    window.history.forward(1);

    //Load Event Fix Opera (Load von Opera wird nicht hier durchgeführt)
    if (!window.opera)
    {
        if (document.getElementById ('basicMapImageContainer'))
        {
            if (browserOk.value == 'false')
                loadBrowserCheckResult();
            else
            {
                MouseOverImageInitPage();
                initImage();
                eventAvailable = true;
            }
        }
        else
        {
            initImage();
            eventAvailable = true;
        }
    }
}

function showSplashImage ()
{
    if (document.getElementById('basicMapImageContainer'))
    {
        clearPan();
        window.clearTimeout(timerShowLoadID);
        showLoad(-1)
    }
}

function clearPan()
{
    document.getElementById('Pan0_0').style.backgroundColor = mouseOutColor;
    document.getElementById('Pan0_1').style.backgroundColor = mouseOutColor;
    document.getElementById('Pan1_0').style.backgroundColor = mouseOutColor;
    document.getElementById('Pan0_2').style.backgroundColor = mouseOutColor;
    document.getElementById('Pan0_3').style.backgroundColor = mouseOutColor;
    document.getElementById('Pan0_4').style.backgroundColor = mouseOutColor;
    document.getElementById('Pan1_2').style.backgroundColor = mouseOutColor;
    document.getElementById('Pan2_1').style.backgroundColor = mouseOutColor;
    document.getElementById('Pan3_0').style.backgroundColor = mouseOutColor;
    document.getElementById('Pan4_0').style.backgroundColor = mouseOutColor;
    document.getElementById('Pan4_1').style.backgroundColor = mouseOutColor;
    document.getElementById('Pan4_2').style.backgroundColor = mouseOutColor;
    document.getElementById('Pan3_1').style.backgroundColor = mouseOutColor;
    document.getElementById('Pan4_4').style.backgroundColor = mouseOutColor;
    document.getElementById('Pan4_3').style.backgroundColor = mouseOutColor;
    document.getElementById('Pan2_0').style.backgroundColor = mouseOutColor;
    
}

function showLoad(_index)
{
    var method = '';
    var mouseOverColor = '#DDD7D7';
    var mouseOutColor = '#FFFFFF';
    var speed = 400;
    var index = _index;
    var newIndex = 0;
    var showLoadStart = false;
    
    if (index == -1)
    {
        showLoadStart = true;
        index = 0;
    }
    
    if (index == 0)
    {
        document.getElementById('Pan2_0').style.backgroundColor = mouseOutColor;
    
        document.getElementById('Pan0_0').style.backgroundColor = mouseOverColor;
        document.getElementById('Pan0_1').style.backgroundColor = mouseOverColor;
        document.getElementById('Pan1_0').style.backgroundColor = mouseOverColor;
        newIndex = 1;
    }
    else if (index == 1)
    {
        document.getElementById('Pan0_0').style.backgroundColor = mouseOutColor;
        document.getElementById('Pan0_1').style.backgroundColor = mouseOutColor;
        document.getElementById('Pan1_0').style.backgroundColor = mouseOutColor;
    
        document.getElementById('Pan0_2').style.backgroundColor = mouseOverColor;
        newIndex = 2;
    }
    else if (index == 2)
    {
        document.getElementById('Pan0_2').style.backgroundColor = mouseOutColor;
    
        document.getElementById('Pan0_3').style.backgroundColor = mouseOverColor;
        document.getElementById('Pan0_4').style.backgroundColor = mouseOverColor;
        document.getElementById('Pan1_2').style.backgroundColor = mouseOverColor;
        newIndex = 3;
    }
    else if (index == 3)
    {
        document.getElementById('Pan0_3').style.backgroundColor = mouseOutColor;
        document.getElementById('Pan0_4').style.backgroundColor = mouseOutColor;
        document.getElementById('Pan1_2').style.backgroundColor = mouseOutColor;
    
        document.getElementById('Pan2_1').style.backgroundColor = mouseOverColor;
        newIndex = 4;
    }
    else if (index == 4)
    {
        document.getElementById('Pan2_1').style.backgroundColor = mouseOutColor;
    
        document.getElementById('Pan3_1').style.backgroundColor = mouseOverColor;
        document.getElementById('Pan4_4').style.backgroundColor = mouseOverColor;
        document.getElementById('Pan4_3').style.backgroundColor = mouseOverColor;
        newIndex = 5;
    }
    else if (index == 5)
    {
        document.getElementById('Pan3_1').style.backgroundColor = mouseOutColor;
        document.getElementById('Pan4_4').style.backgroundColor = mouseOutColor;
        document.getElementById('Pan4_3').style.backgroundColor = mouseOutColor;
    
        document.getElementById('Pan4_2').style.backgroundColor = mouseOverColor;
        newIndex = 6;
    }
    else if (index == 6)
    {
        document.getElementById('Pan4_2').style.backgroundColor = mouseOutColor;
    
        document.getElementById('Pan3_0').style.backgroundColor = mouseOverColor;
        document.getElementById('Pan4_0').style.backgroundColor = mouseOverColor;
        document.getElementById('Pan4_1').style.backgroundColor = mouseOverColor;
        newIndex = 7;
    }
    else if (index == 7)
    {
        document.getElementById('Pan3_0').style.backgroundColor = mouseOutColor;
        document.getElementById('Pan4_0').style.backgroundColor = mouseOutColor;
        document.getElementById('Pan4_1').style.backgroundColor = mouseOutColor;
    
        document.getElementById('Pan2_0').style.backgroundColor = mouseOverColor;
        newIndex = 0;
    }

    method = 'showLoad(' + newIndex + ');';
    if (showLoadStart == false && timerShowLoadID == null)
    {
        window.clearTimeout(timerShowLoadID);
        clearPan();
    }        
    else if (showLoadStart == true && timerShowLoadID != null)
    {
        window.clearTimeout(timerShowLoadID);
        timerShowLoadID = window.setTimeout(method,speed);
    }
    else
        timerShowLoadID = window.setTimeout(method,speed);
}

function displayCallbackError (result, context)
{
//    ToDo:
//        Umleitung auf Error Page
    document.location = errorPageLocation + window.location.pathname
    //alert ("ScriptCallBack E R R O R :: " + result);
}

function displayCallbackResult (result, context)
{

    var resultValues = result.split(";;");
    theIFrame = window.frames[poiDisplayIdentifier].window;
    
    //      Anpassungen für Integration BZO
    
    hidePOIFrame ();

    if (mapImage) mapImage.style.cursor = 'pointer';
   
    if (result != ";;")
    {

        poiFound = true;
        poiFrameVisible = true;

        theIFrame.document.location.reload (true);    
         
    } else {
        if (areaCallBackTimerID) window.clearTimeout (areaCallBackTimerID);
    }
    
    return false;   //suppress postback
}

function hidePOIFrame () {
    
        document.getElementById(poiDisplayIdentifier).style.left = '-10000px';
        document.getElementById(poiDisplayIdentifier).style.top = '-10000px';

        poiFrameVisible = false;
       
}

function displayPOIFrame () {        
            
    if ((pageClientClickX != null) && (pageClientClickY != null) && (mapImageContainer != null) ) {
    
        poiFrameInitialX = pageClientClickX + 10 + getScrollLeft (); 
        poiFrameInitialY = pageClientClickY + mapImageContainer.offsetTop - document.body.offsetTop - document.getElementById(poiDisplayIdentifier).offsetHeight - 10 + getScrollTop (); 


        document.getElementById(poiDisplayIdentifier).style.left = poiFrameInitialX + 'px';
        document.getElementById(poiDisplayIdentifier).style.top = poiFrameInitialY + 'px';
        document.getElementById(poiDisplayIdentifier).style.zIndex = 99;

        if (poiFrameInitialY < 0)
        {
            hoehe = 0;
            iframeWindow = window.frames[poiDisplayIdentifier].window;
            
            height = parseInt(document.getElementById(poiDisplayIdentifier).style.height);
            position = parseInt(document.getElementById(poiDisplayIdentifier).style.top);
            newHeight = parseInt(height + position);
            newWidth = parseInt(document.getElementById(poiDisplayIdentifier).style.width);
            
            newWidth = newWidth + 25;
            
            document.getElementById(poiDisplayIdentifier).style.height = newHeight + 'px';
            document.getElementById(poiDisplayIdentifier).style.width = newWidth + 'px';
            document.getElementById(poiDisplayIdentifier).style.top = 0;
            
            if (document.all && document.documentElement && !window.opera) {
                newHeight = newHeight - 5;
                newWidth = newWidth - 5;
            } else if (window.opera)   {
                newHeight = newHeight;
                newWidth = newWidth;
            } else {
                newHeight = newHeight;
                newWidth = newWidth;
            }
            
            iframeWindow.document.getElementById('Panel1').style.height = newHeight + 'px';
            iframeWindow.document.getElementById('Panel1').style.width = newWidth + 'px';
            iframeWindow.document.getElementById('Panel1').style.overflow = 'auto';
            iframeWindow.document.getElementById('Panel1').style.position = 'absolute';
        }
        else
        {
            iframeWindow = window.frames[poiDisplayIdentifier].window;
            
            
            iframeWindow.document.getElementById('Panel1').style.height = 'auto';
            iframeWindow.document.getElementById('Panel1').style.width = 'auto';
            iframeWindow.document.getElementById('Panel1').style.overflow = 'visible';
            iframeWindow.document.getElementById('Panel1').style.position = '';
        }
        poiFrameVisible = true;
    }
        }

function posIFrame (evt) {
    var theIFrame = window.frames[poiDisplayIdentifier].window;
    var evt =  (evt) ? evt : ((window.event) ? event : null);
    
    var callBackCoordString = null;
                            
    if (evt.shiftKey) {         // ZoomOut mit Shift Linke Maustaste
        contextZoomOut (evt);
        return false;
    }
              
    if ((Math.abs(document.getElementById('ctl00_ZHPlanDesign_ZHPlanTabControl_MapImage_PanImageShiftX').value) <= mouseSensitivity) && 
                                (Math.abs(document.getElementById('ctl00_ZHPlanDesign_ZHPlanTabControl_MapImage_PanImageShiftY').value) <= mouseSensitivity)) 
    {
    
        if (mapImage) mapImage.style.cursor = 'wait';
    
        pageClientClickX = evt.clientX;
        pageClientClickY = evt.clientY;

        if (evt.offsetX) {
            eventClientX = evt.offsetX; //evt.clientX - mapImageContainer.offsetLeft;
            eventClientY = evt.offsetY; //evt.clientY - mapImageContainer.offsetTop + document.body.offsetTop + 1;
        } else {
            eventClientX = evt.layerX; //evt.clientX - mapImageContainer.offsetLeft;
            eventClientY = evt.layerY; //evt.clientY - mapImageContainer.offsetTop + document.body.offsetTop + 1;
        }

        if ((imageClickX != null) && (imageClickY != null)) {
            imageClickX.value = eventClientX;
            imageClickY.value = eventClientY;
        }
        
        if (isAreaScriptCallBack == true) {
        
            callBackCoordString = mouseX + ";" + mouseY;
           
            if ((Math.abs(mouseX - lastAreaCallBackX) > 1) || (Math.abs(mouseY - lastAreaCallBackY) > 1)){
 
               ZHPlan_WebForm_DoCallback('ctl01',callBackCoordString,displayCallbackResult,'mouseclick',displayCallbackError,true);
               
            } else {
                mapImage.style.cursor = 'default';
            }        
            
            lastAreaCallBackX = mouseX;
            lastAreaCallBackY = mouseY;
  
        } else {
        
            callBackCoordString = eventClientX + ";" + eventClientY;
            
            if (lastCallBackTimerID) window.clearTimeout (lastCallBackTimerID);
            lastCallBackTimerID = window.setTimeout("ZHPlan_WebForm_DoCallback('ctl01'," + "'" + callBackCoordString + "'" + ",displayCallbackResult,'mouseclick',displayCallbackError,true)", callbackTimerDelay);
        }
                      
    } 
    else
    {
        poiFrameVisible = false;
    }

    return false;   //suppress postback 
}


function childIFrameSize () {

    if (window.frames[poiDisplayIdentifier]) {    
    
        var theIFrame = window.frames[poiDisplayIdentifier].window;

        adjustIFrameSize (theIFrame);
        
        displayPOIFrame ();
    }

}

function childIFrameOnMouseEnter () {
    if (lastTimerID) window.clearTimeout (lastTimerID);
}

function childIFrameOnMouseOut () {
        hidePOI();
}
    
function adjustIFrameSize (iframeWindow) {
    var newWidth = null;
    
    if (iframeWindow.document.width) {
        //Geändert 27.03.2006 F. Peter für FireFox, etc.
        var iframeElement = document.getElementById (iframeWindow.name);
        var iCount = 0;
        iframeElement.style.height = 0;
        iframeElement.style.width = 1000 + 'px';
        
        while (iframeWindow.document.getElementById('poiDivID_' + iCount)) 
        {
            unitWidth = Math.max (iframeWindow.document.getElementById('poiDivID_' + iCount).offsetWidth, iframeWindow.document.getElementById('poiDivHeader_' + iCount).offsetWidth);
            
            //if (iframeWindow.document.getElementById('poiDivDetailsFotos_' + iCount).offsetWidth > unitWidth)
                //unitWidth = iframeWindow.document.getElementById('poiDivDetailsFotos_' + iCount).offsetWidth;
            
            newWidth = Math.max(newWidth, unitWidth);
            iCount = iCount + 1;
        }

        if (newWidth != null)
            iframeElement.style.width = newWidth + 'px';
        if (iframeWindow.document.documentElement.scrollHeight != null)
            iframeElement.style.height = iframeWindow.document.documentElement.scrollHeight + 1 + 'px';
                          
    } else if ((document.getElementById && !document.documentElement) || window.opera)   {
     //Geändert 27.06.2006 F. Peter für Opera
        var iframeElement = document.getElementById (iframeWindow.name);
        var iCount = 0;
        
        newHeight = 0;
        newWidth = 0;
        iframeElement.style.overflow = 'hidden';
        
        iframeElement.style.height = 0;
        iframeElement.style.width = 1000 + 'px';
        
        while (iframeWindow.document.getElementById('poiDivID_' + iCount)) 
        {
            unitWidth = Math.max(iframeWindow.document.getElementById('poiDivID_' + iCount).offsetWidth, iframeWindow.document.getElementById('poiDivHeader_' + iCount).offsetWidth);
            newWidth = Math.max(newWidth, unitWidth);
            
            newHeight = newHeight + iframeWindow.document.getElementById('poiDivID_' + iCount).offsetHeight + iframeWindow.document.getElementById('poiDivHeader_' + iCount).offsetHeight + iframeWindow.document.getElementById('poiDivDetails_' + iCount).offsetHeight;
            iCount = iCount + 1;
        }
                    
        if (newWidth != null)
            iframeElement.style.width = newWidth + 'px';
        if (newHeight != null)
            iframeElement.style.height = newHeight + 'px';
            
    } else if (document.all) {
    
        var iframeElement = document.all[iframeWindow.name];
        
        newWidth = 0;
        iCount = 0;

        iframeElement.style.height = 0;
        
        while (iframeWindow.document.getElementById('poiDivID_' + iCount)) 
        {
            unitWidth = Math.max (iframeWindow.document.getElementById('poiDivID_' + iCount).offsetWidth, iframeWindow.document.getElementById('poiDivHeader_' + iCount).offsetWidth);
            newWidth = Math.max(newWidth, unitWidth);
            iCount = iCount + 1;
        }
                    
        if (iframeWindow.document.compatMode && iframeWindow.document.compatMode != 'BackCompat') 
        {
            iframeElement.style.height = iframeWindow.document.documentElement.scrollHeight + 4 + 'px';
            
            iframeElement.style.width = newWidth + 4 + 'px';
        } else {
            iframeElement.style.height = iframeWindow.document.body.scrollHeight + 4 + 'px';
            
            iframeElement.style.width = newWidth + 4 + 'px';
        }
        
    }
}

function getScrollLeft () {

    var scrollLeft;
    
    if (self.pageYOffset) // all except Explorer
    {
        scrollLeft = self.pageXOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop)     // Explorer 6 Strict
    {
        scrollLeft = document.documentElement.scrollLeft;
    }
    else if (document.body) // all other Explorers
    {
        scrollLeft = document.body.scrollLeft;
    }
    return scrollLeft;
}

function getScrollTop () {

    var scrollTop;
    
    if (self.pageYOffset) // all except Explorer
    {
        scrollTop = self.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop)     // Explorer 6 Strict
    {
        scrollTop = document.documentElement.scrollTop;
    }
    else if (document.body) // all other Explorers
    {
        scrollTop = document.body.scrollTop;
    }

    return scrollTop;
}
