var tileMap;
var lastZoomLevel = 13;
var numbersOfBoliger = 0;	
var cookieSearch = 0;
var oldRequestString = "";
var requestString = "";
var searchInAction = false	
var searchChanged = true;
var searchPending = false;
var ontheflycount = 0;

var tileAdded = false;
var poiAdded = false;
var isMapSearch = true;
var isExtendedSearch = false;
var iconSuffix = "";
var houseTypeSelected = false;



function load(boliger,map) {
	numbersOfBoliger = boliger;
	isMapSearch = map && !isExtendedSearch;		
	if (map) {
		var settings = {
				mapContainer: document.getElementById('map'),				
	           	bufferSize: 1,
	           	imgDir: "http://tileclient.krak.dk/static/v3/docs/../img/",
				toolBarSettings: {kvec: true, ortho: true, ovc: true, oblique: false, 
				zoom: true, overviewMap: false, route: false, 
				center: true, print: !isExtendedSearch
				}	};
		
		tileMap =  new KrakMap.TileClient(settings);
		tileMap.enableRectangleDraw();
		tileMap.toggleOverviewMap();
		tileMap.disableOverviewMap();	
	    infoOverlay = new KrakMap.TileClient(settings); 
	    tileMap.setMapType('ovc');
	    initializeCoordinates();
	    tileMap.subscribeEvent('afterRectangleDraw',rectangleDrawAction);
	    tileMap.subscribeEvent('zoomed', zoomEventAction);	   
	    tileMap.subscribeEvent('afterBuildingGrid', setBackgroundColorOnMapKort);	    
        iconSuffix = navigator.userAgent.indexOf("MSIE 6.0") > 0 ? ".gif" : ".png";
        resetOnthefly();     
        doAjaxSearch(true);
	} else {		
		updateOnthefly(ontheflycount);
	}
}

function loadForboligjagt(boliger,map) {
	numbersOfBoliger = boliger;
	isMapSearch = map && !isExtendedSearch;
	if (map) {
		var settings = {
				mapContainer: document.getElementById('map'),				
	           	bufferSize: 1,
	           	imgDir: "http://tileclient.krak.dk/static/v3/docs/../img/",
				toolBarSettings: {kvec: true, ortho: true, ovc: true, oblique: false, 
				zoom: true, overviewMap: false, route: false, measureBox: true, 
				center: true, print: true
				}	};
		
		tileMap =  new KrakMap.TileClient(settings);
		tileMap.enableRectangleDraw();
		tileMap.toggleOverviewMap();
		tileMap.disableOverviewMap();		
	    infoOverlay = new KrakMap.TileClient(settings); 
	    tileMap.setMapType('ovc');
	    initializeCoordinates();
	    tileMap.subscribeEvent('afterRectangleDraw',rectangleDrawAction);
	    tileMap.subscribeEvent('zoomed', zoomEventAction);
        iconSuffix = navigator.userAgent.indexOf("MSIE 6.0") > 0 ? ".gif" : ".png";
        resetOnthefly();        
        doAjaxSearch(true);
	} else {		
		updateOnthefly(ontheflycount);
	}
	hideredirectbox();
}
var zoomEventAction = function() {
	//alert('#40# zoomEventAction '+lastZoomLevel+' -> '+tileMap.getZoomLevel());
	lastZoomLevel = tileMap.getZoomLevel();  
		
	//	if the zoom event is coming from the rectangle zoom we will reset the  
	isRecZoom = false;
	var isRec = tileMap.getRectangleExtent().toString();
	if(isRec.indexOf('top: 0,') == -1 && document.getElementById('hvor').value != document.getElementById('locationdefault').value){
		isRecZoom = true;
	}
		
	if (tileAdded) {
		tileMap.removeTileLayer('tileLayerResults');
		tileAdded = false;
	} //alert('#48# startSearchFromZoom '+lastZoomLevel);
	startSearch(false);
}

var rectangleDrawAction = function() {
		var rectExtent = tileMap.getRectangleExtent();
		
		if (rectExtent.top == rectExtent.bottom && rectExtent.left == rectExtent.right) {		
			var lastZoomLevel = tileMap.getZoomLevel();
			var mousePos = tileMap.getMousePosition();
			var coordinates = tileMap.pixelToGeoCoordinate(mousePos);
			var map = tileMap.getMapType();			
			tileMap.jump(coordinates, lastZoomLevel - 1, map, ""); 			
		} else {		
			tileMap.setMapViewExtent(rectExtent);
		}			
}

function doMouseMoveSearch(e){
	try { 
		if (!e) var e = window.event;
		var tg = (window.event) ? e.srcElement : e.target;		
		var id = "";
		if (tg.id) {
			id = tg.id;			
		}
		if (id == 'togglebutton' || id == 'marketinfo_pic' || id == 'submit_klikpris' || id == 'graphinfo0' || id == 'graphinfo1' || id == 'graphinfo2' || id == 'graphinfo3' || id == 'triangle') 
			return;
		while ((id != 'infoDiv' && id.indexOf('info_') == -1) && tg.nodeName != 'BODY') { //IE reagerer på infoDiv og info_. FF på infoDiv og triangle
			tg = tg.parentNode;
			
			if (tg.id) {
				id = tg.id;
			} else {
				id = "";
			}	
		}
		if (id == 'infoDiv' || id.indexOf('info_') > -1) {				
			return;
		}		
	}
	catch(e) {
	}
	
	var coords = tileMap.getMapViewExtent();
	if (document.getElementById('x_min').value == coords.left && document.getElementById('x_max').value == coords.right && document.getElementById('y_min').value == coords.bottom && 	document.getElementById('y_max').value == coords.top && !isRecZoom) {
		return;
	}	
	
	isRecZoom = false;
	clearLocations();	
	searchChanged = true; //alert('#274# startSearchFromMouseMove'); 
	startSearch(false);	
}

function initializeCoordinates() {
	//alert('#51# '+document.homesearchform.x_min.value);
	if(document.homesearchform.road.value != ""){
		var value = document.getElementById("road").value;
		var thething = value.split(";");
		var extent = new KrakMap.Extent(thething[4], thething[5], thething[2], thething[3]);
		tileMap.setMapViewExtent(extent);
		lastZoomLevel = tileMap.getZoomLevel();
		updateCoordinatesInForm();
	} else if(document.homesearchform.location.value != ""){
		var value = document.getElementById("location").value;
		var thething = value.split(";");
		var extent = new KrakMap.Extent(thething[4], thething[5], thething[2], thething[3]);
		tileMap.setMapViewExtent(extent);
		lastZoomLevel = tileMap.getZoomLevel();
		updateCoordinatesInForm(); 
	} else if (document.homesearchform.x_min.value != "") {
		var top = parseInt(document.getElementById('y_max').value) - 1 ;
		var bottom = parseInt(document.getElementById('y_min').value) + 1;
		var left = parseInt(document.getElementById('x_min').value) + 1;
		var right = parseInt(document.getElementById('x_max').value) - 1;
		var extent = new KrakMap.Extent(top, bottom, left,right);
		tileMap.setMapViewExtent(extent);
		lastZoomLevel = tileMap.getZoomLevel();
		if (isExtendedSearch){		
			updateCoordinatesInForm();
		}
	} else { // DEFAULT
		if (isExtendedSearch){		
			var coord = new KrakMap.Coordinate(66200, 6223000);
			tileMap.setMapViewCenter(coord);			
			updateCoordinatesInForm();
		} else {
			tileMap.setZoomLevel(lastZoomLevel);
		}
	}
}

function updateCoordinatesInForm() {
	if (tileMap) {
		var coords = tileMap.getMapViewExtent();
		
		if (lastZoomLevel <13 || isExtendedSearch) {
			document.getElementById('x_min').value = coords.left;
			document.getElementById('x_max').value = coords.right;
			document.getElementById('y_min').value = coords.bottom;
			document.getElementById('y_max').value = coords.top;
		} else {
			clearCoordinatesInForm();
		}
	}
}

function clearCoordinatesInForm() {
	document.getElementById('x_min').value = '';
	document.getElementById('x_max').value = '';
	document.getElementById('y_min').value = '';
	document.getElementById('y_max').value = '';
}

function clearLocations() {
	var input = document.getElementById('hvor');
	input.value = document.getElementById('locationdefault').value;
	input = document.getElementById('vej');
	input.value = document.getElementById('roaddefault').value;
	input = document.getElementById('location');
	input.value = '';
	input = document.getElementById('road');
	input.value = '';
	updateCoordinatesInForm();
}

function resetSagsnummer(defaultValue){
	if(document.homesearchform.sagsnummer.value != "" && document.homesearchform.sagsnummer.value != defaultValue){
		document.homesearchform.sagsnummer.value = defaultValue;
	}
}

function submitenter(myfield,e, nomap)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13)
   	{
  		if(document.homesearchform.sagsnummer.value != "" && document.homesearchform.sagsnummer.value != 'Indtast sagsnummer'){
			doSearchSagsnummer(nomap);
			return false;
		}
   		return true;
   	}
	else{
   		return true;
   		}
}

function doSearchSagsnummer(nomap){
	if(document.homesearchform.sagsnummer.value != "" && document.homesearchform.sagsnummer.value != 'Indtast sagsnummer'){	
		var sagsnummer = document.homesearchform.sagsnummer.value;		
		window.open('/sag/'+sagsnummer.replace(/^\s\s*/, '').replace(/\s\s*$/, '')+"?fromdoSagsnummer=true", '_top');	
	}else{
		doListSearch();
	}	
}

function doListSearch(){
	
	var theform = document.getElementById('homesearchform');
	
	for (i=0;i<theform.ejendomstype.length;i++){		
		if (theform.ejendomstype[i].checked){			
			houseTypeSelected = true;			
			break;
		}
	}
				
	// we do not check for houseTypeSelected, since we do not care whether there are houses 
	// selected or not in order to show the result list
	if(document.getElementById("showlist").className == "redbutton") {
		document.homesearchform.action="/search/doSearch";
		document.homesearchform.submit();
	} 
		
}

function showmap(){

	if(document.homesearchform.location.value != ""){
		var coord = document.homesearchform.location.value.split(";");			
		document.homesearchform.x_min.value = coord[2];
		document.homesearchform.x_max.value = coord[3];
		document.homesearchform.y_max.value = coord[4];
		document.homesearchform.y_min.value = coord[5];	
	} else if(document.homesearchform.road.value != ""){
		var coord = document.homesearchform.road.value.split(";");
		document.homesearchform.x_min.value = coord[2];
		document.homesearchform.x_max.value = coord[3];
		document.homesearchform.y_max.value = coord[4];
		document.homesearchform.y_min.value = coord[5];
	}
	
	document.homesearchform.action="/index.jsp";
	document.homesearchform.fromVisKort.value = "true";
	document.homesearchform.submit();	
}

function getRequestParamsForSimpleSearch() {
	var tempRequestString = "";
	var value = document.homesearchform.maxPrice.value;
	if(value != "" && value != "Evt. til"){
		tempRequestString = tempRequestString + "&maxPrice="+value;
	}
	value = document.homesearchform.minPrice.value;
	if(value != "" && value != "Evt. fra"){
		tempRequestString = tempRequestString + "&minPrice="+value;
	}
	value = document.homesearchform.minSize.value;
	if(value != "" && value != "Evt. fra"){
		tempRequestString = tempRequestString + "&minSize="+value;
	}
	value = document.homesearchform.maxSize.value;
	if(value != "" && value != "Evt. til"){
		tempRequestString = tempRequestString + "&maxSize="+value;
	}
	value = document.homesearchform.location.value;
	if (value != "") {
		tempRequestString = tempRequestString + "&location="+value;
	}
	value = document.homesearchform.road.value;
	if (value != "") {
		tempRequestString = tempRequestString + "&road="+value;
	}
	
	if (lastZoomLevel < 13 || !isMapSearch) {
		tempRequestString += "&x_min="+document.homesearchform.x_min.value;
		tempRequestString += "&x_max="+document.homesearchform.x_max.value;
		tempRequestString += "&y_min="+document.homesearchform.y_min.value;
		tempRequestString += "&y_max="+document.homesearchform.y_max.value;
	}	
	var theform = document.getElementById('homesearchform');
	for (i=0;i<theform.ejendomstype.length;i++){
		if (theform.ejendomstype[i].checked){
			houseTypeSelected = true;
			tempRequestString = tempRequestString +"&ejendomstype="+ theform.ejendomstype[i].value;
			
		}
	 }
	return tempRequestString;
	
}

function doAjaxSearch(onload){ //alert('#100# onload='+onload);
	searchInAction = true;	
	
	//if the search is coming from the load function we don't search on case number  
	if(onload == false && document.homesearchform.sagsnummer.value != "" && document.homesearchform.sagsnummer.value != 'Indtast sagsnummer'){		
		searchInAction = false;
		doSearchSagsnummer(false);
		return;
	} else if(onload){//reset case number	
		resetSagsnummer('Indtast sagsnummer')
	}
	var tempRequestString = getRequestParamsForSimpleSearch();
	
	//alert('#314 start some kind of search: '+tempRequestString);
	var value = "";
	if (isExtendedSearch) {
		
		value = document.homesearchform.grundareal_fra.value; 
		if(value != "" && !isNaN(parseInt(value))){
			tempRequestString += "&grundareal_fra="+value;
		}
		value = document.homesearchform.grundareal_til.value; 
		if(value != ""  && !isNaN(parseInt(value))){
			tempRequestString += "&grundareal_til="+value;
		}
		if(document.homesearchform.garage.checked){
			tempRequestString += "&garage="+document.homesearchform.garage.value;
		}
		if(document.homesearchform.gaardmiljoe.checked){
			tempRequestString += "&gaardmiljoe="+document.homesearchform.gaardmiljoe.value;
		}
		if(document.homesearchform.bindingsvaerk.checked){
			tempRequestString += "&bindingsvaerk="+document.homesearchform.bindingsvaerk.value;
		}
		if(document.homesearchform.studie_egnet.checked){
			tempRequestString += "&studie_egnet="+document.homesearchform.studie_egnet.value;
		}
		if(document.homesearchform.altan_terasse.checked){
			tempRequestString += "&altan_terasse="+document.homesearchform.altan_terasse.value;
		}
		if(document.homesearchform.husdyr_hold.checked){
			tempRequestString += "&husdyr_hold="+document.homesearchform.husdyr_hold.value;
		}
		if(document.homesearchform.patriciervilla.checked){
			tempRequestString += "&patriciervilla="+document.homesearchform.patriciervilla.value;
		}
		if(document.homesearchform.elevator.checked){
			tempRequestString += "&elevator="+document.homesearchform.elevator.value;
		}
		if(document.homesearchform.pool.checked){
			tempRequestString += "&pool="+document.homesearchform.pool.value;
		}
		if(document.homesearchform.haandvaerkertilbud.checked){
			tempRequestString += "&haandvaerkertilbud="+document.homesearchform.haandvaerkertilbud.value;
		}
		if(document.homesearchform.house_exchange.checked) {
			tempRequestString += "&house_exchange="+document.homesearchform.house_exchange.value;
		}
		if(document.homesearchform.aabenthustab.checked) {			
			tempRequestString += "&aabenthustab="+document.homesearchform.aabenthustab.value;
		}			
		
		var theform = document.getElementById('homesearchform');
		for (i = 0; i < theform.length; i++){
			if (theform[i].name == 'prisniveau'){
				if(theform[i].checked){
					tempRequestString += "&prisniveau=" + theform[i].value;
					}
			}
		}
		for (i = 0; i < theform.length; i++){
			if (theform[i].name == 'ant_vaer_fra'){
				
				if(theform[i].checked){
						tempRequestString += "&ant_vaer_fra=" + theform[i].value;
					}
			}
		}
		value = document.homesearchform.byggeaar_fra.value; 
		if(value != "" && !isNaN(parseInt(value))){
			tempRequestString += "&byggeaar_fra=" + value;
		}
		value = document.homesearchform.byggeaar_til.value; 
		if(value != "" && !isNaN(parseInt(value))){
			tempRequestString += "&byggeaar_til=" + value;
		}
		value = document.homesearchform.etage_fra.value; 
		if(value != "" && !isNaN(parseInt(value))){
			tempRequestString += "&etage_fra=" + value;
		}
		value = document.homesearchform.etage_til.value;
		if(value != "" && !isNaN(parseInt(value))){
			tempRequestString += "&etage_til=" + value;
		}
		value = document.homesearchform.ant_vaer_fra.value;
		if (value != "" && !isNaN(parseInt(value))) {
			tempRequestString += "&ant_vaer_fra=" + value;
		}			
		value = document.homesearchform.ant_vaer_til.value;
		if (value != "" && !isNaN(parseInt(value))) {
			tempRequestString += "&ant_vaer_til=" + value;
		}	
		value = document.homesearchform.ant_toil_fra.value; 
		if(value != "" && !isNaN(parseInt(value))){
			tempRequestString += "&ant_toil_fra=" + value;
		}
		value = document.homesearchform.ant_toil_til.value; 
		if(value != "" && !isNaN(parseInt(value))){
			tempRequestString += "&ant_toil_til=" + value;
		}
		value = document.homesearchform.ant_plan_fra.value; 
		if(value != "" && !isNaN(parseInt(value))){
			tempRequestString += "&ant_plan_fra=" + value;
		}
		value = document.homesearchform.ant_plan_til.value; 
		if(value != "" && !isNaN(parseInt(value))){
			tempRequestString += "&ant_plan_til=" + value;
		}
		value = document.homesearchform.omb_fra.value;
		if(value != "" && !isNaN(parseInt(value))){
			tempRequestString += "&omb_fra=" + value;
		}
		value = document.homesearchform.omb_til.value; 
		if(value != "" && !isNaN(parseInt(value))){
			tempRequestString += "&omb_til=" + value;
		}
		value = document.homesearchform.closeto_skole.value; 
		if(value != "" && !isNaN(parseInt(value))){
			tempRequestString += "&closeto_skole="+value;
		}
		value = document.homesearchform.closeto_transport.value; 
		if(value != "" && !isNaN(parseInt(value))){
			tempRequestString += "&closeto_transport="+value;
		}
		value = document.homesearchform.closeto_indkoeb.value; 
		if(value != "" && !isNaN(parseInt(value))){
			tempRequestString += "&closeto_indkoeb="+value;
		}
		value = document.homesearchform.closeto_skov.value; 
		if(value != "" && !isNaN(parseInt(value))){
			tempRequestString += "&closeto_skov="+value;
		}
		value = document.homesearchform.closeto_vand.value; 
		if(value != "" && !isNaN(parseInt(value))){
			tempRequestString += "&closeto_vand="+value;
		}
		value = document.homesearchform.fritekst.value; 
		if(value != 'Indtast søgeord' && value.length >= 3){
			tempRequestString += "&fritekst="+escape(value);
		}	
	}	
	
	requestString = "?" + tempRequestString;
	if (!isExtendedSearch) {
		requestString = requestString+"&prisniveau=Udbetaling";
	}
	
	//alert('#433: '+requestString+'\n'+oldRequestString);
	searchChanged = requestString != oldRequestString;	
	
	if (houseTypeSelected && searchChanged) {	
		
		oldRequestString = requestString;		
		postSearch();
	} else {	
		
		if (!houseTypeSelected) {	
			
			oldRequestString = requestString;			
			handleEmptyHousetype();
			postSearch();
		}
		
		clearSearch();
	}
	
}

	
function clearSearch() {
	
	searchInAction = false;
	houseTypeSelected = false;
	
	
	
		if (document.getElementById('mapwait')) {
			document.getElementById('mapwait').style.display = 'none';
		}
		
	
}

function postSearch(){
	
	var saveCookie = '&saveCookie=1';
	if (cookieSearch == 1) {
		savecookie = '&saveCoookie=0';
	}
	//alert('#352# '+isExtendedSearch+' '+isMapSearch);
	var includesMap = false;
	if (isExtendedSearch || isMapSearch) {
		//if (searchChanged || poiAdded) {
		
		if (document.getElementById('mapwait')!=null) {
    	 document.getElementById('mapwait').style.display = 'block';
		}		
		//}
		includesMap = true;
	}
	if(document.homesearchform.sagsnummer.value != "" && document.homesearchform.sagsnummer.value != 'Indtast sagsnummer'){		
		xmlPost("/search/mapSearch/sagsnummer","sagsnummer="+document.homesearchform.sagsnummer.value+saveCookie,searchResultAnswer);
	}else{
		
		
		var r = includesMap ? requestString+"&zoom="+tileMap.getZoomLevel() : requestString;
		r = r +"&sogeEksakt=true"+saveCookie;
		uri = includesMap ? "/search/mapSearch" : "/search/mapSearch/onthefly";
		//alert('#204# searchResultAnswer'+searchResultAnswer);
		xmlPost(uri,r,searchResultAnswer);
		//alert('#380# '+uri+' '+r);
	}
}

function searchResultAnswer() {
	if (req.readyState == 4) {
		if (req.status == 200) { 
			if(searchPending){ //alert('#183# '+searchPending)
				searchPending = false;
				doAjaxSearch(false);
			}
			var text = req.responseText; //alert('#422# '+text);
			if (text) {
				parseSearchResult(text);
			}
		}
	}
}


function startSearch(nomap){
	
	if (!nomap) {		
		updateCoordinatesInForm();	}
	if (searchInAction) { //alert('#187# searchInAction='+searchInAction);		
		searchPending = true;
	} else {				
		doAjaxSearch(false);
	}
	if (nomap) {	
		//redbutton_disabled		
		document.getElementById("showlist").className = "redbutton";
	}else if (isMapSearch) {		
		resetMarketinfo();
	}	
}


function handleEmptyHousetype() {	
	
	if(poiAdded){
		removeAllPoi();
	} 
	if (tileAdded) {
		tileMap.removeTileLayer('tileLayerResults');
		tileAdded = false;
	}
	resetOnthefly();	
}


/* ON THE FLY PANEL FUNCTIONS */
function resetOnthefly(){
	var onthe = document.getElementById('onthefly');
	var formattedCount = '2.345';
	var antalBoliger = document.getElementById('forsideAntalBoliger');
	onthe.innerHTML = '<div style="font-size: 9px; color: #7c7c7c; font-weight: bold;float:left">Der er i alt&nbsp;<span style="color:#cc0000"><b>'+numbersOfBoliger+'</b></span> boliger</div>';	
	if (antalBoliger!=null) {
		antalBoliger.innerHTML = '<span style="color:#cc0000;"><b>'+numbersOfBoliger+' boliger</b></span>';
	}
	}

function updateOnthefly(count) {
	//alert('#555# ['+count+']');
	var formattedCount = count < 1000 ? count : createDecimalSep(count);
	//alert('#449# updateOnthefly ['+formattedCount+']['+numbersOfBoliger+']');
	if (count < numbersOfBoliger*1000) {
		var onthe = document.getElementById('onthefly');

		if(count == 1){
			onthe.innerHTML = '<div style="font-size: 9px; color: #7c7c7c; font-weight: bold;float:left"><b>'+formattedCount+'</b></span> bolig ud af <span style="color:#cc0000;"><b>'+numbersOfBoliger+'</b></span></div>';
		}else{
			onthe.innerHTML = '<div style="font-size: 9px; color: #7c7c7c; font-weight: bold;float:left"><b>'+formattedCount+'</b></span> boliger ud af <span style="color:#cc0000;"><b>'+numbersOfBoliger+'</b></span></div>';
		}
	} else {
		resetOnthefly();// alert('#573# resetOnthefly()');
	}	
}

/* PARSING FUNCTIONS */

function parseSearchResult(xml)  {
	var count = numbersOfBoliger; 
	
	try {//Internet Explorer
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async="false";
		xmlDoc.loadXML(xml);
	}
	catch(e) {
		try { //Firefox, Mozilla, Opera, etc.
			parser=new DOMParser();
			xmlDoc=parser.parseFromString(xml,"text/xml");
	  	}
	  	catch(e) { alert('#314# '+e.description);
	  		clearSearch();
	  		return;
	  	}
	}
	var i = 0;
	try { // alert('#598# xml:\n'+xml);
		updateOnthefly(xmlDoc.getElementsByTagName("count")[0].childNodes[0].nodeValue);
	}
	catch(e) {
		//alert("#324# updateOnthefly: "+e.description); alert('#324# xml:\n'+xml);
	}
	var root = xmlDoc.getElementsByTagName('boliger')[0];
	
	if(poiAdded){
		removeAllPoi();
	} //alert('#562# '+lastZoomLevel);
	if (root) { // we have a result, i.e. pois should be added
		try { //alert('#326# there was a root');
			var items = root.getElementsByTagName("bolig");
			if (lastZoomLevel < 13) {
				for ( i  ; i < items.length ; i++) {
					markAdded = i;
					// get one item after another
					var bolig = items[i];
					// now we have the item object, time to get the contents
					// get the name of the item
					var ejendomstype = bolig.getElementsByTagName("ejendomstype")[0].firstChild != null ? bolig.getElementsByTagName("ejendomstype")[0].firstChild.nodeValue : "";
					var sagsid = bolig.getElementsByTagName("sagsid")[0].firstChild != null ? bolig.getElementsByTagName("sagsid")[0].firstChild.nodeValue : "";
					var sagsnummer = bolig.getElementsByTagName("sagsnummer")[0].firstChild != null ? bolig.getElementsByTagName("sagsnummer")[0].firstChild.nodeValue : "";				
					var x = bolig.getElementsByTagName("x-koordinater")[0].firstChild != null ? bolig.getElementsByTagName("x-koordinater")[0].firstChild.nodeValue : "";
					var y = bolig.getElementsByTagName("y-koordinater")[0].firstChild != null ? bolig.getElementsByTagName("y-koordinater")[0].firstChild.nodeValue : "";
					var url = bolig.getElementsByTagName("url")[0] != null ? bolig.getElementsByTagName("url")[0].firstChild.nodeValue : "";						
					var sameCoordFound = false;
					var sameSagsid = sagsid+';';
					var sameEjendomstype = ejendomstype+';';
					try{
						var sameCoord = bolig.getElementsByTagName("same_coord");
						
						if (sameCoord.length > 0) {
							var sameElements = sameCoord[0].getElementsByTagName("same");					
							for (var j = 0  ; j < sameElements.length ; j++) {
								var same = sameElements[j];
								sameSagsid += same.getElementsByTagName("same_sagsid")[0].firstChild != null ? same.getElementsByTagName("same_sagsid")[0].firstChild.nodeValue : "";
								sameSagsid += j < sameElements.length-1 ? ';' : '';  
								sameEjendomstype += same.getElementsByTagName("same_ejendomstype")[0].firstChild != null ? same.getElementsByTagName("same_ejendomstype")[0].firstChild.nodeValue : ""; 
								sameEjendomstype += j < sameElements.length-1 ? ';' : '';
								sameCoordFound = true;
							}
						}
					}catch(e){
						//alert('#360# '+e.description);
						sameCoordFound = false;
					} //alert('#362# '+i);
					if(sameCoordFound){
						addSamemark(x, y, i, ejendomstype, sameEjendomstype, sameSagsid);
						sameSagsid = '';
						sameEjendomstype = '';
					}else{
						
						addmark(x , y , ejendomstype, sagsid, sagsnummer , i, url);
					}
					poiAdded = true;
				}
			}
			
			if(tileAdded){
				tileMap.removeTileLayer('tileLayerResults');
				tileAdded = false;
			}
		}
		catch(e) {
			//alert('#379# '+e.description);
		}
	} else {
		//alert('#382# show tiles '+lastZoomLevel+' : '+tileMap.getZoomLevel());
		try {
			if (searchChanged && tileAdded) {
				tileMap.removeTileLayer('tileLayerResults');
				tileAdded = false;
			}
			if (lastZoomLevel < 13) {
				var x = tileMap.getMapViewExtent();
				if (!tileAdded) {
					var d = new Date();
					tileMap.addTileLayer('tileLayerResults', 0, '/maptileprovider?x=#LEFT#&y=#BOTTOM#&zoom=#MPP#&time='+d.getTime());
					tileAdded = true;
				} 
				//alert('#255# can this be false? '+tileAdded)
				if (tileAdded) {
					tileMap.redrawGrid();
				}
			}
		} 
		catch(e) {
			tileMap.redrawGrid(); //alert"#370# "+e.description);
		}
	}
	//alert('#406# almost done')
	searchChanged = false;
	clearSearch();	//alert('#409# done')
}

/* POI HANDLING */

function addmark(x,y,ejendomstype, sagsid, sagsnummer,id, url)  {
	tileMap.removePoi("info_"+id);
	var poi = createPOI(id,ejendomstype,x,y, sagsid, sagsnummer, url);
	var coord = new KrakMap.Coordinate(x, y);
	var poi2 = new KrakMap.Poi(poi, coord, "resultset", 17, 17);
	tileMap.addPoi(poi2);
}

function createPOI(i,ejendomstype, x, y, sagsid, sagsnummer, url) {
	
	var newdiv = document.createElement("div");
	newdiv.setAttribute("id","info_"+i);
	var name = 'info_'+i;		
	
	imageName = findEjendomsTypeImage(ejendomstype) + iconSuffix;
	
	var onclickAction;
	
	if (url) {	
		onclickAction = "window.open(\'"+urldecodeing(url)+"\');";	
	} else {
		onclickAction = "gotoSag(\'"+urldecodeing(sagsnummer)+"\')";		
	}
	
	newdiv.innerHTML = '<div id="'+name+'" style="position:relative; z-index: 5" onclick="javaScript:showInfoLayer('+sagsid+',this, event);"><img style="cursor: pointer" src="/graphics/icons/'+imageName+'" border="0"></div>';
	return newdiv;
}

function addSamemark(x,y,id,ejendomstype, sameEjendomstype, sameSagsid)  {
	var poi = createPOISame(id, ejendomstype, x,y, sameSagsid, sameEjendomstype);
	var coord = new KrakMap.Coordinate(x, y);
	var poi2 = new KrakMap.Poi(poi, coord, "resultset", 17, 17);
	tileMap.addPoi(poi2);
}

function createPOISame(i,ejendomstype,x , y, sagsnummerArray, ejendomstypeArray){
	var newdiv = document.createElement("div");
	newdiv.setAttribute("id","info_"+i);
	var name = 'info_'+i;
	var imageName = findEjendomsTypeImage(ejendomstype) + iconSuffix;
	newdiv.innerHTML = '<div id="'+name+'" style="cursor: pointer; position:relative; z-index: 6" onclick="JavaScript:openPOISame('+x+','+y+',\''+sagsnummerArray+'\',\''+ejendomstypeArray+'\', event);"><img src="/graphics/icons/'+imageName+'" border="0"></div>';
	//newdiv.innerHTML = '<div id="'+name+'" onmouseover="JavaScript:showSameInfoLayer();" onmouseout="JavaScript:removeInfo()"><img src="/graphics/icons/'+imageName+'.png" border="4"></div>';
	
	return newdiv;	
}

function removeAllPoi(){
	tileMap.removeAllPoi('resultset');
	tileMap.removeAllPoi('info_category');
	poiAdded = false;
}

/* HANDLING POI INFO */

function closeInfoFromMap(e) {
	var containerDiv = document.getElementById('infoDivContainer');	
	if (!containerDiv) closeInfoSame();
	removeInfo();	
	
	//try{	
	//	tileMap.removePoi("sameInfo"+samePoiId);		
	//} catch(e){}	
	if (document.getElementById("marketinfo")) {	
		document.getElementById("marketinfo").style.display = "block";		
	}	
}

function stopMouseUpEvent(e) {	
	if (!e) var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();	
}

function showInfoLayer(sagsid, poi, e){

	if(!searchInAction){
		var tg = (window.event) ? e.srcElement : e.target;
		try{
			removeInfo();
		}catch(e){}
		closeInfoSame();			
		poiId = tg.parentNode.id;	
		xmlPost("/search/mapSearch/info","sagsid="+sagsid,getInfo);
	}
}

function closeInfoSame(){	
	removeInfo();		
	try{	
		tileMap.removePoi("sameInfo"+samePoiId);		
	} catch(e){}	
	if (document.getElementById("marketinfo")) {	
		document.getElementById("marketinfo").style.display = "block";		
	}
}

function removeInfo(){	
	try{ tileMap.removePoi("triangle"); }catch(e){}
	try{ tileMap.removePoi("infoDivContainer");}catch(e){}	
	if (document.getElementById("marketinfo")) {	
		document.getElementById("marketinfo").style.display = "block";		
	}
}

function closeInfoPopup(e) {		
	removeInfo();	
	if (document.getElementById("marketinfo")) 	document.getElementById("marketinfo").style.display = "block";	
	if (e.stopPropagation) e.stopPropagation();
}

function getInfo(){

	if (req.readyState == 4) {
		if (req.status == 200) {
			var result = req.responseText;
			var infoLayer = parseInfoXML(result);
			addInfoLayer(infoLayer);
		} else {
			document.getElementById('mapwait').style.display = 'none';
		}
	}
}

function getInfoSame(){
	if (req.readyState == 4) {
		if (req.status == 200) {
			var result = req.responseText;
			var infoLayer = parseInfoXML(result);
			infoLayer.x = xCoord;
			infoLayer.y = yCoord;
			infoLayer.xPre = xPreCoord;
			infoLayer.yPre = yPreCoord;
			addInfoLayerSame(infoLayer);
		} else {
			document.getElementById('mapwait').style.display = 'none';
		}
	}
}

function showInfoLayerSame(x, y, sagsid, poi, e){
	var tg = (window.event) ? e.srcElement : e.target;
	try{
		removeInfo();
	}catch(e){}
	poiId = tg.parentNode.id;
	xCoord = x;
	yCoord = y;
	xPreCoord = x;
	yPreCoord = y;
	xmlPost("/search/mapSearch/info","sagsid="+sagsid, getInfoSame);	
}

function openPOISame(x,y, sagsnummerArray, ejendomstypeArray, e) {
	closeInfoSame();			
	var tg = (window.event) ? e.srcElement : e.target;		
	var targetPoiId = tg.parentNode.id != undefined ? tg.parentNode.id : "";

	try{tileMap.removePoi("infoDivContainer");}catch(e){}
		
	var metersPerPixel = tileMap.getMetersPerPixel();	
	var xInfoLayer;
	var yInfoLayer;	
	var newdiv = document.createElement("div");
	newdiv.id = "sameInfo" + targetPoiId;
	newdiv.className = "sameInfo";	
	newdiv.style.zIndex = "100";
	newdiv.style.width = "48px";	
	newdiv.style.padding = "7px";			
	newdiv.style.position = "absolute";	
	newdiv.style.zIndex = 9;	
		
	var sameEjendomstype = ejendomstypeArray.split(";");
	var sameSagsid = sagsnummerArray.split(";"); 
	var sameInfoHeight = sameEjendomstype.length*(24) + 12+12;	
	var mapViewExtent = tileMap.getMapViewExtent();		
	var yInPixels = (y - mapViewExtent.bottom) / metersPerPixel;
	var xInPixels = (x - mapViewExtent.left) / metersPerPixel;
		
	if (yInPixels < sameInfoHeight) {
		yInPixels += sameInfoHeight - yInPixels;			
	}
	
	yInPixels += 19;// sameInfo hæves lidt!	
	xInPixels -= 19;// sameInfo rykkes til venstre!
	
	y = yInPixels*metersPerPixel + mapViewExtent.bottom;
	x = xInPixels*metersPerPixel + mapViewExtent.left;
		
	var temp = "";	
	temp += '<table onmouseup="stopMouseUpEvent(event)" cellspacing="0" cellpadding="0" border="0" class="sameInfoTable" id="sameInfoTable'+targetPoiId+'">';
	temp +=	'<tr><td class="topLeftCorner"></td><td class="topLine"></td><td class="topRightCorner"></td></tr>';
	temp +=	'<tr><td class="lineLeft"></td>';
	temp += '<td style="background-color: transparent"><table cellpadding="0" cellspacing="0">';

	yInPixels += 0; //justering af infolayer!
	xInPixels += 17;
		
	var xInfoLayer = xInPixels*metersPerPixel + mapViewExtent.left;
	
	for(var j = 0; j < sameEjendomstype.length; j++){
		yInPixels -= 24;	
		yInfoLayer = yInPixels*metersPerPixel + mapViewExtent.bottom;
		temp +='<tr><td style="cursor: pointer; background-color: #ffffff" id="sameInfo_'+j+'" class="POI" onclick="JavaScript:showInfoLayerSame('+xInfoLayer+','+yInfoLayer+','+sameSagsid[j]+', this, event);"><img src="/graphics/icons/'+findEjendomsTypeImage(sameEjendomstype[j])+iconSuffix+'" border="0"></td></tr>';
	}

	temp += '</table></td>';
	temp += '<td class="lineRight"></td></tr><tr><td class="sameBottomLeftCorner"></td>';
	temp +=	'<td class="sameBottomLine"></td><td class="sameBottomRightCorner"></td></tr></table>';
	//temp += '</div>';
	newdiv.innerHTML = temp;
			
	var coord = new KrakMap.Coordinate(x, y);
	var poi2 = new KrakMap.Poi(newdiv, coord, "info_category", 1, 1);
	tileMap.addPoi(poi2);
	
	samePoiId = tg.parentNode.id;	
}

function addInfoLayer(infoLayer) {
	var x = infoLayer.x;
	var y = infoLayer.y;
	var xPre = infoLayer.xPre; 
	var yPre = infoLayer.yPre;
	var infoLayerDiv = infoLayer.infoLayerDiv;
	var sagsnummer = infoLayer.sagsnummer;
	var url = infoLayer.url;	
	var mapViewExtent = tileMap.getMapViewExtent();										
	var mapViewHeight = mapViewExtent.top - mapViewExtent.bottom;
	var mapViewWidth = mapViewExtent.right - mapViewExtent.left;
	var metersPerPixel = tileMap.getMetersPerPixel();	
	var xInPixels =  (x - mapViewExtent.left) / metersPerPixel;	
	var xInPixelsPre = xInPixels;
	var yInPixels = (y - mapViewExtent.bottom) / metersPerPixel;	
	var yInPixelsPre = yInPixels;
	var marketInfoHeight = 0;
	var isInMiddle = false;
	if (document.getElementById("marketinfo")) {	
		marketInfoHeight = document.getElementById("marketinfo").offsetHeight;
	}
	if (mapViewHeight/metersPerPixel == 383) {//Frontpage search
		var mapWidthInPixels = 609;
		var mapHeightInPixels = 383;
		if (xInPixelsPre < (mapWidthInPixels - 350)) {//info på højre side af POI				
			xInPixels += 18;																			
		} else if (xInPixelsPre > (mapWidthInPixels - 270)) {//info på venstre side af POI					
			xInPixels -= 343;																		
		} else {//info i midten af POI				
			isInMiddle = true;
			xInPixels -= 180;								
		}
		
		if (!isInMiddle) {
			if (yInPixels < 50) {						
				yInPixels += 200;
			} else if (yInPixels < (mapHeightInPixels - 238)) {					
				yInPixels += 180;
			} else if (yInPixels > 343) {				
				yInPixels += 20;	
			} else if (yInPixels > 238) {					
				yInPixels += 40;	
			} else if (yInPixels > (mapHeightInPixels - 238) && yInPixels < 238) { 				
				yInPixels += 100;		
			}
		} else {
			if (yInPixels < (mapHeightInPixels - 220)) { 
				yInPixels +=230;			
			} else if (yInPixels > 220) { 											
				yInPixels -= 10;
			} else {
				yInPixels += 100;
			}		
		}	
		
		var triangle = document.createElement('div');	
		triangle.id = "triangle";				
		triangle.style.width = "27px";
		triangle.style.height = "16px";
		triangle.style.backgroundColor = "transparent";	
		triangle.style.position = "relative";				
		triangle.style.zIndex = "10009";
		triangle.style.cursor = "pointer";		
		
		
		if (sagsnummer) {
			triangle.setAttribute("onclick", "gotoSag('"+urldecodeing(sagsnummer)+"')");		
		} else if (url) {
			triangle.setAttribute("onclick", "window.open('"+urldecodeing(url)+"')");	
		}
		
				
		coord = new KrakMap.Coordinate(xPre, yPre);						
		var poiTriangle;
		
		if (!isInMiddle) {	
			if (xInPixelsPre < (mapWidthInPixels - 350)) {	
				triangle.style.paddingLeft = "12px";
				triangle.innerHTML = "<img src='/graphics/infoLagArrowLeft2.png'>";					
				poiTriangle = new KrakMap.Poi(triangle,coord,'info_category', 1, 12);				
			} else {
				triangle.innerHTML = "<img src='/graphics/infoLagArrowHojre2.png'>";					
				poiTriangle = new KrakMap.Poi(triangle,coord,'info_category',33, 12);
			}
		} else {
			if (yInPixelsPre < (mapHeightInPixels - 220)) { 				
				triangle.innerHTML = "<img src='/graphics/infoLagArrowDown2.png'>";	
				poiTriangle = new KrakMap.Poi(triangle,coord,'info_category',13, 37);
			} else if (yInPixelsPre > 210) { 		
				triangle.style.paddingTop = "8px";			
				triangle.innerHTML = "<img src='/graphics/infoLagArrowUp2.png'>";	
				poiTriangle = new KrakMap.Poi(triangle,coord,'info_category',13, 1);
			}			
		}		
		
	} else if (mapViewHeight/metersPerPixel == 536) {//Extended search
		var mapWidthInPixels = 365;
		var mapHeightInPixels = 536;
		
		if (yInPixels < 230) {//info over POI		
			var useragent = navigator.userAgent;
			if (useragent.indexOf("MSIE 8.0") != -1 || useragent.indexOf("Firefox") != -1) {//IE 
				yInPixels += 230;						
			} else { //FF
				yInPixels += 238;
			}
																		
		} else {//info under POI		
			yInPixels -= 9;					
		}
		
		if (xInPixels < 10) {		
			xInPixels -= 10;
		} else if (xInPixels < (mapWidthInPixels - 334)) {		
			xInPixels -= 20;
		} else if (xInPixels > 355) {	
			xInPixels -= 355;	
		} else if (xInPixels > 300) {			
			xInPixels -= 300;	
		} else if (xInPixels > (mapWidthInPixels - 334) && xInPixels < 300) {	
			xInPixels = 0;	
		} 
		
		var triangle = document.createElement('div');	
		triangle.id = "triangle";				
		triangle.style.width = "16px";
		triangle.style.height = "27px";
		triangle.style.backgroundColor = "transparent";	
		triangle.style.position = "relative";				
		triangle.style.zIndex = "10009";
		triangle.style.cursor = "pointer";		
		
		if (sagsnummer != null) {		
			triangle.setAttribute("onclick", "gotoSag('"+urldecodeing(sagsnummer)+"')");		
				
		} else if (url != null) {
			triangle.setAttribute("onclick", "window.open('"+urldecodeing(url)+"')");	
		}					
		
		var poiTriangle;
		
		if (yInPixelsPre < 230) {			
			yInPixelsPre += 18;						
			triangle.innerHTML = "<img src='/graphics/infoLagArrowDown2.png'>";									
		} else {			
			triangle.style.paddingTop = "8px";			
			triangle.innerHTML = "<img src='/graphics/infoLagArrowUp2.png'>";											
		}
		
		xInPixelsPre -= 5;		
		
		xPre = xInPixelsPre * metersPerPixel + mapViewExtent.left;
		yPre = yInPixelsPre * metersPerPixel + mapViewExtent.bottom;
		coord = new KrakMap.Coordinate(xPre, yPre);				
		poiTriangle = new KrakMap.Poi(triangle,coord,'info_category',1, 1);		
	}
		
		x = xInPixels * metersPerPixel + mapViewExtent.left;
		y = yInPixels * metersPerPixel + mapViewExtent.bottom;
		var coord = new KrakMap.Coordinate(x, y);								
		var poitemp = new KrakMap.Poi(infoLayerDiv,coord,'info_category',1,1);
		
		tileMap.addPoi(poitemp);	
		tileMap.addPoi(poiTriangle);
}

function gotoSag(sagsnummer){
	location.href = '/sag/'+sagsnummer + '?frommap=true';	
}
function gotoSagOnlyLeje(sagsnummer){

	location.href = '/sag/'+sagsnummer + '/tilleje?frommap=true';	
}
function gotoSagProjektLeje(oid){

	location.href = '/get/'+oid+'.html?lejeboliger=1';	
}

function addInfoLayerSame(infoLayer) {
	var x = infoLayer.x;
	var y = infoLayer.y;
	var xPre = infoLayer.xPre;
	var yPre = infoLayer.yPre;
	var infoLayerDiv = infoLayer.infoLayerDiv;
	var sagsnummer = infoLayer.sagsnummer;
	var url = infoLayer.url;	
	var mapViewExtent = tileMap.getMapViewExtent();										
	var mapViewHeight = mapViewExtent.top - mapViewExtent.bottom;
	var mapViewWidth = mapViewExtent.right - mapViewExtent.left;
	var metersPerPixel = tileMap.getMetersPerPixel();	
	var xInPixels =  (x - mapViewExtent.left) / metersPerPixel;	
	var xInPixelsPre = xInPixels;
	var yInPixels = (y - mapViewExtent.bottom) / metersPerPixel;	
	var yInPixelsPre = yInPixels;
	var marketInfoHeight = 0;
	var isInMiddle = false;
	
	if (document.getElementById("marketinfo")) {	
		marketInfoHeight = document.getElementById("marketinfo").offsetHeight;
	}
	
	if (mapViewHeight/metersPerPixel == 383) {//Frontpage search
		var mapWidthInPixels = 609;
		var mapHeightInPixels = 383;
		
		if (xInPixelsPre < (mapWidthInPixels - 360)) {//info på højre side af POI			
			xInPixels += 40;																			
		} else if (xInPixelsPre > 330) {//info på venstre side af POI						
			xInPixels -= 343;								
		} else {//info i midten af POI				
			isInMiddle = true;
			xInPixels -= 170;								
		}
		
		
		if (!isInMiddle) {
			if (yInPixels < 50) { 		
				yInPixels += 200;
			} else if (yInPixels < (mapHeightInPixels - 238)) { 		
				yInPixels += 180;
			} else if (yInPixels > 343) {		
				yInPixels += 20;	
			} else if (yInPixels > 238) {			
				yInPixels += 40;	
			} else if (yInPixels > (mapHeightInPixels - 238) && yInPixels < 238) {
				yInPixels += 100;		
			}
		} else {
			if (yInPixels < (mapHeightInPixels - 220)) {//info over POI 
				yInPixels +=30;							
				yInPixels += 200;
			} else if (yInPixels > 220) {//info under POI 											
				yInPixels -= 10;
			} else {//info over POI
				yInPixels += 100;				
			}		
		}	
		
		var triangle = document.createElement('div');	
		triangle.id = "triangle";				
		triangle.style.width = "27px";
		triangle.style.height = "16px";
		triangle.style.backgroundColor = "transparent";	
		triangle.style.position = "relative";				
		triangle.style.zIndex = "10009";
		triangle.style.cursor = "pointer";		
				
		if (sagsnummer) {		
			triangle.setAttribute("onclick", "gotoSag('"+urldecodeing(sagsnummer)+"')");		
				
		} else if (url) {
			triangle.setAttribute("onclick", "window.open('"+urldecodeing(url)+"')");	
		}	
				
		coord = new KrakMap.Coordinate(xPre, yPre);						
		
		var poiTriangle;
		
		if (!isInMiddle) {		
			if (xInPixelsPre < (mapWidthInPixels - 360)) {	
				triangle.style.paddingLeft = "32px";
				triangle.innerHTML = "<img src='/graphics/infoLagArrowLeft2.png'>";					
				poiTriangle = new KrakMap.Poi(triangle,coord,'info_category', 1, 12);				
			} else {
				triangle.innerHTML = "<img src='/graphics/infoLagArrowHojre2.png'>";					
				poiTriangle = new KrakMap.Poi(triangle,coord,'info_category',33, 12);
			}
		} else {
			if (yInPixelsPre < (mapHeightInPixels - 220)) {	
				triangle.style.paddingLeft = "5px";
				triangle.innerHTML = "<img src='/graphics/infoLagArrowDown2.png'>";	
				poiTriangle = new KrakMap.Poi(triangle,coord,'info_category',1, 35);
			} else if (yInPixelsPre > 220) {			
				triangle.style.paddingTop = "8px";	
				triangle.style.paddingLeft = "5px";
				triangle.innerHTML = "<img src='/graphics/infoLagArrowUp2.png'>";	
				poiTriangle = new KrakMap.Poi(triangle,coord,'info_category',1, 1);
			}			
		}
					
	} else if (mapViewHeight/metersPerPixel == 536) {//Extended search
		var mapWidthInPixels = 365;
		var mapHeightInPixels = 536;
	
		if (yInPixels < 230) {//info over POI		
			yInPixels += 238;																	
		} else {//info under POI		
			yInPixels -= 9;					
		}
		
		if (xInPixels < 10) { 	
			xInPixels -= 10;
		} else if (xInPixels < (mapWidthInPixels - 334)) {		
			xInPixels -= 10;
		} else if (xInPixels > 355) {	
			xInPixels -= 335;	
		} else if (xInPixels > 300) {		
			xInPixels -= 310;	
		} else if (xInPixels > (mapWidthInPixels - 334) && xInPixels < 300) { 			
			xInPixels = 5;	
		} 
		
		var triangle = document.createElement('div');	
		triangle.id = "triangle";				
		triangle.style.width = "16px";
		triangle.style.height = "27px";
		triangle.style.backgroundColor = "transparent";	
		triangle.style.position = "relative";				
		triangle.style.zIndex = "10009";
		triangle.style.cursor = "pointer";		
		
		if (sagsnummer != null) {		
			triangle.setAttribute("onclick", "gotoSag('"+urldecodeing(sagsnummer)+"')");		
				
		} else if (url != null) {
			triangle.setAttribute("onclick", "window.open('"+urldecodeing(url)+"')");	
		}					
		
		var poiTriangle;
						
		if (yInPixelsPre < 230) {			
			yInPixelsPre += 18;						
			triangle.innerHTML = "<img src='/graphics/infoLagArrowDown2.png'>";									
		} else {			
			triangle.style.paddingTop = "8px";			
			triangle.innerHTML = "<img src='/graphics/infoLagArrowUp2.png'>";											
		}
		
		xInPixelsPre += 5;		
		
		xPre = xInPixelsPre * metersPerPixel + mapViewExtent.left;
		yPre = yInPixelsPre * metersPerPixel + mapViewExtent.bottom;
		
		coord = new KrakMap.Coordinate(xPre, yPre);				
		poiTriangle = new KrakMap.Poi(triangle,coord,'info_category',1, 1);		
	}
	
		x = xInPixels * metersPerPixel + mapViewExtent.left;
		y = yInPixels * metersPerPixel + mapViewExtent.bottom;
																				
		var coord = new KrakMap.Coordinate(x, y);								
		var poitemp = new KrakMap.Poi(infoLayerDiv,coord,'info_category',1,1);
		
		tileMap.addPoi(poitemp);									
		tileMap.addPoi(poiTriangle);	
}
function parseInfoXML(xml) {
	try { //Internet Explorer

	  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	  xmlDoc.async="false";
	  xmlDoc.loadXML(xml);
	} catch(e) {
	  try { //Firefox, Mozilla, Opera, etc.
	  	  parser=new DOMParser();
		  xmlDoc=parser.parseFromString(xml,"text/xml");
	  } catch(e) {
	 	 return;
	  }
	}
	var i = 0 
	try{
		var root = xmlDoc.getElementsByTagName('ejendomme')[0];
		var items;
		try{
			items = root.getElementsByTagName("ejendom");
		} catch(e){}
		var onlyleje = false;
		if(items.length != 0){
			for ( i  ; i < items.length ; i++) {
				var item = items[i];			
				try{
					item.getElementsByTagName("leje")[0].firstChild
					onlyleje = true;
				}catch(e){
				
				}
				var ejendomstype = item.getElementsByTagName("ejendomstype")[0].firstChild != null ? item.getElementsByTagName("ejendomstype")[0].firstChild.nodeValue : "";
				var adresse = item.getElementsByTagName("adresse")[0].firstChild != null ? item.getElementsByTagName("adresse")[0].firstChild.nodeValue : "";
				var by = item.getElementsByTagName("by")[0].firstChild != null ? item.getElementsByTagName("by")[0].firstChild.nodeValue : "";
				var kontantpris = item.getElementsByTagName("kontantpris")[0].firstChild != null ? item.getElementsByTagName("kontantpris")[0].firstChild.nodeValue : "";
				var sagsnummer = item.getElementsByTagName("sagsnummer")[0].firstChild != null ? item.getElementsByTagName("sagsnummer")[0].firstChild.nodeValue : "";
				var udbetaling = item.getElementsByTagName("udbetaling")[0].firstChild != null ? item.getElementsByTagName("udbetaling")[0].firstChild.nodeValue : "";
				var brutto = item.getElementsByTagName("brutto")[0].firstChild != null ? item.getElementsByTagName("brutto")[0].firstChild.nodeValue : "";
				var overskrift = item.getElementsByTagName("overskrift")[0].firstChild != null ? item.getElementsByTagName("overskrift")[0].firstChild.nodeValue : "";
				var netto = item.getElementsByTagName("netto")[0].firstChild != null ? item.getElementsByTagName("netto")[0].firstChild.nodeValue : "";
				var flex = item.getElementsByTagName("flex")[0].firstChild != null ? item.getElementsByTagName("flex")[0].firstChild.nodeValue : "";
				var kvadratmeterpris = item.getElementsByTagName("kvadratmeterpris")[0].firstChild != null ? item.getElementsByTagName("kvadratmeterpris")[0].firstChild.nodeValue : "";
				if(kvadratmeterpris == '0+kr%2Fm2'){
						kvadratmeterpris = '-';
				}
				var udbudstid = item.getElementsByTagName("udbudstid")[0].firstChild != null ? item.getElementsByTagName("udbudstid")[0].firstChild.nodeValue : "";
				if(udbudstid == '%26nbsp%3B+dage'){
					udbudstid = '-';
				}
				var prisudvikling = item.getElementsByTagName("prisudvikling")[0].firstChild != null ? item.getElementsByTagName("prisudvikling")[0].firstChild.nodeValue : "";
				var foto = item.getElementsByTagName("foto")[0].firstChild != null ? item.getElementsByTagName("foto")[0].firstChild.nodeValue : "";
				var mdlboligydelse = item.getElementsByTagName("mdlboligydelse")[0].firstChild != null ? item.getElementsByTagName("mdlboligydelse")[0].firstChild.nodeValue : "";
				var mdlanvendudgift = item.getElementsByTagName("mdlanvendudgift")[0].firstChild != null ? item.getElementsByTagName("mdlanvendudgift")[0].firstChild.nodeValue : "";			
				var x = eval(item.getElementsByTagName("x-koordinater")[0].firstChild != null ? item.getElementsByTagName("x-koordinater")[0].firstChild.nodeValue : "");
				var y = eval(item.getElementsByTagName("y-koordinater")[0].firstChild != null ? item.getElementsByTagName("y-koordinater")[0].firstChild.nodeValue : "");		
				var xPre = x;
				var yPre = y;	
				var picitems = root.getElementsByTagName("pictogram");
				var pictogrammerText = new Array();
				var pictogrammerType = new Array();
				var pictogrammerValue = new Array();
				for (var j = 0  ; j < picitems.length ; j++) {
					var picitem = picitems[j];
					pictogrammerText[j] = picitem.getElementsByTagName("pictogramtext")[0].firstChild != null ? picitem.getElementsByTagName("pictogramtext")[0].firstChild.nodeValue : "";
					pictogrammerType[j] = picitem.getElementsByTagName("pictogramtype")[0].firstChild != null ? picitem.getElementsByTagName("pictogramtype")[0].firstChild.nodeValue : "";
					pictogrammerValue[j] = picitem.getElementsByTagName("pictogramvalue")[0].firstChild != null ? picitem.getElementsByTagName("pictogramvalue")[0].firstChild.nodeValue : "";
				}					
				var newdiv = document.createElement('div');
				newdiv.setAttribute("id","infoDivContainer");	
				newdiv.setAttribute("className","infoDivContainer");	
				var imageName = findEjendomsTypeImage(ejendomstype)+iconSuffix; 
				var ejendomstypeName = findEjendomsTypeName(ejendomstype); 
				var html = '' 
				if(ejendomstype == 'PLB'){
					html  += '<div id="infoDiv" name="infoDiv" class="infoDiv" onmouseup="stopMouseUpEvent(event)"  onclick="javascript:gotoSagProjektLeje(\''+urldecodeing(sagsnummer)+'\')">';
				}else if(onlyleje){
					html  += '<div id="infoDiv" name="infoDiv" class="infoDiv" onmouseup="stopMouseUpEvent(event)"  onclick="javascript:gotoSagOnlyLeje(\''+urldecodeing(sagsnummer)+'\')">';
				}else{
					html  += '<div id="infoDiv" name="infoDiv" class="infoDiv" onmouseup="stopMouseUpEvent(event)"  onclick="javascript:gotoSag(\''+urldecodeing(sagsnummer)+'\')">';
				}						
				html += '<table id="infoTable" cellspacing="0" cellpadding="0" border="0" style="position: relative; z-index: 10; cursor: pointer">';
				html +=	'<tr><td class="topLeftCorner"></td><td class="topLine"></td><td class="topRightCorner"></td></tr>';
				html +=	'<tr><td class="lineLeft"></td><td style="background-color: #ffffff">';
				html += '<table class="pointInfo_overlay" cellpadding="0" cellspacing="0" border="0">'+
								'<tr class="pointInfo_overlay">'+
									'<td colspan="3" class="pointInfo_adresse">'+urldecodeing(adresse)+'</td>'+
									'<td colspan="1" class="lukVindue" onclick="javascript:closeInfoPopup(event)">Luk vindue&nbsp;'+
										'<span style="cursor: pointer"><img src="/graphics/icons/close.gif" width="9" height="9" title="Luk vindue" border="0"></span>'+
									'</td>'+
								'</tr>'+
							'</table>';
				html += '<table class="pointInfo_overlay" cellpadding="0" cellspacing="0" border="0">'+
								'<tr class="pointInfo_overlay">'+
									'<td colspan="2" class="pointInfo_by">'+urldecodeing(by)+'</td>'
				if(ejendomstype == "PLB" || onlyleje){
									html +='<td class="pointInfo_sagsnummer" style="">&nbsp;</td>';
				}else{
									html += '<td class="pointInfo_sagsnummer" style="">Sagsnr. '+urldecodeing(sagsnummer)+'</td>';
				}
								html += '</tr>'+
							'</table>';
				html += '<table class="pointInfo_overlay" cellpadding="0" cellspacing="0" border="0">'+
								'<tr class="pointInfo_overlay">'+
									'<td colspan="2" class="pointInfo_overskrift">'+urldecodeing(overskrift)+'</td>'+
									'<td style="padding-right: 0px; text-align: right; padding-bottom: 3px;"><img border="0" src="/graphics/home_logo_boliginfo_small.gif" title="home logo"></td>'+
									'<td colspan="1" style="width: 25px"><img src="/graphics/icons/'+imageName+'" align="right" valign="middel" title="'+ejendomstypeName+' "></td>'+
								'</tr>'+
							'</table>';
				if (ejendomstype == "AA") {
					html +=	'<table class="pointInfo_foto" cellpadding="0" cellspacing="0" border="0">'+
									'<tr class="pointInfo_overlay">'+
										'<td colspan="1" rowspan="6" class="pointInfo_foto"><img src='+urldecodeing(foto)+' title="foto" width="142px" height="96px"></td>'+
										'<td colspan="1" class="pointInfo_left_bold">Købspris</td>'+
										'<td colspan="1" class="pointInfo_bold">'+urldecodeing(kontantpris)+'</td>'+
										'<td colspan="1" class="pointInfo_space">&nbsp;</td>'+
									'</tr>'+
									'<tr>'+
										'<td colspan="1" class="pointInfo_left_bold">Mdl. boligydelse</td>'+
										'<td colspan="1" class="pointInfo_bold">'+urldecodeing(mdlboligydelse)+'</td>'+
										'<td colspan="1" class="pointInfo_space">&nbsp;</td>'+
									'</tr>'+
									'<tr>'+
										'<td colspan="1" class="pointInfo_left_bold">Mdl. anv. udgifter</td>'+
										'<td colspan="1" class="pointInfo_bold">'+urldecodeing(mdlanvendudgift)+'</td>'+
										'<td colspan="1" class="pointInfo_space">&nbsp;</td>'+
									'</tr>'+									
									'<tr>'+
										'<td colspan="1" class="pointInfo_left">Udbudstid</td>'+
										'<td colspan="1" class="pointInfo_overlay">'+urldecodeing(udbudstid)+'</td>'+
										'<td colspan="1" class="pointInfo_space">&nbsp;</td>'+
									'</tr>'+
									'<tr>'+
										'<td colspan="1" class="pointInfo_left_end">Prisudvikling</td>'+
										'<td colspan="1" class="pointInfo_end">'+urldecodeing(prisudvikling)+'</td>'+
										'<td colspan="1" class="pointInfo_space">&nbsp;</td>'+
									'</tr>'+
								'</table>';					
					}else if(ejendomstype == "PLB" || onlyleje){
								var leje = item.getElementsByTagName("leje")[0].firstChild != null ? item.getElementsByTagName("leje")[0].firstChild.nodeValue : "";
								var size = item.getElementsByTagName("size")[0].firstChild != null ? item.getElementsByTagName("size")[0].firstChild.nodeValue : "";
								var ledige = item.getElementsByTagName("ledige-boliger")[0].firstChild != null ? item.getElementsByTagName("ledige-boliger")[0].firstChild.nodeValue : "";
							html +=	'<table class="pointInfo_foto" cellpadding="0" cellspacing="0" border="0">'+
								'<tr class="pointInfo_overlay">'+
									'<td colspan="1" rowspan="6" class="pointInfo_foto"><img src='+urldecodeing(foto)+' title="foto" width="142px" height="96px"></td>'+
									'<td colspan="1" class="pointInfo_left_bold">Mdl. basisleje fra</td>'+
									'<td colspan="1" class="pointInfo_bold">'+urldecodeing(leje)+'</td>'+
									'<td colspan="1" class="pointInfo_space">&nbsp;</td>'+
								'</tr>'+
								'<tr>'+
									'<td colspan="1" class="pointInfo_left_bold">Størrelse</td>'+
									'<td colspan="1" class="pointInfo_bold">'+urldecodeing(size)+'</td>'+
									'<td colspan="1" class="pointInfo_space">&nbsp;</td>'+
								'</tr>';
								if(! onlyleje){
								html += '<tr>'+
									'<td colspan="1" class="pointInfo_left_bold">Ledige boliger</td>'+
									'<td colspan="1" class="pointInfo_bold">'+urldecodeing(ledige)+'</td>'+
									'<td colspan="1" class="pointInfo_space">&nbsp;</td>'+
								'</tr>'+	
								'<tr>'+
										'<td colspan="1"  class="pointInfo_left_bold_projektlejebolig">&nbsp;</td>'+
										'<td colspan="1" class="pointInfo_bold_projektlejebolig" >&nbsp;</td>'+
										'<td colspan="1" >&nbsp;</td>'+
									'</tr>'+
									'<tr>'+
										'<td colspan="1" >&nbsp;</td>'+
										'<td colspan="1" >&nbsp;</td>'+
										'<td colspan="1" >&nbsp;</td>'+
									'</tr>'+
									'<tr>'+
										'<td colspan="1" >&nbsp;</td>'+
										'<td colspan="1" >&nbsp;</td>'+
										'<td colspan="1" >&nbsp;</td>'+
									'</tr>'+
									'<tr>'+
										'<td colspan="1" >&nbsp;</td>'+
										'<td colspan="1" >&nbsp;</td>'+
										'<td colspan="1" >&nbsp;</td>'+
									'</tr>'+							
							'</table>';	
								}else if(ejendomstype != "PLB"){
									var forbrug = item.getElementsByTagName("forbrug")[0].firstChild != null ? item.getElementsByTagName("forbrug")[0].firstChild.nodeValue : "";
									var forudbetalt = item.getElementsByTagName("forudbetalt")[0].firstChild != null ? item.getElementsByTagName("forudbetalt")[0].firstChild.nodeValue : "";
									var depositum = item.getElementsByTagName("depositum")[0].firstChild != null ? item.getElementsByTagName("depositum")[0].firstChild.nodeValue : "";
									var ledigfra = item.getElementsByTagName("ledigfra")[0].firstChild != null ? item.getElementsByTagName("ledigfra")[0].firstChild.nodeValue : "";
								
									html += 
									'<tr>'+
										'<td colspan="1" class="pointInfo_left_bold">Aconto forbrug pr. måned</td>'+
										'<td colspan="1" class="pointInfo_bold">'+urldecodeing(forbrug)+'</td>'+
										'<td colspan="1" class="pointInfo_space">&nbsp;</td>'+
									'</tr>'+
									'<tr>'+
										'<td colspan="1" class="pointInfo_left_bold">Forudbetalt leje</td>'+
										'<td colspan="1" class="pointInfo_bold">'+urldecodeing(forudbetalt)+'</td>'+
										'<td colspan="1" class="pointInfo_space">&nbsp;</td>'+
									'</tr>'+
									'<tr>'+
										'<td colspan="1" class="pointInfo_left_bold">Depositum</td>'+
										'<td colspan="1" class="pointInfo_bold">'+urldecodeing(depositum)+'</td>'+
										'<td colspan="1" class="pointInfo_space">&nbsp;</td>'+
									'</tr>'+
									'<tr>'+
										'<td colspan="1" class="pointInfo_left_end"><b>Ledig fra dato</b></td>'+
										'<td colspan="1" class="pointInfo_end">'+urldecodeing(ledigfra)+'</td>'+
										'<td colspan="1" class="pointInfo_space">&nbsp;</td>'+
									'</tr>'+
									'</table>';	
								
								
								}
							
				 }else {					
					html += '<table class="pointInfo_foto" cellpadding="0" cellspacing="0" border="0"><tr class="pointInfo_overlay"><td colspan="1" rowspan="7" class="pointInfo_foto"><img src="http://streaming.home.dk/'+urldecodeing(foto)+'" title="foto"  width="142px" height="96px"></td><td colspan="1" class="pointInfo_left_bold">Kontantpris</td><td colspan="1" class="pointInfo_bold">'+urldecodeing(kontantpris)+'</td><td colspan="1" class="pointInfo_space">&nbsp;</td></tr><tr><td colspan="1" class="pointInfo_left_bold">Udbetaling</td><td colspan="1" class="pointInfo_bold">'+urldecodeing(udbetaling)+'</td><td colspan="1" class="pointInfo_space">&nbsp;</td></tr><tr><td colspan="2" class="pointInfo_brutto_netto"><span class="name">Brutto/Netto</span><span class="number">'+urldecodeing(brutto)+'/'+urldecodeing(netto)+'</span></td><td colspan="1" class="pointInfo_space">&nbsp;</td></tr><tr><td colspan="1" class="pointInfo_left">Flexlån&reg; F1K </td><td colspan="1" class="pointInfo_overlay">'+urldecodeing(flex)+'</td><td colspan="1" class="pointInfo_space">&nbsp;</td></tr><tr><td colspan="1" class="pointInfo_left">Kvadratmeterpris</td><td colspan="1" class="pointInfo_overlay">'+urldecodeing(kvadratmeterpris)+'</td><td colspan="1" class="pointInfo_space">&nbsp;</td></tr><tr><td colspan="1" class="pointInfo_left">Udbudstid</td><td colspan="1" class="pointInfo_overlay">'+urldecodeing(udbudstid)+'</td><td colspan="1" class="pointInfo_space">&nbsp;</td></tr><tr><td colspan="1" class="pointInfo_left_end">Prisudvikling</td><td colspan="1" class="pointInfo_end">'+urldecodeing(prisudvikling)+'</td><td colspan="1" class="pointInfo_space">&nbsp;</td></tr></table>';
				}
				if(ejendomstype == "PLB" || onlyleje){
					html += '<table class="pointInfo_pic" cellpadding="0" cellspacing="0" border="0"><tr>';
					html += '<td>&nbsp;</td>';
					
					html += '</tr><tr class="pointInfo_pictogramvalue">';		
					html += '<td>&nbsp;</td>';
				}else{
					html += '<table class="pointInfo_pic" cellpadding="0" cellspacing="0" border="0"><tr>';
					for (i = 0; i < picitems.length; i++){
						html += '<td><IMG src="/graphics/pictogram/'+pictogrammerType[i]+'.png" title="'+urldecodeing(pictogrammerText[i])+'"></td>';
					}
					
					html += '</tr><tr class="pointInfo_pictogramvalue">';		
					for (i = 0; i < picitems.length; i++){
						html += '	<td class="pointInfo_picvalue">'+pictogrammerValue[i]+'</td>';
					}
				}
				html += '</tr></table>';
				html += '</td><td class="lineRight">&nbsp;&nbsp;&nbsp;</td></tr><tr><td class="bottomLeftCorner">&nbsp;&nbsp;&nbsp;</td>';
				html +=	'<td class="bottomLine"></td><td class="bottomRightCorner"></td></tr></table>';					
				html += '</div>';
				newdiv.innerHTML = html;											
				var infoLayer = {x: x, y: y, xPre: xPre, yPre: yPre, infoLayerDiv: newdiv, sagsnummer: sagsnummer, url: null};
				return infoLayer;
			}
		} else { //Info for fremmedboliger!
			var root = xmlDoc.getElementsByTagName('ejendomme')[0];
			items = root.getElementsByTagName("foreign-ejendom");
			for ( i; i < items.length; i++) {
				var item = items[i];
				var maegler = item.getElementsByTagName("maegler")[0].firstChild != null ? item.getElementsByTagName("maegler")[0].firstChild.nodeValue : "";					
				var ejendomstype = item.getElementsByTagName("ejendomstype")[0].firstChild != null ? item.getElementsByTagName("ejendomstype")[0].firstChild.nodeValue : "";
				var adresse = item.getElementsByTagName("adresse")[0].firstChild != null ? item.getElementsByTagName("adresse")[0].firstChild.nodeValue : "";
				var by = item.getElementsByTagName("by")[0].firstChild != null ? item.getElementsByTagName("by")[0].firstChild.nodeValue : "";
				var kontantpris = item.getElementsByTagName("kontantpris")[0].firstChild != null ? item.getElementsByTagName("kontantpris")[0].firstChild.nodeValue : "";
				var sagsnummer = item.getElementsByTagName("sagsnummer")[0].firstChild != null ? item.getElementsByTagName("sagsnummer")[0].firstChild.nodeValue : "";
				var udbetaling = item.getElementsByTagName("udbetaling")[0].firstChild != null ? item.getElementsByTagName("udbetaling")[0].firstChild.nodeValue : "";
				var brutto = item.getElementsByTagName("brutto")[0].firstChild != null ? item.getElementsByTagName("brutto")[0].firstChild.nodeValue : "";
				var netto = item.getElementsByTagName("netto")[0].firstChild != null ? item.getElementsByTagName("netto")[0].firstChild.nodeValue : "";				
				var kvadratmeterpris = item.getElementsByTagName("kvadratmeterpris")[0].firstChild != null ? item.getElementsByTagName("kvadratmeterpris")[0].firstChild.nodeValue : "";
				if(kvadratmeterpris == '0+kr%2Fm2'){
						kvadratmeterpris = '-';
				}						
				var udbudstid = item.getElementsByTagName("udbudstid")[0].firstChild != null ? item.getElementsByTagName("udbudstid")[0].firstChild.nodeValue : "";				
				if(udbudstid == '%26nbsp%3B+dage'){
					udbudstid = '-';
				}
				var prisudvikling = item.getElementsByTagName("prisudvikling")[0].firstChild != null ? item.getElementsByTagName("prisudvikling")[0].firstChild.nodeValue : "";
				var foto = item.getElementsByTagName("foto")[0].firstChild != null ? item.getElementsByTagName("foto")[0].firstChild.nodeValue : "";		
				var mdlanvendudgift = item.getElementsByTagName("mdlanvendudgift")[0].firstChild != null ? item.getElementsByTagName("mdlanvendudgift")[0].firstChild.nodeValue : "";	
				var x = eval(item.getElementsByTagName("x-koordinater")[0].firstChild != null ? item.getElementsByTagName("x-koordinater")[0].firstChild.nodeValue : "");
				var y = eval(item.getElementsByTagName("y-koordinater")[0].firstChild != null ? item.getElementsByTagName("y-koordinater")[0].firstChild.nodeValue : "");		
				var xPre = x;
				var yPre = y;	
				var picitems = root.getElementsByTagName("pictogram");
				var pictogrammerText = new Array();
				var pictogrammerType = new Array();
				var pictogrammerValue = new Array();
				for (var j = 0  ; j < picitems.length ; j++) {
					var picitem = picitems[j];
					pictogrammerText[j] = picitem.getElementsByTagName("pictogramtext")[0].firstChild != null ? picitem.getElementsByTagName("pictogramtext")[0].firstChild.nodeValue : "";
					pictogrammerType[j] = picitem.getElementsByTagName("pictogramtype")[0].firstChild != null ? picitem.getElementsByTagName("pictogramtype")[0].firstChild.nodeValue : "";
					pictogrammerValue[j] = picitem.getElementsByTagName("pictogramvalue")[0].firstChild != null ? picitem.getElementsByTagName("pictogramvalue")[0].firstChild.nodeValue : "";
				}	
									
				var url = item.getElementsByTagName("url")[0].firstChild != null ? item.getElementsByTagName("url")[0].firstChild.nodeValue : "";					
			}
			var newdiv = document.createElement('div');
			newdiv.setAttribute("id","infoDivContainer");	
			newdiv.setAttribute("className","infoDivContainer");		
			var imageName = findEjendomsTypeImage(ejendomstype) + iconSuffix; 
			var ejendomstypeName = findEjendomsTypeName(ejendomstype); 		
			var html  = '<div id="infoDiv" name="infoDiv" class="infoDiv" onmouseup="stopMouseUpEvent(event)" onclick="javascript:window.open(\''+urldecodeing(url)+'\')">';						
			html += '<table id="infoTable" cellspacing="0" cellpadding="0" border="0" style="position: relative; z-index: 10; cursor: pointer">';
			html +=	'<tr><td class="topLeftCorner"></td><td class="topLine"></td><td class="topRightCorner"></td></tr>';
			html +=	'<tr><td class="lineLeft"></td><td style="background-color: #ffffff">';	
			html += '<table class="pointInfo_overlay" cellpadding="0" cellspacing="0" border="0">'+
							'<tr class="pointInfo_overlay">'+
								'<td colspan="3" class="pointInfo_adresse">'+urldecodeing(adresse)+'</td>'+
								'<td colspan="1" class="lukVindue" onclick="javascript:closeInfoPopup(event)">Luk vindue&nbsp;'+
									'<span style="cursor: pointer"><img src="/graphics/icons/close.gif" title="Luk vindue" border="0"></span>'+
								'</td>'+
							'</tr>'+
						'</table>';				
			html += '<table class="pointInfo_overlay" cellpadding="0" cellspacing="0" border="0">'+
							'<tr class="pointInfo_overlay">'+
								'<td colspan="2" class="pointInfo_by">'+urldecodeing(by)+'</td>'+
								'<td class="pointInfo_sagsnummer" style="">Sagsnr. '+urldecodeing(sagsnummer)+'</td>'+
							'</tr>'+
						'</table>';
			html += '<table class="pointInfo_overlay" cellpadding="0" cellspacing="0" border="0">'+
							'<tr class="pointInfo_overlay">'+
								'<td colspan="2" class="pointInfo_overskrift"></td>'+
								'<td style="padding-right: 0px; text-align: right; padding-bottom: 3px; color: #7c7c7c">'+urldecodeing(maegler)+'</td>'+
								'<td colspan="1" style="width: 25px"><img src="/graphics/icons/'+imageName+'" align="right" valign="middel" title="'+ejendomstypeName+' "></td>'+
							'</tr>'+
						'</table>';
			
			if(ejendomstype == "AA"){
				html +=	'<table class="pointInfo_foto" cellpadding="0" cellspacing="0" border="0">'+
								'<tr class="pointInfo_overlay">'+
									'<td colspan="1" rowspan="6" class="pointInfo_foto"><img src='+urldecodeing(foto)+' title="foto" width="142px" height="96px"></td>'+
									'<td colspan="1" class="pointInfo_left_bold">Købspris</td>'+
									'<td colspan="1" class="pointInfo_bold">'+urldecodeing(kontantpris)+'</td>'+
									'<td colspan="1" class="pointInfo_space">&nbsp;</td>'+
								'</tr>'+
								'<tr>'+
									'<td colspan="1" class="pointInfo_left_bold">Mdl. boligydelse</td>'+
									'<td colspan="1" class="pointInfo_bold">'+urldecodeing(brutto)+' kr.</td>'+
									'<td colspan="1" class="pointInfo_space">&nbsp;</td>'+
								'</tr>'+
								'<tr>'+
									'<td colspan="1" class="pointInfo_left_bold">Mdl. anv. udgifter</td>'+
									'<td colspan="1" class="pointInfo_bold">'+urldecodeing(netto)+'</td>'+
									'<td colspan="1" class="pointInfo_space">&nbsp;</td>'+
								'</tr>'+
								'<tr>'+
									'<td colspan="1" class="pointInfo_left">Udbudstid</td>'+
									'<td colspan="1" class="pointInfo_overlay">'+urldecodeing(udbudstid)+'</td>'+
									'<td colspan="1" class="pointInfo_space">&nbsp;</td>'+
								'</tr>'+
								'<tr>'+
									'<td colspan="1" class="pointInfo_left_end">Prisudvikling</td>'+
									'<td colspan="1" class="pointInfo_end">'+urldecodeing(prisudvikling)+'</td>'+
									'<td colspan="1" class="pointInfo_space">&nbsp;</td>'+
								'</tr>'+
							'</table>';							
					}else {					
						html += '<table class="pointInfo_foto" cellpadding="0" cellspacing="0" border="0"><tr class="pointInfo_overlay"><td colspan="1" rowspan="6" class="pointInfo_foto"><img src='+urldecodeing(foto)+' title="foto" width="142px" height="96px"></td><td colspan="1" class="pointInfo_left_bold">Kontantpris</td><td colspan="1" class="pointInfo_bold">'+urldecodeing(kontantpris)+'</td><td colspan="1" class="pointInfo_space">&nbsp;</td></tr><tr><td colspan="1" class="pointInfo_left_bold">Udbetaling</td><td colspan="1" class="pointInfo_bold">'+urldecodeing(udbetaling)+'</td><td colspan="1" class="pointInfo_space">&nbsp;</td></tr><tr><td colspan="2" class="pointInfo_brutto_netto"><span class="name">Brutto/Netto</span><span class="number">'+urldecodeing(brutto)+'/'+urldecodeing(netto)+'</span></td><td colspan="1" class="pointInfo_space">&nbsp;</td></tr><tr><td colspan="1" class="pointInfo_left">Kvadratmeterpris</td><td colspan="1" class="pointInfo_overlay">'+urldecodeing(kvadratmeterpris)+'</td><td colspan="1" class="pointInfo_space">&nbsp;</td></tr><tr><td colspan="1" class="pointInfo_left">Udbudstid</td><td colspan="1" class="pointInfo_overlay">'+urldecodeing(udbudstid)+'</td><td colspan="1" class="pointInfo_space">&nbsp;</td></tr><tr><td colspan="1" class="pointInfo_left_end">Prisudvikling</td><td colspan="1" class="pointInfo_end">'+urldecodeing(prisudvikling)+'</td><td colspan="1" class="pointInfo_space">&nbsp;</td></tr></table>';
					}
					
					html += '<table class="pointInfo_pic" cellpadding="0" cellspacing="0" border="0"><tr>';
					
				for (i = 0; i < picitems.length; i++){
					html += '<td><IMG src="/graphics/pictogram/'+pictogrammerType[i]+'.png" title="'+urldecodeing(pictogrammerText[i])+'"></td>';
				}
				
				html += '</tr><tr class="pointInfo_pictogramvalue">';
						
				for (i = 0; i < picitems.length; i++){
					html += '	<td class="pointInfo_picvalue">'+pictogrammerValue[i]+'</td>';
				}
				
				html += '</tr></table>';				
				html += '</td><td class="lineRight">&nbsp;&nbsp;&nbsp;</td></tr><tr><td class="bottomLeftCorner">&nbsp;&nbsp;&nbsp;</td>';
				html +=	'<td class="bottomLine"></td><td class="bottomRightCorner"></td></tr></table>';					
				html += '</div>';
				newdiv.innerHTML = html;	
		
				var infoLayer = {x: x, y: y, xPre: xPre, yPre: yPre, infoLayerDiv: newdiv, sagsnummer: null, url: url};
				return infoLayer;				
		}			
	} catch(e) {
		//alert('2:'+e.message);		
	}	
}

function setBackgroundColorOnMapKort(e) {
	var map = document.getElementById('map');
	if (map && tileMap && tileMap.getMapType() == 'kvec' && tileMap.getZoomLevel() == 13) {				
		map.style.backgroundColor = "#99f2ff";
	} else if (map && tileMap && tileMap.getZoomLevel() == 13) {
		map.style.backgroundColor = "#11333D";		
	}	
}

function enableRectangleDraw() {
	tileMap.enableRectangleDraw();
	var rectangleDrawTool = document.getElementById('rectangleDrawTool');
	rectangleDrawTool.style.background = 'transparent url(http://tileclient.krak.dk/static/v3/docs/../img/toolbar/gfx_bgimage_mapbuttons.gif) repeat-x scroll 0px -20px'; 	
	var moveTool = document.getElementById('moveTool');
	moveTool.style.background = '';	
}

function enableMoveTool() {
	tileMap.disableRectangleDraw();	
	var moveTool = document.getElementById('moveTool');
	moveTool.style.background = 'transparent url(http://tileclient.krak.dk/static/v3/docs/../img/toolbar/gfx_bgimage_mapbuttons.gif) repeat-x scroll 0px -20px'; 	 
	var rectangleDrawTool = document.getElementById('rectangleDrawTool');
	rectangleDrawTool.style.background = '';
}
