function highlight(objet, myClass){ 
	d = document.getElementById(objet);
	
	if (d) {
  		d.className = myClass;
  	}
}

function depliance(objet){
	d = document.getElementById(objet);
	var etat = d.style.display;
	
	if (etat!='none') {
		d.style.display = 'none';
	} else {
		d.style.display = 'block';
	}
}

function SwitchArrow(objet1,objet2,id){
	d = document.getElementById(objet1+id);
	c = document.getElementById(objet2+id);
	d.style.display = 'block';
	c.style.display = 'none';
}

function SwitchLine(objet) {
	if (objet.style.backgroundColor=='rgb(216, 232, 204)'){
		objet.style.backgroundColor = '#f6f6f6';
	} else {
		objet.style.backgroundColor = 'rgb(216, 232, 204)';
	}
}

function ChangeColour(ensemble,val1,item,val2) {
	d = document.getElementById(ensemble);
	d.div.style.backgroundColor = val1;
	item.style.backgroundColor = val2;
}

function SwitchLang2(url,lang){
	if (lang=='fr'){
	document.location.href='spip.php?action=cookie&arg=var_lang&url='+url+'&var_lang=en';
	} else {
	document.location.href='spip.php?action=cookie&arg=var_lang&url='+url+'&var_lang=fr';
	}	
}

function SwitchLang3(url,lang){

document.location.href='spip.php?action=cookie&arg=var_lang&url='+url+'&var_lang='+lang;

}

function emailCheck (emailStr) {

	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	var matchArray=emailStr.match(emailPat)
	
	var champmail = document.getElementById('mail_inscription');
	var nom = document.getElementById('nom_inscription');
	var societe = document.getElementById('societe');
	var pays = document.getElementById('pays');
	var tel = document.getElementById('tel');
	var fonction = document.getElementById('fonction');
	var activite = document.getElementById('activite');
	
	if (nom.value == ""){
		document.location = "#champ_nom";
		nom.style.backgroundColor = 'red';
		alert("Vous n'avez pas renseignŽ le champ Nom");
		return false
	}
	
	if (societe.value == ""){
		document.location = "#champ_societe";
		societe.style.backgroundColor = 'red';
		alert("Vous n'avez pas renseignŽ le champ SociŽtŽ");
		return false
	}
	
	if (pays.value == ""){
		document.location = "#champ_pays";
		pays.style.backgroundColor = 'red';
		alert("Vous n'avez pas renseignŽ le champ Pays");
		return false
	}
	
	if (tel.value == ""){
		document.location = "#champ_tel";
		tel.style.backgroundColor = 'red';
		alert("Vous n'avez pas renseignŽ le champ TŽlŽphone");
		return false
	}
	
	if (matchArray==null) {
		document.location = "#champ_email";
		champmail.style.backgroundColor = 'red';
		champmail.style.fontWeight = 'bold';
		champmail.style.color = '#ffffff';
		alert("L'adresse e-mail indiquŽe est invalide.");
		return false
	}

	var user=matchArray[1]
	var domain=matchArray[2]

	if (user.match(userPat)==null) {
    	document.location = "#champ_email";
		champmail.style.backgroundColor = 'red';
		champmail.style.fontWeight = 'bold';
		champmail.style.color = '#ffffff';
		alert("L'adresse e-mail indiquŽe est invalide.");
    	return false
	}

	var IPArray=domain.match(ipDomainPat)
	
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
	    	if (IPArray[i]>255) {
	        	document.location = "#champ_email";
				champmail.style.backgroundColor = 'red';
				champmail.style.fontWeight = 'bold';
				champmail.style.color = '#ffffff';
				alert("L'adresse e-mail indiquŽe est invalide.");
				return false
	    	}
    	}
    	return true
	}

	var domainArray=domain.match(domainPat)
	
	if (domainArray==null) {
		document.location = "#champ_email";
		champmail.style.backgroundColor = 'red';
		champmail.style.fontWeight = 'bold';
		champmail.style.color = '#ffffff';
		alert("L'adresse e-mail indiquŽe est invalide.");
    	return false
	}

	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>4) {
		document.location = "#champ_email";
		champmail.style.backgroundColor = 'red';
		champmail.style.fontWeight = 'bold';
		champmail.style.color = '#ffffff';
		alert("L'adresse e-mail indiquŽe est invalide.");
   		return false
	}

	if (len<2) {
  		document.location = "#champ_email";
		champmail.style.backgroundColor = 'red';
		champmail.style.fontWeight = 'bold';
		champmail.style.color = '#ffffff';
		alert("L'adresse e-mail indiquŽe est invalide.");
   		return false
	}
	
	if (fonction.value == ""){
		document.location = "#champ_fonction";
		fonction.style.backgroundColor = 'red';
		alert("Vous n'avez pas renseignŽ le champ Fonction");
		return false
	}
	
	if (activite.value == ""){
		document.location = "#champ_activite";
		activite.style.backgroundColor = 'red';
		alert("Vous n'avez pas renseignŽ le champ ActivitŽ");
		return false
	}
	
	return true;
}

function switchMsgAuteur() {
	d = document.getElementById("formauteurpreview");
	var orig = document.getElementById("formauteurorig");
		if (d) {
			d.style.opacity = 0.5;
			orig.style.opacity = 1;
		}
	
	}