function validate(event) {
	var tekst = 'Niet alle verplichte velden zijn (juist) ingevuld...:\n\n\n';
	var fout=false;
	var foutveld="";

	xname = trim(document.getElementById("Name"));
	if (xname =='') {
		tekst = tekst + '- Je naam is een verplicht veld.\n\n'
		fout=true;
		foutveld="Name"; // for focus (on first error)
		
	}
	
	mail = trim(document.getElementById("Email")); //document.getElementById("Email");
	if (mail=='') {
		tekst = tekst  + '- Je emailadres is een verplicht veld.\n\n'
		fout=true; 
		if(foutveld.length == 0) { 
			foutveld="Email";
		}	
	} 
	else  
	{
		if	((hasInvalidCharacter(mail))			// has invalid character
			|| (tooMuchOrToSoon(mail, '@'))			// no more than 1 '@', not at position 0
			|| (tooClose(mail, '.'))			// 2 consecutive '.' is not allowed
			|| (tooCloseTo(mail, '@', '.'))			// '.' cannot be immediately after or before '@'
			|| (mail.indexOf('.') < 1)			// '.' is required, not at first position
			|| (mail.lastIndexOf('.') > (mail.length - 3))	// at least 2 characters after last '.'
			)		
			{
				tekst = tekst  + '- Je emailadres is niet geldig.\n\n'
				fout=true;
				if(foutveld.length == 0) {
					foutveld="Email";
				}
			
			}
	}

	mess = trim(document.getElementById("Message")); 
	if (mess=='') {
		tekst = tekst  + '- Typ nog even je bericht!'
		fout=true; 
		if(foutveld.length == 0) { 
			foutveld="Message";
		}	
	} 

	if(fout) {
		alert(tekst);
		document.getElementById(foutveld).focus();
		//event.returnValue=false;
		return false;
		
	}
	
	return true;
}

function trim(field)
{	
	if(field != null && field.value !=null) {
		return field.value.replace(/^\s*|\s*$/g,'');	
	}

	return '';
}

function trimStr(str)
{	
	return str.replace(/^\s*|\s*$/g,'');
}

function removeSpaces(string) 
{
	return string.split(' ').join('');
}


<!-- no more than 1 '@', not at position 0 -->
function tooMuchOrToSoon(str, search) {
	count = 0;
	pos = str.indexOf(search);
	first = str.indexOf(search);

	while (pos != -1) {
		count++;
		pos = str.indexOf(search,pos+1);
	}
	
	if (count != 1 || first == 0) {
		
		return true;
	}

	return false;

}

<!-- 2 consecutive '.' is not allowed -->
function tooClose(str, search) {
	pos = str.indexOf(search);
	previous = str.indexOf(search);

	while (pos != -1) {
		pos = str.indexOf(search, pos + 1);

		if (pos - previous == 1) {
			return true;
		}
		previous = pos;

	}
	
	return false;

}

<!-- '.' cannot be immediately after or before '@' -->
function tooCloseTo(str, one, another) {
	pos = str.indexOf(one);
	
	if ((str.charAt(pos-1) == another) || (str.charAt(pos+1) == another)) {
		return true;
	}
	
	return false;

}

function hasInvalidCharacter(str) {
	var notValid=new Array(";",",","\\",">","<","(",")");
	for (x in notValid)       
	{
		if(str.indexOf(notValid[x]) > -1) {
			return true;
		}
	}

	return false;
}

function checkNumeric(string)
{
	var str = trimStr(string);
	if (str == '')
	{
		return '';
	}
	
	var ValidChars = "0123456789";
	var IsNumber=true;
	var Char;
 
	for (i = 0; i < str.length && IsNumber == true; i++) 
	{ 
		Char = str.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			IsNumber = false;
		}
	}

	if (IsNumber) {
		if(parseInt(str) > 5 && parseInt(str) < 125) 
		{
			return str;
		}
	}


	return '??';
   
}

function focusFirst() {
	document.getElementById("Name").focus();
}

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
	for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 	
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

function opacityTwo(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 
    var img1 = id;

	for(i = opacStart; i >= opacEnd; i--) { 
		setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
		timer++; 
	} 
	setTimeout("toggleImage('" + img1 +"')",(timer * speed)); 	
	for(i = opacEnd; i <= opacStart; i++) { 
		setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            	timer++; 
        } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
} 



function shiftOpacity(id, value, millisec) { 
    //if an element is invisible, make it visible, else make it invisible 
    var x = value/100;

    if(document.getElementById(id).style.opacity == x) { 
        opacity(id, value, 100, millisec);
    } else { 
        opacity(id, 100, value, millisec); 
    } 
} 

function toggleOpacity(id, value, millisec) { 
    var x = value/100;
	
	opacityTwo(id, 100, value, millisec);
} 

function swapImage(imgN,imgU){
	if(document.images)document.images[imgN].src=imgU;
}

function toggleImage(img1){
	if(document.getElementById(img1).getAttribute('tgl') == null || document.getElementById(img1).getAttribute('tgl') == 'on') {
		swapImage( img1 , 'picture_library/aardbei01_bright.jpg' )
		document.getElementById(img1).setAttribute('tgl', 'off');
	}
	else {
		swapImage( img1 , 'picture_library/aardbei01.jpg' )
		document.getElementById(img1).setAttribute('tgl', 'on');
	}
}



