//FORMS
function checkEmailAddress(email) {

	var filter	= /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

	if (filter.test(email)) return true;
	else return false;

}

function checkNewComment() {

	d = document.getElementById("commentForm");

	if(d.commentName.value==''){
		alert('Je moet eerst een naam opgeven!');
		d.commentName.focus();
		return false;
	}

	if(d.commentEmail.value==''){
		alert('Je moet eerst een emailadres opgeven!\nJe emailadres wordt niet op de website vertoond.');
		d.commentEmail.focus();
		return false;
	}

	if (checkEmailAddress(d.commentEmail.value) == false) {
		alert('Je moet een geldig emailadres opgeven!\nJe emailadres wordt niet op de website vertoond.');
		d.commentEmail.focus();
		return false;
	}

	if(d.commentText.value==''){
		alert('Je moet eerst een reactie geven!');
		d.commentText.focus();
		return false;
	}

	if(d.spamFilter.value==''){
		alert('Je moet de cijfers uit het plaatje overtypen!');
		d.spamFilter.focus();
		return false;
	}

	return true;

}


function checkNewContact() {

	d = document.getElementById("contactForm");

	if(d.contactName.value==''){
		alert('Je moet eerst een naam opgeven!');
		d.contactName.focus();
		return false;
	}

	if(d.contactEmail.value==''){
		alert('Je moet eerst een emailadres opgeven!');
		d.contactEmail.focus();
		return false;
	}

	if (checkEmailAddress(d.contactEmail.value) == false) {
		alert('Je moet een geldig emailadres opgeven!');
		d.contactEmail.focus();
		return false;
	}

	if(d.contactText.value==''){
		alert('Je moet eerst een bericht invullen!');
		d.contactText.focus();
		return false;
	}

	if(d.spamFilter.value==''){
		alert('Je moet de cijfers uit het plaatje overtypen!');
		d.spamFilter.focus();
		return false;
	}

	return true;

}

//SEARCH
function checkNewSearch() {

	d = document.getElementById("searchIt");

	if(d.searchText.value==''){
		alert('Je minstens één trefwoord invullen!');
		d.searchText.focus();
		return false;
	}

	return true;

}

//CAPTCHA
var count = 0;
function reloadCaptcha() {
	frm = document.getElementById("captcha");
	opacity("captcha", 100, 0, 300);
	count++;
	frm.src = "http://www.stevelock.nl/live/captcha/gdimg.php?re=" + count;
	opacity("captcha", 0, 100, 300);
}

function rand (mmin, mmax) {
	return ( Math.floor ( Math.random () * 100000 ) % mmax ) + mmin;
}

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++;
		}
	}
}

//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 pause( milisec ) {
	sleep = milisec;
	begin = new Date();
	start = begin.getTime();
	done = false;
	
	while( !done ) {
		alarm = new Date();
		curr = alarm.getTime();
		if( curr - start > sleep) {
			done = true;
			return;
		}
	}
}