var navdef_start, navdef_end, styleswitch, WWidth, WHeight, NS4, IE, NS6;
var bIE4,bIE6,bNS4,bNS6,bOPERA;
var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var keyHandlerEnabler = false;
var executeEnabler = false;
var handleKeyDown;
	
function hisback() 
{
       history.back();
}

function subm(foo)
{
	var foo;
	what = foo + "_form";
	document.forms[what].submit.value    = 'Please Wait...';
	document.forms[what].submit.disabled = true;
	executeEnabler = false;
	toggleGeneralDimLayer(true);
}

function submit_wait()
{
	document.body.style.cursor = 'wait';
}

function submit_radio(foo)
{
	var foo;
	submit_wait;
	document.forms[foo].submit();
	submitForm = blockIt;
	executeEnabler = false;
	toggleGeneralDimLayer(true);

	return false;
}

function blockIt( ) {
	return false;
}

function showpic(pic_name,pic_count) {
	center(pic_name,780,580,pic_count,"/view.php");
}

function center(id,picwidth,picheight,piccount,filename) {
	if (bNS4) {
		y = (WHeight - picheight + 30) / 2 ;
		x = (WWidth - picwidth - 36) / 2 ;
		window.open(filename+"?id="+id+"&count="+piccount, "Enlarge", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,copyhistory=0,width=" + picwidth + ",height=" + picheight + ",screenX="+x+",screenY="+y);
	} else {
		y = (WHeight - picheight + 180) / 2 ;
		x = (WWidth - picwidth - 8) / 2 ;
		window.open(filename+"?id="+id+"&count="+piccount, "Enlarge", "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,copyhistory=0,width=" + picwidth + ",height=" + picheight + ",top="+y+",left="+x);
	}
}

function enableKeyHandler(){
	keyHandlerEnabler = true;
}

function disableKeyHandler(){
	keyHandlerEnabler = false;
}

function handleKeyDown() {
	if(keyHandlerEnabler){
		var intKey = event.keyCode;
			if (intKey == 13){
				return false;
			}
	}
}

function toggleGeneralDimLayer(bSwitch,dimX,dimY,dimWidth,dimHeight) {
	if (!document.getElementById("generalDimLayer")) createDimLayer("general");
	var aDropdowns = document.getElementsByTagName("body")[0].getElementsByTagName("SELECT");
	var refDimLayer = document.getElementById("generalDimLayer");
	if (bSwitch) {
		with (refDimLayer.style) {
			visibility = "visible";
			display = "block";
			left = (dimX)?dimX:"0px";
			top = (dimY)?dimY:"0px";
			width = (dimWidth)?dimWidth:"100%";
			height = (dimHeight)?dimHeight:"100%";
		}
		for (i=0;i<aDropdowns.length;i++) {
			aDropdowns[i].style.visibility = "hidden";
		}
		refDimLayer.focus();
	} else {
		with (refDimLayer.style) {
			display = "none";
			visibility = "hidden";
		}
		for (i=0;i<aDropdowns.length;i++) {
			aDropdowns[i].style.visibility = "visible";
		}
	}
}

function createDimLayer(panelName) {
	document.body.insertAdjacentHTML('beforeEnd','<DIV ID="'+panelName+'DimLayer" CLASS="dimLayer"></DIV>');
}

function swapPic(pic, type) {

	if (document.images) {
		if (type == "on") {
			document.images[pic].src = menuOn[pic].src;
			return true;
		} else if (type == "off") {
			document.images[pic].src = menuOff[pic].src;
			return true;
		}
	}
	return false;
}

function init()	{

	var browser_type = navigator.appName;
    var browser_version = parseInt(navigator.appVersion);
        
    bIE4 = (browser_type=="Microsoft Internet Explorer" && browser_version==4) ? true : false;
	bIE6 = (browser_type=="Microsoft Internet Explorer" && browser_version>=5) ? true : false;
	bNS4 = (browser_type=="Netscape" && browser_version==4) ? true : false;
    bNS6 = (browser_type=="Netscape" && browser_version>=5) ? true : false;
    bOPERA  = (browser_type=="Opera") ? true : false;

	if (bIE4 || bIE6) {
		WWidth=document.body.clientWidth;
		WHeight=document.body.clientHeight;
	} else {
		WWidth=window.innerWidth;
		WHeight=window.innerHeight;
	}

    NS4 = false; IE4 = false; NS6 = false;
    
	executeEnabler = true;
	toggleGeneralDimLayer(false);
}

document.onkeydown = handleKeyDown; 