
/**
 * Globals
 */
//-- verweist auf die Applikation
var app = null;
var map = null;
var model = null;
var serverRequestQueue = null;
var debug = null;
var geocoderResults = null;
var basicLocation = null;
var selectedLocation = null;
var locationsHistory = null;
var locationTableHistory = new Array();
//-- Referenz auf global debug interface WGGAbstractDebugInterface.gDebugInterface
var debug = null;



/**
 * Löscht alle Kindknoten aus einem HTML Knoten
 */
function resetDiv(contentNode){

	for( var i=0; i<contentNode.childNodes.length; i++ ){

		contentNode.removeChild(contentNode.childNodes[i]);
	}
}

/**
 * Url für Printseite zusammenstellen
 */
function makePrintUrl(){
	var printUrl = 'print.php5?LNG=' + WGGNextDoorAppConfig.language;
	return printUrl;

}


/**
 * Löscht aktuelle Selektionen und Highlights
 */
function deleteSelection(){

	resetDiv(document.getElementById('contentDiv'));
	selectedLocation = null;

	if(map.route != null) map.deleteRoute();

}



/**
 * Fügt Loader in linker Contentspalte ein
 */
function activateLoader(div,align){

	var contentNode = document.getElementById(div);
	var divNode = document.createElement("div");
	divNode.setAttribute("align", align);
	var imgNode = document.createElement("img");
	imgNode.setAttribute("src", "img/loader.gif");
	divNode.appendChild(imgNode);
	contentNode.appendChild(divNode);

}

/**
 * Fügt Fehlermeldung in linker Contentspalte ein
 */
function insertErrorMessage(txt){

	var contentNode = document.getElementById('contentDiv');
	var divNode = document.createElement("div");
	var textNode = document.createTextNode(txt);
	divNode.setAttribute("class", "errorMessage");
	divNode.setAttribute("className", "errorMessage");
	divNode.appendChild(textNode);
	contentNode.appendChild(divNode);

}


/**
 * Setzen des Ausgangspunktes der Suche und Starten der Suche
 */
function setBasicLocation(loc) {

	if(loc != null){

		// Umprojezieren, falls API und Kartenprojektion unterschiedlich
		if(WGGNextDoorAppConfig.apiProjection != WGGNextDoorAppConfig.mapProjection){
			var olLoc = loc.toOpenLayersLonLat();
			var prjLoc = olLoc.transform(new OpenLayers.Projection(WGGOpenLayersMap.projectionMap[WGGNextDoorAppConfig.apiProjection]), map.nativeMap.getProjectionObject());
			loc.setX(prjLoc.lon);
			loc.setY(prjLoc.lat);
		}

		//Basislocation setzen
		basicLocation = loc;

		//Model hinzufügen
		model.addLocation(loc, 1);
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////// Tabellenanzeige
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/**
 * NextLocator Ergebnisse in Tabelle einfügen
 */
 function insertNextLocatorResults(){


		// Einfügen der neuen Tabelle für die Ergebnisübersicht
		var contentNode = document.getElementById('contentDiv');
		resetDiv(contentNode);
		var tbl = document.createElement("table");
		tbl.setAttribute("id", "nextLocatorResults");
		tbl.setAttribute("class", "resultList");
		tbl.setAttribute("className", "resultList");
		var tblBody = document.createElement("tbody");
		tbl.appendChild(tblBody);
		contentNode.appendChild(tbl);


		var locs = model.getLocations();

		//Einfügen der Ergebnisse
		for( var i=0; i<locs.length; i++ ){

			var loc = locs[i];

			if(loc.getId() != 0){

				//Name des Standortes
				var newRow = tblBody.insertRow(tblBody.rows.length);
				var textNode1 = document.createTextNode(ILngSource.lng_filiale + " " + loc.getDesc()['name']);
				breakNode = document.createElement("br");
				var textNode2 = document.createTextNode(loc.getDesc()['strasse']);
				var cellNode = newRow.insertCell(0);
				cellNode.appendChild(textNode1);
				cellNode.appendChild(breakNode);
				cellNode.appendChild(textNode2);

				//Distanz des Standortes
				//var textNode = document.createTextNode(loc.getDesc()['distance'] + " km");
				var textNode = document.createTextNode(ILngSource.lng_detailmap);
				var linkNode = document.createElement('a');
				linkNode.setAttribute("href", 'javascript:selectLocation(' + loc.getId() + ');doTheBilling("DETAIL");');
				linkNode.appendChild(textNode);
				var cellNode = newRow.insertCell(1);
				cellNode.setAttribute("class", "resultListRight");
				cellNode.setAttribute("className", "resultListRight");
				cellNode.appendChild(linkNode);
			}


		}

 }




///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////// Auswahl eines Standortes
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function selectLocation(id){

	deleteSelection();

	var loc = model.getLocationById(id);
	var marker = map.markersCache.get(id);
	var contentNode = document.getElementById('contentDiv');

	if(loc != null && marker != null &&  contentNode != null){

			map.setCenter(loc.getX(), loc.getY(),map.getMaxScaleLevel());
			selectedLocation = loc;

			locDetails = loc.getDesc();

			// Einfügen der neuen Tabelle für die Detailanzeige
			var tblDetail = document.createElement("table");
			tblDetail.setAttribute("id", "detailTable");
			var tblBody = document.createElement("tbody");
			tblDetail.appendChild(tblBody);
			tblDetail.setAttribute("class", "detailList");
			tblDetail.setAttribute("className", "detailList");
			contentNode.appendChild(tblDetail);


			//Einfügen der Überschrift
			var newRow = tblBody.insertRow(tblBody.rows.length);
			var textNode = document.createTextNode(ILngSource.lng_filiale + " " + locDetails['name']);
			var cellNode = newRow.insertCell(0);
			cellNode.setAttribute("class", "detailListHeader");
			cellNode.setAttribute("className", "detailListHeader");
			cellNode.appendChild(textNode);

			if(clientModus != "XY"){

				//Einfügen Adressüberschrift
				var newRow = tblBody.insertRow(tblBody.rows.length);
				var textNode = document.createTextNode(ILngSource.lng_address + ":");
				var cellNode = newRow.insertCell(0);
				cellNode.setAttribute("class", "detailListBold");
				cellNode.setAttribute("className", "detailListBold");
				cellNode.appendChild(textNode);

				//Einfügen der Adresse
				var newRow = tblBody.insertRow(tblBody.rows.length);
				var textNode1 = document.createTextNode(locDetails['strasse'] );
				var textNode2 = document.createTextNode(locDetails['plz'] + " " + locDetails['ort']);
				var breakNode = document.createElement("br");
				var cellNode = newRow.insertCell(0);
				cellNode.appendChild(textNode1);
				cellNode.appendChild(breakNode);
				cellNode.appendChild(textNode2);

				//Einfügen Kontaktüberschrift
				var newRow = tblBody.insertRow(tblBody.rows.length);
				var textNode = document.createTextNode(ILngSource.lng_contact + ":");
				var cellNode = newRow.insertCell(0);
				cellNode.setAttribute("class", "detailListBold");
				cellNode.setAttribute("className", "detailListBold");
				cellNode.appendChild(textNode);


				//Einfügen des Kontaktes
				var newRow = tblBody.insertRow(tblBody.rows.length);
				var textNode1 = document.createTextNode(locDetails['ansprechperson'] );
				var textNode2 = document.createTextNode(locDetails['telefon']);
				var textNode3 = document.createTextNode(locDetails['fax']);
				var textNode4 = document.createTextNode(locDetails['email']);
				var breakNode1 = document.createElement("br");
				var breakNode2 = document.createElement("br");
				var breakNode3 = document.createElement("br");
				var linkNode = document.createElement('a');
				linkNode.setAttribute("href", 'mailto:' + locDetails['email']);
				linkNode.appendChild(textNode4);
				var cellNode = newRow.insertCell(0);
				cellNode.appendChild(textNode1);
				cellNode.appendChild(breakNode1);
				cellNode.appendChild(textNode2);
				cellNode.appendChild(breakNode2);
				cellNode.appendChild(textNode3);
				cellNode.appendChild(breakNode3);
				cellNode.appendChild(linkNode);

				//Einfügen Öffnungszeitenüberschrift
				var newRow = tblBody.insertRow(tblBody.rows.length);
				var textNode = document.createTextNode(ILngSource.lng_open_hours + ":");
				var cellNode = newRow.insertCell(0);
				cellNode.setAttribute("class", "detailListBold");
				cellNode.setAttribute("className", "detailListBold");
				cellNode.appendChild(textNode);

				//Einfügen Öffnungszeiten
				var newRow = tblBody.insertRow(tblBody.rows.length);
				var cellNode = newRow.insertCell(0);
				var openingHours = locDetails['oeffnungszeit'];
				var opArray = openingHours.split("<BR>");
				for (var i=0; i<opArray.length;i++){
					var actOp = opArray[i].replace("<BR>","");
					var textNode = document.createTextNode(actOp);
					var breakNode = document.createElement("br");
					cellNode.appendChild(textNode);
					cellNode.appendChild(breakNode);
				}




				//Einfügen Parkplätzeüberschrift
				var newRow = tblBody.insertRow(tblBody.rows.length);
				var textNode = document.createTextNode(ILngSource.lng_park + ":");
				var cellNode = newRow.insertCell(0);
				cellNode.setAttribute("class", "detailListBold");
				cellNode.setAttribute("className", "detailListBold");
				cellNode.appendChild(textNode);

				//Einfügen Parkplätze
				var newRow = tblBody.insertRow(tblBody.rows.length);
				var textNode = document.createTextNode(locDetails['parkplaetze']);
				var cellNode = newRow.insertCell(0);
				cellNode.appendChild(textNode);

				//Einfügen Ausstattungsüberschrift
				var newRow = tblBody.insertRow(tblBody.rows.length);
				var textNode = document.createTextNode(ILngSource.lng_equipment + ":");
				var cellNode = newRow.insertCell(0);
				cellNode.setAttribute("class", "detailListBold");
				cellNode.setAttribute("className", "detailListBold");
				cellNode.appendChild(textNode);

				//Einfügen Ausstattung
				var newRow = tblBody.insertRow(tblBody.rows.length);
				var equipText = "";
				if( locDetails['bankomat'] == 1) equipText = equipText + ILngSource.lng_bankomat;
				var textNode = document.createTextNode(equipText);
				var cellNode = newRow.insertCell(0);
				cellNode.appendChild(textNode);

				//Zurück zur Liste
				if(clientModus == "MAP"){
					var newRow = tblBody.insertRow(tblBody.rows.length);
					var textNode = document.createTextNode(ILngSource.lng_list);
					var linkNode = document.createElement('a');
					linkNode.setAttribute("href", 'javascript:deleteSelection();map.setExtent(model.getExtent());insertNextLocatorResults();doTheBilling("MAP");');
					linkNode.appendChild(textNode);
					var cellNode = newRow.insertCell(0);
					cellNode.appendChild(linkNode);
				}

				//Routelink
				var newRow = tblBody.insertRow(tblBody.rows.length);
				var textNode = document.createTextNode(ILngSource.lng_route);
				var linkNode = document.createElement('a');
				linkNode.setAttribute("href", 'javascript:if( basicLocation != null ){ calculateRoute(' + id + ');doTheBilling("ROUTE");}else{ gotoRouteInput(' + id + ');}');
				linkNode.appendChild(textNode);
				var cellNode = newRow.insertCell(0);
				cellNode.setAttribute("class", "detailListBottom");
				cellNode.setAttribute("className", "detailListBottom");
				cellNode.appendChild(linkNode);
			}else{

				//Routelink
				var newRow = tblBody.insertRow(tblBody.rows.length);
				var textNode = document.createTextNode(ILngSource.lng_route);
				var linkNode = document.createElement('a');
				linkNode.setAttribute("href", 'javascript:gotoRouteInputXY();');
				linkNode.appendChild(textNode);
				var cellNode = newRow.insertCell(0);
				cellNode.setAttribute("class", "detailListBottom");
				cellNode.setAttribute("className", "detailListBottom");
				cellNode.appendChild(linkNode);

			}
	}
 }

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////// Routenberechnung
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function gotoRouteInput(id){

	window.location.href = "start_route.php5?ID=" + id;
}

function gotoRouteInputXY(){

	window.location.href = "start_route.php5?XCO2=" + clientXco + "&YCO2=" + clientYco;
}

function calculateRoute(id){


	//Loader
	resetDiv(document.getElementById('contentDiv'));
	activateLoader('contentDiv','center');

	if(map.route != null) map.deleteRoute();

	//Route vom Typ WGGNextDoorRoute initialisieren
	var routePts = new Array();
	routePts[0] = basicLocation;
	routePts[1] = model.getLocationById(id);

	var opts = new Array();
	opts['DESCDIV'] = document.getElementById('contentDiv');
	opts['LNG'] = WGGNextDoorAppConfig.language;
	opts['WAYPOINTS'] = routePts;
	opts['USR'] = clientUser;
	opts['CID'] = clientCid;
	opts['PRD'] = "WEBMERCATOR";
	opts['PRJ'] = "WEBMERCATOR";
	opts['IPA'] = clientIpa;
    opts['APPLICATIONID'] = WGGNextDoorAppConfig.applicationID;

	//Fenster verändern
	if(clientModus != "ROUTE"){
		document.getElementById('map').style.width = '500px';
		document.getElementById('map').style.height = '370px';
		document.getElementById('map').style.top = '100px';
		document.getElementById('map').style.left = '410px';
		document.getElementById('copyWiGeo').style.top = '457px';
		document.getElementById('copyWiGeo').style.left = '410px';
		document.getElementById('contentDiv').style.width = '380px';
		document.getElementById('contentDiv').style.backgroundColor = '#FFFFFF';

	}

	map.addRoute(opts);

}



///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////// Billing
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function doTheBilling(billModus){

	var srqForBilling = new WGGServerRequestQueue( null, null );

	//- verifier request
	var billVerifier = new WGGVerifier( WGGNextDoorAppConfig.verifierURL, new WGGAjaxLoader() );
	srqForBilling.addServerRequest( billVerifier );

	//-- Was soll gebillt werden
	var billLocs = '-';
	var billXco = '';
	var billYco = '';
	var billAkt = '';
	var billBlg = '';

	switch (billModus){

		case 'MAP':
			billLocs = '-';
			billXco = map.getCenter().getX();
			billYco = map.getCenter().getY();
			billAkt = 'OVERVIEW';
			billBlg = 'SHOWMAP';
			break;
		case 'DETAIL':
			billLocs = '-';
			billXco = map.getCenter().getX();
			billYco = map.getCenter().getY();
			billAkt = 'SHOWMAP';
			billBlg = 'SHOWDETAILMAP';
			break;
		case 'ROUTE':
			billLocs = 'Standort ' + selectedLocation.getId();
			billXco = selectedLocation.getX();
			billYco = selectedLocation.getY();
			billAkt = 'SHOWROUTEMAP';
			billBlg = 'SHOWROUTEMAP';
			break;
		case 'PRINTMAP':
			billLocs = '-';
			billXco = window.opener.map.getCenter().getX();
			billYco = window.opener.map.getCenter().getY();
			billAkt = 'PRINTMAP';
			billBlg = 'PRINTMAP';
			clientUser = window.opener.clientUser;
			clientIpa = window.opener.clientIpa;
			break;
		case 'SHADEDLAYER':
			billLocs = '-';
			billXco = map.getCenter().getX();
			billYco = map.getCenter().getY();
			billAkt = 'BING SHADED LAYER';
			billBlg = 'SHOWMAP';
			break;
		case 'HYBRIDLAYER':
			billLocs = '-';
			billXco = map.getCenter().getX();
			billYco = map.getCenter().getY();
			billAkt = 'BING HYBRID LAYER';
			billBlg = 'SHOWMAP';
			break;
		case 'SATLAYER':
			billLocs = '-';
			billXco = map.getCenter().getX();
			billYco = map.getCenter().getY();
			billAkt = 'BING SATELLITE LAYER';
			billBlg = 'SHOWMAP';
			break;
	}

	//- billing request
	var billing = new WGGBilling( WGGNextDoorAppConfig.billingURL, new WGGAjaxLoader() );
	billing.addParam( "APP", "NEXTDOOR" );
	billing.addParam( "USR", clientUser );
	billing.addParam( "BLG", billBlg );
	billing.addParam( "MSG", "Ajax Action" );
	billing.addParam( "LOC", billLocs );
	billing.addParam( "CTR", "BING" );
	billing.addParam( "IPA", clientIpa);
	billing.addParam( "AKT", billAkt );
	billing.addParam( "XCO", billXco );
	billing.addParam( "YCO", billYco );
	srqForBilling.addServerRequest( billing );

	srqForBilling.start();


}



///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////// OVERWRITTEN METHODS
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	OpenLayers.Util.getImagesLocation = function() {
		 	return WGGNextDoorAppConfig.imageSource + "/";
 	};
	

	//-- Selektion von Standorten
	WGGAbstractMarker.prototype.highlightMarker = function() {

		if(this.point != basicLocation && clientModus != 'ROUTE'){
			doTheBilling("DETAIL");
			selectLocation(this.point.getId());
		}
	};

	//-- Routing Fehler
	WGGAbstractMap.prototype.onRouteError = function() {


			//Fehlermedlung einblenden
			var contentNode = document.getElementById('contentDiv');
			resetDiv(contentNode);

			var divNode = document.createElement("div");
			var textNode = document.createTextNode("Your route could not be calculated!");
			divNode.appendChild(textNode);
			contentNode.appendChild(divNode);

	};

	WGGBingRoute.prototype.onShown = function() {


			var tableNode = document.getElementById('routeTable').tBodies[0];
			for( var i=0; i<tableNode.childNodes.length; i++ ){

				if((i%2)!=0){
					tableNode.childNodes[i].setAttribute("class", "routeListDark");
					tableNode.childNodes[i].setAttribute("className", "routeListDark");
				}
			}

	};



	//-- Initialisieren der Startansicht
	WGGAbstractMap.prototype.initialize = function() {

			this.initializeNativeMap();

			if( this.nativeMap != null ) {


				var config = this.app.getConfig();

				//Umprozezieren falls notwendig
				if(config.mapProjection != config.apiProjection){

					// Center umprojezieren
					var olCenter = config.centerPoint.toOpenLayersLonLat();
					var prjCenter = olCenter.transform(new OpenLayers.Projection(WGGOpenLayersMap.projectionMap[config.apiProjection]), this.nativeMap.getProjectionObject());
					config.centerPoint.setX(prjCenter.lon);
					config.centerPoint.setY(prjCenter.lat);

					if(config.initialExtent && config.initialExtent != null ){
						var wggMax = new WGGPoint(config.initialExtent.getMaxx(),config.initialExtent.getMaxy());
						var wggMin = new WGGPoint(config.initialExtent.getMinx(),config.initialExtent.getMiny());
						var olMax = wggMax.toOpenLayersLonLat();
						var olMin = wggMin.toOpenLayersLonLat();
						var prjMax = olMax.transform(new OpenLayers.Projection(WGGOpenLayersMap.projectionMap[config.apiProjection]), this.nativeMap.getProjectionObject());
						var prjMin = olMin.transform(new OpenLayers.Projection(WGGOpenLayersMap.projectionMap[config.apiProjection]), this.nativeMap.getProjectionObject());

						config.initialExtent = new WGGExtent(prjMin.lon, prjMin.lat, prjMax.lon, prjMax.lat);
					}


				}

				//Extent oder Center setzen
				if(config.initialExtent && config.initialExtent != null){
					config.initialExtent.addPoint(config.centerPoint);
					this.setExtent( config.initialExtent );
				}else{
					this.setCenter( config.centerPoint.getX(), config.centerPoint.getY(), config.scale );
				}

				//-- back reference to the app object
				this.nativeMap.wggNextDoorApp = this.app;

				//-- create markers cache
				this.markersCache = new WGGHashMap();
			}
	};










///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////// INIT
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function init() {


	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	////////////////// GLOBALS
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	debug = WGGAbstractDebugInterface.gDebugInterface;

	/////////////////////////////////////////////////////////////////////


	/**
	 * WGGNextDoorAppConfig
	 */
	WGGNextDoorAppConfig.type = clientMapType;
	WGGNextDoorAppConfig.mapProjection = clientMapProjection;
	WGGNextDoorAppConfig.apiProjection = clientApiProjection;
	WGGNextDoorAppConfig.centerPoint = new WGGPoint(clientXco,clientYco);
	WGGNextDoorAppConfig.initialExtent = clientExtent;
	WGGNextDoorAppConfig.scale = clientSca;
	WGGNextDoorAppConfig.verifierServerRequestClass = null;
	WGGNextDoorAppConfig.verifierURL = WGGHtmlUtils.buildURLFromCurrentPath("functions/authorize.php5");
	WGGNextDoorAppConfig.billingURL = WGGHtmlUtils.buildURLFromCurrentPath() + "/accounting/checkkey.php5";
	WGGNextDoorAppConfig.geocoderURL = WGGHtmlUtils.buildURLFromCurrentPath() + "/rel3/geocode/geocode.php5";
	WGGNextDoorAppConfig.bingGeocoderURL = WGGHtmlUtils.buildURLFromCurrentPath() + "/bingapi/geocode/binggeocode.php5";
	WGGNextDoorAppConfig.nextLocatorURL = "functions/find.php5";
	WGGNextDoorAppConfig.nextLocatorServerRequestClass = WGGNextLocator;
	WGGNextDoorAppConfig.applicationID = clientApplicationID;
	WGGNextDoorAppConfig.nextLocatorOptions = null;
	WGGNextDoorAppConfig.locationListClass = null;
	WGGNextDoorAppConfig.detailBoxClass = null;
	WGGNextDoorAppConfig.geocoderType = clientGeocodeType;
	WGGNextDoorAppConfig.language = clientLng;
	WGGNextDoorAppConfig.environment = clientEnv;
	WGGNextDoorAppConfig.imageSource = WGGHtmlUtils.buildURLFromCurrentPath("img");
	WGGNextDoorAppConfig.routeType = clientRouteType;


	WGGNextDoorAppConfig.markerProperties = {};


	/**
	 * Marker für Ausgangspunkt
	 */
	var startMarkerProperties = new Object();
	startMarkerProperties["locIconPath"] = "img/stecknadel.png",
	startMarkerProperties["locIconSize"] = [20,35];
	startMarkerProperties["locShadowPath"] = "";
	startMarkerProperties["locShadowSize"] = [0,0];
	startMarkerProperties["locIconAnchor"] = [10,30];
	startMarkerProperties["locWindowAnchor"] = [0,0];

	/**
	 * Marker für Standorte
	*/
	var logoMarkerProperties = new Object();
	logoMarkerProperties["locIconPath"] = "img/spar.gif",
	logoMarkerProperties["locIconSize"] = [22,22];
	logoMarkerProperties["locShadowPath"] = "";
	logoMarkerProperties["locShadowSize"] = [0,0];
	logoMarkerProperties["locIconAnchor"] = [11,11];
	logoMarkerProperties["locWindowAnchor"] = [0,0];



	WGGNextDoorAppConfig.markerProperties[0] = logoMarkerProperties;
	WGGNextDoorAppConfig.markerProperties[1] = startMarkerProperties;








	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	////////////////// Finale Initialisierung
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	app = new WGGNextDoorApp( WGGNextDoorAppConfig, { "MAP" : document.getElementById('map') } );
	model = app.getModel();
	map = app.getController().getMap();


	//NEXTDOOR MODUS
	if(clientModus == "MAP"){
		var tTooltip = '<div class="tooltip">' + ILngSource.lng_myLoc + '<br/>' + clientStartLocation + '</div>';
		var tempLoc = new WGGLocation(clientXco,clientYco,0, {'tooltip': tTooltip, 'name': clientStartLocation } );
		setBasicLocation(tempLoc);

	}

	//Locations zur Karte hinzufügen
	var locIds = new Array();
	for(var i=0;i<clientLocations.length;i++){

			// Umprojezieren, falls API und Kartenprojektion unterschiedlich
			if(WGGNextDoorAppConfig.apiProjection != WGGNextDoorAppConfig.mapProjection){

					var olLoc = clientLocations[i].toOpenLayersLonLat();
					var prjLoc = olLoc.transform(new OpenLayers.Projection(WGGOpenLayersMap.projectionMap[WGGNextDoorAppConfig.apiProjection]), map.nativeMap.getProjectionObject());
					clientLocations[i].setX(prjLoc.lon);
					clientLocations[i].setY(prjLoc.lat);
			}

			model.addLocation(clientLocations[i], 0);
			locIds.push (clientLocations[i].getId());

	}

	if(clientModus == "DETAIL" || clientModus == "XY"){

		selectLocation(locIds[0]);


	}else if(clientModus == "ROUTE"  || clientModus == "ROUTEXY"){

		var tTooltip = '<div class="tooltip">' + ILngSource.lng_myLoc + '<br/>' + clientStartLocation + '</div>';
		var tempLoc = new WGGLocation(clientRouteXco,clientRouteYco,0, {'tooltip': tTooltip, 'name': clientStartLocation } );
		setBasicLocation(tempLoc);
		selectedLocation = model.getLocationById(locIds[0]);
		calculateRoute(locIds[0]);

	}else{

		insertNextLocatorResults();
	}

}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////// Printseite
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function initPrintPage() {

	if(window.opener && window.opener.map && window.opener.WGGNextDoorAppConfig){

		debug = WGGAbstractDebugInterface.gDebugInterface;

		//Konfiguration einlesen
		WGGNextDoorAppConfig = window.opener.WGGNextDoorAppConfig;
		WGGNextDoorAppConfig.centerPoint = new WGGPoint(window.opener.map.getCenter().getX(),window.opener.map.getCenter().getY());
		WGGNextDoorAppConfig.scale = window.opener.map.getZoom();


		// Marker für Druckseite festlegen
		var printMarkerProperties = new Object();
		printMarkerProperties["locIconPath"] = "img/printIcons/",
		printMarkerProperties["locIconSize"] = [20,35];
		printMarkerProperties["locShadowPath"] = "";
		printMarkerProperties["locShadowSize"] = [0,0];
		printMarkerProperties["locIconAnchor"] = [10,30];
		printMarkerProperties["locWindowAnchor"] = [0,0];


		//Karte erstellen
		app = new WGGNextDoorApp( WGGNextDoorAppConfig, { "PRINTMAP" : document.getElementById('map') } );
		map = app.getController().getPrintMap();

		//Ausgangspunkt gesetzt
		var basis = window.opener.basicLocation;
		if(basis != null) map.addMarker(basis,0,printMarkerProperties);


		var selLoc = window.opener.selectedLocation;
		if(window.opener.clientModus == "ROUTE" || window.opener.clientModus == "DETAIL"){

			var locs = new Array();
			locs[0] = null;
			locs[1] = selLoc;

		}else{

			var locs = window.opener.model.getLocations();


		}

		//Nach dem Einfügen des Startmarkers, Größe adaptieren
		printMarkerProperties["locIconSize"] = [17,19];
		printMarkerProperties["locIconAnchor"] = [0,19];


		// Einfügen der Aufzählung aller Standorte
		if(locs.length > 0){

			//Tabelle für Ansicht erstellen
			var contentNode = document.getElementById('printDivAll');
			var tbl = document.createElement("table");
			tbl.setAttribute("id", "printLocationsList");
			tbl.setAttribute("class", "printList");
			tbl.setAttribute("className", "printList");
			var tblBody = document.createElement("tbody");
			tbl.appendChild(tblBody);
			contentNode.appendChild(tbl);

			var locCounter = 0;
			if(window.opener.clientModus == "XY") locs[1] = locs[0];

			// Alle Standorte des akuellen Ausschnittes einfügen
			for(var i=1;i<locs.length; i++){

				var loc = locs[i];

				// Falls ein Standort selektiert ist, wird dessen beschreibung eingefügt, sonst alle Standorte
				if(selLoc == null || window.opener.clientModus == "DETAIL" || window.opener.clientModus == "ROUTE" || window.opener.clientModus == "XY"){

					locCounter = locCounter + 1;

					//ERSTE ZEILE
					var newRow = tblBody.insertRow(tblBody.rows.length);

					//Icon des Standortes in erster Spalte
					var imgNode = document.createElement("img");
					if(selLoc == null){
						imgNode.setAttribute("src", printMarkerProperties["locIconPath"] + locCounter + ".png");
					}else{
						imgNode.setAttribute("src", printMarkerProperties["locIconPath"] + "100.png");
					}
					var cellNode = newRow.insertCell(0);
					cellNode.appendChild(imgNode);

					//Name des Standortes in erster Spalte
					var textNode = document.createTextNode(ILngSource.lng_filiale + " " + loc.getDesc()['name']);
					var cellNode = newRow.insertCell(1);
					cellNode.appendChild(textNode);

					//Detailüberschrift in zweiter Spalte
					var textNode = document.createTextNode(ILngSource.lng_address);
					var cellNode = newRow.insertCell(2);
					cellNode.setAttribute("class", "printListDetail");
					cellNode.setAttribute("className", "printListDetail");
					cellNode.appendChild(textNode);


					//Detail in dritte Spalte
					var textNode1 = document.createTextNode(loc.getDesc()['strasse']);
					var breakNode1 = document.createElement("br");
					var textNode2 = document.createTextNode(loc.getDesc()['plz'] + " " + loc.getDesc()['ort']);
					var cellNode = newRow.insertCell(3);
					cellNode.appendChild(textNode1);
					cellNode.appendChild(breakNode1);
					cellNode.appendChild(textNode2);

					//ZWEITE ZEILE
					var newRow = tblBody.insertRow(tblBody.rows.length);

					//leere Spalten
					newRow.insertCell(0);
					newRow.insertCell(1);

					//Detailüberschrift in zweiter Spalte
					var textNode = document.createTextNode(ILngSource.lng_contact);
					var cellNode = newRow.insertCell(2);
					cellNode.setAttribute("class", "printListDetail");
					cellNode.setAttribute("className", "printListDetail");
					cellNode.appendChild(textNode);

					//Detail in dritte Spalte
					var textNode1 = document.createTextNode(loc.getDesc()['ansprechperson']);
					var breakNode1 = document.createElement("br");
					var textNode2 = document.createTextNode(loc.getDesc()['telefon']);
					var breakNode2 = document.createElement("br");
					var textNode3 = document.createTextNode(loc.getDesc()['fax']);
					var breakNode3 = document.createElement("br");
					var textNode4 = document.createTextNode(loc.getDesc()['email']);
					var cellNode = newRow.insertCell(3);
					cellNode.appendChild(textNode1);
					cellNode.appendChild(breakNode1);
					cellNode.appendChild(textNode2);
					cellNode.appendChild(breakNode2);
					cellNode.appendChild(textNode3);
					cellNode.appendChild(breakNode3);
					cellNode.appendChild(textNode4);

					//DRITTE ZEILE
					var newRow = tblBody.insertRow(tblBody.rows.length);

					//leere Spalten
					newRow.insertCell(0);
					newRow.insertCell(1);

					//Detailüberschrift in zweiter Spalte
					var textNode = document.createTextNode(ILngSource.lng_open_hours);
					var cellNode = newRow.insertCell(2);
					cellNode.setAttribute("class", "printListDetail");
					cellNode.setAttribute("className", "printListDetail");
					cellNode.appendChild(textNode);

					//Detail in dritte Spalte
					var cellNode = newRow.insertCell(3);
					var openingHours = loc.getDesc()['oeffnungszeit'];
					var opArray = openingHours.split("<BR>");
					for (var j=0; j<opArray.length;j++){
						var actOp = opArray[j].replace("<BR>","");
						var textNode = document.createTextNode(actOp);
						var breakNode = document.createElement("br");
						cellNode.appendChild(textNode);
						cellNode.appendChild(breakNode);
					}

					//VIERTE ZEILE
					var newRow = tblBody.insertRow(tblBody.rows.length);

					//leere Spalten
					newRow.insertCell(0);
					newRow.insertCell(1);

					//Detailüberschrift in zweiter Spalte
					var textNode = document.createTextNode(ILngSource.lng_park);
					var cellNode = newRow.insertCell(2);
					cellNode.setAttribute("class", "printListDetail");
					cellNode.setAttribute("className", "printListDetail");
					cellNode.appendChild(textNode);

					//Detail in dritte Spalte
					var textNode = document.createTextNode(loc.getDesc()['parkplaetze']);
					var cellNode = newRow.insertCell(3);
					cellNode.appendChild(textNode);

					//FÜNFTE ZEILE
					var newRow = tblBody.insertRow(tblBody.rows.length);

					//leere Spalten
					var cellNode = newRow.insertCell(0);
					cellNode.setAttribute("class", "bottom");
					cellNode.setAttribute("className", "bottom");
					var cellNode = newRow.insertCell(1);
					cellNode.setAttribute("class", "bottom");
					cellNode.setAttribute("className", "bottom");

					//Detailüberschrift in zweiter Spalte
					var textNode = document.createTextNode(ILngSource.lng_equipment);
					var cellNode = newRow.insertCell(2);
					cellNode.setAttribute("class", "bottom");
					cellNode.setAttribute("className", "bottom");
					cellNode.appendChild(textNode);

					//Detail in dritte Spalte
					var equipText = "";
					if( loc.getDesc()['bankomat'] == 1) equipText = equipText + ILngSource.lng_bankomat;
					var textNode = document.createTextNode(equipText);
					var cellNode = newRow.insertCell(3);
					cellNode.setAttribute("class", "bottom");
					cellNode.setAttribute("className", "bottom");
					cellNode.appendChild(textNode);


					//Standort in Karte
					if(selLoc == null){
						map.addMarker(loc,locCounter,printMarkerProperties);
					}else{
						printMarkerProperties["locIconSize"] = [22,22];
						printMarkerProperties["locIconAnchor"] = [11,11];
						map.addMarker(loc,100,printMarkerProperties);
					}
				}
			}
		}

		//Bei Route
		var route = window.opener.map.route;
		if(route != null){
			printMarkerProperties["locIconSize"] = [22,22];
			printMarkerProperties["locIconAnchor"] = [11,11];
			map.addMarker(selLoc,100,printMarkerProperties);

			//Routenbeschreibung
			document.getElementById('printDivRoute').innerHTML = window.opener.document.getElementById('contentDiv').innerHTML;

			// Löschen der HTML Links
			var routeRefs = document.getElementsByTagName("a");
			for( var i=0; i<routeRefs.length; i++ ){

				routeRefs[i].setAttribute("href","javascript:");
			}


			//-- get default style of the vector
			var layerStyle = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']);
			layerStyle.fillOpacity = 0.7;
			layerStyle.strokeWidth = 5;
			layerStyle.strokeOpacity = 0.7;
			layerStyle.markerOpacity = 0.7;
			layerStyle.strokeColor = "#5457E0";

			var routeLayer = new OpenLayers.Layer.Vector("Route",{
										isFixed: false,
										geometryType:OpenLayers.Geometry.LineString
									}
				);
			routeLayer.style = layerStyle;

			var olLineString = new OpenLayers.Geometry.fromWKT( route.wkt );

			routeLayer.addFeatures( new OpenLayers.Feature.Vector( olLineString )  );
			map.nativeMap.addLayer(routeLayer);
			map.nativeMap.raiseLayer(routeLayer,3);
		}
	}
	doTheBilling('PRINTMAP')
	map.printBrowser();
}







