﻿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 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();
}
function setVisitCookie(value) {
    if (getVisitCookie() == "")
    {
        if (value)
            value = 'true';
        else
            value = 'false';
        var expiredays = 365;
        var exdate = new Date();
        exdate.setDate(exdate.getDate() + expiredays);
        document.cookie = "Visited=" + value + ((expiredays == null) ? "" : "expires=" + exdate.toGMTString());
    }
}
function getVisitCookie() {
    var c_name = "Visited";
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}
