function toonInfo()
{
	var fromJaar = $F('fromJaar');
	var fromMaand = $F('fromMaand');
	var fromDag = $F('fromDag');
	var toJaar = $F('toJaar');
	var toMaand = $F('toMaand');
	var toDag = $F('toDag');
	location.href='/info_user.php?fromJaar=' + fromJaar + '&fromMaand=' + fromMaand + '&fromDag=' + fromDag + '&toJaar=' + toJaar + '&toMaand=' + toMaand + '&toDag=' + toDag;
}

function blockVisit(agendaId, weekday, date)
{
	// get checkbox state
	var checkbox = $('visit_' + weekday);
	var isChecked = (checkbox.checked) ? 1 : 0;

	// ajax
	new Ajax.Request('/agenda_block_visit.php',
	{
		method:'get',
		parameters: {id:agendaId, day:date, block:isChecked},
		onLoading: function()
		{},
		onSuccess: function(transport)
		{},
		onFailure: function()
		{
			checkbox.setValue(false);
			alert('Blokkering mislukt!');
		},
		onComplete: function(transport)
		{
			var response = transport.responseText || "no response text";
			
			if (response == 'OK')
			{
				if (isChecked) {
					$('cell_' + weekday).setStyle({backgroundColor: '#FF0000'});
				} else {
					$('cell_' + weekday).setStyle({backgroundColor: '#689e9f'});
				}
			}
			else
			{
				checkbox.setValue(false);
				alert('Blokkering mislukt! (' + response + ')');
			}
		}
	});
}

function trim(s)
{
	var l=0; var r=s.length -1;
	while(l < s.length && s[l] == ' ')
	{	l++; }
	while(r > l && s[r] == ' ')
	{	r-=1;	}
	return s.substring(l, r+1);
}


function validateSms(gsm)
{	
	$('sms').setStyle({backgroundColor: '#FFFFFF'});
	
	if (gsm.length > 0) {
		var match = /^0032[0-9]{9}$/.test(gsm);
		
		if (!match) {
			$('sms').setStyle({backgroundColor: '#FF6666'});
		}
	}
}

function validateForm(form, lng)
{
	var messages = new Array();
	messages['nl'] = new Array();
	messages['fr'] = new Array();
	messages['de'] = new Array();
	messages['en'] = new Array();
	
	messages['nl'][0] = 'U heeft geen emailadres ingevuld. Wil u toch doorgaan?\n';
	messages['fr'][0] = 'You didn\'t enter an email address. Continue?\n';
	messages['de'][0] = 'You didn\'t enter an email address. Continue?\n';
	messages['en'][0] = 'You didn\'t enter an email address. Continue?\n';
	
	messages['nl'][1] = 'Het emailadres is niet correct!\n';
	messages['fr'][1] = 'The email address is incorrect!\n';
	messages['de'][1] = 'The email address is incorrect!\n';
	messages['en'][1] = 'The email address is incorrect!\n';
	
	messages['nl'][2] = 'Het GSM-nummer is niet correct!\n(bv. 0032495986765)';
	messages['fr'][2] = 'Le nombre est incorrect!\n(bv. 0032495986765)';
	messages['de'][2] = 'Der Nummer ist nicht correct!\n(bv. 0032495986765)';
	messages['en'][2] = 'The number is incorrect!\n(bv. 0032495986765)';
	
	var email = trim(form.email.value);
	var gsm = trim(form.sms.value);
	
	if ( (email == '') && (gsm == '') ) {
		return confirm(messages[lng][0]);
	} else {
		if (email.length > 0) {
			var match = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test(email);
			
			if (!match) {
				alert(messages[lng][1]);
				return false;
			}
		}
		
		if (gsm.length > 0) {
			var match = /^0032[0-9]{9}$/.test(gsm);
			
			if (!match) {
				alert(messages[lng][2]);
				return false;
			}
		}
	}
	
	return true;
}

