function resetForm(form)
{
	if(form) {
		for(i=0; i < form.elements.length; i++) {
			if(form.elements[i].type != 'button' &&
			   form.elements[i].type != 'submit' &&
			   form.elements[i].type != 'reset')
			form.elements[i].value = '';
		}
		form.submit();
	}
}

function hideAll(className)
{
	$$('.' + className).each(function(element)
	{
		element.style.display = 'none';
	}
	);
}

function toggle(id)
{
	element = document.getElementById(id);
	if(element)
	{
		if(element.style.display == 'none')
		{
			element.style.display = '';
		}
		else
			element.style.display = 'none';
	}
}

function repopulateHidden(name)
{
	var listCheckbox =  $$('input[name="'+name+'_check"]');
	var ret = '';
	listCheckbox.each(function(el) {
			if(el.checked == true)
				ret += el.value + "|";
		});
	$(name).value=ret;
}

function visToggle(id)
{
	element = document.getElementById(id);
	if(element)
	{
		if(element.style.visibility == 'hidden')
		{
			element.style.visibility = '';
		}
		else
			element.style.visibility = 'hidden';
	}
}

function clean() {

}

function selectTransfer( sourceID, destinationID, saveListID, saveId)
{
	var sourceList = document.getElementById(sourceID);
	var destinationList = document.getElementById(destinationID);

	var saveList = document.getElementById(saveListID);

	var itemsForTransfer = new Array();

	var i;

	// Kijk wat verplaatst moet worden
	for(i = 0; i < sourceList.options.length; i++)
	{

		var option = sourceList.options[i];
		if(option.selected)
		{
			itemsForTransfer[itemsForTransfer.length] = new Option(option.text, option.value);
			itemsForTransfer[itemsForTransfer.length-1].style.backgroundColor = option.style.backgroundColor;
		}
	}

	// Verwijder ze uit de source list
	for(i = 0; i < sourceList.options.length; i++)
	{
		var option = sourceList.options[i];
		if(option.selected)
		{
			sourceList.options[i] = null;
			i--;
		}
	}

	// Verplaats ze
	for(i = 0; i < itemsForTransfer.length; i++)
	{
		var option = itemsForTransfer[i];
		destinationList.options[destinationList.options.length] = option;
		destinationList.options[destinationList.options.length-1].style.backgroundColor = option.style.backgroundColor;

	}

	var state = "";

	for(i = 0; i < saveList.options.length; i++)
	{
		state += saveList.options[i].value + "|";
	}
	$(saveId).value = state;

	//eval("document.forms[0].deelnemersGroep_State.value = state");

}


var AutoCompletes = Array();
var AutoCompleteCount = 0;

window.addEvent('beforeunload', function() {

	for(i = 0; i < AutoCompleteCount; i++)
	{
		AutoCompletes[i].destroy();
		AutoCompletes[i] = null;
	}
	AutoCompletes = null;
});



window.addEvent('load', function() {

	$$('.autoComplete').each(function(element)
	{
		element.id = 'autocomplete' + AutoCompleteCount;
		AutoCompletes[AutoCompleteCount] = new AutocompleteSelect('autocomplete' + AutoCompleteCount,null);
		AutoCompleteCount++;
	}
	);

	$$('.mlEditArea').each(function(element)
	{
		new MlEditor(element);
	}
	);
	
	$$('.filterArgumentsButton').each(function(element)
	{
		new ArgumentList(element);
	}
	);

	var generalTips = new Tips($$('.toolTip'), {
	    maxTitleChars: 50
	});

	var generalTips = new Tips($$('.toolTipVersioning'), {
	    maxTitleChars: 50
	});
	
	var generalTips = new Tips($$('.toolTipContactForm'), {
	    maxTitleChars: 50
	});
	
	
	/*Lightbox.init({showControls: true});*/
});


function toUrl(string) {
	string = string.toLowerCase();
	string = string.replace(/ & /g,"_");
	string = string.replace(/ \/ /g,"_");

	string = string.replace(/ /g,"_");
	string = string.replace(/\//g,"_");
	string = string.replace(/\\/g,"_");

	string = string.replace(/\"/g,"");
	string = string.replace(/'/g,"");

	return string;
}

function confirmAndStop(e)
{
	stopEvent(e);
	return confirm('Weet u dit zeker?');
}

function stopEvent(e)
{
	if (!e) var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
}

