/*
	Some javascript to block right click and selected shortcut keys
*/
var msg = 'That functionality has been disabled';
var asciiBack       = 8;
var asciiTab        = 9;
var asciiSHIFT      = 16;
var asciiCTRL       = 17;
var asciiALT        = 18;
var asciiHome       = 36;
var asciiLeftArrow  = 37;
var asciiRightArrow = 39;
var asciiMS         = 92;
var asciiView       = 93;
var asciiF1         = 112;
var asciiF2         = 113;
var asciiF3         = 114;
var asciiF4         = 115;
var asciiF5         = 116;
var asciiF6         = 117;
var asciiF11        = 122;
var asciiF12        = 123;
var asciiF11        = 122;

function clickIE4()
{
	if (event.button==2)
	{
		//alert(msg);
		return false;
	}
}

function clickNS4(e)
{
	if (document.layers||document.getElementById&&!document.all)
	{
		if (e.which==2||e.which==3)
		{
			//alert(msg);
			return false;
		}
	}
}

if (document.layers)
{
	document.captureEvents(Event.MOUSEDOWN);
	document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById)
{
	document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("/*alert(msg);*/return false");

if(document.all){ //ie has to block in the key down
    document.onkeydown = onKeyPress;
}else if (document.layers || document.getElementById){ //NS and mozilla have to block in the key press
    document.onkeypress = onKeyPress;
}

function onKeyPress(evt) {
    window.status = '';
    var oEvent = (window.event) ? window.event : evt;

    var nKeyCode =  oEvent.keyCode ? oEvent.keyCode : oEvent.which ? oEvent.which : void 0;

    var bIsFunctionKey = false;

    if(oEvent.charCode == null || oEvent.charCode == 0)
	{
        bIsFunctionKey = (nKeyCode >= asciiF2 && nKeyCode <= asciiF12) || (nKeyCode == asciiALT || nKeyCode == asciiMS || nKeyCode == asciiView || nKeyCode == asciiHome || nKeyCode == asciiBack)
    }

    //convert the key to a character, makes for more readable code
    var sChar = String.fromCharCode(nKeyCode).toUpperCase();

    //get the active tag that has the focus on the page, and its tag type
    var oTarget = (oEvent.target) ? oEvent.target : oEvent.srcElement;
    var sTag = oTarget.tagName.toLowerCase();
    var sTagType = oTarget.getAttribute("type");

    var bAltPressed = (oEvent.altKey) ? oEvent.altKey : oEvent.modifiers & 1 > 0;
    var bShiftPressed = (oEvent.shiftKey) ? oEvent.shiftKey : oEvent.modifiers & 4 > 0;
    var bCtrlPressed = (oEvent.ctrlKey) ? oEvent.ctrlKey : oEvent.modifiers & 2 > 0;
    //var bMetaPressed = (oEvent.metaKey) ? oEvent.metaKey : oEvent.modifiers & 8 > 0;

    var bRet = true; //assume true as that will be the case most times

    if(sTagType != null)
	{
		sTagType = sTagType.toLowerCase();
	}

    //allow these keys inside a text box
    if  (sTag == "textarea" || (sTag == "input" && (sTagType == "text" || sTagType == "password")) && (nKeyCode == asciiBack || nKeyCode == asciiSHIFT || nKeyCode == asciiHome || bShiftPressed || (bCtrlPressed && (nKeyCode == asciiLeftArrow || nKeyCode == asciiRightArrow))))
	{
        return true;
    }
	else if(bAltPressed && (nKeyCode == asciiTab || nKeyCode == asciiF4))
	{ // block alt + tab or alt + f4 (seems to not work)
        bRet = false;
    }
	else if(bCtrlPressed && (sChar == 'A' || sChar == 'C' || sChar == 'V' || sChar == 'X'))
	{ // block cut, copy and paste, and SELECT ALL
        bRet = false;
    }
	else if(bShiftPressed && nKeyCode == asciiTab)
	{//allow shift + tab
        bRet = true;
    }
	else if(bIsFunctionKey)
	{ // Capture and stop these keys
        bRet = false;
    }
	else if(bCtrlPressed || bShiftPressed || bAltPressed)
	{ //block ALL other sequences, includes CTRL+O, CTRL+P, CTRL+N, etc....
        bRet = false;
    }

    if(!bRet)
	{
        try
		{
            oEvent.returnValue = false;
            oEvent.cancelBubble = true;
            if(document.all)
			{ //IE
                oEvent.keyCode = 0;
            }else
			{ //NS
                oEvent.preventDefault();
                oEvent.stopPropagation();
            }
            window.status = msg;
            //alert(''+msg);
        }
		catch(ex)
		{
            //alert(ex);
        }
    }
    return bRet;
}
