/**
 * Main map functions
 */
MAPUTILS  = function () {
    
    //global map object
    MAPUTILS.prototype.map;
    MAPUTILS.prototype.counter = 0;
    MAPUTILS.prototype.token = null;

    //default map settings
    MAPUTILS.prototype.currentLat =  40;
    MAPUTILS.prototype.currentLng =  -100;
    MAPUTILS.prototype.currentZoom = 4;
    MAPUTILS.prototype.currentPid = 0;
    
    MAPUTILS.prototype.mapSizeW = 500;
    MAPUTILS.prototype.mapSizeH = 500;
    
    
    MAPUTILS.prototype.initMap = function() {
        
        //check if map object has been loaded or created
        try{
            document.getElementById('map').innerHTML;
        }catch(e){
            if (this.counter > 60) { 
                alert('Can\'t load map! Can\'t find map object!');
            } else { 
                setTimeout("maputil.initMap()", 1000);                 
            } 
            return false; 
        }
    
        //If gmaps main.js didn't load try to call init again after 60 tries we give up
        if (typeof GMap != "function") { 
            if (this.counter > 60) { 
                document.getElementById('map').innerHTML = 'Can\'t load map! Gmap server timeout! ';
            } else { 
                setTimeout("maputil.initMap()", 1000); 
            } 
            this.counter++; 
            return false; 
        }
        
        //if browser not compatible update map tag with error msg
        if (!GBrowserIsCompatible()) { 
            document.getElementById('map').innerHTML = 'Can\'t load map because your browser is too old or key is invalid!';
            return false;
        }
    
        //init gmaps object
        this.map = new GMap2(document.getElementById("map"));
        
                    
        //set center of the map
        this.map.setCenter(new GLatLng(this.currentLat, this.currentLng), this.currentZoom);  
        //this.map.setMapType(G_HYBRID_MAP);        
        
        //add controls and mouse functions
        this.map.enableDoubleClickZoom();
        this.map.enableContinuousZoom();
        this.map.enableScrollWheelZoom();
        
        //control
        this.map.addControl(new GLargeMapControl3D(), new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(5, 30)));
        this.map.addControl(new GMenuMapTypeControl());
        this.map.addControl(new GScaleControl()); 

        // Add the Terrain Map Type
        this.map.addMapType(G_PHYSICAL_MAP);
        // Create a Hierercical map type control
        this.map.setMapType(G_PHYSICAL_MAP);
        //filter
        //this.map.addControl(new maputil.MapControl(), new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(100, 6)));
        //this.map.addControl(new maputil.MapControlDropdown(), new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(100, 26)));//drop down layer
        
        
        
        var decodeUrl = window.location.hash.substring(1).split('=');
        if(decodeUrl.length>2){
             if(parseInt(decodeUrl[1])) this.currentLat = parseInt(decodeUrl[1]) / 1000000;    
             if(parseInt(decodeUrl[2])) this.currentLng = parseInt(decodeUrl[2]) / 1000000;    
             if(parseInt(decodeUrl[3])) this.currentZoom = parseInt(decodeUrl[3]);
             if(parseInt(decodeUrl[4])){
                 this.currentPid = decodeUrl[4];
                 marker.infoWindow(this.currentLat,this.currentLng,parseInt(decodeUrl[4]));
                 var inputs = document.getElementsByClassName('filterselect');
         		 for(i=0;i<inputs.length;i++){
         			 inputs[i].checked = true;	    
         		 }
             }
             maputil.map.setCenter(new GLatLng(this.currentLat, this.currentLng), this.currentZoom);      
         }

        GEvent.addListener(maputil.map, "dragend", function() {                      
             maputil.setSiteUrl();
        });
    	
    	GEvent.addListener(maputil.map, "zoomend", function() {                      
            maputil.setSiteUrl();
            marker.clearMarkers();               
            marker.getMarkers(1);
        });
        
        GEvent.addListener(maputil.map, "dragend", function() {                      
            maputil.setSiteUrl();            
            marker.getMarkers();
        });
        
        
        GEvent.addListener(maputil.map, "infowindowopen", function() {                      
            marker.ajax(marker.ajaxPath + 'getdetails/'+marker.currentPid, marker.showResults); 
            var markerCenter = maputil.map.fromLatLngToDivPixel(new GLatLng(marker.lat,marker.lng));
            markerCenter = maputil.map.fromDivPixelToLatLng(new GPoint(markerCenter.x,markerCenter.y-105));
            maputil.map.panTo(markerCenter);
            marker.processMarkeres();
            marker.hidePointLabelElement();
        });
        
        
        marker.doFilter();
        
        //marker.getMarkers(1);
        
        
         setTimeout("overlay.init()", 3000);        
    }
    

    MAPUTILS.prototype.setMapSize = function (){
        document.getElementById("map").style.width = this.mapSizeW + 'px';
        document.getElementById("map").style.height = this.mapSizeH + 'px';
    }
    
    MAPUTILS.prototype.lookUpAddress = function(latlng){  
            geocoder = new GClientGeocoder();
            geocoder.getLocations(latlng, function(addresses) {
                if(addresses.Status.code != 200) {
                    //alert("reverse geocoder failed to find an address for " + latlng.toUrlValue());
                    //latlng.toUrlValue();
                } else { 
                    var result = addresses.Placemark[0];                
                    //var street = result.address.split(',');
                    document.getElementById("mapaddress").value=result.address ; 
                   //document.getElementById("mapcity").value=street[1] ;                   
                }
            });            
        }

       MAPUTILS.prototype.searchAddress = function(str){  
            geocoder = new GClientGeocoder();
            geocoder.getLocations(str, function(addresses) {
                if(addresses.Status.code != 200) {
                    alert("Geocoder failed to find an address for " + str);
                    //latlng.toUrlValue();
                } else { 
                    var result = addresses.Placemark[0];                
                    point = new GLatLng(result.Point.coordinates[1], result.Point.coordinates[0]);
                    maputil.map.setCenter(point,12);
                    marker.getMarkers(1);
                    
                    //document.getElementById('latbox').value = point.lat();
                    //document.getElementById('lonbox').value = point.lng();  
                }
            });  
            return false;
        }

	MAPUTILS.prototype.setSiteUrl = function(){              
        	var center = maputil.map.getCenter(); 
        	maputil.mapLink = 'lat=' + Math.round(center.y*1000000)  + '|lng=' + Math.round(center.x*1000000) + '|zoom=' + maputil.map.getZoom();
        window.location = window.location.pathname + '#' +  maputil.mapLink;
	}
	
	MAPUTILS.prototype.loading = function(text) {        
        if(text.length>0){
            document.getElementById('mapLoading').style.display = 'block';
        }else{
            document.getElementById('mapLoading').style.display = 'none';
        }
    }
    
    
    
    MAPUTILS.prototype.popup = function(url,w,h){
        document.getElementById('TB_iframeContent').style.display='none';
        
        document.getElementById('TB_window').style.display='block';
        document.getElementById('TB_iframeContent').src = url;
        
          /* newwindow = window.open (url,"newwindow","location=1,status=1,scrollbars=1,width="+w+",height="+h);
           newwindow.moveTo(100,100);
           newwindow.focus();*/
       }

}

MARKERS  = function () {
    //this will store the markers
    MARKERS.prototype.markersDb = new Array();        
    
    //store circles
    MARKERS.prototype.markersDb2 = new Array();        
    
    //define icons path
    MARKERS.prototype.markerIconsPath = 'imgs/';  
    
    //store bounds
    MARKERS.prototype.bounds = new GLatLngBounds();      
    
    //ajax path
    MARKERS.prototype.ajaxPath = "";
    
    MARKERS.prototype.filter = 'start';
    MARKERS.prototype.filterTypes = new Array();
    
    MARKERS.prototype.doFilterCheck = false;
    
    MARKERS.prototype.showPointLabel = function (anchor){
        marker.showLabel(anchor.id);
        anchor.style.zIndex=4;                    
        return false;
    }
    
    MARKERS.prototype.hidePointLabel = function (anchor){
        anchor.style.zIndex=1;         
        this.hidePointLabelElement();
        return false;
    }
    
    MARKERS.prototype.hidePointLabelElement = function (){
        try{
            document.getElementById("infoLabel").style.display = 'none'; 
        }catch(e){}
    }
    
    MARKERS.prototype.processMarkeres = function(){   
        var pointsHtml = '';
        var leftHtml = '';
        var markersCount = 0;
        
        for(i=0;i<this.markersDb2.length;i++) if(this.markersDb2[i].length>5){    
                 
            p = this.markersDb2[i].split("\|");
            //console.log(p[1] +' '+p[2]);
            //calculate marker positions in pixel
            var pos = maputil.map.fromLatLngToDivPixel(new GLatLng( p[1],  p[2]));
            //extends bounds
            //this.bounds.extend(new GLatLng( p[1], p[2]));
            
            //show marker
            if(p[0]>0){
                //set offset params to center marker to position
                var x = parseInt(pos.x) - 15;
                var y = parseInt(pos.y) - 15;                          
            
                //create a new marker achor
                pointsHtml += '<a href="javascript:void(0)"'; 
                
                var turnOff = true;
                //need to check if checkbox is on
                if(marker.doFilterCheck){ 
                    //console.log(p[0]);
                    
                    try{
                        //check all checkbox with same id. if one is on don't turn off marker
                         var inputs = document.getElementsByTagName('input');
                         for(ii=0;ii<inputs.length;ii++){
                             var inputId = parseInt(inputs[ii].value);
                             if(inputs[ii].value.substr(0,1) == 'i') inputId = inputs[ii].value.substr(1);
                         	 if(inputId == parseInt(p[0]) && inputs[ii].checked){
                         	    turnOff = false;
                    	     }
                         }
                    }catch(e){}
                }else{
                    turnOff = false; 
                }
            
                //set style  and icon
                pointsHtml += 'style="position:absolute;z-index:0;';                          
                if(turnOff) pointsHtml += 'display:none;';
                //pointsHtml += "background:url('" + this.markerIconsPath + p[3] + "') no-repeat center;";              
                pointsHtml += 'top:' + y + 'px;left:' + x + 'px;" ';
                pointsHtml += 'id="marker_' + p[0] + '" ';
            
                //hover text
                pointsHtml += "rel='" + p[4] + "$|"+p[5]+"' ";
                            
                //add events to markers
                pointsHtml += 'onmouseover="marker.showPointLabel(this)" ';
                pointsHtml += 'onmouseout="marker.hidePointLabel(this)" ';
                pointsHtml += 'onclick="marker.infoWindow('+p[1]+','+p[2]+','+p[0]+')"';            
                pointsHtml += '><img src="' + this.markerIconsPath + p[3] + '" border="0" /></a>'; 
                
                
            }else{
                //show cluster marker
                var x = parseInt(pos.x) - 25;
                var y = parseInt(pos.y) - 25;                          
            
                //create a new marker achor
                pointsHtml += '<a href="javascript:void(0)" '; 
                pointsHtml += 'id="marker_' + i + '" ';
            
                //set style  and icon
                pointsHtml += 'style="height:50px;width:50px;position:absolute;z-index:0;text-align:center;line-height:70px;color:#000;';                          
                pointsHtml += "background:url('" + this.markerIconsPath + 'markers/' + p[3]+ '.png' + "') no-repeat center;";              
                pointsHtml += 'top:' + y + 'px;left:' + x + 'px;" ';
                       
                //add events to markers
                pointsHtml += 'onmouseover="marker.showPointLabel(this)" ';
                pointsHtml += 'onmouseout="marker.hidePointLabel(this)" ';
                pointsHtml += 'onclick="marker.infoWindow('+p[1]+','+p[2]+',\''+p[5]+'\')"';
                
                //hover text
                pointsHtml += "rel='" + p[6] + "$|"+p[7]+"' ";
                
                
                //pointsHtml += 'onclick="maputil.map.setCenter(new GLatLng('+p[1]+','+p[2]+'),(maputil.map.getZoom()+3))"';            
                pointsHtml += '>' + p[4] +'</a>';
                if(maputil.map.getBounds().containsLatLng(new GLatLng(p[1],p[2]))){
                    markersCount += parseInt(p[4]);
                }
            }
        }  
        
        marker.doFilterCheck = false;
        maputil.map.getPane(G_MAP_MARKER_MOUSE_TARGET_PANE).innerHTML = pointsHtml;
        maputil.loading("");
        //console.log(pointsHtml);
    }
    
    MARKERS.prototype.currentPid = '';
    MARKERS.prototype.lat = 0;
    MARKERS.prototype.lng = 0;
    
    MARKERS.prototype.infoWindow = function(lat,lng,pid){ 
        maputil.map.openInfoWindow(new GLatLng(lat,lng), '<div id="infoWin">Please wait...</div>');
        this.currentPid = pid;
        //maputil.map.panTo(new GLatLng(lat,lng));
       // marker.processMarkeres();
       marker.lat = lat;
       marker.lng = lng;
    }
    
    MARKERS.prototype.ajax = function(url,action) {    
            try {
        		xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP"); 
        	} catch (e) { } 		
        	xmlhttp.onreadystatechange = action; 		
        	xmlhttp.open("GET", url, true); 		
        	xmlhttp.send(null);   
        	maputil.loading("ajax");
                   
    }
    
    
    MARKERS.prototype.showResults = function(){ 
        if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {  
            //console.log( xmlhttp.responseText);         
            document.getElementById('infoWin').innerHTML = xmlhttp.responseText;   
            //maputil.map.openInfoWindowHtml(new GLatLng(marker.lat,marker.lng), xmlhttp.responseText);
            if(maputil.currentPid != 0){
                marker.ajax(marker.ajaxPath + '../../home/getPointInfo/' + maputil.currentPid,marker.showPointDetails);
                maputil.currentPid = 0; 
            }
            maputil.loading("");
            marker.getMarkers();
            if(xmlhttp.responseText.length>0){    			
               // document.getElementById('infoWin').innerHTML = xmlhttp.responseText;    
    			var ra = xmlhttp.responseText.split('\n');
    			var inJs = false;
    			var js = '';			
    			for(i=0; i<ra.length; i++) {
    				if(ra[i].match(/<\/script/i)) inJs = false;
    				if(inJs) js += ra[i]+"\n";
    				if(ra[i].match(/<script/i)) inJs = true;
    			}

    			try {
    				eval(js);
    			} catch(e) {
    				console.log(e);
    			}
            }
        }    
    }
    
    MARKERS.prototype.showPointDetails = function(){ 
        if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {  
            document.getElementById('infopanel').innerHTML = xmlhttp.responseText;   
            maputil.loading("");  
        }else{
             document.getElementById('infopanel').innerHTML = "<span class=\"loadingText\">Loading information ...</span>";
        }    
    }
    
    
    MARKERS.prototype.clearMarkers = function(){           
        var element = maputil.map.getPane(G_MAP_MARKER_MOUSE_TARGET_PANE);  
        while (element.firstChild) {
            element.removeChild(element.firstChild);        
        }                  
    }
    
    MARKERS.prototype.showLabel = function (markerObj){   
       //var ie7 = (document.all && !window.opera && window.XMLHttpRequest) ? true : false;
       //if(ie7) return false;           
        //try to get label element if not in the body add it
        try{
            document.getElementById('infoLabel').innerHTML;
            var label = document.getElementById('infoLabel');        
        }catch(e){
            var label = document.createElement('div');
            label.setAttribute('id','infoLabel');             
            label.onclick = function(){marker.hidePointLabelElement()}
            document.body.appendChild(label);            
        }
                
        //calculate absolute postion of the label
        var m = document.getElementById(markerObj); 
        var mapPos = this.findPos(document.getElementById('map'));
        var lY = (maputil.map.getSize().height - (maputil.map.getSize().height/2 + maputil.map.fromLatLngToDivPixel(maputil.map.getCenter()).y - parseInt(m.style.top))) + mapPos[1] ;
        var lX = (maputil.map.getSize().width - (maputil.map.getSize().width/2 + maputil.map.fromLatLngToDivPixel(maputil.map.getCenter()).x - parseInt(m.style.left))) + mapPos[0] ;
        
        //check if label in map
        if(lY<mapPos[1]+20) return false;
        if(lX<mapPos[0]+20) return false;        
        if(lY>(document.getElementById('map').offsetHeight+mapPos[1])) return false;
        if(lX>(document.getElementById('map').offsetWidth+mapPos[0])) return false;
        
        //show label
        label.style.display='block';
        
        //set attributes
        //if you need to move the label offset you can change it here
        label.style.top = (lY - 25)  + 'px';
        label.style.left = (lX + 25) + 'px';    
        var labelTxt = m.rel.split('$|');
        if(labelTxt[1].length>0) label.style.background = '#' + labelTxt[1];
        else label.style.background = '#FCB03C';
        label.innerHTML = '<span class="mapBubbleTxt">' + labelTxt[0] + '</span><span class="mapBubbleEnd"></span>';         
    }
    
    
    
    MARKERS.prototype.hideBubble = function (){ 
        try{
            document.getElementById('map_bubble').style.display = 'none';             
        }catch(e){}
    }

    MARKERS.prototype.findPos = function(obj) {        
        if (obj.offsetParent) {
            var curleft = obj.offsetLeft
            var curtop = obj.offsetTop
            while (obj = obj.offsetParent) {                    
                curleft += obj.offsetLeft
                curtop += obj.offsetTop
            }
            return [curleft,curtop];
        }    
    }
    
    MARKERS.prototype.getZoomLevel = function() {
        return maputil.map.getBoundsZoomLevel(marker.bounds);
    }
    
    MARKERS.prototype.getMarkerCenter = function() {
        return marker.bounds.getCenter();
    }    
    
    var maxx = 0, maxy = 0, minx = 0, miny = 0;
    
    MARKERS.prototype.getMarkers = function (force){
       
        var bounds = maputil.map.getBounds();
         yt = bounds.getNorthEast().y.toFixed(3);
         xt = bounds.getNorthEast().x.toFixed(3); 
         yb = bounds.getSouthWest().y.toFixed(3);
         xb = bounds.getSouthWest().x.toFixed(3);         
        //console.log('yt:'  + yt + ' yb:'  + yb + ' xt:'  + xt + ' xb:'  + xb);
        if(xt>maxx || yt>maxy || xb<minx || yb<miny || force > 0){
            var detx = xt - xb; 
            var dety = yt - yb;    
            
            maxx = (xt*1 + detx).toFixed(3)*1;            
            maxy = (yt*1 + dety).toFixed(3)*1;
            minx = (xb*1 - detx).toFixed(3)*1;    
            miny = (yb*1 - dety).toFixed(3)*1;  
           
            if(maputil.map.getZoom()>16){maxy += 0.01;maxx += 0.01;miny -= 0.01;minx -= 0.01;  } 
            
            var getUrl = marker.ajaxPath + "getpoints/?yt=" + maxy.toFixed(3) + "&xt=" + maxx.toFixed(3) + "&xb=" + minx.toFixed(3) + "&yb=" + miny.toFixed(3) +"&zoom=" +  maputil.map.getZoom() + "&filter=" + this.filter;
            if(force>1) getUrl += '&nocache=1'
           
        	xmlhttp2 = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");     		
        	
            xmlhttp2.onreadystatechange =  this.downloadMarkeres;
            xmlhttp2.open("GET", getUrl, true); 		    	
            xmlhttp2.send(null);
            maputil.loading("getmarkers");
            
        }
            
    }    
    
    MARKERS.prototype.downloadMarkeres = function(){
        if ((xmlhttp2.readyState == 4) && (xmlhttp2.status == 200)) { 	
            var rows = xmlhttp2.responseText.split("\n");
            marker.markersDb2 = rows;
            marker.processMarkeres();
            
        }
    }
    
    MARKERS.prototype.doFilter = function(){
        var checkBoxList = document.getElementsByClassName('filterselect');
        marker.filter = '';
        /*for(checkbox in checkBoxList){
            if(typeof(checkBoxList[checkbox].id) == 'string'){
                if(checkBoxList[checkbox].checked){
                    marker.filter += checkBoxList[checkbox].value + ",";
                }
            }
        }*/
        
        for(i=0;i<checkBoxList.length;i++) { 
            if(checkBoxList[i].checked){
                marker.filter +=  checkBoxList[i].value + ",";
            }
        }      
         
        //if(marker.filter.length<1) marker.filter = '0';
        marker.getMarkers(1);
    }
    
    MARKERS.prototype.checkZip = function(zip){
        marker.ajax(marker.ajaxPath + 'ajx/getzip.php?zip='+zip, marker.showZipResults); 
        maputil.searchAddress(zip);
        return false;
    }
   
    MARKERS.prototype.showZipResults = function(){ 
         if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {  
             document.getElementById('zipResults').innerHTML = xmlhttp.responseText;   
             maputil.loading("");
         }    
    }
    
    MARKERS.prototype.toggleMarker = function(mid,input){
             
        //When a POI is checked, but its parent category is unchecked, the POI should still show. 
        var getData = false;
        if(input.checked){
            var findNodes = input.parentNode;
            while (findNodes.id != 'ul500'){
              if(findNodes.className != 'leftMenuSub2'){
                  var firstInput = findNodes.getElementsByTagName('input')[0];
                  if(firstInput.name != 'checkbox2' && !firstInput.checked){
                      firstInput.checked = true;
                      getData = true;
                      marker.doFilterCheck = true;
                  }
              }
         
              findNodes = findNodesSub = findNodes.parentNode;
            }
        }
        
        if(getData){
            marker.doFilter();
        }else{
            //console.log(input.checked + ' ' + mid); 
            var turnOff = true;
            try{
                if(!input.checked){
                    //check all checkbox with same id. if one is on don't turn off marker
                    var inputs = document.getElementsByTagName('input');
            		for(i=0;i<inputs.length;i++){
            			if(parseInt(inputs[i].value) == parseInt(mid) && inputs[i].checked){
            			    turnOff = false;
        			    }
        			
            		}
                     if(turnOff) document.getElementById('marker_'+mid).style.display = 'none';
                }else{
                     document.getElementById('marker_'+mid).style.display = 'block';
                }
            }catch(e){}
        }
    }
}

OVERLAYS = function(){
    OVERLAYS.prototype.kmls = new Array();
    OVERLAYS.prototype.poly = new Array();
    
    OVERLAYS.prototype.overLayCount = 0;
    OVERLAYS.prototype.kmlLoadCount = 0;
    OVERLAYS.prototype.circlesAdded = false;
    OVERLAYS.prototype.labels = new Array();
    
    OVERLAYS.prototype.addKml = function(){
        //if got kmls send it to google's server and add results to map. count number of kmls added
        if(overlay.kmls.length>0){
            for(i=0;i<(overlay.kmls.length);i++){
                var geoXml = new GGeoXml(overlay.kmls[i]);
                maputil.map.addOverlay(geoXml);
            }
        }
    }
    
    
   
    OVERLAYS.prototype.addPolies = function(){
      if(overlay.poly.length>0){
          for(i=0;i<(overlay.poly.length);i++){
            
             var polySrc = overlay.poly[i];
             var p = new GPolygon.fromEncoded({
                polylines:[{points: polySrc[0],levels: polySrc[1],color: polySrc[2],opacity: 0.5,weight: 2,numLevels: 18,
                   zoomFactor: 2}],
                fill: true,
                color: polySrc[2],
                opacity: 0.4,
                outline: true
              });
              
             maputil.map.addOverlay(p);
          }
      }
    }
    
    OVERLAYS.prototype.init = function(){
        //overlay.addPolies();
        overlay.addKml();
        
    }
    
    
}
var overlay = new OVERLAYS;


//create maputil class
var maputil = new MAPUTILS;
//create markers class
var marker = new MARKERS;


//after page has been closed try to free up memory
window.onunload = function(){
    try{
        GUnload();
    }catch(e){}
}

if(typeof(document.getElementsByClassName) != "function"){
    
    function getElementsByClass(searchClass,node,tag) {
            var classElements = new Array();
            if ( node == null )
                    node = document;
            if ( tag == null )
                    tag = '*';
            var els = node.getElementsByTagName(tag);
            var elsLen = els.length;
            var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
            for (i = 0, j = 0; i < elsLen; i++) {
                    if ( pattern.test(els[i].className) ) {
                            classElements[j] = els[i];
                            j++;
                    }
            }
            return classElements;
    }

    document.getElementsByClassName = getElementsByClass;
}

function maClick(temp){
chkbox = document.getElementById(temp);
	if(chkbox.checked)
	{
		var poi;
		var ul
		ul =  document.getElementById('li_'+temp);
		poi = ul.getElementsByTagName('input');
		for(i=0;i<poi.length;i++)
		{
			//poi.checked = true;
			//if(ul.getElementsByTagName('input')[i].value=='checkbox')
				ul.getElementsByTagName('input')[i].checked = true;
			
		}
		
	}else{
		var poi;
		var ul;
		ul =  document.getElementById('li_'+temp);
		poi = ul.getElementsByTagName('input');
		for(i=0;i<poi.length;i++)
		{
			//poi.checked = true;
			//if(ul.getElementsByTagName('input')[i].value=='checkbox')
				ul.getElementsByTagName('input')[i].checked = false;
		}
	}

}
function maClick1(temp){
chkbox = document.getElementById(temp);
	var tempId = "ul" + temp;
	var subCatId = "subCat" + temp;
		
	if(document.getElementById(tempId)!=null){
		
		if(document.getElementById(tempId).style.visibility=='visible'){
			
			document.getElementById(tempId).style.visibility='hidden';
			document.getElementById(tempId).style.display='none';
			if(document.getElementById(subCatId)!=null){
				document.getElementById(subCatId).style.visibility='hidden';
				document.getElementById(subCatId).style.display='none';
			}
		    document.getElementById('folder_sign_'+temp).innerHTML = '+';
		}else{
			document.getElementById(tempId).style.visibility='visible';
			document.getElementById(tempId).style.display='block';
			if(document.getElementById(subCatId)!=null){
				document.getElementById(subCatId).style.visibility='visible';
				document.getElementById(subCatId).style.display='block';
			}
		    document.getElementById('folder_sign_'+temp).innerHTML = '-';
		
		}
	}
	
}

function subClick(temp){
//alert(temp);subCat
chkbox = document.getElementById(temp);
	if(chkbox.checked)
	{
		var poi;
		var ul;
		ul =  document.getElementById('li_'+temp);
		poi = ul.getElementsByTagName('input');
		for(i=0;i<poi.length;i++)
		{
			//poi.checked = true;
			//if(ul.getElementsByTagName('input')[i].value=='checkbox2')
				ul.getElementsByTagName('input')[i].checked = true;
		}
		
		
	}else{
		var poi;
		var ul;
		ul =  document.getElementById('li_'+temp);
		poi = ul.getElementsByTagName('input');
		for(i=0;i<poi.length;i++)
		{
			//poi.checked = true;
			//if(ul.getElementsByTagName('input')[i].value=='checkbox2')
				ul.getElementsByTagName('input')[i].checked = false;
		}
	}
	marker.doFilter();
}

function subClick1(temp){
    var folderSign = document.getElementById('folder_sign_sub_' + temp);
    temp = 'sub' + temp;
	chkbox = document.getElementById(temp);
	var tempId =  temp + "ul";
	if(document.getElementById(tempId)!=null){
		if(document.getElementById(tempId).style.visibility=='visible'){
			document.getElementById(tempId).style.visibility='hidden';
			document.getElementById(tempId).style.display='none';
			folderSign.innerHTML = '+';
		}else{
			document.getElementById(tempId).style.visibility='visible';
			document.getElementById(tempId).style.display='block';
			folderSign.innerHTML = '-';
		}
	}	
}

function clearMap(){
    var checkBoxList = document.getElementsByClassName('checkBoxSize');
    for(i=0;i<checkBoxList.length;i++) { 
        checkBoxList[i].checked = false;
        if(checkBoxList[i].value.substr(0,1) == 'i') checkBoxList[i].checked = true;
    }
    marker.doFilter();
    maputil.map.closeInfoWindow();
    document.getElementById('infopanel').innerHTML = '';
    maputil.map.returnToSavedPosition();
}

function tb_showIframe(){
    document.getElementById('TB_iframeContent').style.display='block';
    if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
	    document.getElementById("TB_window").style.height = '425px';
       // document.getElementById("TB_window").style.width = '500px';
        document.getElementById("TB_window").style.top = '265px';
	}
}

