var aPopDiv = new Array();
aPopDiv['testshowvars'] = new Array();
aPopDiv['testshowvars']['H'] = 570;
aPopDiv['testshowvars']['W'] = 650;
aPopDiv['labelling'] = new Array();
aPopDiv['labelling']['H'] = 570;
aPopDiv['labelling']['W'] = 740;
var popID = '';

// ======================================================
function menuOpen(a) {
	var obj = document.getElementById(a); 
	if (obj) {
		obj.style.visibility = "visible";
	}
}

// ======================================================
function menuClose(a) {
	var obj = document.getElementById(a); 
	if (obj) {
		obj.style.visibility = "hidden";
	}
}

// ======================================================
function popShow(ID) {
	popInit(ID);
	document.getElementById('popDiv').innerHTML = document.getElementById('popcontent_'+ID).innerHTML;
	document.getElementById('popDiv').style.display = 'block';
	popID = ID; // hold ID to adjust popDiv position at resize
}

// ======================================================
function popInit(ID) {
	popInitWH(ID);
	popInitPos(ID);
}

// ======================================================
function popInitWH(ID) {
	document.getElementById('popDiv').style.width  = aPopDiv[ID]['W'] + "px";
	document.getElementById('popDiv').style.height = aPopDiv[ID]['H'] + "px";
}

// ======================================================
function popInitPos(ID) {
	if (ID != '') {
		var daH = document.body.clientHeight;
		var daW = document.body.clientWidth;
		document.getElementById('popDiv').style.top  = Math.round((daH-aPopDiv[ID]['H'])/2) + "px";
		document.getElementById('popDiv').style.left = Math.round((daW-aPopDiv[ID]['W'])/2) + "px";
		
		if (document.getElementById('popCloseBut')) {
			document.getElementById('popCloseBut').style.top   = (Math.round((daH-aPopDiv[ID]['H'])/2) + 4) + "px";
			document.getElementById('popCloseBut').style.right = (Math.round((daW-aPopDiv[ID]['W'])/2) + 40) + "px";
		}
	}
}

// ======================================================
function popClose() {
	document.getElementById('popDiv').style.display = 'none';
}

// ======================================================
function addMyEvent(hoo,wot,fun) {
	if (document.addEventListener) hoo.addEventListener(wot,fun,null);
	else if (document.attachEvent) hoo.attachEvent('on'+wot,fun);
	else hoo['on'+wot] = fun;        
}

// ======================================================
function catchEscape(e) {
	e = window.event ? window.event : e;
	if (e.keyCode == 27) { 
		popClose();
	}
	return true; 
}

// ======================================================
function startKeyCatching() {
	addMyEvent(document,'keypress',catchEscape);
}


var aTMPLnr  = new Array();
var aTMPLpth = new Array();
// ======================================================
function addPTH(pPTH) {
	var L    = pPTH.indexOf(" ");
	var tPTH = pPTH.substr(L+1);
	var TMPL = pPTH.substr(0,L);
	var TFfoundTMPL = false;

	for (var t in aTMPLnr) {
		if (TMPL == t) {
			aTMPLnr[t]++;
			TFfoundTMPL = true;
			break;
		}
	}

	if (!TFfoundTMPL) {
		aTMPLnr[TMPL]  = 1;
		aTMPLpth[TMPL] = tPTH;
	}
}

// ======================================================
function insertTMPLinfo() {
	if (document.getElementById('test-show-path')) {
		var RT = "";
		var pth;
		var sc = document.getElementsByTagName('script');

		for (var i=0;i < sc.length; i++) {
			if (sc[i].type == "") {
				pth = sc[i].innerHTML;
				pth = pth.replace("/*","");
				pth = pth.replace("*/","");
				addPTH(pth);
			}
		}

		for (var t in aTMPLnr) {
			if (aTMPLnr[t] == 1) {
				RT += "<b>"+t+"</b> ["+aTMPLpth[t]+"]<br>";
			} else {
				RT += "<b>"+t+"</b> ["+aTMPLnr[t]+"]<br>";
			}
		}
		document.getElementById('test-show-path').innerHTML = RT + "<br>\n";
	}
}


