﻿// JScript File

var gFilters = [];
gFilters["filter_regions"] = "";
gFilters["filter_locations"] = "";
gFilters["filter_types"] = "";
gFilters["filter_amenities"] = "";
gFilters["filter_projects"] = "";
                        

function ApplyFilter(name, value)
{
    // Show loading
	document.getElementById("loadingDiv").style.display = "block";
	
    gFilters[name] = value;
    
    // convert array into filter string
    var temp = "";
    for(var i in gFilters)
    {            
        if(gFilters[i] != "")
        {
            if(temp != "")
                temp += "$";
            temp += i + "=" + gFilters[i];
        }
    }

    UpdateFilters(temp);
}

function RenderFilters(arg)
{  
    // Get JSON array
    var all_results = eval("(" + arg + ")" );
    var filters = all_results.filters;
    var results = all_results.results;
    
      
    // set filters
    for(var i=0; i<filters.length; i++)
    {
        temp = "";
        filter = filters[i];
        
        if(filter.name == "filter_projects")
        {
            for(var j=0; j<filter.options.length; j++)
            {
                name = filter.options[j].name;
                link = "/properties/" + name.replace(/ /g,"_") + ".html";
                temp += "<li><a href=\"" + link + "\">" + name + "</a></li>";
            }
        }
        else
        {
            for(var j=0; j<filter.options.length; j++)
            {
                name = filter.options[j].name;
                count = filter.options[j].count;
                value = filter.options[j].id;
                
                // if 0 projects don't show
                if(count == 0)
                    continue;
                
                // if the filter is already set, show the off option
                if(gFilters[filter.name] != "")
                {
                    count = "off";
                    value = "''";
                }
                
                text = name + " (" + count + ")";
                link = "javascript:ApplyFilter('" + filter.name + "'," + value + ")";
                
                temp += "<li><a href=\"" + link + "\">" + text + "</a></li>";
            }
        }
        
        // Add html to the filter
        temp = "<ul>" + temp + "</ul>";
        document.getElementById(filter.name).innerHTML = temp;
    }
    
    
    // set results
    temp = "";
    for(var i=0; i<results.length; i++)
    {
        id = results[i].id;
        name = results[i].name;
        location_name = results[i].location;
        image = "http://richardpaz.com/RealProjects/project_images/" + results[i].image;
        price = results[i].price;
        description_result = results[i].description;
        link = "/properties/" + name.replace(/ /g,"_") + ".html";
        featured = results[i].featured;
        if(featured)
            fclass = " class=\"featured\" ";
        else
            fclass = "";
        
        temp += "<li" + fclass + "><a href=\"" + link + "\"><img src=\"" + image + "\">" + name + "</a><div class=\"result_description\">" + description_result + "</div></li>";

    }

    temp = "<ul>" + temp + "</ul>";
    document.getElementById("results").innerHTML = temp;

    if (gFilters["filter_locations"] > 0) {
        switch (parseInt(gFilters["filter_locations"])) {
            case 1: // aventura
                document.title = "Paz Global: Your Source For Aventura Real Estate Including Aventura Condos and Foreclosures";
                document.getElementById(PageTitle).innerHTML = "<h1>Aventura Real Estate - Aventura Homes For Sale - Aventura Condos For Sale - Aventura Foreclosures</h1>";
                document.getElementById(LocationDescription).innerHTML = "<div style=\"padding:0 5px 15px 5px; align-text:justify\">PazGlobal.com is home to the best <a class=\"hl\" href=\"/properties\">Aventura real estate</a>! We offer <a class=\"hl\" href=\"/properties\">Aventura foreclosures</a>, <a class=\"hl\" href=\"/properties\">Aventura condos</a>, and <a class=\"hl\" href=\"/properties\">Aventura homes for sale</a>. Our Aventura foreclosures have the highest quality standard, with clean title and the lowest prices. The city has established its niche as an enclave of tropical landscaping. Most Aventura real estate is water-surrounding featuring sleek high-rises and luxurious Aventura homes for sale. Majestic palms line the roadways, colorful flowers cover the medians of Country Club Drive, and majestic Aventura condos line up the sky with a chic exuberance. The Founders Park features a bayside path, a children’s playground, tennis courts, and a multi-purpose athletic field. Besides being known for its highly sought-after condos, the neighborhood offers world-class shopping at Aventura Mall. If you're looking to invest, this is really the place: only a few of steps to the beach and neighboring world-known Sunny Isles Beach, but without losing its urban, business-like feeling.</div>";
                break;
            case 6: // miami beach
                document.title = "Paz Global: Your source for Miami Beach condos for sale and Miami Beach foreclosures";
                document.getElementById(PageTitle).innerHTML = "<h1>Miami Beach Condos For Sale - Miami Beach Foreclosures - Miami Beach Real Estate</h1>";
                document.getElementById(LocationDescription).innerHTML = "<div style=\"padding:0 5px 15px 5px; align-text:justify\">PazGlobal.com is home to the best <a class=\"hl\" href=\"/properties\">Miami Beach condos for sale</a>. SoBe is a yearly destination to thousands worldwide in search of a good time or shopping for Miami Beach condos for sale. Bound by Ocean Drive/Collins Avenue with its world-known <a class=\"hl\" href=\"/properties\">Miami Beach condos</a> on one side and the Intracoastal Waterway with its many luxury high-rises on the other side, the city is home to thousands seeking the ultimate tropical lifestyle. With year-round ocean breezes and warm temperatures, condos in Miami Beach are a desirable home for celebrities and the \"rich and famous.\"  The neighborhood is always evolving as many <a class=\"hl\" href=\"/properties\">Miami Beach condos</a> are constantly being renovated or replaced. In this ever-changing market, buyers now have their turn to invest in <a class=\"hl\" href=\"/properties\">Miami Beach foreclosures</a> and the lowest priced Miami Beach condos for sale. If you’re looking to invest, SoBe is really the place.</div>";
                break;
            case 10: // sunny isles beach
                document.title = "Paz Global: Your source for Sunny Isles real estate including Sunny Isles condos for sale";
                document.getElementById(PageTitle).innerHTML = "<h1>Sunny Isles Real Estate - Sunny Isles Condos For Sale - Sunny Isles Foreclosures</h1>";
                document.getElementById(LocationDescription).innerHTML = "<div style=\"padding:0 5px 15px 5px; align-text:justify\">PazGlobal.com is home to the best <a class=\"hl\" href=\"/properties\">Sunny Isles real estate</a>! We offer <a class=\"hl\" href=\"/properties\">Sunny Isles condos for sale</a>, foreclosures, and single-family homes. The City is a barrier island bounded by the Atlantic Ocean and luxurious Sunny Isles condos on the east and the Intracoastal Waterway on the west. Visited by 1 million investors and vacationers annually in search of <a class=\"hl\" href=\"/properties\">Sunny Isles real estate</a> and looking to enjoy its two-mile long fine sand beach and outdoor amenities such as boating, fishing, and tennis as well as the fine shopping and dining options nearby. The landmark fishing pier is a local favorite, as well as the white sand beach from which you can admire the ocean side of the finest Sunny Isles condos. The City is experiencing a major redevelopment renaissance on the east side of Collins Avenue thanks to the dynamic market of Sunny Isles condos for sale. If you’re looking to invest, this is really the place: a world-known vacation destination to the wealthiest.</div>";
                break;
            default:
                document.title = "CONDOS & COMMUNITIES";
                document.getElementById(PageTitle).innerHTML = "CONDOS & COMMUNITIES";
                document.getElementById(LocationDescription).innerHTML = "<div style=\"padding:0 5px 15px 5px; align-text:justify\"></div>";
        }
    }
    
    // Hide loading
    document.getElementById("loadingDiv").style.display = "none";

}

function UpdateFiltersFirstTime()
{
    // Show loading
	document.getElementById("loadingDiv").style.display = "block";
	
	UpdateFilters('');
}


