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 showNice(id, parent)
{
	element = document.getElementById(id);
	if(element)
	{
		element.style.display = '';
		parent.addClass('toggle-active');
		parent.removeClass('toggle-inactive');
	}
}

function hideNice(id, parent)
{
	element = document.getElementById(id);
	if(element)
	{
		element.style.display = 'none';
		parent.removeClass('toggle-active');
		parent.addClass('toggle-inactive');
	}
}

function hideNiceAll(className, classParent)
{
	hideAll(className);
	$$('.' + classParent).each(function(element)
	{
		element.removeClass('toggle-active');
		element.addClass('toggle-inactive');
	}
	);
	
}



function toggleNiceClass(id, parent)
{
	element = document.getElementById(id);
	parent = $(parent);
	if(element)
	{
		if(element.style.display == 'none')
		{
			showNice(id, parent);
		}
		else
		{
			hideNice(id, parent);
		}
	}
}

function toggleNice(id, parent)
{
	element = document.getElementById(id);
	if(element)
	{
		if(element.style.display == 'none')
		{
			showNice(id, parent);
		}
		else
		{
			hideNice(id, parent);
		}
	}
}

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


function hide(id)
{
	element = document.getElementById(id);
	if(element)
	{
		if(element.style.display != 'none')
		{
			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 toggleCheck(id)
{
	element = document.getElementById(id);
	if(element)
	{
		if(element.checked == false)
		{
			element.checked = true;
		}
		else
		{
			element.checked = false;
		}
		element.fireEvent('onchange');
		
	}
}

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;
}


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

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

var TagSelects = Array();
var TagSelectCount = 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;
	
	for(i = 0; i<  TagSelectCount; i++)
	{
		TagSelects[i].destroy();
		TagSelects[i] = null;
	}
	TagSelects = null;
});

window.addEvent('load', function() {
	
	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
	});
	
	$$('.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();
	}
	);
});

function changeImage(src, target, alt) {
	var foto = $(target);
	foto.src = src;
	foto.alt = alt;
	foto.title = alt;
}


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();
}

function changeDate(value)
{

	switch(value)
	{
		case '1k':
		{
			$('global_from_day').value = '01';
			$('global_from_month').value = '01';
			$('global_to_day').value = '31';
			$('global_to_month').value = '03';
			break;
		}
		case '2k':
		{
			$('global_from_day').value = '01';
			$('global_from_month').value = '04';
			$('global_to_day').value = '30';
			$('global_to_month').value = '06';
			break;
		}
		case '3k':
		{
			$('global_from_day').value = '01';
			$('global_from_month').value = '07';
			$('global_to_day').value = '30';
			$('global_to_month').value = '09';
			break;
		}
		case '4k':
		{
			$('global_from_day').value = '01';
			$('global_from_month').value = '10';
			$('global_to_day').value = '31';
			$('global_to_month').value = '12';
			break;
		}
		case '1j':
		{
			$('global_from_day').value = '01';
			$('global_from_month').value = '01';
			$('global_to_day').value = '30';
			$('global_to_month').value = '06';
			break;
		}
		case '2j':
		{
			$('global_from_day').value = '01';
			$('global_from_month').value = '07';
			$('global_to_day').value = '31';
			$('global_to_month').value = '12';
			break;
		}
		default: 
		{
			show('global_data_row_1');
			show('global_data_row_2');
			break;
		}
	}
}

