//====================== fonctions generales

var erreurs = "";

function getParent(control, parentclass) {
	while((control.className != parentclass)
		&& (control.nodeName != 'BODY')) control = control.parentNode;
	return control;
}

function erreur(objid,msg) {
	erreurs = erreurs + "\n" + msg;
	return 1;
}

function remettre(context) {
	if((context.type == 'checkbox') || (context.type == 'radio')) {
		context = getParent(context,'boundary');		
	}
	context.style.backgroundColor = '#E6F2FB';
	document.getElementById("Erreur").style.display = 'none';
}

function propagate(obj, targetid) {
	var targetobj = document.getElementById(targetid);
	targetobj.value = obj.value;
}

//====================== fonctions de validation

function checkEmpty(id,msg) {
	if(document.getElementById(id).value == "") return erreur(id,msg);
	else return 0;
}

function checkSet(selectid, fieldid,msg) {
	var sel = document.getElementById(selectid);
	if(sel.value == 'none') return erreur(selectid,msg);
	else if(sel.value == 'other' || sel.value == '' || sel.value == null) {
		if(document.getElementById(fieldid).value == "") return erreur(fieldid,msg);
		else return 0;
	}
	return 0;
}

//====================== autres (spécifiques)

function btnIn(obj) {
	obj.style.borderColor = "#688333";
}

function btnOut(obj) {
	obj.style.borderColor = "#F4F8E0";
}

function ValiderFormulaire() {
	var validation = 0;	
	validation += checkEmpty("Nom","Le nom de l'envoyeur doit être spécifié.");
	validation += checkEmpty("Email","L'e-mail de l'envoyeur doit être spécifié.");
	var email1 = document.getElementById("Email").value;
	if(email1.length < 6 || email1.indexOf("@") == -1) validation += erreur("Email","L'e-mail de l'envoyeur doit être valide");
	validation += checkEmpty("Description","Une description non vide doit être fourni.");
	validation += checkEmpty("Fichier","Un nom de fichier local doit être fourni.");
	if(validation == 0) {
		document.getElementById("form1").submit();
	}
	else {
		alert("Veuillez valider les champs manquants ou incorrects. "+erreurs);
		erreurs = "";
	}
}

function ValiderFormulaire2() {
	var validation = 0;	
	validation += checkEmpty("Description","Une description non vide doit être fourni.");
	validation += checkEmpty("Fichier","Un nom de fichier local doit être fourni.");
	if(validation == 0) {
		document.getElementById("form1").submit();
	}
	else {
		alert("Veuillez valider les champs manquants ou incorrects. "+erreurs);
		erreurs = "";
	}
}

function Visualiser() {
	document.forms.form1.previsualiser.value = "oui";
	document.getElementById("form1").submit();
}

function HideDiv(obj) {
	obj.style.display = "none";
	//obj.offsetParent.style.display = "none";
}
