//Enables or disables the UI
function EnableUI(state, backgroundDiv) 
{
    if (!state)
    {
        backgroundDiv.style.display = '';
        backgroundDiv.style.position = 'absolute';
        backgroundDiv.style.left = '0px';
        backgroundDiv.style.top = '0px';
        
        var clientBounds = this.GetClientBounds();
        var clientWidth = clientBounds.width;
        var clientHeight = clientBounds.height;
        backgroundDiv.style.width = 
           Math.max(Math.max(document.documentElement.scrollWidth, 
           document.body.scrollWidth), clientWidth)+'px';
        backgroundDiv.style.height = 
           Math.max(Math.max(document.documentElement.scrollHeight, 
           document.body.scrollHeight), clientHeight)+'px';
        backgroundDiv.style.zIndex = 10000;
        backgroundDiv.className = "ModalBackground1";
    }
    else
    {
        backgroundDiv.style.display = 'none';
    }
}

//Determines the bounds of the client
function GetClientBounds() 
{
    var clientWidth;
    var clientHeight;
    switch(Sys.Browser.agent) {
        case Sys.Browser.InternetExplorer:
            clientWidth = document.documentElement.clientWidth;
            clientHeight = document.documentElement.clientHeight;
            break;
        case Sys.Browser.Safari:
            clientWidth = window.innerWidth;
            clientHeight = window.innerHeight;
            break;
        case Sys.Browser.Opera:
            clientWidth = Math.min(window.innerWidth, 
                          document.body.clientWidth);
            clientHeight = Math.min(window.innerHeight, 
                           document.body.clientHeight);
            break;
        default:  // Sys.Browser.Firefox, etc.
            clientWidth = Math.min(window.innerWidth, 
                          document.documentElement.clientWidth);
            clientHeight = Math.min(window.innerHeight, 
                           document.documentElement.clientHeight);
            break;
    }
    return new Sys.UI.Bounds(0, 0, clientWidth, clientHeight);
}
///////////////////////RadWindow////////////////////////////////////
function FormatDate(date) {
    var year = PadNumber(date.getUTCFullYear(), 4);
    var month = PadNumber(date.getUTCMonth() + 1, 2);
    var day = PadNumber(date.getUTCDate(), 2);
    var hour = PadNumber(date.getUTCHours(), 2);
    var minute = PadNumber(date.getUTCMinutes(), 2);

    return month + "-" + day + "-" + year + " " + hour + ":" + minute;
}

function PadNumber(number, totalDigits) {
    number = number.toString();
    var padding = '';
    if (totalDigits > number.length) {
        for (i = 0; i < (totalDigits - number.length); i++) {
            padding += '0';
        }
    }

    return padding + number.toString();
}
function GetRadWindow() {
    var oWindow = null;
    if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog
    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; //IE (and Moz az well)
    return oWindow;
}

function CloseOnReload() {
    GetRadWindow().Close();
}
function CloseOnReloadVar(closeVar) {
    GetRadWindow().Close(closeVar);
}
function RefreshParentPage() {
    GetRadWindow().BrowserWindow.location.reload();
}
function RadWindowResize(width, height) {
    var radWindow = GetRadWindow();
    radWindow.setSize(width, height);
}
function RadWindowResizeAndCenter(width, height) {
    var radWindow = GetRadWindow();
    radWindow.restore();
    radWindow.setSize(width, height);
    radWindow.center();
}
function OpenRadWindow(url, parameter) {
    var newWindow = window.radopen(url, parameter);
    //newWindow.minimize();
    //var pageLoaded = false;
    //newWindow.add_pageLoad(
    //        function(sender, eventArgs) {
    //            if (!pageLoaded) {
    //                pageLoaded = true;
    //                newWindow.restore();
    //                newWindow.center();
    //            }
    //        }
    //    );
}
