var isAlt = false
//	Capture key presses on the document in Netscape
if (document.layers){
	document.captureEvents(Event.KEYPRESS)
}

/*Is called in the body of all pages*/
function onload(){
//	Give focus to the first visible element in a form
	FormFocus()

//	Catch key presses on the document and test for shortcut keys.
	document.onkeydown=keyDown
	document.onkeyup=keyUp
}





/*
Puts a pop up window in the center of the screen...  Also sets the opening window with the name "opener".
"opener" allows you to refer to the opening page - from the popup window using the following:

	opener.document.location.href='default.asp';
	opener.document.hiddenform.submit();

It then forces focus to the popup window
*/
function newWindow(mypage, myname, w, h) {
	window.name="target"; 
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars,resizable'
	
	win = window.open(mypage, myname, winprops)
	win.focus()
	
	if (!win.opener)
		win.opener = self; 
	
	if (parseInt(navigator.appVersion) >= 4) {
		win.window.focus();
	}
}

function FormFocus(){
//Focus first form element & make all forms method post
	//If there's a form
	if (document.forms.length >0){
		//For Each form
		for (var frm=0; frm < document.forms.length; frm++) {
			//Force the form method to be "post" not "get"
			document.forms[frm].method = "post"
		}
		//For Each form
		for (var frm=0; frm < document.forms.length; frm++) {
			//For Each Element
			for (var elmnt=0; elmnt < document.forms[frm].elements.length; elmnt++) {
				//If it's not hidden, disabled or CSS hidden
				if (document.forms[frm].elements[elmnt].type != "hidden" && document.forms[frm].elements[elmnt].style.visibility != "hidden" && document.forms[frm].elements[elmnt].disabled != true){
					//Give it focus
					document.forms[frm].elements[elmnt].focus();
					//Leave for loops
					elmnt = (document.forms[frm].elements.length - 1);
					frm = (document.forms.length -1);
				}
			}
		}
	}
}

function isDown(asckey){
//	Used to check system hot keys
//	alert(asckey)

//	If alt is held set isAlt true
	if (isAlt!=true){
		if (asckey==18){
			isAlt=true
		}
	}
//	If Alt is being held check for hot keys and perform function
	else{
//	alert(asckey);
		if (asckey==65){// 65 = a - open admin area
			location.href="../administration/";
		}
		else if (asckey==79){// 79 = o - logOut
			location.href="../administration/logout.asp";
		}
//	Reset isAlt
		isAlt=false;
	}
}

function keyDown(txt){
	if (document.layers){
		isDown(txt.keyCode)
	}
	else if (document.all){
		isDown(event.keyCode)
	}
}

function isUp(asckey){
//	If Alt is released then reset isAlt
	if (isAlt==true){
		if (asckey==18){
			isAlt=false
		}
	}
}

function keyUp(txt){
	if (document.layers){
		isUp(txt.keyCode)
	}
	else if (document.all){
		isUp(event.keyCode)
	}

}

