﻿function hintBoxFocus(textBox, text) {
    if (textBox.value == text) {
        textBox.value = '';
        $(textBox).removeClass("inputTextBoxWithHint");
    }
}
function hintBoxLostFocus(textBox, text) {
    if (textBox.value == '') {
        textBox.value = text;
        $(textBox).addClass("inputTextBoxWithHint");
    }
}
function refreshClientTestimonial(brokerId) {
    $.get("/Brokers/GetRandomTestimonial/" + brokerId, {}, function(result) {
        $("#brokerTestimonialContainer").attr("innerHTML", result);
    }, "html");
}
function showPropertyDetails(mlsId) {
    window.open('/PropertyDetail/' + mlsId);
}
function showMessageBox(message, title, logout) {
    var offset = $("#contentContainer").offset();
    $('#messageBoxMessage').attr('innerHTML', message);
    $('#messageBoxTitle').attr('innerHTML', (title == null) ? 'Informational Message' : title);
    $("#messageBoxContainer").css('left', offset.left + 150);
    $("#messageBoxContainer:hidden").show('fold', 400);

    $("#msgBoxOk").unbind("click");

    if (logout != null) {
        $("#btnCloseMessageBoxWindow:visible").hide();
        $("#msgBoxOk").bind('click', hardLogout);
    }
    else {
        $("#btnCloseMessageBoxWindow:hidden").show();
        $("#msgBoxOk").bind('click', closeMessageBoxWindow);
    }
}
function hardLogout() {
    closeMessageBoxWindow();
    logUserOut();
    logonTimedOut();
}
function closeMessageBoxWindow() {
    $('#messageBoxMessage').attr('innerHTML', '');
    $("#messageBoxContainer:visible").hide('fold', 200);
}
function closeSaveSearchWindow() {
    $('#saveSearchMessage').attr('innerHTML', '');
    $('#btnSaveSearchCancel').attr('value', 'Cancel');
    $('#SaveSearchName').val('');
    $('#saveSearchContainer:visible').hide('fold', 200);
}
function showSaveSearchWindow() {
    $('#saveSearchContainer:hidden').show('fold', 200, function() { $("#SaveSearchTitle").focus(); });
}
function openContactWindow(mlsId, brokerId) {
    var offset = $("#contentContainer").offset();
    $("#contactContainer").css('left', offset.left + 150);
    $("#contactContainer:hidden").show('fold', 400, function() {

    if (mlsId == null || mlsId == '')
        mlsId = '0';
    if (brokerId == null || brokerId == '')
        brokerId = '';

    var url = "/ContactForm/OpenForm/" + mlsId + "/" + brokerId;

        $.get(url, function(data) {
            $("#contactFormArea").attr("innerHTML", data);
            $("#ContactName").focus();
        }, "html");
    });
}
function closeContactWindow() {
    $("#contactFormArea").attr("innerHTML", '');
    $("#contactContainer:visible").hide('fold', 200);
}
function contactReset() {
    $("#contactMessageContainer:visible").fadeOut();
    $("#ContactName").focus();
}
function contactSubmissionComplete(content) {
    var jsonContent = content.get_response().get_object();

    if (jsonContent.SubmitSuccessful) {
        $("#contactMessageContainer").attr("innerHTML", "Contact successfully sent.");
        $("#btnContactReset").hide();
        $("#btnContactSubmit").hide();
        $("#btnContactClose").show();
    }
    else
    {
        $("#contactMessageContainer").removeClass("infoContainer");
        $("#contactMessageContainer").addClass("errorContainer");
        $("#contactMessageContainer").attr("innerHTML", jsonContent.ValidationErrors[0].ErrorMessage);
        var controls = jsonContent.ValidationErrors[0].ControlId.split(':');
        $('#' + controls[0]).focus();
    }
}
function contactSubmissionStarted() {
    $("#contactMessageContainer").attr("innerHTML", "Submitting...");
    $("#contactMessageContainer").removeClass("errorContainer");
    $("#contactMessageContainer").addClass("infoContainer");
    $("#contactMessageContainer:hidden").fadeIn();
}