// rafraichissement de l'encart editeurs


function upDateEditeur() {
	
	divUp = $('EditeurMenuVertical');
	var tmpUrl = "lib/editeurs.php";
	o_options = new Object();
	o_options = {	method:'post',
					frequency:3, 
					parameters:{langue:$('EditeurLangue').value},
					onSuccess:function(t) {
						
					}
				};
	var tmpReq = new Ajax.PeriodicalUpdater(divUp,tmpUrl,o_options);
}
// envoi formulaire d'inscription newsletter
function sendNl(nom) {

	var tmpEmail = $('nlMail').value;
	var tmpLangue = $('langue').value;
	
	if(checkMail(tmpEmail)) {
		
		o_options = new Object();
		o_options = {method: 'post', 
					 asynchronous:true,
					 parameters:{email:tmpEmail, langue:tmpLangue},
					 onSuccess:function(t){
							if(t.responseText !== "NOK") {
								Element.update(nom,t.responseText);
								$(nom).show();
							}
						 }
					};
		new Ajax.Request("lib/newsletter.php", o_options);
	} else {
		alert("Please, fill the email field.");	
	}
	
}
// envoi du formulaire d'enquete
function sendReq() {
	
	var tmpEmail = $('email').value;
	var tmpLangue = $('langue').value;
	
	if(checkMail(tmpEmail)) {
	
		var tmpChoix = 0;
		
		for(i=0;i<3;i++) {
			if($('enqueteForm').enquete[i].checked) {
				tmpChoix = $('enqueteForm').enquete[i].value;
				break;
			}
		}
		
		o_options = new Object();
		o_options = {method: 'post', 
					 asynchronous:true,
					 parameters:{email:tmpEmail, enquete:tmpChoix, langue:tmpLangue},
					 onSuccess:function(t){
							if(t !== "NOK") {
								Element.update('texteHPenqueteDiv',t.responseText);
							}
						 }
					};
		new Ajax.Request("lib/enquete.php", o_options);
	} else {
		alert("Please, fill the email field.");	
	}
	
}
// authentification accès intranet
function sendIntranet() {
	
	var tmpEmail = $('login').value;
	var tmpPwd = $('pwd').value;
	
	if(checkMail(tmpEmail) && tmpPwd !=="") {
	
		o_options = new Object();
		o_options = {method: 'post', 
					 asynchronous:true,
					 parameters:{mail:tmpEmail, pwd:tmpPwd},
					 onSuccess:function(t){
							if(t.responseText !== "false") {
								window.location.href = window.location.href +t.responseText;
							} else {
								$('errorMsg').innerHTML = "Nous n'avons pas pu vous authentifier";	
							}
						 }
					};
		new Ajax.Request("lib/login.php", o_options);
	} else {
		$('errorMsg').innerHTML = "Format invalide.";	
	}
	
}

// autres fonctions
function Click(cible) {
	$('redirectionForm').action = cible;
	$('redirectionForm').submit();
}

function MM_preloadImages() {
  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 checkMail(myMail){
	var mail = /^[a-zA-Z0-9\-]+[a-zA-Z0-9\._]+@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/; 
	return mail.test(myMail);
}
// affichage des schemas
function afficherSchema(source) {
	$("schemaDiv").innerHTML = "<img src='" +source+ "' width=600 onclick=\"javascript:$('schemaDiv').hide()\"/>";
	if (navigator.appName=="Microsoft Internet Explorer") 
			{
			offsety = document.body.scrollTop;
			}
	  	else 
			{
			offsety = window.pageYOffset;
			}
	$("schemaDiv").style.top = offsety+"px";
	$("schemaDiv").show();
}

// gestion de l'affichage du div worldwide
var delay = 400;
var timeOut;

function hideDelai() {
	timeOut = setTimeout('hideDiv()',delay);	
}
function clearDelai() {
	if(timeOut)
		clearTimeout(timeOut);
}
function hideDiv() {
	$('worldwideDiv').hide();	
}

// gestion de l'affichage des solutions
var solOpen = 0;
function Over(id) 
{
	if(id !== solOpen) {
		if(solOpen > 0) {
			fondOut(solOpen);
		}
		fondOver(id);
	}
}
function Out() 
{
	if(solOpen > 0) {
		fondOut(solOpen);
		solOpen = 0;
	}
}
function fondOver(id)
{
	var num = id.toString();
		
	if(num == "100") { // cas de l'encart
		$("HGencart").className = "tableCoinHpHGOver";
		$("HDencart").className = "tableCoinHpHDOver";
		$("BGencart").className = "tableCoinHpBGOver";
		$("BDencart").className = "tableCoinHpBDOver";
		$("Hencart").className = "tableCoinHpHOver";
		$("Bencart").className = "tableCoinHpBOver";
		$("Gencart").className = "tableCoinHpGOver";
		$("Dencart").className = "tableCoinHpDOver";
		$("Centerencart").className = "tableCoinCenterOver";
		if($("TitreEncart")) {
			$("TitreEncart").className = "hpTitreEncartOver";
		}
		if($("ImgEncart")) {
			$("ImgEncart").src = imgOver;
		}
		if($("AccrocheEncart")) {
			$("AccrocheEncart").className = "hpAccrocheEncartOver";
		}
	} else {
		$("tableCoinHpHG" + num).className = "tableCoinHpHGOver";
		$("tableCoinHpHD" + num).className = "tableCoinHpHDOver";
		$("tableCoinHpBG" + num).className = "tableCoinHpBGOver";
		$("tableCoinHpBD" + num).className = "tableCoinHpBDOver";
		$("tableCoinHpH" + num).className = "tableCoinHpHOver";
		$("tableCoinHpB" + num).className = "tableCoinHpBOver";
		$("tableCoinHpG" + num).className = "tableCoinHpGOver";
		$("tableCoinHpD" + num).className = "tableCoinHpDOver";
		$("tableCoinCenter" + num).className = "tableCoinCenterOver";
		if($("hpTitre" + num)) {
			$("hpTitre" + num).className = "hpTitreOver";
		}
		if($("hpImg" + num)) {
			$("hpImg" + num).src = imgOver;
		}
		if($("hpAccroche" + num)) {
			$("hpAccroche" + num).className = "hpAccrocheOver";
		}
	}
	solOpen = id;
}
function fondOut(id)
{
	var num = id.toString();
	if(num == "100") { // cas de l'encart
		$("HGencart").className = "tableCoinHpHGEncart";
		$("HDencart").className = "tableCoinHpHDEncart";
		$("BGencart").className = "tableCoinHpBGEncart";
		$("BDencart").className = "tableCoinHpBDEncart";
		$("Hencart").className = "tableCoinHpHEncart";
		$("Bencart").className = "tableCoinHpBEncart";
		$("Gencart").className = "tableCoinHpGEncart";
		$("Dencart").className = "tableCoinHpDEncart";
		$("Centerencart").className = "tableCoinCenterEncart";
		if($("TitreEncart")) {
			$("TitreEncart").className = "hpTitreEncart";
		}
		if($("ImgEncart")) {
			$("ImgEncart").src = imgOver;
		}
		if($("AccrocheEncart")) {
			$("AccrocheEncart").className = "hpAccrocheEncart";
		}
	} else {
		$("tableCoinHpHG" + num).className = "tableCoinHpHG";
		$("tableCoinHpHD" + num).className = "tableCoinHpHD";
		$("tableCoinHpBG" + num).className = "tableCoinHpBG";
		$("tableCoinHpBD" + num).className = "tableCoinHpBD";
		$("tableCoinHpH" + num).className = "tableCoinHpH";
		$("tableCoinHpB" + num).className = "tableCoinHpB";
		$("tableCoinHpG" + num).className = "tableCoinHpG";
		$("tableCoinHpD" + num).className = "tableCoinHpD";
		$("tableCoinCenter" + num).className = "tableCoinCenter";
		if($("hpTitre" + num)) {
			$("hpTitre" + num).className = "hpTitre";
		}
		if($("hpImg" + num)) {
			$("hpImg" + num).src = img;
		}
		if($("hpAccroche" + num)) {
			$("hpAccroche" + num).className = "hpAccroche";
		}
	}
}

// validation de formulaire

function valForm(form) {
	//if(lg == "fr") {
		err = false;
		if(form == "formDejaInscrit") {
			if($("emailInscrit")) {
				if(checkMail($("emailInscrit").value) == false) {
					alert ("Veuillez ressaisir votre mail. Merci");	
					err = true;
				}
			}
		} else {
			if($("email")) {
				if(checkMail($("email").value) == false) {
					alert ("Veuillez ressaisir votre mail. Merci");
					err = true;
				}
			}
			if($("nom")) {
					if($("nom").value == "") {
						alert("Veuillez entrer votre nom. Merci");
						err = true;
					}
			}
			if($("prenom")) {
					if($("prenom").value == "") {
						alert("Veuillez entrer votre prenom. Merci");
						err = true;
					}
			}
			if($("societe")) {
					if($("societe").value == "") {
						alert("Veuillez saisir votre societe. Merci");	
						err = true;
					}
			}
			if($("adresse")) {
					if($("adresse").value == "") {
						alert("Veuillez saisir l'adresse de votre societe. Merci");	
						err = true;
					}
			}
			if($("ville")) {
					if($("ville").value == "") {
						alert("Veuillez saisir la ville de votre societe. Merci");
						err = true;
					}
			}
			if($("cp")) {
					if($("cp").value == "") {
						alert("Veuillez saisir le code postal de votre societe. Merci");	
						err = true;
					}
			}
			if($("message")) {
					if($("message").value == "") {
						alert("Veuillez saisir votre message. Merci");	
						err = true;
					}
			}
		}
		if(err == false) {
			$(form).submit();
		}
	//}
}
