var forceOpenEmployeeLogin = false;

function initializeJQueryCode() {
    /////////////////////////////////////////////////////////////////////////
    // Validation
    /////////////////////////////////////////////////////////////////////////
    $.validity.setup({ outputMode: 'modal', modalErrorsClickable: true });
    $(".validate").click(function () {
        $.validity.start();
        $(".requiredfield").require();
        $(".datefield").match("date");
        $(".emailfield").match("email");
        $(".integerfield").match("number");
        $(".numberfield").match("number");
        $(".numericfield").match("number");
        $(".decimalfield").match("number");
        $(".moneyfield").match("number");
        var result = $.validity.end();
        if (!result.valid) {
            $(".validity-summary-container").show();
            $('html, body').animate({ scrollTop: 0 }, 'fast');
        }
        return result.valid;
    });
    $("label.validity-modal-msg").click(function () { $(this).hide(); return true; });
    try {
        $(".datefield").datepicker({ changeMonth: true, changeYear: true, numberOfMonths: 1, showOtherMonths: true, selectOtherMonths: true, showButtonPanel: true, showOn: 'focus' });
        $(".datefield").datepicker('option', '{showAnim: slideDown}');
    } catch (err) { }
    try {
        $(".datefield").attr('autocomplete', 'off');
    } catch (err) { }

    /////////////////////////////////////////////////////////////////////////
    // Marquee
    /////////////////////////////////////////////////////////////////////////
    $('.marquee_cycle').cycle({
        fx: 'scrollHorz',
        speed: 550,
        timeout: 6000
    });

    /////////////////////////////////////////////////////////////////////////
    // Watermark
    /////////////////////////////////////////////////////////////////////////
    $('.jq_watermark').watermark();

    /////////////////////////////////////////////////////////////////////////
    // Colorbox
    /////////////////////////////////////////////////////////////////////////
    $('.popup_video').colorbox({
        inline: true,
        href: "#divPopupVideo",
        innerWidth: "675px",
        innerHeight: "475px",
        title: "EZ Rent to Own"
    });

    /////////////////////////////////////////////////////////////////////////
    // Employee Login
    /////////////////////////////////////////////////////////////////////////
    $("#open").click(function () {
        $("div#panel").slideDown("slow");
    });
    $("#close").click(function () {
        $("div#panel").slideUp("slow");
    });
    $("#toggle a").click(function () {
        $("#toggle a").toggle();
    });
}

$(document).ready(function () {

    initializeJQueryCode();

    if (forceOpenEmployeeLogin) {
        $("div#panel").slideDown("slow");
        $(".login-open").hide();
        $(".login-close").show();
    }
});

function PopupWindow(aUrl, w, h, sb, rs, tb, dir, st, mnu) {
    if (!sb) sb = "yes"; if (!rs) rs = "yes"; if (!tb) tb = "no"; if (!dir) dir = "no"; if (!st) st = "no"; if (!mnu) mnu = "no";
    popupWin = window.open(aUrl, "PopupWin", "scrollbars=" + sb + ",resizable=" + rs + ",toolbar=" + tb + ",directories=" + dir + ",status=" + st + ",menubar=" + mnu + ",width=" + w + ",height=" + h + ",resizable=yes");
    popupWin.self.focus();
}

function PopupNamedWindow(aName, aUrl, w, h, sb, rs, tb, dir, st, mnu) {
    if (!sb) sb = "yes"; if (!rs) rs = "yes"; if (!tb) tb = "no"; if (!dir) dir = "no"; if (!st) st = "no"; if (!mnu) mnu = "no";
    popupWin = window.open(aUrl, aName, "scrollbars=" + sb + ",resizable=" + rs + ",toolbar=" + tb + ",directories=" + dir + ",status=" + st + ",menubar=" + mnu + ",width=" + w + ",height=" + h + ",resizable=yes");
    popupWin.self.focus();
}

function PopupUniqueWindow(aUrl, w, h, sb, rs, tb, dir, st, mnu) {
    if (!sb) sb = "yes"; if (!rs) rs = "yes"; if (!tb) tb = "no"; if (!dir) dir = "no"; if (!st) st = "no"; if (!mnu) mnu = "no";
    popupWin = window.open(aUrl, "PopupWin" + (new Date()).getTime(), "scrollbars=" + sb + ",resizable=" + rs + ",toolbar=" + tb + ",directories=" + dir + ",status=" + st + ",menubar=" + mnu + ",width=" + w + ",height=" + h + ",resizable=yes");
    popupWin.self.focus();
}

function HideShowControl(ctrlid) {
    var ctrl = document.getElementById(ctrlid);
    if (ctrl.style.display == "none") {
        ctrl.style.display = "";
    }
    else {
        ctrl.style.display = "none";
    }
}

function HideControl() {
    var ctrl;

    for (i = 0; i < arguments.length; i++) {
        ctrl = document.getElementById(arguments[i]);
        if (ctrl.style.display != "none") {
            ctrl.style.display = "none";
        }
    }
}

function ShowControl() {
    var ctrl;

    for (i = 0; i < arguments.length; i++) {
        ctrl = document.getElementById(arguments[i]);

        if (ctrl.style.display == "none") {
            ctrl.style.display = "";
        }
    }
}
