
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//   Teil (1) des myWMSClient (C) BT-GIS, D.Stolz, E. Gerstner, 2006
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


//var AlphaImageLoader = false;

var myWMS = new Array(); 
var myUsemap = new Array();
var myFeatureInfoURL = "";
var saveFeatureInfoURL = "";
var mySingleWMSRequest = true; // 1 maprequest for all WMS
var mySingleUsemapRequest = true; // true:only 1 map request for all usemap
var myBBox = new Array();
var myMapSize = new Array();
var myXY = new Array();
var myHome = new Array(); // x,y,scale
var mynumscales;
var myMinMaxScale;
var myScale;
var myAddNav = 0.5;
//var myDebug = false;

var ie = document.all?1:0;
var opera  = (navigator.userAgent.search(/Opera/)==-1)?0:1;
var safari = (navigator.userAgent.search(/Safari/)==-1)?0:1;
var konqueror = (navigator.userAgent.search(/Konqueror/)==-1)?0:1;

var myResolution = 28.35;
var myMaxScaleMeasure = 10000;
var msgList = new Array();
var imgTitle = new Array();
var myVendorSpecific = new Array();
var myQualityFillPoly = 10;
var myClickXY = new Array();
var myStartXY = new Array();
var myEndXY = new Array();
var myMapresizeDiff = new Array();
var myMapResize;
var myMapFrame;
var myZoomBox;
var myMarker = new Array(-1,-1,myScale,""); // x,y,scale,objName
var mySlidePixel = new Array();
var mySlideActive = false;
var mySliderScale = myScale;
var reqnum = 1;

var myCount=0;
var myCheckWMSComplete = true;
var myPanActive = false;
var myZoomBoxActive = false;
var zbb = new Array();

var myMeasure = new Array(); // x,y,dist,totaldist
var myMeasureActive = false;
var myMeasurePolyClosed = false;
var myShowMeasure = "myWMSClientShowCoords.html";
var myMaxMeasurePoints = 20;
var myMeasureDashDist = 10;
var myMeasureFormat = 1; // 0: without tooltip; 1:with tooltip; 2:only list; 3:tooltip+list

var myTooltip = "";
var myShowXYSc = false; // Gerstner: war true
var myShowScalebar = true;

var myUMArea = "";
var myUMObject = new Object();

var myIFrameSize = new Array(240,300);
var myIFramePos = new Array(200,100);
var myIFrameTitle = 16;
// Gerstner if(ie) { myIFrameW = 4; } else { myIFrameW = 0; }
var myIFrameW = 0;
var myIFrameMaxSize = new Array(200,200);
// Gerstner if(ie) { myFrameBorder = 4; } else { myFrameBorder = 0; }
var myFrameBorder = 0;

if(!document.getElementById) {
  alert('Your browser needs DOM:\n\nNetscape >6.x\nInternet Explorer >5.x\nOpera >5.12\nMozilla Firefox >1.0\Konqueror >3.3\nSafari >1.2');
  this.location.href = transparentImg.src;
}

//-----------------------------------------------------------------------------------
// Initialisiert den Client
//-----------------------------------------------------------------------------------

function my_init(show) {
  mynumscales = myScales.length;
  myMinMaxScale = new Array(myScales[0], myScales[mynumscales-1]);
  myScale = myStartScale;
  my_update_maplayers();
  my_sliderInit();
  myZoomBox = document.getElementById("layerZoomBox");
  myHome[0] = myXY[0];
  myHome[1] = myXY[1];
  myHome[2] = myScale;
  myMapFrame = document.getElementById("layerAll");
  if (show==1) my_repaintXYSc(myXY[0],myXY[1],myScale);
  d.scalecheck(myScale);
}

/* braucht man nicht?
function my_initmaplayers() {
  document.write("<div id='layerMapBorder' style='position:absolute;left:"+(myMapPos[0])+"px;top:"+(myMapPos[1])+"px;width:"+(myMapSize[0])+"px;height:"+(myMapSize[1])+"px;overflow:hidden'>");
  document.write("<div id='layerAll' style='position:absolute;left:0px;top:0px;width:"+(myMapSize[0])+"px;height:"+(myMapSize[1])+"px;background-color:white'>");
  for(var i=0;i<myWMS.length;i++) 
    my_createDiv("layerWMS"+i,0,0,0,0,true,"");
  document.write("</div>");
  my_createDiv("layerZoomBox",0,0,0,0,false,"");
  my_createDiv("layerEventHandling",0,0,myMapSize[0],myMapSize[1],false,"");
  document.write("</div>");
}
*/

//-----------------------------------------------------------------------------------
// Generiert die vom Client benoetigten DIVs
//-----------------------------------------------------------------------------------

function my_setSkin() {
  document.write("<div id='layerMapBorder' style='position:absolute;left:"+(myMapPos[0])+"px;top:"+(myMapPos[1])+"px;width:"+(myMapSize[0])+"px;height:"+(myMapSize[1])+"px;overflow:hidden'>");
    document.write("<div id='layerAll' style='position:absolute;left:0px;top:0px;width:"+(myMapSize[0])+"px;height:"+(myMapSize[1])+"px;background-color:white;'>");
      for(var i=0;i<myWMS.length;i++) {
        my_createDiv("layerWMS"+i,0,0,0,0,true,"");
      }
      my_createDiv("layerUsemapHighlight",0,0,0,0,true,"");
      for(var i=0;i<myUsemap.length;i++) {
        my_createDiv("layerUsemap"+i,0,0,0,0,true,"");
      }
//      content = "<img src='"+markerImg.src+"'><span id='divMarkerInfo' style='visibility:hidden'></span>";
//      my_createDiv("layerMarker",-1000,-1000,0,0,false,content);
      my_createDiv("layerMeasureLine",0,0,0,0,true,"");
      my_createDiv("layerMeasureRun",0,0,0,0,true,"");
      my_createDiv("layerZoomBox",0,0,0,0,false,"");
//      content="<img src='"+highlightImg.src+"'>";
//      my_createDiv("divHighlightIcon",0,0,0,0,false,content);
    document.write("</div>");
    my_createDiv("layerEventHandling",0,0,myMapSize[0],myMapSize[1],false,"");
//    my_createDiv("layerPrintPreview",0,0,0,0,false,"");
  document.write("</div>");
  // statusbar
  my_createDiv("divStatusbar",0,0,0,0,true,"");
  // dummy frame for usemap
  for(var i=0;i<myUsemap.length;i++) {
    document.write("<iframe name='layerUsemapFrame"+i+"' id='layerUsemapFrame"+i+"' style='position:absolute;left:0px;top:0px;width:0px;height:0px;display:none'></iframe>");
  }
// Gerstner: Resize+Minimize deaktiviert
// document.write("<div id='divMapResize' style='position:absolute;left:"+(myMapSize[0]+myMapPos[0]-11-myFrameBorder)+"px;top:"+(myMapSize[1]+myMapPos[1]-11-myFrameBorder)+"px;width:13px;height:13px;background-image:url("+resizeImg.src+");background-repeat:no-repeat' onmousedown=my_mapResize() title='"+msgList[0]+"'></div>");
// Gerstner: +px
// frame for featureinfo, print, search result ...
  document.write("<div id='divInfoFrame' style='position:absolute;left:"+(myIFramePos[0]-2)+"px;top:"+(myIFramePos[1]-2)+"px;width:"+(myIFrameSize[0]+myIFrameW)+"px;height:"+(myIFrameSize[1]+myIFrameW)+"px;display:none;cursor:nw-resize;z-index:34' onmousedown=my_infoFrameMove('resize')></div>");
  document.write("<div id='divInfoFrameStatus' style='position:absolute;left:"+(myIFramePos[0])+"px;top:"+(myIFramePos[1]+myIFrameSize[1]-myIFrameTitle)+"px;width:"+myIFrameSize[0]+"px;height:"+myIFrameTitle+"px; cursor:move; z-index:35;display:none'></div>");
//  document.write("<div id='divInfoFrameResize' style='position:absolute;left:"+(myIFramePos[0])+"px;top:"+(myIFramePos[1]+myIFrameSize[1]-myIFrameTitle)+"px;width:"+myIFrameSize[0]+"px;height:"+myIFrameTitle+"px;z-index:34; cursor:move; background-image:url("+imgPath+"/resize.gif);background-repeat:no-repeat;background-position:right;display:none;cursor:nw-resize;' onmousedown=my_infoFrameMove('resize') title='"+msgList[10]+"'></div>");
  document.write("<iframe id='divInfoFrameSrc' name='divInfoFrameSrc' style='position:absolute;left:"+(myIFramePos[0])+"px;top:"+(myIFramePos[1]+myIFrameTitle)+"px;width:"+myIFrameSize[0]+"px;height:"+(myIFrameSize[1]-myIFrameTitle)+"px;display:none;overflow:none;border:none;;z-index:25' src='"+imgPath+"/transparent.gif' frameborder='0' title=''></iframe>");
  document.write("<div id='divInfoFrameTitle' style='position:absolute;left:"+myIFramePos[0]+"px;top:"+myIFramePos[1]+"px;width:"+myIFrameSize[0]+"px;height:"+myIFrameTitle+"px;display:none;cursor:move;z-index:35' onmousedown=my_infoFrameMove('move') title=''></div>");
  document.write("<div id='divInfoFrameClose' style='position:absolute;left:"+(myIFramePos[0]+myIFrameSize[0])+"px;top:"+(myIFramePos[1])+"px;width:11px;height:11px;z-index:35;background-image:url("+imgPath+"/pfeil_mini_schliessen.gif);background-repeat:no-repeat;margin-left:-13px;margin-top:3px;display:none' onclick=my_infoFrameClose() title='"+msgList[12]+"'></div>");
//  document.write("<div id='divInfoFrameMin' style='position:absolute;left:"+(myIFramePos[0]+myIFrameSize[0])+"px;top:"+(myIFramePos[1])+"px;width:11px;height:11px;z-index:35;background-image:url("+imgPath+"/minimize.gif);background-repeat:no-repeat;margin-left:-27px;margin-top:3px;display:none' onclick=my_infoFrameMin() title='"+msgList[13]+"'></div>");
}

//-----------------------------------------------------------------------------------
// Parsen der Aufrufparameter (deaktiviert)
//-----------------------------------------------------------------------------------

/*
function my_getCGIParams1() {
  var obj = "";
  var argstr = location.search.substring(1,location.search.length);
  if(argstr.length > 0) {
    var args = argstr.toString().split('&');
    for(var i=0;i<args.length;i++) {
      var tmp = args[i].split('=');
      var nam = unescape(tmp[0]);
      var val = unescape(tmp[1]);
      if(nam.search(/\bx\b/i)> -1) { myXY[0] = parseInt(val); }
      if(nam.search(/\by\b/i)> -1) { myXY[1] = parseInt(val); }
      if(nam.search(/\bscale\b/i)> -1) { myScale = parseInt(val); }
      if(nam.search(/\blayers\b/i)> -1) {
        var lay = val.split(",");
        if(val != "") {
          for (var j=0;j<myWMS.length;j++) { myWMS[j][5] = false; }
          for (var j=0;j<lay.length;j++) { myWMS[lay[j]][5] = true; }
        }
      }
      if(nam.search(/\busemaplayer\b/i)> -1) {
        var lay = val.split(",");
        if(val != "") {
          for (var j=0;j<myUsemap.length;j++) { myUsemap[j][5] = false; }
          for (var j=0;j<lay.length;j++) { myUsemap[lay[j]][5] = true; }
        }
      }
      if(nam.search(/\bobject\b/i)> -1) { myMarker = val.split(","); }
      if(nam.search(/\bbbox\b/i)> -1) { my_bb2Scale(val.split(",")); }
      if(nam.search(/\bmeasure\b/i)> -1 && val != "") {
        var co = val.split(",")
        myMeasureFormat = 0;
        if(co.length > 4) {
          my_measureDelete();
          var k = 0;
          for(var j=0;j<co.length;j+=4) {
            myMeasure[k] = new Array(co[j]*1,co[j+1]*1,co[j+2]*1,co[j+3]*1);
            k++;
          }
          if(myMeasure[0][0]==myMeasure[myMeasure.length-1][0] && myMeasure[0][1]==myMeasure[myMeasure.length-1][1]) {
            myMeasurePolyClosed = true;
          } else { myMeasurePolyClosed = false; }
        }
      }
      if(nam.search(/\bdebug\b/i)> -1) {
        if(val == "true") { myDebug = true; }
      }
    }
  }
}

function my_getCGIParams() {
  var obj = "";
  var argstr = location.search.substring(1,location.search.length);
  if(argstr.length > 0) {
    var args = argstr.toString().split('&');
    for(var i=0;i<args.length;i++) {
      var tmp = args[i].split('=');
      var nam = unescape(tmp[0]);
      var val = unescape(tmp[1]);
      if(nam.search(/\bleft\b/i)> -1) { myMapPos[0] = parseInt(val); }
      if(nam.search(/\btop\b/i)> -1) { myMapPos[1] = parseInt(val); }
      if(nam.search(/\bwidth\b/i)> -1) { myMapSize[0] = parseInt(val); }
      if(nam.search(/\bheight\b/i)> -1) { myMapSize[1] = parseInt(val); }
    }
  }
  saveFeatureInfoURL = myFeatureInfoURL; // save featurInfoURL for continue after finish other functions (online registartion etc.)
}
*/

//-----------------------------------------------------------------------------------
// Ganz wichtige Funktion my_setMapRequest:
// Baut den WMS-Request (OGC) zusammen und fordert eine neue Karte bzw. Usemap vom
// myWMS an
//-----------------------------------------------------------------------------------

function my_setMapRequest(val) {
//  my_MapRequestPreFunctions();
  if(val==0 || val=="WMS" ) {
    if(val==0) {
      for(var i=0;i<myUsemap.length;i++) {
        document.getElementById("layerUsemap"+i).innerHTML = ""; 
        document.getElementById("layerUsemap"+i).style.width = "0px";
        document.getElementById("layerUsemap"+i).style.height = "0px";
      }
    }

    if(mySingleWMSRequest == true) { // call WMS together
      for(var i=0;i<myWMS.length;i++) {
        if (i==0 && symbolchange==true) { symbolchange=false; continue; }  // Karte wird beim Layerwechsel nicht neu geladen
        if(myWMS[i][0].indexOf('?') == -1) { myWMS[i][0] += "?"; }
        var newWMS = myWMS[i][0]
         +"&BBOX=" + myBBox
         +"&LAYERS=" + my_checkLayer(i,"WMS")
         +"&WIDTH=" + myMapSize[0]
         +"&HEIGHT=" + myMapSize[1]
         +"&SCALE=" + myScale;
        if (extra_symbols && i==1) newWMS+="&REQNUM=" + (reqnum++);
        for(var j=0;j<myVendorSpecific.length;j++){
          newWMS += "&" + eval(myVendorSpecific[j]);
        }
        if(myWMS[i][5] == false || my_checkLayer(i,"WMS") == "") { newWMS = transparentImg.src; }
        if(myDebug && myWMS[i][5] == true && my_checkLayer(i,"WMS") != "") { prompt("",newWMS); }
        document.getElementById("layerWMS"+i).innerHTML = "<img id='map"+i+"' name='mapimage' style='position:absolute;left:0px;top:0px;width:"+myMapSize[0]+"px;height:"+myMapSize[1]+"px' src='"+newWMS+"' usemap='#mywms'>";  
        my_correctPNG(i,newWMS);
        my_sandclock(true,"map"+i);
      }
      my_mapstat();
    } else {
      var layWMS = my_getLayers("WMS");
      if(myWMS[0][0].indexOf('?') == -1) { myWMS[0][0] += "?"; }
      var newWMS = myWMS[0][0]
       +"&BBOX=" + myBBox
       +"&LAYERS=" + layWMS[0]
       +"&WIDTH=" + myMapSize[0]
       +"&HEIGHT=" + myMapSize[1]
       +"&SCALE=" + myScale;
      if (extra_symbols) newWMS+="&REQNUM=" + (reqnum++);
      for(var j=0;j<myVendorSpecific.length;j++){
        newWMS += "&" + eval(myVendorSpecific[j]);
      }
      if(layWMS[0] == "") { newWMS = transparentImg.src; }
      if(myDebug && layWMS[0] != "") { prompt("",newWMS); }
      document.getElementById("layerWMS0").innerHTML = "<img id='map0' name='mapimage' style='position:absolute;left:0px;top:0px;width:"+myMapSize[0]+"px;height:"+myMapSize[1]+"px' src='"+newWMS+"' usemap='#mywms'>";
      my_sandclock(true,"map0");
      my_mapstat();
    }
  }
  if(val==0 || val=="USEMAP") {
//    out(); // disable usemap
    if(mySingleUsemapRequest == true) { // call usemap/iconlay together
      for(var i=0;i<myUsemap.length;i++) {
        if(myUsemap[i][0].indexOf('?') == -1) { myUsemap[i][0] += "?"; }
        var newUm = myUsemap[i][0]
         +"&BBOX=" + myBBox
         +"&LAYERS=" + my_checkLayer(i,"USEMAP")
         +"&WIDTH=" + myMapSize[0]
         +"&HEIGHT=" + myMapSize[1]
         +"&SCALE=" + myScale
         +"&USEMAPLAYER=layerUsemap" + i; // layer for writing
        if (extra_symbols) newUm+="&REQNUM=" + (reqnum++);
        for(var j=0;j<myVendorSpecific.length;j++){
          newUm += "&" + eval(myVendorSpecific[j]);
        }
        if(myUsemap[i][5] == false || my_checkLayer(i,"USEMAP") == "") {
          document.getElementById("layerUsemap"+i).innerHTML = "";
          document.getElementById("layerUsemap"+i).style.width = "0px";
          document.getElementById("layerUsemap"+i).style.height = "0px";
        } else {
          if(myDebug) { prompt("",newUm); }
          my_arrangeElement("layerUsemap"+i,0,0,myMapSize[0],myMapSize[1]);
          document.getElementById("layerUsemapFrame"+i).src = newUm;
        }
      }
    } else {
      var layUM = my_getLayers("USEMAP");
      if(myUsemap[0][0].indexOf('?') == -1) { myUsemap[0][0] += "?"; }
      var newUm = myUsemap[0][0]
       +"&BBOX=" + myBBox
       +"&LAYERS=" + layUM[0]
       +"&WIDTH=" + myMapSize[0]
       +"&HEIGHT=" + myMapSize[1]
       +"&SCALE=" + myScale
       +"&USEMAPLAYER=layerUsemap0";  // layer for writing
      if (extra_symbols) newUm+="&REQNUM=" + (reqnum++);
      for(var j=0;j<myVendorSpecific.length;j++){
        newUm += "&" + eval(myVendorSpecific[j]);
      }
      if(myDebug && layUM[0] != "") { prompt("",newUm); }
      document.getElementById("layerUsemapFrame0").src = newUm;
    }
  }
//  my_MapRequestSubFunctions();
//  my_hideHighlight();
  my_arrangeElement("layerMapBorder",myMapPos[0],myMapPos[1],myMapSize[0],myMapSize[1]);
  my_arrangeElement("layerAll",0,0,myMapSize[0],myMapSize[1]);
  my_arrangeElement("layerEventHandling",0,0,myMapSize[0],myMapSize[1]);
  if(myMeasure.length>0) { my_drawDashedLine(); }
//  if(my_checkDIV("layerMarker")) { my_setMarker(myMarker[0],myMarker[1],myMarker[2],myMarker[3],1); }
}

//-----------------------------------------------------------------------------------
// Layer-Verwaltung (wird eigentlich nicht gebraucht):
//  - my_checkLayer ueberprueft ob ein Layer aktiv ist
//  - my_getLayers liefert alle aktiven Layers als Array zurueck
//-----------------------------------------------------------------------------------

function my_checkLayer(id,typ) {
  var thisLayer = "";
  var myMinSc = false;
  var myMaxSc = false;

  if(typ == "WMS") {
    if(myWMS[id][3] == 0 || myScale >= myWMS[id][3]) { myMinSc = true; }
    if(myWMS[id][4] == 0 || myScale < myWMS[id][4]) { myMaxSc = true; }
    if(myMinSc == true && myMaxSc == true) {
      thisLayer = myWMS[id][1];
    } else { thisLayer = ""; }
  }
  if(typ == "USEMAP") {
    if(myUsemap[id][3] == 0 || myScale >= myUsemap[id][3]) { myMinSc = true; }
    if(myUsemap[id][4] == 0 || myScale < myUsemap[id][4]) { myMaxSc = true; }
    if(myMinSc == true && myMaxSc == true) {
      thisLayer = myUsemap[id][1];
    } else { thisLayer = ""; }
  }
  return thisLayer;
}

function my_getLayers(typ) {
  var thisLayers = new Array();
  var thisLayersName = new Array();
  var thisLayersID = new Array();
  var thisLayersTitle = new Array();
  if(typ == "WMS") {
    for(var i=0;i<myWMS.length;i++) {
      if(myWMS[i][5] == true && my_checkLayer(i,"WMS") != "") {
        thisLayersName.push(myWMS[i][1]);
        thisLayersID.push(i);
        thisLayersTitle.push(myWMS[i][2]);
      }
    }
  }
  if(typ == "USEMAP") {
    for(var i=0;i<myUsemap.length;i++) {
      if(myUsemap[i][5] == true && my_checkLayer(i,"USEMAP") != "") {
        thisLayersName.push(myUsemap[i][1]);
        thisLayersID.push(i);
        thisLayersTitle.push(myUsemap[i][2]);
      }
    }
  }
  thisLayers = new Array(thisLayersName,thisLayersID,thisLayersTitle);
  return thisLayers;
}

//-----------------------------------------------------------------------------------
// Featureinfo-Requests (deaktiviert)
//-----------------------------------------------------------------------------------

/*
function my_setFeatureRequest() {
  my_eventLayer(false);
  var layWMS = my_getLayers("WMS");
  var layUsemap = my_getLayers("USEMAP");
  if(myFeatureInfoURL == "") { return; }
  var pos = my_pixel2Meter(myClickXY[0]-myFrameBorder,myClickXY[1]-myFrameBorder);
  if(myFeatureInfoURL.indexOf('?') == -1) { myFeatureInfoURL += "?"; }
  var newFI = myFeatureInfoURL
   +"&BBOX=" + myBBox
   +"&WIDTH=" + myMapSize[0]
   +"&HEIGHT=" + myMapSize[1]
   +"&X=" + myClickXY[0]
   +"&Y=" + myClickXY[1]
   +"&SELAREA=" + pos[0]+","+pos[1]
   +"&SCALE=" + myScale
   +"&REQNUM=" + (reqnum++);
  if(myFeatureInfoURL.search(/\bLAYERS\b/i)> -1) {} else {
   newFI += "&LAYERS=" + layWMS[0]+","+layUsemap[0]
  }
  for(var i=0;i<myVendorSpecific.length;i++){
    newFI += "&" + eval(myVendorSpecific[i]);
  }
  newFI += "&ID="+myTooltip;
  my_setMarker(pos[0],pos[1],null,"",1);
  my_getFeatureFrame(newFI);
  if(myDebug) { prompt("",newFI); }
}

function my_getFeatureFrame(url) {
  var Xwin = window.open(url,'featureInfo','width=200,height=300,menu=no');
}
*/

//-----------------------------------------------------------------------------------
// Updatet in der Minimap das Rechteck
//-----------------------------------------------------------------------------------

function my_getOverviewFrame() {
  try {
// Gerstner: overview -> minimap
    window.frames["myMiniMapFrame"].my_setMiniMapBBox(); // set Minimap marker
  } catch (e) {}
}

//-----------------------------------------------------------------------------------
// Ganz wichtige Funktion my_repaintXYSc:
// Fordert neue Karte fuer den Mittelpunkt (x,y) und die Skala sc an
//  - der Mittelpunkt wird auf einen Rasterpunkt (myPositionRound) gerundet
//  - die Skala wird auf eine diskrete Skalen (myScales) gerundet
//  - dann wird die neue BoundingBox fuer den Maprequest ausgerechnet
//  - schliesslich wird durch den Aufruf my_maprequest die neue Karte gezeichnet
//-----------------------------------------------------------------------------------

function my_repaintXYSc(x,y,sc) {
  if(!my_checkWMSComplete()) { return; }
  myCount++;
  if(sc == null || sc == "" || sc == "undefined") {
    var pos = my_getXYSc();
    sc = parseInt(pos[2]);
  }
  if(sc<myMinMaxScale[0]) { sc = myMinMaxScale[0]; }
  if(sc>myMinMaxScale[1]) { sc = myMinMaxScale[1]; }
// Gerstner: auf numscales runden
//  proc=exp(log(sc-myMinMaxScale[0])/log(myMinMaxScale[1]-myMinMaxScale[0])*numscales);
  for (i=0; i<mynumscales; i++) {
    if (sc<=myScales[i]*1.01) { sc=myScales[i]; break; }
  }
  if (sc!=myScale) { myScale=sc; d.scalecheck(sc); my_update_maplayers(); }
  else myScale=sc;

// Gerstner: bei maximaler Skala wird in die Mitte zentriert
  if (sc==myScales[mynumscales-1]) {
    x = (myMapBBox[0]+myMapBBox[2])/2.0;
    y = (myMapBBox[1]+myMapBBox[3])/2.0;
  }
  if(x == null && y == null){
    var pos = my_getXYSc();
    x = pos[0];
    y = pos[1];
  }
// Gerstner:
// Mittelpunkt auf ein Gitter mit Abstand myPositionRound runden
  if (sc!=myScales[mynumscales-1]) {
    if (myRoundRelative==false) {
        x=Math.round(x/myPositionRound)*myPositionRound;
        y=Math.round(y/myPositionRound)*myPositionRound;
    }
    // Mittelpunkt auf Vielfache der Navigationspfeil-Schrittweite (myAddNav) ausgehend von der Startposition runden
    else {
        sx=(myMapSize[0]*sc*myAddNav)/(myResolution*100);
        sy=(myMapSize[1]*sc*myAddNav)/(myResolution*100);
        x=Math.round((x-myXY[0])/sx)*sx+myXY[0];
        y=Math.round((y-myXY[1])/sy)*sy+myXY[1];
    }
  }

  // bbox for ogc maprequest
  myBBox[0] = Math.round((x-(myMapSize[0]/(myResolution*100*2)*sc))*100)/100;
  myBBox[1] = Math.round((y-(myMapSize[1]/(myResolution*100*2)*sc))*100)/100;
  myBBox[2] = Math.round((x+(myMapSize[0]/(myResolution*100*2)*sc))*100)/100;
  myBBox[3] = Math.round((y+(myMapSize[1]/(myResolution*100*2)*sc))*100)/100;
  var pos = my_getXYSc();
//  myXY[0] = Math.round(pos[0]*1)/1;
//  myXY[1] = Math.round(pos[1]*1)/1;
//  myScale = Math.round(pos[2]*1)/1;
// Gerstner: neue Funktion
  my_show_statusbar(myScale);
  my_eventLayer(false);
  my_measureStop();
  my_setSlider(i);
  my_setHistoryObj();
  my_setMapRequest(0);
//  my_setKeyhandler();
  my_getOverviewFrame();
}

//-----------------------------------------------------------------------------------
// Zeigt den aktuellen Massstab an als Text (1:x.xxx.xxx) an
//-----------------------------------------------------------------------------------

// Gerstner: neue Funktion
function my_show_statusbar(sc) {
  if(my_checkDIV("divStatusbar")) {
    var scaletext="";
    for (var i=0; i<mynumscales; i++) if (myScales[i]==sc) scaletext=myScaleTexts[i];
    var tmp = "";
    if(myShowXYSc) {
      tmp += "&nbsp;<a href='#' onclick=my_setXYDialog() title='"+msgList[5]+"'>"+msgList[1]+myXY+"</a>&nbsp;&nbsp;&nbsp;<a href='#' id='divScStatus' onclick=my_setScaleDialog() title='"+msgList[3]+"'>"+msgList[2]+myScale+"</a>";
    }
//    var scaletext=sc+"";
    scl=scaletext.length;
    if (scl>=7) st=scaletext.substring(0,scl-6)+"."+scaletext.substring(scl-6,scl-3)+"."+scaletext.substring(scl-3,scl);
    else if (scl>=4) st=scaletext.substring(0,scl-3)+"."+scaletext.substring(scl-3,scl);
    else st=scaletext;
    if(myShowScalebar) tmp += "1:"+st;
    document.getElementById("divStatusbar").innerHTML = tmp;
    var wz1 = 2;var wz2 = 0;
    document.getElementById("divStatusbar").style.left = (myMapPos[0]+myMapSize[0]+wz1-100)+"px";
    document.getElementById("divStatusbar").style.top = (myMapPos[1]+myMapSize[1]+1-wz2)+"px";
    document.getElementById("divStatusbar").style.width = "95px";
  }
}

//maprequest is only possible when all WMS complete
function my_checkWMSComplete() {
  //needed for: key,nav,pan,slider-click,slider-drag,overview-click,overview-zoom,link,mapresize
  if(myCount>0 && myCheckWMSComplete && my_getID("divWaitIcon").innerHTML != "") {
    my_arrangeElement("layerAll",0,0);
    my_eventLayer(false);
    if(my_getID("divWaitIcon").innerHTML.search(/\berror\b/i) == -1) {
      my_getID("divWaitIcon").innerHTML+="<p class='error'>"+msgList[10]+"</p>";
    }
    return false;
  }
  return true;
}

//-----------------------------------------------------------------------------------
// Liefert aktuellen Mittelpunkt und Skala der Karte als Array zurueck
//-----------------------------------------------------------------------------------

function my_getXYSc() {
  var pos = new Array();
  pos[0] = ((parseFloat(myBBox[2])-parseFloat(myBBox[0]))/2)+parseFloat(myBBox[0]);
  pos[1] = ((parseFloat(myBBox[3])-parseFloat(myBBox[1]))/2)+parseFloat(myBBox[1]);
  var xtenty = parseFloat(myBBox[3])-parseFloat(myBBox[1]);
  var scaleY = (xtenty/myMapSize[1])*(myResolution*100);
  pos[2] = parseFloat(scaleY);
  return pos;
}

//-----------------------------------------------------------------------------------
// Zoomt die Karte um den angegebenen Faktor. Aufruf durch Klick auf die +/- Zoom
// Buttons im Navipanel
//-----------------------------------------------------------------------------------

function my_zoomMap(factor) {
  var pos = my_getXYSc();
// Gerstner: numscales
  sc=Math.round(pos[2]);
  for (i=0; i<mynumscales; i++) {
    if (sc<=myScales[i]*1.01) { sc=myScales[i]; break; }
  }
  i+=factor;
  if (i>mynumscales) i=mynumscales;
  if (i<0) i=0;
  my_repaintXYSc(pos[0],pos[1],myScales[i]);
// pos[2] *= factor;
// my_repaintXYSc(pos[0],pos[1],pos[2]);
// Gerstner: Statistik-Log
  my_statistik("action=zoom");
// Gerstner: andere Modi verlassen
  my_navi_pan_off();
  my_navi_zoom_off();
  my_navi_measure_off();
}

//-----------------------------------------------------------------------------------
// Bewegt die Karte um (addX,addY). Falls border=true, wurde die Bewegung durch
// die Pfeile im Kartenrahmen initiiert, ansonsten durch das Navipanel
//-----------------------------------------------------------------------------------

function my_moveMap(addX,addY,border) {
  var pos = my_getXYSc();
  if(addX==-1 && addY==-1) { // center
     pos[0] = myHome[0];
     pos[1] = myHome[1];
     pos[2] = myHome[2];
  } else {
    var addX = (myBBox[2]-myBBox[0])*addX;
    var addY = (myBBox[3]-myBBox[1])*addY;    

//  Gerstner: um nicht ueber vorgegebene Box hinaus verschieben zu duerfen:
    if (myBBox[0]+addX < myMapBBox[0] || myBBox[2]+addX > myMapBBox[2] ||
    myBBox[1]+addY < myMapBBox[1] || myBBox[3]+addY > myMapBBox[3]) return;

    pos[0] += addX;
    pos[1] += addY;
  }
  my_repaintXYSc(pos[0],pos[1],pos[2]);
// Gerstner: andere Modi verlassen
  my_navi_pan_off();
  my_navi_zoom_off();
  my_navi_measure_off();
// Gerstner: Statistik-Log
  if (border==true) my_statistik("action=navigationKartenrahmen");
  else my_statistik("action=navigation");
}

//-----------------------------------------------------------------------------------
// DIV-Funktionen:
//  - my_createDiv erzeugt ein neues DIV Element
//  - my_checkDIV ueberprueft ob ein DIV existiert
//  - my_arrangeElement zeichnet ein DIV neu
//-----------------------------------------------------------------------------------

function my_createDiv(elName,left,top,width,height,visible,content) {
  if(width>0 && height>0) {
    document.writeln('<div class="empty" id="'+elName+'" style="position:absolute;left:'+left+'px;top:'+top+'px;width:'+width+'px;height:'+height+'px;visibility:'+(visible ? 'visible;' : 'hidden;')+';overflow:none">');
  } else {
    document.writeln('<div class="empty" id="'+elName+'" style="position:absolute;left:'+left+'px;top:'+top+'px;visibility:'+(visible ? 'visible;' : 'hidden;')+';overflow:none">');
  }
  document.writeln(content);
  document.writeln('</div>');
}

function my_checkDIV(elName) {
  if(document.getElementById(elName)) { return true; } else { return false; }
}

function my_arrangeElement(elName,left,top,width,height) {
  var t =typeof(elName);
  if(t == "string") { elName = new Object(document.getElementById(elName)); }
// Gerstner: +"px"
  if(left != null) { elName.style.left = left+"px"; }
  if(top != null) { elName.style.top = top+"px"; }
  if(width) { elName.style.width = width+"px"; }
  if(height) { elName.style.height = height+"px"; }
}

//-----------------------------------------------------------------------------------
// Bestimmt die aktuelle Mausposition
//-----------------------------------------------------------------------------------

function my_getMousePos(e) {
  var El=document.getElementById("layerMapBorder");
  var mapx=0, mapy=0;
  while(El.offsetParent) {
    mapx+=El.offsetLeft;
    mapy+=El.offsetTop;
    El=El.offsetParent;
  }
  if(ie) {
        myClickXY[0] = event.clientX+document.documentElement.scrollLeft-mapx-4;
        myClickXY[1] = event.clientY+document.documentElement.scrollTop-mapy-4;
//window.status="clickx="+myClickXY[0]+" clicky="+myClickXY[1]+" mapx="+mapx+" mapy="+mapy+" scrollleft="+document.documentElement.scrollLeft+" scrolltop="+document.documentElement.scrollTop;
  } 
  else { 
       if (!e) e=window.event;
       myClickXY[0] = e.pageX-mapx+2;
       myClickXY[1] = e.pageY-mapy+2;
//window.status="clickx="+myClickXY[0]+" clicky="+myClickXY[1]+" mapx="+mapx+" mapy="+mapy;
  }
}


/* Original
function my_getMousePos(e) {
  if(ie) {
      myClickXY[0] = event.clientX+document.body.scrollLeft-myMapPos[0];
      myClickXY[1] = event.clientY+document.body.scrollTop-myMapPos[1];

  } else {
    if (!e) e=window.event;
    myClickXY[0] = e.pageX-myMapPos[0];
    myClickXY[1] = e.pageY-myMapPos[1];
  }
}
*/

//-----------------------------------------------------------------------------------
// Umrechnungs-Funktionen
//  - my_pixel2Meter rechnet Pixel in Meter um
//  - my_meter2Pixel rechnet Meter in Pixel um
//  - my_bb2Scale rechnet aus der Boundingbox die Skala aus
//-----------------------------------------------------------------------------------

function my_pixel2Meter(pixX,pixY) {
  var xtentx = myBBox[2]-myBBox[0];
  var xtenty = myBBox[3]-myBBox[1];
  var posX = parseFloat(myBBox[0]+(pixX/myMapSize[0])*xtentx);
  var posY = parseFloat(myBBox[3]-(pixY/myMapSize[1])*xtenty);
  posX = Math.round(posX*100)/100;
  posY = Math.round(posY*100)/100;
  return new Array(posX,posY);
}

function my_meter2Pixel(meterX,meterY) {
  var posX =((meterX-myBBox[0])/(myBBox[2]-myBBox[0]))*myMapSize[0];
  var posY =((myBBox[3]-meterY)/(myBBox[3]-myBBox[1]))*myMapSize[1];
  return new Array(posX,posY);
}

function my_bb2Scale(bb) {
  myXY[0] = ((bb[2]-bb[0])/2)+parseInt(bb[0]);
  myXY[1] = ((bb[3]-bb[1])/2)+parseInt(bb[1]);
  if( (bb[2]-bb[0]) > (bb[3]-bb[1]) ) {
    myScale = parseInt((((bb[2]-bb[0])/myMapSize[0])*1000*3.5)+(bb[2]-bb[0])/10);
  } else {
    myScale = parseInt((((bb[3]-bb[1])/myMapSize[1])*1000*3.5)+(bb[3]-bb[1])/10);
  }
}

//-----------------------------------------------------------------------------------
// Scale-Dialog (deaktiviert)
//-----------------------------------------------------------------------------------

/*
function my_setScaleDialog() {
  var n = prompt(msgList[3],myScale);
  if(isNaN(n) == true || n == 0) {
    alert("1:"+n+" "+msgList[4]);
    return;
  }
  if(n != null) {
    my_repaintXYSc(null,null,Math.abs(n));
  }
}

function my_setXYDialog() {
  var n = prompt(msgList[5],myXY);
  if(n != null) {
    var chkZ = 1;
    n = n.replace(/[ '"_]/g,"");
    n = n.replace(/[,; ]/g,"&");
    var tmp = n.toString().split('&');
    if(isNaN(tmp[0]) == true || isNaN(tmp[1]) == true) {
      alert(n+" "+msgList[6]);
    } else {
      my_repaintXYSc(Math.abs(tmp[0]),Math.abs(tmp[1]),null);
    }
  }
}
*/

//-----------------------------------------------------------------------------------
// Karten-Resize (deaktiviert)
//-----------------------------------------------------------------------------------

/*
function my_mapResize() {
  my_eventLayer(true);
  myMapResize = document.getElementById("divMapResize");
  document.onmousemove = my_mapResizeRun;
  document.onmouseup = my_mapResizeStop;
  myMapResize.style.borderWidth = "2px";
  my_arrangeElement(myMapResize,myMapPos[0],myMapPos[1],myMapSize[0],myMapSize[1]);
}

function my_mapResizeRun(e) {
  my_getMousePos(e);
  myClickXY[0] += myMapPos[0];
  myClickXY[1] += myMapPos[1];
  my_arrangeElement(myMapResize,null,null,myClickXY[0]-myMapPos[0],myClickXY[1]-myMapPos[1]);
  return false;
}

function my_mapResizeStop(e) {
  myMapresizeDiff[0] = myClickXY[0]-myMapPos[0]-myMapSize[0];
  myMapresizeDiff[1] = myClickXY[1]-myMapPos[1]-myMapSize[1];
  document.onmousemove = document_move;
  document.onmouseup = null;
  var newMeterX = myBBox[0]+((((myBBox[2]-myBBox[0])/myMapSize[0])*(myClickXY[0]-myMapPos[0]))/2);
  var newMeterY = myBBox[3]-((((myBBox[3]-myBBox[1])/myMapSize[1])*(myClickXY[1]-myMapPos[1]))/2);
  myMapSize[0] = myClickXY[0]-myMapPos[0];
  myMapSize[1] = myClickXY[1]-myMapPos[1];
  my_arrangeElement(myMapResize,myMapSize[0]+myMapPos[0]-11-myFrameBorder,myMapSize[1]+myMapPos[1]-11-myFrameBorder,13,13);
  myMapResize.style.borderWidth = "0px";
  my_repaintXYSc(newMeterX,newMeterY,myScale);
  my_mapResizeSubFunctions();
}

function my_mapResizeSubFunctions() {}
*/

//-----------------------------------------------------------------------------------
// Panfunktionen:
//  - my_panInit wird in my_navi_pan (functions.js) aufgerufen, wenn man
//    auf den Pan-Button klickt
//  - my_panStart wird aufgerufen, wenn man in die Karte klickt
//  - my_panRun wird aufgerufen, wenn man dann die Maus bewegt, dabei wird die
//    Karte verschoben
//  - my_panStop wird aufgerufen, wenn man die Maus wieder loslaesst, dann wird
//    die neue BoundingBox der Karte ermittelt und die Karte neu gezeichnet
//  - my_panBreak wird aufgerufen, wenn der Panvorgang durch erneuten Klick auf
//    den Pan-Button abgebrochen wird
//-----------------------------------------------------------------------------------

function my_panInit() {
  my_eventLayer(true);
  myMapFrame.style.cursor = "pointer";
  myMapFrame.onmousedown = my_panStart;
  myMapFrame.onmouseup = my_panStop;
}

function my_panStart(e) {
  myMapFrame.style.cursor = "move";
  if(!my_checkWMSComplete()) { my_navi_pan_off(); return; }
  myPanActive = true;
  my_getMousePos(e);
  myStartXY[0] = myClickXY[0];
  myStartXY[1] = myClickXY[1];
  myEndXY[0] = myClickXY[0];
  myEndXY[1] = myClickXY[1];
  myMapFrame.onmousemove = my_panRun;
  return false;
}

function my_panRun(e) {
  if(myPanActive) {
    my_getMousePos(e);
    if(myClickXY[0]>0 && myClickXY[1]>0 && myClickXY[0]<myMapSize[0] && myClickXY[1]<myMapSize[1]) {
      myEndXY[0] = myClickXY[0];
      myEndXY[1] = myClickXY[1];
      var pos1 = my_pixel2Meter(myStartXY[0],myStartXY[1]);
      var pos2 = my_pixel2Meter(myEndXY[0],myEndXY[1]);
      my_arrangeElement("layerAll",myEndXY[0]-myStartXY[0],myEndXY[1]-myStartXY[1]);
    }
    return false;
  }
  if(mySlideActive) {
    myMapFrame.style.cursor = "default";
    my_sliderRun(e);
  }
}

function my_panStop(e) {
 if(myPanActive) {
//   out();
   myPanActive = false;
   window.status = "";
   var dif_x = myEndXY[0]-myStartXY[0];
   var dif_y = myEndXY[1]-myStartXY[1];
   if(Math.abs(dif_x)>10 || Math.abs(dif_y)>10) {
     var newMeterX = ((myBBox[2]-myBBox[0])/myMapSize[0])*dif_x;
     var newMeterY = (((myBBox[3]-myBBox[1])/myMapSize[1])*dif_y)*-1;
     var pos = my_getXYSc();
     my_repaintXYSc(pos[0]-newMeterX,pos[1]-newMeterY,null);
   } else {
     my_arrangeElement("layerAll",0,0);
//     my_eventLayer(false);
   }
   // start feature request
   if(dif_x == 0 && dif_y == 0) {
     if(ie) { var code = event.button; } else { var code = e.button; }
//     if(code != 2) { my_setFeatureRequest(); }
   }
 }
 if(mySlideActive) { my_sliderStop(e); }
// Gerstner
 my_panInit();
// my_panBreak();
// Statistik-Log:
 my_statistik("action=toolbox_pan");
}

// Gerstner
function my_panBreak() {
  myPanActive = false;
  my_eventLayer(false);
  myMapFrame.style.cursor = "default";
  myMapFrame.onmousedown = null;
  myMapFrame.onmousemove = null;
  myMapFrame.onmouseup = null;
  window.status = "";
  if(mySlideActive) { my_sliderStop(e); }
}

//-----------------------------------------------------------------------------------
// Scalebar:
//  - my_sliderInit wird bei der Initialisierung der Scalebar von my_init aufgerufen
//  - my_sliderStart wird aufgerufen, wenn man auf den Slider klickt
//  - my_sliderRun wird aufgerufen, wenn man dann die Maus bewegt, dabei wird das
//    Karte mitskaliert, daber kann die Skala sich nur innerhalb der diskreten
//    Skalen (myScales) aendern
//  - my_sliderStop wird aufgerufen, wenn man die Maus wieder loslaesst, dann wird
//    die Karte mit der neuen Skala gezeichnet
//  - my_setSlider setzt die Position des Sliders waehrend my_sliderRun oder wenn
//    im my_repaintXYSc eine neue Karte gezeichnet wird (die Skala kann sich ja
//    geaendert haben)
//  - my_newSlidePos wird aufgerufen, wenn auf die Scalebar geklickt wird
//-----------------------------------------------------------------------------------

function my_sliderInit() {
 if(my_checkDIV("divSlideBarIcon") && my_checkDIV("divSliderIcon")) {
  var mySlideBar = document.getElementById("divSlideBarIcon");
  var mySlideIcon = document.getElementById("divSliderIcon");
  mySlidePixel[0] = parseInt(mySlideBar.style.top)+(parseInt(mySlideIcon.style.height)/2);
  mySlidePixel[1] = parseInt(mySlideBar.style.height)+parseInt(mySlideBar.style.top)-(parseInt(mySlideIcon.style.height)/2);
  mySlideBar.onclick = my_newSlidePos;
  mySlideIcon.onmousedown = my_sliderStart;
 }
}

function my_sliderStart(e) {
  if(!my_checkWMSComplete()) {return;}
  document.onmousemove = my_sliderRun; //if slider out of mapframe
  document.onmouseup = my_sliderStop;
  my_eventLayer(true);
  mySlideActive = true;
  document.getElementById("layerMeasureLine").style.visibility = "hidden";
  document.getElementById("layerMeasureRun").style.visibility = "hidden";
  for(var i=0;i<myUsemap.length;i++) {
    document.getElementById("layerUsemap"+i).style.visibility = "hidden";
  }
//  document.getElementById("layerMarker").style.visibility = "hidden";
  return false;
}

function my_sliderRun(e) {
  if(!my_checkWMSComplete()) {return;}
  if(mySlideActive) {
    my_getMousePos(e);
    myClickXY[1] += myMapPos[1];
    var proc = 100-((100/(mySlidePixel[1]-mySlidePixel[0]))*(myClickXY[1]-mySlidePixel[0]));
    if(proc>100) { proc = 100; }
    if(proc<0) { proc = 0; }
// Gerstner: auf numscales runden
    mySliderScale = myScales[Math.round(proc*(mynumscales-1)/100)];
    my_setSlider(Math.round(proc*(mynumscales-1)/100));
    var lastProc=myScale;
    proc=mySliderScale;
    var xy = new Array();
    xy[0] = parseInt((myMapSize[0]*lastProc)/(proc));
    xy[1] = parseInt((myMapSize[1]*lastProc)/(proc));
    xy[2] = (myMapSize[0]-(xy[0]))/2;
    xy[3] = (myMapSize[1]-(xy[1]))/2;
    if(isNaN(xy[0]) == false && isNaN(xy[1]) == false && isNaN(xy[2]) == false && isNaN(xy[3]) == false) {
      if(mySingleWMSRequest) { var c = myWMS.length; } else { var c = 1; }
      for(var i=0;i<c;i++) {
        var tmp = document.getElementById("map"+i);
// Gerstner: +px
        tmp.style.left = xy[2]+"px";
        tmp.style.top = xy[3]+"px";
        tmp.style.width = xy[0]+"px";
        tmp.style.height = xy[1]+"px";
      }
    }
    my_show_statusbar(mySliderScale);
    d.scalecheck(mySliderScale);
    return false;
  }
}

function my_sliderStop(e) {
  document.onmousemove = null;
  document.onmouseup = null;
  mySlideActive = false;
  for(var i=0;i<myUsemap.length;i++) {
    document.getElementById("layerUsemap"+i).style.visibility = "visible";
  }
//  document.getElementById("layerMarker").style.visibility = "visible";
  document.getElementById("layerMeasureLine").style.visibility = "visible";
  document.getElementById("layerMeasureRun").style.visibility = "visible";
  my_statistik("scale="+mySliderScale+"&action=slider_scale");
  my_repaintXYSc(null,null,mySliderScale);
// Gerstner: andere Modi verlassen
  my_navi_pan_off();
  my_navi_zoom_off();
  my_navi_measure_off();
}

function my_setSlider(scnum) {
  if(my_checkDIV("divSliderIcon")) { 
// Gerstner: auf numscales runden
    var newPos = mySlidePixel[1]-(mySlidePixel[1]-mySlidePixel[0])*parseInt(scnum)/(mynumscales-1);
    document.getElementById("divSliderIcon").style.top = (newPos-(parseInt(document.getElementById("divSliderIcon").style.height)/2)-myFrameBorder)+"px";
//  document.getElementById("divSliderIcon").style.top = (newPos-5)+"px";
  }
}

function my_newSlidePos(e) {
  my_getMousePos(e);
  myClickXY[0] += myMapPos[0];
  myClickXY[1] += myMapPos[1];
  var proc = 100-((100/(mySlidePixel[1]-mySlidePixel[0]))*(myClickXY[1]-mySlidePixel[0]));
  if(proc>100) { proc = 100; }
  if(proc<0) { proc = 0; }
// Gerstner: auf numscales runden
  mySliderScale = myScales[Math.round(proc*(mynumscales-1)/100)];
  my_statistik("scale="+mySliderScale+"&action=slider_scale");
  my_repaintXYSc(null,null,mySliderScale);
// Gerstner: andere Modi verlassen
  my_navi_pan_off();
  my_navi_zoom_off();
  my_navi_measure_off();
}

//function my_setScaleText(val) {
//  if(my_checkDIV("divScStatus")) {
//    document.getElementById("divScStatus").innerHTML = "<font style='background-color:rgb(255,204,0)'>&nbsp;"+val+"&nbsp;</font>";
//  }
//}

//-----------------------------------------------------------------------------------
// Massstabs-Leiste (deaktiviert)
//-----------------------------------------------------------------------------------

/*
function my_scalebar(res) {
  if(myScale<10){
    var unit = '10&nbsp;cm';
    var factor = 10/myScale;
    var img_width = Math.round(factor * res);
  }
  if(myScale>= 10 && myScale< 100){
    var unit = '1&nbsp;m';
    var factor = 100/myScale;
    var img_width = Math.round(factor * res);
  }
  if(myScale< 1000 && myScale>= 100){
    var unit = '10&nbsp;m';
    var factor = 1000/myScale;
    var img_width = Math.round(factor * res);
  }
  if(myScale< 10000 && myScale>= 1000){
    var unit = '100&nbsp;m';
    var factor = 10000/myScale;
    var img_width = Math.round(factor * res);
  }
  if(myScale< 100000 && myScale>= 10000){
    var unit = '1&nbsp;km';
    var factor = 100000/myScale;
    var img_width = Math.round(factor * res);
  }
  if(myScale< 1000000 && myScale>= 100000){
    var unit = '10&nbsp;km';
    var factor = 1000000/myScale;
    var img_width = Math.round(factor * res);
  }
  if(myScale< 10000000 && myScale>= 1000000){
    var unit = '100&nbsp;km';
    var factor = 10000000/myScale;
    var img_width = Math.round(factor * res);
  }
  if(myScale< 100000000 && myScale>= 10000000){
    var unit = '1000&nbsp;km';
    var factor = 100000000/myScale;
    var img_width = Math.round(factor * res);
  }
  if(myScale>= 100000000){
    var unit = '1000&nbsp;km';
    var factor = 100000000/myScale;
    var img_width = Math.round(factor * res);
  }
  var tmp = "<img id='divScaleBarImg' src='"+scalebarImg.src+"' width='"+img_width+"'><font id='divScalebarText'>"+unit+"</font>";
  return tmp;
}
*/

//-----------------------------------------------------------------------------------
// Zoomfunktionen:
//  - my_zoomBoxInit wird in my_navi_zoom (functions.js) aufgerufen, wenn man
//    auf den Zoom-Button klickt
//  - my_zoomBoxStart wird aufgerufen, wenn man in die Karte klickt
//  - my_zoomBoxRun wird aufgerufen, wenn man dann die Maus bewegt, dabei wird das
//    Auswahlrechteck gezeichnet
//  - my_zoomBoxStop wird aufgerufen, wenn man die Maus wieder loslaesst, dann wird
//    die neue BoundingBox der Karte ermittelt und die Karte neu gezeichnet
//  - my_zoomBoxBreak wird aufgerufen, wenn der Zoomvorgang durch erneuten Klick auf
//    den Zoom-Button abgebrochen wird
//-----------------------------------------------------------------------------------

function my_zoomBoxInit() {
//  my_measureStop();
  my_eventLayer(true);
  myMapFrame.style.cursor = "crosshair";
  myMapFrame.onmousedown = my_zoomBoxStart;
  myMapFrame.onmouseup = my_zoomBoxStop;
}

function my_zoomBoxStart(e) {
  myZoomBoxActive = true;
  my_getMousePos(e);
  myStartXY[0] = myClickXY[0];
  myStartXY[1] = myClickXY[1];
  myMapFrame.onmousemove = my_zoomBoxRun;
  return false;
}

function my_zoomBoxRun(e) {
  my_getMousePos(e);
  var pos = my_pixel2Meter(myClickXY[0],myClickXY[1]);
//  window.status = "XY: "+pos[0]+","+pos[1];
  if(myZoomBoxActive) {
    if(ie) { var ad = 2; } else { var ad = 6; } //NS6
    if(myStartXY[0] > myClickXY[0]) {
      zbb[2] = myStartXY[0]-1;
      zbb[0] = myClickXY[0]-1;
    } else {
      zbb[0] = myStartXY[0]-ad;
      zbb[2] = myClickXY[0]-ad;
    }
    if(myStartXY[1] > myClickXY[1]) {
      zbb[3] = myStartXY[1]-1;
      zbb[1] = myClickXY[1]-1;
    } else {
      zbb[1] = myStartXY[1]-ad;
      zbb[3] = myClickXY[1]-ad;
    }
    if((zbb[2]-zbb[0])>0 && (zbb[3]-zbb[1])>0 && zbb[0]>0 && zbb[1]>0 && zbb[2]<myMapSize[0] && zbb[3]<myMapSize[1]) {
      myZoomBox.style.visibility = "visible";
// Gerstner: +px
      myZoomBox.style.left = zbb[0]+"px";
      myZoomBox.style.top = zbb[1]+"px";
      myZoomBox.style.width = (zbb[2]-zbb[0])+"px";
      myZoomBox.style.height = (zbb[3]-zbb[1])+"px";
    }
    return false;
  }
}

function my_zoomBoxStop(e) {
  myZoomBoxActive = false;
  myMapFrame.onmousedown = null;
  myMapFrame.onmousemove = null;
  myMapFrame.onmouseup = null;
  if(isNaN(zbb[0]) && isNaN(zbb[1]) && isNaN(zbb[2]) && isNaN(zbb[3])) {
    var pos1 = my_pixel2Meter(myClickXY[0],myClickXY[1]);
    my_repaintXYSc(pos1[0],pos1[1],myScale);
  } else {
    var pos1 = my_pixel2Meter(zbb[0],zbb[3]);
    var pos2 = my_pixel2Meter(zbb[2],zbb[1]);
    var mapX = ((pos2[0]-pos1[0])/2)+pos1[0];
    var mapY = ((pos2[1]-pos1[1])/2)+pos1[1];
    if((pos2[0]-pos1[0])>(pos2[1]-pos1[1])) {
      var newSc = (myScale/(myBBox[2]-myBBox[0]))*(pos2[0]-pos1[0]);
    } else {
      var newSc = (myScale/(myBBox[3]-myBBox[1]))*(pos2[1]-pos1[1]);
    }
    myZoomBox.style.visibility = "hidden";
    my_repaintXYSc(mapX,mapY,newSc);
  }
  zbb = new Array();
  window.status = "";
  my_zoomBoxInit();
//   my_zoomBoxBreak();
// Gerstner: Statistik-Log
  my_statistik("action=toolbox_zoombereich");
}

// Gerstner
function my_zoomBoxBreak() {
  myZoomBoxActive = false;
  my_eventLayer(false);
  myMapFrame.style.cursor = "default";
  myMapFrame.onmousedown = null;
  myMapFrame.onmousemove = null;
  myMapFrame.onmouseup = null;
  zbb = new Array();
  window.status = "";
  myZoomBox.style.visibility = "hidden";
}

//-----------------------------------------------------------------------------------
// Messfunktionen:
//  - my_measureInit wird in my_navi_measure (functions.js) aufgerufen, wenn man
//    auf den Mess-Button klickt
//  - my_measureStart wird aufgerufen, wenn man in die Karte klickt
//  - my_measureRun wird aufgerufen, wenn man dann die Maus bewegt
//  - my_measureStop bzw. my_measureDelete wird aufgerufen, wenn der Messvorgang
//    abgebrochen wird, z.B. wenn man nochmal auf den Mess-Button klickt
//  - my_polyClose wird aufgerufen, wenn per Doppelklick in die Karte geklickt wird,
//    dann wird das Ergebnis im Messergebnis-Fenster dargestellt
//  - my_getMeasureFrame oeffnet das Messergebnis-Fenster
//  - my_drawDashedLine zeichnet die gestrichelte Messlinie (wird in my_setMapRequest
//    und in my_measureStart aufgerufen)
//  - my_evaluateDashes berechnet die Laenge des Messlinienzugs
//  - my_getDistance und my_measureArea berechnet den Abstand zweier Punkte bzw. die
//    Flaeche eines Polygons
//-----------------------------------------------------------------------------------

function my_measureInit(val) { // 0: without tooltip; 1:with tooltip; 2:only list; 3:tooltip+list
  myMeasureFormat = val;
  if(myMeasurePolyClosed == true) { my_measureDelete(); }
  my_eventLayer(true);
  myMeasureActive = true;
  myMapFrame.style.cursor = "crosshair";
  myMapFrame.onmousedown = my_measureStart;
  myMapFrame.onmousemove = my_measureRun;
  myMapFrame.ondblclick = my_polyClose;
  myMapFrame.onmouseup = null;
}

function my_measureStart(e) {
  myMeasurePolyClosed = false;
  my_getMousePos(e);
  // right mouseclick -> stop
  if(ie) { var code = event.button; } else { var code = e.button; }
  if(code == 2) { my_polyClose(); return; }

  var pos = my_pixel2Meter(myClickXY[0],myClickXY[1]);
  myMeasure[myMeasure.length] = new Array(0,0,0,0);
  myMeasure[myMeasure.length-1][0] = Math.round(pos[0]*100)/100;
  myMeasure[myMeasure.length-1][1] = Math.round(pos[1]*100)/100;
  if(myMeasure.length > 1) {
    var dist_x = Math.abs(myMeasure[myMeasure.length-2][0]-myMeasure[myMeasure.length-1][0]);
    var dist_y = Math.abs(myMeasure[myMeasure.length-2][1]-myMeasure[myMeasure.length-1][1]);
    var dist = Math.round(Math.sqrt(Math.pow(dist_x,2)+Math.pow(dist_y,2))*100)/100;
    myMeasure[myMeasure.length-1][2] = dist;
    var totalDist = myMeasure[myMeasure.length-2][3]+dist;
    myMeasure[myMeasure.length-1][3] = Math.round(totalDist*100)/100;
  }
  // poly closed
  var d = my_getDistance(myMeasure[0][0],myMeasure[0][1],myMeasure[myMeasure.length-1][0],myMeasure[myMeasure.length-1][1]);
  var tol = 5*(myBBox[2]-myBBox[0])/myMapSize[1];
  if(tol<0.5) { tol = 0.3; }
  if(myMeasure.length>2 && d<tol) {
    myMeasurePolyClosed = true;
    myMeasure[myMeasure.length-1][0] = myMeasure[0][0];
    myMeasure[myMeasure.length-1][1] = myMeasure[0][1];
    my_polyClose();
  }
  my_drawDashedLine();
  if(myMeasure.length>myMaxMeasurePoints) {
    alert(ErrMess[0]);
    my_polyClose();
//my_measureStop();
  }
}

function my_measureRun(e) {
  my_getMousePos(e);
  var pos = my_pixel2Meter(myClickXY[0],myClickXY[1]);
  window.status = "XY: "+(Math.round(pos[0]*100)/100)+","+(Math.round(pos[1]*100)/100);
  if(myMeasure.length>0){
    var dist_x = Math.abs(myMeasure[myMeasure.length-1][0]-pos[0]);
    var dist_y = Math.abs(myMeasure[myMeasure.length-1][1]-pos[1]);
    if(isNaN(dist_x) == false) {
      // rubberline
      var posn = my_meter2Pixel(myMeasure[myMeasure.length-1][0],myMeasure[myMeasure.length-1][1]);
      var str_display = my_evaluateDashes(posn[0],posn[1],myClickXY[0],myClickXY[1],0);
      str_display += "<div style='position:absolute;left:"+(myClickXY[0])+"px;top:"+(myClickXY[1]-18)+"px;z-index:2'><font class='divMeasureText'>"+(Math.round(Math.sqrt(Math.pow(dist_x,2)+Math.pow(dist_y,2))*1)/1)+"&nbsp;m</font></div>";
    } else {
      var str_display = "";
    }
    document.getElementById("layerMeasureRun").innerHTML = str_display;
  }
}

function my_measureStop() {
  myMeasureActive = false;
  window.status = "";
  document.getElementById("layerMeasureRun").innerHTML = "";
  myMapFrame.onmousedown = null;
  myMapFrame.onmousemove = null;
  myMapFrame.ondblclick = null;
  myMapFrame.onmouseup = null;
// Gerstner
//  my_navi_pan_off();
//  my_navi_zoom_off();
  my_navi_measure_off();
  my_eventLayer(false);
}

function my_measureDelete() {
  myMeasureActive = false;
  myMeasure = new Array();
  document.getElementById("layerMeasureLine").innerHTML = "";
  document.getElementById("layerMeasureRun").innerHTML = "";
  myMeasurePolyClosed = false;
  my_eventLayer(false);
  window.status = "";
}

function my_drawDashedLine() {
  var str_mPoints = "";
  for(var i=0;i<myMeasure.length;i++) {
    var pos = my_meter2Pixel(myMeasure[i][0],myMeasure[i][1]);
    // 1. point
    if(i==0 && myMeasurePolyClosed == false) {
      if(ie) { wz=9;pz=6; } else { wz=5;pz=6; }
      str_mPoints += "<div class='divMeasure1stPoint' style='position:absolute;top:"+(pos[1]-pz)+"px;left:"+(pos[0]-pz)+"px;width:"+wz+"px;height:"+wz+"px;font-size:0px'></div>";

    } else {
      // measure labels
      if(myScale<myMaxScaleMeasure && isNaN(myMeasure[i][3]) == false) {
        if(myMeasureFormat==1 || myMeasureFormat==3) { // output tooltip
          str_mPoints += "<div style='position:absolute;top:"+(pos[1]+1)+"px;left:"+(pos[0]+1)+"px;z-index:2'><font class='divMeasureText'>"+Math.round(myMeasure[i][3])+"m (+"+Math.round(myMeasure[i][2])+")</font></div>";
        }
      }
    }
    if(myMeasureActive && (myMeasureFormat==2 || myMeasureFormat==3)) {
      my_getMeasureFrame(myShowMeasure);
    }
  }
  if(myMeasure.length>1) {
    for(var k=1;k<myMeasure.length;k++){
      var pos0 = my_meter2Pixel(myMeasure[k][0],myMeasure[k][1]);
      var pos1 = my_meter2Pixel(myMeasure[k-1][0],myMeasure[k-1][1]);
      str_mPoints += my_evaluateDashes(pos1[0],pos1[1],pos0[0],pos0[1],0);
    }
  }
  document.getElementById("layerMeasureLine").innerHTML = str_mPoints;
}

function my_evaluateDashes(x1,y1,x2,y2,count) {
  var str_dashedLine = "";
  var s = myMeasureDashDist;
  var d = Math.sqrt(Math.pow((y1-y2),2)+Math.pow((x1-x2),2)) ;
  var n = Math.round(d/s);
  var s_x = (x2-x1)/n;
  var s_y = (y2-y1)/n;
  for(var i=0;i<=n;i++) {
    var x = Math.round(x1+i*s_x)-4;
    var y = Math.round(y1+i*s_y)-4;
    if(i == 0 || i == n) { var myCl = "divMeasurePoint"; } else { var myCl = "divMeasureLine"; }
    if(ie) { myCl += "IE"; } else { myCl += "NS"; }
    str_dashedLine += "<div class='"+myCl+"' style='position:absolute;top:"+y+"px;left:"+x+"px'></div>";
  }
  return str_dashedLine;
}

function my_polyClose() {
  if(myMeasure[0][0]==myMeasure[myMeasure.length-1][0] && myMeasure[0][1]==myMeasure[myMeasure.length-1][1]) {
    myMeasurePolyClosed = true;
  } else { myMeasurePolyClosed = false; }
// Gerstner: anderer Infoframe
  my_infoFrameShow(myShowMeasure,'Messergebnis','');
//  my_measureStop();
//  my_getMeasureFrame(myShowMeasure);
}

function my_getMeasureFrame(url) {
  var Xwin = window.open(url,'measure','width=200,height=300,menu=no');
}

function my_getDistance(dx1,dy1,dx2,dy2) {
  return Math.sqrt((dx1-dx2)*(dx1-dx2)+(dy1-dy2)*(dy1-dy2));
}

function my_measureArea() {
  var a = 0;
  if(myMeasurePolyClosed == true) {
    for(var i=1;i<myMeasure.length;i++) {
      a += (myMeasure[i-1][1]-myMeasure[i][1])*(myMeasure[i-1][0]+myMeasure[i][0]);
    }
    a = Math.abs(a/2);
    a = Math.round(a*1)/1;
  }
  return a;
}

//-----------------------------------------------------------------------------------
// Tastatur-Eingaben (deaktiviert)
//-----------------------------------------------------------------------------------

/*
function my_setKeyhandler() {
  //alert(window.frames.name);
  window.focus();
  window.document.onkeydown = my_Keyhandler;
}

function my_Keyhandler(k) {
  if(ie) { code = event.keyCode; } else { code = k.which; }
  if(code == 61 || code == 187) { my_zoomMap(-1); }
  if(code == 109 || code == 189) { my_zoomMap(+1); }
  if(code == 38) { my_moveMap(0,myAddNav); }
  if(code == 40) { my_moveMap(0,-myAddNav); }
  if(code == 39) { my_moveMap(myAddNav,0); }
  if(code == 37) { my_moveMap(-myAddNav,0); }
  if(code == 27) { my_measureDelete(); } //esc
  if(code == 32) { my_measureStop(); }  //space
}
*/

//-----------------------------------------------------------------------------------
// Marker und Hightlight-Funktionen (deaktiviert)
//-----------------------------------------------------------------------------------

/*
function my_showHighlight(x,y) {
  if(my_checkDIV("divHighlightIcon")) {
    var pos = my_meter2Pixel(x,y);
    my_arrangeElement("divHighlightIcon",pos[0]-(highlightImg.width/2),pos[1]-(highlightImg.height/2));
    document.getElementById("divHighlightIcon").style.visibility = "visible";
  }
}

function my_hideHighlight() {
  if(my_checkDIV("divHighlightIcon")) {
    my_arrangeElement("divHighlightIcon",-20,-20);
    my_arrangeElement("divHighlightIcon",-20,-20);
    document.getElementById("divHighlightIcon").style.visibility = "hidden";
  }
}

function my_setMarker(x,y,sc,tooltip,obj) {
  //alert(x+" "+y+" "+sc+" "+tooltip+" "+obj);
  if(x>0) {
    myMarker = new Array();
    myMarker[0] = x;
    myMarker[1] = y;
    if(sc != null) { myMarker[2] = sc; } else { myMarker[2] = myScale; }
    if(tooltip!="") { myMarker[3] = tooltip; } else { myMarker[3] = ""; }
    // if obj==number -> called by my_setMapRequest() -> no redraw
    if(obj!=1) { // new marker is set
      my_repaintXYSc(myMarker[0],myMarker[1],myMarker[2]);
      myMarker[4] = obj;
    }
    if(my_checkDIV("layerMarker")) {
      var pos = my_meter2Pixel(myMarker[0],myMarker[1]);
      document.getElementById("layerMarker").style.visibility = "visible";
// Gerstner: +px
      document.getElementById("layerMarker").style.left = (pos[0]-(parseInt(markerImg.width)/2))+"px";
      document.getElementById("layerMarker").style.top = (pos[1]-(parseInt(markerImg.height)/2))+"px";
      if(my_checkDIV("divMarkerInfo") && myMarker[3]!="") {
        document.getElementById("divMarkerInfo").innerHTML = myMarker[3];
        document.getElementById("divMarkerInfo").style.visibility = "visible";
      } else {
        document.getElementById("divMarkerInfo").innerHTML = "";
        document.getElementById("divMarkerInfo").style.visibility = "hidden";
      }
    }
  } else {
    document.getElementById("layerMarker").style.visibility = "hidden";
    document.getElementById("divMarkerInfo").style.visibility = "hidden";
    myMarker = new Array(-1,-1,myScale,"");
  }
}
*/

function my_eventLayer(val) {
  // over maps, under measure, zoombox
  if(val == true) {
    myMapFrame = document.getElementById("layerEventHandling");
    myMapFrame.style.visibility = "visible";
  } else {
//    my_setInfo(msgList[9]);
    document.getElementById("layerEventHandling").style.visibility = "hidden";
    myMapFrame = document.getElementById("layerAll");
// Gerstner: per default nicht pannen
//    my_panInit();
  }
}

//-----------------------------------------------------------------------------------
// Highlight-Funktionen (reaktiviert)
//-----------------------------------------------------------------------------------


// DEAKTIVIERT!

function over(val) {
return;
  var tmp = typeof val;
  if (tmp == "string" && my_checkDIV(val)) { val = document.getElementById(val); }
  myUMObject = val;
  if(val.title) { myTooltip = val.title; }
  if(val.coords) {
    var coords = val.coords.split(',');
    if(val.shape.toUpperCase() == "RECT") {
      coords = new Array(coords[0],coords[1],coords[0],coords[3],coords[2],coords[3],coords[2],coords[1],coords[0],coords[1]);
    }
    if(val.shape.toUpperCase() == "CIRCLE") {
      var x = coords[0]-coords[2];
      var y = coords[1]-coords[2];
      var t = parseInt(coords[2]*2/3);
      coords = new Array(x,y,x,y+t*3,x+t*3,y+t*3,x+t*3,y); // to rect
    }
    var Xcoords = my_umXCoords(coords);
    var Ycoords = my_umYCoords(coords);
    var pgx = Xcoords.split(',');
    var pgy = Ycoords.split(',');
    for (var i=0;i<pgx.length;i++) {
     pgx[i] = parseInt(pgx[i]);
     pgy[i] = parseInt(pgy[i]);
    }
    my_umFillPoly(pgx,pgy);
    document.getElementById("layerUsemapHighlight").innerHTML = myUMArea;
  }
  return true;
}

function out() {
return;
  myUMArea = "";
  document.getElementById("layerUsemapHighlight").innerHTML = myUMArea;
  myTooltip = "";
  return true;
}

function my_umXCoords(coords) {
  var Xcoords = '';
  for(var i=0;i<coords.length;i=i+2) {
    if(i>0) { Xcoords += ', '; }
    Xcoords += parseInt(coords[i]);
  }
  return Xcoords;
}

function my_umYCoords(coords) {
  var Ycoords = '';
  for(var i=1;i<coords.length;i=i+2) {
    if(i>1) { Ycoords += ', '; }
    Ycoords += parseInt(coords[i]);
  }
  return Ycoords;
}

function my_umFillPoly(array_x,array_y) {
  var i;
  var y;
  var miny, maxy;
  var x1, y1;
  var x2, y2;
  var ind1, ind2;
  var ints;
  var n = array_x.length;
  if (!n) return;
  miny = array_y[0];
  maxy = array_y[0];
  for(var i=1;i<n;i++) {
    if(array_y[i] < miny) miny = array_y[i];
    if (array_y[i] > maxy) maxy = array_y[i];
  }
  for(y=miny;y<=maxy;y+=myQualityFillPoly) {
    var polyInts = new Array();
    ints = 0;
    for(var i=0;i<n;i++) {
      if(!i) {
        ind1 = n-1;
        ind2 = 0;
      } else {
        ind1 = i-1;
        ind2 = i;
      }
      y1 = array_y[ind1];
      y2 = array_y[ind2];
      if(y1 < y2) {
        x1 = array_x[ind1];
        x2 = array_x[ind2];
      } else if(y1 > y2) {
        y2 = array_y[ind1];
        y1 = array_y[ind2];
        x2 = array_x[ind1];
        x1 = array_x[ind2];
      } else continue;
      if ((y >= y1) && (y < y2))
        polyInts[ints++] = Math.round((y-y1)*(x2-x1)/(y2-y1) + x1);
      else if ((y == maxy) && (y > y1) && (y <= y2))
        polyInts[ints++] = Math.round((y-y1)*(x2-x1)/(y2-y1) + x1);
      }
    polyInts.sort(my_IntegerCompare);
    for(var i=0;i<ints;i+=2) {
     my_umMakeDiv(polyInts[i],y,polyInts[i+1]-polyInts[i]+1,myQualityFillPoly);
    }
  }
}

function my_IntegerCompare(x,y) {
  return (x < y) ? -1 : ((x > y)*1);
}

function my_umMakeDiv(x,y,w,h) {
  if(x<0) { w += x; x = 0; }
  if((x+w)>myMapSize[0]){ w = myMapSize[0]-x; }
  if(w>=0 && x<myMapSize[0] && y>=0 && y<myMapSize[1]) {
    myUMArea += '<div class="divUsemapHighlight" style="'+
    'left:' + x + 'px;'+
    'top:' + y + 'px;'+
    'width:' + w + 'px;'+
    'height:' + h + 'px;'+
    'clip:rect(0,'+w+'px,'+h+'px,0);' +
    '"><\/div>';
  }
}


//-----------------------------------------------------------------------------------
// Sanduhr (reaktiviert)
//-----------------------------------------------------------------------------------


var mod_sandclock_maxWait = 5000 * 60;
var mod_sandclock_minWait = 1000 * 0;

function my_sandclock(start,myMapId){
 if (opera==1) return;
 var allMaps = document.getElementsByName("mapimage");
 if(my_checkDIV("divWaitIcon")) {
  if(start) {
    if (OneLayer==false) {  // Gerstner
//      if (symbolchange) allMaps[1].style.display="none";
//      else for(var i=0;i<allMaps.length;i++) allMaps[i].style.display="none";
      document.getElementById("layerWMS1").style.display="none";
    }
    mod_sandclock_count = mod_sandclock_maxWait;
    var tmp = "<img src='"+waitImg.src+"'>";
    document.getElementById("divWaitIcon").innerHTML = tmp;
    document.getElementById("divWaitIcon").style.display="inline";
  }
  aktiv = setTimeout("my_sandclock('','"+myMapId+"')",100);
  mod_sandclock_count -= 1000; 
  var cnt = 0;
  for(var i=0;i<allMaps.length;i++) {
   if(allMaps[i].complete == true) { cnt++; }         
  }
  if((mod_sandclock_count <= 0 || cnt >= allMaps.length) && mod_sandclock_count < (mod_sandclock_maxWait - mod_sandclock_minWait)){
    clearTimeout(aktiv);
    document.getElementById("divWaitIcon").innerHTML = "";
    document.getElementById("divWaitIcon").style.display="none";
    if (OneLayer==false) { // Gerstner
//      for(var i=0;i<allMaps.length;i++) allMaps[i].style.display="inline";
      document.getElementById("layerWMS1").style.display="inline";
    }
  }
 }
}


//-----------------------------------------------------------------------------------
// History
//  - my_setHistoryObj wird in my_repaintXYSc aufgerufen, nachdem eine neue Karte
//    gezeichnet wurde
//  - my_setHistoryBack wird in my_navi_back (functions.js) aufgerufen, wenn man auf
//    den Back-Button klickt
//-----------------------------------------------------------------------------------

var myMapHistory = new Array();
function my_setHistoryObj() {
  var pos = my_getXYSc();
  if(myMapHistory.length <= 25) {
    myMapHistory.push(pos);
  } else {
    myMapHistory.shift();// fifo
    myMapHistory.push(pos);
  }
}

function my_setHistoryBack() {
  if(myMapHistory.length > 1) {
    myMapHistory.pop();// del actual
    var tmp = myMapHistory[myMapHistory.length-1];
    myMapHistory.pop();
    my_repaintXYSc(tmp[0],tmp[1],tmp[2]);
  }
}

//-----------------------------------------------------------------------------------
// Funktionen zur Darstellung des Infobox-Fensters
//-----------------------------------------------------------------------------------

// Gerstner: ersetze layerMenu durch divInfoBox (4x)
function my_moveIFrame() {
  document.onmousedown = my_moveIFrameStart;
  document.onmousemove = my_moveIFrameRun;
  document.onmouseup = my_moveIFrameStop;
}

function my_moveIFrameStart(e) {
  my_getMousePos(e);
  myStartXY[0] = parseInt(document.getElementById("divInfoBox").style.left);
  myStartXY[1] = parseInt(document.getElementById("divInfoBox").style.top);
  myEndXY[0] = myClickXY[0]-myStartXY[0];
  myEndXY[1] = myClickXY[1]-myStartXY[1];
  return false;
}

function my_moveIFrameRun(e) {
  my_getMousePos(e);
  var tmp = new Array(myClickXY[0]-myEndXY[0],myClickXY[1]-myEndXY[1]);
  infowidth = parseInt(infobox.style.width);
  infoheight = parseInt(infobox.style.height);
// Gerstner: Check auf Verlassen des Gebiets
  if (tmp[0]+infowidth+2>myMapPos[0]+myMapSize[0]) tmp[0]=myMapPos[0]+myMapSize[0]-infowidth-2;
  else if (tmp[0]<myMapPos[0]+2) tmp[0]=myMapPos[0]+2;
  if (tmp[1]+infoheight+2>myMapPos[1]+myMapSize[1]) tmp[1]=myMapPos[1]+myMapSize[1]-infoheight-2;
  else if (tmp[1]<myMapPos[1]+2) tmp[1]=myMapPos[1]+2; 
// Gerstner: +px
  document.getElementById("divInfoBox").style.left = tmp[0]+"px";
  document.getElementById("divInfoBox").style.top = tmp[1]+"px";
}

function my_moveIFrameStop(e) {
  eventID=2;
  document.onmousedown = null;
  document.onmousemove = document_move;
  document.onmouseup = null;
//  my_setKeyhandler();
}

//-----------------------------------------------------------------------------------
// Tool-Funktionen (werden nicht gebraucht)
//-----------------------------------------------------------------------------------

/*
function my_getLink() {
  var layWMS = my_getLayers("WMS");
  var layUsemap = my_getLayers("USEMAP");
  var url = window.location.protocol+"//"+window.location.host+window.location.pathname
   +"?X="+myXY[0]+"&Y="+myXY[1]+"&SCALE="+myScale+"&LAYERS="+layWMS[1]
   +"&OBJECT="+myMarker[0]+","+myMarker[1]+","+myMarker[2]+","+escape(myMarker[3])
   +"&USEMAPLAYER="+layUsemap[1]
   +"&MEASURE="+myMeasure
   +"&LEFT="+myMapPos[0]
   +"&TOP="+myMapPos[1]
   +"&WIDTH="+myMapSize[0]
   +"&HEIGHT="+myMapSize[1];
  return url;
}

function my_getCurrentStyle(element,cssPropertyName) {
  if(window.getComputedStyle) {
    return window.getComputedStyle(element,"").getPropertyValue(cssPropertyName.replace(/([A-Z])/g,"-$1").toLowerCase());
  } else if(element.currentStyle) {
    return element.currentStyle[cssPropertyName];
  } else { return ""; }
}

function my_minMaxMenu() {
  if(document.getElementById("myMenuMinMax").src == minImg.src) {
    document.getElementById(myIFrameActiveId).style.display = "none";
    document.getElementById("myMenuMinMax").src = maxImg.src;
  } else {
    document.getElementById(myIFrameActiveId).style.display  = "inline";
    document.getElementById("myMenuMinMax").src = minImg.src;
  }
}

function my_mailTo(subj) {
  this.location = "mailto:?subject="+subj+"&body="+encodeURIComponent(my_getLink());
}

function my_changeSkin(path) {
  if(imgPath == path) {
    val = "images"; 
    document.getElementById("layerMapBorder").style.border="2px solid rgb(70,70,70)";
  } else {
    val = path; 
    document.getElementById("layerMapBorder").style.border="3px double rgb(255,128,64)";
  }
  for(var i=0;i<document.getElementsByTagName("img").length;i++) {
    if(document.getElementsByTagName("img")[i].src.search(/\?/) == -1) {
      var tmp = document.getElementsByTagName("img")[i].src.replace(imgPath,val);
      document.getElementsByTagName("img")[i].src = tmp;
    }
  }
  imgPath = val;
}

my_registerVendorSpecific("setURLExtention()");
function setURLExtention() {
  return "SCALE="+myScale;
}

function my_registerVendorSpecific(stringFunction) {
  myVendorSpecific[myVendorSpecific.length] = stringFunction;
}
*/

//-----------------------------------------------------------------------------------
// Navigationspanel (wird in index.jsp definiert)
//-----------------------------------------------------------------------------------

/*
function my_setNaviPanel(w,h) {
  var l = myMapPos[0]+w;
  var t = myMapPos[1]+h;

  // slidebar
  content="<img src='"+slideBarImg.src+"'>";
  my_createDiv("divSlideBarIcon",l+22,t+70,15,151,true,content);
  content="<img src='"+sliderImg.src+"' title='"+imgTitle[9]+"' onmouseover=my_mOverEl(this) onmouseout=my_mOutOfEl(this)>";
  my_createDiv("divSliderIcon",l+22,t+108,15,9,true,content);

  // zoom
  content="<img src='"+zoomOutImg.src+"' title='"+imgTitle[11]+"' onclick=my_zoomMap(1.3) onmouseover=my_mOverEl(this) onmouseout=my_mOutOfEl(this)>";
  my_createDiv("divZoomOutIcon",l+40,t+63,-1,-1,true,content);
  content="<img src='"+zoomInImg.src+"' title='"+imgTitle[10]+"' onclick=my_zoomMap(0.7) onmouseover=my_mOverEl(this) onmouseout=my_mOutOfEl(this)>";
  my_createDiv("divZoomInIcon",l+40,t+202,-1,-1,true,content);
  content="<img src='"+zoomBoxImg.src+"' title='"+imgTitle[12]+"' onclick=my_zoomBoxInit();my_setInfo(this.title) onmouseover=my_mOverEl(this) onmouseout=my_mOutOfEl(this)>";
  my_createDiv("divZoomBoxIcon",l+55,t+54,-1,-1,true,content);

  // map back
  content="<img src='"+mapBackImg.src+"' title='"+imgTitle[13]+"' onclick=my_setHistoryBack() onmouseover=my_mOverEl(this) onmouseout=my_mOutOfEl(this)>";
  my_createDiv("divMapBackIcon",l+4,t+63,-1,-1,true,content);

  // navigation
  content="<img src='"+navImg[0].src+"' onClick=my_moveMap(0,myAddNav) title='"+imgTitle[0]+"' onmouseover=my_mOverEl(this) onmouseout=my_mOutOfEl(this)>";
  my_createDiv("divNavIcon",l+20,t+5,-1,-1,true,content);
  content="<img src='"+navImg[1].src+"' onClick=my_moveMap(myAddNav,0) title='"+imgTitle[3]+"' onmouseover=my_mOverEl(this) onmouseout=my_mOutOfEl(this)>";
  my_createDiv("divNavIcon",l+40,t+25,-1,-1,true,content);
  content="<img src='"+navImg[2].src+"' onClick=my_moveMap(0,-myAddNav) title='"+imgTitle[1]+"' onmouseover=my_mOverEl(this) onmouseout=my_mOutOfEl(this)>";
  my_createDiv("divNavIcon",l+20,t+45,-1,-1,true,content);
  content="<img src='"+navImg[3].src+"' onClick=my_moveMap(-myAddNav,0) title='"+imgTitle[2]+"' onmouseover=my_mOverEl(this) onmouseout=my_mOutOfEl(this)>";
  my_createDiv("divNavIcon",l,t+25,-1,-1,true,content);
  content="<img src='"+navImg[8].src+"' onClick=my_moveMap(-1,-1) title='"+imgTitle[4]+"' onmouseover=my_mOverEl(this) onmouseout=my_mOutOfEl(this)>";
  my_createDiv("divNavIcon",l+20,t+25,-1,-1,true,content);
  content="<img src='"+navImg[4].src+"' onClick=my_moveMap(myAddNav,myAddNav) title='"+imgTitle[5]+"' onmouseover=my_mOverEl(this) onmouseout=my_mOutOfEl(this)>";
  my_createDiv("divNavIcon",l+39,t+13,-1,-1,true,content);
  content="<img src='"+navImg[5].src+"' onClick=my_moveMap(myAddNav,-myAddNav) title='"+imgTitle[6]+"' onmouseover=my_mOverEl(this) onmouseout=my_mOutOfEl(this)>";
  my_createDiv("divNavIcon",l+39,t+43,-1,-1,true,content);
  content="<img src='"+navImg[7].src+"' onClick=my_moveMap(-myAddNav,myAddNav) title='"+imgTitle[7]+"' onmouseover=my_mOverEl(this) onmouseout=my_mOutOfEl(this)>";
  my_createDiv("divNavIcon",l+9,t+13,-1,-1,true,content);
  content="<img src='"+navImg[6].src+"' onClick=my_moveMap(-myAddNav,-myAddNav) title='"+imgTitle[8]+"' onmouseover=my_mOverEl(this) onmouseout=my_mOutOfEl(this)>";
  my_createDiv("divNavIcon",l+9,t+43,-1,-1,true,content);

  // sandclock for map loading
  content="<img src='"+waitImg.src+"'>";
  my_createDiv("divWaitIcon",(myMapSize[0]/2)+myMapPos[0]-16,(myMapSize[1]/2)+myMapPos[1]-16,-1,-1,true,content);
}

function my_mOverEl(elName) {
  elName.style.marginLeft = "1px";
  elName.style.marginTop = "1px";
  elName.style.cursor = "default";
}

function my_mOutOfEl(elName) {
  elName.style.marginLeft = "0px";
  elName.style.marginTop = "0px";
}

function my_setInfo(val) {
  if(!val) { val = ""; }
  if(my_checkDIV("divInfo")) {
    document.getElementById("divInfo").innerHTML = val;
  }
}
*/

//-----------------------------------------------------------------------------------
// Funktionen zur Darstellung des Messergebnis-Fensters
//-----------------------------------------------------------------------------------

function my_infoFrameMove(val) {
  my_infoFrameFunction = val;
  document.onmousedown = my_infoFrameStart;
  document.onmousemove = my_infoFrameRun;
  document.onmouseup = my_infoFrameStop;
}

function my_infoFrameStart(e) {
  my_getMousePos(e);
  myStartXY[0] = parseInt(document.getElementById("divInfoFrame").style.left);
  myStartXY[1] = parseInt(document.getElementById("divInfoFrame").style.top);
  myEndXY[0] = myClickXY[0]-myStartXY[0];
  myEndXY[1] = myClickXY[1]-myStartXY[1];
  document.getElementById("divInfoFrame").style.zIndex = 99;
}

// Gerstner: +px
function my_infoFrameRun(e) {
  my_getMousePos(e);
  if(my_infoFrameFunction == "move") {
    document.getElementById("divInfoFrame").style.cursor = "move";
    myIFramePos = new Array(myClickXY[0]-myEndXY[0],myClickXY[1]-myEndXY[1]);
    document.getElementById("divInfoFrame").style.left = (myIFramePos[0]-2)+"px";
    document.getElementById("divInfoFrame").style.top = (myIFramePos[1]-2)+"px";
    document.getElementById("divInfoFrameTitle").style.left = myIFramePos[0]+"px";
    document.getElementById("divInfoFrameTitle").style.top = myIFramePos[1]+"px";
    document.getElementById("divInfoFrameSrc").style.left = myIFramePos[0]+"px";
    document.getElementById("divInfoFrameSrc").style.top = (myIFramePos[1]+myIFrameTitle)+"px";
    document.getElementById("divInfoFrameClose").style.left = (myIFramePos[0]+myIFrameSize[0])+"px";
    document.getElementById("divInfoFrameClose").style.top = myIFramePos[1]+"px";
    document.getElementById("divInfoFrameStatus").style.left = myIFramePos[0]+"px";
    document.getElementById("divInfoFrameStatus").style.top = (myIFramePos[1]+myIFrameSize[1]-myIFrameTitle)+"px";
  }
  return false;
}

function my_infoFrameStop(e) {
  document.onmousedown = null;
  document.onmousemove = document_move;
  document.onmouseup = null;
  document.getElementById("divInfoFrame").style.zIndex = 4;
//  my_setKeyhandler();
  document.getElementById("divInfoFrame").style.cursor = "nw-resize";
}

function my_infoFrameClose() {
  document.getElementById("divInfoFrame").style.display = "none";
  document.getElementById("divInfoFrameSrc").style.display = "none";
  document.getElementById("divInfoFrameTitle").style.display = "none";
  document.getElementById("divInfoFrameClose").style.display = "none";
  document.getElementById("divInfoFrameStatus").style.display = "none";
  myFeatureInfoURL = saveFeatureInfoURL;
}

function my_infoFrameShow(url,title,status) {
//  document.getElementById("layerPrintPreview").style.visibility = "hidden";
  document.getElementById("divInfoFrame").style.display = "inline";
  document.getElementById("divInfoFrameSrc").style.display = "inline";
  document.getElementById("divInfoFrameTitle").style.display = "inline";
  document.getElementById("divInfoFrameClose").style.display = "inline";
//  document.getElementById("divInfoFrameMin").style.display = "inline";
//  document.getElementById("divInfoFrameResize").style.display = "inline";
  document.getElementById("divInfoFrameStatus").style.display = "inline";
  if(title) {
    document.getElementById("divInfoFrameTitle").innerHTML = "&nbsp;"+title;
  } else {
    document.getElementById("divInfoFrameTitle").innerHTML = "";
  }
  if(status) {
    document.getElementById("divInfoFrameStatus").innerHTML = "&nbsp;"+status;
  } else {
    document.getElementById("divInfoFrameStatus").innerHTML = "";
  }
  document.getElementById("divInfoFrameSrc").src = url;
//  document.getElementById("divInfoFrameMin").style.backgroundImage = "url("+imgPath+"/minimize.gif)";
}

//function my_infoFrameMin() {
//  if(document.getElementById("divInfoFrame").style.display=="inline") {
//    document.getElementById("divInfoFrame").style.display = "none";
//    document.getElementById("divInfoFrameSrc").style.display = "none";
//    document.getElementById("divInfoFrameResize").style.display = "none";
//    document.getElementById("divInfoFrameStatus").style.display = "none";
//    document.getElementById("divInfoFrameMin").style.backgroundImage = "url("+imgPath+"/maximize.gif)";
//  } else {
//    document.getElementById("divInfoFrame").style.display = "inline";
//    document.getElementById("divInfoFrameSrc").style.display = "inline";
//    document.getElementById("divInfoFrameResize").style.display = "inline";
//    document.getElementById("divInfoFrameStatus").style.display = "inline";
//    document.getElementById("divInfoFrameMin").style.backgroundImage = "url("+imgPath+"/minimize.gif)";
//  }
//}


function my_getID(elName) {
  var theObj = document.getElementById(elName);
  return theObj;
}

function my_correctPNG(i,newWMS) {
  if (AlphaImageLoader && ie && navigator.userAgent.indexOf("Opera")<0 && newWMS.toUpperCase().search(/PNG/i)> -1) {
    my_getID("map"+i).style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+my_getID("map"+i).src+"',sizingmethod=scale);";
    my_getID("map"+i).src=transparentImg.src;
  }
}



