/*nieuwsbrief form*/
function validateNieuwsbriefForm(aForm) {
	var divs = [$('lastname'), $('firstname'), $('email'),$('site'),$('taal')];
	var divWithErrors = [];
	
	// clear the border for all fields
	for (i = 0; i < divs.length; i++) {
		var div = divs[i];
		
		$(div).className = "txt";
	}
	
	// validate the fields
	
	if ($('email').value == "" || !isValidEmail($('email').value))
		divWithErrors.push($('email'));
	
		
	if (divWithErrors.length > 0) {	
		// we have errors, mark the fields						
		for (i = 0; i < divWithErrors.length; i++) {
			var div = divWithErrors[i];
			
			$(div).className = "required";
		}
	} 
	else {
		postString = "q=NB&lastname="+$('lastname').value+"&"+
				"firstname="+$('firstname').value+"&"+
				"email="+$('email').value+"&"+
				"taal="+$('taal').value+"&"+
				"site="+$('site').value;
		//alert(postString);
		var myAjax = new Ajax('ajax_php/forms.php', {
			method: 'post',
			data: postString,
			onRequest: function() { 
				$('message_busy').setStyle("display", "block");				
				$('message_busy').innerHTML = '<img src="img/ajax-loader.gif"> Please wait... processing request...'; 
					},
			onComplete: function(req){
						//alert(req);
					$('message_busy').innerHTML = req;
					$('contact_form_div').setStyle('display', 'none');
					
			}
	}).request();
	}
}
/*contact form*/
function validateContactForm(aForm) {
	var divs = [$('lastname'), $('firstname'), $('email'), $('email2'),$('straat'),$('postcode'),$('gemeente'),$('aantal')]
	var divWithErrors = [];
	
	// clear the border for all fields
	for (i = 0; i < divs.length; i++) {
		var div = divs[i];
		
		$(div).className = "txt";
	}
	
	// validate the fields
	
	if ($('lastname').value == "")
		divWithErrors.push($('lastname'));
	if ($('firstname').value == "")
		divWithErrors.push($('firstname'));
	if ($('straat').value == "")
		divWithErrors.push($('straat'));
	if ($('postcode').value == "")
		divWithErrors.push($('postcode'));
	if ($('gemeente').value == "")
		divWithErrors.push($('gemeente'));
	if ($('email').value == "" || !isValidEmail($('email').value))
		divWithErrors.push($('email'));
	if ($('email').value != $('email2').value){
		divWithErrors.push($('email'));divWithErrors.push($('email2'));}
		
	if (divWithErrors.length > 0) {	
		// we have errors, mark the fields						
		for (i = 0; i < divWithErrors.length; i++) {
			var div = divWithErrors[i];
			
			$(div).className = "required";
		}
	} 
	else {
		postString = "lastname="+$('lastname').value+"&"+
				"firstname="+$('firstname').value+"&"+
				"email="+$('email').value+"&"+
				"straat="+$('straat').value+"&"+
				"postcode="+$('postcode').value+"&"+
				"gemeente="+$('gemeente').value+"&"+
				"aantal="+$('aantal').value;
	
		var myAjax = new Ajax('ajax_php/forms.php', {
			method: 'post',
			data: postString,
			onRequest: function() { 
				$('message_busy').setStyle("display", "block");				
				$('message_busy').innerHTML = '<img src="img/ajax-loader.gif"> Please wait... processing request...'; 
					},
			onComplete: function(req){
					$('message_busy').innerHTML = req;
					$('contact_form_div').setStyle('display', 'none');
					$('contact_success_div').setStyle('display', 'block');
			}
	}).request();
	}
}

function isValidEmail(txt) {
	if (txt == "") return false;
	
	// copy paste from various sites :)
	var regex = /[a-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/;
	return txt.match(regex);
}