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 showAll(className)
{
	$$('.' + className).each(function(element)
	{
		element.style.display = '';
	}
	);
}

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

function toggleAll(className)
{
	$$('.' + className).each(function(element)
	{
		if(element)
		{
			if(element.style.display == 'none')
			{
				element.style.display = '';
			}
			else
				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 toggleApprove(className, value)
{

	$$('.' + className).each(function(element)
	{
		if(element.disabled == false)
		{
				element.checked = value;
		}
	}
	);
}

function toggleDisable(id)
{
	element = document.getElementById(id);
	if(element)
	{
		if(element.getProperty('disabled') == '')
		{
			element.setProperty('disabled', 'true');
		}
		else
			element.setProperty('disabled', '');
	}
}

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;

var AutoCompletesAjax = Array();
var AutoCompleteCountAjax = 0;

var UbbEditors = Array();
var UbbCount = 0;

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

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



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

	$$('.autoComplete').each(function(element)
	{
		if(element.id == null || element.id == '')
			element.id = 'autocompleteAjax' + AutoCompleteCountAjax;
		
		element.id = 'autocomplete' + AutoCompleteCount;
		AutoCompletes[AutoCompleteCount] = new AutocompleteSelect(element.id,null);
		AutoCompleteCount++;
	}
	);
	
	$$('.autoCompleteAjax').each(function(element)
	{
		if(element.id == null || element.id == '')
			element.id = 'autocompleteAjax' + AutoCompleteCountAjax;
		
		AutoCompletesAjax[AutoCompleteCountAjax] = new AutocompleteSelectAjax(element.id,null);
		AutoCompleteCountAjax++;
	}
	);

	$$('.mlEditArea').each(function(element)
	{
		new MlEditor(element);
	}
	);
	
	$$('.filterArgumentsButton').each(function(element)
	{
		new ArgumentList(element);
	}
	);
	
	
	
	$$('textarea.ubb').each(function(element)
	{
		UbbEditors[UbbCount] = new UbbEditor(element);

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

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


	var generalTips = new Tips($$('.toolTipVersioning'), {
	    maxTitleChars: 50
	});
	
	var generalTips = new Tips($$('.toolTipContactForm'), {
	    maxTitleChars: 50
	});
	
	$$('input.confirm').each(function(element)
	{
		element.addEvent('click', confirmAndStop);
	}
	);
	
	$$('.cancel_click_bubble').each(function(element)
	{
		element.addEvent('click', stopEvent);
	}
	);
	
	$$('.mooblink').each(function(element)
	{
		
		blink = new mooBlink(element);
		blink.blink();
		
	}
	);
	
	/*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)
{
	e = new Event(e);
	//e.stop();
	if(! confirm('Weet u dit zeker?') )
		e.stop();
}

function stopEvent(e)
{

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