﻿// JScript File

function browserDetect()
{
    if (($.browser.msie && $.browser.version.number >= 7) || $.browser.firefox) 
    {
        // Do nothing, this browser is supported.
    } else {
        // This browser is not supported, show a facebox message.
        $.facebox(
            'It looks like you are using an unsupported browser.  ' +
            'This site supports Internet Explorer 7.0+ and Firefox.<br><br>' +
            'You can download a supported browser for free here:<br><br>' +
            '<table width="100%"><tr><td style="text-align: center;">'+
            '<a href="http://getfirefox.com/" title="Get Firefox - The Browser, Reloaded."><img src="http://www.mozilla.org/products/firefox/buttons/getfirefox_88x31.png" width="88" height="31" border="0" alt="Get Firefox"></a>' +
            '</td><td style="text-align: center;">' +
            '<a href="http://www.microsoft.com/windows/ie/default.mspx" title="Get Internet Explorer 7."><img src="http://www.tacprogram.com/App_Themes/default/i/getIE7.gif" border="0" alt="Get IE 7"></a>' +
            '</td></tr></table>');
        //$('body').append('<div id="facebox" style="height: 100%; width:100%; z-index:99; position:absolute; background-color: #000000; opacity: 0.75;"></div>');
    }
}

var stillThere;

function setAlertTimeout(mins)
{
    setTimeout('alertTimeout(' + mins + ');', 1000 * 60 * (mins - 1));
}

function alertTimeout(mins)
{
    stillThere = false;
    $.facebox('<div id="alertTimeout">Are you still there?  In order to keep your data confidential, you will automatically be logged out in 60 seconds.  Please <a href="#" onclick="stillThere=true; refreshSession(); $.facebox.close(); ">click here</a> to remain logged in.</div>');
    setTimeout('alertLoggedOut(' + mins + ');', 1000 * 60);
}

function alertLoggedOut(mins)
{
    if (stillThere == false)
    {
        window.location.href ="/login.aspx?action=logout&msg=You have been inactive for more than 20 minutes without clicking a button or a link.  In order to keep your data confidential, you have been automatically logged out."
    } else {
        setAlertTimeout(mins);
    }
}

function refreshSession()
{
    $.get('/App/Home.aspx');
}

// jQuery AJAX Configuration
$.ajaxSetup({
  cache: false
});

// Global Ajax Events
$("body").append("<div id='ajax_error' />");
$("#ajax_error").bind("ajaxError", function(event, request, settings){
    $("#ajax_error").html("Ajax error requesting: <a href='" + settings.url + "'>" + settings.url + "</a>").show();
});

// ClientStatus Get Status Popup
function ClientStatus_GetPopup(ClientRecordId, IntakeDateId, DropDateId, RestartDateId)
{
    var location = window.location + "&AjaxId=ClientStatus_ajax&AjaxFunct=GetStatusPopup&AjaxParam1=" + ClientRecordId;
    $.get(location,
        function(data)
        {
            $.facebox(data);
            $("#" + IntakeDateId).datepicker();
            $("#" + DropDateId).datepicker();
            $("#" + RestartDateId).datepicker();
        }
    )
}
