/* * * * * * * * * * * * * * * * * * * * * * *
 *   C A R E N Z A  S C R I P T  F I L E     *
 *                                           *
 *   (c) Copyright 2009 - CARENZA            *
 *   http://www.carenza.nl/                  *
 *                                           *
 * * * * * * * * * * * * * * * * * * * * * * */


function checkContactForm() {
	return (csscheck('naam', '') + csscheck('mail','mail') + csscheck('mssg','')) == 0;
}

function checkNewsForm() {
	return (csscheck('naam', '') + csscheck('mail','mail')) == 0; // mail, post, phone or other
}

function csscheck(inputId, type) {
	var failCSS = 'invalid';
	if(check(inputId,type)) {
		document.getElementById(inputId).className = 'goodCSS';
		return 0;
	} else {
		document.getElementById(inputId).className = 'failCSS';
		document.getElementById(inputId).onkeyup = new Function("csscheck('"+inputId+"', '"+type+"');");
		return 1;
	}
}

function check(inputId, type) {
	var elem = document.getElementById(inputId);
	var v = elem.value;
	switch (type) {
		
		case 'mail':
			var atIndex = v.indexOf('@');
			var dotIndex = v.lastIndexOf('.');
			return !(atIndex < 1 || atIndex>=(v.length-2) || dotIndex < 1 || dotIndex>=(v.length-2) || atIndex > dotIndex - 1);
		case 'phone':
			var re = new RegExp('[^\\d]', "g");
			v = v.replace(re, "");
			if( parseInt(v,10) >= 100000000 && parseInt(v,10) <= 800000000 ) {
				v = '0' + parseInt(v,10);
				// id.value = v;
				return true;
			}
			return false;
		
		case 'postc':
			var re = new RegExp('(\\d{4})[\\s]*?([A-Z]{2}).*', "i");
			v = v.replace(re, "$1$2");
			v = v.toUpperCase();
			// id.value = v;
			return (v.length == 6 && re.test(v));
		
		default:
			var length = v.length;
			return (length >= 2);
	}

}


window.onload = function () {
	
	var submenu = document.getElementById("submenu");
	
	if(links = document.getElementById("menu").getElementsByTagName("a")) {
		loc1 = location.href.lastIndexOf("/");
		loc2 = location.href.lastIndexOf("/",loc1-1);
		foldername = location.href.substring(loc2+1,loc1);
		filename = location.href.substring(loc1+1);
		
		for (var i=0; i<links.length; i++) {
			if (links[i].href.substring(links[i].href.lastIndexOf("/"),links[i].href.lastIndexOf("/",links[i].href.lastIndexOf("/")-1)+1) == foldername) {
				links[i].className = "active";
			}
		}
	}
	if(submenu) {
		links2 = submenu.getElementsByTagName("a");
		for (var i=0; i<links2.length; i++) {
			if (links2[i].href.substring(links2[i].href.lastIndexOf("/")+1) == filename) {
				links2[i].className = "active";
			}
		}
	}
}