﻿
var InDevelopment = false;

function ShowMapFilter() {
    /// <summary></summary>    
    /// <returns>nothing</returns>
    
    var map = $get('divMapFilter');
    
    if (map == null)
    {
        Debug(InDevelopment, 'Error, cannot find Map Div by the name: divMapFilter');
        return;
    }
    
    if (map.style.display == "none")
        map.style.display = "block";
    else    
        map.style.display = "none";
    
}

function PropertyDistrictClicked(districtName) {
    /// <summary></summary>
    /// <param name="districtName">The Property District Name in URI Safe format (use _ instead of spaces)</param>
    /// <returns>nothing</returns>
    
    Debug(InDevelopment, 'DistrictName: ' + districtName);     
        
    var host = window.location.host;    
    var protocol = window.location.protocol;       
    var CurrentListingType = GetCurrentListingType();    
    var CurrentPropertyType = GetCurrentPropertyType();
    var newLocation = protocol + "//" + host + "/Properties/" + CurrentListingType + "/" + CurrentPropertyType + "/" + districtName + "/Search_Results.aspx";
    Debug(InDevelopment, 'newLocation: ' + newLocation);
    
    window.location = newLocation;
}

function GetCurrentURLInfo() {
    /// <summary>This function will loop through the window.location object</summary>    
    /// <returns>A string containing all location.location properties delimited by a newline char</returns>
  var x = window.location;
   var t = ['Property - Typeof - Value',
            'window.location - ' + (typeof x) + ' - ' + x ];
   for (var prop in x){
     t.push(prop + ' - ' + (typeof x[prop]) + ' - ' +  (x[prop] || 'n/a'));
   } 
   
   return t.join("\n");
}
 
function GetCurrentListingType() {
    /// <summary>The CurrentListingType is in position 2 of our PathName</summary>    
    /// <returns>The CurrentListingType which is in position 2 of our PathName when this script is run</returns>
      
    return GetPathArray()[2]; // our first item in our array is empty because of the way split works with pathname
}

function GetCurrentPropertyType() {
    /// <summary></summary>
    /// <param name=""></param>
    /// <returns></returns>    
    
    return GetPathArray()[3]; // our first item in our array is empty because of the way split works with pathname
}

function GetPathArray() {
var currentPathName = window.location.pathname;    
    var pathObj = currentPathName.split("/");
   
    if ( InDevelopment) {
        for (var i = 0; i < pathObj.length; i++)
            Debug(InDevelopment, 'item: ' +  pathObj[i]);
    }
        
    if (pathObj == null) alert("Error, could not parse the current URL");
    if (pathObj.length < 1) alert("Error, could not parse the current URL");
    
    return pathObj;
}


