try { console.log(); } catch(e) { var console = { log: function(s){}, time: function(s){}, timeEnd: function(s){}, process: function(s){}, processEnd: function(s){} }; } var mls_info = []; Array.prototype.unique = function () { var r = []; o:for(var i = 0, n = this.length; i < n; i++) { for(var x = 0, y = r.length; x < y; x++) { if(r[x]==this[i]) { continue o; } } r[r.length] = this[i]; } return r; }; function isset( ) { var a=arguments; var l=a.length; var i=0; if (l===0) { throw new Error('Empty isset'); } while (i!=l) { if (typeof(a[i])=='undefined' || a[i]===null) { return false; } else { i++; } } return true; } function ucwords (str) { return (str+'').replace(/^(.)|\s(.)/g, function ( $1 ) { return $1.toUpperCase( ); } ); } function number_format (number, decimals, dec_point, thousands_sep) { var n = number, prec = decimals; var toFixedFix = function (n,prec) { var k = Math.pow(10,prec); return (Math.round(n*k)/k).toString(); }; n = !isFinite(+n) ? 0 : +n; prec = !isFinite(+prec) ? 0 : Math.abs(prec); var sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep; var dec = (typeof dec_point === 'undefined') ? '.' : dec_point; var s = (prec > 0) ? toFixedFix(n, prec) : toFixedFix(Math.round(n), prec); //fix for IE parseFloat(0.55).toFixed(0) = 0; var abs = toFixedFix(Math.abs(n), prec); var _, i; if (abs >= 1000) { _ = abs.split(/\D/); i = _[0].length % 3 || 3; _[0] = s.slice(0,i + (n < 0)) + _[0].slice(i).replace(/(\d{3})/g, sep+'$1'); s = _.join(dec); } else { s = s.replace('.', dec); } var decPos = s.indexOf(dec); if (prec >= 1 && decPos !== -1 && (s.length-decPos-1) < prec) { s += new Array(prec-(s.length-decPos-1)).join(0)+'0'; } else if (prec >= 1 && decPos === -1) { s += dec+new Array(prec).join(0)+'0'; } return s; } function in_array (needle, haystack, argStrict) { var key = '', strict = !!argStrict; if (strict) { for (key in haystack) { if (haystack[key] === needle) { return true; } } } else { for (key in haystack) { if (haystack[key] == needle) { return true; } } } return false; } function update_location_list() { var $areas = $("#area_selection :checked"); var area_names = $areas.map( function(){ return $(this).val(); }).get(); $locations = $("#location_selection li"); var areas_selector = $areas.map( function(){ return "." + $(this).val().replace(" ","_"); }).get().join(","); $active_locations = $locations.filter(areas_selector).show(); $inactive_locations = $locations.not(areas_selector).hide().find("input").attr('checked', false); if($active_locations.length) { $('#alert_select_an_area').hide(); } else { $('#alert_select_an_area').show(); } $active_locations.each(function(i) { $location = $(this); var location_name = $location.find(".location_name").html(); var listings_count = 0; $.each(location_statistics[location_name].areas, function(i, v) { if( in_array(i, area_names) ) { listings_count += v; } }); $location.show().find(".listings_count").html(listings_count + " listings"); }); $("#location_selection").css("overflow-x", "auto"); } function update_categories_and_locations(selected_mls) { $quick_search = $("#quick_search"); if($quick_search.length) { default_area = mls_info[selected_mls].default_area; default_location = mls_info[selected_mls].default_location; area_search_name = default_area === "county" ? "counties" : default_area + "s"; location_search_name = default_location === "city" ? "towns" : default_location + "s"; if(typeof selected_mls == "undefined") { return false; } var c_ops = ""; $.each( mls_info[selected_mls].categories, function(i, v){ c_ops += ""; }); $(".select_category").html(c_ops).attr("disabled", false); var a_ops = ""; $.each( mls_info[selected_mls].areas, function(i, v){ a_ops += ""; }); $(".select_area").html(a_ops).attr("name", area_search_name).attr("disabled", false); var l_ops = ""; $.each( mls_info[selected_mls].locations, function(i, v){ l_ops += ""; }); $(".select_location").html(l_ops).attr("name", location_search_name).attr("disabled", false); } } function update_area_locations(selected_mls, selected_area) { $quick_search = $("#quick_search"); if($quick_search.length) { if(typeof selected_mls == 'undefined') { return false; } if(typeof selected_mls == 'undefined') { return false; } var l_ops = ""; $.each( mls_info[selected_mls].locations, function(i, v){ if( isset( mls_info[selected_mls].statistics[v].areas[selected_area] ) ) { l_ops += ""; } }); $(".select_location").html(l_ops).attr("disabled", false); } } function update_property_count() { $property_search_form = $("#property_search_form"); $properties_found = $("#properties_found").html(" "); $("#search_criteria_summary").empty(); var search_criteria_text = ""; var field_values = []; $fields = $property_search_form.find(":input").not("input[type='hidden']:not(input[name='mls'],input[name='category']),:checkbox:not(:checked),:submit,input[name=''],input[value=''],select[value=''],select[value='0']"); $fields.each( function(i){ $field = $(this); var field_name = $field.attr("name").replace("[","").replace("]",""); var field_value = $field.val(); if( typeof( field_values[field_name] ) == "undefined" ) { field_values[field_name] = field_value; } else { field_values[field_name] += ", " + field_value; } }); var field_names = $fields.map( function(){ return $(this).attr("name").replace("[","").replace("]",""); }).get().unique(); $.each( field_names, function(i, v){ if(search_criteria_text !== "") { search_criteria_text += " - "; } if(v === "added_low") { search_criteria_text += "Added Since: " + field_values[v]; } else { field_name = v==="mls" ? v.replace("-"," ").toUpperCase() : ucwords(v.replace("_"," ").toLowerCase()); search_criteria_text += "" + field_name + ": " + field_values[v]; } }); $('#search_criteria_summary').html(search_criteria_text); var query_string = $fields.fieldSerialize() + "&ajax_action=get_property_count"; $.getJSON('/pa_ajax.php?' + query_string, {}, function(data) { $properties_found.html("Found " + number_format(data.property_count) + " Properties"); if( data.property_count === 0 ) { $("#search_button_area").removeClass("highlight_yellow highlight_green").addClass("highlight_red"); $properties_found.append("
Loading Property');
$.get('/pa_ajax.php', { action: 'map_window', mls_number: listing.mls_number, mls: listing.mls, category: listing.category }, function(data_html) {
map.openInfoWindowHtml(point, data_html);
});
});
markers.push(marker);
bounds.extend(point);
}
});
var cluster=new ClusterMarker(map, { markers:markers, clusterMarkerIcon:housesIcon, clusterMarkerTitle:"Click to zoom in and see %count properties" } );
cluster.refresh();
if(map_coordinates.length>1)
{
map.setZoom(map.getBoundsZoomLevel(bounds));
} else
{
map.setZoom(map.getBoundsZoomLevel(bounds)-3);
}
map.setCenter(bounds.getCenter());
}});
} else
{
console.log('Could not find map_id: ' + map_id);
}
}
function load_property_details(mls_number, mls, category, skipHistory)
{
$.scrollTo('#onjax_tools', 100, {offset:-25} );
$('#search_form_and_results').hide();
$('#property_details_loading').fadeIn(1000, function()
{
var data = {action: 'get_property_details', mls_number: mls_number, mls: mls, category: category};
$('#property_details').load('/pa_ajax.php', data, function (responseText)
{
$('#property_details_loading').hide();
$('#property_details_div').show();
var please_login = $('#please_login').html();
if( please_login )
{
$('#login_div').slideDown();
document.customer_login_form.customer_email.focus();
} else
{
initialize_google_map('property_details_google_map', map_coordinates);
}
});
});
}
$(function(){
$quick_search = $("#quick_search");
if($quick_search.length)
{
$select_mls = $('select.select_mls', '#quick_search');
if( $select_mls.length )
{
$('select.select_mls', '#quick_search').change(function(){
$selects = $(this).parents('#quick_search').find('select').not('.select_mls');
$selects.attr('disabled', true);
selected_mls = $(this).val();
if( selected_mls !== '' )
{
$selects.attr('disabled', false);
$('.select_category').html('').attr('disabled', true);
$('.select_area').html('').attr('disabled', true);
$('.select_location').html('').attr('disabled', true);
if( isset( mls_info[selected_mls] ) )
{
update_categories_and_locations(selected_mls);
} else
{
$.getJSON('/pa_ajax.php', {ajax_action: 'get_mls_info', mls: selected_mls}, function(data) {
mls_info[selected_mls] = data;
update_categories_and_locations(selected_mls);
});
}
} else
{
$(".submit_button", "#quick_search").val("SEARCH");
}
}).change();
} else
{
selected_mls = $('input.select_mls').val();
if( !isset( mls_info[selected_mls] ) )
{
$.getJSON('/pa_ajax.php', {ajax_action: 'get_mls_info', mls: selected_mls}, function(data) {
mls_info[selected_mls] = data;
});
}
}
$("#quick_search form :input").change(function(){
$this = $(this);
$form = $this.parents("form");
selected_mls = $form.find(".select_mls").val();
selected_category = $form.find(".select_category").val();
selected_area = $form.find(".select_area").val();
$submit_button = $form.find(":submit");
if( $this.hasClass("select_area") )
{
update_area_locations(selected_mls, selected_area);
}
if( selected_mls !== "" && selected_category !== "")
{
var query_string = $form.serialize() + "&ajax_action=get_property_count";
$.getJSON('/pa_ajax.php?' + query_string, {}, function(data) {
$submit_button.val( number_format(data.property_count) + " Properties");
});
} else
{
$form.find(":submit").val("SEARCH");
}
});
$("#quick_search form").submit(function(){
$form = $(this);
if( $('.select_mls', $form).val() === '' )
{
alert("Please Select a Listing Source / MLS");
return false;
} else if( $('.select_category', $form).val() === '' )
{
alert("Please Select a Property Type");
return false;
}
return true;
});
}
$property_search_form = $("#property_search_form");
if( $property_search_form.length )
{
update_location_list();
$area_selection = $("#area_selection");
$area_selection.find("input").click(function(e)
{
e.stopPropagation();
update_location_list();
return true;
});
$("#select_all_areas").click(function(e)
{
e.stopPropagation();
$area_selection.find("input").attr("checked", this.checked);
update_location_list();
return true;
});
$property_search_form_inputs = $property_search_form.find(":input:not(:checkbox)");
$property_search_form_inputs.change(function(){
update_property_count();
});
$property_search_form_checkboxes = $property_search_form.find(":checkbox");
$property_search_form_checkboxes.click(function(){
update_property_count();
});
update_property_count();
}
if( isset(map_coordinates) )
{
if( $("#google_map").length ) { initialize_google_map('google_map', map_coordinates); }
if( $("#property_details_google_map").length ) { initialize_google_map('property_details_google_map', map_coordinates); }
}
$google_map_div = $("#map_div");
if($google_map_div.length) { $google_map_div.resizable(); }
$("#real_estate_tools").tabs({spinner: ""});
});