jQuery.fn.extend({ 
	disableSelection : function () { 
		this.each(function () { 
			this.onselectstart = function () {
				return false;
			}; 
			this.unselectable = "on"; 
			jQuery(this).css('-moz-user-select', 'none'); 
		}); 
	} 
});
var info = {};
if (!document.getBoxObjectFor) {
	document.getBoxObjectFor = function (el) {
		var pos = {};
		pos.x = el.offsetLeft;
		pos.y = el.offsetTop;
		parent = el.offsetParent;
		if (parent !== el) {
			while (parent) {
				pos.x += parent.offsetLeft;
				pos.y += parent.offsetTop;
				parent = parent.offsetParent;
			}
		}
		parent = el.offsetParent;
		while (parent && parent !== document.body) {
			pos.x -= parent.scrollLeft;                   
			if (parent.tagName !== 'TR') {
				pos.y -= parent.scrollTop;
			}
			parent = parent.offsetParent;
		}
		return pos;
	};   
}
var pages =  function (id) {
	var elem = $("#" + id), page;
	if (elem.length) {
		return {
			counter: 0,
			inactiveClass: "inactive",
			init: function () {
				this.pageList = elem.find("div.pageSelector > ul:first");
				page = this;
				this.pages = elem.find("div.pagesContainer > ul > li");
				this.buttons = elem.find("div.pageSelector > ul > li > a").each(function (index) {
						$(this).data("counter", index);
					});
				this.links = elem.find("div.pageLinks > ul > li > a").each(function (index) {
						$(this).data("counter", index);
					});
				this.totalPageCount = this.pages.length - 1;
				elem.delegate("div.pageSelector a, div.pageLinks a", "click", this.switchPage);
				this.prevButton = $("<li><a>&lt;</a></li>").prependTo(this.pageList).find("a").data("counter", -1);
				this.firstButton = $("<li><a>&#124;&lt;</a></li>").prependTo(this.pageList).find("a").data("counter", -2);
				this.nextButton = $("<li><a>&gt;</a></li>").appendTo(this.pageList).find("a").data("counter", this.totalPageCount + 1);
				this.lastButton = $("<li><a>&gt;&#124;</a></li>").appendTo(this.pageList).find("a").data("counter", this.totalPageCount + 2);
				this.firstButtons = this.prevButton.add(this.firstButton);
				this.lastButtons = this.nextButton.add(this.lastButton);
				this.allButtons = this.buttons.add(this.firstButtons).add(this.lastButtons).add(this.links);
				if (typeof elem.disableSelection === "function") {
					elem.find("div.pageSelector > ul > li > a, div.pageSelector > ul > li").disableSelection();
				}
				this.allButtons.eq(0).trigger("click");
				return this;
			},
			switchPage: function (e) {
				var el = $(e.target), nr;
				if (!el.hasClass(page.inactiveClass)) {
					page.allButtons.removeClass(page.inactiveClass);
					nr = parseInt(el.data("counter"), 10);
					if (nr < 0) {
						page.counter = (nr === -2)? 0 : --page.counter;
					} else if (nr > page.totalPageCount) {
						page.counter = (nr === page.totalPageCount + 1)? ++page.counter : page.totalPageCount;
					} else {
						page.counter = nr;
					}
					if (page.counter === 0) {
						page.firstButtons.addClass(page.inactiveClass);
					} else if (page.counter === page.totalPageCount) {
						page.lastButtons.addClass(page.inactiveClass);
					}
					if (page.buttons.length) {
						page.buttons.eq(page.counter).addClass(page.inactiveClass); 
					}
					if (page.links.length) {
						page.links.eq(page.counter).addClass(page.inactiveClass);
					}
					page.pages.filter(":visible").not(page.pages.eq(page.counter)).hide();
					page.pages.eq(page.counter).show();
				}
			}
		};
	} else {
		return {
			init: function () {
				return false;
			}
		}
	}
}
var settingsObject = function (settingsContainer, extraOpenObject) {
	var sContainer = $("#" + settingsContainer), eOpen = extraOpenObject, slideTime = 200, sObject, postBack, button, choice, currentOption, extraOpenElem, linkedOption;
	if (sContainer.length) {
		postBackOut = $("input[id*='ActiveButton']:first", sContainer);
		postBackIn = $("input[id*='ClickButton']:first", sContainer);
		return {
			removeLastClick: function () {
				$(".lastClicked", sContainer).removeClass("lastClicked");
			},
			buttonClick: function (elem) {
				if (elem.target.nodeName.toLowerCase() !== "a") {
					button = $(elem.target).parents("a:first");
				} else {
					button = $(elem.target);
				}
				sObject.removeLastClick();
				postBackOut.val(button.attr("class"));
				button.addClass("lastClicked");
				choice = button.parent();
				// get the identifier of the clicked button so we can use it later to show the linked option
				currentOption = button.attr("id").substr(1);
				extraOpenElem  = button.data("extraOpen");
				sObject.slideElements();
			},
			headerClick: function (elem) {
				sObject.removeLastClick();
				button = $(elem.target);
				choice = button.next("div.choose");
				sObject.slideElements();
			},
			slideElements: function () {
				if (extraOpenElem) {
					extraOpenElem.filter(":hidden").slideDown(slideTime);
				}
				if (choice.is(":hidden")) {
					choice.slideDown(slideTime);
				}
				if (currentOption !== undefined) {
					linkedOption = $("#o" + currentOption, sContainer);
					if (linkedOption.length && linkedOption.is(":hidden")) {
						linkedOption.slideDown(slideTime);
					}
				}
				// add or remove the active class to the header for visual feedback
				choice.prev().addClass("active");
				// show and hide the choices div's
				sContainer.data("choices").not(choice).filter(":visible").slideUp(slideTime).prev().removeClass("active");
				// show and hide the option div's
				if (linkedOption !== undefined && linkedOption.length) {
					sContainer.data("options").not(linkedOption).filter(":visible").slideUp(slideTime);
				} else {
					sContainer.data("options").slideUp(slideTime);
				}
				// hide and show the extraOpen divs
				if (extraOpenElem && extraOpenElem.length) {
					extraOpenElem.insertAfter(linkedOption);
					sContainer.data("extraOpen").filter(":visible").not(extraOpenElem).slideUp(slideTime);
				} else {
					sContainer.data("extraOpen").slideUp(slideTime);
				}
				// reset
				choice = undefined;
				linkedOption = undefined;
				extraOpenElem = undefined;
				currentOption = undefined;
			},
			init: function () {
				sObject = this;
				// fill the data objects of the buttons so that later we can easilly open them
				if (typeof eOpen === "object") {
					for (var i in eOpen) {
						if (eOpen.hasOwnProperty(i)) {
							var ar = eOpen[i], target = $("#" + i, sContainer);
							for (var j = 0, len = ar.length; j < len; j++) {
								var elem = $("#" + ar[j], sContainer);
								elem.data("extraOpen", (!elem.data("extraOpen"))?  target: elem.data("extraOpen").add(target));
							}
						}
					}
				}
				sContainer.data("sObject", sObject);
				sContainer.data("choices", $(".choice > .choose", sContainer));
				sContainer.data("options", $(".option", sContainer));
				sContainer.data("extraOpen", $(".extraOpen", sContainer));
				if (typeof sContainer.disableSelection === "function") {
					$("div.choice .header, div.choose a", sContainer).disableSelection();
				}
				// attach the click handler for the container.
				sContainer.delegate(".choose > a", "click", this.buttonClick);
				sContainer.delegate(".header", "click", this.headerClick);
				if (postBackIn.length && postBackIn.val() !== "") {
					$("#" + postBackIn.val(), sContainer).trigger("click");
				}
			}
		};
	} else {
		return {
			init: function () {
				alert("settings can't be initialized at this time, try again later or contact support");
			}
		};
	}
};
var PGHS = {
	pad:25, w:0, h:0, bigOnes: [], smallOnes:  [], tables: [],
	initHS: function(target){
		if(target){
			PGHS.editPage = target;
			var cont = $("div.highslide-container:first");
			cont.find(".highslide-footer, .highslide-header, .highslide-body > div").remove();
			PGHS.smallOnes = cont.find("td.highslide-outline");
			PGHS.tables = cont.find("table");
			PGHS.wrapper = $("#highslide-wrapper-0");
			PGHS.bigOnes = $("#highslide-wrapper-0, #highslide-wrapper-0 div, #highslide-wrapper-0 iframe").css({"margin": 0, "padding": 0});
			PGHS.resizeHS();
			$(window).bind('resize', PGHS.resizeHS);
		}
	},
	resizeHS: function(){
		PGHS.w = info.width-(2*PGHS.pad), PGHS.h = info.height-(2*PGHS.pad);
		PGHS.wrapper.css("left", 15+"px");
		PGHS.smallOnes.css({"width": PGHS.w-20, "height": PGHS.h-20});
		PGHS.tables.css({"width": PGHS.w+20, "height": PGHS.h+20, "left": 0});
		PGHS.bigOnes.css({"width": PGHS.w, "height": PGHS.h, "padding": 0});
		if(typeof(PGHS.editPage) == "object")
			PGHS.editPage.resizeEditBody(PGHS.w,PGHS.h);
	}
};
var maintenance = {
	shown: false,
	whichTab: readCookie('tab'),
	expand: readCookie('expand'),
	switchExpandButtons: function(dir){
		if(!dir) dir = "up";
		if(dir === "up"){
			maintenance.expandUp.css("display","none");
			maintenance.expandDown.css("display", 'inline-block');
		}else{
			maintenance.expandUp.css("display","inline-block");
			maintenance.expandDown.css("display", "none");
		}
	},
	hideButtons: function(){
		if(!maintenance.shown)
			maintenance.buttonTimeOut = setTimeout(function(){maintenance.buttons.hide()},500);			
	},
	showButtons: function(){
		clearTimeout(maintenance.buttonTimeOut);
		if(!maintenance.shown)
			maintenance.buttons.css("display","inline-block");
	},
	up: function(){
		createCookie('expand','false',365);
		maintenance.hideButtons();
		maintenance.shown = false;
		maintenance.switchExpandButtons("up");
		maintenance.content.slideToggle();
		createCookie('expand','false',365);
	},
	down: function(){
		createCookie('expand','true',365);
		maintenance.showButtons();
		maintenance.shown = true;
		maintenance.switchExpandButtons("down");
		maintenance.content.slideToggle();
		createCookie('expand','true',365);
	},
	showTab: function(nr){
		if(typeof(nr) !== "number") nr = 0;
		maintenance.tabs.hide();
		maintenance.tabButtons.removeClass("currentSwitch");
		maintenance.tabs.eq(nr).show();
		maintenance.tabButtons.eq(nr).addClass("currentSwitch");
		createCookie('tab', nr ,365);
	},
	init: function(){
		maintenance.container = $('#maintenance');
		if($('#LogoffButton').length){
			maintenance.container.css("visibility" ,"visible");
			maintenance.container.show();
			maintenance.content = $('#maintenanceContent');
			maintenance.tabs = $(".mTab");
			maintenance.tabButtons = $(".tabSwitch");
			if(maintenance.tabButtons.length){
				maintenance.expandDown = $('#expandOut');
				maintenance.expandUp = $('#expandIn');
				maintenance.expandDown.bind("click", maintenance.down);
				maintenance.expandUp.bind("click", maintenance.up);
				maintenance.container.bind("mouseover", maintenance.showButtons);
				maintenance.container.bind("mouseout", maintenance.hideButtons);
				maintenance.buttons = $('#editButtons').find('a').not('#expandOut, #expandIn');
				maintenance.expandUp.css("cursor" ,'pointer');
				maintenance.expandDown.css("cursor" ,'pointer');
				maintenance.showTab(Number(maintenance.whichTab));
				if(maintenance.expand === "true")
					maintenance.shown = true;
				if(maintenance.shown){
					maintenance.switchExpandButtons("down");
					maintenance.content.show();
				}else{
					maintenance.switchExpandButtons("up");
					maintenance.content.hide();
					maintenance.buttons.hide();
				}
			}else{
				maintenance.content.hide();
			}
		}else{
			maintenance.container.hide();
		}
	}
};
/* SlideShow function */
var PGSlideShow = function (cont) {
	var ssCounter = 0, ssTotal = 0, slideshowClass = 'slideshow';
	var ssContainer = $(cont).addClass(slideshowClass);
	return {
		init: function (f, w, l) {
			if (ssContainer.length) {
				this.links = l;
				this.images = ssContainer.find("img").hide();
				this.hideImages = this.images.not(":first").not(":last");
				if (this.images.length > 1) {
					ssTotal = this.images.length;
					this.fadeTime = this.returnMil(f);
					this.interval = this.fadeTime + this.returnMil(w);
					this.images.first().fadeIn(this.fadeTime);
					if(this.links)
						ssContainer.attr("href",this.links[ssCounter]);
					this.start();
				}
			}
		},
		start: function () {
			var that = this;
			this.timer = setInterval(function () {
				that.fadeEm();
			}, this.interval);
		},
		stop: function () {
			clearInterval(this.timer);
		},
		returnMil: function (inp) {
			var input = Number(inp);
			if (input < 10) {
				input *= 1000;
			}
			return input;
		},
		fadeEm: function () {
			if (ssCounter < ssTotal) {
				this.images.eq(ssCounter++).fadeIn(this.fadeTime);
			} else {
				this.hideImages.hide();
				this.images.last().fadeOut(this.fadeTime);
				ssCounter = 1;
			}
			if(this.links){
				ssContainer.attr("href",this.links[ssCounter-1]);
			}
		}
	};
};
/* mouseover functionality */
$(function () {
	$("a.imageMouseOverButton").live("mouseenter mouseleave", function () {
		if (!$(this).data("mouseoverimages")) {
			$(this).data("mouseoverimages",{
					mo: 		$("img:first", this).attr("src"),
			 		 normal:	$("img:.imageMouseOverImage", this).attr("src")
			 });
		}
		var img = $("img:first", this), moObject = $(this).data("mouseoverimages");
		img.attr("src", ((img.attr("src") == moObject.normal )? moObject.mo : moObject.normal ) );
	});
});
/* Menu functions */
function positionMenuElem(button, subMenu, dir) {
	$(button).show();
	var buttonPos	= $(button).offset();
	var buttonX		= buttonPos.left;
	var buttonY		= buttonPos.top;
	var buttonW		= $(button).outerWidth(true);
	var buttonH		= $(button).outerHeight(true);
	var subH		= $(subMenu).outerHeight(true);
	var subW		= $(subMenu).outerWidth(true);
	var l = 0, t = 0;
	switch (dir) {
		case 't':
			if ((buttonY - subH) < info.scrollY && (buttonY + buttonH + subH + 20) < (info.scrollY + info.height))	dir = 'b';
			break;
		case 'b':
			if ((buttonY + buttonH + subH + 20) > (info.scrollY + info.height) && (buttonY - subH) > info.scrollY) dir = 't';
			break;
		case 'r':
			if ((buttonX + subW + buttonW + 20) > (info.scrollX + info.width) && (buttonX - subW) > info.scrollX) dir = 'l';
			break;
		case 'l':
			if ((buttonX - subW) < info.scrollX && (buttonX + buttonW + subW + 20) > (info.scrollX  + info.width)) dir = 'r';
			break;
	}
	switch (dir) {
		case 't':
			t = (buttonY - subH);
			l = buttonX;
			break;
		case 'b':
			t = (buttonY + buttonH);
			l = buttonX;
			break;
		case 'r':
			t = buttonY;
			l = (buttonX + buttonW);
			break;
		case 'l':
			t = buttonY;
			l = (buttonX - subW);
			break;
	}
	$(subMenu).css({"left": l , "top": t });
}
function cancelHideAll() {
	if (menu.hideTimer !== undefined) {
		clearInterval(menu.hideTimer);
		menu.hideTimer = undefined;
	}
}
function hideAll() {
	cancelHideAll();
	for (var i = 0, len = menu.subMenus.length ; i < len ; i++) {
		menu.subMenus[i].hide();
	}
	if(menu.showSubOnLoad && menu.visibleSubItem)
		menu.visibleSubItem.show();
}
function planHideAll() {
	menu.hideTimer = setInterval(hideAll , menu.hideTimerDur);
}
function howManyParents(ob) {
	var count = 0;
	while (ob.parent) {
		ob = ob.parent;
		count++;
	}
	return count;
}
function getDimensions(){
	info.width = $(window).width();
	info.height = $(window).height();
}
function getScroll() {
	var X,Y;
	if( typeof( window.pageYOffset ) == 'number' ) {
		X = window.pageXOffset;
		Y = window.pageYOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		X = document.body.scrollLeft;
		Y = document.body.scrollTop;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		X = document.documentElement.scrollLeft;
		Y = document.documentElement.scrollTop;
	}
	if( X === undefined)
		X = 0;
	if(Y === undefined)
		Y = 0;
	info.scrollX = X;
	info.scrollY = Y;
}
function getPosition(target){
	var x = 0;
	var y = 0;
	if(target.offsetParent){
		while (target.offsetParent) {
			if (target.offsetLeft)
				x += target.offsetLeft;
			if(target.offsetTop)
				y += target.offsetTop;
			target = target.offsetParent;
		}
	}else if(target.x){
		while (target.parentNode) {
			target = target.parentNode;
			if (target.x) 
				x += target.x;	
			if (target.y)
				y += target.y;
		}
	}
	return [x,y]
}
function object(o) {
    function F() {}
    F.prototype = o;
    return new F();
}
function addEventHandler(node, type, f) {
	if(node.addEventListener) {
 		node.addEventListener(type, f, false);
	}else if (node.attachEvent) {
		node.attachEvent("on" + type, f);
	}else{
		node["on" + type] = f;
	}
}
// function to highlight searchwords
function highlightSearchWords(){
	if(searchWords !== ""){
		var reg = new RegExp(searchWords,"i");
		$(".moduleContent").each(function(){
			replaceSearchWords(this,reg);
		});
	}
}
function replaceSearchWords(node,reg){
	var replacedSomething = false;
	var content = [];
	var tempContent = node.innerHTML.split(">");
	if(tempContent.length){
		for(var i = 0, len = tempContent.length ; i < len ; i++){
			var a = tempContent[i].split("<");
			content[content.length] = {html:a[0], node:a[1]};
		}
	}
	for(var i = 0, len = content.length ; i < len ; i++){
		var replacedlocal = false;
		replacedString = new String();
		var searchString = content[i]["html"];
		while(reg.test(searchString)){
			replacedlocal = true;
			replacedString += RegExp.leftContext+"<span class='searchHighlight'>"+RegExp.lastMatch+"</span>";
			searchString = RegExp.rightContext;
		}
		if(replacedlocal){
			replacedSomething = true;
			replacedString += RegExp.rightContext;
			content[i]["html"] = replacedString;
		}
	}
	if(replacedSomething){
		var replacedHTML = new String();
		for(var i = 0 , len = content.length; i < len ; i++){
			replacedHTML += content[i]["html"]+"<"+content[i]["node"]+">";
		}
		node.innerHTML = replacedHTML;
	}
}
// function to get elements by classname for speed this function needs an element type.
function getElementsByClassName(tag, name) {
	var elemements = document.getElementsByTagName(tag);
	var rightElements = [];
	var len = elemements.length;
	for(var i = 0 ; i < len ; i++ ){
		var tempElem = elemements[i].className.split(" ");
		var elemLen = tempElem.length;
		if (elemLen > 1){
			for( var j = 0 ; j < elemLen ; j++){
				if (tempElem[j]=== name)
					rightElements[rightElements.length] = elemements[i];
			}
		}else{
			if(elemements[i].className === name) 
				rightElements[rightElements.length] = elemements[i]; 
		}		
	}
	return rightElements;
}
//function to clean up empty <tr>'s that sometimes end up in the DOM due to not placing right or left colums
function deleteEmptyRows(){
	var trs = document.getElementsByTagName("tr");
	var len = trs.length;
	for(var i = len-1 ; i >= 0 ; i--){
		var tempNode = trs[i];
		if( tempNode.childNodes.length === 0 || (tempNode.childNodes.length === 1 && tempNode.firstChild.nodeType === 3))
			tempNode.parentNode.removeChild(tempNode);
	}
}
//function to add a class to a node
function addClass(node,string){
	var tempClasses = node.className;
	var nodeClasses = tempClasses.split(" ");
	var finalClasses = [];
	var len = nodeClasses.length;
	for (var i = 0; i < len ; i++){
		if (nodeClasses[i] !== string)
			finalClasses[finalClasses.length] = nodeClasses[i];
	}
	if (finalClasses.length === nodeClasses.length)
		finalClasses[finalClasses.length] = string;
	var returnClasses = finalClasses.join(" ");
	node.className = returnClasses;
}
// get the "computed" style, the value thats set in style definitions (CSS or <style>), takes a node and the type of style
function getStyle(node,type){
	var nodeStyle;
	if (element.currentStyle)
		nodeStyle = node.currentStyle[type];
	else if (window.getComputedStyle)
		nodeStyle = document.defaultView.getComputedStyle(node,null).getPropertyValue(type);
	return nodeStyle;
}
// COLOR CONVERSION FUNCTIONS
// decimal --> hexidecimal
function d2h(d){
	return d.toString(16);
}
// hexidecimal --> decimal 
function h2d(h){
	return parseInt(h,16);
}
// get an array returned with the seperate rgb values ( [r,g,b] ), takes a hexidecimal value
function getRGBValues(input){	
	var rgb = h2d(cleanUpHexValue(input));
	return [ (rgb >> 16) & 0xFF , (rgb >> 8) & 0xFF ,rgb & 0xFF ];
}
// formats a hex value so that its unifrm for formating
function cleanUpHexValue(input){
	var hex = (input.indexOf("#") !== -1 ) ? input.replace(/\D/,'') : input;
	if(hex.length === 3){
		var s = hex.split("");
		hex = s[0]+s[0]+s[1]+s[1]+s[2]+s[2];
	}
	return hex;
}
//COOKIES
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name) {
	createCookie(name,"",-1);
}
// XML reader functions
function getXMLData(target){
	var returnXMLObject;
	var parseSource = target;
	if(parseSource){
		returnXMLObject = parseXML(parseSource);
	}
	return returnXMLObject;
}
function parseXML(text){
    if (typeof DOMParser != "undefined") {
        return new DOMParser().parseFromString(text, "application/xml");
    }else if (typeof ActiveXObject != "undefined") {
		var XML = new ActiveXObject("Microsoft.XMLDOM");
        XML.loadXML(text);
        return XML;
    }else {
        var url = "data:text/xml;charset=utf-8," + encodeURIComponent(text);
        var request = new XMLHttpRequest();
        request.open("GET", url, false);
        request.send(null);
        return request.responseXML;
    }
}
//
function IsNumeric(strString){
   //  check for valid numeric strings	
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
}


function CuralisSubmit(){
	if (event.keyCode == 13){
		event.keyCode=9;	
        return false;
	}
	else{
		return true;
	}
}

function CuralisValidate(InputType, ElementId){
	var d,x;  if(!d) d=document; 
	x=d.getElementById(ElementId.id);
	if( x.value.length > 0){
		var i;
		i = ElementId.id.indexOf("txt");
		if  (i != -1){
			var Id=x.id.substring(i+4);
			if( ( typeof MinValue[Id] != 'undefined') &&  (typeof MaxValue[Id] != 'undefined' ) && (MinValue[Id] != MaxValue[Id])){
				if (IsNumeric(x.value)){
					if (x.value < MinValue[Id] || x.value > MaxValue[Id]){
						alert("De waarde moet tussen " + MinValue[Id] + " en " + MaxValue[Id] + " liggen.");
						x.focus();
					}					
				}
				else{
					alert("U moet een getal invullen.");
					x.focus();
				}				
			}
		}
		if (ElementId.id.indexOf("date") != -1){
			if (x.value.length != 0 && !isDate(x.value)){
				x.focus();
			}
		}
	}
}

var dtCh= "-";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("De datum moet voldoen aan : dd-mm-jjjj")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Voer a.u.b. een geldige maand in")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Voer a.u.b. een geldige dag in")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Voer een jaartal tussen "+minYear+" en "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Voer een geldige datum in")
		return false
	}
return true
}


function toggleLayer(whichLayer){
	if (document.getElementById){
	// this is the way the standards work
	var style2 = document.getElementById(whichLayer).style;
	style2.display = style2.display? "":"block";
	}
	else if (document.all){
	// this is the way old msie versions work
	var style2 = document.all[whichLayer].style;
	style2.display = style2.display? "":"block";
	}
	else if (document.layers){
	// this is the way nn4 works
	var style2 = document.layers[whichLayer].style;
	style2.display = style2.display? "":"block";
	}
}

function pausecomp(millis){
var date = new Date();
var curDate = null;

do { curDate = new Date(); } 
while(curDate-date < millis);
} 

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_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_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_changeProp(objName,x,theProp,theValue) { //v3.0
	var obj = MM_findObj(objName);
	if (obj && (theProp.indexOf("style.")==-1 || obj.style)) eval("obj."+theProp+"='"+theValue+"'");
	}
function Closewin(){
	parent.close();
}			
function PrintVersion() { //v4.0
	theSelect=document.getElementById("ReturnToNormal");
	if (theSelect != undefined) {
		theSelect.style.display = "block";
	}
	theSelect=document.getElementById("TopPane");
	if (theSelect != undefined) {
		theSelect.style.display = "none";
	}
	theSelect=document.getElementById("leftcolumn");
	if (theSelect != undefined) {
		theSelect.style.display = "none";
	}
	theSelect=document.getElementById("rightcolumn");
	if (theSelect != undefined) {
		theSelect.style.display = "none";
	}
} 
function returnToNormal() {
	theSelect=document.getElementById("ReturnToNormal");
	if (theSelect != undefined) {
		theSelect.style.display = "none";
	}
	theSelect=document.getElementById("TopPane");
	if (theSelect != undefined) {
		theSelect.style.display = "block";
	}
	theSelect=document.getElementById("leftcolumn");
	if (theSelect != undefined) {
		theSelect.style.display = "block";
	}				
	theSelect=document.getElementById("rightcolumn");
	if (theSelect != undefined) {
		theSelect.style.display = "block";
	}
} 
/* Kalender popup*/
var popUp;

function OpenCalendar(idname, postBack){
		popUp = window.open('Controls/Calendar.aspx?history=false&formname=' + document.forms[0].name + '&id=' + idname + '&selected=' + document.forms[0].elements[idname].value + '&postBack=' + postBack, 'popupcal', 'width=310,height=380,left=200,top=250');
}


function SetDate(formName, id, newDate, postBack){
    eval('var theform = document.' + formName + ';');
	popUp.close();
	theform.elements[id].value = newDate;
	theform.elements[id].focus();
	if (postBack)
		__doPostBack(id,'');
}
function PopupParentPostback(formName, id, postBack){
	eval('var theform = document.' + formName + ';');
	popUp.close()	
	__doPostBack(id,'');
}
function SetDate2(formName, id, newDate, postBack){
	eval('var theform = document.' + formName + ';');
	Popup2.close();	
	theform.elements[id].value = newDate;
	theform.elements[id].focus();
	if (postBack)
		__doPostBack(id,'');
}

function SetParentValues(formName, id1, Value1, id2, Value2, postBack){
	eval('var theform = document.' + formName + ';');
	popUp.close();
	theform.elements[id1].value = Value1;
	theform.elements[id2].value = Value2;
	theform.elements[id1].focus();
	if (postBack)
		__doPostBack(id1,'');
}

function HelpPopUp (URL){
	if(!URL) URL = "http://help.pgportal.nl/";
	var opt = "toolbar=0,scrollbars=1,directories=0,location=0,statusbar=0,menubar=0,resizable=1,status=0";
    opt += ",width=" + String(info.width);
    opt += ",height=" + String(info.height);
    opt += ",left=0,top=0";
    var helpWindow = window.open(URL, "Helpme", opt);
    helpWindow.focus();
}

function HowtoPopUp (URL){   
    window.open(URL, 'Howtooo', 'toolbar=0,scrollbars=1,directories=0,location=0,statusbar=0,menubar=0,resizable=1,status=1,width=806,height=570,left=0,top=0');
}
function HowtoMoviePopUp (URL){   
    window.open(URL, 'HowtoMoviePopUp', 'toolbar=0,scrollbars=0,directories=0,location=0,statusbar=0,menubar=0,resizable=0,status=0,width=790,height=550,left=100,top=100');
}
/* SMOELENBOEK */

var smoelenBoekImagesCount =  48;
var smoelenBoekImagesArray = new Array();

function showMeThisOne(_personsPic,_personsTitle,_personsDescription){
	var personPicTarget = document.getElementById("SmoelenBoekBigPicContainer");
	var oldTitle = document.getElementById("SmoelenBoekTitle");
	var oldDescription = document.getElementById("SmoelenBoekDescription");
	var smoelenBoek = document.getElementById("SmoelenBoek");
	personPicTarget.src = _personsPic;
	
	var newTitle = document.createElement('p');
	newTitle.setAttribute('id','SmoelenBoekTitle');
	newTitle.style.fontFamily = "Arial, Helvetica, Verdana, sans-serif";
	newTitle.style.color = "#fff";
	newTitle.style.fontSize = 14+"px";
	newTitle.style.fontWeight = "bold";
	newTitle.style.margin = "18px 30px 3px 30px";
	newTitle.style.padding = 0;
	newTitle.style.width = 'auto';
	var title = document.createTextNode(_personsTitle);
	newTitle.appendChild(title);
	
	var newDescription = document.createElement('p');
	newDescription.setAttribute('id','SmoelenBoekDescription');
	newDescription.style.fontFamily = "Arial, Helvetica, Verdana, sans-serif";
	newDescription.style.color = "#fff";
	newDescription.style.fontSize = 12+"px";
	newDescription.style.margin = "3px 60px 5px 30px";
	newDescription.style.padding = 0;
	newDescription.style.width = 'auto';
	var description = document.createTextNode(_personsDescription);
	newDescription.appendChild(description);
	
	smoelenBoek.replaceChild(newTitle,oldTitle);
	smoelenBoek.replaceChild(newDescription,oldDescription);
}
function generateSmoelenBoek(){
	//alert(smoelenBoekImagesArray);
	var imagesLengthDifference = smoelenBoekImagesCount - smoelenBoekImagesArray.length;
	if (imagesLengthDifference > 0){
	 for ( var i = 0 ; i < imagesLengthDifference ; i++ ){
		 var tempEmptyArray = new Array("","","","","");
		 smoelenBoekImagesArray.push(tempEmptyArray);
	 }
	 for ( var j=0 ; j < smoelenBoekImagesCount ; j++){
		 var getThisOne = Math.floor(Math.random()*(smoelenBoekImagesArray.length-1));
		 addToSmoelenBoek(smoelenBoekImagesArray[getThisOne][1],smoelenBoekImagesArray[getThisOne][0],smoelenBoekImagesArray[getThisOne][2],smoelenBoekImagesArray[getThisOne][3],smoelenBoekImagesArray[getThisOne][4]);
		 smoelenBoekImagesArray.splice(getThisOne,1);
		 }
	 }else{
		 alert("More pictures added than there are picture spots...");
	 }
}
function addToSmoelenBoek(smallPic,bigPic,title,description,url){
	var imagesFolder = "Userdata/contacts/";
	var smoelenboekTarget = document.getElementById("SmoelenBoekPicContainer");
	var SDiv = document.createElement('div');
	SDiv.setAttribute('class', 'SmoelenBoekLink');
	SDiv.style.display = "inline";
	SDiv.style.styleFloat = "right";
	SDiv.style.float = "right";
	var SImg = document.createElement('img');
	SImg.style.border = "none";
	if(bigPic != ""){
		var SA = document.createElement('a');
		
		SImg.setAttribute('src', smallPic);
		SImg.setAttribute('width', '50');
		SImg.setAttribute('height', '69');
		
		SA.setAttribute('href', url);
		//SA.setAttribute('target','blank');
		SA.setAttribute('onMouseOver' , 'showMeThisOne("'+bigPic+'","'+ title+'","'+description+'")');
		SA.onmouseover = function(){
			showMeThisOne(bigPic,title,description);
		}
	
		SDiv.appendChild(SA);
		SA.appendChild(SImg);
	}else{
		SImg.setAttribute('src', imagesFolder+'spacer.gif');
		SImg.setAttribute('width', '50');
		SImg.setAttribute('height', '69');
		SDiv.appendChild(SImg);
	}
	smoelenboekTarget.appendChild(SDiv);
}
function addToImagesArray(BigPic,SmallPic,Title,Description,URL){
 var tempArray = new Array(BigPic,SmallPic,Title,Description,URL);
 //alert("Added to imagesArray = "+ tempArray);
 smoelenBoekImagesArray.push(tempArray);
}
/* /SMOELENBOEK */

// Section added to resolve the Eolas Patent isue, this section will generate the tags in html that embed Flash or Shockwave;
function PGAddExtension(src, ext){
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function PGGenerate(objAttrs, params, embedAttrs){ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function PGEmbedFlash(){
  var ret = 
    PGGetArguments
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  PGGenerate(ret.objAttrs, ret.params, ret.embedAttrs);
}

function PGEmbedShockwave(){
  var ret = 
    PGGetArguments
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  PGGenerate(ret.objAttrs, ret.params, ret.embedAttrs);
}

function PGGetArguments(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = PGAddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}
// ajax call to replace a module with a newly saved one
function newHTTPReq (){
	if (window.ActiveXObject) 
		return new ActiveXObject("Microsoft.XMLHTTP");
	else if (window.XMLHttpRequest) 
		return new XMLHttpRequest();
	else {
		return undefined;
	}	
}
// replace a certain dom element with another
function replaceContent(target,iHTML){
	target.innerHTML = iHTML;
}
// for every AJAX call a newAJAX object is needed
var newAJAX = function(argObject){
	// make vars
	var Ob = {};
	Ob.argString = '';
	// occupy vars
	Ob.url = argObject.url;
	Ob.target = argObject.target;
	// show waiting text
	replaceContent(Ob.target, "<div class='module replacing'>module is being updated</div>" );
	// combine vars into a GET-vars to pass to Ob.url
	for(i in argObject.vars){
		Ob.argString += (Ob.argString !== '') ? "&" : "?" ;
		Ob.argString += i +"="+  argObject.vars[i];
	}
	// combine url and vars to get the Ob.url + Ob.vars to send with Ob.AJAX later
	Ob.url += Ob.argString;
	// make AJAX component
	Ob.AJAX = newHTTPReq();
	if (Ob.AJAX){
		/* output */
		Ob.outPut = function(){
			if (Ob.AJAX.readyState == 4){
				var bla = cleanupHTML(argObject, Ob.AJAX.responseText);
				replaceContent(Ob.target, bla);
			}
		};
		/* send */
		Ob.AJAX.open('GET', Ob.url, true);
		Ob.AJAX.send(null);
		Ob.AJAX.onreadystatechange = function(){
			Ob.outPut();
		};
		return Ob;
	}else{
		return undefined;	
	}
};
function replaceModule(moduleId){
    var url = "HSModule.aspx";
	var elem = document.getElementById("HS_" + moduleId);
	var moduleReplace = {
		target 	:	elem	,
		url		:	url		,
		vars	:	{ mId : moduleId }
	};
	newAJAX(moduleReplace);
}
function cleanupHTML(argObject , markUp){
	var searchMId = argObject.target.id;
	var temp = markUp.split(searchMId);
	var temp2 = temp[1].split("</form>");
	tempMarkUp = '<div id="' + argObject.target.id + temp2[0];
	return tempMarkUp;
}