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

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 (i == 0 && links[i].href == location.href) { links[i].parentNode.className = "active"; break; }
			//if ( i == 0) alert(links[i].href.length+' '+links[i].href.lastIndexOf("/"));
			if ( i == 0 && links[i].href.lastIndexOf("/") == links[i].href.length - 2) { links[i].parentNode.className = "active"; }
			if (links[i].href.substring(links[i].href.lastIndexOf("/")+1) == filename) {
			//if (links[i].href.substring(links[i].href.lastIndexOf("/"),links[i].href.lastIndexOf("/",links[i].href.lastIndexOf("/")-1)+1) == foldername) {
				if(links[i].parentNode.parentNode.id == "menu") links[i].parentNode.className = "active";				
			}
			if (links[i].href.substring(links[i].href.lastIndexOf("/")+1) == filename) {
				if(links[i].parentNode.parentNode.parentNode.className == "active") links[i].parentNode.className = "activesub";
			}
		}
	}
	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";
			}
		}
	}
	
	document.getElementById('menu').onmouseover = function() {
		var a = document.getElementById("menu").getElementsByTagName("li");
		for (var i=0; i<a.length; i++) { if(a[i].className == "active") { a[i].className="activ"; } }
	}
	
	document.getElementById('menu').onmouseout = function() {
		var a = document.getElementById("menu").getElementsByTagName("li");
		for (var i=0; i<a.length; i++) { if(a[i].className == "activ") { a[i].className="active"; } }
	}	


	var countDownElement = $(document.getElementById('age'));
	var countdown = function(nextText) {
		var newText = '';
		switch(nextText) {
			case '17,5':
				newText = '17';
				break;
			case '17':
				newText = '16,5';
				break;
			case '16,5':
				newText = '';
				break;
			default:
				return;
		}
		countDownElement.fadeOut(100, function() {
			countDownElement.html(nextText);
			countDownElement.fadeIn(100, function() {
				setTimeout(function() {countdown(newText); }, 500);
			});
		});
	};

	setTimeout(function() {countdown('17,5'); }, 1000);
	setInterval(function() {
		countDownElement.html('18');
		setTimeout(function() {countdown('17,5'); }, 1000);
	}, 10000);
}

function checkContactForm() {
	if(ccscheck('naam', '') + ccscheck('mail','mail') + ccscheck('mssg','') == 0) return true;
	else return false;
}

function checkLenteForm() {
	check = ccscheck('l_naam', '') + ccscheck('l_mail','mail');
	//alert(check);
	if(check == 0) return true; else return false;
}
function checkTafForm() {
	if(ccscheck('jouw-naam', '') + ccscheck('jouw-mail','mail') + ccscheck('vriend-naam', '') + ccscheck('vriend-mail','mail') == 0) return true; else return false; // mail, post, phone or other
}

function checkAfspraakForm() {
	if(ccscheck('naam', '') + ccscheck('mail','mail') == 0) return true;
	else return false;
}

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

function check(inputId, type) {
	var id = document.getElementById(inputId);
	var v = id.value;
	switch (type) {
		
		case 'mail':
			var atIndex = v.indexOf('@');
			var dotIndex = v.lastIndexOf('.');
			if (atIndex < 1 || atIndex>=(v.length-2) || dotIndex < 1 || dotIndex>=(v.length-2) || atIndex > dotIndex - 1)
				return 1;
			else
				return 0;
			break
	
		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 0;
			} else return 1;
			break
		
		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;
			if(v.length == 6 && re.test(v)) return 0; else return 1;
			break
		
		default:
			var length = v.length;
			if(length < 2 || v =="Naam") return 1; else return 0;
			break
	}

}


