﻿function zoomToCluster(lat, lon) {

    var map = reimers.map.GMap
    reimers.map.clearAllOverlays(reimers.map.GMap, GMaparrOv);
    //clear all the overalys
    map.setCenter(new GLatLng(lat, lon), map.getZoom() + 1);
}

function showCustomProgressIfPageValid() {
    if (Page_IsValid) {
        showCustomProgress();
    }
}

function showMapCustomProgress() {
    var map = reimers.map.GMap
    showCustomProgress();
}

function hideCustomProgress() {
    $('#dialogProgress').dialog('close');
}

function showCustomProgress() {

    //$('#dialogProgress').position({at: 'center center', of: $('#tdMap') });
    $('#dialogProgress').dialog('open');
}


function invalidAddress() {

    var html = "We could not locate the address you have entered.<br />Please enter a valid address and try again.";
    showErrorMessage("Invalid Address", html)
}


function openListingPopupDialog(address, listingURL) {

  
    hideCustomProgress();
    $('#listingPopupDialog').dialog("option", "title", address);
    $('#listingPopupDialog').dialog("option", "buttons", {
        'View Full Details': function () {
            window.location = listingURL;
        },
        'Close': function () {
            $(this).dialog("close");
        }
    });

    $('#listingPopupDialog').dialog('open');
}

function showAddress(lat, lon, city, prov, accuracy) {
    var map = reimers.map.GMap

    if (accuracy == 'Address') {
        map.setCenter(new GLatLng(lat, lon), 16);
    } else {
        map.setCenter(new GLatLng(lat, lon), 11);
    }
}


function searchServerBusy() {
    var html = "The search server is currently overloaded.<br />Please try again in a few moments.";
    showErrorMessage("Search Server Busy", html)
}


function zoomToCity(url) {

    document.location = url;
}

function getBoundsString() {

    var map = reimers.map.GMap;
    var bounds = map.getBounds();
    var southWest = bounds.getSouthWest();
    var northEast = bounds.getNorthEast();

    var boundsString = southWest.lat() + "|" + southWest.lng() + "|" + northEast.lat() + "|" + northEast.lng();
    return boundsString;
}


function showDialog(listingID) {

    showCustomProgress();

    getRadAjaxManager().ajaxRequest("updateInfoWindow|" + listingID);
}

function updateBookmarks() {

    getRadAjaxManager().ajaxRequest("updateBookmarks");
}

function loadProperties() {

    hideCustomProgress();

    getRadAjaxManager().ajaxRequest("update|" + getBoundsString());
}


$(function () {

    $('#tabsCitiesProvinces > div > table > tbody > tr:odd').addClass("mainCityRow")
  
    $('#tabsCitiesProvinces > div > table > tbody > tr:even').addClass("mainCityAlternatingRow")

 


    $('#listingPopupDialog').dialog({
        autoOpen: false,
        width: 450,
        height: 'auto',
        resizable: false,
        draggable: false,
        modal: true
    });


    //determine what to show
    if ($('#tabsCitiesProvinces').length) {
        $('#tabsCitiesProvinces').tabs();

        $("#tabsCitiesProvinces").tabs().addClass('ui-tabs-vertical ui-helper-clearfix');
        $("#tabsCitiesProvinces li").removeClass('ui-corner-top').addClass('ui-corner-left');
    } else {
        $('#lnkAdvancedFilter').button({ icons: { primary: 'ui-icon-play'} });
        $('#resultTabs').tabs();
        $('#tabs').tabs({ fx: { opacity: 'toggle'} });
    }

    $('#tabsDialog').tabs();
    $('#dialogProgress').dialog({
        autoOpen: false,
        width: 150,
        height: 70,
        resizable: false
    });
    $("#listingPopupDialog").dialog().parents(".ui-dialog").find(".ui-dialog-titlebar").remove();
    $("#dialogProgress").dialog().parents(".ui-dialog").find(".ui-dialog-titlebar").remove();
});
