/*
Created by Razi Haleem in Q3/2009

To use this CapsLock validation on your page, follow these steps:

1. Include CapsLock.js on your page
2. Add LoadCapLockPopup() method to the onload event of your page
eg. <body onload="LoadCapLockPopup()">
3. Find your password textbox and add this event to it:  onkeypress="CheckCapLock(event,this)"
eg <input type="password" id="MyPassword" onkeypress="CheckCapLock(event,this)">

Tips: You can change the styles and text of the Caps Lock Popup by using the Set Methods found below

*/

/*
*
* Change the constants below using the Set() methods, do NOT change manually
*
*/

var CapsLockStyle = "background-color:#fdf5c8;border:solid 1px #FFBB00;padding:5 5 5 5";
var CapsLockTextStyle = "font-size:10px";
var CapsLockTitleStyle = "font-weight:bold;font-size:10px";

var CapsLockTitle = "Caps Lock is On";
var CapsLockText = "Having Caps Lock on may cause you to enter your password incorrectly.<br /><br />You should press Caps Lock to turn it off before continuing.";

//the relative position of the div to the password textbox
var DivRelativeTopPosition = 30;
var DivRelativeLeftPosition = 5;

/*
*
*Set Methods for variables
*
*/

function SetCapsLockStyle(style)
{
    CapsLockStyle = style;
}

function SetCapsLockTextStyle(style)
{
    CapsLockTextStyle = style;
}

function SetCapsLockTitleStyle(style)
{
    CapsLockTitleStyle = style;
}

function SetCapsLockTitle(title)
{
    CapsLockTitle = title;
}

function SetCapsLockText(text)
{
    CapsLockText = text;
}

function SetDivRelativeTopPosition(pos)
{
    DivRelativeTopPosition = pos;
}

function DivRelativeLeftPosition(pos)
{
    DivRelativeLeftPosition = pos;
}

/*
*
*Call this method on the onload event of the page
*
*/
function LoadCapLockPopup(jquerySelector,parentElement,divID) {

    $$(jquerySelector).keypress(function(event) {

        keyCode = event.keyCode ? event.keyCode : event.which;
        shiftKey = event.shiftKey ? event.shiftKey : ((keyCode == 16) ? true : false);

        if (((keyCode >= 65 && keyCode <= 90) && !shiftKey) || ((keyCode >= 97 && keyCode <= 122) && shiftKey)) {
            $$('#capsLockMsg').show('fast');
        
        }
        else {
            $$('#capsLockMsg').hide('fast');
        }

    });
}



/*
*
*Validation method
*
*/
function CheckCapLock(e, obj)
{
    if ($$('#CapsLockPopup')) 
    {
        keyCode = e.keyCode ? e.keyCode : e.which;
        shiftKey = e.shiftKey ? e.shiftKey : ((keyCode == 16) ? true : false);

        if (((keyCode >= 65 && keyCode <= 90) && !shiftKey) || ((keyCode >= 97 && keyCode <= 122) && shiftKey)) {

            $$('#CapsLockPopup').show();
        }
        else {
            $$('#CapsLockPopup').hide();
        }
    }
}


