/* COPYRIGHT: (C) 2001 by ccgis. This program is free software under the GNU General Public
*  License (>=v2). Read the file gpl.txt that comes with Mapbender for details. */

/*GLOBALS*/
var ie = document.all?1:0;
var n6 = document.getElementById&&!document.all?1:0;
var n4 = document.layers?1:0;

var mb_feature_count = 100;

var mb_resolution = 28.35;
var mb_mapObj = new Array();
var mb_fiWin = null;
var mb_panActive = false;
var clickX;
var clickY;
var mb_start_x = 0;
var mb_start_y = 0;
var mb_end_x = 0;
var mb_end_y = 0;
var mb_offset_top = 0;
var mb_offset_right = 0;
var mb_offset_bottom = 0;
var mb_offset_left = 0;
var mb_log = null;

var mb_MapRequestSubFunctions = new Array();
var mb_WfsReadSubFunctions = new Array();
var mb_WfsWriteSubFunctions = new Array();
var mb_MapRequestPreFunctions = new Array();
var mb_FeatureInfoPreFunctions = new Array();
var mb_PanSubElements = new Array();
var mb_InitFunctions = new Array();
var mb_MapObjectSubFunctions = new Array();
var mb_GetScalePreFunctions = new Array();
var mb_vendorSpecific = new Array();
var mb_loadWmsSubFunctions = new Array();
var mb_security_proxy = "http://wms1.ccgis.de/mapbender/tools/security_proxy.php?mb_ows_security_proxy=";

var mb_nr = '5b4784bb6da7d5466285b6f96b0ed8be';var mb_myLogin = '';var mb_styleID = 'd41d8cd98f00b204e9800998ecf8427e';var mb_myBBOX = '';var owsproxy = 'http://<ip or name>/owsproxy';
var mb_trans = new Image; 
mb_trans.src = "../img/transparent.gif";
/*END OF GLOBALS*/
	
function Mb_exception(message) {
	try {
		mb_ajaxWrap_post('../php/mb_js_exception.php', {text:message});
	}
	catch(e) {
		alert(message);
	}
}

function mb_ajax_get(url, param, callback) {
	try {
		mb_ajaxWrap_get(url, param, callback);
	}
	catch(e) {
		alert('map.php: mb_ajax_get:'+e);
	}
}	

function mb_ajax_post(url, param, callback) {
	try {
		mb_ajaxWrap_post(url, param, callback);
	}
	catch(e) {
		alert('map.php: mb_ajax_post:'+e);
	}
}	
	
function mb_ajax_json(url, param, callback) {
	try {
		mb_ajaxWrap_json(url, param, callback);
	}
	catch(e) {
		alert('map.php: mb_ajax_post_json:'+e);
	}
}	
	
function init(){
	for(var i=0; i<mb_InitFunctions.length; i++){
		eval(mb_InitFunctions[i]);
	}
	for(var i=0; i<mb_mapObj.length; i++){
		setMapRequest(mb_mapObj[i].frameName);
	}      	
}
/*registerFunctions*/
function mb_registerInitFunctions(stringFunction){
	mb_InitFunctions[mb_InitFunctions.length] = stringFunction;
}
function mb_registerPanSubElement(elName){
	var ind = mb_PanSubElements.length;
	mb_PanSubElements[ind] = elName;
}
function mb_registerPreFunctions(stringFunction){
	mb_MapRequestPreFunctions[mb_MapRequestPreFunctions.length] = stringFunction;
}
function mb_registerFeatureInfoPreFunctions(stringFunction){
	mb_FeatureInfoPreFunctions[mb_FeatureInfoPreFunctions.length] = stringFunction;
}
function mb_registerSubFunctions(stringFunction){
	mb_MapRequestSubFunctions[mb_MapRequestSubFunctions.length] = stringFunction;
}
function mb_registerWfsReadSubFunctions(stringFunction){
	mb_WfsReadSubFunctions[mb_WfsReadSubFunctions.length] = stringFunction;
}
function mb_registerWfsWriteSubFunctions(stringFunction){
	mb_WfsWriteSubFunctions[mb_WfsWriteSubFunctions.length] = stringFunction;
}
function mb_registerMapObj(frameName, elementName,wms_index,width, height){
	mb_mapObj[mb_mapObj.length] = new mb_mapObj_const(frameName, elementName, width, height, wms_index);    
}
function  mb_registerMapObjectSubFunctions(stringFunction){
	mb_MapObjectSubFunctions[mb_MapObjectSubFunctions.length] = stringFunction;
}
function  mb_registerGetScalePreFunctions(stringFunction){
   mb_GetScalePreFunctions[mb_GetScalePreFunctions.length] = stringFunction;
}
function mb_registerVendorSpecific(stringFunction){
   mb_vendorSpecific[mb_vendorSpecific.length] = stringFunction;
}
function mb_registerloadWmsSubFunctions(stringFunction){
	mb_loadWmsSubFunctions[mb_loadWmsSubFunctions.length] = stringFunction;
}
function mb_removeFunctionFromArray(arrayname,stringFunction){
	var length = eval(arrayname+".length");
	for(var i=0; i<length; i++){
		if(eval(arrayname+"["+i+"]") == stringFunction){
			var newArray1 = eval(arrayname+".slice(0, "+(i-1)+")");
			var newArray2 = eval(arrayname+".slice("+(i+1)+", "+length+")");
			eval(arrayname + " = newArray1.concat(newArray2)");
			i--;
			length--;
		}
	}
}

function deleteWmsObject() {
	wms = new Array();
	wms_layer_count = 0;
}

function deleteMapObj() {
	mb_mapObj = new Array();
}

function cloneObject(a){
	var z = new Array();
	
	for (attr in a) {
		var b = a[attr];
		if (typeof(b) == "object") {z[attr] = cloneObject(b);}
		else z[attr] = b;
	}	
	return z;
}

function mb_mapObj_const(frameName, elementName, width, height, wms_index){

   this.width = width;
   this.height = height;
   this.frameName = frameName;
   this.elementName = elementName;
   this.layers = new Array();
   this.styles = new Array();
   this.querylayers = new Array();
   this.geom = "";
   this.gml = ""; 
   if(wms_index != null){
      this.wms = new Array();
      this.wms[0] = wms[wms_index];
      this.wms[0].mapURL = false;
      var cnt_layers = 0;
      var cnt_querylayers = 0;
      var styles = "";
      var layers = "";
      var querylayers = "";
      for(var ii=0; ii<this.wms[0].objLayer.length; ii++){
         if(this.wms[0].objLayer[ii].gui_layer_visible == 1 && ii>0){
            if(cnt_layers > 0){layers += ","; styles += ","; }
            layers += this.wms[0].objLayer[ii].layer_name; 
            styles += ""; 
            cnt_layers++;
         }   
         if(this.wms[0].objLayer[ii].gui_layer_querylayer == 1 && ii>0){
            if(cnt_querylayers > 0){querylayers += ",";}
            querylayers += this.wms[0].objLayer[ii].layer_name; 
            cnt_querylayers++;
         }                      
      }
      this.layers[0] = layers;
      this.styles[0] = styles;
      this.querylayers[0] = querylayers;   
   }
   else{
	this.wms = new Array();
	for(i=0; i<wms.length; i++){
		this.wms[i] = wms[i];
		this.wms[i].mapURL = false;
	}
      for(var i=0; i< this.wms.length; i++){
         var cnt_layers = 0;
         var cnt_querylayers = 0;
         var styles = "";
         var layers = "";
         var querylayers = "";
         for(var ii=0; ii<this.wms[i].objLayer.length; ii++){
            if(this.wms[i].objLayer[ii].gui_layer_visible == 1 && ii>0){
               if(cnt_layers > 0){layers += ","; styles += ","; }
               layers += wms[i].objLayer[ii].layer_name; 
               styles += ""; 
               cnt_layers++;
            }            
            if(this.wms[i].objLayer[ii].gui_layer_querylayer == 1 && ii>0){
               if(cnt_querylayers > 0){querylayers += ",";}
               querylayers += wms[i].objLayer[ii].layer_name; 
               cnt_querylayers++;
            }                          
         }
         this.layers[i] = layers;
         this.styles[i] = styles;
         this.querylayers[i] = querylayers;
      }
   }
   this.epsg = wms[0].gui_wms_epsg;
   this.extent = setExtent(this.width,this.height,this.epsg);
   this.mapURL = new Array();
   for(var i=0; i<mb_MapObjectSubFunctions.length; i++){
      eval(mb_MapObjectSubFunctions[i]);
   }   
}

function mb_moveWmsById (mapObj_ind, wms_id, toIndex) {
	return mb_wmsMoveByIndex(mapObj_ind, getWMSIndexById(mapObj_ind, wms_id), toIndex);
}

function mb_wmsMoveByIndex(mapObj_ind, fromIndex, toIndex) {
	if (fromIndex != toIndex && fromIndex >= 0 && fromIndex < mb_mapObj[mapObj_ind].wms.length && toIndex >= 0 && toIndex < mb_mapObj[mapObj_ind].wms.length) {
		var changed = false;

		if (fromIndex > toIndex) {
			for (var i = fromIndex; i > toIndex ; i--) {
				var result = mb_swapWmsByIndex(mapObj_ind, i-1, i);
				if (result == true) changed = true;
			}
		}
		else {
			for (var i = fromIndex; i < toIndex ; i++) {
				var result = mb_swapWmsByIndex(mapObj_ind, i, i+1);
				if (result == true) changed = true;
			}
		}
		return changed;
	}
	else {
		return false;
	}
}

function mb_swapWmsById(mapObj_ind, wms1_id, wms2_id) {
	return mb_swapWmsByIndex(mapObj_ind, getWMSIndexById(mapObj_ind, wms1_id), getWMSIndexById(mapObj_ind, wms2_id));
}

function mb_swapWmsByIndex(mapObj_ind, indexA, indexB) {
	if (indexA != indexB && indexA >= 0 && indexA < mb_mapObj[mapObj_ind].wms.length && indexB >= 0 && indexB < mb_mapObj[mapObj_ind].wms.length) {
		upper = mb_mapObj[mapObj_ind].wms[indexA];
		mb_mapObj[mapObj_ind].wms[indexA] = mb_mapObj[mapObj_ind].wms[indexB];
		mb_mapObj[mapObj_ind].wms[indexB] = upper;
		var upperLayers = mb_mapObj[mapObj_ind].layers[indexA];
		var upperStyles = mb_mapObj[mapObj_ind].styles[indexA];
		var upperQuerylayers = mb_mapObj[mapObj_ind].querylayers[indexA];
		mb_mapObj[mapObj_ind].layers[indexA] = mb_mapObj[mapObj_ind].layers[indexB];
		mb_mapObj[mapObj_ind].styles[indexA] = mb_mapObj[mapObj_ind].styles[indexB];
		mb_mapObj[mapObj_ind].querylayers[indexA] = mb_mapObj[mapObj_ind].querylayers[indexB];
		mb_mapObj[mapObj_ind].layers[indexB] = upperLayers;
		mb_mapObj[mapObj_ind].styles[indexB] = upperStyles;
		mb_mapObj[mapObj_ind].querylayers[indexB] = upperQuerylayers;
		return true;
	}
	else {
		return false;
	}
}

function mb_moveUpWmsByIndex(mapObj_ind, index) {
	if (index > 0 && index < wms.length) {
		return mb_swapWmsByIndex(mapObj_ind, index-1, index);
	}
	else {
		return false;
	}
}

function mb_moveDownWmsByIndex(mapObj_ind, index) {
	if (index >= 0 && index < wms.length-1) {
		return mb_swapWmsByIndex(mapObj_ind, index, index+1);
	}
	else {
		return false;
	}
}

function mb_mapObjaddWMS(obj){
	var cnt_layers = 0;
	var cnt_querylayers = 0;
	var styles = "";
	var layers = "";
	var querylayers = "";
	var ind = getMapObjIndexByName(obj);
	//is the id valid?
	for( var i=0; i<(wms.length-1); i++){
		if(parseInt(wms[i].wms_id) >= parseInt(wms[wms.length-1].wms_id)){
			wms[wms.length-1].wms_id = parseInt(mb_mapObj[ind].wms[i].wms_id) + 1;
		}
	} 
	mb_mapObj[ind].wms[mb_mapObj[ind].wms.length] = wms[wms.length-1];
	mb_mapObj[ind].layers[mb_mapObj[ind].layers.length] = layers;
	mb_mapObj[ind].styles[mb_mapObj[ind].styles.length] = styles;
	mb_mapObj[ind].querylayers[mb_mapObj[ind].querylayers.length] = querylayers;  
	for(var i=0; i<mb_loadWmsSubFunctions.length; i++){
		eval(mb_loadWmsSubFunctions[i]);
	}
	return true; 
}
//CB
function mb_mapObjaddWMSwithLayers(obj,layers,querylayers){
	var cnt_layers = 0;
	var cnt_querylayers = 0;
	var styles = "";
	var ind = getMapObjIndexByName(obj);
	mb_mapObj[ind].wms[mb_mapObj[ind].wms.length] = wms[wms.length-1];
	mb_mapObj[ind].layers[mb_mapObj[ind].layers.length] = layers;
	mb_mapObj[ind].styles[mb_mapObj[ind].styles.length] = styles;
	mb_mapObj[ind].querylayers[mb_mapObj[ind].querylayers.length] = querylayers;   
}
function mb_mapObjremoveWMS(objind,wmsind){
	var wms_ID = null;
	
	var new_wmsarray = new Array();
	var new_layerarray = new Array();
	var new_querylayerarray = new Array();
	var new_stylesarray = new Array();
	var new_mapURLarray = new Array();
	
	for	(var i=0;i<mb_mapObj[objind].wms.length; i++){
		if(i != wmsind){
			new_wmsarray[new_wmsarray.length] = mb_mapObj[objind].wms[i];
			new_layerarray[new_layerarray.length] = mb_mapObj[objind].layers[i];
			new_querylayerarray[new_querylayerarray.length] = mb_mapObj[objind].querylayers[i];
			new_stylesarray[new_stylesarray.length] = mb_mapObj[objind].styles[i];
			new_mapURLarray[new_mapURLarray.length] = mb_mapObj[objind].mapURL[i] 
		}
		else {
			wms_ID = mb_mapObj[objind].wms[i].wms_id;
		}
	}
	mb_mapObj[objind].wms = new_wmsarray; 
	mb_mapObj[objind].layers = new_layerarray; 
	mb_mapObj[objind].querylayers = new_querylayerarray; 
	mb_mapObj[objind].styles = new_stylesarray; 
	mb_mapObj[objind].mapURL = new_mapURLarray;

	var another_new_wmsarray = new Array();
	for	(var i=0;i<wms.length; i++){
		if(wms[i].wms_id != wms_ID){
			another_new_wmsarray[another_new_wmsarray.length] = wms[i]; 
		}
	}
	wms = another_new_wmsarray; 
}
function setExtent(width,height,epsg){
   for(var i=0; i < wms[0].gui_epsg.length; i++){
      if(wms[0].gui_epsg[i] == epsg){      
         var bbox_minx = parseFloat(wms[0].gui_minx[i]);
         var bbox_miny = parseFloat(wms[0].gui_miny[i]);
         var bbox_maxx = parseFloat(wms[0].gui_maxx[i]);
         var bbox_maxy = parseFloat(wms[0].gui_maxy[i]);     
   
         var extenty = bbox_maxy - bbox_miny;
         var extentx = bbox_maxx - bbox_minx;

         var relation_px_x = width / height;
         var relation_px_y = height / width;
         var relation_bbox_x = extentx / extenty;         
         var centerx = bbox_minx + (extentx/2);
         var centery = bbox_miny + (extenty/2);
         if(relation_bbox_x <= relation_px_x){                
                bbox_minx = centerx - relation_px_x * extenty / 2;
                bbox_maxx = centerx + relation_px_x * extenty / 2;
         }
        
         if(relation_bbox_x > relation_px_x){                
                bbox_miny = centery - relation_px_y * extentx / 2;
                bbox_maxy = centery + relation_px_y * extentx / 2;
         }
        return bbox_minx  +","+ bbox_miny +","+ bbox_maxx  +","+ bbox_maxy;
     }
   }
}
function setMapRequest(frameName){

	var ts = mb_timestamp();

	for(var i=0; i<mb_MapRequestPreFunctions.length; i++){
		var ret = eval(mb_MapRequestPreFunctions[i]);
		if(ret == false){
			return true;
		}
	}
	for(var i=0; i<mb_mapObj.length; i++){
		var newMapRequest = "";
		if(mb_mapObj[i].frameName == frameName){
			for(var ii=0; ii<mb_mapObj[i].wms.length; ii++){
				if(mb_mapObj[i].wms[ii].gui_wms_visible > 0){
					var myDivId = "div_" + ii;          
					var myMapId = "map_" + ii;
					//disable Layer which are out of scale
					var str_LayerStyles = mb_checkScale(frameName,i,ii);
					if(mb_mapObj[i].layers[ii] != "" && str_LayerStyles[0] != ''){
						var newMapURL = "";
						newMapRequest += "<div id='"+myDivId+"' style='position:absolute; top:0px; left:0px; z-index:'"+ii+"'>";
						newMapRequest += "<img id='"+myMapId+"' name='mapimage' src='";
						newMapURL += mb_mapObj[i].wms[ii].wms_getmap;   
						
						newMapURL += mb_getConjunctionCharacter(mb_mapObj[i].wms[ii].wms_getmap);
						
						if(mb_mapObj[i].wms[ii].wms_version == "1.0.0"){newMapURL += "WMTVER="+mb_mapObj[i].wms[ii].wms_version+"&REQUEST=map&";}
						if(mb_mapObj[i].wms[ii].wms_version != "1.0.0"){newMapURL += "VERSION="+mb_mapObj[i].wms[ii].wms_version+"&REQUEST=GetMap&SERVICE=WMS&";} 
						
						newMapURL += "LAYERS="+str_LayerStyles[0]+"&";
						newMapURL += "STYLES="+str_LayerStyles[1]+"&";
		
						newMapURL += "SRS="+mb_mapObj[i].epsg+"&";
						newMapURL += "BBOX="+mb_mapObj[i].extent+"&";
						newMapURL += "WIDTH="+mb_mapObj[i].width+"&";
						newMapURL += "HEIGHT="+mb_mapObj[i].height+"&";
						newMapURL += "FORMAT="+mb_mapObj[i].wms[ii].gui_wms_mapformat+"&";
						newMapURL += "BGCOLOR=0xffffff&";
						if(mb_mapObj[i].wms[ii].gui_wms_mapformat.search(/gif/i)>-1 || mb_mapObj[i].wms[ii].gui_wms_mapformat.search(/png/i)>-1){
							newMapURL += "TRANSPARENT=TRUE&";
						}
						newMapURL += "EXCEPTIONS="+mb_mapObj[i].wms[ii].gui_wms_exceptionformat;
						// add vendor-specifics
						for(var v=0; v<mb_vendorSpecific.length; v++){
							newMapURL += "&" + eval(mb_vendorSpecific[v]);
						}           
						// add Filter
						if(mb_mapObj[i].wms[ii].wms_filter != ""){
							var tmp = mb_mapObj[i].wms[ii].wms_filter +"?id="+ mb_styleID;

							var temp = "&SLD=" + tmp+ "&";
							newMapURL += temp;
						}
						if(mb_log){
							var tmp = eval(mb_log + "('" + newMapURL + "','" + ts + "')");
						}
						newMapRequest += newMapURL;
						mb_mapObj[i].mapURL[ii] = newMapURL;	
						mb_mapObj[i].wms[ii].mapURL = newMapURL;
						newMapRequest += "' width='"+mb_mapObj[i].width+"' height='"+mb_mapObj[i].height+"' border='0'></div>";   
					}
					else{
						mb_mapObj[i].mapURL[ii] = false;
						mb_mapObj[i].wms[ii].mapURL = false;
						newMapRequest += "<div id='"+myDivId+"' style='position:absolute; top:0px; left:0px; z-index:'"+ii+"'>";
						newMapRequest += "<img id='"+myMapId+"' name='mapimage' src='" + mb_trans.src;
						newMapRequest += "' width='"+mb_mapObj[i].width+"' height='"+mb_mapObj[i].height+"' border='0'>";
						newMapRequest +="</div>";
					}
				}
				
			}
			
			//prompt("",newMapRequest);
			writeTag(mb_mapObj[i].frameName,mb_mapObj[i].elementName,newMapRequest);
		}
	}
	for(var i=0; i<mb_MapRequestSubFunctions.length; i++){
		eval(mb_MapRequestSubFunctions[i]);
	}
}
function setSingleMapRequest(frameName,wms_id){
	
	var ts = mb_timestamp();	
	
	for(var i=0; i<mb_MapRequestPreFunctions.length; i++){
		eval(mb_MapRequestPreFunctions[i]);
	}
	for(var i=0; i<mb_mapObj.length; i++){
		var newMapRequest = "";
		if(mb_mapObj[i].frameName == frameName){
			for(var ii=0; ii<mb_mapObj[i].wms.length; ii++){ 
				var myDivId = "div_" + ii;
				var myMapId = "map_" + ii;
				if(mb_mapObj[i].wms[ii].wms_id == wms_id){  
					var newMapURL = "";
					newMapRequest += "<img id='"+myMapId+"' name='mapimage' src='";
					newMapURL += mb_mapObj[i].wms[ii].wms_getmap; 

					newMapURL += mb_getConjunctionCharacter(mb_mapObj[i].wms[ii].wms_getmap);
						
					if(mb_mapObj[i].wms[ii].wms_version == "1.0.0"){newMapURL += "WMTVER="+mb_mapObj[i].wms[ii].wms_version+"&REQUEST=map&";}
					if(mb_mapObj[i].wms[ii].wms_version != "1.0.0"){newMapURL += "VERSION="+mb_mapObj[i].wms[ii].wms_version+"&REQUEST=GetMap&SERVICE=WMS&";}             
					
					//disable Layer which are out of scale
					var str_LayerStyles = mb_checkScale(frameName,i,ii); 

					newMapURL += "LAYERS="+str_LayerStyles[0]+"&";
					newMapURL += "STYLES="+str_LayerStyles[1]+"&";
         
					newMapURL += "SRS="+mb_mapObj[i].epsg+"&";
					newMapURL += "BBOX="+mb_mapObj[i].extent+"&";
					newMapURL += "WIDTH="+mb_mapObj[i].width+"&";
					newMapURL += "HEIGHT="+mb_mapObj[i].height+"&";
					newMapURL += "FORMAT="+mb_mapObj[i].wms[ii].gui_wms_mapformat+"&";
					newMapURL += "BGCOLOR=0xffffff&";
					if(mb_mapObj[i].wms[ii].gui_wms_mapformat.search(/gif/i)>-1 || mb_mapObj[i].wms[ii].gui_wms_mapformat.search(/png/i)>-1){
						newMapURL += "TRANSPARENT=TRUE&";
					}
					newMapURL += "EXCEPTIONS="+mb_mapObj[i].wms[ii].gui_wms_exceptionformat;
					// add vendor-specific
					for(var v=0; v<mb_vendorSpecific.length; v++){
						newMapURL += "&" + eval(mb_vendorSpecific[v]);
					}
					// add Filter
					if(mb_mapObj[i].wms[ii].wms_filter != ""){
						var tmp = mb_mapObj[i].wms[ii].wms_filter +"?id="+ mb_styleID;
						//prompt("",tmp);;
						var temp = "&SLD=" + tmp+ "&";
						newMapURL += temp;
					}
					//prompt("",newMapURL);
					if(mb_mapObj[i].layers[ii] != "" && str_LayerStyles[0] != ""){
						newMapRequest += newMapURL;
						mb_mapObj[i].mapURL[ii] = newMapURL;
						mb_mapObj[i].wms[ii].mapURL = newMapURL;
						newMapRequest += "' width='"+mb_mapObj[i].width+"' height='"+mb_mapObj[i].height+"' border='0'>";
					}
					else{
						mb_mapObj[i].mapURL[ii] = false;
						mb_mapObj[i].wms[ii].mapURL = false;
						newMapRequest = "<img id='"+myMapId+"' name='mapimage' src='" + mb_trans.src;
						newMapRequest += "' width='"+mb_mapObj[i].width+"' height='"+mb_mapObj[i].height+"' border='0'>";
					}        
					//prompt("",newMapRequest);
					if(mb_log){
						var tmp = eval(mb_log + "('" + newMapURL + "','" + ts + "')");
					}
					writeTag(mb_mapObj[i].frameName,myDivId,newMapRequest);
				}                            
			}           
		}      
	}   
	for(var i=0; i<mb_MapRequestSubFunctions.length; i++){
		eval(mb_MapRequestSubFunctions[i]);
	}   
}
function mb_restateLayers(frameName,wms_id){
	//alert(frameName + " / " + wms_id);
	var ind = getMapObjIndexByName(frameName);	
	for(var i=0; i<mb_mapObj[ind].wms.length; i++){
		if(mb_mapObj[ind].wms[i].wms_id == wms_id){
			var cnt_layers = 0;
			var cnt_querylayers = 0;
			var layers = "";
			var styles = "";
			var querylayers = "";
			for(var ii=0; ii<mb_mapObj[ind].wms[i].objLayer.length; ii++){
				if(mb_mapObj[ind].wms[i].objLayer[ii].gui_layer_visible == 1 && ii>0){
					if(cnt_layers > 0){layers += ","; styles += ","; }
					layers += mb_mapObj[ind].wms[i].objLayer[ii].layer_name;
					//alert(mb_mapObj[ind].wms[i].objLayer[ii].layer_name); 
					styles += ""; 
					cnt_layers++;
				}            
				if(mb_mapObj[ind].wms[i].objLayer[ii].gui_layer_querylayer == 1 && ii>0){
					if(cnt_querylayers > 0){querylayers += ",";}
					querylayers += mb_mapObj[ind].wms[i].objLayer[ii].layer_name; 
					cnt_querylayers++;
				}
				mb_mapObj[ind].layers[i] = layers;
				mb_mapObj[ind].querylayers[i] = querylayers;
				mb_mapObj[ind].styles[i] = styles;
			}
		}
	}
}

function mb_checkScale(frameName,mObj,wmsObj){
	var thisLayer = mb_mapObj[mObj].layers[wmsObj].split(",");
	var thisScale = mb_getScale(frameName);  
	var str_layer = "";
	var str_styles = "";
	var str_titles = "";
	var str_legendurls = "";
	var str_parent = "";
	var cnt_layer = 0;
	for(var i=0; i<mb_mapObj[mObj].wms[wmsObj].objLayer.length; i++){  
		var myLayername = mb_mapObj[mObj].wms[wmsObj].objLayer[i].layer_name;
		var myMinscale = mb_mapObj[mObj].wms[wmsObj].objLayer[i].gui_layer_minscale;
		var myMaxscale = mb_mapObj[mObj].wms[wmsObj].objLayer[i].gui_layer_maxscale;
		for(var ii=0; ii<thisLayer.length; ii++){
			var minscaleOK = false;
			var maxscaleOK = false;   
			if(thisLayer[ii] == myLayername){
				if(myMinscale == 0 || thisScale >= myMinscale){minscaleOK = true;}
				if(myMaxscale == 0 || thisScale <= myMaxscale){maxscaleOK = true;}
				if(maxscaleOK == true && minscaleOK == true ){
					if(cnt_layer > 0){str_layer += ","; str_styles += ","; str_titles += ",";str_parent += ","; str_legendurls += ",";}
					str_layer += thisLayer[ii];
					str_styles += "";
					str_titles += mb_mapObj[mObj].wms[wmsObj].objLayer[i].layer_title;
					str_parent += mb_mapObj[mObj].wms[wmsObj].objLayer[i].layer_parent;
					if(mb_mapObj[mObj].wms[wmsObj].objLayer[i].layer_style.length>0){
					 	str_legendurls += mb_mapObj[mObj].wms[wmsObj].objLayer[i].layer_style[0]["legendurl"] ;
					}
					cnt_layer++;
				}
			}
		}
	}
	var str_layerstyles = new Array();
	str_layerstyles[0] = str_layer;
	str_layerstyles[1] = str_styles;
	str_layerstyles[2] = str_titles;
	str_layerstyles[3] = str_legendurls;
	str_layerstyles[4] = str_parent;
	return str_layerstyles;
}
function setFeatureInfoRequest(fName,x,y, path) {
	var ts = mb_timestamp();
	for(var i=0; i<mb_FeatureInfoPreFunctions.length; i++){
		eval(mb_FeatureInfoPreFunctions[i]);
	}   
	var cnt_fi = 0;
	for(var i=0; i<mb_mapObj.length; i++){
		if(mb_mapObj[i].frameName == fName){
			for(var ii=0; ii<mb_mapObj[i].wms.length; ii++){
				var newfeatureInfoRequest = "";
				var requestParams = "";
				var validation = false;
				newfeatureInfoRequest += mb_mapObj[i].wms[ii].wms_getfeatureinfo;          
            	newfeatureInfoRequest += mb_getConjunctionCharacter(mb_mapObj[i].wms[ii].wms_getfeatureinfo);
            	
				if(mb_mapObj[i].wms[ii].wms_version == "1.0.0"){requestParams += "WMTVER="+mb_mapObj[i].wms[ii].wms_version+"&REQUEST=feature_info&";}
				if(mb_mapObj[i].wms[ii].wms_version != "1.0.0"){requestParams += "VERSION="+mb_mapObj[i].wms[ii].wms_version+"&REQUEST=GetFeatureInfo&SERVICE=WMS&";}
				requestParams += "SRS="+mb_mapObj[i].epsg+"&";
				requestParams += "BBOX="+mb_mapObj[i].extent+"&";
				requestParams += "WIDTH="+mb_mapObj[i].width+"&";
				requestParams += "HEIGHT="+mb_mapObj[i].height+"&";
				requestParams += "LAYERS="+mb_mapObj[i].layers[ii]+"&";
				requestParams += "STYLES="+mb_mapObj[i].styles[ii]+"&";
				requestParams += "FORMAT="+mb_mapObj[i].wms[ii].gui_wms_mapformat+"&";
				requestParams += "INFO_FORMAT="+mb_mapObj[i].wms[ii].gui_wms_featureinfoformat+"&";
				requestParams += "EXCEPTIONS=application/vnd.ogc.se_xml&";
				if(mb_feature_count > 0){             
					requestParams += "FEATURE_COUNT="+mb_feature_count+"&";
				}
				requestParams += "QUERY_LAYERS="+mb_mapObj[i].querylayers[ii]+"&";
				requestParams += "X=" + x  + "&";
				requestParams += "Y=" + y;
				
				if(mb_mapObj[i].querylayers[ii] != "" && mb_mapObj[i].layers[ii] != ""){
					validation = true;
				}
				//add vendor-specific
				for(var v=0; v<mb_vendorSpecific.length; v++){
		            requestParams += "&" + eval(mb_vendorSpecific[v]);
				}
				if(mb_log && validation){
					var tmp = eval(mb_log + "('" + newfeatureInfoRequest + requestParams + "','" + ts + "')");
				}
				if(document.getElementById("FeatureInfoRedirect") && validation){
					newfeatureInfoRequest += requestParams;
					if(path){
						window.frames["FeatureInfoRedirect"].document.getElementById(mb_mapObj[i].wms[ii].wms_id).src = path + "?url=" + escape(newfeatureInfoRequest)+"&"+mb_nr;
					}
					else{
						window.frames["FeatureInfoRedirect"].document.getElementById(mb_mapObj[i].wms[ii].wms_id).src = newfeatureInfoRequest;
					}
					cnt_fi++;
            	}
				else if(path && validation){
					newfeatureInfoRequest += requestParams
					window.open(path + "?url=" + escape(newfeatureInfoRequest)+"&"+mb_nr, "" , "width=300,height=400,scrollbars=yes,resizable=yes");
					cnt_fi++;
				}
				else if(validation){
					newfeatureInfoRequest += requestParams;
					window.open(newfeatureInfoRequest, "" , "width=300,height=400,scrollbars=yes,resizable=yes");
					cnt_fi++;          
				}      
			}
		}
	}
   	if(cnt_fi == 0){alert(unescape("Please select a layer! \n Bitte waehlen Sie eine Ebene zur Abfrage aus!"));}
}
function writeTag(frameName, elName, tagSource) {
  if(frameName && frameName != ""){
     window.frames[frameName].document.getElementById(elName).innerHTML = tagSource;
  }
  else if(!frameName || frameName == ""){
       document.getElementById(elName).innerHTML = tagSource;
  }
}
function zoom(frameName,in_, factor,x,y) {
  var x = parseFloat(x);
  var y = parseFloat(y);
  var ind = getMapObjIndexByName(frameName);
  var arrayBBox = mb_mapObj[ind].extent.split(",");
  var xtentx = parseFloat(arrayBBox[2]) - parseFloat(arrayBBox[0]);
  var xtenty =  parseFloat(arrayBBox[3]) - parseFloat(arrayBBox[1]);
  var centerx = parseFloat(arrayBBox[0]) + xtentx/2;
  var centery = parseFloat(arrayBBox[1]) + xtenty/2;
  var factor = parseFloat(factor);
  if(x){
   centerx = x;
   centery = y;
  }
  if (!in_) {factor = 1 / factor;}
  var new_xtentx = xtentx / factor;
  var new_xtenty = xtenty / factor;
  var minx = centerx - new_xtentx / 2;
  var miny = centery - new_xtenty / 2;
  var maxx = centerx + new_xtentx / 2;
  var maxy = centery + new_xtenty / 2;
  mb_mapObj[ind].extent = minx + "," + miny + "," + maxx + "," + maxy;
  setMapRequest(frameName);
}
function mb_panMap(frameName,dir){
   var ind = getMapObjIndexByName(frameName);
   var arrayBBox = mb_mapObj[ind].extent.split(",");
   var minx = parseFloat(arrayBBox[0]);
   var miny = parseFloat(arrayBBox[1]);
   var maxx = parseFloat(arrayBBox[2]);
   var maxy = parseFloat(arrayBBox[3]);
   var xtentx = parseFloat(arrayBBox[2]) - parseFloat(arrayBBox[0]);
   var xtenty =  parseFloat(arrayBBox[3]) - parseFloat(arrayBBox[1]);

   if(dir == "NW"){minx = minx - (xtentx/2); maxx = maxx - (xtentx/2); miny = miny + (xtenty/2); maxy = maxy + (xtenty/2);}
   if(dir == "N"){miny = miny + (xtenty/2); maxy = maxy + (xtenty/2);}
   if(dir == "NE"){minx = minx + (xtentx/2); maxx = maxx + (xtentx/2); miny = miny + (xtenty/2); maxy = maxy + (xtenty/2);}
   if(dir == "W"){minx = minx - (xtentx/2); maxx = maxx - (xtentx/2);}
   if(dir == "E"){minx = minx + (xtentx/2); maxx = maxx + (xtentx/2);}
   if(dir == "SW"){minx = minx - (xtentx/2); maxx = maxx - (xtentx/2); miny = miny - (xtenty/2); maxy = maxy - (xtenty/2);}
   if(dir == "S"){miny = miny - (xtenty/2); maxy = maxy - (xtenty/2);}
   if(dir == "SE"){minx = minx + (xtentx/2); maxx = maxx + (xtentx/2); miny = miny - (xtenty/2); maxy = maxy - (xtenty/2);}
  mb_mapObj[ind].extent = minx + "," + miny + "," + maxx + "," + maxy;
  setMapRequest(frameName);
}

function handleSelectedLayer(frameName,wms_title,layerName,type,status){
    //	alert(frameName + " , " +wms_title + " , " +layerName + " , TYP:" +type + " , " +status);
   //type = {visible || querylayer] status = {0 || 1}
   for(var i=0; i<mb_mapObj.length; i++){
      if(mb_mapObj[i].frameName == frameName){
         var cnt_layer = 0;
         var str_layer = "";
         var myMapObj = i;
         for(var ii=0; ii<mb_mapObj[i].wms.length; ii++){
             if(mb_mapObj[i].wms[ii].wms_title == wms_title){ //ii is true
                var myWMS = ii; 
                if(type == "visible"){var arrayLayer = mb_mapObj[i].layers[ii].split(",");}
                if(type == "querylayer"){var arrayLayer = mb_mapObj[i].querylayers[ii].split(",");}
                for(var iii=1; iii<mb_mapObj[i].wms[ii].objLayer.length; iii++){
                   var layer_name = mb_mapObj[i].wms[ii].objLayer[iii].layer_name;
                   if(type == "querylayer"){
	              	if(layer_name == layerName && status == 1 && mb_mapObj[i].wms[ii].objLayer[iii].layer_queryable == 1){
                         if(cnt_layer > 0){str_layer += ",";}
                         str_layer += layer_name;
                         cnt_layer++;                   
                   	}
                   }
                   else if(type == "visible"){
                   	if(layer_name == layerName && status == 1){
                         if(cnt_layer > 0){str_layer += ",";}
                         str_layer += layer_name;
                         cnt_layer++;                   
                   	}
                   }
                   for(var iiii=0; iiii<arrayLayer.length; iiii++){
                      if(layer_name == arrayLayer[iiii] && layer_name != layerName){
                         if(cnt_layer > 0){str_layer += ",";}
                         str_layer += layer_name;
                         cnt_layer++;             
                      }
                   }
                }
             }   
         }         
      }
   }
   if(type == "visible"){
      mb_mapObj[myMapObj].layers[myWMS] = str_layer;
      var array_str_layer = str_layer.split(",");
      var str_styles = "";
      for(var cnt=0; cnt<array_str_layer.length; cnt++){
         if(cnt > 0){str_styles += ",";}
         str_styles += "";
      }
      mb_mapObj[myMapObj].styles[myWMS] = str_styles;
   }
   if(type == "querylayer"){mb_mapObj[myMapObj].querylayers[myWMS] = str_layer;}
   /*
   if(type == 'visible'){
      setSingleMapRequest(frameName,wms_title);
   }
   */
}
function handleSelectedLayer_array(mapObj, array_wms, array_layer, type, status){
	//alert(mapObj+" / "+array_wms[0]+" / "+ array_layer[0]+" / "+ type+" / "+ status);
	var ind = getMapObjIndexByName(mapObj);
	for(var j=0; j<array_wms.length; j++){
		for(var i=0; i<mb_mapObj[ind].wms.length; i++){
			if(mb_mapObj[ind].wms[i].wms_id == array_wms[j]){
				var check = false;
				for(var ii=0; ii<mb_mapObj[ind].wms[i].objLayer.length; ii++){
					if(mb_mapObj[ind].wms[i].wms_id == array_wms[j] && mb_mapObj[ind].wms[i].objLayer[ii].layer_name == array_layer[j]){
						if(type == "visible"){
							mb_mapObj[ind].wms[i].objLayer[ii].gui_layer_visible = parseInt(status);
							//alert(mb_mapObj[ind].wms[i].objLayer[ii].layer_name);
							check = true;
						}
                        if(type == "querylayer" && (mb_mapObj[ind].wms[i].objLayer[ii].gui_layer_queryable == "1" || mb_mapObj[ind].wms[i].objLayer[ii].gui_layer_queryable == 1)){
							mb_mapObj[ind].wms[i].objLayer[ii].gui_layer_querylayer = parseInt(status);
						}
					}
				}
                mb_restateLayers(mapObj, array_wms[j]);
                //alert('restate');
                /*
                * hier noch checken, welche wms sich geaendert haben und disctinct eine singleRequest aufrufen:
                */ 
                if(check == true){					
                    
                    if(mb_mapObj[ind].wms[i].gui_wms_visible == 1){
						setSingleMapRequest(mapObj,mb_mapObj[ind].wms[i].wms_id);
                        //alert('sSMR');
					}
				}
			}
		}
	}
}

function makeClickPos2RealWorldPos(frameName, myClickX, myClickY) {
	var ind = getMapObjIndexByName(frameName);
	var width = parseInt(mb_mapObj[ind].width);
	var height = parseInt(mb_mapObj[ind].height);
	var arrayBBox = mb_mapObj[ind].extent.split(",");
	var minX = parseFloat(arrayBBox[0]);
	var minY = parseFloat(arrayBBox[1]);
	var maxX = parseFloat(arrayBBox[2]);
	var maxY = parseFloat(arrayBBox[3]);
	var deltaX = (maxX - minX)/width;
	var deltaY = (maxY - minY)/height;
	if(deltaX > 0){
		var roundx = 1/Math.pow(10,(Math.round(Math.log(deltaX)/Math.log(10))));
	}
	else{
		var roundx =  Math.pow(10,(Math.round(Math.log(deltaX)/Math.log(10))));
	}
	if(deltaY > 0){
		var roundy = 1/Math.pow(10,(Math.round(Math.log(deltaY)/Math.log(10))));
	}
	else{
		var roundy =  Math.pow(10,(Math.round(Math.log(deltaY)/Math.log(10))));
	}	
	var xtentx = maxX - minX;
	var xtenty =  maxY - minY;
	var posX = parseFloat(minX + (myClickX / width) * xtentx);
	var posY = parseFloat(maxY - (myClickY / height) * xtenty);
	posX = Math.round(posX * roundx)/roundx;
	posY = Math.round(posY * roundy)/roundy;
	return new Array(posX, posY);
}
function makeRealWorld2mapPos(frameName,rw_posx, rw_posy){
   var ind = getMapObjIndexByName(frameName);
   var arrayBBox = mb_mapObj[ind].extent.split(",");
   var minX = parseFloat(arrayBBox[0]);
   var minY = parseFloat(arrayBBox[1]);
   var maxX = parseFloat(arrayBBox[2]);
   var maxY = parseFloat(arrayBBox[3]);
   var xtentx = parseFloat(arrayBBox[2]) - parseFloat(arrayBBox[0]);
   var xtenty =  parseFloat(arrayBBox[3]) - parseFloat(arrayBBox[1]);
   var width = mb_mapObj[ind].width;
   var height = mb_mapObj[ind].height;
   pixPos_x = Math.round(parseFloat(((rw_posx - minX)/xtentx)*width));
   pixPos_y = Math.round(parseFloat(((maxY - rw_posy)/xtenty)*height));
   return new Array(pixPos_x, pixPos_y);
}

function mb_arrangeElement(frameName, elName, left, top) {
   if(frameName != ""){
      window.frames[frameName].document.getElementById(elName).style.top = top;
      window.frames[frameName].document.getElementById(elName).style.left = left;
   }
   else{
      document.getElementById(elName).style.top = top;
      document.getElementById(elName).style.left = left;   
   }
}
/****************BUTTON HANDLING*************************/
var mb_button = new Array();

function mb_regButton_frame(wii, frameName, param){
	var ind = mb_button.length;
	mb_button[ind] = new mb_conButton(wii, ind);
	if (frameName == null) {
		if (param == null) {
			eval(wii+"("+ind+")");
		}
		else {
			eval(wii+"("+ind+", "+param+")");
		}
	}
	else if (param == null) {
		eval("window.frames['" + frameName + "']."+wii+"("+ind+")");
	}
	else {
		eval("window.frames['" + frameName + "']."+wii+"("+ind+", "+param+")");
	}
	mb_button[ind].prev = mb_button[ind].src;
	mb_button[ind].src = mb_button[ind].img_over;
	mb_button[ind].onmouseover = new Function("mb_button_over("+ind+")");
	mb_button[ind].onmouseout = new Function("mb_button_out("+ind+")");
	mb_button[ind].onclick = new Function("mb_button_click("+ind+")");
	if (frameName==null) {
		mb_button[ind].frameName = "";
	}
	else {
		mb_button[ind].frameName = frameName;
	}
}

function mb_regButton(wii){
	mb_regButton_frame(wii, null, null);
}

function mb_conButton(wii, ind){
   this.wii = wii;
   return true;
}
function mb_button_over(ind){
   if(mb_button[ind].status == 0){
      mb_button[ind].prev = mb_button[ind].src;
      mb_button[ind].src = mb_button[ind].img_over;
   }
}
function mb_button_out(ind){
   mb_button[ind].src = mb_button[ind].prev;
}
function mb_button_click(ind){
   var mbStatus = mb_button[ind].status;
   if(mbStatus == 0){
      mb_disableButton(mb_button[ind].elName);
      mb_button[ind].prev = mb_button[ind].img_on;
      mb_button[ind].src = mb_button[ind].img_on;
      mb_button[ind].status = 1;
      if (mb_button[ind].frameName != "") {
          window.frames[mb_button[ind].frameName].document.getElementById(mb_button[ind].elName).go();
      }
      else {
	      document.getElementById(mb_button[ind].elName).go();
      }
   }
   else{
      mb_button[ind].prev = mb_button[ind].img_off;
      mb_button[ind].src = mb_button[ind].img_off;
      mb_button[ind].status = 0;      
      if (mb_button[ind].frameName != "") {
          window.frames[mb_button[ind].frameName].document.getElementById(mb_button[ind].elName).stop();
      }
      else {
	      document.getElementById(mb_button[ind].elName).stop();
      }
   }
}
function mb_disableButton(elName){
   for(var i=0; i<mb_button.length; i++){
      if(mb_button[i].elName != elName && mb_button[i].status == 1){
            mb_button[i].status = 0;
		      if (mb_button[i].frameName != "") {
    	        window.frames[mb_button[i].frameName].document.getElementById(mb_button[i].elName).src = mb_button[i].img_off;
	            window.frames[mb_button[i].frameName].document.getElementById(mb_button[i].elName).stop();
		      }
		      else {
    	        document.getElementById(mb_button[i].elName).src = mb_button[i].img_off;
	            document.getElementById(mb_button[i].elName).stop();
		      }
            return true;
       
      }
   }
}
function mb_disableThisButton(elName){
   for(var i=0; i<mb_button.length; i++){
      if(mb_button[i].elName == elName && mb_button[i].status == 1){
      		//alert(mb_button[i].elName);
            mb_button[i].status = 0;
		      if (mb_button[i].frameName != "") {
    	        window.frames[mb_button[i].frameName].document.getElementById(mb_button[i].elName).src = mb_button[i].img_off;
	            window.frames[mb_button[i].frameName].document.getElementById(mb_button[i].elName).stop();
		      }
		      else {
        	    document.getElementById(mb_button[i].elName).src = mb_button[i].img_off;
		        document.getElementById(mb_button[i].elName).stop();
		      }
            return true;
       
      }
   }
}
/***********************Drag & Drop***********************/
function mb_getMousePos(e,fName){
if(fName){
     if(ie){
        clickX = window.frames[fName].event.clientX;
        clickY = window.frames[fName].event.clientY;
     }
     else{
        clickX = e.pageX;
        clickY = e.pageY;
     }
  }
  else{
       if(ie){
        clickX = event.clientX;
        clickY = event.clientY;
     }
     else{
        clickX = e.pageX;
        clickY = e.pageY;
     }
  }
  var pos = new Array(clickX,clickY);
  return pos;
}
// function for object-identification 
function getMapObjIndexByName(frameName){
	for(var i=0; i<mb_mapObj.length; i++){
		if(mb_mapObj[i].frameName == frameName){
			return i;
		}
	}   
}
function mb_getLayerTitleByName(map_index, wms_index, myLayer_name){
	for(var i=0; i<mb_mapObj[map_index].wms[wms_index].objLayer.length; i++){
		if(mb_mapObj[map_index].wms[wms_index].objLayer[i].layer_name == myLayer_name){
			return mb_mapObj[map_index].wms[wms_index].objLayer[i].layer_title;
		}
	}
}
function getWMSIDByTitle(frameName,wms_title){
   var ind = getMapObjIndexByName(frameName);
   for(var i=0; i< mb_mapObj[ind].wms.length; i++){
      if(mb_mapObj[ind].wms[i].wms_title == wms_title){
         //return i;
         return mb_mapObj[ind].wms[i].wms_id;
      }
   }
}
function getWMSIndexByTitle(frameName,wms_title){
   var ind = getMapObjIndexByName(frameName);
   for(var i=0; i< mb_mapObj[ind].wms.length; i++){
      if(mb_mapObj[ind].wms[i].wms_title == wms_title){
         return i;
      }
   }
}
function getWMSIndexById(frameName,wms_id){
   var ind = getMapObjIndexByName(frameName);
   for(var i=0; i< mb_mapObj[ind].wms.length; i++){
      if(mb_mapObj[ind].wms[i].wms_id == wms_id){
         return i;
      }
   }
}
//scale
function mb_getScale(frameName) {
   for(var i=0; i<mb_GetScalePreFunctions.length; i++){
		var myScale = eval(mb_GetScalePreFunctions[i]);
	}
   if(myScale){
      var Y_str = myScale;
   }
   else{
      var ind = getMapObjIndexByName(frameName);
      var arrayBBox = mb_mapObj[ind].extent.split(",");
      var xtenty =  parseFloat(arrayBBox[3]) - parseFloat(arrayBBox[1]);
      var scaleY = (xtenty / mb_mapObj[ind].height) *(mb_resolution * 100);
      if (scaleY<1){
      	var Y_str = scaleY;
      }else{
      	var Y_str = Math.round(scaleY);
      }
   }   
   return Y_str;   
}

function mb_repaintScale(frameName, x, y, scale){
   var ind = getMapObjIndexByName(frameName);
   if(x == null && y == null){
      var arrayBBox = mb_mapObj[ind].extent.split(",");
      x = parseFloat(arrayBBox[0]) + ((parseFloat(arrayBBox[2]) - parseFloat(arrayBBox[0]))/2);
      y = parseFloat(arrayBBox[1]) + ((parseFloat(arrayBBox[3]) - parseFloat(arrayBBox[1]))/2);
   }
   var minx = parseFloat(x) - (mb_mapObj[ind].width / (mb_resolution * 100 *2) * scale);
   var miny = parseFloat(y) -  (mb_mapObj[ind].height / (mb_resolution * 100 *2) * scale);
   var maxx = parseFloat(x) + (mb_mapObj[ind].width / (mb_resolution * 100 *2) * scale);
   var maxy = parseFloat(y) +  (mb_mapObj[ind].height / (mb_resolution * 100 *2) * scale);
   mb_repaint(frameName,minx, miny, maxx, maxy);
}
function mb_repaint(frameName,minx,miny,maxx,maxy){
   var ind = getMapObjIndexByName(frameName);
   mb_mapObj[ind].extent = minx + "," + miny + "," + maxx + "," + maxy;
   setMapRequest(frameName);
}
function mb_calculateExtent(frameName,minx,miny,maxx,maxy){
  var ind = getMapObjIndexByName(frameName);
  
  var extenty = parseFloat(maxy) - parseFloat(miny);
  var extentx = parseFloat(maxx) - parseFloat(minx);

  var relation_px_x = mb_mapObj[ind].width / mb_mapObj[ind].height;
  var relation_px_y = mb_mapObj[ind].height / mb_mapObj[ind].width;
  var relation_bbox_x = extentx / extenty;     
  var centerx = parseFloat(minx) + (extentx/2);
  var centery = parseFloat(miny) + (extenty/2);
  if(relation_bbox_x <= relation_px_x){                
    minx = centerx - relation_px_x * extenty / 2;
    maxx = centerx + relation_px_x * extenty / 2;
  }
  if(relation_bbox_x > relation_px_x){                
    miny = centery - relation_px_y * extentx / 2;
    maxy = centery + relation_px_y * extentx / 2;
  }
  mb_mapObj[ind].extent = minx  +","+ miny +","+ maxx  +","+ maxy;
}

function mb_showHighlight(frameName,x,y){
   var pos = makeRealWorld2mapPos(frameName,x, y);
   mb_arrangeElement(frameName,"highlight",pos[0]-7, pos[1]-7);
   window.frames[frameName].document.getElementById("highlight").style.visibility = 'visible';
}
function mb_hideHighlight(frameName){
   mb_arrangeElement(frameName,"highlight",-20, -20);
   mb_arrangeElement(frameName,"highlight",-20, -20);
   window.frames[frameName].document.getElementById("highlight").style.visibility = 'hidden';
}
function mb_permanentHighlight(frameName,x,y){   
   var pos = makeRealWorld2mapPos(frameName,x, y);
   mb_arrangeElement(frameName,"permanent",pos[0]-7, pos[1]-7);
   window.frames[frameName].document.getElementById("permanent").style.visibility = 'visible';
}
// framename, commaseparated coordinates, commaseparated rgb values (color)
//new: coords is array!
function mb_markResult(frameName,geom,col){
	var x = "";
	var y = "";
	var tmp = new Array();
	var ind = getMapObjIndexByName(frameName);
	for(var i=0; i<geom.length; i++){
		if(i>0){
			x += ":";
			y += ":";
		}
		tmp = geom[i].split(",");
		for(var ii=0; ii<tmp.length; ii+=2){			
			var pos = makeRealWorld2mapPos(frameName,tmp[ii], tmp[ii+1]);
			if(ii>0){
				x += ",";
				y += ",";
			}
			x += pos[0];
			y += pos[1];
		}      
	}
	var source = "<img src='../extensions/markResult.php?x=" + x + "&y=" + y + "&width=" + mb_mapObj[ind].width + "&height=" + mb_mapObj[ind].height + "&color="+col+"'>";
	//prompt("",source);
	writeTag(frameName,"markResult",source);   
}
function mb_disableResult(frameName){
   writeTag(frameName,"markResult","");
}
function Numsort(a,b){
	return a-b;
}
function mb_registerGML(frameName,obj){
	var ind = getMapObjIndexByName(frameName);
	mb_mapObj[ind].geom = obj;
}
function mb_timestamp(){
	var d = new Date();
	var ts = Math.round(Date.parse(d)/1000);
	return ts;
}
function mb_getlayerposbyname(objInd,wmsInd,lname){
	var t = mb_mapObj[objInd].wms[wmsInd];
	for(var i=0; i < t.objLayer.length; i++){
		if(t.objLayer[i].layer_name == lname){
			return t.objLayer[i].layer_pos;
		}
	}
}
function mb_getLayerObjByName(fname,wms_id,layer_name){
	var ind = getMapObjIndexByName(fname);
	var wmsInd = getWMSIndexById(fname,wms_id);
	var t = mb_mapObj[ind].wms[wmsInd];
	for(var i=0; i < t.objLayer.length; i++){
		if(t.objLayer[i].layer_name == layer_name){
			return t.objLayer[i];
		}
	}
}
function mb_getchildsbyname(objInd,wmsInd,lname){
	var t = mb_mapObj[objInd].wms[wmsInd];
	var pos = mb_getlayerposbyname(objInd, wmsInd,lname);
	var l = new Array();
	l["name"] = new Array();
	l["title"] = new Array();
	l["legendurl"] = new Array();
	for(var i=0; i < t.objLayer.length; i++){
		if(t.objLayer[i].layer_parent == pos){
			l["name"][l["name"].length] = t.objLayer[i].layer_name;
			l["title"][l["title"].length] = t.objLayer[i].layer_title;
			if(t.objLayer[i].layer_style.length>0){
				l["legendurl"][l["legendurl"].length] = t.objLayer[i].layer_style[0]["legendurl"] ;
			}else{
				l["legendurl"][l["legendurl"].length] = 0 ;
			}
		}
	}
	if(l["name"].length > 0){
		return l;
	}
	else{
		return false;
	}
}


// ----------------------------------------------------------------------------------------------------
// DivTag
// ----------------------------------------------------------------------------------------------------

function DivTag (aTagName, aFrameName, aStyle) {
	this.exists = function () { 
		return (rootNode.getElementById(tagName)) ? true : false;
	};
	
	var determineRootNode = function () {
		node = document;
		if (frameName !== "") {
			if (checkFrame()) {node = window.frames[frameName].document;}
			else {alert("frame "+frameName+" doesn't exist.");}
		}
		return node;	
	};
	
	var toCamelCase = function(aString) {
		var newString = "";
		for (var i = 0; i < aString.length; i++) {
			if (aString.substr(i,1) != "-") {
				newString += aString.substr(i,1); 
			}
			else {
				i++;
				newString += aString.substr(i,1).toUpperCase();
			}
		}
		return newString;
	}
	
	var setStyle = function () {
		if (that.exists()) {
			var node = rootNode.getElementById(tagName);
			node.setAttribute("style", "");
			
			for (var attr in tagStyle) {
				if (typeof(tagStyle[attr] != "function") && typeof(tagStyle[attr] != "object")) {
					var evalString = "node.style."+toCamelCase(attr)+" = \"" + tagStyle[attr] + "\";"; 
					eval(evalString);				
				}
			}
		}
	}
	
	var create = function () {
		if (!that.exists()) {
			var divTag = rootNode.createElement("div");
			var divTagAppended = rootNode.getElementsByTagName("body")[0].appendChild(divTag);
			divTagAppended.id = tagName;
		}
		else {
			that.clean();
		}
		setStyle();
	};
	var checkFrame = function () {
		if (frameName !== "") {
			return (typeof(window.frames[frameName]) != 'undefined');
		}
		return true;
	};
	
	this.getTag = function() {
		return rootNode.getElementById(tagName);
	};
	
	var that = this;
	var tagName = aTagName;
	var frameName = aFrameName;
	var rootNode = determineRootNode();
	var tagStyle = aStyle;

	create();
}

DivTag.prototype.write = function (someText) {
	if (this.exists()) {
		this.getTag().innerHTML = someText;
	}
};
DivTag.prototype.clean = function () {
	this.write("");
};




function mb_checkTag(frameName, tagName, elementId, appendAtTagName, attributes){
	var oldElement;
	var newElement;
	var prefix;
	if(frameName && frameName != ""){
		prefix = window.frames[frameName].document;
	}
	else if(!frameName || frameName == ""){
		prefix = document;
	}
	oldElement = prefix.getElementById(elementId);
	if (oldElement == null) {
		newElement = prefix.createElement(tagName);
		newElement = prefix.getElementsByTagName(appendAtTagName)[0].appendChild(newElement);
	}
	else {
		if (oldElement.nodeName.toLowerCase() == tagName.toLowerCase()) {
			for (var i=0; i<attributes.length; i++) {
				oldElement.setAttribute(attributes[i][0], attributes[i][1]);
			}
			return oldElement;
		}
		else {
			return false;
		}
	}
	var newElementAttributeNode = document.createAttribute("id");
	newElementAttributeNode.value = elementId;
	newElement.setAttributeNode(newElementAttributeNode);
	for (var i=0; i<attributes.length; i++) {
		newElement.setAttribute(attributes[i][0], attributes[i][1]);
	}
	return newElement;
}
function mb_execloadWmsSubFunctions(){
	for(var i=0; i<mb_loadWmsSubFunctions.length; i++){
		eval(mb_loadWmsSubFunctions[i]);
	}	
}

function mb_execWfsReadSubFunctions(geom) { 	 
	for(var i=0; i<mb_WfsReadSubFunctions.length; i++){ 	 
		mb_WfsReadSubFunctions[i](geom); 	 
	} 	 
}

function mb_execWfsWriteSubFunctions() { 	 
	for(var i=0; i<mb_WfsWriteSubFunctions.length; i++){
		mb_WfsWriteSubFunctions[i](); 	 
	} 	 
}

function mb_getConjunctionCharacter(onlineresource){
	if(onlineresource.indexOf("?") > -1){ 
		if(onlineresource.charAt(onlineresource.length-1) == "?"){ 
			nextvalue = "";
		}else if(onlineresource.charAt(onlineresource.length-1) == "&"){
			nextvalue = "";
		}else{
			nextvalue = "&";
		}
	}
	if(onlineresource.indexOf("?") == -1){
		nextvalue = "?";
	} 
	return nextvalue;  
}
var mod_toggleModule ='init_featureInfo1';mb_registerInitFunctions('mod_toggleModule_init()');
function mod_toggleModule_init(){
	mb_regButton(mod_toggleModule);
	mb_button_click(0);	
}var mod_zoomOut_img = new Image(); mod_zoomOut_img.src = "../img/button_gray/zoomOut2_off.png";
var mod_zoomOut_img_over = new Image(); mod_zoomOut_img_over.src = "../img/button_gray/zoomOut2_over.png";


function mod_zoomOut1(){
   zoom("mapframe1", false,2.0);
}
function mod_zoomOut1_init(obj){
   document.getElementById("zoomOut1").src = mod_zoomOut_img_over.src;
   obj.onmouseover = new Function("mod_zoomOut1_over()");
   obj.onmouseout = new Function("mod_zoomOut1_out()");
}
function mod_zoomOut1_over(){
   document.getElementById("zoomOut1").src = mod_zoomOut_img_over.src;
}
function mod_zoomOut1_out(){
   document.getElementById("zoomOut1").src = mod_zoomOut_img.src;
}

var mod_scaleText_target = 'mapframe1';function mod_scaleText(){
	mod_scaleText_val(mod_scaleText_target);
	return false;
}
function mod_scaleText_val(frameName){
	var scale = document.getElementById("scaleText").elements[0];
	if(scale.value.search(/\D/) != -1 || scale.value == ""){
		scale.value = "";
		return;
	}   
	var ind = getMapObjIndexByName(frameName);
	var arrayBBox = mb_mapObj[ind].extent.split(",");
	var x = parseFloat(arrayBBox[0]) + ((parseFloat(arrayBBox[2]) - parseFloat(arrayBBox[0]))/2);
	var y = parseFloat(arrayBBox[1]) + ((parseFloat(arrayBBox[3]) - parseFloat(arrayBBox[1]))/2);

	var minx = parseFloat(x) - (mb_mapObj[ind].width / (mb_resolution * 100 *2) * scale.value);
	var miny = parseFloat(y) -  (mb_mapObj[ind].height / (mb_resolution * 100 *2) * scale.value);
	var maxx = parseFloat(x) + (mb_mapObj[ind].width / (mb_resolution * 100 *2) * scale.value);
	var maxy = parseFloat(y) +  (mb_mapObj[ind].height / (mb_resolution * 100 *2) * scale.value);     
	mb_mapObj[ind].extent = minx + "," + miny + "," + maxx + "," + maxy;
	setMapRequest(frameName);
	scale.value = "";
}
var mod_selArea_elName = "selArea1";
var mod_selArea_frameName = "";
var mod_selArea_target = "mapframe1";

var mod_selArea_img_on = new Image(); mod_selArea_img_on.src = "../img/button_gray/selArea_on.png";
var mod_selArea_img_off = new Image(); mod_selArea_img_off.src = "../img/button_gray/selArea_off.png";
var mod_selArea_img_over = new Image(); mod_selArea_img_over.src = "../img/button_gray/selArea_over.png";

function init_selArea1(ind){
	mb_button[ind] = document.getElementById(mod_selArea_elName);
	mb_button[ind].img_over = mod_selArea_img_over.src;
	mb_button[ind].img_on = mod_selArea_img_on.src;
	mb_button[ind].img_off = mod_selArea_img_off.src;
	mb_button[ind].status = 0;
	mb_button[ind].elName = mod_selArea_elName;
	mb_button[ind].fName = mod_selArea_frameName;
	mb_button[ind].go = new Function ("mod_selArea_click()");
	mb_button[ind].stop = new Function ("mod_selArea_disable()");
}
function mod_selArea_click(){
	var el = window.frames[mod_selArea_target].document;
	el.onmouseover = mod_selArea_init;
	el.onmousedown = mod_box_start;
	el.onmouseup = mod_selArea_get;
	el.onmousemove = mod_box_run;
}
function mod_selArea_disable(){
	var el = window.frames[mod_selArea_target].document; 
	el.onmousedown = null;
	el.onmouseup = null;
	el.onmousemove = null;
}
function mod_selArea_init(e){
	mb_isBF = mod_selArea_target;
	mb_zF = mod_selArea_target;
}
function mod_selArea_get(e){
	mod_selArea_setValidClipping(mod_box_stop(e));
	mb_isBF = mod_selArea_target;
	mb_zF = mod_selArea_target;
}
function mod_selArea_setValidClipping(coords){
	if(coords.length > 2){
		mb_calculateExtent(mb_zF,coords[0],coords[1],coords[2],coords[3]);
		setMapRequest(mb_zF);
	}
	else{
		zoom(mb_zF,true,1.0,coords[0], coords[1]);
	}
}
//  ++ //

/* This notice must be untouched at all times.

wz_jsgraphics.js    v. 2.3
The latest version is available at
http://www.walterzorn.com
or http://www.devira.com
or http://www.walterzorn.de

Copyright (c) 2002-2004 Walter Zorn. All rights reserved.
Created 3. 11. 2002 by Walter Zorn (Web: http://www.walterzorn.com )
Last modified: 29. 9. 2004

Performance optimizations for Internet Explorer
by Thomas Frank and John Holdsworth.
fillPolygon method implemented by Matthieu Haller.

High Performance JavaScript Graphics Library.
Provides methods
- to draw lines, rectangles, ellipses, polygons
  with specifiable line thickness,
- to fill rectangles and ellipses
- to draw text.
NOTE: Operations, functions and branching have rather been optimized
to efficiency and speed than to shortness of source code.

LICENSE: LGPL

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License (LGPL) as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA,
or see http://www.gnu.org/copyleft/lesser.html
*/



var jg_ihtm, jg_ie, jg_fast, jg_dom, jg_moz,
jg_n4 = (document.layers && typeof document.classes != "undefined");

function chkDHTM(x, i)
{
        x = document.body || null;
        jg_ie = x && typeof x.insertAdjacentHTML != "undefined";
        jg_dom = (x && !jg_ie &&
                typeof x.appendChild != "undefined" &&
                typeof document.createRange != "undefined" &&
                typeof (i = document.createRange()).setStartBefore != "undefined" &&
                typeof i.createContextualFragment != "undefined");
        jg_ihtm = !jg_ie && !jg_dom && x && typeof x.innerHTML != "undefined";
        jg_fast = jg_ie && document.all && !window.opera;
        jg_moz = jg_dom && typeof x.style.MozOpacity != "undefined";
}


function pntDoc()
{
        this.wnd.document.write(jg_fast? this.htmRpc() : this.htm);
        this.htm = '';
}


function pntCnvDom()
{
        var x = document.createRange();
        x.setStartBefore(this.cnv);
        x = x.createContextualFragment(jg_fast? this.htmRpc() : this.htm);
        this.cnv.appendChild(x);
        this.htm = '';
}


function pntCnvIe()
{
        this.cnv.insertAdjacentHTML("BeforeEnd", jg_fast? this.htmRpc() : this.htm);
        this.htm = '';
}


function pntCnvIhtm()
{
        this.cnv.innerHTML += this.htm;
        this.htm = '';
}


function pntCnv()
{
        this.htm = '';
}


function mkDiv(x, y, w, h)
{
        this.htm += '<div style="position:absolute;'+
                'left:' + x + 'px;'+
                'top:' + y + 'px;'+
                'width:' + w + 'px;'+
                'height:' + h + 'px;'+
                '-opacity:' + cw_opacity + ';'+
                '-moz-opacity:' + cw_opacity + ';'+
                '-khtml-opacity:' + cw_opacity + ';'+
                'filter: alpha(opacity=' + (cw_opacity * 100) + ');'+
                'clip:rect(0,'+w+'px,'+h+'px,0);'+
                'background-color:' + this.color +
                (!jg_moz? ';overflow:hidden' : '')+
                ';"><\/div>';
}


function mkDivIe(x, y, w, h)
{
        this.htm += '%%'+this.color+';'+x+';'+y+';'+w+';'+h+';';
}


function mkDivPrt(x, y, w, h)
{
        this.htm += '<div style="position:absolute;'+
                'border-left:' + w + 'px solid ' + this.color + ';'+
                'left:' + x + 'px;'+
                'top:' + y + 'px;'+
                'width:0px;'+
                'height:' + h + 'px;'+
                'clip:rect(0,'+w+'px,'+h+'px,0);'+
                'background-color:' + this.color +
                (!jg_moz? ';overflow:hidden' : '')+
                ';"><\/div>';
}


function mkLyr(x, y, w, h)
{
        this.htm += '<layer '+
                'left="' + x + '" '+
                'top="' + y + '" '+
                'width="' + w + '" '+
                'height="' + h + '" '+
                'bgcolor="' + this.color + '"><\/layer>\n';
}


var regex =  /%%([^;]+);([^;]+);([^;]+);([^;]+);([^;]+);/g;
function htmRpc()
{
        return this.htm.replace(
                regex,
                '<div style="overflow:hidden;position:absolute;background-color:'+
                '$1;left:$2;top:$3;width:$4;height:$5"></div>\n');
}


function htmPrtRpc()
{
        return this.htm.replace(
                regex,
                '<div style="overflow:hidden;position:absolute;background-color:'+
                '$1;left:$2;top:$3;width:$4;height:$5;border-left:$4px solid $1"></div>\n');
}


function mkLin(x1, y1, x2, y2)
{
        if (x1 > x2)
        {
                var _x2 = x2;
                var _y2 = y2;
                x2 = x1;
                y2 = y1;
                x1 = _x2;
                y1 = _y2;
        }
        var dx = x2-x1, dy = Math.abs(y2-y1),
        x = x1, y = y1,
        yIncr = (y1 > y2)? -1 : 1;

        if (dx >= dy)
        {
                var pr = dy<<1,
                pru = pr - (dx<<1),
                p = pr-dx,
                ox = x;
                while ((dx--) > 0)
                {
                        ++x;
                        if (p > 0)
                        {
                                this.mkDiv(ox, y, x-ox, 1);
                                y += yIncr;
                                p += pru;
                                ox = x;
                        }
                        else p += pr;
                }
                this.mkDiv(ox, y, x2-ox+1, 1);
        }

        else
        {
                var pr = dx<<1,
                pru = pr - (dy<<1),
                p = pr-dy,
                oy = y;
                if (y2 <= y1)
                {
                        while ((dy--) > 0)
                        {
                                if (p > 0)
                                {
                                        this.mkDiv(x++, y, 1, oy-y+1);
                                        y += yIncr;
                                        p += pru;
                                        oy = y;
                                }
                                else
                                {
                                        y += yIncr;
                                        p += pr;
                                }
                        }
                        this.mkDiv(x2, y2, 1, oy-y2+1);
                }
                else
                {
                        while ((dy--) > 0)
                        {
                                y += yIncr;
                                if (p > 0)
                                {
                                        this.mkDiv(x++, oy, 1, y-oy);
                                        p += pru;
                                        oy = y;
                                }
                                else p += pr;
                        }
                        this.mkDiv(x2, oy, 1, y2-oy+1);
                }
        }
}


function mkLin2D(x1, y1, x2, y2)
{
        if (x1 > x2)
        {
                var _x2 = x2;
                var _y2 = y2;
                x2 = x1;
                y2 = y1;
                x1 = _x2;
                y1 = _y2;
        }
        var dx = x2-x1, dy = Math.abs(y2-y1),
        x = x1, y = y1,
        yIncr = (y1 > y2)? -1 : 1;

        var s = this.stroke;
        if (dx >= dy)
        {
                if (s-3 > 0)
                {
                        var _s = (s*dx*Math.sqrt(1+dy*dy/(dx*dx))-dx-(s>>1)*dy) / dx;
                        _s = (!(s-4)? Math.ceil(_s) : Math.round(_s)) + 1;
                }
                else var _s = s;
                var ad = Math.ceil(s/2);

                var pr = dy<<1,
                pru = pr - (dx<<1),
                p = pr-dx,
                ox = x;
                while ((dx--) > 0)
                {
                        ++x;
                        if (p > 0)
                        {
                                this.mkDiv(ox, y, x-ox+ad, _s);
                                y += yIncr;
                                p += pru;
                                ox = x;
                        }
                        else p += pr;
                }
                this.mkDiv(ox, y, x2-ox+ad+1, _s);
        }

        else
        {
                if (s-3 > 0)
                {
                        var _s = (s*dy*Math.sqrt(1+dx*dx/(dy*dy))-(s>>1)*dx-dy) / dy;
                        _s = (!(s-4)? Math.ceil(_s) : Math.round(_s)) + 1;
                }
                else var _s = s;
                var ad = Math.round(s/2);

                var pr = dx<<1,
                pru = pr - (dy<<1),
                p = pr-dy,
                oy = y;
                if (y2 <= y1)
                {
                        ++ad;
                        while ((dy--) > 0)
                        {
                                if (p > 0)
                                {
                                        this.mkDiv(x++, y, _s, oy-y+ad);
                                        y += yIncr;
                                        p += pru;
                                        oy = y;
                                }
                                else
                                {
                                        y += yIncr;
                                        p += pr;
                                }
                        }
                        this.mkDiv(x2, y2, _s, oy-y2+ad);
                }
                else
                {
                        while ((dy--) > 0)
                        {
                                y += yIncr;
                                if (p > 0)
                                {
                                        this.mkDiv(x++, oy, _s, y-oy+ad);
                                        p += pru;
                                        oy = y;
                                }
                                else p += pr;
                        }
                        this.mkDiv(x2, oy, _s, y2-oy+ad+1);
                }
        }
}


function mkLinDott(x1, y1, x2, y2)
{
        if (x1 > x2)
        {
                var _x2 = x2;
                var _y2 = y2;
                x2 = x1;
                y2 = y1;
                x1 = _x2;
                y1 = _y2;
        }
        var dx = x2-x1, dy = Math.abs(y2-y1),
        x = x1, y = y1,
        yIncr = (y1 > y2)? -1 : 1,
        drw = true;
        if (dx >= dy)
        {
                var pr = dy<<1,
                pru = pr - (dx<<1),
                p = pr-dx;
                while ((dx--) > 0)
                {
                        if (drw) this.mkDiv(x, y, 1, 1);
                        drw = !drw;
                        if (p > 0)
                        {
                                y += yIncr;
                                p += pru;
                        }
                        else p += pr;
                        ++x;
                }
                if (drw) this.mkDiv(x, y, 1, 1);
        }

        else
        {
                var pr = dx<<1,
                pru = pr - (dy<<1),
                p = pr-dy;
                while ((dy--) > 0)
                {
                        if (drw) this.mkDiv(x, y, 1, 1);
                        drw = !drw;
                        y += yIncr;
                        if (p > 0)
                        {
                                ++x;
                                p += pru;
                        }
                        else p += pr;
                }
                if (drw) this.mkDiv(x, y, 1, 1);
        }
}


function mkOv(left, top, width, height)
{
        var a = width>>1, b = height>>1,
        wod = width&1, hod = (height&1)+1,
        cx = left+a, cy = top+b,
        x = 0, y = b,
        ox = 0, oy = b,
        aa = (a*a)<<1, bb = (b*b)<<1,
        st = (aa>>1)*(1-(b<<1)) + bb,
        tt = (bb>>1) - aa*((b<<1)-1),
        w, h;
        while (y > 0)
        {
                if (st < 0)
                {
                        st += bb*((x<<1)+3);
                        tt += (bb<<1)*(++x);
                }
                else if (tt < 0)
                {
                        st += bb*((x<<1)+3) - (aa<<1)*(y-1);
                        tt += (bb<<1)*(++x) - aa*(((y--)<<1)-3);
                        w = x-ox;
                        h = oy-y;
                        if (w&2 && h&2)
                        {
                                this.mkOvQds(cx, cy, -x+2, ox+wod, -oy, oy-1+hod, 1, 1);
                                this.mkOvQds(cx, cy, -x+1, x-1+wod, -y-1, y+hod, 1, 1);
                        }
                        else this.mkOvQds(cx, cy, -x+1, ox+wod, -oy, oy-h+hod, w, h);
                        ox = x;
                        oy = y;
                }
                else
                {
                        tt -= aa*((y<<1)-3);
                        st -= (aa<<1)*(--y);
                }
        }
        this.mkDiv(cx-a, cy-oy, a-ox+1, (oy<<1)+hod);
        this.mkDiv(cx+ox+wod, cy-oy, a-ox+1, (oy<<1)+hod);
}


function mkOv2D(left, top, width, height)
{
        var s = this.stroke;
        width += s-1;
        height += s-1;
        var a = width>>1, b = height>>1,
        wod = width&1, hod = (height&1)+1,
        cx = left+a, cy = top+b,
        x = 0, y = b,
        aa = (a*a)<<1, bb = (b*b)<<1,
        st = (aa>>1)*(1-(b<<1)) + bb,
        tt = (bb>>1) - aa*((b<<1)-1);

        if (s-4 < 0 && (!(s-2) || width-51 > 0 && height-51 > 0))
        {
                var ox = 0, oy = b,
                w, h,
                pxl, pxr, pxt, pxb, pxw;
                while (y > 0)
                {
                        if (st < 0)
                        {
                                st += bb*((x<<1)+3);
                                tt += (bb<<1)*(++x);
                        }
                        else if (tt < 0)
                        {
                                st += bb*((x<<1)+3) - (aa<<1)*(y-1);
                                tt += (bb<<1)*(++x) - aa*(((y--)<<1)-3);
                                w = x-ox;
                                h = oy-y;

                                if (w-1)
                                {
                                        pxw = w+1+(s&1);
                                        h = s;
                                }
                                else if (h-1)
                                {
                                        pxw = s;
                                        h += 1+(s&1);
                                }
                                else pxw = h = s;
                                this.mkOvQds(cx, cy, -x+1, ox-pxw+w+wod, -oy, -h+oy+hod, pxw, h);
                                ox = x;
                                oy = y;
                        }
                        else
                        {
                                tt -= aa*((y<<1)-3);
                                st -= (aa<<1)*(--y);
                        }
                }
                this.mkDiv(cx-a, cy-oy, s, (oy<<1)+hod);
                this.mkDiv(cx+a+wod-s+1, cy-oy, s, (oy<<1)+hod);
        }

        else
        {
                var _a = (width-((s-1)<<1))>>1,
                _b = (height-((s-1)<<1))>>1,
                _x = 0, _y = _b,
                _aa = (_a*_a)<<1, _bb = (_b*_b)<<1,
                _st = (_aa>>1)*(1-(_b<<1)) + _bb,
                _tt = (_bb>>1) - _aa*((_b<<1)-1),

                pxl = new Array(),
                pxt = new Array(),
                _pxb = new Array();
                pxl[0] = 0;
                pxt[0] = b;
                _pxb[0] = _b-1;
                while (y > 0)
                {
                        if (st < 0)
                        {
                                st += bb*((x<<1)+3);
                                tt += (bb<<1)*(++x);
                                pxl[pxl.length] = x;
                                pxt[pxt.length] = y;
                        }
                        else if (tt < 0)
                        {
                                st += bb*((x<<1)+3) - (aa<<1)*(y-1);
                                tt += (bb<<1)*(++x) - aa*(((y--)<<1)-3);
                                pxl[pxl.length] = x;
                                pxt[pxt.length] = y;
                        }
                        else
                        {
                                tt -= aa*((y<<1)-3);
                                st -= (aa<<1)*(--y);
                        }

                        if (_y > 0)
                        {
                                if (_st < 0)
                                {
                                        _st += _bb*((_x<<1)+3);
                                        _tt += (_bb<<1)*(++_x);
                                        _pxb[_pxb.length] = _y-1;
                                }
                                else if (_tt < 0)
                                {
                                        _st += _bb*((_x<<1)+3) - (_aa<<1)*(_y-1);
                                        _tt += (_bb<<1)*(++_x) - _aa*(((_y--)<<1)-3);
                                        _pxb[_pxb.length] = _y-1;
                                }
                                else
                                {
                                        _tt -= _aa*((_y<<1)-3);
                                        _st -= (_aa<<1)*(--_y);
                                        _pxb[_pxb.length-1]--;
                                }
                        }
                }

                var ox = 0, oy = b,
                _oy = _pxb[0],
                l = pxl.length,
                w, h;
                for (var i = 0; i < l; i++)
                {
                        if (typeof _pxb[i] != "undefined")
                        {
                                if (_pxb[i] < _oy || pxt[i] < oy)
                                {
                                        x = pxl[i];
                                        this.mkOvQds(cx, cy, -x+1, ox+wod, -oy, _oy+hod, x-ox, oy-_oy);
                                        ox = x;
                                        oy = pxt[i];
                                        _oy = _pxb[i];
                                }
                        }
                        else
                        {
                                x = pxl[i];
                                this.mkDiv(cx-x+1, cy-oy, 1, (oy<<1)+hod);
                                this.mkDiv(cx+ox+wod, cy-oy, 1, (oy<<1)+hod);
                                ox = x;
                                oy = pxt[i];
                        }
                }
                this.mkDiv(cx-a, cy-oy, 1, (oy<<1)+hod);
                this.mkDiv(cx+ox+wod, cy-oy, 1, (oy<<1)+hod);
        }
}


function mkOvDott(left, top, width, height)
{
        var a = width>>1, b = height>>1,
        wod = width&1, hod = height&1,
        cx = left+a, cy = top+b,
        x = 0, y = b,
        aa2 = (a*a)<<1, aa4 = aa2<<1, bb = (b*b)<<1,
        st = (aa2>>1)*(1-(b<<1)) + bb,
        tt = (bb>>1) - aa2*((b<<1)-1),
        drw = true;
        while (y > 0)
        {
                if (st < 0)
                {
                        st += bb*((x<<1)+3);
                        tt += (bb<<1)*(++x);
                }
                else if (tt < 0)
                {
                        st += bb*((x<<1)+3) - aa4*(y-1);
                        tt += (bb<<1)*(++x) - aa2*(((y--)<<1)-3);
                }
                else
                {
                        tt -= aa2*((y<<1)-3);
                        st -= aa4*(--y);
                }
                if (drw) this.mkOvQds(cx, cy, -x, x+wod, -y, y+hod, 1, 1);
                drw = !drw;
        }
}


function mkRect(x, y, w, h)
{
        var s = this.stroke;
        this.mkDiv(x, y, w, s);
        this.mkDiv(x+w, y, s, h);
        this.mkDiv(x, y+h, w+s, s);
        this.mkDiv(x, y+s, s, h-s);
}


function mkRectDott(x, y, w, h)
{
        this.drawLine(x, y, x+w, y);
        this.drawLine(x+w, y, x+w, y+h);
        this.drawLine(x, y+h, x+w, y+h);
        this.drawLine(x, y, x, y+h);
}


function jsgFont()
{
        this.PLAIN = 'font-weight:normal;';
        this.BOLD = 'font-weight:bold;';
        this.ITALIC = 'font-style:italic;';
        this.ITALIC_BOLD = this.ITALIC + this.BOLD;
        this.BOLD_ITALIC = this.ITALIC_BOLD;
}
var Font = new jsgFont();


function jsgStroke()
{
        this.DOTTED = -1;
}
var Stroke = new jsgStroke();


function jsGraphics(id, wnd)
{
        this.setColor = new Function('arg', 'this.color = arg.toLowerCase();');

        this.setStroke = function(x)
        {
                this.stroke = x;
                if (!(x+1))
                {
                        this.drawLine = mkLinDott;
                        this.mkOv = mkOvDott;
                        this.drawRect = mkRectDott;
                }
                else if (x-1 > 0)
                {
                        this.drawLine = mkLin2D;
                        this.mkOv = mkOv2D;
                        this.drawRect = mkRect;
                }
                else
                {
                        this.drawLine = mkLin;
                        this.mkOv = mkOv;
                        this.drawRect = mkRect;
                }
        };


        this.setPrintable = function(arg)
        {
                this.printable = arg;
                if (jg_fast)
                {
                        this.mkDiv = mkDivIe;
                        this.htmRpc = arg? htmPrtRpc : htmRpc;
                }
                else this.mkDiv = jg_n4? mkLyr : arg? mkDivPrt : mkDiv;
        };


        this.setFont = function(fam, sz, sty)
        {
                this.ftFam = fam;
                this.ftSz = sz;
                this.ftSty = sty || Font.PLAIN;
        };


        this.drawPolyline = this.drawPolyLine = function(x, y, s)
        {
                for (var i=0 ; i<x.length-1 ; i++ )
                        this.drawLine(x[i], y[i], x[i+1], y[i+1]);
        };


        this.fillRect = function(x, y, w, h)
        {
                this.mkDiv(x, y, w, h);
        };


        this.drawPolygon = function(x, y)
        {
                this.drawPolyline(x, y);
                this.drawLine(x[x.length-1], y[x.length-1], x[0], y[0]);
        };


        this.drawEllipse = this.drawOval = function(x, y, w, h)
        {
                this.mkOv(x, y, w, h);
        };


        this.fillEllipse = this.fillOval = function(left, top, w, h)
        {
                var a = (w -= 1)>>1, b = (h -= 1)>>1,
                wod = (w&1)+1, hod = (h&1)+1,
                cx = left+a, cy = top+b,
                x = 0, y = b,
                ox = 0, oy = b,
                aa2 = (a*a)<<1, aa4 = aa2<<1, bb = (b*b)<<1,
                st = (aa2>>1)*(1-(b<<1)) + bb,
                tt = (bb>>1) - aa2*((b<<1)-1),
                pxl, dw, dh;
                if (w+1) while (y > 0)
                {
                        if (st < 0)
                        {
                                st += bb*((x<<1)+3);
                                tt += (bb<<1)*(++x);
                        }
                        else if (tt < 0)
                        {
                                st += bb*((x<<1)+3) - aa4*(y-1);
                                pxl = cx-x;
                                dw = (x<<1)+wod;
                                tt += (bb<<1)*(++x) - aa2*(((y--)<<1)-3);
                                dh = oy-y;
                                this.mkDiv(pxl, cy-oy, dw, dh);
                                this.mkDiv(pxl, cy+oy-dh+hod, dw, dh);
                                ox = x;
                                oy = y;
                        }
                        else
                        {
                                tt -= aa2*((y<<1)-3);
                                st -= aa4*(--y);
                        }
                }
                this.mkDiv(cx-a, cy-oy, w+1, (oy<<1)+hod);
        };



/* fillPolygon method, implemented by Matthieu Haller.
This javascript function is an adaptation of the gdImageFilledPolygon for Walter Zorn lib.
C source of GD 1.8.4 found at http://www.boutell.com/gd/

THANKS to Kirsten Schulz for the polygon fixes!

The intersection finding technique of this code could be improved
by remembering the previous intertersection, and by using the slope.
That could help to adjust intersections to produce a nice
interior_extrema. */
        this.fillPolygon = function(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 (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++)
                {
                        var polyInts = new Array();
                        ints = 0;
                        for (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;

                                 // modified 11. 2. 2004 Walter Zorn
                                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(integer_compare);
                        for (i = 0; i < ints; i+=2)
                                this.mkDiv(polyInts[i], y, polyInts[i+1]-polyInts[i]+1, 1);
                }
        };


        this.drawString = function(txt, x, y)
        {
                this.htm += '<div style="position:absolute;white-space:nowrap;'+
                        'left:' + x + 'px;'+
                        'top:' + y + 'px;'+
                        'font-family:' +  this.ftFam + ';'+
                        'font-size:' + this.ftSz + ';'+
                        'color:' + this.color + ';' + this.ftSty + '">'+
                        txt +
                        '<\/div>';
        }


        this.drawImage = function(imgSrc, x, y, w, h)
        {
                this.htm += '<div style="position:absolute;'+
                        'left:' + x + 'px;'+
                        'top:' + y + 'px;'+
                        'width:' +  w + ';'+
                        'height:' + h + ';">'+
                        '<img src="' + imgSrc + '" width="' + w + '" height="' + h + '">'+
                        '<\/div>';
        }


        this.clear = function()
        {
                this.htm = "";
                if (this.cnv) this.cnv.innerHTML = this.defhtm;
        };


        this.mkOvQds = function(cx, cy, xl, xr, yt, yb, w, h)
        {
                this.mkDiv(xr+cx, yt+cy, w, h);
                this.mkDiv(xr+cx, yb+cy, w, h);
                this.mkDiv(xl+cx, yb+cy, w, h);
                this.mkDiv(xl+cx, yt+cy, w, h);
        };

        this.setStroke(1);
        this.setFont('verdana,geneva,helvetica,sans-serif', String.fromCharCode(0x31, 0x32, 0x70, 0x78), Font.PLAIN);
        this.color = '#000000';
        this.htm = '';
        this.wnd = wnd || window;

        if (!(jg_ie || jg_dom || jg_ihtm)) chkDHTM();
        if (typeof id != 'string' || !id) this.paint = pntDoc;
        else
        {
                this.cnv = document.all? (this.wnd.document.all[id] || null)
                        : document.getElementById? (this.wnd.document.getElementById(id) || null)
                        : null;
                this.defhtm = (this.cnv && this.cnv.innerHTML)? this.cnv.innerHTML : '';
                this.paint = jg_dom? pntCnvDom : jg_ie? pntCnvIe : jg_ihtm? pntCnvIhtm : pntCnv;
        }

        this.setPrintable(false);
}



function integer_compare(x,y)
{
        return (x < y) ? -1 : ((x > y)*1);
}


// ++ //


var item = 'ms:comment';
var layerlist = 'mess';
var mod_usemap_wfs = 'http://www.webmapcenter.de/cgi-bin/mapserv?map=/var/data/www.webmapcenter.de/gbu/mapfiles/pegel_wfs.map&service=wfs&VERSION=1.0.0&REQUEST=GetFeature';
var mysld = '100907_5b4784bb6da7d5466285b6f96b0ed8be';
var mod_usemap_target = 'mapframe1';
var mod_usemap_px = 10;
var um_title;
var um_draw; 

mb_registerSubFunctions('mod_usemap_init()');
mb_registerInitFunctions("um_init()");

function mod_usemap_init(){
  var ind = getMapObjIndexByName(mod_usemap_target);
  var extent = mb_mapObj[ind].extent;
  var Thems = layerlist.split("|");
  arrCrudeThems = new Array;
  arrThems = new Array;
  arrTemp = new Array;
  arrCrudeThems = mb_mapObj[ind].layers;
 
  for (j=0; j<arrCrudeThems.length; j++) {
   arrTemp = arrCrudeThems[j].split(",");
	 for (jj=0; jj<arrTemp.length; jj++) {
    cnt = arrThems.length;
		arrThems[cnt] = arrTemp[jj];	  
	 }
	}

	var url = "../php/mod_usemap2.php?url="
	url += escape(mod_usemap_wfs + "&typename=");	
  astr = "";

  for (var i=0; i<Thems.length; i++) {	
	  for (var ii=0; ii<arrThems.length; ii++) {
          if (arrThems[ii] != "" && arrThems[ii] == Thems[i]) {

      astr += arrThems[ii]; 
      astr += ",";
     }
    }
   }
  astr = astr.substring(0,astr.length -1);
  url += escape(astr);
	url += escape("&BBOX=" + extent);
	url += "&extent=" + extent;
	url += "&width=" + mb_mapObj[ind].width;
	url += "&height=" + mb_mapObj[ind].height;
       url += "&item=" + item;
       url += "&myview=" + mysld;
	document.getElementById('usemap').src = url;
	var myImg = window.frames[mod_usemap_target].document.getElementById("um_img").style; 
	myImg.width = mb_mapObj[ind].width;
	myImg.height = mb_mapObj[ind].height;
}

function mod_usemap_set(title,x,y){
	var str = "";
	for(var i=0; i<title.length; i++){
		var pos = makeRealWorld2mapPos(mod_usemap_target,x[i],y[i]);
		str += "<AREA  onmouseover='parent.over(event, \"" + title[i] + "\", this)' ";
		str += "onmouseout=parent.out(this) shape='circle'  coords='";
		str += Math.round(pos[0]) + "," + Math.round(pos[1]) + "," + mod_usemap_px + "'";
		str += " href='#'>";
	}	
	writeTag(mod_usemap_target, 'um', str);
}



/* Opacity for hilighting */
    cw_opacity = 0.5;
/* Color for polygon boundary */
    cw_bndcolor = "#ff0000";
/* Color for polygon fill */
    cw_fillcolor = "#ffff00";




function polyXcoords(coords) {
    var Xcoords = '';
    for (var z = 0; z<coords.length; z=z+2) {
        if (z > 0) { Xcoords += ', '; }
            Xcoords += parseInt(coords[z]);
        }
        return Xcoords;
    }

function polyYcoords(coords) {
   var Ycoords = '';
   for (var z = 1; z<coords.length; z=z+2) {
       if (z > 1) { Ycoords += ', '; }
            Ycoords += parseInt(coords[z]);
        }
        return Ycoords;
}

function setFocus(objid) {
    if (canvasHasDrawing == true) return true;
        var coords = objid.coords.split(',');
        if ((objid.shape.toUpperCase() == 'POLY') || (objid.shape.toUpperCase() == 'POLYGON')) {
            var Xcoords = polyXcoords(coords);
            var Ycoords = polyYcoords(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]);
            }
            canvas.setColor(cw_fillcolor);
            canvas.fillPolygon(pgx,pgy);
            canvas.paint();
            canvas.setColor(cw_bndcolor);
            canvas.drawPolygon(pgx,pgy);
            canvas.paint();
        }
        if ((objid.shape.toUpperCase() == 'CIRCLE')) {
            var c = coords;
            canvas.setColor(cw_fillcolor);
            canvas.fillEllipse(parseInt(c[0])-mod_usemap_px/2,parseInt(c[1])-mod_usemap_px/2,parseInt(c[2]),parseInt(c[2]));
            canvas.paint();
            canvas.setColor(cw_bndcolor);
            canvas.drawEllipse(parseInt(c[0])-mod_usemap_px/2,parseInt(c[1])-mod_usemap_px/2,parseInt(c[2]),parseInt(c[2]));
            canvas.paint();            
        }
        canvasHasDrawing = true; 
        return true;
    }

function clearFocus(objid) {
    if (canvasHasDrawing) canvas.clear();
        canvasHasDrawing = false;
        return true;
    }

function over(e, id, area) {
    var coords = area.coords.split(',');
    area.setAttribute('title', "");
    if (!isOver) {
        um_title.innerHTML = id;
        um_title.style.display = "block";
        isOver = area;
        setFocus(area);
    }
    mb_arrangeElement(mod_usemap_target, 'um_title', parseInt(coords[0])+mod_usemap_px, parseInt(coords[1])+mod_usemap_px);
    canvasHasDrawing = true;
}

function out(area) {
    um_title.innerHTML = "";
    um_title.style.display = "none";
    clearFocus(area);
    isOver = false;
    canvasHasDrawing = false;
}

function um_init() {
    um_title = window.frames[mod_usemap_target].document.getElementById("um_title"); /* tooltip */
    um_draw = window.frames[mod_usemap_target].document.getElementById("um_draw"); /* tooltip */
    canvas = new jsGraphics('um_draw', window.frames['mapframe1']);
    canvas.setStroke(2);
    canvasHasDrawing = false;
    isOver = false;

}

































var mod_scalebar_target = 'mapframe1';
var mod_scalebar_left = 5;
var mod_scalebar_bottom = 17;

var mod_scalebar_color1 = "white";
var mod_scalebar_color2 = "black";
var mod_scalebar_font = "Arial, Helvetica, sans-serif";
var mod_scalebar_fontsize = "9px";

mb_registerSubFunctions("mod_scalebar()");
function mod_scalebar(){
	var scale = mb_getScale(mod_scalebar_target);
	var ind = getMapObjIndexByName(mod_scalebar_target);
	if(scale < 10){
		var unit = '10&nbsp;cm';
		var factor = 10/scale;
		var img_width = Math.round(factor * mb_resolution);
	}
	if(scale >= 10 && scale < 100){
		var unit = '1&nbsp;m';
		var factor = 100/scale;
		var img_width = Math.round(factor * mb_resolution);
	}
	if(scale < 1000 && scale >= 100){
		var unit = '10&nbsp;m';
		var factor = 1000/scale;
		var img_width = Math.round(factor * mb_resolution);
	}
	if(scale < 10000 && scale >= 1000){
		var unit = '100&nbsp;m';
		var factor = 10000/scale;
		var img_width = Math.round(factor * mb_resolution);
	}
	if(scale < 100000 && scale >= 10000){
		var unit = '1&nbsp;km';
		var factor = 100000/scale;
		var img_width = Math.round(factor * mb_resolution);
	}
	if(scale < 1000000 && scale >= 100000){
		var unit = '10&nbsp;km';
		var factor = 1000000/scale;
	var img_width = Math.round(factor * mb_resolution);
	}
	if(scale < 10000000 && scale >= 1000000){
		var unit = '100&nbsp;km';
		var factor = 10000000/scale;
		var img_width = Math.round(factor * mb_resolution);
	}
	if(scale < 100000000 && scale >= 10000000){
		var unit = '1000&nbsp;km';
		var factor = 100000000/scale;
		var img_width = Math.round(factor * mb_resolution);
	}
	if(scale >= 100000000){
		var unit = '1000&nbsp;km';
		var factor = 100000000/scale;
		var img_width = Math.round(factor * mb_resolution);
	}
	var scalebarTag = "<img src='../img/scalebar_bw.gif' width='"+ img_width  +"' height='6'>&nbsp; ";
	scalebarTag += "<div style='position:absolute;left:"+(img_width + 4)+"px;top:5px;color:"+mod_scalebar_color1+";font-family:"+mod_scalebar_font+";font-size:"+mod_scalebar_fontsize+";'><nobr>"+ unit+"</nobr></div>";
	scalebarTag += "<div style='position:absolute;left:"+(img_width + 2)+"px;top:7px;color:"+mod_scalebar_color1+";font-family:"+mod_scalebar_font+";font-size:"+mod_scalebar_fontsize+";'><nobr>"+ unit+"</nobr></div>";
	scalebarTag += "<div style='position:absolute;left:"+(img_width + 2)+"px;top:5px;color:"+mod_scalebar_color1+";font-family:"+mod_scalebar_font+";font-size:"+mod_scalebar_fontsize+";'><nobr>"+ unit+"</nobr></div>";
	scalebarTag += "<div style='position:absolute;left:"+(img_width + 3)+"px;top:6px;color:"+mod_scalebar_color2+";font-family:"+mod_scalebar_font+";font-size:"+mod_scalebar_fontsize+";'>"+ unit+"</div>";
	mb_arrangeElement(mod_scalebar_target, "scalebar", mod_scalebar_left, (mb_mapObj[ind].height - mod_scalebar_bottom));
	writeTag(mod_scalebar_target, "scalebar", scalebarTag);   
}var mod_dependentDiv_target = 'mapframe1';mod_dependentDiv_offsetLeft = 10;
mod_dependentDiv_offsetTop = 10;

mb_registerSubFunctions("mod_dependentDiv()");
function mod_dependentDiv(){
	var obj = document.getElementById(mod_dependentDiv_target).style;
	var thisObj = document.getElementById('dependentDiv').style; 
	thisObj.left = parseInt(obj.left) - mod_dependentDiv_offsetLeft;
	thisObj.top = parseInt(obj.top) + parseInt(obj.height) +  mod_dependentDiv_offsetTop;
	thisObj.width = parseInt(obj.width) + (2*mod_dependentDiv_offsetTop);
}var mod_sandclock_target = 'mapframe1';
var mod_sandclock_img = new Image();
mod_sandclock_img.src = "../img/sandclock.gif";
mb_registerSubFunctions("mod_sandclock(true,myMapId)");

function mod_sandclock(start,myMapId){
	var ind = getMapObjIndexByName(mod_sandclock_target);
	if(start){
		var temp = "<img src='"+mod_sandclock_img.src+"'>";
		writeTag(mod_sandclock_target, "sandclock", temp);
		mb_arrangeElement(mod_sandclock_target, "sandclock", (mb_mapObj[ind].width/2 - 16), (mb_mapObj[ind].height/2 - 16));
	}
	aktiv = setTimeout("mod_sandclock('','"+myMapId+"')",100);
	if(window.frames[mod_sandclock_target].document.getElementById(myMapId) && window.frames[mod_sandclock_target].document.getElementById(myMapId).complete){
		clearTimeout(aktiv);
		writeTag(mod_sandclock_target, "sandclock", "");
	} 
}
var tab_ids = new Array();
tab_ids[0] = 'treeGDE';
tab_ids[1] = 'legend';
var tab_prefix = '  ';
var tab_style = 'position:absolute;visibility:visible;border: 1px solid #000000;font-size:12;color:#343434;background-color:#b5d6e2;cursor:pointer;';
var tab_titles = new Array();
tab_titles[0] = 'Karten';
tab_titles[1] = 'Legende';
var tab_frameHeight = new Array();
tab_frameHeight[0] = 300;
tab_frameHeight[1] = 300;
tab_frameHeight[2] = 300;
var open_tab = 1;
tab_titles[2] = 'Impressum';
tab_ids[2] = 'imprint';
var tab_height = false;
var tab_width = false;
var tab_topOffset = false;
var tab_leftOffset = false;
var tab_active = -1;
var tab_check = new Array();
var tab_iv1 = false;
var tab_wait = false;

try{
	if (open_tab){}
}
catch(e){
	open_tab = false;
}

/********** Configuration*************************************************/
mb_registerInitFunctions('tab_init()');
function tab_init(){
	var obj = document.getElementById("tabs").style;
	tab_topOffset = parseInt(obj.top);
	tab_leftOffset = parseInt(obj.left);
	tab_width = parseInt(obj.width);
	tab_height = parseInt(obj.height);
	var str = "";

	for(var i = 0; i<tab_ids.length; i++){
		document.getElementById(tab_ids[i]).style.visibility = 'hidden';
		tab_titles[i] = tab_prefix + tab_titles[i];
		var newId = "tab_" + i;
		str += "<div id='"+newId+"' ";
		str += "style='";
		str += tab_style;
		str += "width:"+tab_width+"px;";
		str += "height:"+tab_height+"px;";        
		str += "top:" + ((i * tab_height)) + "px;";
		str += "'";
		str += " onclick='tab_set("+i+")'>";
		str += tab_titles[i];
		str += "</div>";
	}
	document.getElementById("tabs").innerHTML = str;

	if (open_tab != 'false'){
		tab_set(open_tab);
	}
}
function tab_set(ind){
	if(tab_wait){
		return;
	}
	tab_unsetFrame();
	if(ind == tab_active){
		tab_wait = true;
		tab_active = -1;
		tab_check = new Array();
		tab_iv1 = setInterval("tab_move("+tab_active+")",1);
		return;
	}	
	else{
		tab_wait = true;
		tab_active = ind;
		tab_check = new Array();
		tab_iv1 = setInterval("tab_move("+tab_active+")",1);
		return;
	}
}
function tab_setFrame(ind){
	for(var i = 0; i<tab_ids.length; i++){		
		if(i == ind){
			var obj = document.getElementById(tab_ids[i]).style;
			var newpos = ((i+1) * tab_height) + parseInt(tab_topOffset);
			obj.top = (newpos + 1) + "px";
			obj.left = (tab_leftOffset) + "px";
			obj.width = tab_width;
			obj.height = (parseInt(tab_frameHeight[ind]) - 2);
			obj.visibility = 'visible';
		}
	}
}
function tab_unsetFrame(){
	for(var i = 0; i<tab_ids.length; i++){
		var obj = document.getElementById(tab_ids[i]).style;
		obj.visibility = 'hidden';
	}
}
function tab_open(tabid){
	var t = false;
	for(var i = 0; i<tab_ids.length; i++){
		if(tab_ids[i] == tabid){
			t = i;
		}
	}
	if(tab_active != t){
		tab_set(t);
	}
}
function tab_move(ind){			
	for(var i = 0; i<tab_ids.length; i++){
		var newpos = (i * tab_height);
		if(i > ind && tab_active >= 0){
			newpos += parseInt(tab_frameHeight[ind]);
		}
		var myid = "tab_" + i;		
		var pos = parseInt(document.getElementById(myid).style.top);
		if(pos == newpos){
			tab_check[i] = true;
		}
		else if(pos < newpos){			
			document.getElementById(myid).style.top = (pos + 10) + "px"; 
			tab_check[i] = false;
		}
		else if(pos > newpos){
			document.getElementById(myid).style.top = (pos - 10) + "px";
			tab_check[i] = false;
		}		
	}
	
	var check = true;
	for(var j=0; j<tab_check.length; j++){
		if(tab_check[j] == false){
			check = false;
		}
	}
	if(check == true){
		clearInterval(tab_iv1);
		tab_check = new Array();
		tab_wait = false;
		if(ind >= 0){
			tab_setFrame(ind);
		}
		return;
	}
}var mod_scaleSelect_target = 'mapframe1';mb_registerSubFunctions("mod_scaleSelect_val(frameName)");
function mod_scaleSelect(obj){
	var ind = obj.selectedIndex;
	mb_repaintScale(mod_scaleSelect_target,null,null,obj.options[ind].value);
}
function mod_scaleSelect_val(frameName){
	if(frameName == mod_scaleSelect_target){
		var scale = mb_getScale(frameName);
		document.getElementById("scaleSelect").options[0].text = "1 : " + scale;
		document.getElementById("scaleSelect").options[0].selected = true;
	}
}
var mod_navFrame_target = 'mapframe1';var mod_navFrame_src = '';var mod_navFrame_ext = 10;
mb_registerSubFunctions("mod_navFrame_arrange()");

function  mod_navFrame_arrange(){
	var el = document.getElementById(mod_navFrame_target).style;
	var ext = mod_navFrame_ext;
	var myLeft = parseInt(el.left);
	var myTop = parseInt(el.top);
	var myWidth = parseInt(el.width);
	var myHeight = parseInt(el.height);
	//left,top,width,height
	mod_navFrame_pos("mbN",(myLeft),(myTop - ext),(myWidth),(ext));
	document.getElementById("arrow_n").style.left = myWidth/2 - document.getElementById("arrow_n").width/2;   
	mod_navFrame_pos("mbNE",(myLeft + myWidth),(myTop - ext),(ext),(ext));
	mod_navFrame_pos("mbE",(myLeft + myWidth),(myTop),(ext),(myHeight));
	document.getElementById("arrow_e").style.top = myHeight/2 - document.getElementById("arrow_n").height/2;
	mod_navFrame_pos("mbSE",(myLeft + myWidth),(myTop + myHeight),(ext),(ext));
	mod_navFrame_pos("mbS",(myLeft),(myTop + myHeight),(myWidth),(ext));
	document.getElementById("arrow_s").style.left = myWidth/2 - document.getElementById("arrow_s").width/2;
	mod_navFrame_pos("mbSW",(myLeft - ext),(myTop + myHeight),(ext),(ext));
	mod_navFrame_pos("mbW",(myLeft - ext),(myTop),(ext),(myHeight));
	document.getElementById("arrow_w").style.top = myHeight/2 - document.getElementById("arrow_w").height/2;
	mod_navFrame_pos("mbNW",(myLeft - ext),(myTop -ext),(ext),(ext));   
}
function mod_navFrame(val){
	mb_panMap(mod_navFrame_target,val);  
}
function mod_navFrame_pos(el,left,top,width,height){
//alert(el + " , " +left + " , " +top + " , " +width + " , " +height)
	document.getElementById(el).style.left = left;
	document.getElementById(el).style.top = top;
	document.getElementById(el).style.width = width;
	document.getElementById(el).style.height = height;
}
var mod_back_map = 'mapframe1';var mod_back_overview = 'overview0';var mb_MapHistoryObj = new Array();
var mod_back_img_off = new Image(); mod_back_img_off.src = "../img/button_gray/back_off.png";
var mod_back_img_off_disabled = new Image(); mod_back_img_off_disabled.src = "../img/button_gray/back_off_disabled.png";
var mod_back_img_over = new Image(); mod_back_img_over.src = "../img/button_gray/back_over.png";
var mod_back_img_previous = null;
var mod_back_cnt = -1;

mb_registerSubFunctions("mb_setHistoryObj(frameName)");
mb_registerSubFunctions("mod_back_check(frameName)");

function mod_back_check(frameName){
	if(frameName == mod_back_map){
		mod_back_cnt++;
		if(mb_MapHistoryObj[mod_back_map].length > 1){
			document.getElementById("back").src =  mod_back_img_off.src;
		}
		else{
			document.getElementById("back").src =  mod_back_img_off_disabled.src;
			mod_back_img_previous = document.getElementById("back").src;
		}
	}
}
function mod_back_over(obj){
	mod_back_img_previous = document.getElementById("back").src;
	if(document.getElementById("back").src ==  mod_back_img_off.src){
		document.getElementById("back").src = mod_back_img_over.src;
	}
}

function mod_back_out(obj){
	document.getElementById("back").src  = mod_back_img_previous;
}

function mod_back_set(){
	if(mod_back_img_previous ==  mod_back_img_off.src){
		if(mb_MapFutureObj){
			mb_setFutureObj(mod_back_map);
		}
		var ind = getMapObjIndexByName(mod_back_map);
		var cnt = mb_MapHistoryObj[mod_back_map].length - 2;
		if(mb_mapObj[ind].epsg != mb_MapHistoryObj[mod_back_map][cnt].epsg){
			var oind = getMapObjIndexByName(mod_back_overview);
			for(var i=0; i < mb_MapHistoryObj[mod_back_overview].length; i++){
				if(mb_MapHistoryObj[mod_back_overview][i].epsg == mb_MapHistoryObj[mod_back_map][cnt].epsg){
					mb_mapObj[oind].epsg = mb_MapHistoryObj[mod_back_overview][i].epsg;
					mb_mapObj[oind].extent = mb_MapHistoryObj[mod_back_overview][i].extent;
					setMapRequest(mod_back_overview);
					break;
				}
			}
		}
		document.getElementById(mod_back_map).style.width = mb_MapHistoryObj[mod_back_map][cnt].width;
		document.getElementById(mod_back_map).style.height = mb_MapHistoryObj[mod_back_map][cnt].height;     
		mb_mapObj[ind].width = mb_MapHistoryObj[mod_back_map][cnt].width;
		mb_mapObj[ind].height = mb_MapHistoryObj[mod_back_map][cnt].height;     
		mb_mapObj[ind].epsg = mb_MapHistoryObj[mod_back_map][cnt].epsg;
		mb_mapObj[ind].extent = mb_MapHistoryObj[mod_back_map][cnt].extent;
		mb_mapObj[ind].layers = mb_MapHistoryObj[mod_back_map][cnt].layers;
		mb_mapObj[ind].styles = mb_MapHistoryObj[mod_back_map][cnt].styles;
		mb_mapObj[ind].querylayers = mb_MapHistoryObj[mod_back_map][cnt].querylayers;
		mb_MapHistoryObj[mod_back_map].length = (mb_MapHistoryObj[mod_back_map].length - 2);
		setMapRequest(mod_back_map);
	}
}
function mb_setHistoryObj(frameName){
	if(mb_MapHistoryObj[frameName] == null){
		mb_MapHistoryObj[frameName] = new Array();
	}
	var ind = getMapObjIndexByName(frameName);
	var cnt = mb_MapHistoryObj[frameName].length;
	mb_MapHistoryObj[frameName][cnt] = new Object();
	mb_MapHistoryObj[frameName][cnt].width = mb_mapObj[ind].width;
	mb_MapHistoryObj[frameName][cnt].height = mb_mapObj[ind].height;
	mb_MapHistoryObj[frameName][cnt].epsg = mb_mapObj[ind].epsg;
	mb_MapHistoryObj[frameName][cnt].extent = mb_mapObj[ind].extent;
	mb_MapHistoryObj[frameName][cnt].layers = new Array();
	for(var i=0; i<mb_mapObj[ind].layers.length;i++){
		mb_MapHistoryObj[frameName][cnt].layers[i] = mb_mapObj[ind].layers[i];
	}
	mb_MapHistoryObj[frameName][cnt].styles = new Array();
	for(var i=0; i<mb_mapObj[ind].styles.length;i++){
		mb_MapHistoryObj[frameName][cnt].styles[i] = mb_mapObj[ind].styles[i];
	}
	mb_MapHistoryObj[frameName][cnt].querylayers = new Array();
	for(var i=0; i<mb_mapObj[ind].querylayers.length;i++){
		mb_MapHistoryObj[frameName][cnt].querylayers[i] = mb_mapObj[ind].querylayers[i];
	}
}
var mod_featureInfo_elName = "featureInfo1";
var mod_featureInfo_frameName = "";
var mod_featureInfo_target = "mapframe1";

var mod_featureInfo_img_on = new Image(); mod_featureInfo_img_on.src =  "../img/button_gray/query_on.png";
var mod_featureInfo_img_off = new Image(); mod_featureInfo_img_off.src ="../img/button_gray/query_off.png";
var mod_featureInfo_img_over = new Image(); mod_featureInfo_img_over.src = "../img/button_gray/query_over.png";

function init_featureInfo1(ind){
	mb_button[ind] = document.getElementById(mod_featureInfo_elName);
	mb_button[ind].img_over = mod_featureInfo_img_over.src;
	mb_button[ind].img_on = mod_featureInfo_img_on.src;
	mb_button[ind].img_off = mod_featureInfo_img_off.src;
	mb_button[ind].status = 0;
	mb_button[ind].elName = mod_featureInfo_elName;
	mb_button[ind].fName = mod_featureInfo_frameName;
	mb_button[ind].go = new Function ("mod_featureInfo_click()");
	mb_button[ind].stop = new Function ("mod_featureInfo_disable()");
}
function mod_featureInfo_click(){   
	window.frames[mod_featureInfo_target].document.onclick = mod_featureInfo_event;
}
function mod_featureInfo_disable(){
	window.frames[mod_featureInfo_target].document.onclick = null;
}
function mod_featureInfo_event(e){
	if(ie){
		clickX = window.frames[mod_featureInfo_target].event.clientX;
		clickY = window.frames[mod_featureInfo_target].event.clientY;
	}
	else{
		clickX = e.pageX;
		clickY = e.pageY;
	}
	setFeatureInfoRequest(mod_featureInfo_target,clickX,clickY);
}var mod_forward_map = 'mapframe1';var mod_forward_overview = 'overview0';var mb_MapFutureObj = new Array();
var mod_forward_img_off = new Image(); mod_forward_img_off.src = "../img/button_gray/forward_off.png";
var mod_forward_img_off_disabled = new Image(); mod_forward_img_off_disabled.src = "../img/button_gray/forward_off_disabled.png";
var mod_forward_img_over = new Image(); mod_forward_img_over.src = "../img/button_gray/forward_over.png";
var mod_forward_img_previous = mod_forward_img_off_disabled.src;
var mod_forward_cnt = 0;
var mod_forward_hist_cnt = 0;
mb_registerSubFunctions("mod_forward_check(frameName)");

function mod_forward_check(frameName){
	if(mb_MapFutureObj[frameName] == null){
		mb_MapFutureObj[frameName] = new Array();
	}
	if(frameName == mod_forward_map){
		if(mb_MapFutureObj[mod_forward_map].length > 0){
			document.getElementById("forward").src =  mod_forward_img_off.src;
		}
		else{
			document.getElementById("forward").src =  mod_forward_img_off_disabled.src;
			mod_forward_img_previous = document.getElementById("forward").src;
		}
	}
	if(mb_MapHistoryObj[mod_forward_map]){
		if(mb_MapHistoryObj[mod_forward_map].length > mod_forward_hist_cnt && mb_MapFutureObj[mod_forward_map].length == mod_forward_cnt){
			mod_forward_reset();
		}
		mod_forward_cnt = mb_MapFutureObj[mod_forward_map].length;
		mod_forward_hist_cnt = mb_MapHistoryObj[mod_forward_map].length;
	}
}
function mod_forward_reset(){
	if(mb_MapHistoryObj[mod_forward_map].length > 0){
		mb_MapFutureObj[mod_forward_map] = new Array();
		document.getElementById("forward").src =  mod_forward_img_off_disabled.src;
		mod_forward_img_previous = document.getElementById("forward").src;
	}
}
function mod_forward_over(obj){
	mod_forward_img_previous = document.getElementById("forward").src;
	if(document.getElementById("forward").src ==  mod_forward_img_off.src){
		document.getElementById("forward").src = mod_forward_img_over.src;
	}
}
function mod_forward_out(obj){
	document.getElementById("forward").src  = mod_forward_img_previous;
}
function mod_forward_set(){
	if(mod_forward_img_previous ==  mod_forward_img_off.src){
		var ind = getMapObjIndexByName(mod_forward_map);
		var cnt = mb_MapFutureObj[mod_forward_map].length - 1;
		if(mb_mapObj[ind].epsg != mb_MapFutureObj[mod_forward_map][cnt].epsg){
			var oind = getMapObjIndexByName(mod_forward_overview);
			for(var i=0; i<mb_MapHistoryObj[mod_forward_overview].length; i++){
				if(mb_MapHistoryObj[mod_forward_overview][i].epsg == mb_MapFutureObj[mod_forward_map][cnt].epsg){
					mb_mapObj[oind].epsg = mb_MapHistoryObj[mod_forward_overview][i].epsg;
					mb_mapObj[oind].extent = mb_MapHistoryObj[mod_forward_overview][i].extent;
					setMapRequest(mod_forward_overview);
					break;
				}
			}
		}
		document.getElementById(mod_forward_map).style.width = mb_MapFutureObj[mod_forward_map][cnt].width;
		document.getElementById(mod_forward_map).style.height = mb_MapFutureObj[mod_forward_map][cnt].height;     
		mb_mapObj[ind].width = mb_MapFutureObj[mod_forward_map][cnt].width;
		mb_mapObj[ind].height = mb_MapFutureObj[mod_forward_map][cnt].height;
		mb_mapObj[ind].epsg = mb_MapFutureObj[mod_forward_map][cnt].epsg;
		mb_mapObj[ind].extent = mb_MapFutureObj[mod_forward_map][cnt].extent;
		mb_mapObj[ind].layers = mb_MapFutureObj[mod_forward_map][cnt].layers;
		mb_mapObj[ind].styles = mb_MapFutureObj[mod_forward_map][cnt].styles;
		mb_mapObj[ind].querylayers = mb_MapFutureObj[mod_forward_map][cnt].querylayers;
		mb_MapFutureObj[mod_forward_map].length = (mb_MapFutureObj[mod_forward_map].length - 1);
		setMapRequest(mod_forward_map);
	}
}
function mb_setFutureObj(frameName){
	var ind = getMapObjIndexByName(frameName);
	var cnt = mb_MapFutureObj[frameName].length;
	mb_MapFutureObj[frameName][cnt] = new Object();
	mb_MapFutureObj[frameName][cnt].reqCnt = mod_back_cnt;
	mb_MapFutureObj[frameName][cnt].width = mb_mapObj[ind].width;
	mb_MapFutureObj[frameName][cnt].height = mb_mapObj[ind].height;
	mb_MapFutureObj[frameName][cnt].epsg = mb_mapObj[ind].epsg;
	mb_MapFutureObj[frameName][cnt].extent = mb_mapObj[ind].extent;
	mb_MapFutureObj[frameName][cnt].layers = new Array();
	for(var i=0; i<mb_mapObj[ind].layers.length;i++){
		mb_MapFutureObj[frameName][cnt].layers[i] = mb_mapObj[ind].layers[i];
	}
	mb_MapFutureObj[frameName][cnt].styles = new Array();
	for(var i=0; i<mb_mapObj[ind].styles.length;i++){
		mb_MapFutureObj[frameName][cnt].styles[i] = mb_mapObj[ind].styles[i];
	}
	mb_MapFutureObj[frameName][cnt].querylayers = new Array();
	for(var i=0; i<mb_mapObj[ind].querylayers.length;i++){
		mb_MapFutureObj[frameName][cnt].querylayers[i] = mb_mapObj[ind].querylayers[i];
	}
}var mod_measure_target = 'mapframe1';var mod_measure_color1 = "white";
var mod_measure_color2 = "black";
var mod_measure_font = "Arial, Helvetica, sans-serif";
var mod_measure_fontsize = "9px";
var mod_measure_basepoint = "#8a2be2";
var mod_measure_linepoint = "#ff00ff";
var mod_measure_bg = "";
var mod_measure_pgsql = true;

var mod_measure_win = null;

var mod_measure_elName = "measure";
var mod_measure_frameName = "";
var mod_measure_epsg;
var mod_measure_width;
var mod_measure_height;
var mod_measure_RX = new Array();
var mod_measure_RY = new Array();
var mod_measure_Dist = new Array();
var mod_measure_TotalDist = new Array();
var mod_measureSubFunctions = new Array();

var mod_measure_img_on = new Image(); mod_measure_img_on.src = "../img/button_gray/measure_on.png";
var mod_measure_img_off = new Image(); mod_measure_img_off.src = "../img/button_gray/measure_off.png";
var mod_measure_img_over = new Image(); mod_measure_img_over.src = "../img/button_gray/measure_over.png";

function init_mod_measure(ind){
	mb_button[ind] = document.getElementById(mod_measure_elName);
	mb_button[ind].img_over = mod_measure_img_over.src;
	mb_button[ind].img_on = mod_measure_img_on.src;
	mb_button[ind].img_off = mod_measure_img_off.src;
	mb_button[ind].status = 0;
	mb_button[ind].elName = mod_measure_elName;
	mb_button[ind].fName = mod_measure_frameName;
	mb_button[ind].go = new Function ("mod_measure_go()");
	mb_button[ind].stop = new Function ("mod_measure_disable()");
	var ind = getMapObjIndexByName(mod_measure_target);
	mod_measure_width = mb_mapObj[ind].width;
	mod_measure_height = mb_mapObj[ind].height;
	mod_measure_epsg = mb_mapObj[ind].epsg;
	mb_registerSubFunctions("drawDashedLine()");
	mb_registerPanSubElement("measuring");
}
function register_measureSubFunctions(stringFunction){
	mod_measureSubFunctions[mod_measureSubFunctions.length] = stringFunction;
}
function mod_measure_go(){
	var el = window.frames[mod_measure_target].document;
	el.onmousedown = mod_measure_start;
	el.onmousemove = mod_measure_run;
	var measureSub = "";
	for(var i=0; i<mod_measureSubFunctions.length; i++){
		measureSub += eval(mod_measureSubFunctions[i]);
	}   
	writeTag(mod_measure_target,"measure_sub",measureSub);
}
function mod_measure_disable(){
	var el = window.frames[mod_measure_target].document; 
	el.onmousedown = null;
	el.onmousemove = null;
	writeTag(mod_measure_target,"measure_display","");
	writeTag(mod_measure_target,"measure_sub","");
}
function mod_measure_timeout(){
	var el = window.frames[mod_measure_target].document; 
	el.onmousedown = null;
	el.ondblclick = null;
	el.onmousemove = null;
}
function mod_measure_disableTimeout(){
	var el = window.frames[mod_measure_target].document;
	el.onmousedown = mod_measure_start;
	el.onmousemove = mod_measure_run;
}
function mod_measure_start(e){
	mb_getMousePos(e,mod_measure_target);
	var realWorldPos = makeClickPos2RealWorldPos(mod_measure_target,clickX,clickY);
	if(mod_measure_epsg=="EPSG:4326"){
		mod_measure_RX[mod_measure_RX.length] = realWorldPos[0];
		mod_measure_RY[mod_measure_RY.length] = realWorldPos[1];
	}
	else{
		mod_measure_RX[mod_measure_RX.length] = Math.round(realWorldPos[0] * 100)/100;
		mod_measure_RY[mod_measure_RY.length] = Math.round(realWorldPos[1] * 100)/100;
	}
	if(mod_measure_RX.length > 1){
		var dist;
		if(mod_measure_epsg=="EPSG:4326"){
			//convert coordinates to radian
			var lon_from=(mod_measure_RX[mod_measure_RX.length-2]*Math.PI)/180;
			var lat_from=(mod_measure_RY[mod_measure_RY.length-2]*Math.PI)/180;
			var lon_to=(mod_measure_RX[mod_measure_RX.length-1]*Math.PI)/180;
			var lat_to=(mod_measure_RY[mod_measure_RY.length-1]*Math.PI)/180;
			dist=6371229*Math.acos(Math.sin(lat_from)*Math.sin(lat_to)+Math.cos(lat_from)*Math.cos(lat_to)*Math.cos(lon_from-lon_to));
			dist=Math.round(dist*100)/100;
		}
		else{
			var dist_x = Math.abs(mod_measure_RX[mod_measure_RX.length-2] - mod_measure_RX[mod_measure_RX.length-1]);
			var dist_y = Math.abs(mod_measure_RY[mod_measure_RY.length-2] - mod_measure_RY[mod_measure_RY.length-1]);
			dist = Math.round(Math.sqrt(Math.pow(dist_x,2) + Math.pow(dist_y,2))*100)/100;
		}
		mod_measure_Dist[mod_measure_Dist.length] = dist;
		var totalDist = mod_measure_TotalDist[mod_measure_TotalDist.length-1] + dist;
		mod_measure_TotalDist[mod_measure_TotalDist.length] = Math.round(totalDist * 100)/100;
	}
	else{
		mod_measure_Dist[mod_measure_Dist.length] = 0;
		mod_measure_TotalDist[mod_measure_TotalDist.length] = 0;
	}
	drawDashedLine();
}
function drawDashedLine(){
	var str_mPoints = "<div style='position:absolute;left:0px;top:0px' ><img src='"+mb_trans.src+"' width='"+mod_measure_width+"' height='0'></div>";
	str_mPoints += "<div style='position:absolute;left:0px;top:0px' ><img src='"+mb_trans.src+"' width='0' height='"+mod_measure_height+"'></div>";
	for(var i=0; i<mod_measure_RX.length; i++){
		var pos = makeRealWorld2mapPos(mod_measure_target,mod_measure_RX[i],mod_measure_RY[i]);
		str_mPoints += "<div style='font-size:1px;position:absolute;top:"+(pos[1]-2)+"px;left:"+(pos[0]-2)+"px;width:4px;height:4px;background-color:"+mod_measure_basepoint+"'></div>";
		if(i>0){
			str_mPoints += "<div  style='font-family:"+mod_measure_font+";font-size:"+mod_measure_fontsize+";color:"+mod_measure_color1+";";
			if(mod_measure_bg != ""){
				str_mPoints += "background-color:"+mod_measure_bg+";";
			}
			str_mPoints += "position:absolute;top:"+(pos[1] + 3)+"px;left:"+(pos[0]+3)+"px;z-index:20'>"+mod_measure_TotalDist[i]+"</div>";
			str_mPoints += "<div  style='font-family:"+mod_measure_font+";font-size:"+mod_measure_fontsize+";color:"+mod_measure_color2+";position:absolute;top:"+(pos[1] + 4)+"px;left:"+(pos[0]+4)+"px;z-index:21'>"+mod_measure_TotalDist[i]+"</div>";
		}
	}
	if(mod_measure_RX.length>1){
		for(var k=1; k<mod_measure_RX.length; k++){
			var pos0 = makeRealWorld2mapPos(mod_measure_target,mod_measure_RX[k], mod_measure_RY[k]);
			var pos1 = makeRealWorld2mapPos(mod_measure_target,mod_measure_RX[k-1], mod_measure_RY[k-1]);
			str_mPoints += evaluateDashes(pos1[0],pos1[1],pos0[0],pos0[1],k);
		}
	}
	writeTag(mod_measure_target,"measuring",str_mPoints);
}
function evaluateDashes(x1,y1,x2,y2,count){
	var str_dashedLine = "";
	var s = 10;
	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=1; i<n; i++){
		var x = Math.round(x1 + i * s_x)-2;
		var y = Math.round(y1 + i * s_y)-2;
		if(x >= 0 && x <= mod_measure_width && y >= 0 && y <= mod_measure_height){
			str_dashedLine += "<div style='font-size:1px;position:absolute;top:"+y+"px;left:"+x+"px;width:4px;height:4px;background-color:"+mod_measure_linepoint+"'></div>";
		}
	}
	str_dashedLine += "<div style='font-family:"+mod_measure_font+";font-size:"+mod_measure_fontsize+";color:"+mod_measure_color1+";";
	if(mod_measure_bg != ""){
		str_dashedLine += "background-color:"+mod_measure_bg+";";
	}   
	str_dashedLine += "position:absolute;top:"+(Math.round(y1 + (y2-y1)/2 +3))+"px;left:"+(Math.round(x1 + (x2-x1)/2 +3))+"px'>"+mod_measure_Dist[count]+"</div>";
	str_dashedLine += "<div style='font-family:"+mod_measure_font+";font-size:"+mod_measure_fontsize+";color:"+mod_measure_color2+";position:absolute;top:"+(Math.round(y1 + (y2-y1)/2 + 4))+"px;left:"+(Math.round(x1 + (x2-x1)/2+4))+"px'>"+mod_measure_Dist[count]+"</div>";
	return str_dashedLine;
}
function mod_measure_run(e){
	mb_getMousePos(e,mod_measure_target);
	var pos = makeClickPos2RealWorldPos(mod_measure_target,clickX,clickY);
	var dist;
	if(mod_measure_epsg=="EPSG:4326"){
		//convert coordinates to radian
		var lon_from=(pos[0]*Math.PI)/180;
		var lat_from=(pos[1]*Math.PI)/180;
		var lon_to=(mod_measure_RX[mod_measure_RX.length-1]*Math.PI)/180;
		var lat_to=(mod_measure_RY[mod_measure_RY.length-1]*Math.PI)/180;
		dist=6371229*Math.acos(Math.sin(lat_from)*Math.sin(lat_to)+Math.cos(lat_from)*Math.cos(lat_to)*Math.cos(lon_from-lon_to));
	}
	else{
		var dist_x = Math.abs(mod_measure_RX[mod_measure_RX.length-1] - pos[0]);
		var dist_y = Math.abs(mod_measure_RY[mod_measure_RY.length-1] - pos[1]);
		dist=Math.sqrt(dist_x*dist_x+dist_y*dist_y);
	}
	if(isNaN(dist) == false && clickX > 0 && clickX < mod_measure_width && clickY > 0 && clickY < mod_measure_height){
		var str_display = "<span style='font-family:"+mod_measure_font+";font-size:"+mod_measure_fontsize+";color:"+mod_measure_color2+";'>"+(Math.round(dist*100)/100)+" m</span>";
		writeTag(mod_measure_target,"measure_display",str_display);
		mb_arrangeElement(mod_measure_target,"measure_display",clickX +2, clickY - 10);
	}
	else{
		writeTag(mod_measure_target,"measure_display","");
	}
}
function mod_measure_close(){
	if(mod_measure_RX.length < 3 || (mod_measure_RX[mod_measure_RX.length-1] == mod_measure_RX[0] && mod_measure_RY[mod_measure_RY.length-1] == mod_measure_RY[0])){return;}
	mod_measure_RX[mod_measure_RX.length] = mod_measure_RX[0];
	mod_measure_RY[mod_measure_RY.length] = mod_measure_RY[0];
	if(mod_measure_RX.length > 1){
		var dist;
		if(mod_measure_epsg=="EPSG:4326"){
			//convert coordinates to radian
			var lon_from=(mod_measure_RX[mod_measure_RX.length-2]*Math.PI)/180;
			var lat_from=(mod_measure_RY[mod_measure_RY.length-2]*Math.PI)/180;
			var lon_to=(mod_measure_RX[mod_measure_RX.length-1]*Math.PI)/180;
			var lat_to=(mod_measure_RY[mod_measure_RY.length-1]*Math.PI)/180;
			dist=6371229*Math.acos(Math.sin(lat_from)*Math.sin(lat_to)+Math.cos(lat_from)*Math.cos(lat_to)*Math.cos(lon_from-lon_to));
			dist=Math.round(dist*100)/100;
		}
		else{
			var dist_x = Math.abs(mod_measure_RX[mod_measure_RX.length-2] - mod_measure_RX[mod_measure_RX.length-1]);
			var dist_y = Math.abs(mod_measure_RY[mod_measure_RY.length-2] - mod_measure_RY[mod_measure_RY.length-1]);
			dist = Math.round(Math.sqrt(Math.pow(dist_x,2) + Math.pow(dist_y,2))*100)/100;
		}
		mod_measure_Dist[mod_measure_Dist.length] = dist;
		var totalDist = mod_measure_TotalDist[mod_measure_TotalDist.length-1] + dist;
		mod_measure_TotalDist[mod_measure_TotalDist.length] = Math.round(totalDist * 100)/100;
	}
	else{
		mod_measure_Dist[mod_measure_Dist.length] = 0;
		mod_measure_TotalDist[mod_measure_TotalDist.length] = 0;
	}
	drawDashedLine();
}
function mod_measure_delete(){
	mod_measure_RX = new Array();
	mod_measure_RY = new Array();
	mod_measure_Dist = new Array();
	mod_measure_TotalDist = new Array();
	writeTag(mod_measure_target,"measuring","");
	writeTag(mod_measure_target,"measure_display","");
}var mod_pan_target = 'mapframe1';var mod_pan_elName = "pan1";
var mod_pan_frameName = "";


var mod_pan_img_on = new Image(); mod_pan_img_on.src = "../img/button_gray/pan_on.png";
var mod_pan_img_off = new Image(); mod_pan_img_off.src = "../img/button_gray/pan_off.png";
var mod_pan_img_over = new Image(); mod_pan_img_over.src = "../img/button_gray/pan_over.png";

function init_mod_pan(ind){
	mb_button[ind] = document.getElementById(mod_pan_elName);
	mb_button[ind].img_over = mod_pan_img_over.src;
	mb_button[ind].img_on = mod_pan_img_on.src;
	mb_button[ind].img_off = mod_pan_img_off.src;
	mb_button[ind].status = 0;
	mb_button[ind].elName = mod_pan_elName;
	mb_button[ind].fName = mod_pan_frameName;
	mb_button[ind].go = new Function ("mod_pan_click()");
	mb_button[ind].stop = new Function ("mod_pan_disable()");
}
function mod_pan_click(){   
	var el = window.frames[mod_pan_target].document; 
	el.onmousedown = mod_pan_start;
	el.onmouseup = mod_pan_stop;
	el.onmousemove = mod_pan_run;
}
function mod_pan_disable(){
	var el = window.frames[mod_pan_target].document; 
	el.onmousedown = null;
	el.onmouseup = null;
	el.onmousemove = null;
}
function mod_pan_start(e){
	mb_panActive = true;
	mb_getMousePos(e,mod_pan_target);
	mb_start_x=clickX;
	mb_start_y=clickY;
	mb_end_x = clickX;
	mb_end_y = clickY; 
	return false;
}
function mod_pan_run(e){
	if(mb_panActive){
		mb_getMousePos(e,mod_pan_target);
		mb_end_x = clickX;
		mb_end_y = clickY;
		mod_pan_move_map();
		if(ie){
			return false;
		}
		else{
			return true;
		}
	}
}
function mod_pan_stop(e){
	mb_panActive = false;
	var dif_x = mb_end_x - mb_start_x;
	var dif_y = mb_end_y - mb_start_y;
	for(var i=0; i<mb_mapObj.length; i++){
		if(mb_mapObj[i].frameName == mod_pan_target){
			var width = mb_mapObj[i].width;
			var height = mb_mapObj[i].height;      
		}
	} 
	var center_x = (width / 2)  - dif_x;
	var center_y = (height / 2) - dif_y;
	var real_center = makeClickPos2RealWorldPos(mod_pan_target,center_x, center_y);   
	mb_arrangeElement(mod_pan_target, "maps", 0, 0);
	for(var i=0; i<mb_PanSubElements.length; i++){
		mb_arrangeElement(mod_pan_target, mb_PanSubElements[i], 0, 0);
	}
   zoom(mod_pan_target,false, 1.0, real_center[0], real_center[1]);   
}
function mod_pan_move_map(){
	var dif_x = mb_end_x - mb_start_x;
	var dif_y = mb_end_y - mb_start_y;
	mb_arrangeElement(mod_pan_target, "maps", dif_x, dif_y);
	for(var i=0; i<mb_PanSubElements.length; i++){
		mb_arrangeElement(mod_pan_target, mb_PanSubElements[i], dif_x, dif_y);
	} 
	return false;  
}   var mod_zoomFull_img = new Image(); mod_zoomFull_img.src = "../img/button_gray/zoomFull_off.png";
   var mod_zoomFull_img_over = new Image(); mod_zoomFull_img_over.src = "../img/button_gray/zoomFull_over.png";

function mod_zoomFull(){
    var ind         = this.getMapObjIndexByName("mapframe1");		
		var arrayThemen = new Array();
		var arrayThemen = mb_mapObj[ind].wms[0].objLayer[0].layer_name;
		this.Layer0     = arrayThemen;
		//alert(mb_mapObj[ind].width + " - " + mb_mapObj[ind].height);
		this.width      = mb_mapObj[ind].width;
		this.height     = mb_mapObj[ind].height;
      this.epsg       = wms[0].gui_wms_epsg;
		//mb_mapObj[ind].epsg = "EPSG:31493";
    //alert(Layer0);
		var arrayExt = new Array();		
		var frameName = "mapframe1"
		var exts = setExtent(width,height,epsg);
		arrayExt = exts.split(",");
		
		mb_repaint(frameName,arrayExt[0],arrayExt[1],arrayExt[2],arrayExt[3]);
}

function mod_zoomFull_init(obj){
   document.getElementById("zoomFull").src = mod_zoomFull_img_over.src;
   obj.onmouseover = new Function("mod_zoomFull_over()");
   obj.onmouseout = new Function("mod_zoomFull_out()");
}
function mod_zoomFull_over(){
   document.getElementById("zoomFull").src = mod_zoomFull_img_over.src;
}
function mod_zoomFull_out(){
   document.getElementById("zoomFull").src = mod_zoomFull_img.src;
}



var mod_zoom1_img = new Image(); mod_zoom1_img.src = "../img/button_gray/zoomIn2_off.png";
var mod_zoom1_img_over = new Image(); mod_zoom1_img_over.src = "../img/button_gray/zoomIn2_over.png";


function mod_zoomIn1(){
	zoom("mapframe1", true,2.0);
}
function mod_zoomIn1_init(obj){
	document.getElementById("zoomIn1").src = mod_zoom1_img_over.src;
	obj.onmouseover = new Function("mod_zoomIn1_over()");
	obj.onmouseout = new Function("mod_zoomIn1_out()");
}
function mod_zoomIn1_over(){
	document.getElementById("zoomIn1").src = mod_zoom1_img_over.src;
}
function mod_zoomIn1_out(){
	document.getElementById("zoomIn1").src = mod_zoom1_img.src;
}
var mod_getArea_target = 'mapframe1';var mod_getArea_img = new Image();
mod_getArea_img.src = "../img/button_gray/getArea_off.gif";
register_measureSubFunctions("mod_getArea()");

function mod_getArea(){
	var str =  "<div style='position:absolute;top:50px' onmouseup='parent.mod_getArea_go()' ";
	str += "onmouseover='parent.mod_measure_timeout()' onmouseout='parent.mod_measure_disableTimeout()'><img src='"+mod_getArea_img.src+"'></div>";
	return str;
}
function mod_getArea_go(){
	if(mod_measure_RX[mod_measure_RX.length -1] == mod_measure_RX[0] && mod_measure_RY[mod_measure_RY.length -1] == mod_measure_RY[0]){
		var ind = getMapObjIndexByName(mod_getArea_target);
		var url = "../php/mod_evalArea.php?x=";
		for(var i=0; i<mod_measure_RX.length;i++){
			if(i>0){ url += ",";}
			url += mod_measure_RX[i];
		}
		url += "&y=";
		for(var i=0; i<mod_measure_RY.length;i++){
			if(i>0){ url += ",";}
			url += mod_measure_RY[i];
		}
		var srs = mb_mapObj[ind].epsg.split(":");
		url += "&srs="+ escape(srs[1]);
		url += "&length=" + mod_measure_TotalDist[mod_measure_TotalDist.length-1];
		url += "&distance="  + mod_measure_TotalDist[mod_measure_TotalDist.length-2];
		if(!mod_measure_win || mod_measure_win == null || mod_measure_win.closed == true){
			mod_measure_win = window.open(url,"mod_measure_win","width=200,height=150,resizable=yes");
		}
		else{
			mod_measure_win.document.location.href = url;
		}
		mod_measure_win.focus();
	}
	else{
		if(!mod_measure_win || mod_measure_win == null || mod_measure_win.closed == true){
			mod_measure_win = window.open("","mod_measure_win","width=200,height=150,resizable=yes");
			mod_measure_win.document.open("text/html");
			mod_measure_win.document.write("<span style = 'font-family : Arial, Helvetica, sans-serif;font-size : 12px;font-weight : bold;';>Strecke: " +mod_measure_TotalDist[mod_measure_TotalDist.length-1]+" m</span>");
			mod_measure_win.document.close();        
		}
		else{
			mod_measure_win.document.open("text/html");
			mod_measure_win.document.write("<span style = 'font-family : Arial, Helvetica, sans-serif;font-size : 12px;font-weight : bold;';>Strecke: " +mod_measure_TotalDist[mod_measure_TotalDist.length-1]+" m</span>");
			mod_measure_win.document.close();
		}
		mod_measure_win.focus();      
	}
}//$Id: mod_rubber.js 11 2006-07-31 16:22:36Z rothstein $
//$Header: /cvsroot/mapbender/mapbender/http/javascripts/mod_rubber.js,v 1.4 2005/09/13 14:38:11 bjoern_heuser Exp $
var mod_rubber_img = new Image();
mod_rubber_img.src = "../img/button_gray/rubber_off.gif";
register_measureSubFunctions("mod_rubber()");

function mod_rubber(){
   var str =  "<div onmouseup='parent.mod_rubber_go()' onmouseover='parent.mod_measure_timeout()' onmouseout='parent.mod_measure_go()'><img src='"+mod_rubber_img.src+"'></div>";
   return str;
}
function mod_rubber_go(){
   mod_measure_delete();
}var mod_closePolygon_img = new Image();
mod_closePolygon_img.src = "../img/button_gray/closePolygon_off.gif";
register_measureSubFunctions("mod_closePolygon()");
function mod_closePolygon(){
	var str =  "<div style='position:absolute;top:25px' onmouseup='parent.mod_closePolygon_go()' ";
	str += "onmouseover='parent.mod_measure_timeout()' onmouseout='parent.mod_measure_disableTimeout()'><img src='"+mod_closePolygon_img.src+"'></div>";
	return str;
}
function mod_closePolygon_go(){
	mod_measure_close();
}