// -- Controleren gegevens


function isValidURL(url){
    var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
    if(RegExp.test(url)){
        return true;
    }else{
        return false;
    }
}

function isValidEmail(email){
    var RegExp = /^((([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.))*([a-z]|[0-9])([a-z]|[0-9]|\-){0,61}([a-z]|[0-9])\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/
    if(RegExp.test(email)){
        return true;
    }else{
        return false;
    }
} 




function checkContact(text) {



	document.getElementById('contact_error_org').style.display = 'none';
	clearElement('contact_error_org');

	document.getElementById('contact_error_bericht').style.display = 'none';
	clearElement('contact_error_bericht');

	
	var naam_error=false;		
	var org_error=false;
	var tel_error=false;
	var mob_error=false;	
	var email_error=false;	
	var onderwerp_error=false;	
	var tekst_error=false;	
	var error_org = false;
	var error_bericht = false;

	if(document.contactformulier.contact_naam.value=='') {
		document.contactformulier.contact_naam.className = document.contactformulier.contact_naam.className + " error";
		naam_error=true;		
	} 
	if(document.contactformulier.contact_orga.value=='') {
		document.contactformulier.contact_orga.className = document.contactformulier.contact_orga.className + " error";
		org_error=true;
	}
	/*
	if(document.contactformulier.contact_tel.value=='') {
		document.contactformulier.contact_tel.className = document.contactformulier.contact_tel.className + " error";
		tel_error=true;
	}
	
	if(document.aanmeldformulier.contact_mob.value=='') {
		document.contactformulier.contact_mob.className = document.contactformulier.contact_mob.className + " error";
		mob_error=true;	
	}
	*/
	if(!isValidEmail(document.contactformulier.contact_email.value)) {
		document.contactformulier.contact_email.className = document.contactformulier.contact_email.className + " error";
		email_error=true;	
	}

	if(document.contactformulier.contact_onderwerp.value=='') {
		document.contactformulier.contact_onderwerp.className = document.contactformulier.contact_onderwerp.className + " error";
		onderwerp_error=true;
	}

	if(document.contactformulier.contact_tekst.value=='') {
		document.contactformulier.contact_tekst.className = document.contactformulier.contact_tekst.className + " error";
		tekst_error=true;
	}

	

	if(naam_error || org_error || tel_error || mob_error || email_error) {
		document.getElementById('contact_error_org').style.display = 'block';

		insertElement(text[7], 'p', '', '', 'contact_error_org', '', '');
		insertElement('', 'ul', 'contact_error_org_ul', '', 'contact_error_org', '', '');

		if(naam_error) {
			insertElement(text[0], 'li', '', 'error', 'contact_error_org_ul', '', 0);
		}
		if(org_error) {
			insertElement(text[1], 'li', '', 'error', 'contact_error_org_ul', '', 0);
		}
		if(email_error) {
			insertElement(text[2], 'li', '', 'error', 'contact_error_org_ul', '', 0);
		}
		/*
		if(tel_error) {
			insertElement(text[3], 'li', '', 'error', 'contact_error_org_ul', '', 0);
		}
		if(mob_error) {
			insertElement(text[4], 'li', '', 'error', 'contact_error_org_ul', '', 0);
		}
		*/
		
		document.getElementById('contact_orga').scrollIntoView(true);
		error_org = true;
	}  else if(tekst_error || onderwerp_error) {
		document.getElementById('contact_error_bericht').style.display = 'block';

		insertElement(text[7], 'p', '', '', 'contact_error_bericht', '', '');
		insertElement('', 'ul', 'contact_error_bericht_ul', '', 'contact_error_bericht', '', '');

		if(onderwerp_error) {
			insertElement(text[5], 'li', '', 'error', 'contact_error_bericht_ul', '', 0);
		}
		if(tekst_error) {
			insertElement(text[6], 'li', '', 'error', 'contact_error_bericht_ul', '', 0);
		}
		document.getElementById('contact_error_bericht').scrollIntoView(true);
		error_bericht = true;

	}

	if(error_org || error_bericht) {
		return false;
	} else {
		return true;
	}
}




function clearClassFormElements(div) {
    if(div) {
        elements = document.getElementById(div);
    } else {
        elements = document;
    }
	if(elements.getElementsByTagName('form')) {
	    
		/* list all input elements in a form */
		var input = elements.getElementsByTagName('input');
		
		for (var i=0;i<input.length;i++) { 
			/* all list elements in array */
			var formelement = input[i];
			addEvent(formelement, 'change', function() {
				if(this.className == 'error') {
					this.className = '';
				}
				
			});
			if(div) {
			   if(formelement.className == 'error') {
					formelement.className = '';
				} 
			}
			
		}
		var select = elements.getElementsByTagName('select');
		for (var i=0;i<select.length;i++) { 
			/* all list elements in array */
			var formelement = select[i];
			addEvent(formelement, 'change', function() {
				if(this.className == 'error') {
					this.className = '';
				}
			});
			if(div) {
			   if(formelement.className == 'error') {
					formelement.className = '';
				} 
			}
		}
		var textarea = elements.getElementsByTagName('textarea');
		for (var i=0;i<textarea.length;i++) { 
			/* all list elements in array */
			var formelement = textarea[i];
			addEvent(formelement, 'change', function() {
				if(this.className == 'error') {
					this.className = '';
				}
			});
			if(div) {
			   if(formelement.className == 'error') {
					formelement.className = '';
				} 
			}
		}
	}
}




/* add event function */
function addEvent(element, type, handler) {
    // assign each event handler a unique ID
    if (!handler.$$guid) handler.$$guid = addEvent.guid++;
    // create a hash table of event types for the element
    if (!element.events) element.events = {};
    // create a hash table of event handlers for each element/event pair
    var handlers = element.events[type];
    if (!handlers) {
        handlers = element.events[type] = {};
        // store the existing event handler (if there is one)
        if (element["on" + type]) {
            handlers[0] = element["on" + type];
        }
    }
    // store the event handler in the hash table
    handlers[handler.$$guid] = handler;
    // assign a global event handler to do all the work
    element["on" + type] = handleEvent;
};
// a counter used to create unique IDs
addEvent.guid = 1;

function removeEvent(element, type, handler) {
    // delete the event handler from the hash table
    if (element.events && element.events[type]) {
        delete element.events[type][handler.$$guid];
    }
};

function handleEvent(event) {
    // grab the event object (IE uses a global event object)
    event = event || window.event;
    // get a reference to the hash table of event handlers
    var handlers = this.events[event.type];
    // execute each event handler
    for (var i in handlers) {
        this.$$handleEvent = handlers[i];
        this.$$handleEvent(event);
    }
};

function insertElement(text, objType, objID, objClass, objParent, objSibling, numOfNodes) {
	// if the object doesnt exsist yet
	if(!document.getElementById(objID)) {
	// create an element with the objType
	var objElement = document.createElement(objType);
		// if there is an id, assign it to the element
		if(objID) 		
			objElement.setAttribute('id', objID);
		// if there is an class, assign it to the element
		if(objClass)
			objElement.className = objClass;
		// if there is any text, insert it into the element
		if(text)
			objElement.innerHTML = text;

		// insert the element inside an other element
		objParent = document.getElementById(objParent);
		if(objParent) {
			objParent.appendChild(objElement);
		}
		// insert the element after an other element
		objSibling = document.getElementById(objSibling);
		if(objSibling) {
			if(numOfNodes>0) {
                for(var n=0; n<numOfNodes; n++) {
	                objSibling = objsibling.nextSibling;
                }
			}
			objSibling.parentNode.insertBefore(objElement, objSibling.nextSibling );
		}
	}
}


function clearElement(element) {
    document.getElementById(element).innerHTML = '';
}
	

function disappear(element, opacity) {
    element = document.getElementById(element); 
	var reduce_opacity_by = 15;
	var rate = 30;	// 15 fps
	
	if (opacity > 0) {
		opacity -= reduce_opacity_by;
		if (opacity < 0) opacity = 0;
		
		if (element.filters) {
			try {
				element.filters.item("DXImageTransform.Microsoft.Alpha").opacity = opacity;
			} catch (e) { 
				// If it is not set initially, the browser will throw an error.  This will set it if it is not set yet.
				element.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + opacity + ')';
			}
		} else {
			element.style.opacity = opacity / 100;
		}
	}
	

	if(opacity > 0) {
		setTimeout(function() { disappear(element.id, opacity); }, rate);
	} else {
		element.style.display = "none";
	}
}


/*
	Developed by Robert Nyman, http://www.robertnyman.com
	Code/licensing: http://code.google.com/p/getelementsbyclassname/
*/	
var getElementsByClassName = function (className, tag, elm){
	if (document.getElementsByClassName) {
		getElementsByClassName = function (className, tag, elm) {
			elm = elm || document;
			var elements = elm.getElementsByClassName(className),
				nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
				returnElements = [],
				current;
			for(var i=0, il=elements.length; i<il; i+=1){
				current = elements[i];
				if(!nodeName || nodeName.test(current.nodeName)) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	else if (document.evaluate) {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = "",
				xhtmlNamespace = "http://www.w3.org/1999/xhtml",
				namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,
				returnElements = [],
				elements,
				node;
			for(var j=0, jl=classes.length; j<jl; j+=1){
				classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
			}
			try	{
				elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
			}
			catch (e) {
				elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
			}
			while ((node = elements.iterateNext())) {
				returnElements.push(node);
			}
			return returnElements;
		};
	}
	else {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = [],
				elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
				current,
				returnElements = [],
				match;
			for(var k=0, kl=classes.length; k<kl; k+=1){
				classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
			}
			for(var l=0, ll=elements.length; l<ll; l+=1){
				current = elements[l];
				match = false;
				for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
					match = classesToCheck[m].test(current.className);
					if (!match) {
						break;
					}
				}
				if (match) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	return getElementsByClassName(className, tag, elm);
};


function showTitle(element) {
	elements = getElementsByClassName('projecttitle', 'p', element);
	elements[0].style.display = 'block';
}

function hideTitle(element) {
	elements = getElementsByClassName('projecttitle', 'p', element);
	elements[0].style.display = 'none';
}

/**
 * SWFObject v2.0: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2006 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept == "undefined") var deconcept = new Object();
if(typeof deconcept.util == "undefined") deconcept.util = new Object();
if(typeof deconcept.SWFObjectUtil == "undefined") deconcept.SWFObjectUtil = new Object();
deconcept.SWFObject = function(swf, id, w, h, ver, c, quality, xiRedirectUrl, redirectUrl, detectKey) {
	if (!document.getElementById) { return; }
	this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
	this.skipDetect = deconcept.util.getRequestParameter(this.DETECT_KEY);
	this.params = new Object();
	this.variables = new Object();
	this.attributes = new Array();
	if(swf) { this.setAttribute('swf', swf); }
	if(id) { this.setAttribute('id', id); }
	if(w) { this.setAttribute('width', w); }
	if(h) { this.setAttribute('height', h); }
	if(ver) { this.setAttribute('version', new deconcept.PlayerVersion(ver.toString().split("."))); }
	this.installedVer = deconcept.SWFObjectUtil.getPlayerVersion();
	if (!window.opera && document.all && this.installedVer.major > 7) {
		// only add the onunload cleanup if the Flash Player version supports External Interface and we are in IE
		deconcept.SWFObject.doPrepUnload = true;
	}
	if(c) { this.addParam('bgcolor', c); }
	var q = quality ? quality : 'high';
	this.addParam('quality', q);
	this.setAttribute('useExpressInstall', false);
	this.setAttribute('doExpressInstall', false);
	var xir = (xiRedirectUrl) ? xiRedirectUrl : window.location;
	this.setAttribute('xiRedirectUrl', xir);
	this.setAttribute('redirectUrl', '');
	if(redirectUrl) { this.setAttribute('redirectUrl', redirectUrl); }
}
deconcept.SWFObject.prototype = {
	useExpressInstall: function(path) {
		this.xiSWFPath = !path ? "expressinstall.swf" : path;
		this.setAttribute('useExpressInstall', true);
	},
	setAttribute: function(name, value){
		this.attributes[name] = value;
	},
	getAttribute: function(name){
		return this.attributes[name];
	},
	addParam: function(name, value){
		this.params[name] = value;
	},
	getParams: function(){
		return this.params;
	},
	addVariable: function(name, value){
		this.variables[name] = value;
	},
	getVariable: function(name){
		return this.variables[name];
	},
	getVariables: function(){
		return this.variables;
	},
	getVariablePairs: function(){
		var variablePairs = new Array();
		var key;
		var variables = this.getVariables();
		for(key in variables){
			variablePairs.push(key +"="+ variables[key]);
		}
		return variablePairs;
	},
	getSWFHTML: function() {
		var swfNode = "";
		if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
			if (this.getAttribute("doExpressInstall")) {
				this.addVariable("MMplayerType", "PlugIn");
				this.setAttribute('swf', this.xiSWFPath);
			}
			swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'"';
			swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
			var params = this.getParams();
			 for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
			var pairs = this.getVariablePairs().join("&");
			 if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
			swfNode += '/>';
		} else { // PC IE
			if (this.getAttribute("doExpressInstall")) {
				this.addVariable("MMplayerType", "ActiveX");
				this.setAttribute('swf', this.xiSWFPath);
			}
			swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'">';
			swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
			var params = this.getParams();
			for(var key in params) {
			 swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
			}
			var pairs = this.getVariablePairs().join("&");
			if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
			swfNode += "</object>";
		}
		return swfNode;
	},
	write: function(elementId){
		if(this.getAttribute('useExpressInstall')) {
			// check to see if we need to do an express install
			var expressInstallReqVer = new deconcept.PlayerVersion([6,0,65]);
			if (this.installedVer.versionIsValid(expressInstallReqVer) && !this.installedVer.versionIsValid(this.getAttribute('version'))) {
				this.setAttribute('doExpressInstall', true);
				this.addVariable("MMredirectURL", escape(this.getAttribute('xiRedirectUrl')));
				document.title = document.title.slice(0, 47) + " - Flash Player Installation";
				this.addVariable("MMdoctitle", document.title);
			}
		}
		if(this.skipDetect || this.getAttribute('doExpressInstall') || this.installedVer.versionIsValid(this.getAttribute('version'))){
			var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
			n.innerHTML = this.getSWFHTML();
			return true;
		}else{
			if(this.getAttribute('redirectUrl') != "") {
				document.location.replace(this.getAttribute('redirectUrl'));
			}
		}
		return false;
	}
}

/* ---- detection functions ---- */
deconcept.SWFObjectUtil.getPlayerVersion = function(){
	var PlayerVersion = new deconcept.PlayerVersion([0,0,0]);
	if(navigator.plugins && navigator.mimeTypes.length){
		var x = navigator.plugins["Shockwave Flash"];
		if(x && x.description) {
			PlayerVersion = new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
		}
	}else{
		// do minor version lookup in IE, but avoid fp6 crashing issues
		// see http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
		try{
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		}catch(e){
			try {
				var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
				PlayerVersion = new deconcept.PlayerVersion([6,0,21]);
				axo.AllowScriptAccess = "always"; // throws if player version < 6.0.47 (thanks to Michael Williams @ Adobe for this code)
			} catch(e) {
				if (PlayerVersion.major == 6) {
					return PlayerVersion;
				}
			}
			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			} catch(e) {}
		}
		if (axo != null) {
			PlayerVersion = new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
		}
	}
	return PlayerVersion;
}
deconcept.PlayerVersion = function(arrVersion){
	this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0;
	this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0;
	this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0;
}
deconcept.PlayerVersion.prototype.versionIsValid = function(fv){
	if(this.major < fv.major) return false;
	if(this.major > fv.major) return true;
	if(this.minor < fv.minor) return false;
	if(this.minor > fv.minor) return true;
	if(this.rev < fv.rev) return false;
	return true;
}
/* ---- get value of query string param ---- */
deconcept.util = {
	getRequestParameter: function(param) {
		var q = document.location.search || document.location.hash;
		if(q) {
			var pairs = q.substring(1).split("&");
			for (var i=0; i < pairs.length; i++) {
				if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
					return pairs[i].substring((pairs[i].indexOf("=")+1));
				}
			}
		}
		return "";
	}
}
/* fix for video streaming bug */
deconcept.SWFObjectUtil.cleanupSWFs = function() {
	var objects = document.getElementsByTagName("OBJECT");
	for (var i=0; i < objects.length; i++) {
		objects[i].style.display = 'none';
		for (var x in objects[i]) {
			if (typeof objects[i][x] == 'function') {
				objects[i][x] = function(){};
			}
		}
	}
}
// fixes bug in fp9 see http://blog.deconcept.com/2006/07/28/swfobject-143-released/
if (deconcept.SWFObject.doPrepUnload) {
	deconcept.SWFObjectUtil.prepUnload = function() {
		__flash_unloadHandler = function(){};
		__flash_savedUnloadHandler = function(){};
		window.attachEvent("onunload", deconcept.SWFObjectUtil.cleanupSWFs);
	}
	window.attachEvent("onbeforeunload", deconcept.SWFObjectUtil.prepUnload);
}
/* add Array.push if needed (ie5) */
if (Array.prototype.push == null) { Array.prototype.push = function(item) { this[this.length] = item; return this.length; }}

/* add some aliases for ease of use/backwards compatibility */
var getQueryParamValue = deconcept.util.getRequestParameter;
var FlashObject = deconcept.SWFObject; // for legacy support
var SWFObject = deconcept.SWFObject;


this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("tr[href]").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("tr[ahref]").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};



$(document).ready(function() { 
	$("a.fancybox").fancybox({
		'padding':'0px',
		'frameWidth':'490',
		'frameHeight':'440'
	}); 



	$("tr[href]").click(function(){
		window.location.href= $(this).attr('href');
	});
	
	//$("tr[href]").qtip();

	//	$('<input type="text" />').attr({'id':'dothemath', 'style':'position:absolute;top:0;'}).appendTo($('body'));

	//var plus;
	$("div table").hover(function() {
		var tb = $("div table").index(this);
		i = ((tb * 60) + 30);	
		//$('#dothemath').val(i);
		$("tr[href]").hover(function() {
			var tr = $('tr[href]').index(this);
			var yPosition = ((tr * 30) + i);
			$(this).parent().parent().parent().css({'backgroundImage':'url(images/tr_hover_bg.png)', 'backgroundRepeat':'no-repeat', 'backgroundPosition':'0px '+ yPosition +'px'});
		}, function () {
			$(this).parent().parent().parent().css({'backgroundImage':'none'});
		});
	}, function () {
		
	});
	//*/
}); 