﻿

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(onEndRequest);
function onEndRequest(sender, args) {
    if (args.get_error() != undefined) {
        alert(args.get_error());
        args.set_errorHandled(true);

    }

}

function zoomToCluster(lat, lon) {

    var map = reimers.map.GMap
    reimers.map.clearAllOverlays(reimers.map.GMap, ctl00_ContentPlaceHolder1_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 showChangePassword() {
    $('#dlgChangePassword').parent().appendTo(jQuery('form:first'));
    $('#dlgChangePassword').dialog('open');
}
function showDlg(title, html, supportsButtons) {
    $('#dlg').dialog("option", "title", title);
    var spn = $('#dlgMessage');
    if (supportsButtons) {
        $('#dlg').dialog("option", "height", "150");
        $('#dlg').dialog("option", "buttons", { 'Register': function () { $(location).attr('href', 'register.aspx'); }, 'Cancel': function () { $(this).dialog("close"); } });

    }
    else {
        $('#dlg').dialog("option", "height", "100");
        $('#dlg').dialog("option", "buttons", "");
    }

    $('#dlg').dialog('open');
    spn.html(html);
}
function hideDlg() {
    if ($('#dlg').dialog('isOpen')) {
        $('#dlg').dialog('close');
    }
}



function invalidAddress() {

    var html = "We could not locate the address you have entered.<br />Please enter a valid address and try again.";
    showDlg("Invalid Address", html, false)

}


function hideNoRecords() {
    hideDlg();
}

function showNoRecords() {
    var html = "We could not find any listings.<br />You can zoom out on the map or change your search filter.";
    showDlg("No Listings Found", html, false)
}

function openDialog(address) {
    hideCustomProgress();
    $('#dialog').dialog("option", "title", address);
    $('#dialog').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.";
    showDlg("Search Server Busy", html, false)
}


function addListingWarning() {
    var html = "You must register as a landlord to add listings.<br />Please loging as a landlord.";
    showDlg("Not A Landlord", html, true)


}
function registrationRequiredEmailLandlord() {
    var html = "Contacting landlord requires registration.<br />Please register for an accont<br/>it's free and and easy.";
    showDlg("Registration Required", html, true)


}
function registrationRequiredBookmark() {
    var html = "Adding bookmarks requires registration.<br />Please register for an accont<br/>it's free and and easy.";
    showDlg("Registration Required", html, true)


}
function registrationRequiredMessage() {
    var html = "Adding listings requires registration.<br />Please register for an accont<br/>it's free and and easy.";
    showDlg("Registration Required", html, true)


}




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 loadCityInfo(city, prov) {

    getRadAjaxManager().ajaxRequest("UpdateCityInfo|" + city + "|" + prov);
}
function bindTopCities() {

    showTopCities();
    getRadAjaxManager().ajaxRequest("updateTopCities|" + getBoundsString());
}


function updateBookmarks() {

    getRadAjaxManager().ajaxRequest("updateBookmarks");
}
function bindTopCitiesAndProperties() {


    showTopCities();
    getRadAjaxManager().ajaxRequest("updateListingsAndCities|" + getBoundsString());
    hideCustomProgress();
}
function loadProperties() {

    hideCustomProgress();
    showFilter();
    getRadAjaxManager().ajaxRequest("update|" + getBoundsString());
}

$(function () {

    $('#dlg').dialog({
        autoOpen: false,
        width: 430,
        height: 100,
        resizable: false,
        draggable: false,
        modal: true
    });


    $('#tabs').tabs();
    $('#tabsProvinces').tabs({ selected: 7, event: 'click' });
    $('#tabsDialog').tabs();
    $('#resultTabs').tabs();
    $('#dialog').dialog({
        autoOpen: false,
        width: 430,
        resizable: false,
        draggable: false,
        modal: true
    });
    $('#dlgChangePassword').dialog({
        autoOpen: false,
        width: 430,
        resizable: false,
        draggable: false,
        modal: true
    });
    $('#dialogProgress').dialog({
        autoOpen: false,
        width: 150,
        height: 70,
        resizable: false
    });
    $("#dialogProgress").dialog().parents(".ui-dialog").find(".ui-dialog-titlebar").remove();

});


function showFilter() {
    var div = $('#divTopCities');
    div.hide();

    $('#divSideHeader').text("Advanced Filter");
    $('#divSideHeader').show();
    var div = $('#divFilter');
    div.show();

    var infoMsg = $("#infoMessage");
    infoMsg.html("<img src='images/16x16/bulb.gif'  width='14' height=14' align='absMiddle' alt='info'/> You can use advanced filtering to narrow your search.");
    infoMsg.show("slow");
}


function showTopCities() {
    var div = $('#divTopCities');
    div.show();
    $('#divSideHeader').show();
    $('#divSideHeader').text("Quick Jump");
    var div = $('#divFilter');
    div.hide();

    var infoMsg = $("#infoMessage");
    infoMsg.html("<img src='images/16x16/bulb.gif' width='14' height=14' alt='info' align='absMiddle' /> You can use quick jump/map zooming specific communities.");
    infoMsg.show("slow");
}
