﻿// Begin Supporting JQuery Functions //
// Misc Start //
function presentSecureWindow(url) {
    $('#secureWindowIFrame').attr('src', url);
    $('#secureWindowIFrame').attr('height', '100%');
    $('#secureWindow').dialog('option', 'width', ($(window).width() - 80));
    $('#secureWindow').dialog('option', 'height', ($(window).height() - 25));    
    $('#secureWindow').dialog('open');
};
$.urlParam = function(name) {
    var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
    if (!results) { return 0; }
    return results[1] || 0;
}
function resizeIFrame(iframeObj) {
    var obj = $(iframeObj);
    var innerDoc = (obj.get(0).contentDocument) ? obj.get(0).contentDocument : obj.get(0).contentWindow.document;
    obj.height(innerDoc.body.scrollHeight);
}
function prepTabs(selector, defaultIndex, urlParamSelector) {
    selector.tabs({ selected: defaultIndex, select: function(event, ui) {
        var url = $.data(ui.tab, 'load.tabs');
        if (url) {
            location.href = url;
            return false;
        }
            return true;
        }
    });
    var tabIndex = $.urlParam(urlParamSelector);
    var tabCount = selector.tabs("length") - 1;
    var canSwitch = (tabIndex < 1 | tabIndex > tabCount) ? false : true;
    if (canSwitch) {
        selector.tabs('select', tabIndex);
    }
}
// Misc End //
// Start Chat Support Functions //
function handleChatRequest() {
    //if ($("#chatWindow").length != 0) {
    //    if (getCookie('ChatRequested') == null) {            
    //        setTimeout(function () { presentChatWindow() }, 5000);
    //    }
    //}
};
function presentChatWindow() {
    $("#chatWindow").css('top', $(window).scrollTop() + 200 + 'px');
    $("#chatWindow").css('left', ($(window).width() / 2) - ($("#chatWindow").width() / 2));
    $("#chatWindow").slideDown('600');
    holdDivPositionStart($("#chatWindow"));
}
function declineChat() {
    setCookie('ChatRequested', true, 1, '/', '', '');
    $("#chatWindow").slideUp();
}
// End Chat Support Functions //
// Start Scrolling Functions //
function holdDivPositionStart(selector) {
    var scrollingDiv = selector;
    $(window).scroll(function () {
        scrollingDiv.stop().animate({"marginTop": $(window).scrollTop() + "px" }, "slow");
    });
}
// End Scrolling Functions //
// Menu Start //
var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;
function jsddm_open() {
    jsddm_canceltimer();
    jsddm_close();
    ddmenuitem = $(this).find('ul').css('visibility', 'visible');
}
function jsddm_close()
{ if (ddmenuitem) ddmenuitem.css('visibility', 'hidden'); }
function jsddm_timer()
{ closetimer = window.setTimeout(jsddm_close, timeout); }
function jsddm_canceltimer() {
    if (closetimer) {
        window.clearTimeout(closetimer);
        closetimer = null;
    }
}
document.onclick = jsddm_close
// Menu End //
// End Supporting JQuery Functions //
