function Alerte(element) {
 var classelement = document.getElementById(element).className;
 //alert(classelement);
 if (classelement!='') document.getElementById(element).className= classelement+' alerte';
 else document.getElementById(element).className= 'alerte';
}

function messagerie(adresse,taille) {
		mes=0;
	
		validelog = false;
		validedom = false;
		valideext = false;
		
		arob = adresse.lastIndexOf("@");
		login = adresse.substring(0,arob);
		
		pointfinal = adresse.lastIndexOf(".");
		extension = adresse.substring(pointfinal,taille);
		
		domaine = adresse.substring(arob+1,pointfinal);
		
		
		if ( login.length > 1 ) {
		validelog = true;
		} else {
		  validelog = false;
		}
		
		if ( domaine.length > 1 ) {
		validedom = true;
		} else {
			 validelog = false;
		}
		if ( pointfinal > -1 && (extension.length == 3 || extension.length == 4 || extension.length == 5) ) {
		   valideext = true;
		} else {
		  valideext = false;
		}
		
		if ( validelog == false || validedom == false || valideext == false) {
		   mes=1;
		  
		} 
		return mes;
}

function ChangerClasse () { // parametre (element,classe,...)
  var i,args=ChangerClasse.arguments;
  for (i=0; i<(args.length); i+=2) {
  	if (document.getElementById) {
    	document.getElementById(args[i]).className = args[i+1];
  	} else if (document.layers) {
    	document[args[i]].className = args[i+1];
	} else if (document.all) {
    	document.all[args[i]].className = args[i+1];
	}
  }
}

function envoyerMess(type) { //modif Henriette 16/11/2010 pour regrouper les controles
  if (type=="enquete") var champs = ['textAnnees','selectRdt','textPrenom','textNom','textAdr','textCP','textVille',
  'textEmail','textTel','textSurf'];
  else if (type=="technosol") {
	  var champs = ['nom','prenom','societe','adresse','codepost','commune','textEmail','picto'];
	  var champs2=['fournisseur','surface'];
  } else if (type=="agroforum") {
	  var champs = ['nom','prenom','societe','adresse','codepost','commune','textEmail','picto'];
	  var champs2=['mg','mf','to','co'];
  }
  var i;
  var cpt=0;
  for (i=0 ; i < champs.length ; i++) {		
	var champ = champs[i];
	document.getElementById(champ).className = '';
	if (!document.getElementById(champ).value) {
			Alerte(champ);
			cpt++;
	} else if (document.getElementById(champ).value && champ=="textEmail" && messagerie(document.getElementById(champ).value,document.getElementById(champ).value.length)==1) {
			Alerte(champ);
			cpt++;
	}
  }
 if (type=="agroforum") {
	 if (document.mail.francay.checked==false && document.mail.boe.checked==false) {
		document.mail.francay.className='radio alerte';
		document.mail.boe.className='radio alerte';
		cpt++;
	}
	for (i=0 ; i < champs2.length ; i++) {		
		var champ = champs2[i];
		document.getElementById(champ).className = '';
	}
	if (!document.mail.mg.value && !document.mail.mf.value && !document.mail.to.value && !document.mail.co.value) {
		Alerte('mg');
		Alerte('mf');
		Alerte('to');
		Alerte('co');
		cpt++;
	}
 }
  
 if (type=="technosol") { // contrôles supplémentaires
	if (document.mail.cultive[0].checked==false && document.mail.cultive[1].checked==false) {
		document.mail.cultive[0].className='radio alerte';
		document.mail.cultive[1].className='radio alerte';
		cpt++;
	} else  if (document.mail.cultive[0].checked==true) {
		for (i=0 ; i < champs2.length ; i++) {		
			var champ = champs2[i];
			document.getElementById(champ).className = '';
			if (!document.getElementById(champ).value) {
					Alerte(champ);
					cpt++;
			}
		}
		if (document.getElementById('oleique').checked==false && document.getElementById('linoleique').checked==false) {
				Alerte('oleique');
				Alerte('linoleique');
				cpt++;
		}
	}
 } // fin if (type=="technosol")
  
  if (cpt==0) {
	  if (type=="enquete") document.forms[0].action.value="envoyerEnquete";
	  document.forms[0].submit();
  }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);


function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function OuvrirFenetre(url,nom)
{
var fenetre= window.open(url,nom,'toolbar=no,menubar=no,location=no,directories=no,status=no,scrollbars=no,resizable=1,width=400,height=300,innerWidth=400,innerHeight=300');
fenetre.moveTo( ( screen.availWidth - 400) / 2 , (screen.availHeight - 300) /2 );
}

function OuvrirCalculette(nom){// calcul date de récolte fourrage
	
	window.open('',nom,'toolbar=1,location=0,directories=0,menuBar=1,scrollbars=1,resizable=1,width=680,height=540,left=100,top=50');   
}

function OuvrirLexique(url) {
	window.open(url,"lexique","width=600,height=400,toolbar=0,status=1,directories=0,menubar=1,scrollbars=1,resizable=1,left=200,top=200");
	}

function OuvrirFenetre600(url,nom)
{
var fenetre= window.open(url,nom,'toolbar=no,menubar=no,location=no,directories=no,status=no,scrollbars=no,resizable=1,width=600,height=450,innerWidth=600,innerHeight=450');
fenetre.moveTo( ( screen.availWidth - 600) / 2 , (screen.availHeight - 450) /2 );
}

function OuvrirPetiteFenetre(url) {
	window.open(url,"etape","width=400,height=400,toolbar=0,status=0,directories=0,scrollbars=1,resizable=0");
	}

function OuvrirZoom(nom) //utilisée pour les panneaux Agroforum //
	{
	window.open("",nom,"width=780,height=580,toolbar=0,status=0,directories=0,scrollbars=1,resizable=1,left=20,top=20");
	}

function OuvrirResultatsColza(url) 
	{
	window.open(url,"essais","width=550,height=450,toolbar=0,status=0,directories=0,scrollbars=1,resizable=0");
	}

function OuvrirBelgique(url) {
	window.open(url,"etape","width=600,height=460,toolbar=1,status=1,directories=1,scrollbars=1,resizable=1");
	}
	
function OuvrirVoeux(url,nom) {
var fenetre= window.open(url,nom,'toolbar=no,menubar=no,location=no,directories=no,status=no,scrollbars=no,resizable=1,width=470,height=660,innerWidth=470,innerHeight=660');
fenetre.moveTo( ( screen.availWidth - 600) / 2 , (screen.availHeight - 600) /10 );
}


function   verif() {
     document.calque.top=pageYOffset;
	document.calque.left=window.innerWidth-document.calque.document.width;
     setTimeout('verif()',20)
	}
function replacer() {
Navig=navigator.appName
if(Navig=='Netscape')
    {verif();}
else
     {calque.style.top=document.body.scrollTop;
calque.style.left=document.body.clientWidth-document.all.calque.offsetWidth;
     }
}

function montrerCalqueMAS() {//calque1,contenu,...
	var i,args=montrerCalqueMAS.arguments; 
  	for (i=0; i<(args.length); i+=2) {   
		if (document.getElementById) {
			if (document.getElementById(args[i]).style.visibility == 'visible') CacherCalque(args[i]);
			else  MontrerCalque(args[i]);
				
		} else {
			if (document.layers) {
				if (document[args[i]].visibility == 'show') CacherCalque(args[i]); 
				else  MontrerCalque(args[i]);
			} else if (document.all) {
				if (document.all[args[i]].style.visibility == 'visible' ) CacherCalque(args[i]); 
				else  MontrerCalque(args[i]);
			} 
		}
  	}
}


function MontrerCalque () { // parametres (calque1,calque2,...)
  var i,args=MontrerCalque.arguments; 
  for (i=0; i<(args.length); i+=1) {   
  	if (document.getElementById) {
    	document.getElementById(args[i]).style.visibility = 'visible';
		document.getElementById(args[i]).style.height = '100%';
		document.getElementById(args[i]).style.display = 'block';
	} else if (document.layers) {
    	document[args[i]].visibility = 'show';
		document[args[i]].height = '100%';
		document[args[i]].display = 'block';
	} else if (document.all) {
		document.all[args[i]].style.visibility = 'visible';
		document.all[args[i]].style.height = '100%';
		document.all[args[i]].style.display ='block';
	}
  }
}

function CacherCalque () { // paramètre (calque1,calque2,...)
  var i,args=CacherCalque.arguments;
  for (i=0; i<(args.length); i+=1) {
	if (document.getElementById) {
    	document.getElementById(args[i]).style.visibility = 'hidden';
		document.getElementById(args[i]).style.height = '0';
		document.getElementById(args[i]).style.display = 'none';
  	} else if (document.layers) {
    	document[args[i]].visibility = 'hide';
		document[args[i]].height = '0';
		document[args[i]].display = 'none';
	} else if (document.all) {
    	document.all[args[i]].style.visibility = 'hidden';
		document.all[args[i]].style.height = '0';
		document.all[args[i]].style.display = 'none';
	}
  } 
}

function Deplacer () {
	var i,args=Deplacer.arguments;
	for (i=0; i<(args.length); i+=1) {
  		if (document.layers)
    	document[args[i]].top = '400';
 		else if (document.all)
    	document.all[args[i]].style.top = '400';
  		else if (document.getElementById)
		document.getElementById(args[i]).style.top = '400';
	}
}

function mail(prenom,nom,nome) {
fenetre=window.open("","courriel","toolbar=no,menubar=no,location=no,directories=no,status=no,scrollbars=no,resizable=1,width=300,height=150,innerWidth=300,innerHeight=150,left=200,top=200");
fenetre.document.write("<html><head><title>Contacter "+prenom+" "+nom+"</title>");
fenetre.document.write("<style type=text/css><!--a {text-decoration: underlined; color : #00582A} a:hover {text-decoration: none; color : #00582A} p {  font-family: Arial, Verdana, Helvetica; font-size: 12pt; color: #000000}-->");
fenetre.document.write("</style><script language=javascript type=text/javascript>");
fenetre.document.write("setTimeout(\'window.close()\',10000)</script></head>");
fenetre.document.write("<body bgcolor=#FFCC00>");
fenetre.document.write("<p align=center>Pour envoyer un courriel à<br><br>"+prenom+" "+nom+" :<br><br>");
fenetre.document.write("<a href=mailto:"+nome+"@maisadour.com?subject=from%20maisadour-semences>Cliquez ici</a></p></body></html>");
}
function mailspe(prenom,nom,nome,objet) {
fenetre=window.open("","courriel2","toolbar=no,menubar=no,location=no,directories=no,status=no,scrollbars=no,resizable=1,width=300,height=150,innerWidth=300,innerHeight=150,left=200,top=200");
fenetre.document.write("<html><head><title>Contacter "+prenom+" "+nom+"</title>");
fenetre.document.write("<style type=text/css><!--a {text-decoration: underlined; color : #00582A} a:hover {text-decoration: none; color : #00582A} p {  font-family: Arial, Verdana, Helvetica; font-size: 12pt; color: #000000}-->");
fenetre.document.write("</style><script language=javascript type=text/javascript>");
fenetre.document.write("setTimeout(\'window.close()\',10000)</script></head>");
fenetre.document.write("<body bgcolor=#FFCC00>");
fenetre.document.write("<p align=center>Pour envoyer un courriel à<br><br>"+prenom+" "+nom+" :<br><br>");
fenetre.document.write("<a href=mailto:"+nome+"@maisadour.com?subject="+objet+">Cliquez ici</a></p></body></html>");
}
function mailtech(nome) {
fenetre=window.open("","courriel3","toolbar=no,menubar=no,location=no,directories=no,status=no,scrollbars=no,resizable=1,width=300,height=150,innerWidth=300,innerHeight=150,left=200,top=200");
fenetre.document.write("<html><head><title>Informations complémentaires</title>");
fenetre.document.write("<style type=text/css><!--a {text-decoration: underlined; color : #00582A} a:hover {text-decoration: none; color : #00582A} p {  font-family: Arial, Verdana, Helvetica; font-size: 12pt; color: #000000}-->");
fenetre.document.write("</style><script language=javascript type=text/javascript>");
fenetre.document.write("setTimeout(\'window.close()\',10000)</script></head>");
fenetre.document.write("<body bgcolor=#FFCC00>");
fenetre.document.write("<p align=center>Pour adresser par mail une demande d'informations techniques à l'équipe de Maïsadour Semences<br><br>");
fenetre.document.write("<a href=mailto:"+nome+"@maisadour.com?subject=Demande%20d\'informations%20techniques>Cliquez ici</a></p></body></html>");
}
