/**                  
 * functions.js
 *
 * This file profites an general function set! 
 * The functions below are very handy for handling
 * common javascript functionality or Dynamic (X)HTML.
 *
 * @version 	1.0
 * @author	A.J. de Vries	
 * @package	javascript 
 * 
 * Copyright (c) 2005 Malibomba                               
 * IT IS NOT ALLOWED TO USE OR MODIFY ANYTHING OF THIS SITE,  
 * WITHOUT THE PERMISION OF THE AUTHOR.                       
 * Info? Mail to info@malibomba.com                           
 */
//<![CDATA[ 
var xmlhttp = null;
/*@cc_on @*/
/*@if(@_jscript_version >= 5)
	try {
		xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
	} catch(e) {
		try {
			xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
		} catch(e) {
			xmlhttp = false;
		}
	}
@else
	var xmlhttp = false;
@end @*/
if(!xmlhttp && document.createElement) {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch(e) {
		xmlhttp = false;
	}
}


/**
 * Array.prototype.addItem = function(item)
 *
 * Add an item to an excisting Array.
 *
 * @version 1.0
 * @access  public
 * @author  A.J. de Vries
 * @param   [mixed]   item: the new item to add.
 * @return  [integer] the new length of the array.
 */
Array.prototype.addItem = function(item) {
	this[this.length] = item;
	return this.length;
};



/**
 * Array.prototype.indexOf = function(value)
 *
 * Get the index (key) that identifier the given value
 * in an Array.
 *
 * @version 1.0
 * @access  public
 * @author  A.J. de Vries
 * @param   [mixed] value: the value of the array.
 * @return  [mixed] the index that identifier the given value.
 */
Array.prototype.indexOf = function(value) { 
	for(var i = 0; i < this.length; i++) {
		if(this[i] == value) { 
			return i;
		}
	} return-1;
};



/**
 * String.prototype.startsWith = function(value)
 *
 * Check if the current string starts with the given value.
 *
 * @version 1.0
 * @access  public
 * @author  A.J. de Vries
 * @param   [mixed]   value: the value to check for.
 * @return  [boolean] true if the string starts with the given value, false otherwise.
 */
String.prototype.startsWith = function(value) { 
	return (this.substr(0, value.length) == value);
};



/**
 * String.prototype.endsWith = function(value, ignoreCase)
 *
 * Check if the current string end with the given value.
 * It's possible to specfify if the check should be case-sensative
 * or not.
 *
 * @version 1.0
 * @access  public
 * @author  A.J. de Vries
 * @param   [mixed]   value: the value to check for.
 * @param   [boolean] ignoreCare: to specify if the checl should be case-sensative.
 * @return  [boolean] true if the string end with the given value, false otherwise.
 */
String.prototype.endsWith = function(value, ignoreCase) {
	if(value.length > this.length) {
		return false;
	} else {
		if(ignoreCase) {
			var oRegex = new RegExp(value + '$', 'i');
			return oRegex.test(this);
		} else {
			return (value.length == 0 || this.substr(this.length - value.length, value.length) == value);
		}
	}
};



/**
 * String.prototype.remove = function(start, length)
 *
 * Remove a piece from the current string.
 *
 * @version 1.0
 * @access  public
 * @author  A.J. de Vries
 * @param   [integer] start: the starting position.
 * @param   [integer] length: the lenght of the piece to remove.
 * @return  [string]  the new string.
 */
String.prototype.remove = function(start, length) {
	var str = (start > 0) ? this.substring(0, start) : '';
	if(start + length < this.length) {
		str += this.substring(start + length, this.length);
	} 
	return str;
};



/**
 * String.prototype.trim = function()
 *
 * Remove white space from the beginning and end of a string.
 *
 * @version 1.0
 * @access  public
 * @author  A.J. de Vries
 * @return  [string] the trimmed string.
 */
String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, '');
};



/**
 * String.prototype.ltrim = function()
 *
 * Remove white space from the beginning of a string.
 *
 * @version 1.0
 * @access  public
 * @author  A.J. de Vries
 * @return  [string] the trimmed string.
 */
String.prototype.ltrim = function() {
	return this.replace(/^\s*/g, '');
};



/**
 * String.prototype.rtrim = function()
 *
 * Remove white space from the end of a string.
 *
 * @version 1.0
 * @access  public
 * @author  A.J. de Vries
 * @return  [string] the trimmed string.
 */
String.prototype.rtrim = function() {
	return this.replace(/\s*$/g, '');
};



/**
 * String.prototype.replaceNewLineChars = function(replacement)
 *
 * Replace new line breaks with the given replacement
 *
 * @version 1.0
 * @access  public
 * @author  A.J. de Vries
 * @param   [mixed]  replacement: the replacement of the new line break.
 * @return  [string] the new (replaced) string.
 */
String.prototype.replaceNewLineChars = function(replacement) {
	return this.replace(/\n/g, replacement);
};



/**
 * getElement(elem)
 *
 * Get the element with the given name (elem)
 * and return a reference (object) to it.
 *
 * @version 1.0
 * @access  public
 * @author  A.J. de Vries
 * @param   [string] elem: the name of the element
 * @return  [object] the object that references the element with the given name.
 */
function getElement(elem) {
	if(document.getElementById)
		return document.getElementById(elem);
	if(document.all)
		return document.all[elem];
}



/**
 * addEvent(elem, evt, func)
 *
 * Add an event to the given element (elem)
 *
 * @version 1.0
 * @access  public
 * @author  A.J. de Vries
 * @param   [object]   elem: the element(object) on which the event is set to.
 * @param   [string]   evt:  the name of the event, e.g: 'load', 'focus', 'unload', etc.
 * @param   [function] func: the function to execute.
 * @return  [void]
 */
function addEvent(elem, evt, func) {
	if(elem.addEventListener)
		elem.addEventListener(evt, func, false);
	else if(elem.attachEvent)
		elem.attachEvent('on'+evt, func);
}



/**
 * removeEvent(elem, evt, func)
 *
 * Remove an event from the given element (elem)
 *
 * @version 1.0
 * @access  public
 * @author  A.J. de Vries
 * @param   [object]   elem: the element(object) on which the event is set to.
 * @param   [string]   evt:  the name of the event, e.g: 'load', 'focus', 'unload', etc.
 * @param   [function] func: the function to execute.
 * @return  [void]
 */
function removeEvent(elem, evt, func) {
	if(elem.addEventListener)
		elem.removeEventListener(evt, func, true);
	else if(elem.attachEvent)
		elem.detachEvent("on" + evt, func);
};



/**
 * random image
 *
 */
 
var theImages = new Array() // do not change this

theImages[0] = '/pics/professionaliseren01.jpg'
theImages[1] = '/pics/professionaliseren02.jpg'
theImages[2] = '/pics/professionaliseren03.jpg'
theImages[3] = '/pics/professionaliseren04.jpg'
theImages[4] = '/pics/professionaliseren05.jpg'

// ======================================
// do not change anything below this line
// ======================================

var j = 0
var p = theImages.length;

var preBuffer = new Array()
for (i = 0; i < p; i++){
   preBuffer[i] = new Image()
   preBuffer[i].src = theImages[i]
}

var whichImage = Math.round(Math.random()*(p-1));
function showImage(){
document.write('<img src="'+theImages[whichImage]+'">');
}




/**
 * upload document bij het formulier
 *
 */

window.onload = function() {
	var loc = document.location.href;
	var querystr = loc.match(/erno=1/);
	if(querystr == 'erno=1') {
		alert('Uw bestand is te groot om verstuurd te worden!\nDe maximale bestandsgrootte is 2 MB.');
	}
}

function checkFile(elem) {
	if(elem.value != '') {
		var bCheck = elem.value.match(/\.doc|.csv|.xls|.pdf|.jpg|.jpeg|.gif|.bmp$/i);
		if(bCheck == null) {
			alert('Uw bestand komt niet overeen met de toegenstane extenties, probeer opnieuw!');
			elem.value = '';
			elem.focus();
		}
	}
}

var news_slideSpeed = 20;	// Higher value = faster
var news_timer = 10;	// Lower value = faster

var objectIdToSlideDown = false;
var news_activeId = false;
function showHideContent()
{
	var numericId = this.id.replace(/[^0-9]/g,'');
	var readmoreDiv = document.getElementById('news_a' + numericId);
	if(!readmoreDiv.style.display || readmoreDiv.style.display=='none'){

		if(news_activeId &&  news_activeId!=numericId){
			objectIdToSlideDown = numericId;
			slideContent(news_activeId,(news_slideSpeed*-1));
		}else{
			readmoreDiv.style.display='block';
			readmoreDiv.style.visibility = 'visible';
			slideContent(numericId,news_slideSpeed);
		}
	}else{
		slideContent(numericId,(news_slideSpeed*-1));
		news_activeId = false;
	}	
}

function slideContent(inputId,direction)
{
	var obj =document.getElementById('news_a' + inputId);
	var contentObj = document.getElementById('news_ac' + inputId);
	var Footer = document.getElementById('container-foot');
	var ContentBody = document.getElementById('contentBody');
	height = obj.clientHeight;
	height = height + direction;
	rerunFunction = true;
	if(height>contentObj.offsetHeight){
		height = contentObj.offsetHeight;
		rerunFunction = false;
	}
	if(height<0){
		height = 0;
		rerunFunction = false;
	}

	obj.style.height = height + 'px';

	

	Footer.style.top =  ContentBody.offsetHeight + 200 + height + 'px';

	
	var topPos = height - contentObj.offsetHeight;
	if(topPos>0)topPos=0;
	contentObj.style.top = topPos + 'px';
	if(rerunFunction){
		setTimeout('slideContent(' + inputId + ',' + direction + ')',news_timer);
	}else{
		if(height==0){
			obj.style.display='none'; 
			if(objectIdToSlideDown && objectIdToSlideDown!=inputId){
				document.getElementById('news_a' + objectIdToSlideDown).style.display='block';
				document.getElementById('news_a' + objectIdToSlideDown).style.visibility='visible';
				slideContent(objectIdToSlideDown,news_slideSpeed);				
			}
		}else{
			news_activeId = inputId;
		}
	}
}



function initShowHideDivs()
{
	var divs = document.getElementsByTagName('DIV');
	var divCounter = 1;
	for(var no=0;no<divs.length;no++){
		if(divs[no].className=='news_title'){
			divs[no].onclick = showHideContent;
			divs[no].id = 'news_q'+divCounter;
			
			var readmore = divs[no].nextSibling;
			while(readmore && readmore.tagName!='DIV'){
				readmore = readmore.nextSibling;
			}
			
			readmore.id = 'news_a'+divCounter;	
			
			contentDiv = readmore.getElementsByTagName('DIV')[0];
			contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px'; 	
			contentDiv.className='news_readmore_content';
			contentDiv.id = 'news_ac' + divCounter;
			readmore.style.display='none';
			divCounter++;
		}		
	}	
}


// menu

	var timeBeforeAutoHide = 700;	// Microseconds to wait before auto hiding menu(1000 = 1 second)
	var slideSpeed_out = 10;	// Steps to move sub menu at a time ( higher = faster)
	var slideSpeed_in = 10;
		
	
	var slideTimeout_out = 25;	// Microseconds between slide steps ( lower = faster)
	var slideTimeout_in = 10;	// Microseconds between slide steps ( lower = faster)
	
	var showSubOnMouseOver = true;	// false = show sub menu on click, true = show sub menu on mouse over
	var fixedSubMenuWidth = false;	// Width of sub menu items - A number(width in pixels) or false when width should be dynamic
	
	var xOffsetSubMenu = -30; 	// Offset x-position of sub menu items - use negative value if you want the sub menu to overlap main menu
	
	var slideDirection = 'right';	// Slide to left or right ?
	
	/* Don't change anything below here */
	
	var activeSubMenuId = false;
	var activeMainMenuItem = false;
	var currentZIndex = 1000;		
	var autoHideTimer = 0;
	var submenuObjArray = new Array();
	var okToSlideInSub = new Array();
	var subPositioned = new Array();
	

	function stopAutoHide()
	{
		autoHideTimer = -1;
	}
	
	function initAutoHide()
	{
		autoHideTimer = 0;
		if(autoHideTimer>=0)autoHide();
	}
	
	function autoHide()
	{
		
		if(autoHideTimer>timeBeforeAutoHide)
		{
			
			if(activeMainMenuItem){
				activeMainMenuItem.className='';
				activeMainMenuItem = false;
			}
			
			if(activeSubMenuId){
				var obj = document.getElementById('subMenuDiv' + activeSubMenuId);
				showSub();
			}
		}else{
			if(autoHideTimer>=0){
				autoHideTimer+=50;
				setTimeout('autoHide()',50);
			}
		}
	}	
	
	function getTopPos(inputObj)
	{		
	  var returnValue = inputObj.offsetTop;
	  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetTop;
	  return returnValue;
	}
	
	function getLeftPos(inputObj)
	{
	  var returnValue = inputObj.offsetLeft;
	  while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;
	  return returnValue;
	}
	
	function showSub()
	{
		var subObj = false;
		if(this && this.tagName){
			var numericId = this.parentNode.id.replace(/[^0-9]/g,'');
			okToSlideInSub[numericId] = false;
			var subObj = document.getElementById('subMenuDiv' + numericId);
			if(activeMainMenuItem)activeMainMenuItem.className='';
			if(subObj){
				if(!subPositioned[numericId]){
					if(slideDirection=='right'){
						subObj.style.left = getLeftPos(submenuObjArray[numericId]['parentDiv']) + submenuObjArray[numericId]['parentDiv'].offsetWidth + xOffsetSubMenu + 'px';
					}else{
						subObj.style.left = getLeftPos(submenuObjArray[numericId]['parentDiv']) + xOffsetSubMenu + 'px';
						
					}
					submenuObjArray[numericId]['left'] = subObj.style.left.replace(/[^0-9]/g,'');
					subObj.style.top = getTopPos(submenuObjArray[numericId]['parentDiv']) + 'px';
					subPositioned[numericId] = true;
				}				
				subObj.style.visibility = 'visible';
				subObj.style.zIndex = currentZIndex;
				currentZIndex++;	
				this.className='activeMainMenuItem';
				activeMainMenuItem = this;
			}
		}else{
			var numericId = activeSubMenuId;
		}
		if(activeSubMenuId && (numericId!=activeSubMenuId || !subObj))slideMenu(activeSubMenuId,(slideSpeed_in*-1));
		if(numericId!=activeSubMenuId && this && subObj){
			subObj.style.width = '0px';	
			slideMenu(numericId,slideSpeed_out);
			activeSubMenuId = numericId;
		}else{
			if(numericId!=activeSubMenuId)activeSubMenuId = false;
		}
		if(showSubOnMouseOver)stopAutoHide();
	}
	
	function slideMenu(menuIndex,speed){
		var obj = submenuObjArray[menuIndex]['divObj'];
		var obj2 = submenuObjArray[menuIndex]['ulObj'];
		var width = obj.offsetWidth + speed;
		if(speed<0){
			if(width<0)width = 0;
			obj.style.width = width + 'px';
			if(slideDirection=='left'){
				obj.style.left = submenuObjArray[menuIndex]['left'] - width + 'px';
				obj2.style.left = '0px';
			}else{
				obj2.style.left = width - submenuObjArray[menuIndex]['width'] + 'px' 
			}
			if(width>0 && okToSlideInSub[menuIndex])setTimeout('slideMenu(' + menuIndex + ',' + speed + ')',slideTimeout_in); else{
				obj.style.visibility = 'hidden';
				obj.style.width = '0px';
				if(activeSubMenuId==menuIndex)activeSubMenuId=false;
			}
			
		}else{
			if(width>submenuObjArray[menuIndex]['width'])width = submenuObjArray[menuIndex]['width'];
			if(slideDirection=='left'){
				obj.style.left = submenuObjArray[menuIndex]['left'] - width + 'px';
				obj2.style.left = '0px';
			}else{
				obj2.style.left = width - submenuObjArray[menuIndex]['width'] + 'px' 
			}		
			
			obj.style.width = width + 'px';
			if(width<submenuObjArray[menuIndex]['width']){
				setTimeout('slideMenu(' + menuIndex + ',' + speed + ')',slideTimeout_out);
			}else{
				okToSlideInSub[menuIndex] = true;
			}
		}
	}
	function resetPosition()
	{
		subPositioned.length = 0;
	}
			
	function initLeftMenu()
	{
		var menuObj = document.getElementById('professionaliseren_menu');	
		var mainMenuItemArray = new Array();
		
		var mainMenuItem = menuObj.getElementsByTagName('LI')[0];
		while(mainMenuItem){
			if(mainMenuItem.tagName && mainMenuItem.tagName.toLowerCase()=='li'){
				mainMenuItemArray[mainMenuItemArray.length] = mainMenuItem;
				var aTag = mainMenuItem.getElementsByTagName('A')[0];
				if(showSubOnMouseOver)
					aTag.onmouseover = showSub;	
				else
					aTag.onclick = showSub;	
			}
			mainMenuItem = mainMenuItem.nextSibling;
		}		
		
		var lis = menuObj.getElementsByTagName('A');
		for(var no=0;no<lis.length;no++){
			if(!showSubOnMouseOver)lis[no].onmouseover = stopAutoHide;
			lis[no].onmouseout = initAutoHide;
			lis[no].onmousemove = stopAutoHide;
		}
				
		for(var no=0;no<mainMenuItemArray.length;no++){
			var sub = mainMenuItemArray[no].getElementsByTagName('UL')[0];
			if(sub){
				mainMenuItemArray[no].id = 'mainMenuItem' + (no+1);
				var div = document.createElement('DIV');
				div.className='professionaliseren_subMenu';
				document.body.appendChild(div);
				div.appendChild(sub);
				if(slideDirection=='right'){
					div.style.left = getLeftPos(mainMenuItemArray[no]) + mainMenuItemArray[no].offsetWidth + xOffsetSubMenu + 'px';
				}else{
					div.style.left = getLeftPos(mainMenuItemArray[no]) + xOffsetSubMenu + 'px';
				}
				div.style.top = getTopPos(mainMenuItemArray[no]) + 'px';
				div.id = 'subMenuDiv' + (no+1);
				sub.id = 'submenuUl' + (no+1);
				sub.style.position = 'relative';	

				if(navigator.userAgent.indexOf('Opera')>=0){
					submenuObjArray[no+1] = new Array();
					submenuObjArray[no+1]['parentDiv'] = mainMenuItemArray[no];
					submenuObjArray[no+1]['divObj'] = div;
					submenuObjArray[no+1]['ulObj'] = sub;
					submenuObjArray[no+1]['width'] = sub.offsetWidth;
					submenuObjArray[no+1]['left'] = div.style.left.replace(/[^0-9]/g,'');
				}
				sub.style.left = 1 - sub.offsetWidth + 'px';	
				
				if(document.all)div.style.width = '1px';	
					
				if(navigator.userAgent.indexOf('Opera')<0){
					submenuObjArray[no+1] = new Array();
					submenuObjArray[no+1]['parentDiv'] = mainMenuItemArray[no];
					submenuObjArray[no+1]['divObj'] = div;
					submenuObjArray[no+1]['ulObj'] = sub;
					submenuObjArray[no+1]['width'] = sub.offsetWidth;
					
					
					
					submenuObjArray[no+1]['left'] = div.style.left.replace(/[^0-9]/g,'');
					if(fixedSubMenuWidth)submenuObjArray[no+1]['width'] = fixedSubMenuWidth;
				}	

				if(!document.all)div.style.width = '1px';			
					
			}			
		}
			

		
		
		menuObj.style.visibility = 'visible';
		
		window.onresize = resetPosition;
	}
	
	
//]]>