$(function() {

	$(".required").append('<span class="asterisk">*</span>');

	$('.underline').click(function(){
		$('.dialog').html('<img src="'+baseUrl+'/img/loader.gif" alt="loader" />');
		$('.dialog').load(baseUrl+'/enquete/definitie/' + $(this).attr('id'));
		$('.dialog').dialog('open');
        return false;
	});
	
	$('.dialog').dialog({
	    autoOpen: false,
	    width: 600,
	    buttons: {
		    "Ok": function() {
		    	$(this).dialog("close");
	    	}
    	}	
    });
});

$(document).ready(function() {

	$('div.register_provincie_gemeente').hide();

	$('table.vragenlijstenoverzicht tr:odd').css('background-color', '#CEC7BB');
	$('table.vragenlijstenoverzicht tr:even').css('background-color', '#ECE6D9');
	
	$('table.questiontable tr:odd').css('background-color', '#CEC7BB');
	$('table.questiontable tr:even').css('background-color', '#ECE6D9');
	
	$('div.question div:first').css('border-bottom', 'none');
	$('div.question div:last').css('border-bottom', 'none');

	$('table#uitslagtable tr:last td.uitslag').css('border-bottom', '0px');
	
	$('div.register_provincie > h3').click(function() {
		
		//$(this).siblings('div.register_provincie_gemeente').toggle();
		if($(this).parent().children('.register_provincie_opener').html() == '[+]'){
			$(this).siblings('div.register_provincie_gemeente').css('display', 'block');
			$(this).parent().children('.register_provincie_opener').html('[-]');
		}else{
			$(this).siblings('div.register_provincie_gemeente').css('display', 'none');
			$(this).parent().children('.register_provincie_opener').html('[+]');
		}
	});
	
	$('div.register_provincie div.register_provincie_gemeente div.register_gemeente input.register_gemeente:checked').each(function() {
		$(this).parent().parent().parent().show();
		$(this).parent().parent().parent().siblings('.register_provincie_opener').html('[-]');
	});
});


/**
 * Functie om tekstveld leeg te maken bij unchecken checkbox of checkbox te unchecken als het tekstveld leeg wordt gemaakt
 * @param string checkfilter
 * @param string fieldfilter
 * @return
 */
var registerCheckToggleField = function(checkfilter, fieldfilter) {

	$(checkfilter).eq(0).click(function() {
		if (!this.checked) {
			$(fieldfilter).val('');
		}
	});
	$(fieldfilter).keyup(function() {
		$(checkfilter).eq(0).get(0).checked = this.value != '';
	});
}

/**
 * Functie om gedeelte van webpagina tevoorschijn te halen als een checkbox is gechecked of laten verdwijnen als unchecked
 * @param string areas
 * @param boolean enabled
 * @param boolean collapse
 * @return
 */
var toggleArea = function(areas, enabled, collapse) {
	$areas = $(areas);
	if (enabled) {
		$areas.find('input, textarea, select').removeAttr('disabled');
		$areas.removeClass('disabled');
		if (collapse) {
			$areas.show();
		}
	} else {
		$areas.find('input, textarea, select').attr('disabled', 'disabled');
		$areas.find('input:checkbox').each(function() {
			this.checked = false;
		});
		$areas.find('input:text, textarea').val(' ');
		$areas.find('select').each(function() {
			this.selectedIndex = 0;
		});
		$areas.addClass('disabled');
		if (collapse) {
			$areas.hide();
		}
	}
}

var toggleAreaCheck = function(checkfield, area){
	$(checkfield).click(function(){
		$area = $(area);
		if($(checkfield+":checked").attr('value') == 'ja'){
			$area.show();
		}else{
			$area.find('input:text, textarea').val('');
			$area.hide();
		}
	});
}
