﻿// JScript File

var mapImageContainerID='basicMapImageContainer';
var mapImageID='ctl00_ZHPlanDesign_ZHPlanTabControl_MapImage_imgBtnMap';

var btnDistanceMeasureID='imgMeasureDistance';

var dotImage="./ZPL/images/measureDistanceDot.gif";
var meassureDistanceOffImg = "./ZPL/images/measureDistanceOff.gif"
var meassureDistanceOnImg = "./ZPL/images/measureDistanceOn.gif";

var measureDistanceTextID = 'measureDistanceText';
var measureDistanceContainerID = 'measureDistanceContainer';
var measureDistanceDisplayText = 'Distanz: ';
var measureDistanceDisplayUnit = ' m';
var measureDistanceOutputElement = null;

var arrRubName=new Array();
var arrRubLayerInitialX=new Array();
var arrRubLayerInitialY=new Array();
var arrDotsName=new Array();

var currentMeasure=0;
var numDecimals=0;
var units = Math.pow(10,numDecimals);

var shiftDistanceX = null;
var shiftDistanceY = null;

var anzRubDots = 6;
var currentPxSize = 0;

var measureDistancePixelSize = 'ctl00_ZHPlanDesign_ZHPlanTabControl_MapImage_ImagePixelMeasure';

var mapImage =null;
var mapImageContainer = null;

var evt = null;
var startPanX = null;
var startPanY = null;
var isPanning = false;

var startDistanceX = null;
var startDistanceY = null;
var mouseX = null;
var mouseY = null;
var previousMouseX = null;
var previousMouseY = null;

var mapImageShiftX = null;
var mapImageShiftY = null;
var imageClickX = null;
var imageClickY = null;
var imageClickShiftKey = false;

var ovImage = null;
var ovImageHeight = null;
var ovImageWidth = null;

var panClipTop = null;
var panClipLeft = null;
var panClipButtom = null;
var panClipRight = null;

var mouseSensitivity = 2;
var timerDelay = 1500;          // msec
var callbackTimerDelay = 200;   // msec

var lastTimerID = null;
var lastCallBackTimerID = null;
var globalEvt = null;

var isDistanceMeasuring = false;
var isStartDistanceMeasuring = false;

// BZO
var isAreaScriptCallBack = false;
var areaCallBackTimerID = null;
var areaMousePositionEvent = null;

function makeMozClick(evt)
{
    __IMAGEMAP_onClick(0, evt)
}

function changeVisibility()
{
    var ie = false;
        if (document.all)
            ie = true;
        else
            document.getElementById ('basicMapImageContainer').style.visibility = 'hidden';
}

function MouseOverImageInitPage () {

    //
    // ToDo: Umstellen auf variable ID's
    //
    
    if (!mapImageContainer) mapImageContainer = document.getElementById ('basicMapImageContainer');
    if (!mapImageContainer) return;

    if (!mapImage) mapImage = document.getElementById ('ctl00_ZHPlanDesign_ZHPlanTabControl_MapImage_imgBtnMap');  
    if (!mapImage) return;
        
    mapImageContainer.onmousedown = startMouseCaptureMapImage;
    mapImageContainer.onmouseup = stopMouseCaptureMapImage;
    mapImageContainer.onmousemove = panMapImage;
    mapImageContainer.onmouseout = panStop;
    
    mapImageContainer.oncontextmenu = contextZoomOut;
    mapImage.style.cursor = 'default';

    measureDistanceOutputElement = document.getElementById (measureDistanceTextID)

    mapImageShiftX = document.getElementById ('ctl00_ZHPlanDesign_ZHPlanTabControl_MapImage_PanImageShiftX');
    mapImageShiftY = document.getElementById ('ctl00_ZHPlanDesign_ZHPlanTabControl_MapImage_PanImageShiftY');
    
    imageClickX = document.getElementById ('ctl00_ZHPlanDesign_ZHPlanTabControl_MapImage_ImageClickX');
    imageClickY = document.getElementById ('ctl00_ZHPlanDesign_ZHPlanTabControl_MapImage_ImageClickY');
        
    ovImage = document.getElementById ('ctl00_ZHPlanDesign_ZHPlanOverviewMapImage_imgBtnOverview');    
    ovImageHeight = document.getElementById ('ctl00_ZHPlanDesign_ZHPlanOverviewMapImage_OvImageHeight');
    ovImageWidth = document.getElementById ('ctl00_ZHPlanDesign_ZHPlanOverviewMapImage_OvImageWidth');
        
    ovImageHeight.value = ovImage.offsetHeight;
    ovImageWidth.value = ovImage.offsetWidth;

    mapImageContainer.style.left = 0 + 'px'
    mapImageContainer.style.top = 0 + 'px'
    mapImageContainer.style.width = mapImage.offsetWidth + 'px';
    mapImageContainer.style.height = mapImage.offsetHeight + 'px';

    panClipTop =  mapImageContainer.offsetTop;
    panClipButtom = panClipTop + mapImageContainer.offsetHeight; 
    panClipLeft = mapImageContainer.offsetLeft;
    panClipRight = panClipLeft + mapImageContainer.offsetWidth;
        
    //Loading
    window.clearTimeout(timerShowLoadID);
    clearPan();

    if (document.getElementById ('basicMapImageContainer').style.visibility == 'hidden' || document.getElementById ('basicMapImageContainer').style.visibility == '')
    {
        document.getElementById ('basicMapImageContainer').style.visibility = 'visible';
    }
    
    //TreeView
    setLastScrollValue();
}

function startDistanceMeasure ()
{
    btnDistanceMeasure = document.getElementById (btnDistanceMeasureID);
    
    if (btnDistanceMeasure) {
        btnDistanceMeasure.src = meassureDistanceOnImg
        if (mapImage)
            mapImage.style.cursor = 'default';
        
        if (document.getElementById(measureDistanceContainerID).style.display != 'none')
            document.getElementById(measureDistanceContainerID).style.display = 'none';
        
        mouseX = null;
        mouseY = null;
        
        hideRubLayers ();
        calcDistance(0, 0, currentPxSize);    
        
        if (isDistanceMeasuring || isStartDistanceMeasuring)
        {
            isDistanceMeasuring = false;
            isStartDistanceMeasuring = false
            btnDistanceMeasure.src = meassureDistanceOffImg;
        } else { 
            currentPxSize = document.getElementById (measureDistancePixelSize).value;
            isStartDistanceMeasuring = true;
        }
    }
}

function stopDistanceMeasure ()
{
    isDistanceMeasuring = false;
    isStartDistanceMeasuring = false;
                
    if ((mouseX) && (mouseY)) {
        moveRubLayers(mouseX, mouseY, true);
        calcDistance(mouseX-startDistanceX, mouseY-startDistanceY, currentPxSize);
    }
    
	for(var i=0;i<anzRubDots;i++)
	{
		arrRubLayerInitialX[i] =  parseInt(getLayerStyle(arrRubName[i]).left);
		arrRubLayerInitialY[i] =  parseInt(getLayerStyle(arrRubName[i]).top);
	}

    btnDistanceMeasure.src = meassureDistanceOffImg;
}

function startMouseCaptureMapImage (evt) {
    var evt = (evt) ? evt : ((window.event) ? event : null);
    
    if (eventAvailable == true)
    {
        if (evt.button == 2 && window.opera)
        {
            contextZoomOut(evt);
        }
    
	    evt.cancelBubble = true;
	    if (evt.stopPropagation) evt.stopPropagation();

        if (lastTimerID) window.clearTimeout (lastTimerID);
        
    //	if (evt.target) targ = evt.target;
    //	else if (evt.srcElement) targ = evt.srcElement;

        if (evt.offsetX) {
                eventX = evt.offsetX;
                eventY = evt.offsetY;
        } else {
                eventX = evt.layerX;
                eventY = evt.layerY;
        }


        if (((eventX > 0 ) && (eventX < panClipRight)) &&
            ((eventY > 0 ) && (eventY < panClipButtom)))  {

            startPanX = evt.clientX;
            startPanY = evt.clientY;

            shiftDistanceX = startPanX - eventX - panClipLeft;
            shiftDistanceY = startPanY - eventY - panClipTop; 
            
            startDistanceX = eventX + panClipLeft; 
            startDistanceY = eventY + panClipTop;
            
            if (isStartDistanceMeasuring == true) {
                createRubDotLayers(anzRubDots);
	            startDistanceMeasuring = false;
	            isDistanceMeasuring = true;
            } else {
                imageClickShiftKey = evt.shiftKey;
                if (evt.button == 1 || evt.button == 0)
                {
                    isPanning = true;
                }
            }
        }
    }
    return false;
}

function stopMouseCaptureMapImage (evt) {

    var evt = (evt) ? evt : ((window.event) ? event : null);
 
 	evt.cancelBubble = true;
	if (evt.stopPropagation) evt.stopPropagation();

    if (isPanning == true) {
    
        showSplashImage();
        
        stopPanX = evt.clientX;
        stopPanY = evt.clientY;
        
        mapImageShiftX.value = stopPanX - startPanX;
        mapImageShiftY.value = stopPanY - startPanY;

        if ((Math.abs(mapImageShiftX.value) < mouseSensitivity) && (Math.abs(mapImageShiftY.value) < mouseSensitivity) ) {    
            theForm.__IMAGEMAP_TYPE.value = ""; 
        } else {
            theForm.__IMAGEMAP_TYPE.value = "pan";
        }
        
        isPanning = false;
                
    } else if (isDistanceMeasuring == true) {

        theForm.__IMAGEMAP_TYPE.value = "suppressPostback"; 

        stopDistanceMeasure ();
    }
    
    return false;
}

function panMapImage (evt) {

    if (areaCallBackTimerID) window.clearTimeout (areaCallBackTimerID);

    var evt = (evt) ? evt : ((window.event) ? event : null);
    
  	evt.cancelBubble = true;
	if (evt.stopPropagation) evt.stopPropagation();

    if (evt.offsetX) {
        eventX = evt.offsetX;
        eventY = evt.offsetY;
    } else {
        eventX = evt.layerX;
        eventY = evt.layerY;
    }
        
    if (isPanning == true && eventAvailable == true) {
        if (mapImage)
            mapImage.style.cursor = 'move';

        if (((eventX > 0 ) && (eventX < panClipRight)) &&
            ((eventY > 0 ) && (eventY < panClipButtom)))  {

            panShiftX = evt.clientX - startPanX;
            panShiftY = evt.clientY - startPanY;
            
            mapImage.style.left = panShiftX + 'px';
            mapImage.style.top = panShiftY + 'px';

            if (poiFrameVisible == true) {
            
                poiDisplay = document.getElementById(poiDisplayIdentifier);
                poiDisplay.style.left = poiFrameInitialX + panShiftX + 'px';
                poiDisplay.style.top = poiFrameInitialY + panShiftY + 'px'; 
             }

             shiftRubLayers (panShiftX, panShiftY);
            
        } else {
            stopMouseCaptureMapImage (evt);
            theForm.__IMAGEMAP_TYPE.value = "pan";
            if (document.all && document.documentElement && !window.opera)
                mapImage.click();
            else
                makeMozClick(evt); 
        }
 

    } else if (isDistanceMeasuring == true) {

        if (((eventX > 0 ) && (eventX < panClipRight)) &&
            ((eventY > 0 ) && (eventY < panClipButtom)))  {

    	    mouseX = evt.clientX - shiftDistanceX; // - document.body.scrollLeft;
    	    mouseY = evt.clientY - shiftDistanceY; // - document.body.scrollTop;

    	    moveRubLayers(mouseX, mouseY, false);

            calcDistance(mouseX-startDistanceX, mouseY-startDistanceY, currentPxSize);

        } else {

            if (evt.target) targ = evt.target;
            else if (evt.srcElement) targ = evt.srcElement;
            
            if (targ.name != 'click') stopMouseCaptureMapImage (evt);            
        }
        
    } else if (isAreaScriptCallBack == true) {
    
        // BZO
        
        mouseX = eventX;
        mouseY = eventY;

        areaMousePositionEvent = cloneObject(evt);
        areaCallBackTimerID = window.setTimeout("showPOI ()", 500);
        
        previousMouseX = mouseX;
        previousMouseY = mouseY;
        
    }        
        
    return false;
}

function panStop(evt)
{

    if (areaCallBackTimerID) window.clearTimeout (areaCallBackTimerID);

    var evt = (evt) ? evt : ((window.event) ? event : null);
    var fromElement = null;
    var stopPaning = false;
    
        if (evt.relatedTarget)
        {
            fromElement = evt.relatedTarget;
            tempElement = fromElement.id
            tempElement = tempElement.toString();
            pos = tempElement.indexOf('MapImage_area')
            
            if (fromElement == document.location + '#' || pos >= 0)
                stopPaning = false;
            else
            {
                stopPaning = true;
            }    
        }
        else if (evt.toElement)
        {
            fromElement = evt.toElement.id;
            
            if (fromElement == 'ctl00_ZHPlanDesign_ZHPlanTabControl_MapImage_imgBtnMap')
                stopPaning = false;
            else
                stopPaning = true;
        }
        else
            stopPaning = true;
            
    if (isPanning == true && stopPaning == true)
    {
        stopMouseCaptureMapImage (evt);
        theForm.__IMAGEMAP_TYPE.value = "pan";
        if (document.all && document.documentElement && !window.opera)
            mapImage.click();
        else
            makeMozClick(evt); 
    }
}

function __IMAGEMAP_onClick(area, evt) {

    if (areaCallBackTimerID) window.clearTimeout (areaCallBackTimerID);

    var evt = (evt) ? evt : ((window.event) ? event : null);
    
    if ((!theForm.onsubmit || theForm.onsubmit() != false) && (eventAvailable == true))
    {
        theForm.__EVENTTARGET.value = "ctl00$ZHPlanDesign$ZHPlanTabControl$MapImage$imgBtnMap";
        theForm.__EVENTARGUMENT.value = "";
        theForm.__IMAGEMAP_AREA.value = area;
    	
        if (evt.offsetX) 
        {
            eventClientX = evt.offsetX;
            eventClientY = evt.offsetY;
        } 
        else 
        {
            eventClientX = evt.layerX;
            eventClientY = evt.layerY;
        }
    	
        theForm.__IMAGEMAP_X.value = eventClientX;
        theForm.__IMAGEMAP_Y.value = eventClientY;
                                
        if ((theForm.__IMAGEMAP_TYPE.value == '') && (imageClickShiftKey == true)) 
        {
            showSplashImage();
            theForm.__IMAGEMAP_TYPE.value = 'zoomOut';
            zoomOutSmoothTransition(eventClientX, eventClientY, returnUpperScale());
        }
        else if ((theForm.__IMAGEMAP_TYPE.value == 'zoomOut') && (imageClickShiftKey == false)) 
        {
            showSplashImage();
            zoomOutSmoothTransition(eventClientX, eventClientY, returnUpperScale());
        }
        if ((theForm.__IMAGEMAP_TYPE.value == '') && (imageClickShiftKey == false))
        {
            showSplashImage();
            theForm.__IMAGEMAP_TYPE.value = 'zoomIn';
            zoomInSmoothTransition(eventClientX, eventClientY, returnLowerScale());
        }
        if (theForm.__IMAGEMAP_TYPE.value != 'suppressPostback')
        {
            blockTreeNodeToggle();
            eventAvailable = false;
            theForm.submit();
        }
    }
}

function contextZoomOut (evt) {
  
    var evt = (evt) ? evt : ((window.event) ? event : null);

    if (eventAvailable == true)
    {
        evt.cancelBubble = true;
        if (evt.stopPropagation) evt.stopPropagation();

        if (evt.offsetX) {
            eventClientX = evt.offsetX;
            eventClientY = evt.offsetY;
        } else {
            eventClientX = evt.layerX;
            eventClientY = evt.layerY;
        }

        //zoomOutSmoothTransition(eventClientX, eventClientY, returnUpperScale());

        theForm.__IMAGEMAP_TYPE.value = "zoomOut";
        if (document.all && document.documentElement && !window.opera)
            mapImage.click();
        else
            makeMozClick(evt); 
      
        showSplashImage();
    }
   
    return false;                    
}

function zoomOutSmoothTransition(x, y, zoomOutFaktor)
{
    var styleX = 0.0;
    var styleY = 0.0;
    var width = 0;
    var height = 0;
    var oldWidth = 0;
    var oldHeight = 0;
    var panX = x;
    var panY = y;
    
    if (zoomOutFaktor != 'nothing' && eventAvailable == true)
    {
        eventAvailable = false;
        blockTreeNodeToggle();
        oldWidth = document.getElementById('ctl00_ZHPlanDesign_ZHPlanTabControl_MapImage_imgBtnMap').width;
        oldHeight = document.getElementById('ctl00_ZHPlanDesign_ZHPlanTabControl_MapImage_imgBtnMap').height;
           
        if (panX == -1 && panY == -1)
        {
            panX = oldWidth / 2;
            panY = oldHeight / 2;
        }
               
        width = oldWidth / zoomOutFaktor;
        height = oldHeight / zoomOutFaktor;
        
        styleY = (oldHeight - height) / 2;
        
        if (panX <= (oldWidth / 2))
        {
            styleX = (((oldWidth / 2) - panX)  / zoomOutFaktor);
        }
        else if (panX > (oldWidth / 2))1
        {
            styleX = '-' + ((panX - (oldWidth / 2)) / zoomOutFaktor);
        }

        if (panY <= (oldHeight / 2))
        {
            styleY = styleY + (((oldHeight/2) - panY) / zoomOutFaktor);
        }
        else if (panY > (oldHeight / 2))
        {
            styleY = styleY - ((panY - (oldHeight/2)) / zoomOutFaktor);
        }

        mapSmoothTransition(oldWidth, oldHeight, parseInt(styleX), parseInt(styleY), width, height, 0);
    }
}

function zoomInSmoothTransition(x, y, zoomInFaktor)
{
    var styleX = 0.0;
    var styleY = 0.0;
    var width = 0;
    var height = 0;
    var oldWidth = 0;
    var oldHeight = 0;
    var panX = x;
    var panY = y;

    if (zoomInFaktor != 'nothing' && eventAvailable == true)
    {
        eventAvailable = false;
        blockTreeNodeToggle();
        oldWidth = document.getElementById('ctl00_ZHPlanDesign_ZHPlanTabControl_MapImage_imgBtnMap').width;
        oldHeight = document.getElementById('ctl00_ZHPlanDesign_ZHPlanTabControl_MapImage_imgBtnMap').height;
           
        if (panX == -1 && panY == -1)
        {
            panX = (oldWidth / 2) ;
            panY = (oldHeight / 2);
        }
               
        width = oldWidth * zoomInFaktor;
        height = oldHeight * zoomInFaktor;
        
        //styleX = '-' + ((panX * zoomInFaktor) - (oldWidth/2));
        //styleY = '-' + ((panY * zoomInFaktor) - (oldHeight/2));
        
        /*if ((panX * zoomInFaktor) <= (oldWidth / 2))
        {
            styleX =  ((panX * zoomInFaktor) - (oldWidth/2));
        }
        else if ((panX * zoomInFaktor) > (oldWidth / 2))
        {
            styleX =  ((oldWidth/2) - (panX * zoomInFaktor));
        }

        if ((panY * zoomInFaktor) <= (oldHeight / 2))
        {
            styleY = ((panY * zoomInFaktor) - (oldHeight/2));
        }
        else if ((panY * zoomInFaktor) > (oldHeight / 2))
        {
           styleY = ((oldHeight/2) - (panY * zoomInFaktor));
        }*/
        
        styleX =  ((oldWidth/2) - (panX * zoomInFaktor));
        styleY = ((oldHeight/2) - (panY * zoomInFaktor));
               
        mapSmoothTransition(oldWidth, oldHeight, parseInt(styleX), parseInt(styleY), width, height, 0);
    }
}

function mapSmoothTransition(oldWidth, oldHeight, styleX, styleY, width, height, counter)
{  
    var widthStep = 0;
    var heightStep = 0;
    var styleXStep = 0;
    var styleYStep = 0;
    
    counter = counter + 1;
    widthStep = ((oldWidth - width) / 10) * counter;
    heightStep = ((oldHeight - height) / 10) * counter;
    styleXStep = (styleX / 10) * counter;
    styleYStep = (styleY / 10) * counter;
    
    document.getElementById('ctl00_ZHPlanDesign_ZHPlanTabControl_MapImage_imgBtnMap').width = oldWidth - widthStep;
    document.getElementById('ctl00_ZHPlanDesign_ZHPlanTabControl_MapImage_imgBtnMap').height = oldHeight - heightStep;
    document.getElementById('ctl00_ZHPlanDesign_ZHPlanTabControl_MapImage_imgBtnMap').style.left = styleXStep + 'px';
    document.getElementById('ctl00_ZHPlanDesign_ZHPlanTabControl_MapImage_imgBtnMap').style.top = styleYStep + 'px'; 
    
    repeat='mapSmoothTransition(' + oldWidth + ', ' + oldHeight + ', ' + styleX + ', ' + styleY + ', ' + width + ', ' + height + ', ' + counter + ');';
    
    
    if (counter < 10)
        timerID=setTimeout(repeat, 15);
}
    
function captureOvImageSize (evt) {

    var evt = (evt) ? evt : ((window.event) ? event : null);

    if (ovImageHeight) ovImageHeight.value = ovImage.offsetHeight;
    if (ovImageWidth) ovImageWidth.value = ovImage.offsetWidth;

}

function showPOI (evt) {
        
    if (isAreaScriptCallBack == true) {
    
        if ((Math.abs(previousMouseX - mouseX) > mouseSensitivity) ||  (Math.abs(previousMouseY - mouseY) > mouseSensitivity)) return false;

        globalEvt = areaMousePositionEvent;
        theForm.__IMAGEMAP_TYPE.value = "showAreaInfo"
        
    } else {
    
        globalEvt = (evt) ? evt : ((window.event) ? event : null);
        
    }

    window.clearTimeout (lastTimerID);
    
    if (areaCallBackTimerID) window.clearTimeout (areaCallBackTimerID);
    
    posIFrame(globalEvt);
    
}

function hidePOI () {

    if (mapImage)
    {
        mapImage.style.cursor = 'default';

        if (lastCallBackTimerID) window.clearTimeout (lastCallBackTimerID);

        lastTimerID = window.setTimeout ( "hidePOIFrame()", timerDelay);
    }
}


//
// =======================  Hilfsfunktionen Distanzmessung  =====================================
//

function createRubDotLayers(anz)
{
	for(var i=0;i<anz;i++){
		arrRubName[i]="rub1_"+i;
		if(!hasLayer(arrRubName[i])){
		    var newLayerName=createDynaLayer(arrRubName[i],0,0,11,11,true,dotImage);}
		hideLayer(arrRubName[i]);
	}
}

function createDynaLayer(name,left,top,width,height,visible,image)
{
	if(!document.body.insertAdjacentHTML){
				
		var newLyr=document.createElement("div");
		newLyr.id=name;
		newLyr.style.position="absolute";
		newLyr.style.overflow="hidden";
		newLyr.style.left=left+"px";
		newLyr.style.top=top+"px";
		newLyr.style.width=width+"px";
		newLyr.style.height=height+"px";
		newLyr.style.visibility=(visible?'visible;':'hidden;');
		
		//zIndex added from F.Peter 2006-06-08
		newLyr.style.zIndex = '100';
		
		var imgLyr=document.createElement("img");
		imgLyr.setAttribute("src",image);
		newLyr.appendChild(imgLyr);
		
		var containerLayer=document.getElementById(mapImageContainerID);
		var lastLayer=document.getElementById(mapImageID);
		
		containerLayer.insertBefore(newLyr, lastLayer);
		
	}else{
	
		var txt='<div id="'+name+'" style="position:absolute;overflow:hidden;left:'+left+'px;top:'+top+'px;width:'+width+'px;height:'+height+'px;z-index:100;' + 
				' visibility:'+(visible?'visible;':'hidden;')+'">';
		txt=txt + '<img name="click" border=0 src="'+image+'" width=11 height=11 hspace=0 vspace=0>';
		txt=txt+"</div>";
		
		basicMapImageContainer.insertAdjacentHTML( "afterEnd",txt);
	}
	
	return name;
}

function hideRubLayers()
{
	for(var i=0;i<anzRubDots;i++)
	{
		if (hasLayer(arrRubName[i])) hideLayer(arrRubName[i]);
	}
}

function shiftRubLayers(deltaX, deltaY)
{

		for(var i=0;i<anzRubDots;i++)
		{
		    if ((hasLayer (arrRubName[i])) && (getLayerStyle(arrRubName[i]).visibility == 'visible')) {
		    
		        getLayerStyle(arrRubName[i]).left = arrRubLayerInitialX[i] + deltaX; 
		        getLayerStyle(arrRubName[i]).top = arrRubLayerInitialY[i] + deltaY; 
            }
		}
}

function moveRubLayers(x,y,finalMove)
{
	var anz = anzRubDots;
	var dotkl_width=12;
	var mozillaLineshift = document.getElementById('Pan0_1').clientHeight;

    setDistanceContainer(startDistanceX, startDistanceY, x, y);
        
	loop = anz - 1;
    if (finalMove == true) loop = anz;

		for(var i=0;i<loop;i++)
		{
			showLayer(arrRubName[i]);
			
			if (window.innerHeight != null) //Für FireFox, Mozilla, Netscape, Opera zuständig
            {
			    moveLayer(arrRubName[i],(startDistanceX +i*((x-startDistanceX)/(anz-1))) - (dotkl_width * 1.25),(startDistanceY+i*((y-startDistanceY)/(anz-1)))-dotkl_width - mozillaLineshift);
		    }
            else if (document.body != null && document.body.offsetHeight != null)   //Für IE zuständig
            {
                moveLayer(arrRubName[i],(startDistanceX +i*((x-startDistanceX)/(anz-1)))-dotkl_width,(startDistanceY+i*((y-startDistanceY)/(anz-1)))-dotkl_width/2);
            }
        }
}

function setDistanceContainer(startX, startY, endX, endY)
{
    var difX = endX - startX;
    var difY = endY - startY;
	var paddingX, paddingY;
    var measureContainer = document.getElementById(measureDistanceContainerID);
    var dif = 20;
    var mouseDif = 10;
    
    if (difX <= 0)
        paddingX = - measureContainer.clientWidth / 2;
    else
        paddingX = - measureContainer.clientWidth / 2;
       
    if (difY <= 0)
        paddingY = - (dif + measureContainer.clientHeight + mouseDif);
    else
        paddingY = dif + mouseDif;
    
    moveLayer(measureDistanceContainerID, endX + paddingX, endY + paddingY);
    
    if (document.getElementById(measureDistanceContainerID).style.display != '')
        document.getElementById(measureDistanceContainerID).style.display = '';
}

function hasLayer(name)
{
	var result=false;
	
	if (document.getElementById (name) != null) result=true;
	
	return result;
}

function showLayer(name)
{
	var layerStyle=getLayerStyle(name);
				
	layerStyle.visibility="visible";
}

function moveLayer(name,x,y)
{
	var layerStyle=getLayerStyle(name);

    // document.getElementById ('Output').innerHTML = x + "//" + y;
	layerStyle.left = x + 'px'
	layerStyle.top = y + 'px'
}

function shiftLayer(name, deltaX, deltaY)
{
	var layerStyle=getLayerStyle(name);

	layerStyle.left = parseInt(layerStyle.left) + deltaX + 'px'
	layerStyle.top = parseInt(layerStyle.top) + deltaY + 'px'
}

function hideLayer(name)
{
	var layerStyle=getLayerStyle(name);

	layerStyle.visibility="hidden";
}

function getLayerStyle(name)
{
	    return (document.getElementById (name).style);
}						

function calcDistance(mXpx,mYpx,pxSize)
{
	mDistance=Math.sqrt(Math.pow(mXpx*pxSize,2)+Math.pow(mYpx*pxSize,2));
	currentMeasure=parseInt(mDistance*units + 0.5) / units;

    measureDistanceOutputElement.innerHTML = measureDistanceDisplayText + currentMeasure + measureDistanceDisplayUnit
}

function cloneObject(from) 
{
    to = {};
    for (i in from) {
        to[i] = from[i];
    }
    return to;
}