﻿//-------------------------------------------------------------
// Include this Javascript file to allow a window to be closed by pressing the "ESC" key.
//
// NOTE: This page will handle the Document's and Window's "OnKeyDown" events.
//
// EX:
// <script language="javascript" type="text/javascript" src="Javascript/CloseOnESC.js"></script>
//-------------------------------------------------------------

//This captures the ESC key and closes the window.
//NOTE: N4 doesn't appear to capture ESC key.
if (navigator.appName.indexOf("Netscape") != -1){
        window.captureEvents(Event.KEYPRESS);
}

function blockESC(e) {
    var keyChar, keyCode;
	if(navigator.appName.indexOf("Microsoft")!=-1) {
		//IE
		keyCode = window.event.keyCode;
	} else {
		//Netscape
		keyCode = e.which;
	}

	keyChar = String.fromCharCode(keyCode);
	if (isNaN(keyChar) ) {
		//Capture ESC key
		if (keyCode == 27 ) {
            window.close();
            if (window.opener) {if(!window.opener.closed) {window.opener.focus();}}
		}
	}
	return true;
}

document.onkeydown=blockESC;
window.onkeydown=blockESC;

