
// map support functions
        var map, marker
        var mRed, mRedStar, mGreen, mGreenStar, mBlue, mBlueStar, mPurple, mPurpleStar, mDesign;

		function gMapIni(vLat, vLon, vDiv, vZoom) {
            if (GBrowserIsCompatible()) {
                document.getElementById(vDiv).style.display = "block";
                map = new GMap2(document.getElementById(vDiv));
				//set to the current UI of google, will update automatically if google maps changes
				//map.setUIToDefault();
				var customUI = map.getDefaultUI();
				//customUI.controls.maptypecontrol = false;
				customUI.maptypes.satellite = false;
				customUI.maptypes.physical = false;
				customUI.maptypes.hybrid = false;
				customUI.controls.menumaptypecontrol = false;
				customUI.controls.scalecontrol = false;
				map.setUI(customUI);
                //vPage will tell us if the map page of the community page is loading google maps - set zoom level according
				if (vDiv == 'gmap'){//region map
					map.setCenter(new GLatLng(vLat, vLon), vZoom);
				} else {//community map
					map.setCenter(new GLatLng(vLat, vLon), vZoom);
				}				
                //map.addControl(new GSmallMapControl());
                //map.addControl(new GMapTypeControl());
                map.enableScrollWheelZoom();

                //markers setup
					var pinDir = "/img/communities/pin/";
                    var pinRed = new GIcon(G_DEFAULT_ICON); pinRed.image = pinDir + "red.gif"; mRed = { icon: pinRed };
                    var pinRedStar = new GIcon(G_DEFAULT_ICON); pinRedStar.image = pinDir + "redStar.gif"; mRedStar = { icon: pinRedStar };
                    var pinGreen = new GIcon(G_DEFAULT_ICON);pinGreen.image = pinDir +"green.gif";mGreen = { icon: pinGreen };
                    var pinGreenStar = new GIcon(G_DEFAULT_ICON);pinGreenStar.image = pinDir +"greenStar.gif";mGreenStar = { icon: pinGreenStar };
                    var pinBlue = new GIcon(G_DEFAULT_ICON); pinBlue.image = pinDir +"blue.gif";mBlue = { icon: pinBlue };
                    var pinBlueStar = new GIcon(G_DEFAULT_ICON); pinBlueStar.image = pinDir +"blueStar.gif";mBlueStar = { icon: pinBlueStar };
                    var pinPurple = new GIcon(G_DEFAULT_ICON); pinPurple.image = pinDir +"purple.gif";mPurple = { icon: pinPurple };
                    var pinPurpleStar = new GIcon(G_DEFAULT_ICON); pinPurpleStar.image = pinDir + "purpleStar.gif"; mPurpleStar = { icon: pinPurpleStar };
                    var pinDesign = new GIcon(G_DEFAULT_ICON); pinDesign.image = pinDir + "logoBlock2.gif"; mDesign = { icon: pinDesign };
                    //var pinDesignStar = new GIcon(G_DEFAULT_ICON); pinDesignStar.image = pinDir + "design.gif"; mDesignStar = { icon: pinDesignStar };
            }
        }

        function setMarker(vId, vLat, vLon, vMkr, vInfo) {
            if (map) {
                var vMkr = eval(vMkr);
                var GLoc = new GLatLng(vLat, vLon);
                var marker = new GMarker(GLoc, vMkr);
                var vOpenInfo = vInfo.indexOf('Directions to here')
                map.addOverlay(marker);
                if (vInfo.length > 0) {
                    GEvent.addListener(marker, "click", function() {
                        marker.openInfoWindow(vInfo);
                    });
                }
                if (vOpenInfo > 0) {
                    GEvent.trigger(marker, "click");
                }
                var table = document.getElementById("results");
                if (table){
                    var tr = table.getElementsByTagName("tr");
                    for (var i = 0; i < tr.length; i++) {
                        if (tr[i].getAttribute('mapId') == vId + '') {
                            tr[i].style.cursor = 'pointer';
                            /*tr[i].onclick = function() {
                                var GLoc = new GLatLng(vLat, vLon);
								map.openInfoWindowHtml(GLoc, vInfo);
                                window.scrollTo(0, 0);
                            }*/
                        }
                    }
                }
            }
        }

        var results_trStyle;
        function resultsSetup() {
            var table = document.getElementById("results");
            var tr = table.getElementsByTagName("tr");
            for (var i = 0; i < tr.length; i++) {
                if (i % 2 == 0) { tr[i].className = 'even'; }
                if (i >= 2) {
                    tr[i].onmouseover = function() {
                        results_trStyle = this.className;
                        this.className = 'hover'
                    }
                    tr[i].onmouseout = function() {
                        this.className = results_trStyle;
                    }
                }
            }
        } 
        
// search support functions

        function srchSetup(vS, vT, vD) {
            //alert(vS +' / '+ vT +' / '+ vD)
            var frm = document.getElementById("srch");
            frm.name = frm.id;
            frm.action = '/communities/default.asp'
            frm.method = 'get';
            for (var i = 0; i < frm.elements.length; i++) {
                frm.elements[i].name = frm.elements[i].id;
            }

            if (document.URL.indexOf('/home/') > 0) {
                var vGo = document.getElementById('go')
                vGo.style.backgroundColor = '#f2b633';
                vGo.style.color = '#000000';
                vGo.value = 'Find My Home';
                vGo.style.marginLeft = '0px';
                vGo.style.fontWeight = 'bold';
                vGo.style.float = 'right';
            }

            var vDiv = document.getElementById("srchLocation")
            if (vDiv) {
                vDiv.onmouseover = function() { document.getElementById('s_ul').style.display = 'block'; }
                vDiv.onmouseout = function() { document.getElementById('s_ul').style.display = 'none'; }
                var b = vDiv.getElementsByTagName("li");
                for (var i = 0; i < b.length; i++) {b[i].onclick = function() {srchSet(this.id)}}
            }

            var vDiv = document.getElementById("srchType")
            if (vDiv) {
                vDiv.onmouseover = function() { document.getElementById('t_ul').style.display = 'block'; }
                vDiv.onmouseout = function() { document.getElementById('t_ul').style.display = 'none'; }
                var b = vDiv.getElementsByTagName("li");
                for (var i = 0; i < b.length; i++) { b[i].onclick = function() { srchSet(this.id) } } 
            }

            var vDiv = document.getElementById("srchPrice")
            if (vDiv) {
                vDiv.onmouseover = function() { document.getElementById('d_ul').style.display = 'block'; }
                vDiv.onmouseout = function() { document.getElementById('d_ul').style.display = 'none'; }
                var b = vDiv.getElementsByTagName("li");
                for (var i = 0; i < b.length; i++) { b[i].onclick = function() { srchSet(this.id) } } 
            }

            srchSet('s_'+ vS);
            srchSet('t_'+ vT);
            srchSet('d_'+ vD);
        }

        function searchValidate() {
            var s = document.getElementById('s')
            if (s) {
                if (s.value == '0') {
                    //replace the alert with a message holder
                    document.getElementById('alertMsg').style.display = 'block';
                    //alert('Please select a location');
                    return false;
                }
            } else {
              return true;
            }
        }

        function srchReset() {
            srchSet('s_0');
            srchSet('t_0');
            srchSet('d_0');
            document.location = '/community/default.asp';
        }

        function srchSet(vValue) {
            var a = vValue.split('_');
            switch (a[0]){
                case 's':
                    document.getElementById('alertMsg').style.display = 'none';
                    var vDiv = document.getElementById("srchLocation")
                    var vFld = 's';
                    var vTitle = 'srchLocation_title';
                    var vUl = 's_ul';
                    break;
                case 't':
                    var vDiv = document.getElementById("srchType")
                    var vFld = 't';
                    var vTitle = 'srchType_title';
                    var vUl = 't_ul';
                    break;
                case 'd':
                    var vDiv = document.getElementById("srchPrice")
                    var vFld = 'd';
                    var vTitle = 'srchPrice_title';
                    var vUl = 'd_ul';
                    break;
            }

            if (a[1] == '0') { document.getElementById(vFld).value = 0; }
            
            if (vDiv) {
                var b = vDiv.getElementsByTagName("li");
                for (var i = 0; i < b.length; i++) {
                    if (b[i].id == vValue) {
                        b[i].style.backgroundColor = '#687819';
                        document.getElementById(vFld).value = a[1];
                        document.getElementById(vTitle).innerHTML = b[i].innerHTML.toUpperCase();
                        document.getElementById(vUl).style.display = 'none';
                   }
                }
            }
        }