﻿    map_element = "dMap";
    document.getElementById(map_element).style.display = "block";
    onload = loadMap;
    var Beds = document.getElementById("dlBeds");
    var Baths = document.getElementById("dlBaths");
    var MinPrice = document.getElementById("txMinPrice");
    var MaxPrice = document.getElementById("txMaxPrice");
    var Sqfoot = document.getElementById("txSqf");
    
    Beds.key = "Beds";
    Baths.key = "Baths";
    MinPrice.key = "MinPrice";
    MaxPrice.key = "MaxPrice";
    
    var initializing = true;
    var cookies = getCookies();
    Beds.value = cookies["Beds"]?cookies["Beds"]:"";
    Baths.value = cookies["Bath"]?cookies["Bath"]:"";
    MinPrice.value = cookies["MinPrice"]?cookies["MinPrice"]:"";
    MaxPrice.value = cookies["MaxPrice"]?cookies["MaxPrice"]:"";
    Sqfoot.value = cookies["sqf"]?cookies["sqf"]:"";
    
    initializing = false;
    
    function setPriceRange()
    {
        var minPrice = Number(MinPrice.value);
        var maxPrice = Number(MaxPrice.value);
        
        if(isNaN(minPrice))
        {
            alert("Please enter a number for Minimum Price");
            MinPrice.value = '';
            MinPrice.focus();
        }
        else if(isNaN(maxPrice))
        {
            alert("Please enter a number Maximum Price");
            MaxPrice.value = '';
            MaxPrice.focus();
        }
        else if(maxPrice>0 && minPrice > maxPrice)
        {
            alert("Invalid Price Range!\nPlease enter a starting price lower than the upper limit.");
        }
        else
        {
            setFilter(MinPrice.key, MinPrice.value);
            setFilter(MaxPrice.key, MaxPrice.value);
            reloadMap();
        }
    }
    
    function setSqf()
    {
        if(isNaN(Sqfoot.value))
        {
            alert("Please enter a number for Sq. Footage");
            Sqfoot.value = '';
            Sqfoot.focus();
            return;
        }
        
        setFilter("sqf", Sqfoot.value);
        reloadMap();
    }
    
    function getCookies()
    {
        var cks = new Object();
        var ckList = document.cookie.split("; ");
        for (var i=0; i < ckList.length; i++)
        {
            var ck = ckList[i].split("=");
            cks[ck[0]] = unescape(ck[1]);
        }
        return cks;
    }
    
    function listviewURL()
    {
        var url = document.location.pathname + "Homes.aspx?nomap=true";
        if(MinPrice.value>0)
            url += "&MinPrice=" + MinPrice.value;
        if(MaxPrice.value>0)
            url += "&MaxPrice=" + MaxPrice.value;
        if(Beds.value != "")
            url += "&Beds=" + Beds.value;
        if(Baths.value != "")
            url += "&Bath=" + Baths.value;
        return url;
    }

    function smallMapLinkClick() {
        function listviewURL() {
            var urlbase = document.location.pathname + "Homes.aspx";
            var url = "";
            if (MinPrice.value > 0)
                url += "&MinPrice=" + MinPrice.value;
            if (MaxPrice.value > 0)
                url += "&MaxPrice=" + MaxPrice.value;
            if (Beds.value != "")
                url += "&Beds=" + Beds.value;
            if (Baths.value != "")
                url += "&Bath=" + Baths.value;

            if (url.length > 0) urlbase = urlbase + "?" + url;
            location = urlbase;
            return false;
        }
    }
    
