/* JS
   (c) 2008 Oskar D
*/

var invfields;

function isEmpty(string)
{
	for (var i = 0; i < string.length; i++)
	{
		var ch = string.substring(i, i+1);
		if (ch != " " && ch != "\t" && ch != "\n" && ch != "\r")
		{
			return false;
		}
	}
	return true;
}

function invalid_field_check(field) {
	if (isEmpty(field.value)) {
		field.style.borderColor = 'red';
		field.style.backgroundColor = '#ff6666';
		invfields++;
	} else {
		field.style.borderColor = '#CCCCCC';
		field.style.backgroundColor = 'white';
	}
	
}

function FormValidatie() {
	var field;
	invfields = 0;
	
	invalid_field_check(document.getElementById('postcode'));
	invalid_field_check(document.getElementById('email'));
		
	if (invfields > 0) {
		document.getElementById('mark').style.display = 'block';
		return false;
	}else{
		document.getElementById('mark').style.display = 'none';
	}

	var email = document.getElementById('email'); 
	var positieAt = email.value.indexOf('@');
	var positieLaatstePunt = email.value.lastIndexOf('.');
	var domein = email.value.substr(positieLaatstePunt+1);
	if((positieAt == -1) || (positieLaatstePunt == -1) || (positieAt > positieLaatstePunt)	|| (domein.length < 2) || (domein.length > 4) ) {
		document.getElementById('email').style.borderColor = 'red';
		document.getElementById('email').style.backgroundColor = '#ff6666';
		document.getElementById('mail-mark').style.display = 'block';
		return false;
	}else{
		document.getElementById('email').style.borderColor = '#CCCCCC';
		document.getElementById('email').style.backgroundColor = 'white';
		document.getElementById('mail-mark').style.display = 'none';
	}	
	//return true;
	
	
}