﻿
function urlRandomizer() {
	var strChars = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";			
	var minLength = 30;
	var maxLength = 30;
	var diffLength = maxLength - minLength		
	var thisLength = Math.round((Math.random() * diffLength)+minLength);		
	var outLoop = 0; var strGen = '';			
	while(outLoop<thisLength)	{
		strGen += strChars.charAt(Math.round(Math.random() * strChars.length));
		outLoop++;
	}			
	return(strGen);
}

function validateEmail(email){
	 if (email.length == 0) return false; 
	 var splitted = email.match("^(.+)@(.+)$");
	 if(splitted == null) return false;
	 if(splitted[1] != null )
	 {
		var regexp_user=/^\"?[\w-_\.]*\"?$/;
		if(splitted[1].match(regexp_user) == null) return false;
	 }
	 if(splitted[2] != null)
	 {
		var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
		if(splitted[2].match(regexp_domain) == null) 
		{
		 var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
		 if(splitted[2].match(regexp_ip) == null) return false;
		}// if
		return true;
	 }
	return false;
}	

function spinner(divId){
	$(divId).update('<img src="/img/activity_spinners/spinner.gif" width="18" height="18" style="margin-left:20px" alt="Loading..." />');
}

function processor(divId){
	$(divId).update('<img src="/img/activity_spinners/loading_animation_liferay.gif" width="70" height="10" style="margin-left:20px" alt="Processing..." />');
}

function StyleOver(id) {
    $(id).parentNode.className = "chromeover";
}

function StyleOrig(id) {
    $(id).parentNode.className = "";
}
function StyleActive(id) {
    $(id).parentNode.className = "chromestyleactive";
}

function getEventArchive(){
	var eY=$('archiveYr')[$('archiveYr').selectedIndex].value;
	var eT=$('archiveTp')[$('archiveTp').selectedIndex].value;
	new Ajax.Updater('archiveResults','scripts/getEventArchive.asp?y='+eY+'&t='+eT+'&r='+urlRandomizer(),{evalScripts:true})
}

function submitPoll(vote){	
	spinner('hpPoll');
	new Ajax.Updater('hpPoll','/ajax/doPoll.asp?r='+urlRandomizer()+'&vote='+vote, {evalScripts:true});
}

function showThermoText(bid,step){
	spinner('thermometerArticle');
	new Ajax.Updater('thermometerArticle','scripts/getThermArticle.asp?r='+urlRandomizer()+'&bid='+bid+'&step='+step, {evalScripts:true});
	$('thermometerArticle').show();
}

function submitThermoReply(bid){
	aTR = $('TRauthor').value;
	mTR = $('TRbericht').value;
	vTR = $('TRverification').value;

	if(aTR==''){
		alert('Je hebt nog geen naam ingevuld.');
		$('TRauthor').focus();
		return false;
	}
	if(mTR==''){
		alert('Je hebt nog geen reactie ingevuld.');
		$('TRbericht').focus();
		return false;
	}
	/*
	if(vTR==''){
		alert('Je hebt de controlecode overgetikt.');
		$('TRverification').focus();
		return false;
	}
*/
	divHgt = $('myReply').offsetHeight;
	$('myReply').style.height=divHgt+'px'
	processor('myReply');
	new Ajax.Updater('thermometerArticle','scripts/getThermArticle.asp?r='+urlRandomizer()+'&bid='+bid+'&v='+encodeURIComponent(vTR)+'&a='+encodeURIComponent(aTR)+'&m='+encodeURIComponent(mTR), {evalScripts:true});
}

function refreshCaptcha(){	
	//alert($('verification').src)
	$('verificationImg').src='/scripts/captcha/CAPTCHA.asp?CaptchaType=3&rnd='+urlRandomizer();
}




var re_date = /^(?=\d)(?:(?!(?:(?:0?[5-9]|1[0-4])(?:\.|-|\/)10(?:\.|-|\/)(?:1582))|(?:(?:0?[3-9]|1[0-3])(?:\.|-|\/)0?9(?:\.|-|\/)(?:1752)))(31(?!(?:\.|-|\/)(?:0?[2469]|11))|30(?!(?:\.|-|\/)0?2)|(?:29(?:(?!(?:\.|-|\/)0?2(?:\.|-|\/))|(?=\D0?2\D(?:(?!000[04]|(?:(?:1[^0-6]|[2468][^048]|[3579][^26])00))(?:(?:(?:\d\d)(?:[02468][048]|[13579][26])(?!\x20BC))|(?:00(?:42|3[0369]|2[147]|1[258]|09)\x20BC))))))|2[0-8]|1\d|0?[1-9])([-.\/])(1[012]|(?:0?[1-9]))\2((?=(?:00(?:4[0-5]|[0-3]?\d)\x20BC)|(?:\d{4}(?:$|(?=\x20\d)\x20)))\d{4}(?:\x20BC)?)(?:$|(?=\x20\d)\x20))?((?:(?:0?[1-9]|1[012])(?::[0-5]\d){0,2}(?:\x20[aApP][mM]))|(?:[01]\d|2[0-3])(?::[0-5]\d){1,2})?$/;

function activiteitenAanmeldenFormSubmit(theForm){
	if(validateForm(theForm,ValArr)){
		
		dtDob=$('geboorteDag').value + "/" + $('geboorteMaand').value + "/" + $('geboorteJaar').value;
		if (!re_date.test(dtDob)) {
			alert("De ingevoerde geboortedatum is incorrect. Voor de datum in als dag-maand-jaar");
			return false;
		}
		
		strFields=$(theForm).serialize();
		formHandler(strFields,'activiteit');
	}	
}



function peerEducatorAanmeldenFormSubmit(theForm){
	if(validateForm(theForm,ValArr)){
		
		dtDob=$('geboorteDag').value + "/" + $('geboorteMaand').value + "/" + $('geboorteJaar').value;
		if (!re_date.test(dtDob)) {
			alert("De ingevoerde geboortedatum is incorrect. Voor de datum in als dag-maand-jaar");
			return false;
		}
		strFields=$(theForm).serialize();
		formHandler(strFields,'peer educator');
	}	
}

function jaaAanmeldenFormSubmit(theForm){
	if(validateForm(theForm,ValArr)){
		
		dtDob=$('geboorteDag').value + "/" + $('geboorteMaand').value + "/" + $('geboorteJaar').value;
		if (!re_date.test(dtDob)) {
			alert("De ingevoerde geboortedatum is incorrect. Voor de datum in als dag-maand-jaar");
			return false;
		}
		strFields=$(theForm).serialize();
		formHandler(strFields,'aanmelding jaa');
	}	
}

function kennismakingAanmeldenFormSubmit(theForm){
	if(validateForm(theForm,ValArr)){
		
		dtDob=$('verzoekDag').value + "/" + $('verzoekMaand').value + "/" + $('verzoekJaar').value;
		if (!re_date.test(dtDob)) {
			alert("De ingevoerde verzoekdatum is incorrect. Voor de datum in als dag-maand-jaar");
			return false;
		}
		strFields=$(theForm).serialize();
		formHandler(strFields,'kennismaking');		
	}	
}

function toolkitAanmeldenFormSubmit(theForm){
	if(validateForm(theForm,ValArr)){
		
		dtDob=$('verzoekDag').value + "/" + $('verzoekMaand').value + "/" + $('verzoekJaar').value;
		if (!re_date.test(dtDob)) {
			alert("De ingevoerde verzoekdatum is incorrect. Voor de datum in als dag-maand-jaar");
			return false;
		}
		strFields=$(theForm).serialize();
		formHandler(strFields,'toolkit');
	}	
}

function workshopAanmeldenFormSubmit(theForm){
	if(validateForm(theForm,ValArr)){
		
		dtDob=$('verzoekDag').value + "/" + $('verzoekMaand').value + "/" + $('verzoekJaar').value;
		if (!re_date.test(dtDob)) {
			alert("De ingevoerde verzoekdatum is incorrect. Voor de datum in als dag-maand-jaar");
			return false;
		}
		strFields=$(theForm).serialize();
		formHandler(strFields,'thermometerworkshop');
	}	
}

function vraagFormSubmit(theForm){
	if(validateForm(theForm,ValArr)){
		strFields=$(theForm).serialize();
		formHandler(strFields,'Vraag aan JAA!');
	}	
}



function kH(e) {
	var code;
	
	if (!e) var e = window.event
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	
	if((code==13)||(code==9)){ //13: enter; 9: tab
		e.cancelBubble = true;
		if (e.stopPropagation) e.stopPropagation();
		storeAddress();		
	}
}
 
function catchtabenter (evt, cNextID) {
    nextID = cNextID;
    return kH(evt);
}


function storeAddress() {
	theAddress = $('nl_email').value;	
	if(validateEmail(theAddress)){
		new Ajax.Updater('nl_block','/community/subscribe/doNewsletter_iframe.asp?e-mail='+theAddress+'&rnd='+urlRandomizer(), {});
	} else {
		alert('Het opgegeven e-mail adres is ongeldig.');
		$('nl_email').focus();
	}
}

function showNewsletterReg(){
	if($('nl_block').style.display=='none'){
		Effect.SlideDown('nl_block');
	}
}

function formHandler(strVars,formType){
	divHgt = $('updatearea').offsetHeight;
	$('updatearea').style.height=divHgt+'px'
	processor('updatearea');
	strVars=strVars.replace(/&/gim,'{;}')
	new Ajax.Updater('updatearea','/ajax/formHandler.asp?form='+encodeURIComponent(formType)+'&vars='+strVars+'&rnd='+urlRandomizer(),{evalScripts:true});
}



// RV: a href rel="external" openenen in nieuwe vensters (dit ipv target=_blank, wat niet xHTML strict compliant is) 
window.onload = function() {
	externalLinks();
}

// open externe links in nieuw browser venster 
function externalLinks() { 
	if (!document.getElementsByTagName) return; 
	var anchors = document.getElementsByTagName("a"); 
	for (var i=0; i<anchors.length; i++) { 
		var anchor = anchors[i]; 
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") anchor.target = "_blank"; 
	} 
} 
