function afficherCacher(id) {
	var element = document.getElementById(id);
	if (element.style.display == "none") {
		element.style.display = "block";
	}
	else {
		element.style.display = "none";
	}
}


function addContact(currentSelect) {
	var hiddenField = document.liste.contacts;
	var hiddenValue = document.liste.contacts.value;
	var textareaField = document.liste.contactslist;
	var textareaValue = document.liste.contactslist.value;
	
	var newValue = new RegExp(" " + currentSelect.options[currentSelect.selectedIndex].value + " ");
	var alreadyThere = hiddenValue.search(newValue);

	if (hiddenValue == '') {
		if (currentSelect.options[currentSelect.selectedIndex].value != '' && alreadyThere == -1) {
			hiddenValue += " " + currentSelect.options[currentSelect.selectedIndex].value+" ";
			textareaValue += currentSelect.options[currentSelect.selectedIndex].text+"\n";
		}
	} else {
		if (currentSelect.options[currentSelect.selectedIndex].value != '' && alreadyThere == -1) {
			hiddenValue +=  " " + currentSelect.options[currentSelect.selectedIndex].value + " ";
			textareaValue += currentSelect.options[currentSelect.selectedIndex].text+"\n";
		}
	}
	hiddenValue = hiddenValue.replace(/\s+/g, " ");

	hiddenField.value = hiddenValue;
	textareaField.value = textareaValue;
	currentSelect.selectedIndex = 0;
}


function deleteContact(currentSelect) {
	var hiddenField = document.liste.contacts;
	var hiddenValue = document.liste.contacts.value;
	var textareaField = document.liste.contactslist;
	var textareaValue = document.liste.contactslist.value;
		
	if (hiddenValue != '') {
		var change1 = new RegExp(" " + currentSelect.options[currentSelect.selectedIndex].value + " ");	
		var change3 = new RegExp(currentSelect.options[currentSelect.selectedIndex].text + "\\s*\\n");

		hiddenValue = hiddenValue.replace(change1, " ");
		hiddenValue = hiddenValue.replace(/\s+/g, " ");

		textareaValue = textareaValue.replace(change3, "");
	} 

	hiddenField.value = hiddenValue;
	textareaField.value = textareaValue;
	currentSelect.selectedIndex = 0;
}

function resetContact() {
	var hiddenField = document.liste.contacts;
	var textareaField = document.liste.contactslist;

	hiddenField.value = "";
	textareaField.value = "";
}
