

var agt=navigator.userAgent.toLowerCase();
var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_win    = ((agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
var is_mac    = (agt.indexOf("mac")!=-1);
var is_opera  = (agt.indexOf("opera") != -1);
var is_konq   = (agt.indexOf("konquer") != -1);


var thumbnail_prefix = '_th';

window.onload = function(){

	if (self.innerHeight){ // all except Explorer
		browser_pix = "px";
	}
	else{ // Explorers
		browser_pix = "";
	}

    if (is_ie && is_mac) {
		window.onresize = setHeight;
		setHeight(); 
	}

	links = document.getElementsByTagName("a");
	var index = 0;

	document.previews = new Array();

	for (i=0; i<links.length; i++) {
		link = links[i];
		link.onfocus=function(){
			this.blur();
		}
		
		if(img = link.getElementsByTagName('img')[0]){
			if(link.href == img.src.replace(thumbnail_prefix,'')){
				link.onclick = show_preview;
				link.index = index;
				document.previews[index] = link;
				index++;
			}			
		}
	}

	init_tabcontrol();	
	init_forms();
}
    


var preview = new Object();

function show_preview(obj){
	if(this.tagName) obj = this;
	
	if (document.getElementById('preview')){
		document.body.style.cursor = 'wait';
		
		preview.trigger = obj;
		preview.div = document.getElementById('preview');

		preview.mask = document.getElementById('mask');
		preview.mask.onclick =  close_img;

		preview.title = obj.getAttribute("title")	
		preview.Img = new Image();
				
		if (preview.Img.attachEvent){
			preview.Img.attachEvent("onload" , preview_onload);
		}
		else if(preview.Img.addEventListener){
			preview.Img.addEventListener("load", preview_onload, false);
		}
		else{
			preview.noevent = true;
		}

		preview.Img.src = obj.href;
		preview.mask.style.display = "";	
	
		if(preview.noevent){
			if(! preview.imgnode){
				var imgnode = document.createElement("img");
				imgnode.style.display = "none";
				preview.imgnode = document.body.appendChild(imgnode);
			}
			
			preview.imgnode.onload = preview_onload;
			preview.imgnode.src = this.href;
		}

		return false;
	}
	else{	
		return true;
	}
}

function preview_onload(){
	var title = "klik voor de volgende afbeelding";

	preview.div.style.marginTop = (- preview.Img.height/2 ) + browser_pix;
	var width = preview.Img.width + 22 + (is_ie ? 2 : 0);
	
	preview.div.style.width = width + browser_pix ;
	preview.div.style.marginLeft =  - width / 2 + browser_pix;

	html = "<img src=\"" + preview.Img.src + "\" title = \"" + title + "\" alt=\"" + title + "\" onclick=\"next_img()\" />" +
		"<p>" + preview.title + "</p>" +
		"<div class=\"controls\">" +
		"<span id=\"previous_img\" onclick=\"previous_img()\" title=\"vorige\">&laquo; </span>" +
		"<span id=\"close_img\" onclick=\"close_img()\" title=\"sluiten\"> sluit </span>" +
		"<span id=\"next_img\" onclick=\"next_img()\" title=\"volgende\"> &raquo;</span>" +
		"</div>";

	preview.div.innerHTML = html;
	preview.div.style.display = "";	

	document.body.style.cursor = 'default';
}

function close_img(){
	preview.div.style.display = "none";	
	preview.div.innerHTML = "";	
	preview.mask.style.display = "none";
	document.body.style.cursor = 'default';
}

function next_img(){
	current = preview.trigger.index;
	next =  current + 1 < document.previews.length ? current + 1 : 0;
	show_preview(document.previews[next]);
}

function previous_img(){
	current = preview.trigger.index;
	next = current - 1 >= 0 ? current -1 : document.previews.length - 1;
	show_preview(document.previews[next]);
}


function setHeight (){
	subMarPad = 275; /* the total value of margins and padding to subtract from the body height */
	mainDiv = document.getElementById('main');
	mainDiv.style.top = (parseInt(document.body.clientHeight)/2 - subMarPad) + "px";
	mainDiv.style.visibility = "visible";
}


//SCRIPT OM CONTENTBLOKKEN TE TOGLEN
function init_tabcontrol(){
	var tabcontrol = document.getElementById("tabcontrol");
	if(tabcontrol){
		var tabs = tabcontrol.getElementsByTagName("DT");
		var pages = tabcontrol.getElementsByTagName("DD");
		
		for(n=0; n<tabs.length; n++){
			tab = tabs[n];		
			tab.parent = tabcontrol;
			tab.page = pages[n];
			tab.page.className = "hidden";
			tab.onmouseover = mouse_over;
			tab.onmouseout = mouse_out;
			tab.onfocus = link_blur;
			tab.onclick = tabclick;
		}
		
		tabcontrol.activetab = tabs[0];
		tabs[0].className ="active";
		pages[0].className = "display";
	}
}

function tabclick(){
	var currenttab = this.parent.activetab;
	currenttab.className = "";
	currenttab.page.className = "hidden";

	currenttab.onmouseover = mouse_over;
	currenttab.onmouseout = mouse_out;

	this.parent.activetab = this;

	this.onmouseover = '';
	this.onmouseout = '';

	currenttab = this.parent.activetab;
	currenttab.className = "active";
	currenttab.page.className = "display";
}

//MAILSCRIPT & VALIDATIE

function init_forms(){
	var forms = document.getElementsByTagName("form");

	for(n=0; n<forms.length; n++){
		var form = forms[n];
		form.onsubmit = form_submit;
	}
}

function form_submit(){
	this.valid = true;
	
	var elems = this.elements;
	for(n=0; n<elems.length && this.valid; n++){
		elem = elems[n];
		
		
			var validation = elem.getAttribute("required");

			switch(validation){
				case "true":
					if(elem.value.trim().length == 0){
						this.valid = false;
						elem.select();
						elem.className += " invalid";
						//wndow.status = elem.getAttribute("onvalidate");
					}
					else{
						elem.className =  elem.className.replace(/invalid/g ,"");
						//window.status = "";
					}
					break;

				case "email":
					if(is_email(elem.value)){
						this.valid = false;
						elem.select();
						elem.className += " invalid";
						//wndow.status = elem.getAttribute("onvalidate");
					}
					else{
						elem.className =  elem.className.replace(/invalid/g ,"");
						//window.status = "";
					}
					break;

				default:
					break;
			}
		
	}

	return this.valid;
}


function is_email(email){
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return ! (!r1.test(email) && r2.test(email));	
}

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };



function link_blur(){
	this.blur();
}

function mouse_over(){
	this.className = this.className + " hover";	
}

function mouse_out(){
	this.className = this.className.replace(/hover/g,"")
}

