var lyrArr;
var xmlReq=null;
var nodeNameEbenen;
var nodeNameThema;
var mMapLoaded;
var mTimer;

function CancelCurrentRequest(){
	if(xmlReq!=null)xmlReq.abort();
}

function StartApp() {
    mTimer = 0;
	SetSize();
	ShowQuickSearch('default');
	var mctlMainImg = GetMainImage();
	addEvent(mctlMainImg, 'load', hideProcessing, true);	
}

function GetLineChooserVal() {
	var f = document.Form1, i;
	
	if (f.LineChooser) {
	for (i = 0; i < f.LineChooser.length; i ++) {
      if (f.LineChooser[i].checked == true) {
         return f.LineChooser[i].value;
      }
	}
	}
	return false;
}
function GetLineColorChooserVal() {
	var f = document.Form1, i;
	
	if (f.LineColorChooser) {
	for (i = 0; i < f.LineColorChooser.length; i ++) {
      if (f.LineColorChooser[i].checked == true) {
         return f.LineColorChooser[i].value;
      }
	}
	}
	return false;
}

function GetAreaChooserVal() {
	var f = document.Form1, i;
	
	if (f.AreaChooser) {
	for (i = 0; i < f.AreaChooser.length; i ++) {
      if (f.AreaChooser[i].checked == true) {
         return f.AreaChooser[i].value;
      }
	}
	}
	return false;
}

function GetAreaColorChooserVal() {
	var f = document.Form1, i;
	
	if (f.AreaColorChooser) {
	for (i = 0; i < f.AreaColorChooser.length; i ++) {
      if (f.AreaColorChooser[i].checked == true) {
         return f.AreaColorChooser[i].value;
      }
	}
	}
	return false;
}

function GetSymbolChooserVal() {
	var f = document.Form1, i;
	
	if (f.SymbolChooser) {
	for (i = 0; i < f.SymbolChooser.length; i ++) {
      if (f.SymbolChooser[i].checked == true) {
         return f.SymbolChooser[i].value;
      }
	}
	}
	return false;
}

function GetSymbolColorChooserVal() {
	var f = document.Form1, i;
	
	if (f.SymbolColorChooser) {
	for (i = 0; i < f.SymbolColorChooser.length; i ++) {
		if (f.SymbolColorChooser[i].checked == true) {
			return f.SymbolColorChooser[i].value;
		}
	}
	}
	return false;
}

function GetFontChooserVal() {
	var f = document.Form1, i;
	
	if (f.FontChooser) {
	for (i = 0; i < f.FontChooser.length; i ++) {
      if (f.FontChooser[i].selected == true) {
         return f.FontChooser[i].value;
      }
	}
	}
	return false;
}

function GetFontColorChooserVal() {
	var f = document.Form1, i;
	
	if (f.FontColorChooser) {
	for (i = 0; i < f.FontColorChooser.length; i ++) {
		if (f.FontColorChooser[i].checked == true) {
			return f.FontColorChooser[i].value;
		}
	}
	}
	return false;
}

function GetFontFaceChooserVal() {
	var f = document.Form1, i;
	
	if (f.FontFaceChooser) {
	for (i = 0; i < f.FontFaceChooser.length; i ++) {
		if (f.FontFaceChooser[i].checked == true) {
			return f.FontFaceChooser[i].value;
		}
	}
	}
	return false;
}

function GetFontSizeChooserVal() {
	var f = document.Form1, i;
	
	if (f.FontSizeChooser) {
	for (i = 0; i < f.FontSizeChooser.length; i ++) {
		if (f.FontSizeChooser[i].checked == true) {
			return f.FontSizeChooser[i].value;
		}
	}
	}
	return false;
}

function chkWert(id) {
	if (document.getElementById(id) != null) {
		return document.getElementById(id).checked;
	} else if (document.getElementsByName(id) != null) {
		return document.getElementsByName(id).checked;
	}
	return false;
}

function getEncValue(id) {
	var val;
	val = getValue(id);
	return escape(val);
}

function getValue(id) {
	if (document.getElementById(id) != null) {
		return document.getElementById(id).value;
	}
}

function setValue(id, value) {
	if (document.getElementById(id) != null) {
		document.getElementById(id).value = value;
	}
}

function setInnerHTML(id, innerText) {
	if (document.getElementById(id) != null) {
		document.getElementById(id).innerHTML = innerText;
	} else if (parent.document.getElementById(id) != null) {
		parent.document.getElementById(id).innerHTML = innerText;	
	}
}

function GetControl(id) {
	if (document.getElementById(id) != null) {
		return document.getElementById(id);
	} else {
		if (parent.document.getElementById(id) != null) {
			return parent.document.getElementById(id);
		}		
	}	
}

function GetVisibility(divName) {
	if (document.getElementById(divName) != null) {
		return document.getElementById(divName).style.visibility;
	} else {
		if (parent.document.getElementById(divName) != null) {
			return parent.document.getElementById(divName).style.visibility;
		}		
	}	
}

function GetHeight(divName) {
	var height;
	height = 0;
	if (GetVisibility(divName) == "visible") {
		if (document.getElementById(divName) != null) {
		  height=document.getElementById(divName).style.height.replace("px","");
		} else {
		  height=parent.document.getElementById(divName).style.height.replace("px","");
		}
	}
	return height;
}

function GetWidth(divName) {
	if (GetVisibility(divName) == "visible") {
		if (document.getElementById(divName) != null) {
		  return document.getElementById(divName).style.width;
		} else {
		  return parent.document.getElementById(divName).style.width;
		}
	}
	return 0;
}

function ShowDiv(divName, width, height) {		
	if (document.getElementById(divName) != null) {
		document.getElementById(divName).style.visibility = "visible";
		document.getElementById(divName).style.zIndex="150";
		if (width) {
			document.getElementById(divName).style.width=width;	
		}
		if (height) {
			document.getElementById(divName).style.height=height;		
		}
	} else {
		ShowParentDiv(divName);
	}
}

function ShowParentDiv(divName) {
	if (parent.document.getElementById(divName) != null) {
		parent.document.getElementById(divName).style.visibility = "visible";
		parent.document.getElementById(divName).style.zIndex="150";
	}
}

function CloseDiv(divName) {
	if (document.getElementById(divName) != null) {
		document.getElementById(divName).style.visibility = "hidden";
		document.getElementById(divName).style.zIndex="10";
		SetCookie(divName, "hidden", 1);
	} else {
		CloseParentDiv(divName);
	}
}

function CloseParentDiv(divName) {
	if (parent.document.getElementById(divName) != null) {
		parent.document.getElementById(divName).style.visibility = "hidden";
		parent.document.getElementById(divName).style.zIndex="10";
		SetCookie(divName, "hidden", 1);
	}
}

function ShowAdvCosmToolbar(divName) {		
	SwitchDivVisibility(divName);
}

function SwitchDivVisibility(divName) {
	var status;
	
	status = GetCookie(divName);
	if (status != null) {
		if (status == "visible") {
			document.getElementById(divName).style.visibility="hidden";
			document.getElementById(divName).style.zIndex="10";
			SetCookie(divName, "hidden", 1);
		}
		else {
			document.getElementById(divName).style.visibility="visible";
			document.getElementById(divName).style.zIndex="150";
			SetCookie(divName, "visible", 1);
		}
	} else {
		if (document.getElementById(divName).style.visibility == "visible") {
			document.getElementById(divName).style.visibility="hidden";
			document.getElementById(divName).style.zIndex="10";
			SetCookie(divName, "hidden", 1);
		}
		else {
			document.getElementById(divName).style.visibility="visible";
			document.getElementById(divName).style.zIndex="150";
			SetCookie(divName, "visible", 1);
		}
	}
}

function SetDivVisibilityFromCookie(divName) {
	var status;
	
	status = GetCookie(divName);
	if (status != null) {
		document.getElementById(divName).style.visibility = status;
	}
}

function ShowCosmeticLayerToolbar() {
	if (document.getElementById("divCosmeticLayerToolbar").style.visibility == "visible") {
		document.getElementById("divCosmeticLayerToolbar").style.visibility="hidden";
		SetCookie("divCosmeticLayerToolbar", "hidden", 1);
		CloseRotateObj();
	}
	else {
	    document.getElementById("divCosmeticLayerToolbar").style.width=25;
	    //document.getElementById("divCosmeticLayerToolbar").style.height=25;
		document.getElementById("divCosmeticLayerToolbar").style.visibility="visible";
		SetCookie("divCosmeticLayerToolbar", "visible", 1);
	}	
}

function SetCookie(name, value, days, path) {
    if(!days) days = -1;
    if(!path) path = '/';

    var expire = new Date();
    expire.setTime(expire.getTime() + 86400000 * days);

    document.cookie = name + "=" + escape(value)
    //+  "; expires=" + expire.toGMTString() + ";"
    + ";"
    + path
    ;
}


function GetCookie(name) {
    var c = new Object();
    var i = 0;
    var clen = document.cookie.length;
    while (i < clen)
    {
         var endstr = document.cookie.indexOf (";", i);
         if (endstr == -1) endstr = document.cookie.length;

         var v = unescape(document.cookie.substring(i, endstr));
         var key = v.substring(0, v.indexOf("=", 0));
         var val = v.substring(v.indexOf("=") + 1);
         c[key] = val;
         i = endstr + 2; // Leerzeichen nach ; überspringen
    }
    if(name) return c[name];
    return c;
}

function OpenKarteiKarte(urlString){
	//Add code to handle your event here.
	var url, name;
	var urlArr = urlString.split("|");
	url=urlArr[0];
	name=urlArr[1];
	g=window.open(url,name,'width=700,height=500,status=yes,scrollbars=yes,resizable=yes,dependent=yes,location=center');
	if (g.opener == null) g.opener=self; g.focus();
}

function ICAfterSelectChangeHandler(gn){
	var g=igtbl_getGridById(gn);
	
	if(g.ReadyState!=0)
		return;
		
	//.DataKey geht nur im IE
	//var dataKey=g.oActiveRow.DataKey;
	var dataKey=g.oActiveRow.get("lit:DataKey");
	
	g.ReadyState=g.eReadyState.Loading;
			
	if(ig_csom.IsIE) {
		g.XmlHttp.open("POST", g.Url, false);
		g.XmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		g.XmlHttp.onreadystatechange=new Function("igtbl_onReadyStateChange('"+g.Id+"')");
		g.XmlHttp.send("__EVENTTARGET="+g.UniqueID+"&__EVENTARGUMENT=XmlHttpRequest&ActiveDataKey="+dataKey+"&Index="+g.oActiveRow.getIndex());
	} else {
		g.XmlHttp.open("POST",g.Url,false);
		g.XmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		g.XmlHttp.igtbl_currentGrid=g.Id;
		g.XmlHttp.addEventListener("load",igtbl_onReadyStateChange,false);
		g.XmlHttp.send("__EVENTTARGET="+g.UniqueID+"&__EVENTARGUMENT=XmlHttpRequest&ActiveDataKey="+dataKey+"&Index="+g.oActiveRow.getIndex());
	}
	
	location.href=location.href;
	ShowFeature(false);
}

function ICAfterSelectedTabChange(id, url){
	var o=igtab_all[id];
	xmlReq=getXmlHTTP();
	
	xmlReq.open("POST", url, false);
	xmlReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlReq.send("SelectedTab="+o.selected);
}

function GetOverviewImg() {
	if (document.getElementById("mctlOverView_Image") != null) {
		return document.getElementById("mctlOverView_Image");
	} else {
		return parent.document.getElementById("mctlOverView_Image");
	}	
}

function GetMainImageOpener() {
	if (opener.document.getElementById("mctlMainView_Image") != null) {		
		return opener.document.getElementById("mctlMainView_Image");
	} else {
		return opener.parent.document.getElementById("mctlMainView_Image");
	}
}

function GetMainImage() {
	if (document.getElementById("mctlMainView_Image") != null) {
		return document.getElementById("mctlMainView_Image");
	} else {
		return parent.document.getElementById("mctlMainView_Image");
	}	
}

function ShowInfoPickerSearchResult() {	
	var xmlHttp = CreateXMLHttp();
	var msg;
	
	showProcessing();
	
	var url = "GeoASController.aspx?Command=CheckSearchInfo"+
		"&MapAlias=MainView" + 
		"&R=" + Math.random();
	xmlHttp.open("GET", url, false);
	xmlHttp.send(null);
	msg = xmlHttp.responseText;

	if (msg == "0") {
	  CloseWarning();
	  ShowSearchResultPopUp();
	} else if (msg == "1") {
	  CloseWarning();
	  ShowSearchResultFrame();
	//} else {
	//  CloseSearchResult();
	//  ShowWarning(msg);
	}
}

function ShowKarteikartePopUp() {

}

function ShowKarteikarteFrame() {
	ShowDiv('divSearchResultDocking');
}

function ShowSearchResultPopUp() {	
	window.open('searchResult.aspx');
}

function ShowSearchResultFrame() {	
	var iFrame;
	var mctlMainImg = GetMainImage();
	
	iFrame = "<iframe style='HEIGHT: 100%;' frameborder='no' width='100%' src='searchResult.aspx'></iframe>";
	setInnerHTML('divSearchResultContent', iFrame);
	var div = FindElement("divSearchResultDocking");
	
	if(navigator.appName == 'Netscape') {
		div.style.width = mctlMainImg.width-3+"px";
		div.style.height= "287px";
	} else {
		div.style.width = mctlMainImg.width+"px";
		div.style.height= "280px";
	}
	ShowDiv('divSearchResultDocking');
	CloseAdvSearch();
	ReLoadMainView();
}

function ShowMeasureResult() {
	var res;
	
	if(mTimer<=6){
	  if(mMapLoaded == true) {
	    mTimer=0;
	    res=GetGeoASController('GetMeasureResult');
	    setInnerHTML('divMeasureResult', res);
	    var div = GetControl('divMeasureResult');
	    div.style.visibility = "visible";
	    div.style.zIndex="150";
	    var top = GetMapHeight() - 50;
	    div.style.top= top+"px";
	  } else {
	    mTimer++;
	    setTimeout("ShowMeasureResult()", 500); 
	  } //if(mMapLoaded == true)
	} //if(mTimer<=6)
}

function ShowSearchResult() {
	var iFrame;
	var xmlHttp = CreateXMLHttp();
	var val1, val2, val3;
	var msg;
	
	showProcessing();
	val1 = getValue('txt0');
	val2 = getValue('txt1');
	val3 = getValue('txt2');
	
	var valArr = val1+"|"+val2+"|"+val3;
	
	var url = "GeoASController.aspx?Command=SetSearchInfo"+
		"&MapAlias=MainView" + 
		"&Value=Frame" + 
		"&valArr=" + valArr + 
		"&R=" + Math.random();
	xmlHttp.open("GET", url, false);
	xmlHttp.send(null);
	msg = xmlHttp.responseText;

	if (msg == "0") {
	  CloseWarning();
	  ShowSearchResultPopUp();
	} else if (msg == "1") {
	  CloseWarning();
	  ShowSearchResultFrame();
	} else {
	  ShowWarning(msg);
	  CloseDiv("processing");
	}
}

function ShowWarning(msg) {
	CancelCurrentRequest();
	setInnerHTML('divWarningContent', msg);
	ShowDiv('divWarning');
}

function CloseWarning() {
	setInnerHTML('divWarningContent', '');
	CloseDiv('divWarning');
}

function ReLoadMainView2(){
	showProcessing();
	var mctlMainImg = GetMainImageOpener();
	try {
	var url = "MapCommand.aspx?Command=Reload"+ 
		"&MapAlias=MainView" + 
		"&Width=" + mctlMainImg.width +
		"&Height=" + mctlMainImg.height +
		"&ExportFormat=" + mctlMainImg.exportFormat +
		"&Left=0"+
		"&Top=0"+
		"&Right="+ mctlMainImg.width +
		"&Bottom="+ mctlMainImg.height +
		"&R=" + Math.random();
	mctlMainImg.src = url;
	} catch(e) {  }
}

function ReLoadMainView() {
	SetMapCommand('Reload');
}

function ReLoadOverView() {
	var mctlOver = GetOverviewImg();

	try {
	if (!mctlOver.mapAlias) mctlOver.mapAlias = mctlOver.attributes["mapAlias"].value;
	if (!mctlOver.exportFormat) mctlOver.exportFormat = mctlOver.attributes["exportFormat"].value;
	var url = "MapCommand.aspx?Command=Reload"+ 
		"&MapAlias=" + mctlOver.mapAlias + 
		"&Width=" + mctlOver.width +
		"&Height=" + mctlOver.height +
		"&ExportFormat=" + mctlOver.exportFormat +
		"&Left=0"+
		"&Top=0"+
		"&Right="+ mctlOver.width +
		"&Bottom="+ mctlOver.height +
		"&R=" + Math.random();

	mctlOver.src = url;
	} catch(e) { }
}

function ShowHotLink() {
	var httpReq=getXmlHTTP();
	var url = "GeoASController.aspx?Command=GetHotLinkURL"+
		"&R=" + Math.random();
	
	httpReq.onreadystatechange=function(){
		if(httpReq.readyState==4){
			var resText;
			resText=httpReq.responseText;
			if (resText != "False") {
				window.open(resText);
			}			
		}
	}
	
	httpReq.open("GET", url);
	httpReq.send(null);	
}

function ShowFeatStyleText() {
	mapCmdDrawTextTool.Activate();
	ShowDiv('divFeatureStyleText');	
}

function GetFeatStyle() {
	CloseDrawLegacyText();
	ShowFeatStyleDiv('GetFeatStyle');
}

function ShowFeatStyle() {
	CloseDrawLegacyText();
	if (navigator.appName == 'Netscape') {
		ShowDiv('divFeatureStyleEdit',null,null);
	} else {
		ShowDiv('divFeatureStyleEdit',200,100);
	}
}

function ShowFeatStyleDiv(cmd) {
	xmlReq = CreateXMLHttp();
    
	CancelCurrentRequest();
	CloseWarning();
	var url = "GeoASController.aspx?Command="+ cmd +
		"&MapAlias=MainView" + 
		"&R=" + Math.random();
	
	xmlReq.onreadystatechange=function() {
		if(xmlReq.readyState==4){
		if (xmlReq.status == "200") {
			setInnerHTML('divFeatureStyle', xmlReq.responseText);
			
			if (navigator.appName == 'Netscape') {
				ShowDiv('divFeatureStyle',null,null);
			} else {
				ShowDiv('divFeatureStyle',200,100);
			}			
		}
		}
	}
	xmlReq.open("GET", url);
	xmlReq.send(null);
}

function ShowFeatStyleError() {
	var errMsg = "Die Daten konnten nicht nachgeladen werden.";
	ShowWarning(errMsg);
}

function SaveFeatStyle() {
	SetFeatStyle('SaveFeatStyle');
}

function SaveFeatTextStyle() {
	SetFeatStyle('SaveFeatTextStyle');
}

function ApplyFeatStyle() {
	SetFeatStyle('ApplyFeatStyle');
	ReLoadMainView();
}

function SelectWert(name) {
	var rObj;
    rObj=document.getElementById(name);
	  
    if (rObj) {
      return rObj.options.value;
	}
    return false;
}

function ChooserWert(name, count) {
	var rObj;
	var docID;
	for (var i=0; i<count; i++) {
	  docID = name+'_'+i;
	  rObj=document.getElementById(docID);
	  if (rObj) {
	    if (rObj.checked) return rObj.value;
	  }
	}
    return false;
}
		
function SetFeatStyle(cmd) {
	xmlReq=getXmlHTTP();
	var val1, val2, val3, val4, val5, val6, valStr;
	
	if (cmd == "ApplyFeatStyle") {
		val1=GetLineChooserVal();
		if (val1 == false || val1 == undefined) {
			val1=GetFontChooserVal();
			if (val1 == false || val1 == undefined) {
				val1 = "&SymbolChooser="+GetSymbolChooserVal();
				val2 = "&SymbolColorChooser="+GetSymbolColorChooserVal();
				valStr = val1+val2;
			} else {
				val1 = "&FontChooser="+val1;
				val2 = "&FontColorChooser="+GetFontColorChooserVal();
				val3 = "&FontFaceChooser="+GetFontFaceChooserVal();
				val4 = "&FontSizeChooser="+GetFontSizeChooserVal();
				val5 = "&BBox="+chkWert('chkTextBox');			
				val6 = "&Value="+getEncValue('txtFontText');
				valStr = val1+val2+val3+val4+val5+val6;
			}
		} else {
			val1 = "&LineChooser="+val1;	
			val2 = "&LineColorChooser="+GetLineColorChooserVal();
			val3 = "&AreaChooser="+GetAreaChooserVal();
			val4 = "&AreaColorChooser="+GetAreaColorChooserVal();
			valStr = val1+val2+val3+val4;
		}
	} else {
		val1 = "&LineChooser="+ChooserWert('FeatureStyle_LineChooser',8);
		val2 = "&LineColorChooser="+ChooserWert('FeatureStyle_LineColorChooser',4);
		val3 = "&AreaChooser="+ChooserWert('FeatureStyle_AreaChooser',8);
		val4 = "&AreaColorChooser="+ChooserWert('FeatureStyle_AreaColorChooser',4);
		val5 = "&SymbolChooser="+ChooserWert('FeatureStyle_SymbolChooser',8);
		val6 = "&SymbolColorChooser="+ChooserWert('FeatureStyle_SymbolColorChooser',4);
		if (cmd == "SaveFeatStyle") {
			var val7, val8;
			val7 = "&Snapping="+chkWert('FeatureStyle_chkSnapping');
			val8 = "&Combine="+chkWert('FeatureStyle_chkCombine');
			valStr = val1+val2+val3+val4+val5+val6+val7+val8;
		} else {
		valStr = val1+val2+val3+val4+val5+val6;
		}
	}
	
	var url = "GeoASController.aspx?Command="+ cmd +
		valStr+
		"&MapAlias=MainView" + 
		"&R=" + Math.random();
	xmlReq.open("GET", url, false);
	xmlReq.send(null);
	CloseDiv('divFeatureStyle');
	CloseDiv('divFeatureStyleEdit');
}

function ShowObjectInfo() {
	if(mTimer<=6){
	  if(mMapLoaded == true) {
	    mTimer=0;
	    
		var httpReq=getXmlHTTP();
		var url = "GeoASController.aspx?Command=GetObjectInfo"+
		  "&MapAlias=MainView" + 
		  "&R=" + Math.random();
		httpReq.onreadystatechange=function(){
		  if(httpReq.readyState==4){
		    setInnerHTML('divObjectInfo', httpReq.responseText);
		    
		    if (navigator.appName == 'Netscape') {
		      ShowDiv('divObjectInfo',null,null);
		    } else {
		      ShowDiv('divObjectInfo',null,'100');
		    }
		  }
		}
		
		httpReq.open("GET", url);
		httpReq.send(null);
	  } else {
	    mTimer++;
	    setTimeout("ShowObjectInfo()", 500); 
	  } //if(mMapLoaded == true)
	} //if(mTimer<=3)	
}

function ShowPrintDataSettings() {
	var div = GetControl('divTempContent');
	div.style.height = 80;
	div.style.width = 300;
	ShowDivTemp('printDataSettings.aspx');
}

function ShowDivTemp(tarUrl) {
	var iFrame;
	
	iFrame = "<iframe id='frmTemp' style='HEIGHT: 100%' WIDTH='100%' frameborder='no' src='"+tarUrl+"'></iframe>";
	setInnerHTML('divTempContent', iFrame);
	ShowDiv('divTemp');
}

function CloseDivTemp() {
	setInnerHTML('divTempContent', '');
	CloseDiv('divTemp');
}

function SetAdvSearchHeader(msg) {
	setInnerHTML('advSearch', msg);
}

function ShowAdvSearch() {
	CloseWarning();
	var iFrame;
	
	iFrame = "<iframe id='advSearch' style='HEIGHT: 100%' WIDTH='100%' frameborder='no' src='advSearch.aspx'></iframe>";
	setInnerHTML('divSearchContent', iFrame);
	ShowDiv('divSearch');
}

function CloseAdvSearch(){
	setInnerHTML('divSearchContent', '');
	CloseDiv('divSearch');
}

function ShowQuickSearch(node) {
	var httpReq=getXmlHTTP();

	var url = "GeoASController.aspx?Command=GetQuickSearch"+
		"&Value=" + node + 
		"&MapAlias=MainView" + 
		"&R=" + Math.random();		
		
	httpReq.onreadystatechange=function(){
		if(httpReq.readyState==4){
			if (httpReq.responseText != "False") {
				setInnerHTML('divQuickSearch', httpReq.responseText);						
				ShowDiv('divQuickSearch');
				SetGroupControlSize();
			}
		}
	}
	httpReq.open("GET", url);
	httpReq.send(null);
}

function CloseQuickSearch() {
	setInnerHTML('divQuickSearch', '');
	CloseDiv('divQuickSearch');
	var grpCtrl = GetControl('divGroupControl');
	grpCtrl.style.height = GetBrowserHeight() - 175;	//175 = Hoehe Overview + Hoehe Kopfzeile + Platz
}

function ClosePrintSettings() {
	setInnerHTML('divPrintSettingsContent', '');
	CloseDiv('divPrintSettings');
}

function ShowPrintSettings() {
	var iFrame;
	var frameHeight;
	
	if (navigator.appName == 'Netscape') {
		frameHeight = 390;
	} else {
		frameHeight = 350;
	}		
	
	iFrame = "<iframe style='HEIGHT: " + frameHeight + "px;' frameborder='no' width='100%' src='printsettings.aspx'></iframe>";		
	setInnerHTML('divPrintSettingsContent', iFrame);
	ShowDiv('divPrintSettings');
}

function UpdateLayerArray() {
	var res;
	res=GetGeoASController('GetLayers');
	lyrArr=res.split(";");
}

function GetLayerVisibility(grpName, lyrAlias){
	var i;
	var tmpArr;
	for(i=0;i<lyrArr.length;i++) {
		tmpArr=lyrArr[i].split("|");
		if (tmpArr[0]==grpName && tmpArr[1]==lyrAlias) {
			return tmpArr;
		}
	}
}

function UpdateLayers() {
	UpdateLayerArray();
	var treeID = "GroupControl1tvGruppen";
	var nodeID;
	var tree=igtree_getTreeById(treeID);
	var grpNodes;
	grpNodes=tree.getNodes();
	var i;
	for(i=1;i<=grpNodes.length;i++) {
		nodeID=treeID+"_"+i;
		var node=igtree_getNodeById(nodeID);
		node.setEnabled(true);
		var node = igtree_getElementById(nodeID);
		var title = node.getAttribute("Title");
		UpdateLayer(nodeID, title);		
	}
}

function CheckNode(nodeID) {
	var node=igtree_getNodeById(nodeID);
	node.setChecked(true);
}

function ParentNodeIsLyrMain(nodeName) {
	if (!nodeNameEbenen) {
		nodeNameEbenen = GetGeoASController('GetLayerGroupNodeName');
	}
	if (nodeName == nodeNameEbenen) return true
	else return false
}

function ParentNodeIsThmMain(nodeName) {
	if (!nodeNameThema) {
		nodeNameThema = GetGeoASController('GetLayerThemeNodeName');
	}
	if (nodeName == nodeNameThema) return true
	else return false
}

function Trim (str) {
	return str.replace (/^\s+|\s+$/g,'');
}

function UpdateLayer(nodeID, lyrName) {
	var node=igtree_getNodeById(nodeID);
	var parent=node.getParent();
	if(parent != null) {
		var grpName;
		var tmpNode = igtree_getElementById(parent.Id);
		var title = tmpNode.getAttribute("Title");
		grpName=Trim(title.split(":")[1]);
		var src=igtree_getNodeSpan(igtree_getElementById(nodeID));
		var nodeName;
		if(igtree_IE)
			nodeName=src.innerText;
		else
			nodeName=src.innerHTML;			
		if ((ParentNodeIsLyrMain(nodeName)==true) || (ParentNodeIsThmMain(nodeName)==true)) {
			var nodes;
			nodes=node.getChildNodes();
			var i;
			var	tmpID;
			for(i=1;i<=nodes.length;i++) {
				var res;
				var cssClass;
				var enable;
				tmpID=nodeID+"_"+i;
				var tmpNode=igtree_getNodeById(tmpID);
				if (parent.getChecked() == false){
					tmpNode.setEnabled(false);
					cssClass="LayerNode";
				} else {
				var title;
				title=tmpNode.getText()
				res = GetLayerVisibility(grpName, title);
				if (res) {
					if (res[2]=="True") {	//Enabled
						tmpNode.setEnabled(true);
						cssClass="LayerNodeVisible";
						if (res[3]=="True") {	//Visible
							tmpNode.setChecked(true);
						}
					} else {
						tmpNode.setEnabled(false);
						cssClass="LayerNode";
					}
				}				
				}
				tmpNode.setClass(cssClass);
			}			
		}
	} else {
		var nodes;
		nodes=node.getChildNodes();
		var i;
		var	tmpID;
		for(i=1;i<=nodes.length;i++) {
			tmpID=nodeID+"_"+i;
			var tmpNode = igtree_getElementById(tmpID);
			var title = tmpNode.getAttribute("Title");
			UpdateLayer(tmpID, title);	
		}
	}
}

function hideProcessing() {
	mMapLoaded = false;
	SetMapImgSize();
	CloseDiv("processing");
	setMapZoom();
	mMapLoaded = true;
}

function showProcessing() {
    mMapLoaded = false;
	ShowDiv("processing");	
}

function HandleSubmit() {
	return false;
	if(navigator.appName == 'Netscape') {
		return TasteGedruecktNetscape();
	} else {
		return TasteGedruecktIE();
	}
}

function TasteGedruecktNetscape(Ereignis){
	if (Ereignis.which == 13) {
		ShowSearchResult();
		return false;	
	}
}

function TasteGedruecktIE(){
	if (window.event.keyCode == 13) {
		ShowSearchResult();
		return false;
	}
}

function ChangeNode(nodeId, enable) {
	var node=igtree_getNodeById(nodeId);
	var parent=node.getParent();
	var parentName;
	if (parent != null) {
		parentName = parent.getText();
		var grp;
		var grpName;
		grp=parent.getParent();
		if (grp != null) {
			grpName = grp.getText();
		}
	}
	ChangeLayer(node.getText(), parentName, grpName, enable);
}

function ChangeLayer(lyrName, parentName, grpName, enable) {
	showProcessing();
	var mctlMainImg = GetMainImage();
	try {
	
	var url = "MapCommand.aspx?Command=LayerVisibility"+ 
		"&MapAlias=MainView" + 
		"&LayerAlias=" + lyrName +
		"&ParentAlias=" + parentName +
		"&GrpAlias=" + grpName +
		"&Visible=" + enable +
		"&Width=" + mctlMainImg.width +
		"&Height=" + mctlMainImg.height +
		"&ExportFormat=" + mctlMainImg.exportFormat +
		"&Left=0"+
		"&Top=0"+
		"&Right="+ mctlMainImg.width +
		"&Bottom="+ mctlMainImg.height +
		"&R=" + Math.random();
		
	mctlMainImg.src = url;
	} catch(e) {  }
}

function setMapZoom() {
	var mapZoom;
	var httpReq=getXmlHTTP();
	
	var url = "MapCommand.aspx?Command=GetHTML"+
		"&Typ=MapZoom" + 
		"&MapAlias=MainView" + 
		"&R=" + Math.random();
	
	httpReq.onreadystatechange=function(){
		if(httpReq.readyState==4){			
			mapZoom = httpReq.responseText;
			setValue('txtScale',mapZoom);
			UpdateLayers();
		}
	}

	httpReq.open("GET", url);
	httpReq.send(null);
}

function IsZahl(value) {
    if ((value==null) || (value=="")) {
		return false;
	}

	var num = value.match(/[^0-9,\.]/gi);
	var dot = value.match(/\./g);
    var com = value.match(/,/g);
    
    if (num!=null) {
		return false;
    } else if ((dot!=null)&&(dot.length>1)) {
        return false;
    } else if ((com!=null)&&(com.length>1)) {
        return false;
    }
    return true;
}

function CloseSearchResult() {
	CloseDiv('divSearchResultDocking');
	ReLoadMainView();
}

function CloseDrawLegacyText() {
	if (mapCmdDrawTextTool.active == true) {
		mapCmdDrawTextTool.Deactivate();
	}
	CloseDiv('divFeatureStyleText');
}

function CloseRotateObj() {
	var img=GetControl('imgRotateObject');
	img.src = "Images/btnRotate.gif";
	if (mapCmdRotObjTool.active == true) {
		mapCmdRotObjTool.Deactivate();
	}
	CloseDiv('divRotateObject');
}

function ShowRotateObj() {
	if (mapCmdRotObjTool.active == true) {
		CloseRotateObj();
	} else {
		var sel = GetGeoASController('CosmLyrHasSelection');
		mapCmdRotObjTool.Activate();
		if (sel == "True") {
			mapCmdRotObjTool.Deactivate();
			ShowDiv('divRotateObject');
		} else {
			var img=GetControl('imgRotateObject');
			img.src = "Images/btnRotate_pressed.gif"
		}
	}
}

function RotateObject(val) {
	var angle = getValue('txtRotate');

	if (IsZahl(angle) == true) {
		var val1 = angle+"&Rot="+val;
		SetMapCommand('RotateFeature',val1);
	} else {
		ShowNoNumber();
	}
}

function ChangeFeature() {
	var val1, val2;
	val1 = getValue('txtValue1');
	val2 = getValue('txtValue2');
	if ((IsZahl(val1) == false) || (IsZahl(val2) == false))  {
		ShowNoNumber();
	} else {
		CloseWarning();
		SetMapCommand('ChangeFeature',val1+"_"+val2);
		CloseDiv('divObjectInfo');
	}
}

function zoomTo() {
	var zoom;
	zoom = getValue('txtScale');
	if (IsZahl(zoom) == true) {
		SetMapCommand('ZoomTo',zoom);
	} else {
		ShowNoNumber();
	}
}

function ShowLegend(url) {
	var img = GetControl('imgLegend');
	img.src = url;	
	ShowDiv('divLegend',100,50);
}

function ShowFeature(all) {
	SetMapCommand('ShowFeature',all);
}

function LastView() {
	SetMapCommand('LastView');
	ReLoadOverView();
}

function NextView() {
	SetMapCommand('NextView');
	ReLoadOverView();
}

function Deselect() {
	SetMapCommand('Deselect');
}

function ZoomAll() {
	SetMapCommand('ZoomAll');
	ReLoadOverView();
}

function GetGeoASController(action, value) {
	var httpReq=getXmlHTTP();
	
	var url = "GeoASController.aspx?Command="+ action +
		"&Value=" + value +
		"&MapAlias=MainView" + 
		"&R=" + Math.random();

	httpReq.open("GET", url, false);
	httpReq.send(null);
	return httpReq.responseText;
}

function SetMapCommand(action, value) {
	showProcessing();
	var mctlMainImg = GetMainImage();
	
	var height = GetMapHeight();

	if (mctlMainImg == null) {
		mctlMainImg = GetMainImageOpener();
		height = mctlMainImg.height;
	}

	try {
	var url = "MapCommand.aspx?Command="+ action +
		"&Value=" + value +
		"&MapAlias=MainView" + 
		"&Width=" + mctlMainImg.width +
		"&Height=" + height +
		"&ExportFormat=" + mctlMainImg.exportFormat +
		"&Left=0"+
		"&Top=0"+
		"&Right="+ mctlMainImg.width +
		"&Bottom="+ mctlMainImg.height +
		"&R=" + Math.random();
	
	mctlMainImg.src = url;
	} catch(e) { }
}

//Get XMLHTTP for IE or Mozilla
function getXmlHTTP(){
	//if (xmlReq!=null) return xmlReq;
	if(typeof XMLHttpRequest!="undefined"){
		return new XMLHttpRequest();
	}
	else if(typeof ActiveXObject != "undefined")
	{
		try{
			var xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
			return xmlhttp;
		}
		catch(e)
		{
			return null;
		}
	}
	return null;
}

function addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be attached");
  }
}

function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
} 

function encode_utf8(rohtext) {
     // dient der Normalisierung des Zeilenumbruchs
     rohtext = rohtext.replace(/\r\n/g,"\n");
     var utftext = "";
     for(var n=0; n<rohtext.length; n++)
         {
         // ermitteln des Unicodes des  aktuellen Zeichens
         var c=rohtext.charCodeAt(n);
         // alle Zeichen von 0-127 => 1byte
         if (c<128)
             utftext += String.fromCharCode(c);
         // alle Zeichen von 127 bis 2047 => 2byte
         else if((c>127) && (c<2048)) {
             utftext += String.fromCharCode((c>>6)|192);
             utftext += String.fromCharCode((c&63)|128);}
         // alle Zeichen von 2048 bis 66536 => 3byte
         else {
             utftext += String.fromCharCode((c>>12)|224);
             utftext += String.fromCharCode(((c>>6)&63)|128);
             utftext += String.fromCharCode((c&63)|128);}
         }
     return utftext;
 }
