﻿function addToBuyersFolder(propertyId) {
    savePropertyToBuyersFolder("Saving Property to Your Buyer's Folder", "Saving Listing: " + propertyId + " to your Buyers Folder - please wait...", propertyId);
}
function savePropertyToBuyersFolder(title, message, propertyId) {
    var offset = $("#contentContainer").offset();
    $("#saveNotificationContainer").css('left', offset.left + 150);

    $("#saveTitle").attr("innerHTML", title);
    $("#saveMessage").attr("innerHTML", message);
    $("#btnCloseSaveNotificationWindow").hide();

    $("#saveNotificationContainer").show('fold', 200, function() {
        $.post("/BuyersFolder/SavePropertyToBuyersFolder",
        {
            PropertyID: propertyId
        },
            function(result) {

                $("#saveMessage").attr("innerHTML", result.Message);
                $("#btnCloseSaveNotificationWindow").show();
                
                if (result.Success)
                    setTimeout(closeSaveNotificationWindow, 2000);

            }, "json");
    });
}
function closeSaveNotificationWindow() {
    $("#saveNotificationContainer:visible").hide('fold', 300);
}
function mapProperties() {  populateBuyersMap(); }
function reloadProperties() {
    $.post("/BuyersFolder/GetBuyersProperties", {},
        function(result) {
            $("#spList").attr("innerHTML", result);
            _displayQiv = true;
        }, "html");
    populateBuyersMap();
}
function runSearch(searchId) {
    window.location = '/Search/SavedSearch/' + searchId;
}
function deleteProperty(propertyId) {
    $.post("/BuyersFolder/DeletePropertyFromBuyersFolder",
        {
            PropertyID: propertyId
        }, function(result) {
            if (result.LoginNeeded)
                showMessageBox(result.Message, 'Your Session Timed Out', true);
            else {
                if (result.Success) {
                    hideQiv(propertyId);
                    _displayQiv = false;
                    $('#sp_' + propertyId).hide('slide', { direction: 'up' }, 400, function() { reloadProperties(); });
                }
            }
        }, "json");
    }
function deleteSavedSearch(searchId) {
    $.post("/BuyersFolder/DeleteSearchFromBuyersFolder",
        {
            SearchId: searchId
        }, function(result) {
            
            if (result.Success) {
                $('#ss_' + searchId).hide('slide', { direction: 'up' }, 400, function() { reloadSearches(); });
            }   
        }, "json"
    );
}
function reloadSearches() {
    $.post("/BuyersFolder/GetBuyersSearches", {},
        function(result) {
            $("#ssTabPanel").attr("innerHTML", result);
        }, "html"
    );
}
function updateEmailPreferences(deactivateGuid, emailUpdates)
{
    $.post("/BuyersFolder/UpdateEmailPreferences", {
        DeactivateGuid: deactivateGuid,
        EmailUpdates: emailUpdates
    },
        function(result) {
            reloadSearches();
        }, "json"
    );
}
function swapTabs(tabId) {
    $(".selectedTab").toggleClass("unselectedTab").toggleClass("selectedTab");
    $('#' + tabId).toggleClass("selectedTab").toggleClass("unselectedTab");
    $('.bfPanel:visible').hide();
    $('#' + tabId + 'Panel:hidden').show();
}
function setSecretQuestion(questionId) {
    $("#SecretQuestion option").each(function() {
        if ($(this).val() == questionId)
            this.selected = true;
    });
}