﻿var activeMarker;
var arrLaatstBekeken = new Array();
var arrObjects = new Array();

var currPageNumber = 1;                     // page number for paging 

var sortPrijsRule = "desc";
var sortKamersRule = "desc";
var sortPlaatsRule = "desc";
var sortOppervalkteRule = "desc";

var filterType = -1;

var arrPrijsSort = new Array();

var request;

    function AddToLaatstBekeken(detailhtml, html, id){
        var bFound = false;
        var strHtml= "";
        //array doorzoeken
        for (var a = 0; a < arrLaatstBekeken.length; a++) {
            if(id==arrLaatstBekeken[a][0]){
                bFound=true;
            }
        }
        //nog niet gevonden.
        if(!bFound){
            var arrTemp = new Array();
            arrTemp[0]=id;
            arrTemp[1]=html;
            arrTemp[2]=detailhtml;
            arrLaatstBekeken[arrLaatstBekeken.length] = arrTemp;
        }
        document.getElementById("eerder-bekeken").innerHTML="<h2 class=\"column-title\">Eerder bekeken " + strObjectType + "</h2>";
        strHtml += "<ul class=\"woningen-small\">";
        for (var a = 0; a < arrLaatstBekeken.length; a++) {
            if(a%2!=0){
                strHtml+="<li>" + arrLaatstBekeken[a][1] + "</li>"
            }else{
                strHtml+="<li class=\"odd\">" + arrLaatstBekeken[a][1] + "</li>"
            }
        }
        strHtml += "</ul><div class=\"column\"><div class=\"column-green\"></div></div><div class=\"column column-last\"><div class=\"column-blue\"></div></div>";
        document.getElementById("eerder-bekeken").innerHTML+=strHtml;

        /*document.getElementById("eerder-bekeken").innerHTML+="<ul class=\"woningen-small\">"
        for (var a = 0; a < arrLaatstBekeken.length; a++) {
            if(a%2!=0){
                document.getElementById("eerder-bekeken").innerHTML+="<li>" + arrLaatstBekeken[a][1] + "</li>"
            }else{
                document.getElementById("eerder-bekeken").innerHTML+="<li class=\"odd\">" + arrLaatstBekeken[a][1] + "</li>"
            }
        }
        document.getElementById("eerder-bekeken").innerHTML+="</ul>"
        */
        //alert(document.getElementById("eerder-bekeken").innerHTML);
    }
    
    
    function showItemByIdUitLijst(id){
        for (var a = 0; a < arrObjects.length; a++) {
            if(id==arrObjects[a][0]){
                document.getElementById("divObjectDetails").innerHTML="";
                document.getElementById("divObjectDetails").innerHTML+=""+ arrObjects[a][7] + "";
                //switchTabs('tabResultatenlijst','divDetails');
                zzShowTab('detail');
                AddToLaatstBekeken(arrObjects[a][7], arrObjects[a][13], arrObjects[a][0]);
                
                $(function() {
                     //$("div.detailgallery map a").lightBox();
                     $("#ulhidden a").lightBox();
                });
                
                $(".zoom").click(function() {
			        //$("div.detailgallery map a:first").click();
			        $("#ulhidden a.active").click();
		        });
            }
        }
    }
    function showItemById(id){
        for (var a = 0; a < arrObjects.length; a++) {
            if(id==arrObjects[a][0]){
                document.getElementById("divObjectDetails").innerHTML="";
                document.getElementById("divObjectDetails").innerHTML+=""+ arrObjects[a][7] + "";
                //switchTabs('tabResultatenlijst','divDetails');
                zzShowTab('detail');
                AddToLaatstBekeken(arrObjects[a][7], arrObjects[a][13], arrObjects[a][0]);
                
                $(function() {
                     //$("div.detailgallery map a").lightBox();
                     $("#ulhidden a").lightBox();
                });
                
                $(".zoom").click(function() {
			        //$("div.detailgallery map a:first").click();
			        $("#ulhidden a.active").click();
		        });
            }
        }
    }
    
    function loadObjectInfo(a){
        document.getElementById("divObjectDetails").innerHTML="";
        //Omschrijving
        document.getElementById("divObjectDetails").innerHTML+=""+ arrObjects[a][7] + "";
        map.setCenter(new GLatLng(arrObjects[a][8], arrObjects[a][9]),14);
        //document.getElementById("divLaatstBekeken").innerHTML = "<a href=\"#\" onClick=\"loadObjectInfo(" + a + ");switchToDetails();return false;\">" + arrObjects[a][3] + ", " + arrObjects[a][5] + "</a><br />" + document.getElementById("divLaatstBekeken").innerHTML
        AddToLaatstBekeken(arrObjects[a][7], arrObjects[a][13], arrObjects[a][0]);
        
        $(function() {
                     //$("div.detailgallery map a").lightBox();
                     $("#ulhidden a").lightBox();
                });
                
                $(".zoom").click(function() {
			        //$("div.detailgallery map a:first").click();
			        $("#ulhidden a.active").click();
		        });
    }
    
    
    function loadMarks(xmlDoc){
        arrObjects =  new Array();
        var pcs = xmlDoc.documentElement.getElementsByTagName("pc");        
	    var strResults="";
        document.getElementById("divObjectDetails").innerHTML="";
        document.getElementById("overzichtlijst").innerHTML="";
        document.getElementById("eerder-bekeken").innerHTML="";
        arrLaatstBekeken = new Array();
        if(pcs.length==0){
            document.getElementById("gmnoresults").style.display="";
        }
        document.getElementById("lijst-tab").innerHTML="<a href=\"#\" onclick=\"javascript:pageTracker._trackPageview('TabLijst');zzShowTab('lijst');return false;\">Lijst ["+pcs.length+"]</a>"
        
        
        var strPaging = "";   
        currPageNumber = 1;       
                
        for (var a = 0; a < pcs.length; a++) 
        {   
            //Uitlezen van XML nodes
            var id  = pcs[a].getAttribute("id");
            var img  = pcs[a].getAttribute("foto");
            var adres  = pcs[a].getAttribute("adres");
            var postcode  = pcs[a].getAttribute("postcode");
            var plaats  = pcs[a].getAttribute("plaats");
            var title  = pcs[a].getAttribute("title");
            var markertype =  pcs[a].getAttribute("markertype");
            var verkocht =  pcs[a].getAttribute("verkocht");
            var wijk  = pcs[a].getAttribute("wijk");                        
            
            if(markertype==11 || markertype==12){
                if(markertype==11){
                    var box2omschrijving = pcs[a].getElementsByTagName("i2")[0].firstChild.nodeValue;
                }else{
                    var box2omschrijving = ""
                }
                var omschrijving = ""
                var box1omschrijving = ""
                
                var resultaat = ""
                var laatstbekeken  = ""
            }else{
                var omschrijving = pcs[a].getElementsByTagName("oms")[0].firstChild.nodeValue;
                var box1omschrijving = pcs[a].getElementsByTagName("i1")[0].firstChild.nodeValue;
                var box2omschrijving = pcs[a].getElementsByTagName("i2")[0].firstChild.nodeValue;
                var resultaat = pcs[a].getElementsByTagName("r")[0].firstChild.nodeValue;
                var laatstbekeken  = pcs[a].getElementsByTagName("l")[0].firstChild.nodeValue;
            }
                        
            var arrObject = new Array();
            arrObject[0]=id;
            arrObject[1]=img;
            arrObject[2]=title;
            arrObject[3]=adres;
            arrObject[4]=postcode;
            arrObject[5]=plaats;
            arrObject[6]=wijk;
            arrObject[7]=omschrijving;
            arrObject[8]=pcs[a].getAttribute("marklat");
            arrObject[9]=pcs[a].getAttribute("marklong");
            arrObject[10]=box1omschrijving;
            arrObject[11]=box2omschrijving;
            arrObject[12]=resultaat;
            arrObject[13]=laatstbekeken;      
            
            arrObject[14] = pcs[a].getAttribute("prijs");            
            arrObject[15] = pcs[a].getAttribute("kamers");   
            arrObject[16] = pcs[a].getAttribute("oppervalkte");
            
            arrObject[17] = markertype;
                        
            
            arrObjects[a] = arrObject;
            addMarker(a,arrObject[8],arrObject[9],omschrijving,resultaat,box1omschrijving,box2omschrijving, markertype);                        
            
            //Paging
            if(arrObjects[a] != null) 
            {       
                strPaging = "<ul>";
                strPaging += "<li><a class=\"text\" href=\"#\" onclick=\"selectPrevPage();\">Vorige</a></li>";
                var pagesCount = pcs.length/10;                
                
                for(var i=0; i<pagesCount; i++) {
                    if(i==0) strPaging += "<li><a href=\"#\" class=\"selected\" onclick=\"selectPage("+(i+1) +");\" >" + (i+1) + "</a></li>";
                    else strPaging += "<li><a href=\"#\" onclick=\"selectPage("+(i+1) +");\" >" + (i+1) + "</a></li>";
                }                
            }

            if(markertype!=11 && markertype!=12)
            {
                //strResults+= resultaat + "<br /><br />";                
                var frompg = currPageNumber*10-10;
                var topg = currPageNumber*10-1;
                
                if(a>=frompg && a<=topg) {                
                    strResults += resultaat;
                }
            }
        }
        
        //document.getElementById("overzichtlijst").innerHTML+= strResults+ "<br /><br />";
        document.getElementById("overzichtlijst").innerHTML+= strResults;
        
        //document.getElementById("paging") != null && 
        
        if(document.getElementById("paging").innerHTML != null && strResults.length > 0) {
            strPaging += "<li><a class=\"text\" href=\"#\" onclick=\"selectNextPage();\">Volgende</a></li>"; 
            strPaging += "</ul>";          
            
            document.getElementById("paging").innerHTML = strPaging;            
            checkPageInPaging(currPageNumber);
        }
        

	//No results message and no results filter message from homepage
	if (pcs.length == 0){
	  document.getElementById("paging").style.display="none";
	  document.getElementById("noresults").style.display="none";
	  document.getElementById("noresultshome").style.display="none";

  	  if (getQuerystring('filter') != "") {
	    document.getElementById("noresults").style.display="none";
	    document.getElementById("noresultshome").style.display="";
	  }	
	  else {
	    document.getElementById("noresults").style.display="";
	    document.getElementById("noresultshome").style.display="none";
	  }

	}	
	else {
	  document.getElementById("paging").style.display="";
          document.getElementById("noresults").style.display="none";
    	  document.getElementById("noresultshome").style.display="none";	
	}

        sortPrijs();                           

    }
    

    function getQuerystring(key, default_)
    {
	  if (default_==null) default_=""; 
	  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
	  var qs = regex.exec(window.location.href);
	  if(qs == null)
	    return default_;
	  else
	    return qs[1];
    }


    
    function filterMarks(){
        
        arrPrijsSort = new Array();   
        //arrPrijsSort = arrObjects;    
        for(x=0; x<arrObjects.length; x++) {
            //arrPrijsSort[x] = arrObjects[x];
            if(filterType == -1 || filterType == arrObjects[x][17])
            {
                arrPrijsSort.push(arrObjects[x]);
            }
        }
        
        var pcs = "";//xmlDoc.documentElement.getElementsByTagName("pc");     
        var resultaat = ""   
	    var strResults="";
        document.getElementById("divObjectDetails").innerHTML="";
        document.getElementById("overzichtlijst").innerHTML="";
        //document.getElementById("eerder-bekeken").innerHTML="";
        arrLaatstBekeken = new Array();

        document.getElementById("lijst-tab").innerHTML="<a href=\"#\" onclick=\"javascript:pageTracker._trackPageview('TabLijst');zzShowTab('lijst');return false;\">Lijst ["+arrPrijsSort.length+"]</a>"
                
        var strPaging = "";   
        currPageNumber = 1;       
        
        
        for (var a = 0; a < arrPrijsSort.length; a++) 
        {   
            //Paging
            if(arrPrijsSort[a] != null) 
            {  
                resultaat += arrPrijsSort[a][12];
                strPaging = "<ul>";
                strPaging += "<li><a class=\"text\" href=\"#\" onclick=\"selectPrevPage();\">Vorige</a></li>";
                var pagesCount = arrPrijsSort.length/10;                
                
                for(var i=0; i<pagesCount; i++) {
                    if(i==0) strPaging += "<li><a href=\"#\" class=\"selected\" onclick=\"selectPage("+(i+1) +");\" >" + (i+1) + "</a></li>";
                    else strPaging += "<li><a href=\"#\" onclick=\"selectPage("+(i+1) +");\" >" + (i+1) + "</a></li>";
                }                
            }
            
            if(arrPrijsSort[a][17]!=11 && arrPrijsSort[a][17]!=12)
            {
                //strResults+= resultaat + "<br /><br />";                
                var frompg = currPageNumber*10-10;
                var topg = currPageNumber*10-1;
                
                if(a>=frompg && a<=topg) {                
                    strResults += resultaat;
                }
            }
        }
        
        //document.getElementById("overzichtlijst").innerHTML+= strResults+ "<br /><br />";
        document.getElementById("overzichtlijst").innerHTML+= strResults;
        
        //document.getElementById("paging") != null && 
        
        if(document.getElementById("paging").innerHTML != null && strResults.length > 0) {
            strPaging += "<li><a class=\"text\" href=\"#\" onclick=\"selectNextPage();\">Volgende</a></li>"; 
            strPaging += "</ul>";          
            
            document.getElementById("paging").innerHTML = strPaging;            
            checkPageInPaging(currPageNumber);
        }
        
        sortPrijs();                
    }
       
    
    
    
    function clearSelectedColumn() {        
        if(document.getElementById("sortprijs") != null)        
            //document.getElementById("sortprijs").setAttribute("class", "sortprijs");
            document.getElementById("sortprijs").className = "sortprijs";
            
        if(document.getElementById("sortkamers") != null)        
            //document.getElementById("sortkamers").setAttribute("class", "sortkamers");
            document.getElementById("sortkamers").className = "sortkamers";
            
        if(document.getElementById("sortplaats") != null)        
            //document.getElementById("sortplaats").setAttribute("class", "sortplaats");
            document.getElementById("sortplaats").className = "sortplaats";
    }
    
    function showSortingArrowImage(elem, sortRule) 
    {
        //clear all arrow images
        if(document.getElementById("sortprijs")!=null && document.getElementById("sortprijs").childNodes.length > 1) {
            document.getElementById("sortprijs").removeChild(document.getElementById("sortprijs").childNodes[1]);
        }        
       if(document.getElementById("sortkamers")!=null && document.getElementById("sortkamers").childNodes.length > 1) {
            document.getElementById("sortkamers").removeChild(document.getElementById("sortkamers").childNodes[1]);
        }
        
        if(document.getElementById("sortplaats")!=null && document.getElementById("sortplaats").childNodes.length > 1) {
            document.getElementById("sortplaats").removeChild(document.getElementById("sortplaats").childNodes[1]);
        }
        
        //create image element
        var img = document.createElement("img");
        img.setAttribute("height", "7");
        img.setAttribute("alt", "");        
        if(sortRule == "asc") { img.setAttribute("src", "/gfx/icons/arrow_ascending.gif"); } 
        else { img.setAttribute("src", "/gfx/icons/arrow_descending.gif"); }
        
        //add new image to the sorting column element
        elem.appendChild(img);
    }
       
    function sortPrijs() 
    {   
        clearSelectedColumn();
        //document.getElementById("sortprijs").setAttribute("class", "sortprijs selected");    
        document.getElementById("sortprijs").className = "sortprijs selected";    
    
        if(sortPrijsRule == "asc") {                 
            sortDesc(14, false);        
            sortPrijsRule = "desc";
        } else {            
            sortAsc(14, false);        
            sortPrijsRule = "asc";
        }        
        
        showSortingArrowImage(document.getElementById("sortprijs"), sortPrijsRule);
    }    
        
    function sortKamers() {
    
        clearSelectedColumn();
        //document.getElementById("sortkamers").setAttribute("class", "sortkamers selected");    
        document.getElementById("sortkamers").className = "sortkamers selected";
    
        if(sortKamersRule == "asc") {                 
            sortDesc(15);        
            sortKamersRule = "desc";
        } else {            
            sortAsc(15);        
            sortKamersRule = "asc";
        }        
        
        showSortingArrowImage(document.getElementById("sortkamers"), sortKamersRule);
    }  
    
     function sortPlaats() 
     {     
        clearSelectedColumn();
        //document.getElementById("sortplaats").setAttribute("class", "sortplaats selected");        
        document.getElementById("sortplaats").className = "sortplaats selected";        
     
        if(sortPlaatsRule == "asc") {                 
            sortDesc(5, true);        
            sortPlaatsRule = "desc";
        } else {            
            sortAsc(5, true);        
            sortPlaatsRule = "asc";
        }        
        
        showSortingArrowImage(document.getElementById("sortplaats"), sortPlaatsRule);
    }    
    
    function sortOppervalkte() 
    {
        clearSelectedColumn();
        //document.getElementById("sortkamers").setAttribute("class", "sortkamers selected");        
        document.getElementById("sortkamers").className = "sortkamers selected";        
     
        if(sortOppervalkteRule == "asc") {                 
            sortDesc(16, false);        
            sortOppervalkteRule = "desc";
        } else {            
            sortAsc(16, false);        
            sortOppervalkteRule = "asc";
        } 
        
        showSortingArrowImage(document.getElementById("sortkamers"), sortOppervalkteRule);
    }
    
    function sortAsc(itemIndex, isString) {
        var x, y, holder;        
        var a1, a2;
        
        arrPrijsSort = new Array();
        //arrPrijsSort = arrObjects;    
        for(x=0; x<arrObjects.length; x++) {
            if(filterType == -1 || filterType == arrObjects[x][17])
            {
                arrPrijsSort.push(arrObjects[x]);
            }
        }
        
        for(x=0; x<arrPrijsSort.length; x++) {
            for(y=0; y<(arrPrijsSort.length-1); y++) { 
                if(!isString) 
                {                       
                    if(arrPrijsSort[y][itemIndex].length == 0) { arrPrijsSort[y][itemIndex] = 0;}
                    if(arrPrijsSort[y+1][itemIndex].length == 0) { arrPrijsSort[y+1][itemIndex] = 0;}                
                                 
                    a1 = parseInt(arrPrijsSort[y][itemIndex], 10);
                    a2 = parseInt(arrPrijsSort[y+1][itemIndex], 10);
                } else {
                    a1 = (arrPrijsSort[y][itemIndex]).toString();
                    a2 = (arrPrijsSort[y+1][itemIndex]).toString();
                }
                
                if(a1 > a2) {
                    holder = arrPrijsSort[y+1];
                    arrPrijsSort[y+1] = arrPrijsSort[y];
                    arrPrijsSort[y] = holder;
                }
            }
        }         
        //arrObjects = arrPrijsSort;        
        selectPage(currPageNumber);
    }
    
    function sortDesc(itemIndex, isString) {
        var x, y, holder;     
        var a1, a2;
           
        arrPrijsSort = new Array();   
        //arrPrijsSort = arrObjects;    
        for(x=0; x<arrObjects.length; x++) {
            //arrPrijsSort[x] = arrObjects[x];
            if(filterType == -1 || filterType == arrObjects[x][17])
            {
                arrPrijsSort.push(arrObjects[x]);
            }
        }
        
        for(x=0; x<arrPrijsSort.length; x++) {
            for(y=0; y<(arrPrijsSort.length-1); y++) {   
                if(!isString) 
                {
                    if(arrPrijsSort[y][itemIndex].length == 0) { arrPrijsSort[y][itemIndex] = 0;}
                    if(arrPrijsSort[y+1][itemIndex].length == 0) { arrPrijsSort[y+1][itemIndex] = 0;}  
                                        
                    a1 = parseInt(arrPrijsSort[y][itemIndex], 10);
                    a2 = parseInt(arrPrijsSort[y+1][itemIndex], 10);
                } else {
                    a1 = (arrPrijsSort[y][itemIndex]).toString();
                    a2 = (arrPrijsSort[y+1][itemIndex]).toString();                
                }
                           
                if(a1 < a2) {
                    holder = arrPrijsSort[y];
                    arrPrijsSort[y] = arrPrijsSort[y+1];
                    arrPrijsSort[y+1] = holder;
                }
            }
        }         
        //arrObjects = arrPrijsSort;        
        selectPage(currPageNumber);
    }

    
    
    
    //------------------------------------------------------------ START PAGING FUNC
    function selectPage(pageNumber) 
    {          
        checkPageInPaging(pageNumber);        
        currPageNumber = pageNumber;
        strResults = "<ul>";       
        
        for(var a=0; a<arrPrijsSort.length; a++) {        
            var frompg = pageNumber*10-10;
            var topg = pageNumber*10-1;
            
            if(a>=frompg && a<=topg) { 
                strResults += "<li>";
                //strResults += arrObjects[a][12];
                strResults += arrPrijsSort[a][12];
                strResults += "</li>";
            }
        }                   
        strResults += "</ul>";
        document.getElementById("overzichtlijst").innerHTML = strResults;                
    }         
    
    function checkPageInPaging(pageNumber) 
    {    
        var pgItems = document.getElementById("paging");
        if(pgItems != null && pgItems.hasChildNodes()) 
        {            
            var el = document.getElementById("paging").getElementsByTagName("a");            
            for(var j=0; j<el.length; j++)  {
                //if(el[j].getAttribute("class") == "selected") {                
                //    el[j].removeAttribute("class");                    
                //}                
                if(el[j].className == "selected") {                
                    el[j].className = "";                    
                }                
                if(j == pageNumber) {
                    //el[j].setAttribute("class", "selected");  
                    el[j].className = "selected";
                }                
            }
        }    
    }  
    
    function selectNextPage() {        
        var currPageNum = currPageNumber;
        var pagesCount = Math.ceil(arrObjects.length/10);        
        
        if(currPageNum < pagesCount) {
            var newPageNum = parseInt(currPageNum) + 1;            
            selectPage(newPageNum);
        } 
    }
    
    function selectPrevPage() {                     
        var currPageNum =  currPageNumber;
        if(currPageNum > 1) {
            var newPageNum = parseInt(currPageNum) - 1;            
            selectPage(newPageNum);
        }     
    }
    //------------------------------------------------------------ END PAGING FUNC
    
    
    
    function load(){
        if (GBrowserIsCompatible()) {
            var labels = [];
            map = new GMap2(document.getElementById("gmmap"));
            // Display the map, with some controls and set the initial location 
            map.addControl(new GLargeMapControl());
            map.addControl(new GMapTypeControl());

		// add the HtmlControl to the map	
		//var html='<div class="legend"><img class="maps-header" src="/gfx/googlemaps/legenda_top.png" width="115" height="17" alt="" /><ul id="legenda_inhoud"><li class="legenda_icon_orange">Sociale huur</li><li class="legenda_icon_green">Nieuwbouw in ontwikkeling</li><li class="legenda_icon_blue">Vrije sector huur</li></ul></div></div>';
		var html= getLegend();		
		legendMessage=new HtmlControl(html);		
		//alert(legendMessage);
		map.addControl(legendMessage, new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10, 10)));
			

            map.setCenter(new GLatLng(mapLat, mapLong),11);
            //map.enableScrollWheelZoom();
            map.disableScrollWheelZoom();
            map.enableContinuousZoom();
            map.enableDoubleClickZoom();
            var loadUrl = strUrl;            
            if(startWijk!=""){
                loadUrl+="?wijk="+startWijk;
                ResetWijk(startWijk);
                document.getElementById("wijknaam").innerHTML = "<h1 class=\"page-title\">In " + startWijk + "</h1>";
                document.getElementById("kieseenwijk").innerHTML = "<h3>Kies een andere wijk</h3>";
                document.getElementById("wijklinks").style.display = "";
                document.getElementById("wijklinkstitel").innerHTML = "Meer informatie over " + startWijk +":<br />";

		        document.getElementById("subsubnavigation").innerHTML = "";
      			document.getElementById("subsubnavigation").innerHTML += getMenuString(startWijk);
                document.getElementById("subsubnavigation").innerHTML += "";
            }
            
            $("#first-level-nav a, #second-level-nav a, #rightCol a, #servicemenuNav a").click(function() {
		        request.abort();
		        return true;
	        });

            request = GXmlHttp.create();
            request.open("GET", "/inc/" + loadUrl + "", true);
            document.getElementById("gmloading").style.display="";
            
            request.onreadystatechange = function() {
                if (request.readyState == 4) {
                       
                    var xmlDoc = request.responseXML                    
                    if(xmlDoc.documentElement == null)
                        return;

                    loadMarks(xmlDoc);
                    document.getElementById("gmloading").style.display="none";
                    if(strLoadObject!=""){
                        showItemById(strLoadObject)
                    }
                }
            }
            
            request.send(null);

            $("img.maps-header").click(function() {
		        //window.alert('oke!!!');
		        $("#legenda_inhoud").slideToggle(250);
	        });
	        
	        //sortPrijs();
            
        }else {
            alert("Sorry, the Google Maps API is not compatible with this browser");
        }

    //]]>
    }

function InfoBox(marker,divHeight, anchorOffsetX, anchorOffsetY, divHtml) 
{
    this.marker = marker;
    //this.template = template;
    this.divHeight = divHeight;
    this.anchorOffsetX = anchorOffsetX;
    this.divHtml = divHtml
    if (null == this.anchorOffsetX){
        this.anchorOffsetX = 0;
    }

    this.anchorOffsetY = anchorOffsetY;

    if (null == this.anchorOffsetY){
        this.anchorOffsetY = 0;
    }

}

InfoBox.prototype = new GOverlay();

InfoBox.prototype.initialize = function(map) 
{
    var div = document.createElement("div");
    div.style.position = "absolute";
    div.innerHTML = this.divHtml
    div.style.left 	= (map.fromLatLngToDivPixel(this.marker.getPoint()).x - this.anchorOffsetX)+ 'px';
    div.style.top 	= (map.fromLatLngToDivPixel(this.marker.getPoint()).y - this.divHeight - this.anchorOffsetY) + 'px';
    map.getPane(G_MAP_FLOAT_PANE).appendChild(div);
    this.map_ = map;
    this.div_ = div;
    this.marker.hide();
}

InfoBox.prototype.remove = function() 
{
    this.div_.parentNode.removeChild(this.div_);
}

InfoBox.prototype.redraw = function(force) 
{
    this.div_.style.left 	= (this.map_.fromLatLngToDivPixel(this.marker.getPoint()).x - this.anchorOffsetX)+ 'px';
    this.div_.style.top = (this.map_.fromLatLngToDivPixel(this.marker.getPoint()).y - this.divHeight - this.anchorOffsetY) + 'px';
}
function showActiveDetails()
{
    if(activeMarker){
        loadObjectInfo(activeMarker.PointId);
        zzShowTab('detail')
    }
}
function showActiveDetailsWijkkaart()
{
    if(activeMarker){
        document.getElementById("divObjectDetails").innerHTML="";
        //Omschrijving
        document.getElementById("divObjectDetails").innerHTML+=""+ arrObjects[activeMarker.PointId][7] + "";
        map.setCenter(new GLatLng(arrObjects[activeMarker.PointId][8], arrObjects[activeMarker.PointId][9]),14);
    }
}
function showBox2(){
    map.removeOverlay(activeMarker.overlay);
    map.addOverlay(activeMarker.overlayBox2);
    map.setCenter(new GLatLng(parseFloat(arrObjects[activeMarker.PointId][8])+0.02, parseFloat(arrObjects[activeMarker.PointId][9])+0.045),12);
}
function closeOverlay()
{	
    if (activeMarker)
    {
        map.removeOverlay(activeMarker.overlay);
        map.removeOverlay(activeMarker.overlayBox2);
        activeMarker.show();
    }
    activeMarker = false;
    return false;
}

function addMarker(a,ilat,ilong, oms, resultaat, box1, box2, markertype){

    var icon = new GIcon();
    if(markertype==1){
        //huisje oranje
        icon.image = "/gfx/icons/google_huisje_orange.gif";
    }
    if(markertype==2){
        //huisje blauw
        icon.image = "/gfx/icons/google_huisje_blue.gif";
    }
    if(markertype==3){
        //huisje groen
        icon.image = "/gfx/icons/google_huisje_green.gif";
    }
    if(markertype==4){
        //wijkkaart Activiteit
        icon.image = "/gfx/icons/google_pointer_A.gif";
    }
    if(markertype==5){
        //wijkkaart Buurtkamer
        icon.image = "/gfx/icons/google_pointer_B.gif";
    }
    if(markertype==6){
        //wijkkaart Herstructurering
        icon.image = "/gfx/icons/google_pointer_H.gif";
    }
    if(markertype==7){
        //wijkkaart Infopunt
        icon.image = "/gfx/icons/google_pointer_I.gif";
    }
    if(markertype==8){
        //wijkkaart Nieuwbouw
        icon.image = "/gfx/icons/google_pointer_N.gif";
    }
    if(markertype==9){
        //wijkkaart Servicepunt
        icon.image = "/gfx/icons/google_pointer_S.gif";
    }
    if(markertype==10){
        //wijkkaart Verhuur
        icon.image = "/gfx/icons/google_pointer_V.gif";
    }
    if(markertype==11){
        //wijkkaart Staedion
        icon.image = "/gfx/icons/google_pointer_staedion.v2.gif";
    }
    if(markertype==12){
        //google_pointer_wijk
        icon.image = "/gfx/icons/google_pointer_wijk.gif";
    }
    if(markertype==13){
        //googlepointer berging
        icon.image= "/gfx/icons/google_pointer_p_geel.gif"
    }
    if(markertype==14){
        //googlepointer overdekte parkeerplaats
        icon.image= "/gfx/icons/google_pointer_p_bruin.gif"
    }
    if(markertype==15){
        //googlepointer parkeerbox
        icon.image= "/gfx/icons/google_pointer_p_groen.gif"
    }
    if(markertype==16){
        //googlepointer parkeerplaatsmetbuegel
        icon.image= "/gfx/icons/google_pointer_p_blauw.gif"
    }
    if(markertype==17){
        //google_pointer_huurbedrijf
        icon.image= "/gfx/icons/google_pointer_huurbedrijf.gif"
    }
    if(markertype==18){
        //huisje rood
        icon.image = "/gfx/icons/google_huisje_red.gif";
    }
    if(markertype==19){
        //huisje geel
        icon.image = "/gfx/icons/google_huisje_yellow.png";
    }
    if(markertype==20){
        //huisje paars
        icon.image = "/gfx/icons/google_huisje_purple.png";
    }    
    
    //21.24
    icon.iconSize = new GSize(26,34);
    icon.iconAnchor = new GPoint(17,34);

    var marker = new GMarker(new GLatLng(ilat,ilong), icon);
    marker.divBox1 = box1;
    marker.divBox2 = box2;
    marker.oms = oms;
    marker.resultaat = resultaat;
    marker.PointId = a;
    if(markertype!=11 && markertype!=12){
        GEvent.addListener(marker, "mouseover", function() {
            if (activeMarker){
                closeOverlay();
            }
            activeMarker=this;
            activeMarker.overlay = new InfoBox(activeMarker, 31, 17, 3, box1);
            activeMarker.overlayBox2 = new InfoBox(activeMarker, 31, 17, 128, box2);
            map.addOverlay(activeMarker.overlay);
        });
    }
    if(markertype==11){
        GEvent.addListener(marker, "mouseover", function() {
            if (activeMarker){
                closeOverlay();
            }
            activeMarker=this;
            activeMarker.overlay = new InfoBox(activeMarker, 31, 17, 3, box1);
            activeMarker.overlayBox2 = new InfoBox(activeMarker, 31, 17, 127, box2);
            map.addOverlay(activeMarker.overlayBox2);
        });
    }
    map.addOverlay(marker);
}
function switchTabs(from,to){
    document.getElementById(from).style.display="none";
    document.getElementById(to).style.display="";
}
function switchToDetails(){
    document.getElementById("tabKaart").style.display="none";
    document.getElementById("tabResultatenlijst").style.display="none";
    document.getElementById("divDetails").style.display="";
}
function switchToMap(){
    document.getElementById("tabKaart").style.display="";
    document.getElementById("tabResultatenlijst").style.display="none";
    document.getElementById("divDetails").style.display="none";
}


function HtmlControl(html, options){
	this.html=html;
	this.isVisible=true;
	this.isPrintable=false;	
	this.isSelectable=true;
	if(options){
		this.isVisible=(options.visible===false)?false:true;
		this.isPrintable=(options.printable===true)?true:false;
		this.isSelectable=(options.selectable===true)?true:false;
	}
}

HtmlControl.prototype=new GControl();

HtmlControl.prototype.initialize=function(map){
	this.div=document.createElement('div');
	this.div.innerHTML=this.html;
	this.setVisible(this.isVisible);
	map.getContainer().appendChild(this.div);
	return this.div;
};

HtmlControl.prototype.getDefaultPosition=function(){
	return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(7,7));
};

HtmlControl.prototype.selectable=function(){
	return this.isSelectable;
};

HtmlControl.prototype.printable=function(){
	return this.isPrintable;
};

HtmlControl.prototype.setVisible=function(bool){
	this.div.style.display=bool ? '':'none';
	this.isVisible=bool;
};

HtmlControl.prototype.visible=function(){
	return this.isVisible;
}	

$(document).ready(function() {
   //window.alert("Test");
});


function selectLegendItem(itemtype) {    
    //Hide all items
    $("div#gmmap div div div:eq(8) img").each(function (i) {
        this.style.display = "none";       
    });      
    //hide expanded item
    showExtMapItemBox(false, itemtype);  
    
    
    //get search string
    var searchstr;
        
    if(itemtype == "orange") 
    {
        searchstr = "/gfx/icons/google_huisje_orange.gif";   
        filterType = 1;
    }
        
    if(itemtype == "blue") 
    {
        searchstr = "/gfx/icons/google_huisje_blue.gif"; 
        filterType = 2;
    }
    if(itemtype == "green") 
    {
        searchstr = "/gfx/icons/google_huisje_green.gif"; 
        filterType = 3;
    }
    if(itemtype == "red") 
    {
        searchstr = "/gfx/icons/google_huisje_red.gif";
        filterType = 18;
    }
    if(itemtype == "yellow") 
    {
        searchstr = "/gfx/icons/google_huisje_yellow.png";
        filterType = 19;
    }
    if(itemtype == "purple") 
    {
        searchstr = "/gfx/icons/google_huisje_purple.png";
        filterType = 20;
    }
        
    if(itemtype == "bed") 
    {
        searchstr = "/gfx/icons/google_pointer_huurbedrijf.gif";              
        filterType = 17;
    }
        
    if(itemtype == "berging")
    { 
        searchstr = "/gfx/icons/google_pointer_p_geel.gif"; 
        filterType = 13;
    }
    if(itemtype == "garage") 
    {
        searchstr = "/gfx/icons/google_pointer_p_groen.gif"; 
        filterType = 15;
    }
    if(itemtype == "overpark")
    { 
        searchstr = "/gfx/icons/google_pointer_p_bruin.gif"; 
        filterType = 14;
    }
    if(itemtype == "park") 
    {
        searchstr = "/gfx/icons/google_pointer_p_blauw.gif"; 
        filterType = 16;
    }
    
    
    //show only items matched to the search string
    $("div#gmmap div div div:eq(8) img").each(function (i) {        
        if((this.src).match(searchstr) != null) {            
            this.style.display = "block";       
        }
    });
    //show expanded item
    showExtMapItemBox(true, itemtype);
    
    // filter the list of objects in result tab
    filterMarks();
}

function showExtMapItemBox(flag, itemtype) {    
    if(flag) {
        if(itemtype=="blue")
        {
                $("div.gmboxklein_blue").show();
                $("div.gmboxgroot_blue").show();
        }
        if(itemtype=="orange") 
        {
             $("div.gmboxklein_orange").show();
             $("div.gmboxgroot_orange").show();
        }
        if(itemtype=="green")       
        {
            $("div.gmboxklein_green").show();
            $("div.gmboxgroot_green").show();
        }
        if(itemtype=="red")         
        {
            $("div.gmboxklein_red").show();
            $("div.gmboxgroot_red").show();
        }
        if(itemtype=="bed")
        {
            $("div.gmboxkleinmidden_br").parent().show();
            $("div.gmboxgrootmiddenlijnen_op").parent().show();
        }
        if(itemtype=="park")
        {        
            $("div.gmboxkleinmidden_pl").parent().show();
            $("div.gmboxgrootmiddenlijnen_pl").parent().show();
        }
        if(itemtype=="overpark")    
        {
            $("div.gmboxkleinmidden_op").parent().show();
            $("div.gmboxgrootmiddenlijnen_op").parent().show();
        }
        if(itemtype=="berging")    
        {
            $("div.gmboxkleinmidden_bg").parent().show();
            $("div.gmboxgrootmiddenlijnen_bg").parent().show();
        }
        if(itemtype=="garage")    
        {
            $("div.gmboxkleinmidden_px").parent().show();
            $("div.gmboxgrootmiddenlijnen_px").parent().show();
        }
        
      /*  || itemtype=="berging" || itemtype=="garage" ||  || )    
            $("div.gmboxklein").show();*/
            
       /* $("div.gmboxklein").show();
        $("div.gmboxklein").show();
        $("div.gmboxklein").show();
        $("div.gmboxklein").show();*/
    } else {
        if(itemtype!="blue")  
        {
            $("div.gmboxklein_blue").hide();
            $("div.gmboxgroot_blue").hide();
        }
        if(itemtype!="orange")
        {
            $("div.gmboxklein_orange").hide();
            $("div.gmboxgroot_orange").hide();
        }
        if(itemtype!="green") 
        {
            $("div.gmboxklein_green").hide();
            $("div.gmboxgroot_green").hide();
        }
        if(itemtype!="red")
        {
            $("div.gmboxklein_red").hide();
            $("div.gmboxgroot_red").hide();            
        }
        if(itemtype!="yellow")
        {
            $("div.gmboxklein_yellow").hide();
            $("div.gmboxgroot_yellow").hide();            
        }
        if(itemtype!="purple")
        {
            $("div.gmboxklein_purple").hide();
            $("div.gmboxgroot_purple").hide();            
        }
        
        if(itemtype!="bed")
        {
             $("div.gmboxkleinmidden_br").parent().hide();
             $("div.gmboxgrootmiddenlijnen_op").parent().hide();                 
        }
        //if(itemtype!="berging")     $("div.gmboxklein").hide();
        //if(itemtype!="garage")      $("div.gmboxklein").hide();
        if(itemtype!="overpark")
        {
            $("div.gmboxkleinmidden_op").parent().hide();
            $("div.gmboxgrootmiddenlijnen_op").parent().hide();
        }
        if(itemtype!="park")
        {        
            $("div.gmboxkleinmidden_pl").parent().hide();
            //$("div.gmboxgrootmiddenlijnen_op").parent().hide();
            $("div.gmboxgrootmiddenlijnen_pl").parent().hide();
        }
        if(itemtype!="berging")
        {        
            $("div.gmboxkleinmidden_bg").parent().hide();
            //$("div.gmboxgrootmiddenlijnen_op").parent().hide();
            $("div.gmboxgrootmiddenlijnen_bg").parent().hide();
        }
        if(itemtype!="garage")
        {        
            $("div.gmboxkleinmidden_px").parent().hide();
            //$("div.gmboxgrootmiddenlijnen_op").parent().hide();
            $("div.gmboxgrootmiddenlijnen_px").parent().hide();
        }
    }
}
