/* Algemeen
------------------------------------------------------------------*/
function focusOn(inputId) {
	if (eleId(inputId)) {
		eleId(inputId).focus();
	}
}
function eleId(id) {
	if (document.getElementById(id)) {
		return document.getElementById(id);
	}
	return false;
}
function isDefined(checkVar) {
	return (typeof(checkVar) != "undefined");
}
function getOffset(ele) {
	xPos = parseInt(ele.offsetLeft);
	yPos = parseInt(ele.offsetTop);
	
	var parent = ele;
	while (parent.offsetParent)	{
		parent = parent.offsetParent;
		xPos += parseInt(parent.offsetLeft);
		yPos += parseInt(parent.offsetTop);
	}

	return {x: xPos, y: yPos};
}
function scrollToEle(id) {
	if (eleId(id)) {
		off = getOffset(eleId(id));
		if (off.y >= 20) {
			off.y -= 20;
		}
		window.scrollTo(off.x, off.y);
	}
}
function redirectTo(url, openInNewWindow) {
	if (openInNewWindow == true) {
		window.open(url);
	} else {
		document.location.href = url;
	}
}
function stopBubble(e) {
	if (!e) var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
}
function filterOpacity(ele, percentage) {
	if (BrowserDetect.browser == "Explorer") {
		ele.style.filter = 'alpha(opacity=' + percentage + ')';
	} else {
		ele.style.opacity = (percentage / 100);
	}
}


/* Pagina frame informatie
------------------------------------------------------------------*/
function getFrameSize(dW, dH) {
	// Credits: http://www.quirksmode.org/
	doc = document;
	
	// Scrollbar
	var x,y;
	if (self.pageYOffset) {
		// all except Explorer
		x = self.pageXOffset;
		y = self.pageYOffset;
	} else if (doc.documentElement && doc.documentElement.scrollTop) {
		// Explorer 6 Strict
		x = doc.documentElement.scrollLeft;
		y = doc.documentElement.scrollTop;
	} else if (doc.body) {
		// all other Explorers
		x = doc.body.scrollLeft;
		y = doc.body.scrollTop;
	}
	
	// Page frame size
	if (self.innerWidth) {
		// all except Explorer
		fWidth = self.innerWidth;
		fHeight = self.innerHeight;
	} else if (doc.documentElement && doc.documentElement.clientWidth) {
		// Explorer 6 Strict
		fWidth = doc.documentElement.clientWidth;
		fHeight = doc.documentElement.clientHeight;
	} else if (document.body) {
		// all other Explorers
		fWidth = doc.body.clientWidth;
		fHeight = doc.body.clientHeight;
	}
	
	if (fWidth && fHeight) {
		return {fW: fWidth, sW: fWidth + x, fH: fHeight, sH: fHeight + y, sL: x, sT: y};
	}
	return {fW: dW, sW: dW + x, fH: dH, sH: dH + y, sL: x, sT: y};
}


/* Titel tonen en verbergen
------------------------------------------------------------------*/
var divInfo = false;
function dpInfo(ele, title) {
	if (!divInfo) {
		divInfo = document.createElement('div');
		divInfo.setAttribute('id', 'hoverdiv');
		with (divInfo.style) {
			position		= 'absolute';
			backgroundColor	= '#f5f5f5';
			color 		   	= 'black';
			padding     	= '2px';
			height     	  	= '18px';
			border	     	= 'solid 1px #d5d5d5';
			overFlow		= 'hidden';
			whiteSpace		= 'nowrap';
		}
		
		filterOpacity(divInfo, 80);
		divInfo.onmouseover = new Function("divInfo.style.display = 'none';");
		
		document.body.appendChild(divInfo);
	}
	
	divInfo.innerHTML = title;	
	divInfo.style.display = '';
	
	offset = getOffset(ele);
	divInfo.style.left = offset.x + 'px';
	divInfo.style.top = (offset.y - 24) + 'px';
	
	if (divInfo.offsetWidth) {
		offWidth = parseInt(divInfo.offsetWidth);
		fs = getFrameSize(2000, 2000);
		eW = (offset.x + offWidth);
		eW = (eW - fs.fW);
		
		if (eW > 0) {
			eW += 20;
			divInfo.style.left = (offset.x - eW) + 'px';
		}
	}
}
function hdInfo() {
	if (divInfo) {
		divInfo.style.display = 'none';
	}
}


/* Element tonen en verbergen
------------------------------------------------------------------*/
function dpEle(id) {
	if (eleId(id)) {
		eleId(id).style.display = '';
	}
}
function hdEle(id) {
	if (eleId(id)) {
		eleId(id).style.display = 'none';
	}
}


/* Tabblad tonen
------------------------------------------------------------------*/
function dpTab(id) {
	id = 'tab_' + id;
	
	if (eleId('tabs') && eleId(id)) {
		tabItems = eleId('tabs');
		
		aElements = tabItems.getElementsByTagName('a');
		for (i = 0; i < aElements.length; i++) {
			aEle = aElements[i];
			if (aEle.id == id) {
				aEle.innerHTML = aEle.innerHTML.replace("_u", "_s");
			} else {
				aEle.innerHTML = aEle.innerHTML.replace("_s", "_u");
			}
		}
	}
}


/* Doorverwijzing teller
------------------------------------------------------------------*/
function MsgCount(seconds, url) {
	this.url = url;
	this.seconds = seconds;
	this.ticker = false; 
}
MsgCount.prototype.start = function() {
	this.ticker = setInterval('msgCount.tick();', 1000);
}
MsgCount.prototype.tick = function() {
	this.seconds--;
	eleId('msgClock').innerHTML = this.seconds;
	
	if (this.seconds == 0) {
		this.ticker = clearInterval(this.ticker);
		redirectTo(this.url);
	}
}


/* Ajax
------------------------------------------------------------------*/
var jxReq;
var jxCallFunc;
var jxResp;
function jxLoad(u, f, p, a) {
	a = (a === false ? false : true);
	jxCallFunc = f;
	
    if (window.XMLHttpRequest) {
        jxReq = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        jxReq = new ActiveXObject("Microsoft.XMLHTTP");
    }

	if (jxReq) {
		if (jxCallFunc) {
			jxReq.onreadystatechange = jxProcess;
		}
		
		if (p) {
			jxReq.open('POST', u, a);
			jxReq.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			jxReq.setRequestHeader("Content-length", p.length);
			jxReq.setRequestHeader("Connection", "close");
			jxReq.send(p);
		} else {
			jxReq.open("GET", u, a);
			jxReq.send("");
		}
		
		return true;
	}
	return false;
}

function jxProcess() {
    if (jxReq.readyState == 4) {
        if (jxReq.status == 200) {
			jxResp = new Function("return " + jxReq.responseText)();
			lf = new Function(jxCallFunc);
			lf();
        }
    }
}
