var aPopDiv = new Array();
var popID = '';



var footerH = 84;
var headerH = 302;

var argL = 0; // default
var tipID = -1; // -1:none


// ======================================================
function doTip(ID) {
	if (ID == tipID) { // drukte dezelfde
		document.getElementById('tip'+tipID).style.display = 'none';
		document.images['tipIMG'+tipID].src = 'http://www.objectiefondernemersadvies.nl/graphics/plus.gif';
		tipID = -1;
	} else { // drukte een andere
		if (tipID != -1) { // klap huidige in
			document.getElementById('tip'+tipID).style.display = 'none';
			document.images['tipIMG'+tipID].src = 'http://www.objectiefondernemersadvies.nl/graphics/plus.gif';
		}
		document.getElementById('tip'+ID).style.display = 'block'; // klap deze uit
		document.images['tipIMG'+ID].src = 'http://www.objectiefondernemersadvies.nl/graphics/min.gif';
		tipID = ID;
		doresize();
	}
}

// ======================================================
function doresize() {
	setH('content','right');
	// give the id's of all concerning columns inside 'container'
	// Each column stretches its height due to its content :
	// the footer top position is computed after the page is loaded : under the heighest column
}

// ======================================================
function setH() {
	argL = setH.arguments.length;

	var i;
	var allColH = colH(setH.arguments);
	var windowH = document.body.clientHeight - headerH;
	var fillH = windowH - footerH;
	var TFfill = (footerH + allColH < windowH);
	var daH = TFfill ? fillH : allColH;

	for (i=0;i < argL;i++) {
		document.getElementById(setH.arguments[i]).style.height = daH + "px";
		document.getElementById(setH.arguments[i]).style.marginBottom = (TFfill ? 0 : footerH) + "px";
	}

	document.getElementById('footer').style.top = (daH + headerH) + "px";
	document.getElementById('footer').style.visibility = "visible";
}

// ======================================================
function colH(aColID) { // Array containing all IDs of the concerning COLumns
	var i;
	var oH = 0;
	var cOH = new Array();

	for (i=0;i < argL;i++) {
		document.getElementById(aColID[i]).style.height = 'auto';
		cOH[i] = document.getElementById(aColID[i]).offsetHeight;
	}

	for (i=0;i < argL;i++) {
		if (cOH[i] > oH)
			oH = cOH[i];
	}

	return oH;
}

// ======================================================
function TFso(FEnr) {
	var FE = document.forms['form_so'];
	var FEL;
	var FEix = 0;
	var TFfrm = true;
	while (TFfrm && (FEix < FEnr)) {
		FEL = FE.elements['RDso'+FEix];
		TFfrm = TFfrm && (FEL[0].checked || FEL[1].checked || FEL[2].checked);
		FEix++;
	}
	if (!TFfrm)
		alert("beantwoord eerst alle vragen ..!");
	return TFfrm;
}

// ======================================================
function miMV(ID) {
	document.getElementById("L"+ID).style.backgroundPosition = "0px -71px";
}

// ======================================================
function miMT(ID) {
	document.getElementById("L"+ID).style.backgroundPosition = "0px 0px";
}

// ======================================================
function subMV(ID) {
	miMV(ID);
	document.getElementById("U"+ID).style.display = 'block';
}

// ======================================================
function subMT(ID) {
	miMT(ID);
	document.getElementById("U"+ID).style.display = 'none';
}

// ======================================================
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);
}

