/* ------------------------------------ GENERIC --------------------------------- */

function rwclass(rw,cls) {
	rw.className = cls;
}

// doMaillink: Mail address scrambler
function doMaillink(usr,dom,txt) {
	//writes an E-mail address + maillink (anti-spam purposes)
	var at = "@";
	var mailaddress = usr + at + dom;
	if(txt=="") {
		txt = mailaddress; 
	}
	document.write("<a href=\"mailto:" + mailaddress + "\">" + txt + "</a>");
}	
//checkmail: kijk na of e-mailadres mogelijk is
function checkmail(str){
	if (str != '')
   	{	if (str.indexOf('.') == -1)
			 return false;
		if (str.indexOf('@') == -1)
			 return false;
		len = str.length;
		for (i = 0; i < len; i++)
		{	if (  ( str.charAt(i) < 'a' || str.charAt(i) > 'z' ) && isNaN(str.charAt(i)) )
				  if (str.charAt(i) < 'A' || str.charAt(i) > 'Z')
					   if (str.charAt(i) != '.' && str.charAt(i) != '-' && str.charAt(i) != '_' && str.charAt(i) != '@')
							return false;
		}
	}
	return true;
}
//setfocus: plaats cursor in bepaald veld
function setfocus(a_field_id) {
	var thefield = document.getElementById(a_field_id);
	if(thefield){	thefield.focus(); }
}
function numeric(keyP){
	var key;	
	if (document.all) {key = window.event.keyCode;}
	else {key = keyP.which;}	
	if ((key>47 && key<58) || (key==46) || (key==45) || (key < 32 || key==127)) {return true;}
	else {return false;}
}
function fGetSDims () {
	var x, y;
	if (self.pageYOffset) { // all except Explorer
		x = self.pageXOffset;
		y = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6/7 Strict Mode
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	}
	else if (document.body) { // all other Explorers
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
	}
	return [x, y];
}
function scrollto(elementId, hideEl) {
	var coords = findPos(document.getElementById(elementId));
	var dist;
	var coef = 1;
	var y;
	var diff;
	
	var slideStep = 30;
    var slideTime = 30;
	
	var dimens = fGetSDims();
	y = dimens[1];
	
	dist = coords[1] - y;
	if (dist < 0) {
		coef = -1;
	}	
	var timer = setInterval(function () {
		dimens = fGetSDims();
		y = dimens[1];
	
		if ((coords[1] - y)*coef < ((dist*coef)/slideStep)) {
			window.scrollTo(0, coords[1]);
			clearInterval(timer);
			if (hideEl) {
				hideEl.style.display = "none";
			}
		} else {
			window.scrollBy(0, (dist/slideStep));
			dimens = fGetSDims();		
			diff = dimens[1];
			
			if (y === diff) { //scroll bottom reached
				clearInterval(timer);
				if (hideEl) {
					hideEl.style.display = "none";
				}
			}
		}
	}, slideTime);
}
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return [curleft,curtop];
}
function inarray(arr, str)
{	var gevonden = false;
	for(i in arr)
	{	if (arr[i].toLowerCase() == str.toLowerCase())
		{	gevonden = true;
		}
	}
	return gevonden;
}
function isnumeric(sText)
{	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;
	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{	Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
        {	IsNumber = false;
		}
	}
	return IsNumber;
}
function setValue(id, val){
	if (val) {
		var aa = document.getElementById(id);
		aa.value = foRev(val);
	}
}	
function RefreshImage(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	var str = ""
	
	str = objImage.src;
	if(str.indexOf('?x=') > 0)
	{	str = str.split('?x=')[0];
	}
	if(str.indexOf('&x=') > 0)
	{	str = str.split('&x=')[0];
	}	
	if(objImage.src.indexOf('?') > 0)
	{	str += '&x=' + now.toUTCString();	
	}
	else
	{	str += '?x=' + now.toUTCString();	
	}
	objImage.src = str;
}
function getValue(id){
	var aa = document.getElementById(id);
	return aa.value;
}
function show_div(id)
{	var thediv = document.getElementById(id);
	thediv.style.display="";
}
function hide_div(id)
{	var thediv = document.getElementById(id);
	thediv.style.display="none";
}

/* ------------------------------------ LOGIN IN HEADER ----------------------------- */
function login_onblur_email(language)
{	var fld = document.getElementById("fld_login_email");
	if(fld)
	{	fld.style.background='#FFFFFF';	
		if (fld.value=='') 		
		{	fld.style.background='url(../images_template_new/login_email_' + language + '.gif) #FFFFFF';
		}	
	}			
}		
function login_onblur_password(language)
{	var fld = document.getElementById("fld_login_pass");
	if(fld)
	{	fld.style.background='#FFFFFF';	
		if (fld.value=='') 		
		{	fld.style.background='url(../images_template_new/login_password_' + language + '.gif) #FFFFFF';
		}		
	}		
}
function login_onfocus_email(lang)
{	var fld = document.getElementById("fld_login_email");
	fld.style.background='#FFFFFF';			
}	
function login_onfocus_password(lang)
{	var fld = document.getElementById("fld_login_pass");
	fld.style.background='#FFFFFF';			
}	
function LoginInit(language) {
	login_onblur_email(language);
	login_onblur_password(language);
}

/* ------------------------------------ NAVIGATION --------------------------------- */
// Navigation - menu highlighting
function setNavClass(section) {
	//Sets an image in the navigation bar to "highlight" mode
	//it is essential to use correct image names (must correspond with the "section" argument).
	if ((section != '') && (section != 'none')) {
		var secid = document.getElementById(section);
		if(secid){
			secid.className = "mactive";
		}
	}
}

/* ------------------------------------ TABS can be improved--------------------- */
function hide_tabs(name, maxnr){
	var el_content;
	var el_button;
	for (i=0; i < maxnr; i++)
	{	el_content = document.getElementById("tab_" + name + "_content_" + (i +1))
		el_button = document.getElementById("tab_" + name + "_button_" + (i +1))
		if(el_content) el_content.style.display="none";
		if(el_button) el_button.className = "s_tab_block_button";
	}
}
function show_tab(name, tabnr, maxnr){
	if(!maxnr){
		maxnr = 20;
	}

	hide_tabs(name, maxnr);
	var el_content = document.getElementById("tab_" + name + "_content_" + tabnr)
	var el_button = document.getElementById("tab_" + name + "_button_" + tabnr)
	
	if(el_content) el_content.style.display="";	
	if(el_button) el_button.className = "s_tab_block_button_active";	
}

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

//

// getPageSize()

// Returns array with page width, height and window width, height

// Core code from - quirksmode.org

// Edit for Firefox by pHaez

//

function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	

	// for small pages with total height less then height of the viewport

	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}


	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;

}

/* ------------------------------------ LIGHTBOX ------------------------------- */
function ShowLightBox(name, focus_to){											
	//vergeet geen div aan te maken met id edit_block_background
	
	var objOverlay = document.getElementById('lightbox_block_background');
	var objLightbox = document.getElementById(name);
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();


	var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - 35 ) / 2);
	var lightboxLeft = ((arrayPageSize[0] - 20 ) / 2);


	objLightbox.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
	objLightbox.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";

	if (document.body.scrollWidth > document.body.offsetWidth) // all but Explorer Mac											
	{	x = document.body.scrollWidth;
	}											
	else // Explorer Mac would also work in Explorer 6 Strict, Mozilla and Safari
	{	x = document.body.offsetWidth;
	}

	objOverlay.style.display="";
	objOverlay.style.width = x + "px";
	objOverlay.style.height = (arrayPageSize[1] + 'px');
	

	objLightbox.style.display = "";
	
	// probeer cursor in focus veld te plaatsen
	if(focus_to != "")
	{	setfocus(focus_to);
	}
}

function CloseLightBox(name){
	var thebox = document.getElementById(name);
	thebox.style.display = "none";
	document.getElementById("lightbox_block_background").style.display="none";	
}
/* ------------------------------------ AJAX --------------------------------- */
var ajaxDirectory = "/ajax/";
var errorText = "error";
var generalErrorMessage = "Er heeft zich een fout voorgedaan. Probeer het opnieuw aub.";
var noBrowserSupport = "Sorry, uw browser ondersteunt geen AJAX technologie.";

var xmlHttp;
var responseText;
var responseXml;
var ajaxasync = true;

function fdoAjaxPostText(page, funcname) {
	fdoAjax(page, funcname,"text", "post");
}
// geef de pagina (met parameters die uitgevoerd moet worden) en de js functie die na de call moet uitgevoerd worden
function fdoAjaxText(page, funcname) {
	fdoAjax(page, funcname,"text", "get");
}
function fdoAjaxXml(page, funcname) {
	fdoAjax(page, funcname,"xml", "get");
}
function fdoAjax(page, funcname, method, post_or_get) {
	responseText = '';
	responseXml = '';
	var xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null) {
		alert (noBrowserSupport);
		return;
	}
	
	var rand;
	if (page.indexOf("?") >= 0)
		rand = "&sid="+Math.random();
	 else
	 	rand = "?sid="+Math.random();	
	
	if (page.indexOf("http://") >= 0) {
	 	url = page+ rand;
	} else {
 		url = ajaxDirectory + page+ rand;
	}
	
	if(post_or_get=="get") {
		var url=ajaxDirectory + page + rand;
		xmlHttp.onreadystatechange= function() {
			fEndAjax(funcname,method, xmlHttp);
		};
		xmlHttp.open("GET",url,ajaxasync);
		xmlHttp.send(null);
	}
	else {
		var url = ajaxDirectory + page.split("?")[0];
		var query = page.split("?")[1];
		xmlHttp.open("POST", url, true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", query.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.onreadystatechange = function() {
			fEndAjax(funcname,method, xmlHttp);
		}
		xmlHttp.send(query);
	}
}

function fdoAjaxSync(page, method) {

	var xmlHttp= self.xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
		alert (noBrowserSupport);
		return;
	} 
	var url;
	if (page.indexOf("http://") >= 0)
	{
	 url= page+"&sid="+Math.random();
	} else{
	 url=ajaxDirectory + page+"&sid="+Math.random();
	}

	
	xmlHttp.open("GET",url,false);
	xmlHttp.send(null);
	if (method=="text" )
		return xmlHttp.responseText;
	else
		return xmlHttp.responseXML;
}

function fEndAjax(funcname, method, xmlHttp)
{
	document.body.style.cursor = 'wait';
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
		if (xmlHttp.status == '200' || xmlHttp.status=='0') {
			if (method=="text") {
				if (xmlHttp.responseText != errorText) {	
					responseText= xmlHttp.responseText;
					funcname(xmlHttp.responseText, xmlHttp);
				} else { //an error occurred
					alert(generalErrorMessage + " (code 1)")
				}
			} else {
				if (xmlHttp.responseText != errorText) {
					if (window.ActiveXObject) {
						responseXml=new ActiveXObject("Microsoft.XMLDOM");
					} // code for Mozilla, Firefox, Opera, etc.
					else if (document.implementation && document.implementation.createDocument) {
						responseXml=document.implementation.createDocument("","",null);
					}
					responseXml = xmlHttp.responseXML;
					funcname(xmlHttp.responseXML, xmlHttp);
				} else {//an error occurred
					alert(generalErrorMessage + " (code 2)")
				}
			}
		} else {
			alert(generalErrorMessage + " (code 3)" + '\n\n' +  + xmlHttp.responseXML);
		}
	}
	document.body.style.cursor = 'default';
}
function GetXmlHttpObject() { 
	var objXMLHttp=null;
	if (window.XMLHttpRequest) {
		objXMLHttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp;
}
function fillbox(box, list){
	var rec	= list.split("-|-");
	var ret = "";
	box.options.length = 0;
	for (i in rec){
		if (rec[i]!=''){
			var dd = rec[i].split('-,-')[0].indexOf('*');
			var ee = dd != -1 ? true:false;
			box[i] = new Option(rec[i].split('-,-')[1], rec[i].split('-,-')[0].replace('*', ''),false,ee);
			if (ee) {ret = rec[i].split('-,-')[0].replace('*', '');}
		}
	}
	return ret;	
}
function URLencode(sStr) {
    return escape(sStr).
             replace(/\+/g, '%2B').
                replace(/\"/g,'%22').
                   replace(/\'/g, '%27').
                     replace(/\//g,'%2F');
}

function clearTextField(object, str) {
	if (object) {
		if (object.value == str || str == '') {
			object.value = '';
		}
	}
}

function changeToPass(object) {
	if (object) {
		object.type = 'password';
	}
}

function changeToTextField(object) {
	if (object) {
		if (object.value.length == 0) {
			object.type = 'text';
		}
	}
}

function changeFontColor(object, color) {
	if (object) {
		object.style.color = color;
	}
}

function fillField(object, str) {
	if (object) {
		if (object.value.length == 0) {
			object.value = str;
		}
	}
}
/* ------------------ Macromedia FUNCTIONS ------------------------------ */
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_reloadPage(init) {  //reloads the window if Nav4 resized -DISABLED!!!!!!
  //if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
//	document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  //else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
//MM_reloadPage(true);	- DISABLED!!!
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}
