var emailfilter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
var telefoonfilter = /^([0-9-]{10})/;

window.onload = window.onresize = correctShadow;

function correctShadow(){
	document.getElementById("shadow").style.height = document.getElementById("meta").offsetHeight + "px";
}

function findObj(id){
	return ((document.getElementById) ? document.getElementById(id) : document.all[id]);
}

function getContent(url) {
	var client = new HttpClient();
	client.isAsync = true;
	client.callback = function(result) { 
 		document.getElementById('stage').innerHTML = result;
		correctShadow();
	}
 	client.makeRequest(url,null);
}

function validateForm(obj,required,msg){
	var errorFields = '';
	var firstField = '';
	var message = '';
	var requiredFields = required.split (/\s*,\s*/);
	
	for(var i=0;i<requiredFields.length;i++){
		var frmObj = findObj(obj);
		var fldObj = eval('frmObj.' + requiredFields[i]);
			if ((fldObj.value == '' || fldObj.value.indexOf("< ") != -1 || fldObj.value.indexOf("-- ") != -1) || ( ((fldObj.id == "email")||(fldObj.id == "Email")) && !(emailfilter.test(fldObj.value))) || ( ((fldObj.id == "telefoon")||(fldObj.id == "mobiel")) && !(telefoonfilter.test(fldObj.value))) ) {
				if (firstField == '') firstField = fldObj;
				if (fldObj.title != ''){
					if (fldObj.title == "< DD >") { errorFields += '- Datum dag\n'; }
					else if (fldObj.title == "< MM >") { errorFields += '- Datum maand\n'; }
					else if (fldObj.title == "< JJJJ >") { errorFields += '- Datum jaar\n'; }
					else { errorFields += '- ' + fldObj.title + '\n'; }
				} else {
					errorFields += '- ' + fldObj.id + '\n';
				}
				addClassName(fldObj,"notValid");
			}
	}
	
	if(errorFields != ''){
		alert(msg + '\n\n' + errorFields);
		return false;
	}
	return true;
}

function validateInput(obj){
	if(obj.id == "Email" || obj.id == "email" ) {
		if(emailfilter.test(obj.value)) removeClassName(obj,"notValid");
	} else if(obj.id == "telefoon" || obj.id == "mobiel" ) {
		if(telefoonfilter.test(obj.value)) removeClassName(obj,"notValid");
	} else {
		if(obj.value != '' || obj.value.indexOf("< ") == -1 || obj.value.indexOf("-- ") == -1) removeClassName(obj,"notValid");
	}
}


function removeClassName(objElement, strClass){
   if (objElement.className){
      var arrList = objElement.className.split(' ');

      for (var i=0; i<arrList.length; i++){
         if (arrList[i] == strClass){
            arrList.splice(i, 1)
            // decrement loop counter as we have adjusted the array's contents
            i--;
         }
      }
      // assign modified class name attribute
      objElement.className = arrList.join(' ');
   }
}

function addClassName(objElement, strClass){
	if (objElement.className){
		var arrList = objElement.className.split(' ');
		for (var i=0; i<arrList.length; i++){
			if (arrList[i] == strClass){
				return false;
			} else {
				objElement.className += " "+strClass;	
			}
		}
	} else {
		objElement.className = strClass;
	}
}


function popup(url,w,h,name) {
	var popwidth = parseInt(w);
	var popheight = parseInt(h);
	var parenttop = (self.screenTop)? self.screenTop:self.screenY;
	var parentleft = (self.screenLeft)? self.screenLeft:self.screenX;
	var topcorrection = (navigator.appName == "Microsoft Internet Explorer")? -20:43;
	var parentwidth = (document.documentElement)? document.documentElement.clientWidth:document.body.clientWidth;
	var parentheight = (document.documentElement)? document.documentElement.clientHeight:document.body.clientHeight;
	var popleft = (parentwidth/2 - popwidth/2) + parentleft;
	var poptop = (parentheight/2 - popheight/2) + parenttop + topcorrection;
	var popup = window.open(url,name,'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=yes,resizable=no,width='+popwidth+',height='+popheight+',left='+popleft+',top='+poptop+',screenX='+popleft+',screenY='+poptop)
	popup.focus();
}

function showLogin()
{
	$("#popLog").show();
}

//werkwijze pagina
currentId = "1"
function activate(id){
	deactivate(currentId);
	objLink = findObj("link-stap" + id);
	objLi = findObj("li-stap" + id);
	objDiv = findObj("stap" + id)
		
	objLink.className = "active";
	objLi.className = "active";	
	objDiv.style.display = "block";

	currentId = id
}

function deactivate(id){
	objLink = findObj("link-stap" + id);
	objLi = findObj("li-stap" + id);
	objDiv = findObj("stap" + id)
		
	objLink.className = "";
	objLi.className = "";	
	objDiv.style.display = "none";
}

$(document).ready(function(){
	
	// init popups
	$(".jqPop").each( function(){
		var target = $(this).attr("rel");
		$(this).click( function(){
			$(target).show();
		});
		$(target).find("a.close").add("input.reset").click( function(){
			$(target).hide();								 
		})
	});
	
	$("#popLog").find("a.close").add("input.reset").click( function(){
		$("#popLog").hide();
	});
	
	$(".jqWerkwijze").click(function() {
		$(this).next().toggle();
	}).next().hide();
	
});