function multiselectToggle(objectId)
{
	//close all other (open) multiselects except this select
	closeMultiSelects(objectId);

	$('#'+objectId).toggle();		
}

function multiselectToggleOption(multiselectId, checkboxId, emptyLabel)
{
	var inputElement = $('#'+multiselectId+'_input');
	var labelElement = $('#'+multiselectId+'_label');
	var checkbox = $('#'+checkboxId);
	
	labelElement.html('');
	inputElement.val('');
	
	var teller = 0;
	$('#'+multiselectId+'_container > .multiSelectOption > .multiSelectCheckBoxInput').each(function() {
		if ( $(this).attr('checked') )
		{
			var labelId = $(this).attr('id')+'_label';
			//var labelAdd = '<li>'+$('#'+labelId).html()+'</li>';
			var valueAdd = $(this).val();
			if ( teller > 0 )
			{
				valueAdd = ','+valueAdd;
				labelElement.html( '- Meerdere opties gekozen -' );
			}
			else
			{
				labelElement.html( $('#'+labelId).html() );
			}
			//labelElement.html( labelElement.html()+labelAdd );
			//inputElement.val( inputElement.html()+valueAdd );
			teller++;
		}
	});
	
	
	if ( labelElement.html() == '' )
	{
		labelElement.html(emptyLabel);
	}
	/*else
	{
		labelElement.html('<ul>'+labelElement.html()+'</ul>');
	}*/
	
	ajaxUpdate();
}

function closeMultiSelects(dontCloseId)
{
	$('.multiSelect > .multiSelectOptions').each(function() {
				
		if ( dontCloseId != $(this).attr('id') )
			$(this).hide();
			
	});
}

//close all open multiselects when you click outside them in the window.
$(document).click(function(e) {
	closeMultiSelects();
});


$(document).ready(function(){
	
	//prevent bubbling after the opening of the div by clicking on the toggler: else it will immediately close again!
	$('.multiSelect > .multiSelectToggler').each(function() {
		$(this).click(function(e){
			e.stopPropagation();
		});
	});
	
	//prevent bubbling of the onclick in document that closes all open multiSelects.
	//otherwise clicking an item in the container will close it!
	$('.multiSelect > .multiSelectOptions').each(function() {
		$(this).click(function(e){
			e.stopPropagation();
		});
	});
	
});


