/**
 * @author Huub Segers
 */

function parse_key (xmlHttpResponse) {
	var t = $('_key_');
	
	if( !t ) return;
	
	t.value = xmlHttpResponse.responseText;
}

function getkey () {
	
	new Ajax.Request('/create_key.php', {
		method : 'POST',
		onComplete : parse_key
	});
	
}


function mailsent(){
	if( document.location.search == '?send=true' ) {
		var t = $('sent');
		if (t) t.show();
	}
	
	if( document.location.search == '?send=false' ) {
		var t = $('error');
		if (t) t.show();
	}
}

function do_post (e) {
	
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,5})+$/;
	
	if( !$('i_email') || !filter.test($('i_email').value) ) {
		alert( 'gelieve een geldig e-mail adres in te vullen' );
		return;
	}
	
	var f = $('i_info-aanvraag');
	
	if( !f ) return false;
	
	f.action = 'send.php';
	
	f.submit();
}

Event.observe( window, "load", getkey );
Event.observe( window, "load", mailsent );
