﻿


// Function that validates the input and checks if its an unsigned INT
function isUInt(e) {
    if (e.charCode == null) {
        //Internet Explorer has no charCode in event - perform this test
        return e.keyCode >= 48 && e.keyCode <= 57 ? true : false;
    }
    else {
        //Other Browsers have charCode in event - perform this test
        return e.charCode ? (e.charCode >= 48 && e.charCode <= 57 ? true : false) :
                (e.keyCode == 8 || e.keyCode == 9 || e.keyCode == 37 || e.keyCode == 39 || e.keyCode == 46 ? true : false);
    }
}




// Set Input Control to empty when selected and to
// controlValue when focus
function setTextFocus(control, controlValue) {
    control.value = control.value == controlValue ? "" : control.value;
}




// Set Input Control to empty when selected and to
// controlValue when focus
function setTextBlur(control, controlValue) {
    control.value = control.value == "" ? controlValue : control.value;
}




// Set Input Control to empty when selected and to
// controlValue when focus
function setTextFocusInt(control, controlValue) {
    control.value = control.value == controlValue ? "" : control.value * 1;
}




// Set Input Control to empty when selected and to
// controlValue when focus
function setTextBlurInt(control, controlValue) {
    control.value = control.value == "" ? controlValue : control.value * 1;
}




// Center a div in the middle of the screen
function showdeadcenterdiv(Xwidth, Yheight, divid) {
    var obj = document.getElementById(divid);
    var objStyle = obj.style;
    var scrolledX, scrolledY, centerX, centerY;

    // First, determine how much the visitor has scrolled 
    if (self.pageYOffset) {
        scrolledX = self.pageXOffset;
        scrolledY = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {
        scrolledX = document.documentElement.scrollLeft;
        scrolledY = document.documentElement.scrollTop;
    } else if (document.body) {
        scrolledX = document.body.scrollLeft;
        scrolledY = document.body.scrollTop;
    }

    // Next, determine the coordinates of the center of browser's window 
    if (self.innerHeight) {
        centerX = self.innerWidth;
        centerY = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        centerX = document.documentElement.clientWidth;
        centerY = document.documentElement.clientHeight;
    } else if (document.body) {
        centerX = document.body.clientWidth;
        centerY = document.body.clientHeight;
    }

    // The initial width and height of the div can be set in the 
    // style sheet with display:none; divid is passed as an argument to // the function 
    objStyle.position = 'absolute';
    objStyle.top = (scrolledY + (centerY - Yheight) / 2) + 'px';
    objStyle.left = (scrolledX + (centerX - Xwidth) / 2) + 'px';
}

function SetXYOriginAuto(ObjName)                                   //was the old SetFramePos(ObjName)
/*-------------------------------------------------------------------------*/
/* Set the XY co-ordinates for the object so it will appear in middle of   */
/* the screen.                                                             */
/*-------------------------------------------------------------------------*/
{
    if (document.getElementById(ObjName) != null) {
        var viewablewidth;
        var viewableheight;

        //The more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
        if (typeof window.innerWidth != 'undefined') {
            viewablewidth = window.innerWidth,
            viewableheight = window.innerHeight
        }
        //IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
        else if (typeof document.documentElement != 'undefined'
             && typeof document.documentElement.clientWidth !=
             'undefined' && document.documentElement.clientWidth != 0) {
            viewablewidth = document.documentElement.clientWidth,
            viewableheight = document.documentElement.clientHeight
        }
        //Older versions of IE
        else {
            viewablewidth = document.getElementsByTagName('body')[0].clientWidth,
            viewableheight = document.getElementsByTagName('body')[0].clientHeight
        }

        var IObj = document.getElementById(ObjName);

        var leftOverWidth = viewablewidth - (IObj.offsetWidth);
        var leftOverHeight = viewableheight - (IObj.offsetHeight);
        IObj.style.left = (leftOverWidth / 2) + "px";
        IObj.style.top = (leftOverHeight / 2) + "px";
    }
}


// Fade div in or out
var TimeToFade = 180.0;
function fade(eid, defaultFadeState) {
    var element = document.getElementById(eid);
    element.style.display = "block";
    if (element == null) {
        return;
    }

    if (defaultFadeState != 0) {
        element.FadeState = defaultFadeState;
    }
    else {
        if (element.FadeState == null) {
            element.FadeState = -2;
        }
    }

    if (element.FadeState == 1 || element.FadeState == -1) {
        element.FadeState = element.FadeState == 1 ? -1 : 1;
        element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
    }
    else {
        element.FadeState = element.FadeState == 2 ? -1 : 1;
        element.FadeTimeLeft = TimeToFade;
        setTimeout("animateFade(" + new Date().getTime() + ",'" + eid + "')", 33);
    }
}


// Fade animation
function animateFade(lastTick, eid) {
    var curTick = new Date().getTime();
    var elapsedTicks = curTick - lastTick;

    var element = document.getElementById(eid);

    if (element.FadeTimeLeft <= elapsedTicks) {
        element.style.opacity = element.FadeState == 1 ? '1' : '0';
        element.style.filter = 'alpha(opacity = '
        + (element.FadeState == 1 ? '100' : '0') + ')';
        element.FadeState = element.FadeState == 1 ? 2 : -2;
        element.style.display = (element.FadeState > 0 ? "block" : "none");
        return;
    }
    element.FadeTimeLeft -= elapsedTicks;
    var newOpVal = element.FadeTimeLeft / TimeToFade;
    if (element.FadeState == 1)
        newOpVal = 1 - newOpVal;

    element.style.opacity = newOpVal;
    element.style.filter = 'alpha(opacity = ' + (newOpVal * 100) + ')';
    setTimeout("animateFade(" + curTick + ",'" + eid + "')", 33);
}


// Caps lock validation
function checkCapsLock(e) {
    var myKeyCode = 0;
    var myShiftKey = false;
    var myMsg = 'Caps Lock is On.\n\nTo prevent entering your password incorrectly,\nyou should press Caps Lock to turn it off.';

    // Internet Explorer 4+
    if (document.all) {
        myKeyCode = e.keyCode;
        myShiftKey = e.shiftKey;

        // Netscape 4
    } else if (document.layers) {
        myKeyCode = e.which;
        myShiftKey = (myKeyCode == 16) ? true : false;

        // Netscape 6
    } else if (document.getElementById) {
        myKeyCode = e.which;
        myShiftKey = (myKeyCode == 16) ? true : false;

    }

    // Upper case letters are seen without depressing the Shift key, therefore Caps Lock is on
    if ((myKeyCode >= 65 && myKeyCode <= 90) && !myShiftKey) {
        alert(myMsg);

        // Lower case letters are seen while depressing the Shift key, therefore Caps Lock is on
    } else if ((myKeyCode >= 97 && myKeyCode <= 122) && myShiftKey) {
        alert(myMsg);

    }
}







