var		activeEmployee	=	0;

/**
 *	Our treatment select handler. Shows the dropdown box,
 *	clears any previous values and loads the options for
 *	the given type.
 *
 *	@param	type	Int		The treatment type (1 = dames, 2 = heren, etc).
 *	@return	Void
**/
function selectTreatment (type) {
	showDropDown();
	clearDropDown();
	addTreatments(type);
}


/**
 *	Show the select box for treatments.
**/
function showDropDown () {
	var selectElement						=	$('treatmentSelect');
	selectElement.style.display = 'block';
}


/**
 *	Clear all options from the treatment select box.
**/
function clearDropDown () {
	var selectElement	=	$('treatmentSelect');
	while(selectElement.firstChild) 
		selectElement.removeChild(selectElement.firstChild);
}


/**
 *	Add treatments of the specified type to the select box.
 *
 *	Basicly this loops over the treatments [type] array and calls
 *	createOption for each treatment.
 *
 *	@param	type	Int		The treatment type (1 = dames, 2 = heren, etc).
 *	@return	Void.
**/
function addTreatments (type) {
	var item;
	var selectElement	=	$('treatmentSelect');
	
	for(item in treatments[type])
		selectElement.appendChild(createOption(type, treatments[type][item]));
}


/**
 *	Create a new option for the select dropdown with the given
 *	treatment. We require the type to append to our textnode since
 *	we build up the 'code' part dynamically.
 *
 *	Note that code should always be a [type][2-digit code], so if the code
 *	is under 10 we append a zero to it.
 *
 *	@param	type				Int			The treatment type (1 = dames, 2 = heren, etc).
 *	@param	Treatment		Array 	Data array, contains treatment data like code, name, id.
 *	@return	DOM Element	Returns an 'option' DOM element with value and content.
**/
function createOption (type, treatment) {
	var code				=	treatment['code'] < 10 ? '0' + treatment['code'] : treatment['code'];
	var optionValue = document.createTextNode(type + code + ' ' + treatment['name']);
	var optionNode	=	document.createElement('option');
	
	optionNode.value = treatment['id'];
	
	if (treatment['id'] == oldTreatmentType)
		optionNode.selected = true;
	
	optionNode.appendChild(optionValue);
	return optionNode;
}


/**
 *	If the active employee is changed, we remove the
 *	picture of the previously selected employee (if any)
 *	and show the picture of the newly selected employee
 *	if available.
**/
function updateEmployeePicture () {
	if(activeEmployee) {
		var	oldPicture		=	$('employeePicture_' + activeEmployee);
		if (oldPicture)
			oldPicture.style.display	=	'none';
	}
	var employeeSelect	=	$('employeeId');
	activeEmployee			=	employeeSelect.value;

	var newPicture			=	$('employeePicture_' + activeEmployee);

	if(!newPicture)
		return;

	newPicture.style.display	=	'block';
}
