/* * * * * /* * * * * * * * * * * * * * * * * * * * * * *
 *   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/                  *
 *                                           *
 * * * * * * * * * * * * * * * * * * * * * * */

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);
		if(filename.lastIndexOf("?")>0) filename = filename.substring(0,filename.lastIndexOf("?"));
		gevonden = "NEE";
		for ( var i = 0; i < links.length; i++) {
			//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].className = "active"; }
			
			if (links[i].href.substring(links[i].href.lastIndexOf("/"),links[i].href.lastIndexOf("/",links[i].href.lastIndexOf("/")-1)+1) == foldername) {
			//if (links[i].href.substring(links[i].href.lastIndexOf("/")+1) == filename) {
				links[i].className = "active"; gevonden="JA"; break;
			}
		}
		if (loc1+1 == location.href.length && gevonden != "JA") { links[0].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";
			}
		}
	}

	url = "http://dev2.carenza.nl/projecten/carenza/";
	
	if(typeof slider    == 'function') { slider(); }
	if(typeof sliderref == 'function') { sliderref(); }	
	if(foldername == "contact" && filename=="route.html") { googlemaps();}	
	
	$(function() { $('#container-1 > ul').tabs({ selected: 1 }); });


}

function removearrow() {
	var a = document.getElementById("menu").getElementsByTagName("a");
	for (var i=0; i<a.length; i++) { if(a[i].className == "active") { a[i].className="activ"; } }
}
function returnarrow() {
	var a = document.getElementById("menu").getElementsByTagName("a");
	for (var i=0; i<a.length; i++) { if(a[i].className == "activ") { a[i].className="active"; } }
}

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

function checkBelMeTerugForm() {
	if(ccscheck('naam', '') + ccscheck('tel','phone') == 0) { return true; } else { return false; } // mail, postc, phone or dropd or empty
}

function ccscheck(inputId, type) {
	var failCSS = 'invalid';
	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);
	if(type!='dropd') 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 0;
			else
				return 1;
			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 1; else return 0;
			break
		
		case 'dropd':
			v = id.selectedIndex.value;
			// id.value = v;
			if(length >= 2) return 0; else return 1;
			break
			
		default:
			var length = v.length;
			if(length >= 2) return 0; else return 1;
			break
	}

}


	

