﻿//<![CDATA[

// FUNCTION: PageInitialSetup()
//           Initalizes a form by maximizing it and
//           disabling the backbutton
function pageInitialSetup() {
    disableBrowserHistory();
    maximizeBrowserWindow();
}

// FUNCTION: PageInitialSetupEx(ElemendId)
//           Initalizes a form by maximizing it and
//           disabling the backbutton
//           if ElemendId != "" then set focus to element
function pageInitialSetupEx(ElemendId) {
    disableBrowserHistory();
    maximizeBrowserWindow();
    SetFocusToControl(ElemendId);
    GetScreenSize();
}

// FUNCTION: PageInitialSetupWPostback()
//           Initalizes a form by maximizing it and
//           disabling the backbutton
function pageInitialSetupWPostback() {
    disableBrowserHistory();
    maximizeBrowserWindow();
    forcepostback();
}

// FUNCTION: forcepostback()
//           Method is used to force a postback on the form's OnLoad event.
//           This is used to assit in the disabling of the Browser Back button.
function forcepostback() {
    if (!document.getElementById('hidForcePostBack')) {
        return;
    }
    else {
        var x = document.getElementById('hidForcePostBack');
        if (x.value == 'Y') {
            //window.location.reload(); 'doesn't work causes page to reload but not actually postback
            __doPostBack(x.id, '');
        }
    }
}


// FUNCTION: maximizeBrowserWindow()
//           Maximize the Browser Window to available Width and Height.
function maximizeBrowserWindow() {
    if (isPostBack() != true) {
        try {
            window.moveTo(0, 0);
            window.resizeTo(screen.availWidth, screen.availHeight);
        }
        catch (e) {
            //skip - bypasses an occasional error when someting else may have the focus at the moment.
        }
    }
}

// FUNCTION: disableBrowserHistory()
//           Disable the use of the browser History back button by advancing the history
function disableBrowserHistory() {
    window.history.go(1)
}


// FUNCTION: SetFocusToControl(ElemendId)
//           Checkif there is a control with the passed ID,
//           If So, set the focus to that control.
//           same as using the <form>'s defaultfocus="" property
function SetFocusToControl(ElemendId) {
    // Check if control exists
    if (!document.getElementById(ElemendId))
        return false;
    else
        document.getElementById(ElemendId).focus();
    return true;
}

// FUNCTION: isPostBack()
//           Check if page is loading fir the first time or doing a Postback
//           (Requires a HiddenField with id="clientSideIsPostBack" or will always return false).
function isPostBack() {
    // Check if control exists
    if (!document.getElementById('clientSideIsPostBack'))
        return false;
    if (document.getElementById('clientSideIsPostBack').value == 'Y')
        return true;
    else
        document.getElementById('clientSideIsPostBack').value = 'Y';
    return false;
}

// FUNCTION: GetScreenSize()
//           Determines the current screen Width/Height in Px and loads it into a Hidden Control.
//           Loads the control with a String w=####;h=#### (ie: w=800;h=600)
//           (Requires a HiddenField with id="ScreenSize" or will always return Null).
function GetScreenSize() {
    // Check if control exists
    if (!document.getElementById('ScreenSize'))
        return;
    else
        document.getElementById("ScreenSize").value = "w=" + screen.width + ";h=" + screen.height;
    return false;
}

// Determines the current screen Width, Height, etc in Px and loads it into a Hidden Control.
function GetScreenInformation(hidCtlID) {
    if (!document.getElementById(hidCtlID)) {
        //skip;
    }
    else {
        var s;
        s = 'w=' + screen.width + ';h=' + screen.height + ';aw=' + screen.availWidth + ';ah=' + screen.availHeight + ';cd=' + screen.colorDepth;
        document.getElementById(hidCtlID).value = s;
    }
}
//]]>
