/*********************************************************************************
 Copyright (c) 2002-2005 Armin Burger
 Copyright (c) 2005-2006 GEOSIGNAL - www.geosignal.fr - contact@geosignal.fr

 
 Permission is hereby granted, free of charge, to any person obtaining 
 a copy of this software and associated documentation files (the "Software"), 
 to deal in the Software without restriction, including without limitation 
 the rights to use, copy, modify, merge, publish, distribute, sublicense, 
 and/or sell copies of the Software, and to permit persons to whom the Software 
 is furnished to do so, subject to the following conditions:
 
 The above copyright notice and this permission notice shall be included 
 in all copies or substantial portions of the Software.
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 
 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR OR 
 COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 
 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 
 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
**********************************************************************************/

function RechercheAvancee(visible) {
	var oRecherche = document.getElementById('recherche');
    if(visible) {    	
        oRecherche.style.visibility='visible';
    } else {
        oRecherche.style.visibility='hidden';
    }
}
 
//Debut Ring
//Initialise les parametres de la flèche
//______________________________________
function initSmokering() {
  Img=new Image();
  Img.src="images/ring4.gif";  //Pre-load
  S=null;
  fadeStep = 3;
  fade = 40;
  currentStep=0;
  step = 1;
  x=mapW/2+1;
  y=mapH/2+1;
  nb=0;
  expandSmokering();
}

//Active la fleche
//________________
function expandSmokering(){
    if (nb < 3) {
       if (nb == 1)
       {
         document.getElementById('pic').style.visibility='visible';
         document.getElementById('pic').zIndex = 100;
        // document.getElementById('pic2').zIndex = 100;
        // document.getElementById('pic3').zIndex = 100;
       }

       document.getElementById('pic').height=currentStep*2;
       document.getElementById('pic').width=currentStep*2;
       document.getElementById('pic').style.top=y+(-currentStep);
       document.getElementById('pic').style.left=x+(-currentStep);
       document.getElementById('pic').style.filter='alpha(opacity='+fade+');'; 
       currentStep+=step;
       if (currentStep > 30) fade-=fadeStep;
       if (fade < -20) {
           currentStep=0;
           fade=40;
           nb=nb+1;
       }

       S=setTimeout('expandSmokering()',60);
    }
    else {
      //  document.getElementById('pic3').zIndex = 0;
      //  document.getElementById('pic2').zIndex = 0;
        document.getElementById('pic').zIndex = 0;
        document.getElementById('pic').style.visibility='hidden';
    }
}
//Fin Ring

//global var
var preloadImgArray = []; 
function preloadImg() {
    var fct = arguments[arguments.length - 1];
    var len = arguments.length - 1;
    var cpt = 0;

    preloadImgArray = [];   
    for(var i = 0; i < arguments.length - 1; i++) {
        preloadImgArray[i] = new Image();
        preloadImgArray[i].onload = function() {
            cpt++;
            if(cpt == len) {
                fct();
            }
        }
        preloadImgArray[i].src = arguments[i];
    }
}

/**************************************************** 
 * LOAD MAP IMAGE INTO PARENT WINDOW MAP DIV
 * Reset parameters of some DIV's
 ****************************************************/

 function loadMapImg2() {
    var argv = [];
    var index = 0;

    for(var i = 0; i < arguments.length - 1; i += 4) {
        var arr = [];
            
        arr[0] = document.getElementById(arguments[i]); // objet image
        arr[1] = arguments[i + 1]; // image source
        arr[2] = arguments[i + 2]; // opacité actuelle
        arr[3] = arguments[i + 3]; // position
        argv[index] = arr;
        index++;
    }

    crossfade(argv, arguments[arguments.length - 1]);
}

function loadMapImg() {
    for(var i = 0; i < arguments.length; i += 2) {
        var theMapImg = document.getElementById(arguments[i]);
        theMapImg.src = arguments[i + 1];
    }   
}

function resetMapBgImgParams() {
    var theMapBgImg = document.getElementById('mapBgImg');
    var theMapBgImgL = document.getElementById('mapBgLayer');

    theMapBgImg.style.width = mapW;
    theMapBgImg.style.height = mapH;
    
    theMapBgImgL.style.top  = 0;  
    theMapBgImgL.style.left = 0;
    theMapBgImgL.style.width = mapW;
    theMapBgImgL.style.height = mapH;
    theMapBgImgL.style.clip = 'rect(auto auto auto auto)';  // NEEDED TO RESET DIV TO NON-CLIPPED AND ORIGINAL SIZE

    maploading = false;
}
 
function resetMapImgParams() {
    var theMapImgL = document.getElementById("mapimgLayer");
    var theMapImg = document.getElementById("mapImg");
    
    theMapImg.style.width = mapW;
    theMapImg.style.height = mapH;
    
    theMapImgL.style.top  = 0;  
    theMapImgL.style.left = 0;
    theMapImgL.style.width = mapW;
    theMapImgL.style.height = mapH;
    theMapImgL.style.clip = 'rect(auto auto auto auto)';  // NEEDED TO RESET DIV TO NON-CLIPPED AND ORIGINAL SIZE
    
    document.getElementById("zoombox").style.visibility = 'hidden';
    document.getElementById('loading').style.visibility = 'hidden';
    
    maploading = false;
}



function init() {
    
    resizeDiv(true);
    initToc();
    writeTocMenu('toc_menu.php?' + SID + '&action=write'+ SID + '&NumMenu=1', '');
    // Set zoombox class for Opera and Konqueror to non-semitransparent
    if (navigator.userAgent.match(/Opera|Konqueror/i)) {
        document.getElementById("zoombox").className = 'zoombox_nontransp';
    }

    createZSliderSwap("tslider", "mapBgImg", "mapImg");
    createZSlider('zslider');
    // createSearchOptions();
    domouseclick('zoomin');
    setTbTDButton('zoomin');       
    
    // Masque le div de chargement
    document.getElementById("chargement").style.visibility = 'hidden'; 
}

var _moveMapIntervalId = 0;
function moveMap(left, top, fct) {
  var moveMapPixelStep = 40;
  var moveMapTimeStep  = 1;
  
  var mapimgLayer   = document.getElementById('mapimgLayer');
  var mapbgimgLayer = document.getElementById('mapBgLayer');
  var curL          = objLeft(mapimgLayer);;
  var curT          = objTop(mapimgLayer);
  var endL          = curL + left;
  var endT          = curT + top;
  var pixelStepL    = Math.abs(left) > Math.abs(top) ? moveMapPixelStep : Math.abs(left) / Math.abs(top) * moveMapPixelStep;
  var pixelStepT    = Math.abs(top) > Math.abs(left) ? moveMapPixelStep : Math.abs(top) / Math.abs(left) * moveMapPixelStep;
  var intervalFct   = function() {
    var exit = true;

    if(left > 0) {
      curL += pixelStepL;
      if(parseInt(curL) < endL) {
        mapimgLayer.style.left   = parseInt(curL) + "px";
        mapbgimgLayer.style.left = parseInt(curL) + "px";
        exit = false; 
      } else {
        mapimgLayer.style.left   = endL + "px";
        mapbgimgLayer.style.left = endL + "px";
      }
    } else {
      curL -= pixelStepL;
      if(parseInt(curL) > endL) {
        mapimgLayer.style.left   = parseInt(curL) + "px";
        mapbgimgLayer.style.left = parseInt(curL) + "px";
        exit = false; 
      } else {
        mapimgLayer.style.left   = endL + "px";
        mapbgimgLayer.style.left = endL + "px";
      }
    }

    if(top > 0) {
      curT += pixelStepT;
      if(parseInt(curT) < endT) {
        mapimgLayer.style.top   = parseInt(curT) + "px";
        mapbgimgLayer.style.top = parseInt(curT) + "px";
        exit = false;
      } else {
        mapimgLayer.style.top   = endT + "px";
        mapbgimgLayer.style.top = endT + "px";
      }
    } else {
      curT -= pixelStepT;
      if(parseInt(curT) > endT) {
        mapimgLayer.style.top   = parseInt(curT) + "px";
        mapbgimgLayer.style.top = parseInt(curT) + "px";
        exit = false; 
      } else {
        mapimgLayer.style.top   = endT + "px";
        mapbgimgLayer.style.top = endT + "px";
      }
    }

		var clipT = 0;
		var clipR = mapW;
		var clipB = mapH;
		var clipL = 0;

		if (objTop(mapimgLayer) > 0) {
			clipB = mapH - objTop(mapimgLayer);	
		} else {
			clipT = -1 * objTop(mapimgLayer);     
		}
		
		if (objLeft(mapimgLayer) > 0) {
			clipR = mapW - objLeft(mapimgLayer);
		} else {
			clipL = -1 * objLeft(mapimgLayer);
		}       

		mapimgLayer.style.clip   = 'rect(' + clipT + 'px ' + clipR + 'px ' + clipB + 'px ' + clipL + 'px)';
		mapbgimgLayer.style.clip = 'rect(' + clipT + 'px ' + clipR + 'px ' + clipB + 'px ' + clipL + 'px)';

    if(exit == true) {
      clearInterval(_moveMapIntervalId);
      _moveMapIntervalId = 0;
      fct();
    }  
  }

  resetMeasure();

  if(_moveMapIntervalId == 0) { _moveMapIntervalId = setInterval(intervalFct, moveMapTimeStep); }
}

function resizeDiv(initmap) {
    // Margins in application window
    var lMargin  = 2; // LEFT 
    var mMargin  = 10; // MIDDLE, between map and toc 
    var rMargin  = 1; // RIGHT
    var tMargin  = 10; // TOP
    var bMargin  = 6; // BOTTOM
    var m2Margin = 25; // MIDDLE, between TOC and refmap
    var contourCadre = 2; //BPU
    
    //BPU spécifique IE
    var deltaIE = 0;
    if (document.all) 
        var deltaIE = contourCadre ; 
    //
    
    var winix = document.body.clientWidth;
    var winiy = document.body.clientHeight;
    
    if (winix < 1 || winiy < 1)  {
        winix = parseInt(window.innerWidth);
        winiy = parseInt(window.innerHeight);
        //alert (winiy + ' - ' + winiy2);
    }

    
    // Element definitions
    var top             = document.getElementById('top');
    var bottom          = document.getElementById('bottom');
    var mapFrame        = document.getElementById('mapFrame');
    var mapimgLayer     = document.getElementById('mapimgLayer');
    var mapImg          = document.getElementById('mapImg');
    var zoombox         = document.getElementById('zoombox');
    var toolBar         = document.getElementById('toolBar');
    var topMapFrame     = document.getElementById('topMapFrame');
    var botMapFrame     = document.getElementById('bottomMapFrame');

    //Menu
    //var backgr          = document.getElementById('backgr');
    var toc             = document.getElementById('toc');
    var menuToc         = document.getElementById('menuToc');
    var tree            = document.getElementById('tree');
    var rue             = document.getElementById('rues');
    var liste           = document.getElementById('liste');
    var infos           = document.getElementById('infos');
    var recherche       = document.getElementById('recherche');
    var refmapPallier   = document.getElementById('refmapPallier');
    var refmap2         = document.getElementById('refmap2');
    var refmap          = document.getElementById('refmap');
    var refmapBG        = document.getElementById('refmapBG');
    var loading         = document.getElementById('loading');
    var comment_l       = document.getElementById('comment_l');
    var comment_r       = document.getElementById('comment_r');
    
    // Position (T, L) and sizes (W, H) of elements

    //Entete
    var topW            = objW(top);
    var topH            = objH(top);
    var topMapFrameH    = objH(topMapFrame);
    //var backgrW         = objH(backgr);

    //Bouton
    var toolBarH        = objH(toolBar);
    var toolBarW        = objW(toolBar);
    var bottomW         = objW(bottom);
    var bottomH         = objH(bottom);

    //map
    var mapFrameL       = objLeft(mapFrame);
    var mapimgLayerW    = objW(mapimgLayer);
    var mapimgLayerL    = objLeft(mapimgLayer);
    var mapFrameT       = objTop(mapFrame);
    var mapimgLayerH    = objH(mapimgLayer);
    var mapimgLayerT    = objTop(mapimgLayer);

    //Refmap
    var refmap2W        = objW(refmap2);
    var refmapH         = objH(refmap);

    //Menu
    var tocW            = objW(toc);  
    var tocH            = objH(toc);  
    var tocT            = objTop(toc);
    var treeT           = objTop(tree);

    var botMapFrameH    = objH(botMapFrame);
    
    // NEW sizes
    var newImgLayerW    = winix - lMargin - mMargin - rMargin - tocW - toolBarW;
    //var newImgLayerW    = backgrW;
    var newImgLayerH    = winiy - tMargin - bMargin - topH - bottomH - topMapFrameH - botMapFrameH - 12;
    var newToolBarL     = mapimgLayerL + newImgLayerW;
    //var newTocL         = mapFrameL + newImgLayerW + toolBarW + mMargin;
    var newTocL         = winix - tocW - rMargin ;
    var newTocH         = newImgLayerH + topMapFrameH + botMapFrameH; 
    var newMenuH        = newImgLayerH - 56;  //BPU
    

    // RESIZE elements
    mapW = newImgLayerW;
    mapH = newImgLayerH;
    
    mapFrame.style.width        = newImgLayerW + contourCadre + deltaIE + 'px';
    mapFrame.style.height       = newImgLayerH + contourCadre + deltaIE + 'px';  //newImgLayerH + topMapFrameH + 'px'; BPU
    //mapFrame.style.top          = topH + tMargin + 'px'; 
    mapFrame.style.left         = lMargin + 'px';

    mapimgLayer.style.width     = newImgLayerW +'px';
    mapimgLayer.style.height    = newImgLayerH + 'px';
    
    mapImg.style.width          = newImgLayerW + 'px';
    mapImg.style.height         = newImgLayerH + 'px';

    var mapBgLayer = document.getElementById('mapBgLayer');
    var mapBgImg = document.getElementById('mapBgImg');
    
    mapBgLayer.style.width     = newImgLayerW + 'px';
    mapBgLayer.style.height    = newImgLayerH + 'px';
    
    mapBgImg.style.width       = newImgLayerW + 'px';
    mapBgImg.style.height      = newImgLayerH + 'px';

    var posLeft = getRealPosition(mapimgLayer, 'x');
    var posTop  = getRealPosition(mapimgLayer, 'y');
    var arrowUp    = document.getElementById("arrowUp");
    var arrowHautg = document.getElementById("arrowHautg");
    var arrowRight = document.getElementById("arrowRight");
    var arrowBasd  = document.getElementById("arrowBasd");
    var arrowDown  = document.getElementById("arrowDown");
    var arrowBasg  = document.getElementById("arrowBasg");
    var arrowLeft  = document.getElementById("arrowLeft");
    var arrowHautd = document.getElementById("arrowHautd");

    arrowLeft.style.left = posLeft + contourCadre + "px";
    arrowLeft.style.top  = posTop + contourCadre + parseInt((newImgLayerH - objH(arrowLeft)) / 2) + "px";
      
    arrowRight.style.left = posLeft - contourCadre - contourCadre + newImgLayerW - objW(arrowRight) + "px";
    arrowRight.style.top  = posTop + contourCadre + parseInt((newImgLayerH - objH(arrowRight)) / 2) + "px";

    arrowDown.style.left = posLeft - contourCadre + parseInt((newImgLayerW - objW(arrowDown)) / 2) + "px";
    arrowDown.style.top  = posTop - contourCadre  + newImgLayerH - objH(arrowDown) + "px";

    arrowUp.style.left = posLeft - contourCadre + parseInt((newImgLayerW - objW(arrowUp)) / 2) + "px";
    arrowUp.style.top  = posTop + contourCadre + "px";

    arrowHautd.style.left = posLeft + contourCadre  + newImgLayerW - objW(arrowHautd) + "px";
    arrowHautd.style.top  = posTop + contourCadre + "px";  
    
    arrowBasd.style.left = posLeft + contourCadre  + newImgLayerW - objW(arrowBasd) + "px";
    arrowBasd.style.top  = posTop + contourCadre  + newImgLayerH - objH(arrowBasd) + "px";  

    arrowBasg.style.left = posLeft + contourCadre + "px";
    arrowBasg.style.top  = posTop  + contourCadre + newImgLayerH  - objH(arrowBasg) + "px";

    arrowHautg.style.left = posLeft + contourCadre + "px";
    arrowHautg.style.top  = posTop + contourCadre + "px";
    
    zoombox.style.width         = newImgLayerW + 'px';
    zoombox.style.height        = newImgLayerH + 'px';
    
    topMapFrame.style.width     = newImgLayerW + 'px';
    botMapFrame.style.width     = newImgLayerW + 'px';
    botMapFrame.style.top       = mapimgLayerT + topMapFrameH + newImgLayerH + 'px';
      
    toolBar.style.left          = newToolBarL + 'px';
    toolBar.style.height        = topMapFrameH + botMapFrameH + newImgLayerH + 'px';

    //Menu
    toc.style.left              = newTocL + 'px';
    toc.style.height            = newTocH + 'px';
    toc.style.top               = mapFrameT + 'px';  //BPU

    recherche.style.height      = newMenuH + 'px';
    tree.style.height           = newMenuH + 'px';
    rue.style.height            = newMenuH + 'px';  
    liste.style.height          = newMenuH + 'px';  
    infos.style.height          = newMenuH + 'px';

    refmapPallier.style.left    = newTocL + 50 + 'px';
    refmap2.style.left          = newTocL + tocW - refmap2W + 'px';
    
    refmap.style.left           = objLeft(refmap2) + 16 + 'px'; // newTocL + 'px';
    refmap.style.top            = m2Margin + 'px';  //mapFrameT + newTocH + m2Margin + 'px';
    
    refmapBG.style.left         = objLeft(refmapPallier) + rMargin - 15 + 'px';

    comment_l.style.left  =  lMargin + 'px';
    comment_l.style.width =  newImgLayerW + (contourCadre * 2) + 'px';

    comment_r.style.left  =  newTocL + 'px';
    comment_r.style.width =  objW(toc) - rMargin + 'px';

    top.style.width             = winix + 'px';
    bottom.style.width          = winix + 'px';

    loading.style.left          = mapW/2 - 77 + 'px';
    loading.style.top           = mapH/2 - 6 + 'px';

    // RELOAD MAP!!!
    var mapurl = 'x_load.php?'+SID+ '&mapW=' + newImgLayerW + '&mapH=' + newImgLayerH + '&zoom_type=zoompoint';
    // For IE add key to prevent automatic map refresh
    if (!initmap) {
        if (document.all) mapurl += '&resizeupdate=1';
    }
    updateMap(mapurl, '');

    
}



function pMap () {
    //this.setMapProperties = pMap_setMapProperties;
    //this.getMapProperties = pMap_getMapProperties;
    this.getMapScale = pMap_setMapScale;
    this.RefMapW = pMap_getRefMapW;
    this.RefMapH = pMap_getRefMapH; 
}

function pMap_setMapProperties(width, height, scale) {
    var mapimgLayer = document.getElementById('mapimgLayer');
    mapimgLayer.style.width = width;
    mapimgLayer.style.height = height;
    
    this.width  = width;
    this.height = height;
    this.scale  = scale;
}


function pMap_getMapProperties() {
    var width = this.width;
    var height = this.height; 
    //alert(width + ' - ' + height);
    //loadMapImg0();
}


/**
 * SCALE OF CURRENT MAP
 */
function pMap_setMapScale(scale) {
    //alert (scale);
    this.scale = scale;
}

function pMap_getMapScale() {
    //alert(this.scale);
    return this.scale;
}


/**
 * REFERENCE MAP WIDTH/HEIGHT
 */
function pMap_setRefMapW(refW) {
    this.RefMapW = refW;
}

function pMap_setRefMapH(refH) {
    this.RefMapH = refH;
}

function pMap_getRefMapW() {
    return this.RefMapW;
}

function pMap_getRefMapH() {
    return this.RefMapH;
}






/*****************************************************************************
 * SWAP FUNCTIONS FOR TOOLBAR TD -> USE ALTERNATIVELY TO IMAGE SWAP
 * Changes TD class (default.css -> .TOOLBARTD...) in toolbar
 ********************************************************************/
// Function for state buttons (CLICKED TOOLS: zoomin, pan, identify, select, measure)
function setTbTDButton(button) {
    //var tdarr = document.getElementsByName('tbtd');  //!!!!! DOES NOT WORK WITH CRAPPY IE !!!!
    var tdarr = document.getElementsByTagName('td');
    for (var i = 0; i < tdarr.length; i++) {
        var tdid = tdarr[i].id;
        //alert(tdid);
        //if (tdid != 'tsep') {
        
        //!!!!! WORKAROUND FOR CRAPPY IE !!!!
        if (tdid == 'zoomin' || tdid == 'zoomout' || tdid == 'pan' || tdid == 'identify' || tdid == 'select' || tdid == 'measure' || tdid == 'digitize') {
            if (tdid != button) {
                rmHighlTD(tdid)
            } else {
                highlTD(tdid);
            }
        }
    }
}

function highlTD(elId) {
    var but = document.getElementById(elId);
    if (but) {
        var img = but.getElementsByTagName("IMG")[0];
        but.className='TOOLBARTD_ON';
        img.src = img.src.replace(/_off.gif/, "_on.gif");
    }
}

function rmHighlTD(elId) {
    //alert(elId);
    var but = document.getElementById(elId);
    if (but) {
        var img = but.getElementsByTagName("IMG")[0];
        but.className='TOOLBARTD';
        img.src = img.src.replace(/_on.gif/, "_off.gif");
    }
}


// Functions for MouseOver/Out
function TbOverOut(elId, status){
    var but = document.getElementById(elId);
    if (but) {
        if (but.className != 'TOOLBARTD_ON') {
            var img = but.getElementsByTagName("IMG")[0];
            if (status == 'on') {
                but.className='TOOLBARTD_OVER';
                img.src = img.src.replace(/_off.gif/, "_on.gif");
            } else {
                but.className='TOOLBARTD';
                img.src = img.src.replace(/_on.gif/, "_off.gif");
            }
        }
    }
}

// MouseDown/Up, only set for stateless buttons
function TbDownUp(elId, status){
    var but = document.getElementById(elId);
    if (status == 'd') {
        but.className='TOOLBARTD_ON';
    } else {
        but.className='TOOLBARTD';
    }
}

function changeButtonClr(myObj, myAction) {
    switch (myAction) {
        case 'over':
            myObj.className = 'button_on';
            break;
            alert(myAction);
            
        case 'out':
            myObj.className = 'button_off';
            break;
    }
}




/*****************************************************************************
 * IMAGE SWAP FUNCTIONS FOR TOOLBAR
 * swaps images from imgname_on.gif to imgname_off.gif and vice versa
 *********************************************************************/
// SWITCH IMAGE OF CLICKED TOOL TO 'ON', ALL OTHERS TO 'OFF'
function setButton(button) {
    var imgarr = document.getElementsByTagName('img');
    for (var i = 0; i < imgarr.length; i++) {
        var butid = imgarr[i].id;
        if (butid != 'sep') {
            if (butid != button) {
                setImg(butid, 'off');
            } else {
                setImg(butid, 'on');
            }
        }
    }
}

// set image to ON or OFF
function setImg(obj, status){
    var source = 'images/buttons/' + obj + '_' + status + '.gif';
    imgobj = document.getElementById(obj);
    imgobj.src = source;
}




/**************************************************
 * Set cursor symbol according to tool selection
 *************************************************/
// return root path of application
function getRootPath() {
    var theLoc = document.location.href;
    var theLastPos = theLoc.lastIndexOf('/');
    var RootPath = theLoc.substr(0,theLastPos) + '/';
    
    return RootPath;
}

/** 
 * set the cursor to standard internal cursors
 * or special *.cur url (IE6+ only)
 */
function setCursor(rmc) {
    if (!rmc) {
        if (document.varform) {
            var toolType = document.varform.tool.value;
        } else {
            var toolType = 'zoomin';
        }
    } else {
        toolType = 'pan';
    }

    
    /* Define settings for cursor to be used for tools
       set to true if you want to use the same cursors for all browsers (incl. IE) */
    var internalCursor = ((navigator.version < 6) || (navigator.appName == 'Netscape'));
    //var internalCursor = true; 
    
    var rootPath = getRootPath();
    var usedCursor = (internalCursor) ? toolType : "url(" +rootPath + "images/cursors/zoomin.cur)";
    
    document.getElementById('mapimgLayer').style.cursor = usedCursor;
    
    switch (toolType) {
        case "zoomin" :
            var usedCursor = (internalCursor) ? 'crosshair' : 'url(' +rootPath + 'images/cursors/zoomin.ani)';  
            break;
        
        case "zoomout" :
            var usedCursor = (internalCursor) ? 'e-resize' : 'url(' +rootPath + 'images/cursors/zoomout.cur)';  
            break;
        
        case "identify" :
            //var usedCursor = (internalCursor) ? 'help' : 'url(' +rootPath + 'images/cursors/identify.cur)';   
            var usedCursor = (internalCursor) ? 'help' : 'help';    
            break;

        case "pan" :
            //var usedCursor = (internalCursor) ? 'move' : 'url(' +rootPath + 'images/cursors/pan.cur)';    
            var usedCursor = 'move';
            break;
            
        case "select" :
            //var usedCursor = (internalCursor) ? 'help' : 'url(' +rootPath + 'images/cursors/select.cur)';
            var usedCursor = (internalCursor) ? 'help' : 'help';                
            break;
            
        case "measure" :
            var usedCursor = (internalCursor) ? 'crosshair' : 'url(' +rootPath + 'images/cursors/measure.cur)'; 
            break;
            
        case "digitize" :
            var usedCursor = (internalCursor) ? 'crosshair' : 'crosshair';  
            break;
            
        default:
            var usedCursor = 'default';
    }
    
    document.getElementById('mapimgLayer').style.cursor = usedCursor;
    
}




/*
 * OPEN RESULT WINDOW FOR IDEBNTIFY AND SEARCH
 ***********************************************/
function openResultwin(winurl) {
    var w = window.open(winurl, "resultwin", "width=500,height=200,status=no,resizable=yes,scrollbars=yes");
}


/*****************************************************************************
 * SEARCH
 **********/
// CLOSE SEARCH PAGE
function searchClose() {
    parent.searchFrame.location = "blank.html";
}

// OPEN SEARCH PAGE
function searchOpen() {
    parent.searchFrame.location = "search.phtml?"+SID;
}



/******************************************************************************
 * PRINT FUNCTIONS
 *******************/
function openPrintDlg() {
    var printPopup = document.getElementById("printPopup");
    if(printPopup.style.visibility != "visible") 
    {
        var http = new httpRequest();
        var buff = "";
        var type = getOpacityType(printPopup);
        http.send("printdlg.phtml", SID, function(data) { buff = data; } , false);
        printPopup.innerHTML = buff;
        printPopup.style.left = parseInt((parseInt(document.body.clientWidth) - parseInt(printPopup.style.width)) / 2) + "px";
        printPopup.style.top = parseInt((parseInt(document.body.clientHeight) - parseInt(printPopup.style.height)) / 2) + "px";
/*      
        switch(type)
        {
            case 'ie' :
                printPopup.filters.alpha.opacity = 100;
                break;
                
            case 'khtml' :
                printPopup.style.KhtmlOpacity = 1;
                break;
                
            case 'moz' : 
                printPopup.style.MozOpacity = 1;
                break;
                
            default : 
                printPopup.style.opacity = 1;                   
        }
*/      
        printPopup.style.visibility = "visible";
    }
}


function printMap() {
    var w = window.open("printmap.phtml?"+SID,"printdlg","width=300,height=180,status=no,resizable=no");
}



/*
 * OPEN HELP WINDOW 
 *************************************/
function openHelp() {
    window.open("help.phtml", "help","width=400,height=500,status=no,resizable=yes");
}



/************************************************************************************
 * DOWNLOAD FUNCTIONS
 * get image with higher resolution for paste in othet programs
 ****************************************************************/
function openDownloadDlg() {
    window.open("downloaddlg.phtml?"+SID, "dldlg","width=300,height=180,status=no,resizable=no");
}

function openDownload() {
    window.open("download.phtml?"+SID, "download");
}



/************************************************************************** 
 * DISPLAY COORDINATES IN MORE THAN ONE COORDIMNATE SYSTEM
 **************************************************************************/
function showCoords(imgxy) {
    window.open("showcoords.phtml?"+SID + "&imgxy="+imgxy, "coords","width=280,height=130,status=no,resizable=no");
}

function openProjection() {
    window.open("projection.phtml", "projection","width=320,height=180,status=no,resizable=yes");
}



function openDigitizeDlg(imgxy) {
    //alert(imgxy);
    var coordsList = imgxy.split('+');
    
    var mpoint = getCoords(coordsList[0], coordsList[1], false);
    
    // Round values (function 'roundN()' in 'measure.js')
    var rfactor = 4;
    var px = isNaN(mpoint.x) ? '' : roundN(mpoint.x, rfactor);
    var py = isNaN(mpoint.y) ? '' : roundN(mpoint.y, rfactor);
    
    var inserttxt = prompt(localeList['addLocation'], '');
    
    if (inserttxt) {
        //alert(inserttxt + ' --- ' + px + ' -- ' + py);
        //var ul = + px + ',' + py + ',' + inserttxt;
        var digitizeurl = 'x_digitize.php?' +SID + '&up=' + px + '@@' + py + '@@' + escape(inserttxt);
        //alert(digitizeurl);
        digitizePoint(digitizeurl, '');
    }
    
}
