
/**
this code is to disable printing in IE6,7 and mozilla fireFox 3.0.12
IE does not recognize the keypress event, for special keys like
Ctrl, Alt, Tab and Enter etc. So we have to use the key down
event even for catching the special keys.


*/





document.onkeydown = disablePrintKeyDown; // for IE7 and above
document.onkeypress = disablePrintKeyPress; //for Mozilla


function disablePrintKeyDown(e){

	//get the browser version first
	var ua = navigator.userAgent;
    var MSIEOffset = ua.indexOf("MSIE ");
	var version ;
    if (MSIEOffset == -1) {
        return 0;
    } else {
        version = parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset)));
    }


	//get the event and the keyCode of the key pressed
	e = window.event;
	var keyCode = e.keyCode;


	//disable the Ctrl key altogether, if the version is less than 7.
	if(version < 7){
		if(keyCode == 17){
			alert("CTRL key disabled for this version . Use IE 7 or higher");
		}
	//else we do the catching of the sequence Ctrl+P
	}else{

		if(window.event.ctrlKey){
			if(keyCode == 80 || keyCode == 112 || keyCode == 78 || keyCode == 110){
				window.event.keyCode = false;
				//alert("printing disabled");
				return false
			}
		}else{
			if(keyCode == 17){
				this.prevKey = 17;
			}
			else if(keyCode == 9){
				if(e.preventDefault){
						e.preventDefault();
				}else{
					e.returnValue = false;
				}
				if(this.prevKey == 17){
					this.lastToPrevKey = this.prevKey;
					this.prevKey = keyCode;

				}
			}
			else if(keyCode == 80 || keyCode == 112 || keyCode == 78 || keyCode == 110){
				if((this.prevKey == 17)  || (this.lastToPrevKey == 17 && this.prevKey == 9)){
					window.event.keyCode = false;
					this.lastToPrevKey = false;
					this.prevKey = false;
					//alert("printing disabled");
					return false;
				}
			}
		}
	}
}

function disablePrintKeyPress(e){
	if(e){
		var keyCode = e.which;

		if(e.ctrlKey){
			if(keyCode == 80 || keyCode == 112 || keyCode == 83 || keyCode == 115 || keyCode == 97 || keyCode == 65 || keyCode == 78 || keyCode == 110){
				//alert(keyCode);
				return false;
			}
		}
		else if(keyCode == 0){
			if(e.preventDefault){
				e.preventDefault();
			}else{
				e.returnValue = false;
			}
		}
	}
}





