// Switch to other image
function ToggleImage(anchor) {

	$("#image_container div").css('display','none');
	$("#image_" + anchor).fadeIn();

}

// Validate a single inputfield
function ValidateField(element) {

	var value = $(element).val();
	
	if(value == '') {
	
		$(element).css('border','solid #ff4444 1px');
		return false;
	
	} else {
	
		$(element).css('border','solid #cccccc 1px');
		return true;
		
	}

}

// Validate whole form
function CheckErrors() {

	error = 0;

	$("#form_error").slideUp();

	$('input[type=text]').add('textarea').each(function(index) {
		
		if($(this).val() == '') {
		
			if($(this).hasClass('optional')) {
			
			} else {
			
				ValidateField(this);
			
				$("#form_error").html('Een aantal verplichte velden zijn nog niet ingevuld.');
				$("#form_error").slideDown();
				
				error++;
			
			}
		
		} else {
		
			if (!ValidateField(this)) {
			
				error++;
			
			}
			
		}
		
	});
	
	if (error > 0) {
	
		return false;
	
	} else {
	
		return true;
	
	}

}

// Zoekbalk
function SearchInput(value) {

	if (value == 'Zoekwoord...') {
	
		$("#search_input").val('');
	
	}

}

// Zoekactie
function SubmitSearch(value) {

	if (value != 'Zoekwoord...' && value != '' && value != ' ') {
	
		window.location = 'key/' + value +'/';

	}

}

// Laat thumbnail zien
function ShowThumb(image) {

	if(image != '') {
	
		$("#sidebar_thumb").css('display','block');
		$("#sidebar_thumb").css('background-image', 'url(' + image + ')');
		
	} else {
	
		$("#sidebar_thumb").css('display','none');	
	
	}

}

// Laat volledige afbeelding zien
function ShowFullThumb(id, hide) {

	if(id != '' && hide == 0) {
	
		$("#image_hover_" + id).css('display','block');
	
	} else {
	
		$("#image_hover_" + id).css('display','none');
	
	}

}

// Poll submitten
function SetPollChoice(value) {

	$('#poll_choice').val(value);
	$('#form_poll').submit();

}
