function checkForm(id)
{
	var form = $('form#' + id);
	// first remove any error class still present on the form
	form.removeClass('formerror');
	$('.errormessage').remove();

	var formerror = false;

	if (!checkCaptcha(form))
	{
		formerror = true;
	}

	form.find('input[type=hidden]').each(function(){
		var checkfield = $('#' + $(this).attr('name').replace('_required', ''));
		var label = $('#lbl_' + checkfield.attr('name'));
		var fieldname = checkfield.attr('name');


		var error = false;
		switch (checkfield.attr('name'))
		{
			case "email":
				var filter = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
				if (!filter.test(checkfield.val()))
				{
					error = true;
				}
			break;
			
			case "zip":
				var filter = /^[0-9]{4}[a-z|A-Z]{2}$/i;
				if (!filter.test(checkfield.val()))
				{
					error = true;
				}
			break;


			default:
				if (checkfield.attr('type') == 'checkbox')
				{
					if(!checkfield.is(':checked'))
					{
						error = true;
					}
				}
				if (checkfield.attr('type') == 'text')
				{
					if (checkfield.val().length == 0 )
					{
						error = true;
					}
				}
			}
			
			if (error)
			{
				label.addClass('formerror');
				formerror = true;
			}
			else
			{
				label.removeClass('formerror');
			}
		});

	
	if (formerror)
	{		
		// show the new error
		form.prepend('<p class="errormessage">Een of meerdere verplichte velden zijn niet juist ingevuld.</p>');
		return false;
	}
	return true;
}

// captcha check, copied from isource.nl
function checkCaptcha(form)
{
	if ($('div.captcha').length)
	{
		form.removeClass('error');

		$('#captchaerror').hide();

		var label = $('label[for=captchacode]');

		var sData = 'captcha_code=' + $('#captchacode').val();

		var returnValue = false;

		$.ajax({
			type: "POST",
			url: "/ajax/captchacheck.php",
			data: sData,
			async: false,
			success: function(response) {
				if (response != 'ok')
				{
					form.addClass('error');
					document.getElementById('captcha').src = '/phpcaptcha/securimage_show.php?' + Math.random();
					$('#captchacode').val('');
					$('#captchaerror').show();
					label.addClass('formerror');
					returnValue = false;
				}
				else
				{
					if (form.hasClass('error'))
					{
						returnValue = false;
					}
					else
					{
						label.removeClass('formerror');
						returnValue = true;
						//return true;
					}
				}
			}
		});

		return returnValue;
	}
	else
	{
		if (form.hasClass('error'))
		{
			return false;
		}

		return true;
	}
}

function showNextBanner(curBanner, nextBanner)
{
	if (nextBanner > totalBanners)
	{
		nextBanner = 1;
	}

	// first show the next banner
	$('.banner_rotator .banner' + nextBanner).show();
	// then hide the current banner
	$('.banner_rotator .banner' + curBanner).hide();

	curBanner = nextBanner;
	nextBanner++;

	if (nextBanner > totalBanners)
	{
		nextBanner = 1;
	}

	setTimeout('showNextBanner(' + curBanner + ', ' + nextBanner + ')', bannerSpeed * 1000);
}

$().ready(function() {
	// only start looping if there are multiple banners to show
	if (totalBanners > 1)
	{
		// first hide all banners except the first one
		$('.banner_rotator .banner + .banner').hide();

		// then start the 'slideshow' of banners
		setTimeout('showNextBanner(1, 2)', bannerSpeed * 1000)
	}
	

	$('.screenshot img').click(function() {
		var sAlt = $(this).attr('alt'); 
		$('img#cboxPhoto').attr('alt', sAlt);
	});

	$('#mainmenu .menuitem').hover(	 
		function()
		{
			if( ! ($(this).hasClass('menuitem_active')) )
			{
				$(this).attr('style', 'background-color:#767676;');
			}
		},
		function()
		{
			$(this).attr('style', ' ');
	});


});