﻿//Alerts user if Caps Lock is on

// see http://www.codeproject.com/KB/scripting/Detect_Caps_Lock.aspx

function CapsLock(){
    
    this.Height = 60;   // would be better if this could be worked out dynamically
                        // ie the height of the bubble
    
    this.capLock =function(e, msg, elem){
        kc = e.keyCode?e.keyCode:e.which;
        sk = e.shiftKey?e.shiftKey:((kc == 16)?true:false);
        if(((kc >= 65 && kc <= 90) && !sk)||((kc >= 97 && kc <= 122) && sk)){
            var obj = document.getElementById(elem);
            Tip(msg, BALLOON, true, ABOVE, true, WIDTH, 220, FOLLOWMOUSE, false, FIX, [this.CalcFixX(obj), this.CalcFixY(obj)  - this.Height]);
        }
    }

    this.CalcFixX = function(obj){
        var curleft = 0;
        if (obj.offsetParent)
        {
            while (obj.offsetParent)
            {
                curleft += obj.offsetLeft;
                obj = obj.offsetParent;
            }
        }
        else if (obj.x)
            curleft += obj.x;
        return curleft;
    }

    this.CalcFixY = function (obj){
        var curtop = 0;
        if (obj.offsetParent)
        {
            while (obj.offsetParent)
            {
                curtop += obj.offsetTop;
                obj = obj.offsetParent;
            }
        }
        else if (obj.y)
            curtop += obj.y;
        return curtop;
    }
    
}
var capsLock = new CapsLock();