// Applikations-Funktionen für OSIRIS
// CV, 10.07.2004, GIS Consult GmbH
var standard_query_win=null;
var standard_query_result_win=null;
var sql_query_win=null;
var sql_result_win=null;
var cb_query_win=null;
var cb_result_win=null;
var select_win=null;
var selection_list_win=null;
var station_win=null;
var profile_win=null;
var infowin_win=null;
var overview_win=null;
var stadtplan_win=null;
var searchmap_win=null;
var config_win=null;
var layer_options_win=null;
var layer_win=null;
var help_win=null;
var legend_win=null;
var plot_win=null;
var message_win=null;
var wms_config_win=null;
var browser_windows = new Array();
var tbw_win=null;
var druck_win = null;
var coord_win=null;
var worlds_win=null;
var wroads_win = null;
var EditorWin = null;
var ProjectWin = null;
var gps_win = null;
var olc_win = null;

// -----------------------------------------------------------------------------------
// Funktion beim Beenden der Applikation: close_all_views()
// -----------------------------------------------------------------------------------
function close_all_views() {
	// Wird beim Schließen der Head-Seite aufgerufen.
	// Dadurch werden automatisch die Übersicht, der Stadplan,
	// die Konfiguration sowie sämtliche Browser-Fenster beendet.
	if (layer_win != null) {
		layer_win.close();
	}
	if (overview_win != null) {
		overview_win.close();
	}
	if (stadtplan_win != null) {
		stadtplan_win.close();
	}
	if (searchmap_win != null) {
		searchmap_win.close();
	}
	if (sql_query_win != null) {
		sql_query_win.close();
	}
	if (sql_result_win != null) {
		sql_result_win.close();
	}
	if (cb_query_win != null) {
		cb_query_win.close();
	}
	if (cb_result_win != null) {
		cb_result_win.close();
	}
	if (help_win != null) {
		help_win.close();
	}
	if (legend_win != null) {
		legend_win.close();
	}
	if (plot_win != null) {
		plot_win.close();
	}
	if (message_win != null) {
		message_win.close();
	}
	if (select_win != null) {
		select_win.close();
	}
	if (selection_list_win != null) {
		selection_list_win.close();
	}
	if (station_win != null) {
		station_win.close();
	}
	if (profile_win != null) {
		profile_win.close();
	}
	if (infowin_win != null) {
		infowin_win.close();
	}
	if (wms_config_win != null) {
		wms_config_win.close();
	}
	if (layer_options_win != null) {
		layer_options_win.close();
	}
	if (tbw_win != null) {
		tbw_win.close();
	}
	if (coord_win != null) {
		coord_win.close();
	}
	if (wroads_win != null) {
		wroads_win.close();
	}
	if (standard_query_win != null) {
		standard_query_win.close();
	}
	if (standard_query_result_win != null) {
		standard_query_result_win.close();
	}
	for (var i=0; i<browser_windows.length;i++) {
		if (browser_windows[i] != null) {
			browser_windows[i].close();
		}
	}
        if (EditorWin != null) {
            EditorWin.close();
        }
	if (ProjectWin != null) {
            ProjectWin.close();
        }
        if (druck_win != null) {
            druck_win.close();
        }
        if (coord_win != null) {
		coord_win.close();
	}
	if (worlds_win != null) {
		worlds_win.close();
	}

	if (gps_win != null) {
		gps_win.close();
	}
	
	if (olc_win != null) {
        	olc_win.close();
    	}

	for (var i=0; i<browser_windows.length;i++) {
		if (browser_windows[i] != null) {
			browser_windows[i].close();
		}
	}

	close_config();
}
// -----------------------------------------------------------------------------------
// Funktionen für die Übersicht, die Ortsuche sowie den Stadtplan
// -----------------------------------------------------------------------------------
function start_overview(){
	// Diese Funktion öffnet ein Overview-Fenster,
	// falls es noch keins gibt. Aufgerufen wird sie
	// als Callback des verborgenen Buttons "startOverview"
	// auf dem Head-Frame (Head.html)

	if (parent.frameTab != null) {
		var div1 = parent.frameTab.document.getElementById("OsirisTab");
		var t = div1.tabber;
		
		for (var i=0; i < parent.frameTab.frames.length; i++) {
			if (parent.frameTab.frames[i].frameOverview != null) {
				t.tabShow(i);
				parent.frameTab.frames[i].page_selected();
				return;	
			}	
			if (parent.frameTab.frames[i].frameSearchMap != null) {
				t.tabShow(i);
				parent.frameTab.frames[i].page_selected();
				return;	
			}
		}
	}
	
	overview_win = open("Overview.jsp","overview_win",
		"width=375,height=375,dependent=yes,directories=no,location=no" +
		",menubar=no,resizable=yes,scrollbars=no,status=yes,toolbar=no");
	overview_win.focus();
}
function starte_ortsuche(topic,category){
	// Diese Funktion öffnet die Ortsuche, falls es
	// das Fenster noch nicht gibt

	if (document.getElementById("Searchmode") != null) {
		if (! topic)
			document.getElementById("Searchmode").value="";
		else {
			var str = topic;
			if (category != null && category != "") 
				str = topic + "|" + category;
			document.getElementById("Searchmode").value=str;
		}
	}
	
	if (parent.frameTab != null && parent.frameTab.ortsuche_frame != null) {
		var div1 = parent.frameTab.document.getElementById("OsirisTab");
		var div2 = parent.frameTab.document.getElementById("ortsuche");
		var t = div1.tabber;

		var tab = null;
		for (var i=0; i < t.tabs.length; i++) {
			if (t.tabs[i].div == div2) {
				t.tabShow(i);
			}
		}
		parent.frameTab.ortsuche_frame.page_selected();
		return;	
	}

	// Ortsuche mit oder ohne Suchmaske?
	var use_searchmap = document.getElementById("use_searchmap").value;
	if (use_searchmap == "true") {
		searchmap_win = open("Ortsuche.html","searchmap_win",
			"width=550,height=600,dependent=yes,directories=no,location=no" +
			",menubar=no,resizable=yes,scrollbars=no,status=yes,toolbar=no");
	}
	else {
		searchmap_win = open("Searchframe.jsp","searchmap_win",
			"width=550,height=400,dependent=yes,directories=no,location=no" +
			",menubar=no,resizable=yes,scrollbars=no,status=yes,toolbar=no");
	}
	searchmap_win.focus();
}
function start_citysearch(topic){
	// Diese Funktion öffnet die Ortsuche, falls es
	// das Fenster noch nicht gibt
	starte_ortsuche();
}
function start_stadtplan(){
	// Diese Funktion öffnet ein Stadtplan-Fenster,
	// falls es noch keins gibt. Aufgerufen wird sie
	// als Callback des verborgenen Buttons "startStadtplan"
	// auf dem Head-Frame (Head.html)

	stadtplan_win = open("Stadtplan.jsp","stadtplan_win",
		"width=530,height=550,dependent=yes,directories=no,location=no" +
		",menubar=no,resizable=yes,scrollbars=no,status=yes,toolbar=no");
	stadtplan_win.focus();
}
// -----------------------------------------------------------------------------------
// Funktionen zur Behandlung der Konfiguration (Optionsfenster):
// activate_view_configuration(),view_config(),close_config()
// -----------------------------------------------------------------------------------
function activate_view_configuration(){
	// Oeffnet das Fenster zur Konfiguration der Maps
	parent.frameMap.document.RequestForm.viewConfig.click();
}
function view_config(){
	// Diese Funktion öffnet das Options-Fenster,
	// falls es noch keins gibt.
	var ival = "";
	if (document.RequestForm.infowin_option != null) 
		ival = document.RequestForm.infowin_option.value;

	var cmd = "Options.jsp"
		+ "?FORMAT=" + document.RequestForm.format.value 
		+ "&SRS=" + document.RequestForm.srs.value 
		+ "&TRANSPARENT=" + document.RequestForm.transparent.value 
		+ "&DISTORTION=" + document.RequestForm.distortion.value 
		+ "&BGCOLOR=" + document.RequestForm.bgcolor.value 
		+ "&GC!MAP_PARAMS=" + document.RequestForm.additional_map_params.value
		+ "&INFOWIN_OPTION=" + ival
		+ "&SW!SHOW_SCALE=" + document.RequestForm.show_scale.value
		+ "&SW!SHOW_DISPLAY_SCALE=" + document.RequestForm.show_display_scale.value
		+ "&SW!DISPLAY_SCALE=" + document.RequestForm.display_scale.value
		+ "&AUTOREFRESH=" + document.RequestForm.autorefresh.value
		+ "&STARTMODE=" + document.RequestForm.startmode.value
		+ "&LAYER_VISMODE=" + document.RequestForm.layer_vismode.value
		+ "&CLOSE_OBJECTLIST=" + document.HiddenForm.close_objectlist.value
		+ "&USE_SEARCHMAP=" + document.HiddenForm.use_searchmap.value
		+ "&";
		
		config_win = open(cmd,"config_win","width=480,height=265,dependent=yes,"
		+ "directories=no,location=no,menubar=no,resizable=yes," 
		+ "scrollbars=auto,status=yes,toolbar=no");
	config_win.focus();
}
function close_config() {
	// Wird beim Schließen der Map-Seite aufgerufen.
	// Dadurch wird automatisch die Übersicht mit beendet.
	if (config_win != null) {
		config_win.close();
	}
}
// -----------------------------------------------------------------------------------
// Funktionen für die WMS-Konfiguration
// -----------------------------------------------------------------------------------
function open_wms_config_win() {
	// Diese Funktion öffnet das WMS-Konfigurations-Fenster,
	// falls es noch keins gibt.
	wms_config_win = open("WMSConfig.jsp","wms_config_win","width=750,height=550,dependent=yes,"
		+ "directories=no,location=no,menubar=no,resizable=yes," 
		+ "scrollbars=auto,status=yes,toolbar=no");
	wms_config_win.focus();
}
// -----------------------------------------------------------------------------------
// Funktionen für den Umgang mit dem Browser bzw. zusätzlichen
// Browser-Fenstern
// -----------------------------------------------------------------------------------
function start_new_browser() {
	// Startet einen neuen Browser.
	// Dies ist ein Callback aus den HTML-Seiten, wenn
	// der versteckte Button "startBrowser" betätigt wird.
	// An dieser Stelle wird nun zunächst geprüft, ob
	// die Anwendung einen Browser besitzt. Ist dies der
	// Fall, und ist der Modus des Browser nicht auf
	// Mehrfenster-Modus eingestellt, wird der bestehende 
	// Browser benutzt.

	var Request = document.getElementById("BrowserRequest").value;
	
	// Haben wir einen "fest installierten" Browser der alten Oberfläche?
	var obj = parent.frameData;

	if (! obj) {
		// Eventuell haben wir einen Browser in einem Tabulator:
		if (parent.frameTab != null && parent.frameTab.browser_frame != null) {
			obj = parent.frameTab.browser_frame.frameData;
			// Den Tabulator aktualisieren:
			var tab = parent.frameTab.document.getElementById("OsirisTab").tabber;
			for (var i=0; i < parent.frameTab.frames.length; i++) {
				if (parent.frameTab.frames[i] == obj.parent)
					tab.tabShow(i);
			}
		}
	}
		
	if (obj == null) {
	    // Kein fester Bereich für Objektinformationen.
	    // Deshalb separates Fenster (select_win) benutzen.
	    if (select_win == null || select_win.closed == true) {
		    // Es existiert noch kein Browser-Fenster.
		    // Deshalb eines öffnen:
	    	    select_win = open("Browser_window.html","select_win",
			"width=375,height=500,dependent=yes,directories=no,location=no" +
			",menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no");
		    select_win.focus();
		    return;
	    }
	    // Es existiert ein separates Fenster. Dann kann dort der
	    // Request abgeladen werden, falls es im Single-Mode ist
	    if (select_win.frameIcons.document.getElementById("window_mode") == null ||
	    	select_win.frameIcons.document.getElementById("window_mode").value.indexOf("multi_win") == -1) {
		    
	    	document.getElementById("BrowserRequest").value=Request;
	        select_win.frameData.location.href = "EmptyObject.html";
		select_win.focus();
	    	return;
	    }
	}
	else {
		// Das bestehende Fenster kann genutzt werden, falls kein
		// Multi-Windows-Mode
		if (obj.parent.frameIcons.document.getElementById("window_mode") == null ||
	    	    obj.parent.frameIcons.document.getElementById("window_mode").value.indexOf("multi_win") == -1) {
	
		    obj.parent.frameIcons.document.getElementById("actualCmd").value = Request;
    		    obj.location.href= "EmptyObject.html";
		    return false;
		}
	}
	// Wenn wir hier angekommen sind, bedeutet das,
	// dass ein neues Browser-Fenster gestartet werden muss.
	var win;
	var win = open("Browser_window.html","",
			"width=375,height=500,dependent=yes,directories=no,location=no" +
			",menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no");
	win.focus();
	browser_windows[browser_windows.length] = win;
}
// -----------------------------------------------------------------------------------
// Funktionen für den Umgang mit Abfragen
// -----------------------------------------------------------------------------------
function activate_sql_query(){
	// Gibt den Aufruf des SQL-Windows weiter.
	// Wird nur benötigt, wenn die SQL-Abfrage nicht
	// aus dem Kartenfenster gestartet wird.
	parent.frameMap.document.HiddenForm.startSQL.click();
}
function open_sql_win() {
	// Startet das SQL-Fenster.
	var Request = "../GCGisService?Request=GetCollectionNames"
		+ "&EXCEPTIONS=text/html"
		+ "&STYLESHEET=html/SQLQuery.xsl&";
	
	sql_query_win = open(Request,"SQLWin",
			"width=450,height=320,dependent=yes,directories=no,location=no" +
			",menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no");
	sql_query_win.focus();
}
function open_sql_result() {
	// Startet ein Fenster für die Ergebnisse der SQL-Abfrage.
	sql_result_win = open("EmptySQLResult.html","SQLResult",
			"width=600,height=350,dependent=yes,directories=no,location=no" +
			",menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=no");
	sql_result_win.focus();
}
function open_wfs_client() {
	open("../wfsclient/index.jsp","WFSClient");
}
// -----------------------------------------------------------------------------------
// Funktionen für den Umgang mit der Standardabfrage
// -----------------------------------------------------------------------------------
function activate_standard_queries(){
	// Gibt den Aufruf der Standardabfragen weiter
	// Wird nur benötigt, wenn die Standardabfrage nicht
	// aus dem Kartenfenster gestartet wird.
	parent.frameMap.document.HiddenForm.startQuery.click();
}
function open_query_win(queryToStart) {
	// Aktiviert die Standardabfrage

	if (queryToStart == null)
		queryToStart = "";
	document.getElementById("queryToStart").value = queryToStart;

	if (parent.frameTab != null && parent.frameTab.standard_query_frame != null) {
		parent.frameTab.activate_tab("standard_query_mode");
		standard_query_win = parent.frameTab.standard_query_frame;
		
		// evtl. Queries nachladen
		var page = standard_query_win.document.location.href;
		if (page.indexOf("Blank.html") != -1 || queryToStart != "") {
			var Request = "../GCGisService?Request=GetQueries"
				+ "&EXCEPTIONS=text/html"
				+ "&STYLESHEET=html/StandardQuery.xsl&";
			parent.frameTab.standard_query_frame.document.location.href = Request;
		}

		// allg. Objektsuche schließen
		if (parent.frameTab != null && parent.frameTab.object_query_frame != null) {
			try {
				parent.frameTab.deactivate_tab("object_query_mode");
			} catch(err) {}
			cb_query_win = null; 
		}
		return;	
	}

	var Request = "../GCGisService?Request=GetQueries"
		+ "&EXCEPTIONS=text/html"
		+ "&STYLESHEET=html/StandardQuery.xsl&";
	
	standard_query_win = open(Request,"QueryWin",
			"width=500,height=550,dependent=yes,directories=no,location=no" +
			",menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no");
	standard_query_win.focus();
}
function open_query_result() {
	// Startet ein Fenster für die Ergebnisse der Standardabfrage.

	standard_query_result_win = open("html/EmptyQueryResult.html","QueryResult",
		"width=600,height=375,dependent=yes,directories=no,location=no" +
		",menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=no");
	standard_query_result_win.focus();
}
// -----------------------------------------------------------------------------------
// Funktionen für den Umgang mit der Objektabfrage
// -----------------------------------------------------------------------------------
function activate_collection_browser(){
	// Gibt den Aufruf der Objektabfrage weiter
	// Wird nur benötigt, wenn die Objektabfrage nicht
	// aus dem Kartenfenster gestartet wird.
	parent.frameMap.document.HiddenForm.startCB.click();
}
function open_cb_win() {
	// Aktiviert die Objektabfrage

	if (parent.frameTab != null && parent.frameTab.object_query_frame != null) {
		parent.frameTab.activate_tab("object_query_mode");
		cb_query_win = parent.frameTab.object_query_frame;
		
		// evtl. Queries nachladen
		var page = cb_query_win.document.location.href;
		if (page.indexOf("Blank.html") != -1) {
			var Request = "../GCGisService?Request=GetCollectionNames"
				+ "&EXCEPTIONS=text/html"
				+ "&STYLESHEET=html/ClassBrowser.xsl&";	
			cb_query_win.document.location.href = Request;
		}

		// Standardabfragen schließen
		if (parent.frameTab != null && parent.frameTab.standard_query_frame != null) {
			try {
				parent.frameTab.deactivate_tab("standard_query_mode");
			} catch(err) {}
			standard_query_win = null; 
		}
		
		// DB und Tabelle setzen (falls vorhanden)
		var db = get_application().HiddenForm.CBDatabase.value;
		var coll = get_application().HiddenForm.CBCollection.value;
		try {
		    if (db != "" && coll != "") {
    		    var selDB = cb_query_win.document.getElementById("DatabaseNames");
    		    var selColl = cb_query_win.document.getElementById("Collections");
    	        for (var i = 0; i < selDB.options.length; i++) {
    	           if (selDB.options[i].text.toLowerCase() == db.toLowerCase()) {
                        selDB.selectedIndex = i;
                        break;
                   }
    	        }
    	        for (var i = 0; i < selColl.options.length; i++) {
    	           if (selColl.options[i].text.toLowerCase() == coll.toLowerCase()) {
                        selColl.selectedIndex = i;
                        break;
                   }
    	        }
        		selColl.onchange();
    		}
		}
		catch (err) {}
		
		return;	
	}
	
	var Request = "../GCGisService?Request=GetCollectionNames"
		+ "&EXCEPTIONS=text/html"
		+ "&STYLESHEET=html/ClassBrowser.xsl&";

	cb_query_win = open(Request,"CBWin",
			"width=450,height=450,dependent=yes,directories=no,location=no" +
			",menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no");
	cb_query_win.focus();
}
function open_cb_result() {
	// Startet ein Fenster für die Ergebnisse der Objektabfrage.
	cb_result_win = open("html/EmptyCBResult.html","CBResult",
			"width=600,height=375,dependent=yes,directories=no,location=no" +
			",menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=no");
	cb_result_win.focus();
}
// -----------------------------------------------------------------------------------
// Funktionen für Legende, Hilfe, ausgewählte Objekte
// -----------------------------------------------------------------------------------
function open_help_window(help_page) {
	// Öffnet das Hilfefenster

	var src = document.location.href.split("/html/")[0];
	var page = src + "/Hilfe/html/Hilfe.jsp";
	
	if (! help_page || help_page == "")
		help_page = "Hilfe-Hauptfenster.jsp";
	
	if (help_page.indexOf("html/") >= 0)
		help_page = help_page.split("html/")[1];

	help_win = open(page + "?help_page=" + help_page,"Help",
		"width=800,height=650,dependent=yes,directories=no,location=no" +
		",menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no");
	help_win.focus();
}
function open_legend_window() {
	// Öffnet das Legendenfenster

	var static_legend = false;
	var functions = document.getElementById("extra_functions").value;
	if (functions.indexOf("#/#OSIRIS!static_legend#/#") != -1)
		static_legend = true;

	if (parent.frameTab != null && parent.frameTab.legend_frame != null && parent.frameTab.legend_frame.frameLegend != null) {
		var div1 = parent.frameTab.document.getElementById("OsirisTab");
		var div2 = parent.frameTab.document.getElementById("legend");
		var t = div1.tabber;

		var tab = null;
		for (var i=0; i < t.tabs.length; i++) {
			if (t.tabs[i].div == div2) {
				t.tabShow(i);
			}
		}
		parent.frameTab.legend_frame.page_selected();
		return;	
	}

	// Block für statische Legenden:
	if (static_legend == true) {
		var visl = document.RequestForm.visible_layers.value;
		legend_win = open("../Legende/Legende.jsp?layers="+visl,"Legende",
			"width=400,height=600,dependent=yes,directories=no,location=no" +
			",menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no");
		legend_win.focus();
		return;
	}

	var wd = 400;
	var ht = 600;
	var wd2 = wd - 30;
	var ht2 = ht - 30;
	legend_win = open("../html/Legende.jsp?legend_width=" + wd2 + "&legend_height=" + ht2,
		"Legende","width=" + wd + ",height=" + ht + 
		",dependent=yes,directories=no,location=no" +
		",menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no");
	legend_win.focus();
}
function show_map_selection() {
	// Öffnet ein Fenster, das die aktuelle Objektauswahl zeigt
	var src = document.location.href.split("/html/")[0];
	var page = src + "/html/SelectionList.jsp";
	
	if (src.indexOf("/html/") >= 0)
	 	  page = "../" + page;
	selection_list_win = open(page,"selection_list_win",
				"width=500,height=375,dependent=yes,directories=no,location=no" +
				",menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no");
	selection_list_win.focus();
}
// -----------------------------------------------------------------------------------
// Funktionen für das Plotten
// -----------------------------------------------------------------------------------
function open_plot_window() {
	// Öffnet das Plot-Fenster
	
	if (parent.frameTab != null && parent.frameTab.plot_frame != null) {
		parent.frameTab.activate_tab("plot_mode");
		plot_win = parent.frameTab.plot_frame;
		plot_win.check_plot_window();
		return;	
	}

	plot_win = open("Plotting.jsp","plot_win",
		"width=375,height=400,dependent=yes,directories=no,location=no" +
		",menubar=no,resizable=yes,scrollbars=no,status=yes,toolbar=no");

	plot_win.focus();
}
// -----------------------------------------------------------------------------------
// Funktionen für das GPS-Tracking
// -----------------------------------------------------------------------------------
function open_gps_window() {
	// Öffnet das GPS-Fenster
	
	if (parent.frameTab != null && parent.frameTab.gps_frame != null) {
		parent.frameTab.activate_tab("gps_mode");
		gps_win = parent.frameTab.gps_frame;
		gps_win.page_selected();
		return;	
	}

	gps_win = open("GPS.jsp","gps_win",
		"width=375,height=400,dependent=yes,directories=no,location=no" +
		",menubar=no,resizable=yes,scrollbars=no,status=yes,toolbar=no");
	gps_win.focus();
}
// -----------------------------------------------------------------------------------
// Funktionen für das Infofenster und SIB Bauwerke
// -----------------------------------------------------------------------------------
function open_infowin() {
	// Öffnet ein zusätzliches Fenster für das Infofenster
	var w = 250;
	var h = 300;
	
	var option = document.RequestForm.infowin_option.value;
	var visLayers = document.RequestForm.visible_infowin_layers.value;
	if (infowin_win == null || infowin_win.closed) 
		infowin_win = open("Infofenster.jsp?INFOWIN_OPTION=" + option + "&INFOWIN_LAYERS=" + visLayers,"infowin",
				"width=" + w + ",height=" + h + ",dependent=no,directories=no,location=no"
				+ ",menubar=no,resizable=yes,scrollbars=no,status=yes,toolbar=no");	
	infowin_win.focus();
}
function do_start_sibbw() {
	// SB 07.01.2004
	// Öffnet ein Fenster zur Ausgabe des Bauwerksübersichtsblattes 
	set_cursor("wait","Aktiv");

	var bwnr = window.document.getElementById("BuildingRequest").value;	

	tbw_win = open("Bauwerke.html?TBWNR="+bwnr+"&","tbw_win",
			"width=550,height=600,dependent=yes,directories=no,location=no" +
			",menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no");
	tbw_win.status = "Teilbauwerk "+bwnr;
	tbw_win.focus();
}
// -----------------------------------------------------------------------------------
// weitere Map-Funktionen: home_bounds(), overview_bounds(), refresh_bounds()
//         sowie die Suchfunktionen search_parcel() und search_building()
// -----------------------------------------------------------------------------------
function home_bounds(){
	// Callback für den Home-Button
	if (home_bnds != null)
		document.RequestForm.bounds.value = home_bnds;
	else 
		document.RequestForm.bounds.value = "VIEW:default";

	document.RequestForm.operation.value = "VIEW:default";
	document.RequestForm.layers.value = "SW!ACE";
	document.RequestForm.GetMap.click();
}
function overview_bounds(){
	// Lädt die Übersicht

	document.RequestForm.bounds.value = document.RequestForm.application_bounds.value;
	document.RequestForm.operation.value = "ZOOM";
	document.RequestForm.layers.value = "SW!ACE";
	document.RequestForm.GetMap.click();
}
function refresh_bounds(){
	// Callback für den Refresh-Button
	document.RequestForm.operation.value = "refresh";
	document.RequestForm.GetMap.click();
}

// -----------------------------------------------------------------------------------
// Funktionen für den JPEG-Druck
// -----------------------------------------------------------------------------------
function UmwandelnRequest(req) {
    var repl = req.replace(/\?/gi,"!§!");
    repl = repl.replace(/\&/gi,"!§§!");
    repl = repl.replace(/\=/gi,"!§§§!");
    return repl
}
function Drucke() {
        var wms = false;
        if (document.getElementById("BGWMSDef").value != "" ||
    	document.getElementById("FGWMSDef").value != "")
            wms = true;
	
        druck_win = open("Loading_JPEG_Print.jsp?wms="+ wms,"druck_win",
			"width=450,height=320,dependent=yes,directories=no,location=no" +
			",menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=no");
    druck_win.focus();
}
function DoDrucke() {
       
       var MapRequests = getMapRequests();
       if (MapRequests == null) 
            return;
       var bg = MapRequests[0];
       var gis = MapRequests[1];
       var fg = MapRequests[2];
       
       //var repl = gis.replace(/\?/gi,"!§!");
       //repl = repl.replace(/\&/gi,"!§§!");
       //repl = repl.replace(/\=/gi,"!§§§!");
       var count = 1;
       var Request = "../GCImageService?";
       for (var i=0;i<bg.length;i++) {
            if (bg[i] == null)
                continue;
            var current = UmwandelnRequest(bg[i]);
            Request += "B-REQUEST"+count+"="+current+"&";
            count += 1;
       }
       // Jetzt GIS
       //var current = UmwandelnRequest(gis);
       Request +=gis;
       //Request += "REQUEST"+count+"="+"http://services.gis-consult.de/"+current+"&";
       count = 1;
       // Jetzt Vordergrund
       for (var i=0;i<fg.length;i++) {
            if (fg[i] == null)
                continue;
            var current = UmwandelnRequest(fg[i]);
            Request += "V-REQUEST"+count+"="+current+"&";
            count += 1;
       }
       
        //alert(Request);
        set_cursor("wait","Aktiv...");
	druck_win = open(Request,"druck_win",
			"width=450,height=320,dependent=yes,directories=no,location=no" +
			",menubar=yes,resizable=yes,scrollbars=yes,status=yes,toolbar=no");
	druck_win.focus();
        window.setTimeout("set_cursor('default','OK');",2000); 
}
// -----------------------------------------------------------------------------------
// Funktionen für den Umgang mit Editoren
// -----------------------------------------------------------------------------------
function OpenEditor(fid,src)
{
	// Öffnet einen Editor für ein konkretes Objekt,
	// dessen fid übergeben wird.
	try {
	    if (! src) src = document.location.href;
	    var srs = document.getElementById("srs").value;
	    var Call = "editors/WFSeditor.jsp";
	    var add_layers = null;
	    
	    // prüfen, ob ein spezieller Editor verwendet werden soll
	    // TABLE aus FID extrahieren
	    var table = fid.split(".")[0] + "." + fid.split(".")[1];
	    for (var i = 0; i < wfs_editors.length; i++) {
	        if (wfs_editors[i][0] == table && wfs_editors[i][3] != "") {
	            Call = "editors/" + wfs_editors[i][3];
	        }
		if (wfs_editors[i][0] == table && wfs_editors[i].length > 5) {
		    add_layers = wfs_editors[i][5];
		}
	    }
    
	    if (src.indexOf("/notizen/") >= 0)
	 	  Call = "../" + Call;

	    if (src.indexOf("/html/") >= 0 || src.indexOf("/editors/") >= 0)
	 	  Call = "../" + Call;
   
	       Call += "?object="+fid+"&srs=" + srs;

	    if (parent.frameTab != null && parent.frameTab.editor_frame != null) {
	    	parent.frameTab.activate_tab("editor_mode");
	    	EditorWin = parent.frameTab.editor_frame;
	    	
	    	EditorWin.location.href = Call;
		if (add_layers != null)
			ensure_layer_vis(add_layers);
	    	return;	
	    }

	    if (EditorWin != null && !EditorWin.closed) {
	    	EditorWin.location.href = Call;

	    } else {
	        EditorWin = open(Call,"EditorWin",
			"width=500,height=750,dependent=yes,directories=no,location=no" +
			",menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no");
	    }
	    EditorWin.focus();

	    if (add_layers != null)
			ensure_layer_vis(add_layers);
	    	
	} catch(er) {
		// Fehler: Dann warten und erneut aufrufen:
		setTimeout("OpenEditor('" + fid + "')",200);
	}
}
function open_notiz_editor(startup_action, src) {
    // Diese Methode öffnet den Notizeditor mit einer StartupAction 
    // (bislang nur: erzeugeNotiz)
    
    if (!src || src == null) src = document.location.href;
    
    // Tabelle
    var table = "osiris.osiris_notiz";
    var wfs_editors = get_application_window().wfs_editors;
    var add_layers = null;
	    
    for (var i = 0; i < wfs_editors.length; i++) {
        if (wfs_editors[i][0].indexOf("osiris_notiz") >= 0){
            table = wfs_editors[i][0];
	    if (wfs_editors[i].length > 5)
			add_layers = wfs_editors[i][5];
            break;
        }
    }
    
    var Call = "../editors/Notizeditor.jsp";
    var srs = document.getElementById("srs").value;

    if (src.indexOf("/notizen/") >= 0) {
        Call = "../Notizeditor.jsp";
    }
    
    Call += "?table="+table+"&srs="+srs;
    if (startup_action != null) {
        Call += "&startupAction=" + startup_action;
    }
    
    if (parent.frameTab != null && parent.frameTab.editor_frame != null) {
    	parent.frameTab.activate_tab("editor_mode");
    	EditorWin = parent.frameTab.editor_frame;
    	EditorWin.location.href = Call;
    	if (add_layers != null)
		ensure_layer_vis(add_layers);
	return;	
    }
    
    EditorWin = open(Call,"EditorWin",
		        "width=500,height=750,dependent=yes,directories=no,location=no" +
		        ",menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no");
    EditorWin.focus();
    if (add_layers != null)
	ensure_layer_vis(add_layers);
	    	
}

function open_object_editor(table) {
    // Diese Methode öffnet den WFS-Editor.
    // Der Aufruf erfolgt aus dem Pulldown-Menu für einen
    // leeren Editor heraus.
    var srs = document.getElementById("srs").value;    
    var Call = "../editors/WFSeditor.jsp";
    var add_layers = null;
	    
    // prüfen, ob ein spezieller Editor verwendet werden soll
    for (var i = 0; i < wfs_editors.length; i++) {
        if (wfs_editors[i][0] == table && wfs_editors[i][3] != "") {
            Call = "../editors/" + wfs_editors[i][3];
        }
	if (wfs_editors[i][0] == table && wfs_editors[i].length > 5) {
	    add_layers = wfs_editors[i][5];
	}
    }
    Call += "?table="+table+"&srs="+srs;
    
    if (parent.frameTab != null && parent.frameTab.editor_frame != null) {
    	parent.frameTab.activate_tab("editor_mode");
    	EditorWin = parent.frameTab.editor_frame;
    	EditorWin.location.href = Call;
	if (add_layers != null)
		ensure_layer_vis(add_layers);
	    	
    	return;	
    }
    
    EditorWin = open(Call,"EditorWin",
		        "width=500,height=750,dependent=yes,directories=no,location=no" +
		        ",menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no");
    EditorWin.focus();
    if (add_layers != null)
	ensure_layer_vis(add_layers);
	    	
}
function OpenEditorTemplate(table,filter,src)
{
	try {
	    if (! src) src = document.location.href;
	    var srs = document.getElementById("srs").value;
	    var Call = "editors/WFSeditor.jsp";
	    var add_layers = null;
	    
	    // prüfen, ob ein spezieller Editor verwendet werden soll
	    // TABLE aus FID extrahieren
	    for (var i = 0; i < wfs_editors.length; i++) {
	        if (wfs_editors[i][0] == table && wfs_editors[i][3] != "") {
	            Call = "editors/" + wfs_editors[i][3];
	        }
		if (wfs_editors[i][0] == table && wfs_editors[i].length > 5) {
	    	    add_layers = wfs_editors[i][5];
		}
	    }
	    if (src.indexOf("/notizen/") >= 0)
	 	  Call = "../" + Call;
	
	    if (src.indexOf("/html/") >= 0 || src.indexOf("/editors/") >= 0)
	 	  Call = "../" + Call;
	   
	    Call += "?table=" + table + "&filter=" + filter + "&srs=" + srs + "&useFilterValues=true";
	
	    if (parent.frameTab != null && parent.frameTab.editor_frame != null) {
	    	parent.frameTab.activate_tab("editor_mode");
	    	EditorWin = parent.frameTab.editor_frame;
	    	
	    	EditorWin.location.href = Call;
		if (add_layers != null)
			ensure_layer_vis(add_layers);
	    	return;	
	    }

	    if (EditorWin != null && !EditorWin.closed) {
	    	EditorWin.location.href = Call;

	    } else {
	        EditorWin = open(Call,"EditorWin",
			"width=500,height=750,dependent=yes,directories=no,location=no" +
			",menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no");
	    }
	    EditorWin.focus();
	    if (add_layers != null)
		ensure_layer_vis(add_layers);
	} catch(er) {
		// Fehler: Dann warten und erneut aufrufen:
		setTimeout("OpenEditorTemplate('" + table + "','" + filter + "')",200);		
	}
}

function OpenEditorFromBrowser(fid)
{
	alert("OBSOLET!!! Bitte melden !!!");
}
function OpenBrowser(fid) {
	// Staret den Browser
	
	try {
		var srs = document.RequestForm.srs.value;
		var Request = "GCGisService?Request=GetObjectById"
			+ "&OBJECTID=" + fid
			+ "&SRS=" + srs
			+ "&EXCEPTIONS=text/html"
			+ "&STYLESHEET=html/Browser.xsl&";
		document.getElementById("BrowserRequest").value="../" + Request;
		start_new_browser();
	} catch(er) {
		// Fehler: Dann warten und erneut aufrufen:
		setTimeout("OpenBrowser('" + fid + "')",200);
	}
}
function ensure_layer_vis(add_layers) {
	// Diese Funktion stellt sicher, dass die übergebenen
	// Layer auch wirklich sichtbar sind.

	var new_layers = "";
	var layer_vec = add_layers.split(",");
	var all_layer_vec = document.getElementById("all_layers").value.split(",");
	var vis_layer_vec = document.getElementById("visible_layers").value.split(",");

	if (vis_layer_vec == "SW!ACE" || vis_layer_vec == "")
		return;

	for (var i=0; i < layer_vec.length; i ++) {
		var layer = layer_vec[i];
		var found_layer = false;
		for (var j=0; j < all_layer_vec.length; j++) {
			if (layer == all_layer_vec[j]) {
				found_layer = true;
				break;
			}
		}
		if (! found_layer)
			continue;

		var vis_layer = false;
		for (var j=0; j < vis_layer_vec.length; j++) {
			if (layer == vis_layer_vec[j]) {
				vis_layer = true;
				break;
			}
		}

		if (vis_layer == true)
			continue;

		// Der Layer muss sichtbar geschaltet werden:
		if (new_layers == "")
			new_layers = layer;
		else
			new_layers += "," + layer;
	}
	if (new_layers != "") {
		var actual_layers = document.getElementById("visible_layers").value;
		if (actual_layers == "")
			actual_layers = new_layers;
		else
			actual_layers += "," + new_layers;

		document.RequestForm.layers.value = actual_layers;
		document.RequestForm.GetMap.click();
	}
}
// -----------------------------------------------------------------------------------
// Funktionen für StartupActions
// -----------------------------------------------------------------------------------
function execute_startup_method() {
	// Startup der Applikation
	if (! document.RequestForm.jsstartupmethod)
		return; 
 	
	var mthd = document.RequestForm.jsstartupmethod.value;
	if (mthd == "")
		return;

	// Haben wir eine Tab-Frame? Dann warten wir
	// auf dessen Onload-Ereignis
	if (parent.frameTab != null) {	
		if (! parent.frameTab.document || 
		    ! parent.frameTab.document.StartupForm ||
		    ! parent.frameTab.document.StartupForm.startup_complete ||
		    parent.frameTab.document.StartupForm.startup_complete.value == "")
		{
			setTimeout('execute_startup_method()',200);
			return;
		}
	}
	setTimeout(mthd,200);
}
// -----------------------------------------------------------------------------------
// Funktionen für die Weltenverwaltung
// -----------------------------------------------------------------------------------
function open_world_window() {
	// Öffnet das Fenster für die Weltenverwaltung
	worlds_win = open("Weltenverwaltung.html","worlds_win",
		"width=450,height=300,dependent=yes,directories=no,location=no" +
		",menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no");
	worlds_win.focus();
}

// -----------------------------------------------------------------------------------
// Funktionen für Pulldown-Menus
// -----------------------------------------------------------------------------------
function show_menu(id,anchorname,xoff,yoff) {
	// Setzt die Sichtbarkeit des übergebenen
	// Elements
	
	var el = document.getElementById(id);
	if (! el)
		return;

	if (anchorname != null) {
		var pos = getAnchorPosition(anchorname);
		var x_off = 0;
		if (xoff != null) x_off = xoff;
		var y_off = 0;
		if (yoff != null) y_off = yoff;
		set_div_position(el,pos.x + x_off,pos.y + y_off)
	}
	document.getElementById(id).style.visibility="visible";
}
	
function hide_menu(id) {
	// Setzt die Sichtbarkeit des übergebenen
	// Elements
	if (document.getElementById(id) != null)
		document.getElementById(id).style.visibility="hidden"
}
function open_olc_win() {
    // Startet den OpenLayersClient
    
    var srs = document.RequestForm.srs.value;
    var layers = document.RequestForm.visible_layers.value;
    var bounds = document.RequestForm.bounds.value;
    var Datum = new Date();
    
    var request = "../GCGisService?request=startolc" +
                  "&srs=" + srs +
                  "&layers=" + layers +
                  "&bounds=" + bounds +
                  "&INT!DATE=" + Datum +
                  "&STYLESHEET=html/start_olc.xsl";
                  
    
    	// Öffnet das Fenster für den OpenLayers-Client
	olc_win = open(request,"olc_win",
		"width=700,height=500,dependent=yes,directories=no,location=no" +
		",menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no");
	olc_win.focus();
}
