/**
* Declaration variables
*/
var screenHeight = window.screen.availHeight;
var screenWidth = window.screen.availWidth;
var colorDepth = window.screen.colorDepth;
var timeNow = new Date();
var referrer = escape(document.referrer);
var windows, mac, linux;
var ie, op, moz, misc, browsercode, browsername, browserversion, operatingsys;
var dom, ienew, ie4, ie5, ie6, moz_rv, moz_rv_sub, ie5mac, ie5xwin, opnu, op4, op5, op6, op7, saf, konq;
var appName, appVersion, userAgent;
var appname = navigator.appName;
var appVersion = navigator.appVersion;
var userAgent = navigator.userAgent.toLowerCase();
var title = document.title;
var checktoggle = 1;
var DOM = "default";
windows = (appVersion.indexOf('Win') != -1);
mac = (appVersion.indexOf('Mac') != -1);
linux = (appVersion.indexOf('Linux') != -1);

/**
* DOM Compatible?
*/
if (!document.layers)
{
	dom = (document.getElementById ) ? document.getElementById : false;
} else {
	dom = false;
}

if (document.getElementById)
{
	DOM = "default";
} else if (document.layers) {
	DOM = "NS4";
} else if (document.all) {
	DOM = "IE4";
}

misc=(appVersion.substring(0,1) < 4);
op=(userAgent.indexOf('opera') != -1);
moz=(userAgent.indexOf('gecko') != -1);
ie=(document.all && !op);
saf=((userAgent.indexOf('safari') != -1) || (navigator.vendor == "Apple Computer, Inc."));
konq=(userAgent.indexOf('konqueror') != -1);

if (op) {
	op_pos = userAgent.indexOf('opera');
	opnu = userAgent.substr((op_pos+6),4);
	op5 = (opnu.substring(0,1) == 5);
	op6 = (opnu.substring(0,1) == 6);
	op7 = (opnu.substring(0,1) == 7);
} else if (moz){
	rv_pos = userAgent.indexOf('rv');
	moz_rv = userAgent.substr((rv_pos+3),3);
	moz_rv_sub = userAgent.substr((rv_pos+7),1);
	if (moz_rv_sub == ' ' || isNaN(moz_rv_sub)) {
		moz_rv_sub='';
	}
	moz_rv = moz_rv + moz_rv_sub;
} else if (ie){
	ie_pos = userAgent.indexOf('msie');
	ienu = userAgent.substr((ie_pos+5),3);
	ie4 = (!dom);
	ie5 = (ienu.substring(0,1) == 5);
	ie6 = (ienu.substring(0,1) == 6);
}

if (konq) {
	browsercode = "KO";
	browserversion = appVersion;
	browsername = "Knoqueror";
} else if (saf) {
	browsercode = "SF";
	browserversion = appVersion;
	browsername = "Safari";
} else if (op) {
	browsercode = "OP";
	if (op5) {
		browserversion = "5";
	} else if (op6) {
		browserversion = "6";
	} else if (op7) {
		browserversion = "7";
	} else {
		browserversion = appVersion;
	}
	browsername = "Opera";
} else if (moz) {
	browsercode = "MO";
	browserversion = appVersion;
	browsername = "Mozilla";
} else if (ie) {
	browsercode = "IE";
	if (ie4) {
		browserversion = "4";
	} else if (ie5) {
		browserversion = "5";
	} else if (ie6) {
		browserversion = "6";
	} else {
		browserversion = appVersion;
	}
	browsername = "Internet Explorer";
}

if (windows) {
	operatingsys = "Windows";
} else if (linux) {
	operatingsys = "Linux";
} else if (mac) {
	operatingsys = "Mac";
} else {
	operatingsys = "Unkown";
}

function checkFieldsCommentForm() {
	var thisForm = document.forms["commentform"];
	thisForm.mcname.value = trim (thisForm.mcname.value);
	thisForm.email.value = trim (thisForm.email.value);	

	if (thisForm.mcname.value == "") {
		alert("Geen naam ingevuld");
		return false;
	}
	else if (thisForm.comments.value == "") {
		alert("Geen commentaar ingevuld");
		return false;
	}
	else if (thisForm.email.value != "") {
		if (thisForm.email.value.indexOf('@', 0) == -1) {
			alert("Geen geldig e-mail adres!");
			return false;
		}
		else if (thisForm.email.value.indexOf(' ', 0) != -1) {
			//alert("Geen geldig e-mail adres! (Een spatie)");
			var temp = "";
			var string = thisForm.email.value;
			string = '' + string;
			var splitstring = string.split(" ");
			for(i = 0; i < splitstring.length; i++)
			temp += splitstring[i];
			thisForm.email.value = temp;
			//alert ("temp = " + temp);
			return true;
		}
		else if (thisForm.email.value.indexOf(',', 0) != -1 || thisForm.email.value.indexOf(';', 0) != -1) {
			alert("Geen geldig e-mail adres! (, of ; scheidingsteken)");
			return false;
		}
		else if (thisForm.email.value.indexOf('\'', 0) != -1 || thisForm.email.value.indexOf('\"', 0) != -1 || thisForm.email.value.indexOf('´', 0) != -1 || 	thisForm.email.value.indexOf('`', 0) != -1 || 
			thisForm.email.value.indexOf('&', 0) != -1 || thisForm.email.value.indexOf('!', 0) != -1 || thisForm.email.value.indexOf('(', 0) != -1 || thisForm.email.value.indexOf(')', 0) != -1 ||
			thisForm.email.value.indexOf('{', 0) != -1 || thisForm.email.value.indexOf('}', 0) != -1 || thisForm.email.value.indexOf('[', 0) != -1 || thisForm.email.value.indexOf(']', 0) != -1 ||
			thisForm.email.value.indexOf('~', 0) != -1 || thisForm.email.value.indexOf('*', 0) != -1 || thisForm.email.value.indexOf('+', 0) != -1 ||
			thisForm.email.value.indexOf('#', 0) != -1 || thisForm.email.value.indexOf('|', 0) != -1 || thisForm.email.value.indexOf('§', 0) != -1 || thisForm.email.value.indexOf('^', 0) != -1 ||
			thisForm.email.value.indexOf('°', 0) != -1 || thisForm.email.value.indexOf('=', 0) != -1) {
			alert("Geen geldig e-mail adres! (\'  \" ´ ` & ! ( ) { } [ ] ~ * + # | § ^ ° ongeldige tekens)");
			return false;
		}
	}
	return true;
}

function checkFieldsSearchForm() {
	var thisForm = document.forms["SearchForm"];
	thisForm.searchString.value = trim (thisForm.searchString.value);

	if (thisForm.searchString.value == "") {
		alert("Geen zoekterm ingevuld");
		return false;
	}
	else if (thisForm.searchString.value == "- voer zoekterm in -") {
		alert("Geen zoekterm ingevuld");
		return false;
	}
	return true;
}

function doRand()
{
	var num;
	now=new Date();
	num=(now.getSeconds());
	num=num+1;
	return num;
}

function getCookie(name) {
	var crumb = document.cookie;
	var index = crumb.indexOf(name + "=");
	if (index == -1) return null;
	index = crumb.indexOf("=", index) + 1;
	var endstr = crumb.indexOf(";", index);
	if (endstr == -1) endstr = crumb.length;
	return unescape(crumb.substring(index, endstr));
}

function deleteCookie(name) {
	var expiry = new Date();
	document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
}

function browserObject(objid)
{
	if (DOM == "default")
	{
		return document.getElementById(objid);
	} else if (DOM == "NS4") {
		return document.layers[objid];		
	} else if (DOM == "IE4") {
		return document.all[objid];
	}
}

function switchDisplay(objid)
{
	/**alert ("objid = " + objid)**/
	result = browserObject(objid);
	
	if (!result)
	{
		alert("Invalid Display Object: "+objid+"\nPlease make sure that all correct display objects are on the page");
		return;
	}
	if (result.style.display == "none")
	{
		result.style.display = "";
		if (objid == "commentdata") {
			if (ie) {
				document.all.mySpan1.innerText = "Reacties van lezers verbergen";
			}
			else if (moz) {
				var pappie
				var inhoud
				var strSelect
				// een parentNode nodig om select aan te koppelen
				pappie = document.getElementById('mySpan1');
				//bewaar de huidge inhoud
				//inhoud = pappie.innerHTML
				// nieuwe inhoud
				inhoud="Reacties van lezers verbergen";
				pappie.innerHTML = inhoud
			}
		}
		else if (objid == "commentform") {
			if (ie) {
				document.all.mySpan2.innerText = "Voeg uw reactie toe verbergen";
			}
			else if (moz) {
				var pappie
				var inhoud
				var strSelect
				pappie = document.getElementById('mySpan2');
				// nieuwe inhoud
				inhoud="Voeg uw reactie toe verbergen";
				pappie.innerHTML = inhoud
			}
		}
	} else {
		result.style.display = "none";
		if (objid == "commentdata") {
			if (ie) {
				document.all.mySpan1.innerText = "Reacties van lezers";
			}
			else if (moz) {
				var pappie
				var inhoud
				var strSelect
				pappie = document.getElementById('mySpan1');
				// nieuwe inhoud
				inhoud="Reacties van lezers";
				pappie.innerHTML = inhoud
			}
		}
		else if (objid == "commentform") {
			if (ie) {
				document.all.mySpan2.innerText = "Voeg uw reactie toe!";
			}
			else if (moz) {
				var pappie
				var inhoud
				var strSelect
				pappie = document.getElementById('mySpan2');
				// nieuwe inhoud
				inhoud="Voeg uw reactie toe!";
				pappie.innerHTML = inhoud
			}
		}
	}
}

function displayObject(objid)
{
	result = browserObject(objid);
	if (!result)
	{
		alert("Invalid Display Object: "+objid+"\nPlease make sure that all correct display objects are on the page");
		return;
	}

	result.style.display = "";
}

function hideObject(objid)
{
	result = browserObject(objid);
	if (!result)
	{
		alert("Invalid Display Object: "+objid+"\nPlease make sure that all correct display objects are on the page");
		return;
	}

	result.style.display = "none";
}

function htmlize(str){
        str = str.replace(/\&/g,"&amp;");
        str = str.replace(/\</g,"&lt;");
        str = str.replace(/\>/g,"&gt;");
        str = str.replace(/\"/g,"&quot;");
        str = str.replace(/\n/g,"<br/>\n");
        return str;
}

function writeMessage(towrite) {
	if (browsercode == "OP") {
		window.parent.contentframe.writeToDiv(towrite);
	} else if (browsercode == "SF") {
		writeToDivSaf(towrite);
	} else {
		writeToDoc(towrite);
	}
}

function writeToDoc(data) {
	window.parent.contentframe.window.document.write(data);

	if (typeof(scrollBy) != "undefined")
	{
		window.parent.contentframe.window.scrollBy(0, 6000);
	} else if (typeof(scroll) != "undefined") {
		window.parent.contentframe.window.scrollBy(0, 6000);
	}
}

function clearDoc() {
	if (browsercode == "OP") {
		window.parent.contentframe.clearDiv();
	} else {
		window.parent.contentframe.window.document.close();
		window.parent.contentframe.window.document.open();
		window.parent.contentframe.window.document.clear();
		window.parent.contentframe.window.document.write("");
	}
}

function writeToDiv(data) {
	divobj = browserObject("buffer");
	divobj.innerHTML = divobj.innerHTML+data;

	if (typeof(scrollBy) != "undefined")
	{
		window.scrollBy(0, 6000);
	} else if (typeof(scroll) != "undefined") {
		window.scrollBy(0, 6000);
	}
}

function writeToDivSaf(data) {
	divobj = parent.contentframe.document.getElementById("buffer");
	divobj.innerHTML = divobj.innerHTML+data;

	if (typeof(scrollBy) != "undefined")
	{
		window.scrollBy(0, 6000);
	} else if (typeof(scroll) != "undefined") {
		window.scrollBy(0, 6000);
	}
}

function clearDiv() {
	divobj = browserObject("buffer");
	divobj.innerHTML = "";
}

function addBookmark(title,url) {
if (window.sidebar) { 
window.sidebar.addPanel(title, url,""); 
} else if( document.all ) {
window.external.AddFavorite( url, title);
} else if( window.opera && window.print ) {
return true;
}
}

function popupInfoWindow(url) {
	screen_width = screen.width;
	screen_height = screen.height;
	widthm = (screen_width-400)/2;
	heightm = (screen_height-500)/2;
	window.open(url,"infowindow"+doRand(), "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=400,height=500,left="+widthm+",top="+heightm);
}

function jumpLanguage(selObj)
{
	languageid = selObj.options[[selObj.selectedIndex]].value;
	window.location.href = 'index.php?languageid='+languageid;
}

/**
* ###############################################
* AJAX
* ###############################################
*/

var xmlhttp;
var xmlaction = "";

function loadXMLHTTPRequest(url) {
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
		xmlhttp.onreadystatechange = processStatusChange;
		xmlhttp.open("GET", url, true);
		xmlhttp.send(null);
	} else if (window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		if (xmlhttp) {
			xmlhttp.onreadystatechange = processStatusChange;
			xmlhttp.open("GET", url, true);
			xmlhttp.send();
		}
	}
}

function processStatusChange() {
	if (xmlhttp.readyState == 4) {
		if (xmlhttp.status == 200) {

			// ======= IRS Fetch? =======
			if (xmlaction == "irsfetch")
			{
				irsObject = browserObject("irsui");
				if (irsObject)
				{
					irsObject.innerHTML = xmlhttp.responseText;
				}
			}
		}
	}
}

var irsContents = "";
function startIRSTimer()
{
	if (document.submitticket.message.value != irsContents && document.submitticket.message.value != "")
	{
		displayObject("irsui");

		xmlaction = "irsfetch";
		loadXMLHTTPRequest(swiftpath+"index.php?_m=knowledgebase&_a=irsfetch&randno="+doRand()+"&query="+escape(document.submitticket.message.value));

		irsContents = document.submitticket.message.value;
	}

	setTimeout('startIRSTimer();', 2000);
}

/**
* ###############################################
* Tekst tonen of verbergen
* ###############################################
*/

var onthouden="aan" 		// actuele status bijhouden met sessie-cookie (aan/uit)
var vorige_verbergen="ja"   // bij nieuw item vorige geopende item dichtvouwen(ja/nee)

if (document.getElementById) {
	document.write('<style type="text/css">')
	document.write('.wisselen{display:none;}')
	document.write('</style>')
}

function getElementbyClass(classname) {
	ophalen=new Array()
	var teller=0
	var alleTags=document.all? document.all : document.getElementsByTagName("*")
	for (i=0; i<alleTags.length; i++) {
		if (alleTags[i].className==classname)
		ophalen[teller++]=alleTags[i]
	}
}

function dichtvouwen(omit) {
	var teller=0
	while (ophalen[teller]) {
		if (ophalen[teller].id!=omit)
		ophalen[teller].style.display="none"
		teller++
	}
}

function uitvouwen(cid){
if (typeof ophalen!="undefined"){
if (vorige_verbergen=="ja")
dichtvouwen(cid)
document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"}}

function vernieuwen() {
	dichtvouwen("alles")
	selectedItem=getselectedItem()
	selectedComponents=selectedItem.split("|")
	for (i=0; i<selectedComponents.length-1; i++)
	document.getElementById(selectedComponents[i]).style.display="block"
}

function get_cookie(Name) { 
	var search = Name + "="
	var returnvalue = "";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search)
		if (offset != -1) { 
			offset += search.length
			end = document.cookie.indexOf(";", offset);
			if (end == -1) end = document.cookie.length;
			returnvalue=unescape(document.cookie.substring(offset, end))
		}
	}
	return returnvalue;
}

function getselectedItem() {
	if (get_cookie(window.location.pathname) != "") {
		selectedItem=get_cookie(window.location.pathname)
		return selectedItem
	}
	else return ""
}

function status_opslaan() {
	var teller=0, selectedItem=""
	while (ophalen[teller]) {
		if (ophalen[teller].style.display=="block")
		selectedItem+=ophalen[teller].id+"|"
		teller++
	}
	document.cookie=window.location.pathname+"="+selectedItem
}

function do_onload() {
	getElementbyClass("wisselen")
	if (onthouden=="aan" && typeof ophalen!="undefined")
	vernieuwen()
}

if (window.addEventListener)
	window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
	window.attachEvent("onload", do_onload)
else if (document.getElementById)
	window.onload=do_onload

if (onthouden=="aan" && document.getElementById)
	window.onunload=status_opslaan

function goNextAnchor(where) {
	window.location.hash = where
}