function checkForm()
{
	$form = $("form#contactform");
	$form.find("input[type=text],textarea").each(function(){
		var $field = $(this);
		var $label = $field.prev('br').prev('label');

		// required fields
		if ($label.html().toString().indexOf('*') > -1)
		{
			var error = false;
			switch($field.attr('name'))
			{
				case "email":
					var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
					if (!filter.test($field.val()))
					{
						error = true;
					}
					break;
				default:
					if ($field.val().trim().length == 0)
					{
						error = true;
					}
			}
			if (error)
			{
				$label.addClass('error');
				$form.addClass('error');
			}
			else
			{
				$label.removeClass('error');
			}
		}
	});

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

	return true;
}

// start of jQuery document ready
$(document).ready(function(){

	if ($("ul.winternet.documentMenu").length > 0)
	{
		$("ul.winternet.documentMenu div.moreInfo").parent().children('h1,h2,h3,h4,h5').addClass('clickable');
		$("ul.winternet.documentMenu .clickable").click(function(){
			$li = $(this).parents("li:first");
			if ($li.hasClass('open'))
			{
				//$li.parent().children('li').children('ul').fadeOut('fast').prev('div.moreInfo').show();
				$li.children('div.moreInfo').show();
				$li.children('ul.category').slideUp('slow');
			}
			else
			{
				//$li.parent().children('li').children('ul').fadeOut('fast').prev('div.moreInfo').show();
				$li.children('div.moreInfo').hide();
				$li.children('ul.category').slideDown('slow');
			}
			$li.toggleClass('open');
		});
	}

	$("div.loginform ul.loginSwitch li").click(function(){
		if (!$(this).hasClass('active'))
		{
			var $li = $(this);
			$li.parent().children('li').removeClass('active');
			$li.addClass('active');

			$li.parent().next().height($li.parent().next().height());

			var $form = $("div.loginform form:visible")
			$form.fadeOut('fast' , function(){
				$form.prev('form').fadeIn('slow');
				$form.next('form').fadeIn('slow');
				$li.parent().next().height('auto');
			});
		}
	});

	$("div.loginform form.memberLogin").bind('submit' , function(){
		var $form = $("div.loginform form.memberLogin");
		if ($form.attr('confirmed') == 'true')
		{
			return true;
		}

		$.getJSON('/ajax/ajax_winternetSoap.php?result=json' , $form.find("input") , function(json){
			if (typeof(json.succes) != 'undefined')
			{
				$form.attr('confirmed', 'true');
				$form.submit();
				return true;
			}
			var $error = $('<div class="error">' + json.error + '</div>');
			$form.children('div.error').remove();
			$form.prepend($error);
		});

		return false;
	});

	$("div.winternetsoap").each(function(){
		var $soapTarget = $(this);
		var sAction = $soapTarget.clone().removeClass('winternetsoap winternetsoapReady').attr('class');
		var iId = $soapTarget.attr('id').replace('soapEvent_', '');
		$.get(
			'/ajax/ajax_winternetSoap.php', {
					'action': sAction,
					action_id: iId
				},
			function(data){
				$soapTarget.html(data);
				$soapTarget.addClass('winternetsoapReady');

				switch(sAction)
				{
					case 'getMembers':
						$soapTarget.children('form').bind('submit' , function(){
						if (confirm('Wilt u de geselecteerde leden aanmelden?'))
						{
							return true;
						}
						return false;
					});
					break;
				}
			}
		);
	});

	$("form.registermembers").submit(function(){
		if ($(this).find('input[name=register]:checked').length == 0)
		{
			alert('U dient aan te geven dat u wilt inschrijven!');
			return false;
		}

		return true;
	});

	/* search */
	
	$('#chooseCategorieAnchor').toggle(function() {
		$('#chooseCategorieTop').slideDown('slow');
	}, function() {
		$('#chooseCategorieTop').slideUp('slow');
	});

	setTimeout(function(){
		$("div.winternet div.msg").css({display:'none', visibility:'visible'}).fadeIn(2000);
	}, 1000);
	
	$('#chooseCategorieTop label').click(function(event) {
		var inputTag = $('#input_' + event.target.id.substring(4));
		if (inputTag.attr('checked'))
		{
			inputTag.attr('checked', false);
		}
		else
		{
			inputTag.attr('checked', true);
		}
	});
});