// Detection de la version de flash pour le header
var MM_contentVersion = 8;
var MM_FlashCanPlay = "t";
function FlashHeader(LeFlash , Limage, MM_FlashCanPlay, modesecur){

var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
if ( plugin ) {
  var words = navigator.plugins["Shockwave Flash"].description.split(" ");
     for (var i = 0; i < words.length; ++i)
     {
  if (isNaN(parseInt(words[i])))
  continue;
  var MM_PluginVersion = words[i]; 
     }
 var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
}
else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.appVersion.indexOf("Win") != -1)) {
 LadetectionVB='<SCR' + 'IPT LANGUAGE=VBScript> \n'; //FS hide this from IE4.5 Mac by splitting the tag
 LadetectionVB= LadetectionVB +'Function MM_FlashCanPlay()\n';
 LadetectionVB= LadetectionVB +'on error resume next \n';
 LadetectionVB= LadetectionVB +'MM_FlashCanPlayVB = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+MM_contentVersion+'")))\n';
 LadetectionVB= LadetectionVB +'var MM_FlashCanPlay = MM_FlashCanPlayVB \n';
 LadetectionVB= LadetectionVB +'End Function \n';
  LadetectionVB= LadetectionVB +'</SCR' + 'IPT> \n';
 document.write(LadetectionVB);
}
if (MM_FlashCanPlay ) {FlashActif=true;
var so = new SWFObject(LeFlash, "flashheaderhome", "735", "81", "8", "#FFFFFF");
so.addParam("quality", "high");
so.addParam("wmode", "transparent");
so.addParam("allowScriptAccess","always");
so.addParam("swLiveConnect","false");
so.addParam("align","left");
var eDiv=document.createElement("div");
eDiv.id='flashheaderhome';
document.getElementById("Tabbandeau").replaceChild(eDiv,document.getElementById("Tabbandeau").firstChild);
so.write("flashheaderhome");
} else{
var eImg=document.createElement("IMG");
eImg.src=Limage;
eImg.width=735;
eImg.height=81;
eImg.id='flashheaderhome';
document.getElementById("Tabbandeau").replaceChild(eImg,document.getElementById("Tabbandeau").firstChild);
}
}
// Fin de la detection du flash

// defilement des bon d'achat
var pas=2 ;
// hauteur de la partie visible 
var h_fen="46px" ;
// marge du texte defilant
var m_mrq=0 ;
  
function scrollmrq(){
    mrq.style.left="0px";
if ( parseInt(mrq.style.top) > -h_mrq ) 
mrq.style.top = parseInt(mrq.style.top)-pas+"px" 
else 
mrq.style.top=parseInt(h_fen)+"px" 
} 
  
function init_mrq(){ 
mrq=document.getElementById("marquee"); 
fen=document.getElementById("scroller"); 
//fen.onmouseover=function(){stoc=pas;pas=0}; 
//fen.onmouseout=function(){pas=stoc};fen.style.height=h_fen; 
h_mrq=mrq.offsetHeight + m_mrq; 
with(mrq.style){position="absolute";top=h_fen;} 
setInterval("scrollmrq()",150);
fen.style.display="block";
} 
//window.onload=init_mrq 

// gestion des ventes à venir
var quelleventeAvenir=0;
var NbventeAvenir=0;
function AffVenteAvenir(action){
    if (quelleventeAvenir==0){
        quelleventeAvenir=1;
        NombreDeFuturVente();
    }
    if ((quelleventeAvenir+action >0) && (quelleventeAvenir+action < NbventeAvenir+1)){
        document.getElementById('FuturVente'+ quelleventeAvenir).style.display='none';
        quelleventeAvenir = quelleventeAvenir + action;
        document.getElementById('FuturVente'+ quelleventeAvenir).style.display='block';
    }
}


function NombreDeFuturVente(){
    nb=0;
    var d = document.getElementById("FuturVente");
    for (var i = 1; i<=d.childNodes.length; i++) {
        if (document.getElementById('FuturVente'+i)) {
            nb=nb+1;
        }
    }
    NbventeAvenir=nb;
}
// fin de la gestion des ventes à venir


FlashActif=false;
function DecouvrirLaPresentation(leloader,LeFlash , Limage, Affichage, emplacement){
    if (Affichage!="popup") {
        LeDivDuFlash=document.getElementById('FlashPresentation_'+index);
        LeDivDuFlash.style.display=Affichage;
        if(Affichage=='block'){
            AffichageBou='hidden';
            LeDivBoutique=document.getElementById('teaserboutique_'+index);
            LeDivBoutique.style.visibility=AffichageBou;
        }
    } else {
    var Para_aff="toolbar=no,location=no,directories=no,menubar=no,status=no,"; 
        Para_aff+="scrollbars=no,width=780, height=420, left=30, top=50"; 
    var PopupFlash=window.open("","popup",Para_aff);
    var strflash='<?xml version="1.0" encoding="iso-8859-1"?><!DOCTYPE html'
        +'PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"'
        +'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
        +'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">'
        + '<head><title>Surinvitation.com</title>'
        +'<script language="JavaScript" type="text/javascript">\n'
        +'<!--\n'
        +'function DecouvrirLaPresentation(var1,var2,var3) {\n window.close();\n}\n'
        +'function ouvrirInscription(adresse) {\n self.opener.document.location.href=adresse;window.close();\n}\n'
        +'function FermerAnimFlash() {\n window.close();\n}\n'
        +'-->\n'
        +'</script>\n'
        +'</head>' 
        +'<body  bgcolor="#FFFFFF"  marginheight="0" marginwidth="0" leftmargin="0" topmargin="0">'
        +'<div id="FlashPresentation"></div>'
        +'</body></html>';  
     PopupFlash.document.write(strflash);
     LeDivDuFlash=PopupFlash.document.getElementById('FlashPresentation');
     PopupFlash.focus();
     
    }   
    if (LeFlash!="") {
      var so = new SWFObject(leloader, "flashvente", "780", "420", "8", "#FFFFFF");
      so.addVariable("adresse", LeFlash+'*');
    so.addVariable("id", emplacement);
    so.addVariable("lien_avant","index.php?tpl=1");
    so.addVariable("lien_devenir","index.php?tpl=35");
    so.addVariable("lien-amis","index.php?tpl=19");
    so.addVariable("lien_accueil","index.php?tpl=1");
    so.addVariable("lien_vente","index.php?tpl=6");
    so.addVariable("lien_produits","index.php?tpl=6");
    so.addVariable("lien_acceder","index.php?tpl=6");
    so.addVariable("lien_inviter","index.php?tpl=19");
    so.addParam("quality", "high");
    so.addParam("quality", "high");
    so.addParam("wmode", "transparent");
    so.addParam("allowScriptAccess","always");
    so.addParam("swLiveConnect","false");
    so.addParam("align","left");
      
        if (Affichage!="popup")
      so.write('FlashPresentation_'+index);
    else
      LeDivDuFlash.innerHTML = so.getSWFHTML();
    
  
    } else{
        Lachaine = '<img src="'+Limage+'" width="780" height="399" id="flashvente" />';
    LeDivDuFlash.innerHTML=Lachaine;    
    }
//document.getElementById('textarea').value=Lachaine;
//LeDivDuFlash.innerHTML=Lachaine

//TimeOutFlash =clearTimeout(TimeOutFlash);
}
function FermerAnimFlash(){
    if (document.getElementById('teaserboutique_'+index)) {
        document.getElementById('teaserboutique_'+index).style.display="block";
        document.getElementById('teaserboutique_'+index).style.visibility="visible";
    }
    if (document.getElementById('FlashPresentation_'+index)) {
        document.getElementById('FlashPresentation_'+index).innerHTML="";
        document.getElementById('FlashPresentation_'+index).style.display="none";
    }
}
// defilement vertical des petits visuel produit.
NbmaxVisu=3;
NbVisu=0;
NbActuel=0;
function AffvisuModele(action){
    nb=0;
    // decompte du nombre de visuel
    if (NbVisu==0) {
        var d = document.getElementById("listedesmodele");
        for (var i = 1; i<=d.childNodes.length; i++) {
            if (document.getElementById('modele'+i)) {
                nb=nb+1;
            }
        }
        NbVisu=nb;
    }
    if (NbVisu>NbmaxVisu) {
        if (action==1) {
            if ( (NbVisu-NbmaxVisu) > NbActuel){
                NbActuel=NbActuel+action;
                document.getElementById('modele'+NbActuel).style.display='none';
            }
        } else {
            if ( 0 < NbActuel) {
                document.getElementById('modele'+ NbActuel).style.display='inline';
                NbActuel = NbActuel + action;
            }
        }
    }
}

//gestion du texte en bandeau sup
function ReglerTexteBandeau() {
// test IE / FFX
if (document.all) { // IE
var MenuWidth=document.getElementById('entete').contentWidth;
} else { // FFX
var MenuWidth=document.getElementById('entete').clientWidth;
}
alert(MenuWidth);
}


// gestion des marques dans la page marque
function AffTeaserMarque(laquelle) {
    //document.getElementById('zoneDetailMarque').innerHTML=document.getElementById('zoneDetailMarque'+laquelle).innerHTML;
    document.getElementById('colloneDroiteGene').style.display='block';
    for(i=0 ; i< 9 ;i++){
    if(document.getElementById('zoneDetailMarque'+i))
    {
        if(typeof(document.getElementById('zoneDetailMarque'+i)) == 'object'){
            document.getElementById('zoneDetailMarque'+i).style.display = 'none';
        }
      }
    }
    document.getElementById('zoneDetailMarque'+laquelle).style.display = 'block';
    
}

// fonction gérant les affichages d'image
// typeAff="page" remplacement du visuel intrapage
// typeAff="popup" affichage en popup (zoom)
// CheminImage adresse du grand visuel sur la page
// CheminImageZ adresse de l'image pour le zoom
var IdModeleEnCours="vide";
var ZoomModeleEnCours="vide";
function AfficherVisuelProduit(CheminImage,CheminImageZ,typeAff,IdVisuel) {
// actuellement je passe en param le nom de fichier mais ça peut-être changé facilement par autre chose
if (typeAff=="popup"){
    if (IdModeleEnCours!="vide") {
        CheminImage=ZoomModeleEnCours;
    } else {
        CheminImage=CheminImageZ;
    }
    var largeur="820";
    var hauteur="340";
    var Para_aff="toolbar=0,location=0,directories=0,menubar=0,status=0,resizable=no,"; 
    Para_aff+="scrollbars=0,width="+largeur+", height="+hauteur+", left=10, top=10"; 
    fenetre = window.open("zoomproduit.php?image="+CheminImage, "Zoom", Para_aff);
    fenetre.focus();
}else{
IdModeleEnCours=IdVisuel;
ZoomModeleEnCours=CheminImageZ;
texteAlt=document.getElementById(IdVisuel).getAttribute( "alt" );
document.getElementById("VisuelProduit").src=CheminImage;
document.getElementById("VisuelProduit").setAttribute( "alt", texteAlt );
document.getElementById("LienVisuelProduit").setAttribute( "title", texteAlt );
}
}

function resetOther(thisInput) {
  switch (thisInput){
        case "codePromo":
         document.getElementById("parrain").value="";
     document.getElementById("email1").value="";
    break;
    case "parrain":
         document.getElementById("codePromo").value="";
     document.getElementById("email1").value="";
    break;
    case "email1":
         document.getElementById("codePromo").value="";
     document.getElementById("parrain").value="";
    break;
  }  
}
function ouvrirInscription(adresse) {
        location.href=adresse;
    }
//Afficher ou cacher la réponse de FAQ
function faqToggle(faqReponse, faqImage, cheminImage){

    var el = document.getElementById(faqReponse);
    var styleattribute = el.getAttribute('style');

    if (typeof styleattribute == 'string') { // what Firefox returns
        if(styleattribute == 'display: none;'){
            document.getElementById(faqReponse).style.display= 'block';
            document.getElementById(faqImage).src=cheminImage+'/picto_minus.gif';
        }else{
            document.getElementById(faqReponse).style.display= 'none';
            document.getElementById(faqImage).src=cheminImage+'/picto_plus.gif';
        }
    } else if (typeof styleattribute == 'object') { // what IE returns
     styleattribute = styleattribute .cssText;
     if(styleattribute == 'DISPLAY: none'){
            document.getElementById(faqReponse).style.display= 'block';
            document.getElementById(faqImage).src=cheminImage+'/picto_minus.gif';
        }else{
            document.getElementById(faqReponse).style.display= 'none';
            document.getElementById(faqImage).src=cheminImage+'/picto_plus.gif';
        }
    }
}

//Valider form si entrée par clavier
function ValidWithEnter(form,evenement) {
    var touche = window.event ? evenement.keyCode : evenement.which;
    if (touche == 13) {
        Identification(form);
    }
}

// identification
function Identification(identForm) {
    if ( document.forms[identForm].email.value != "" && document.forms[identForm].password.value != "") {
        document.forms[identForm].submit();
    } else {
        alert("Les champs email et password sont obligatoires.");
    }
}
//Vérification Date
function checkDate(pDate){
    var modele = /^[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4}$/i;
    if (modele.test(pDate)){
        tab = pDate.split('/');
        j = Math.round(tab[0]);
        m = Math.round(tab[1]);
        a = Math.round(tab[2]);
        //alert("j = "+j+"\nm = "+m+"\na = "+a);
        if ((0<j)&&(j<32)&&(0<m)&&(m<13)&&(1900<a)&&(a<2100)){
            return ""+j+"/"+m+"/"+a+"";
        }
    }
    return false;
}
//Vérification téléphone
function checkTelephone(pPhone) {
  if (pPhone == '') {
      return true;  
  }
  else if (pPhone.length > 10) {
      return false;
  }else{
      return true;
  }
}
//Vérification Mail
function checkMail(pMail){
  //var modele = /^[a-z0-9\-_\.]+@[a-z0-9\-]+\.[a-z]{2,5}$/i;
  var modele = /^[a-z0-9\-_\.]+@[a-z0-9\-\.]+\.[a-z]{2,5}$/i;
  if (modele.test(pMail)){
        return true;
    }else{
        return false;
    }
}   

function checkCodePostal(cCodeP)   {
    var cpModel =  /^\d{4,6}$/;
    return  ( cpModel.test(cCodeP) ) ;
 }
 
function checkNaf(Naf)   {
    var codenaf =  Naf;
    return (codenaf.length = 5) ;   
}

function isletter(lettre){
i=0;
retour=false;
alpha="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQSTUVWXYZ"
for (i=0;i<=52;i++) {

 retour=(lettre.charAt(0)==alpha.charAt(i))|| retour;

}
return retour;

}


//Vérification du formulaire, champs obligatoires remplis ?
//dans HTML exemple ajouter dans la balise input : 
// => code="obligatoire" field="Code Postal"
function check_form(id){
    //console.debug('check_form');
    //Variables
    flag = true;
    error = "Merci de vérifier les champs suivants:\n";
    
        id_form = document.getElementById(id);
    
        for(i=0; (input = document.getElementsByTagName("input")[i]); i++) {            
            if(code = input.getAttribute("code")) {
                strFieldName = input.getAttribute("field") ? input.getAttribute("field") : input.name;
                
                switch (code){
                    case "sans":break;
                    case "obligatoire":
                        if(input.value == ""){
                            flag = false;
                            error += " - Le champ [" + strFieldName + "] n'est pas rempli.\n";
                        }
                    break;
                    case "email":
                        if(input.value == ""){
                          if(input.id != "parrain"){
                            flag = false;
                            error += " - Le champ [" + strFieldName + "] n'est pas rempli.\n";
                        }   
                        }else{
                            if(!checkMail(input.value)){
                                flag = false;
                                error += " - L'adresse email du champ [" + strFieldName + "] n'est pas au bon format.\n";
                            }else{
                                input.value = input.value.toLowerCase();
                            }
                        }
                    break;
                    case "date":
                        if(option.value == ""){
                            flag = false;
                            error += " - Le champ [" + strFieldName + "] n'est pas rempli.\n";
                        }
                    break;
                    case "phone" : 
                        phone = checkTelephone(input.value);
                        if(!phone) {
                          flag = false;
                          error += " - Le numéro de téléphone du champ [" + strFieldName + "] n'est pas au bon format.\n";
                        }
                    break;       
                    case "nombre":
                        if(input.value == ""){
                            flag = false;
                            error += " - Le champ [" + strFieldName + "] n'est pas rempli.\n";
                        }else{
                            if(isNaN(input.value)){
                                flag = false;
                                error += " - Le champ [" + strFieldName + "] n'est pas un nombre.\n";
                            }
                        }
                    break;
                    case "acocher":
                        if(input.checked != true){
                            flag = false;
                            error += " - Cocher la case du champ [" + strFieldName + "] est obligatoire.\n";
                        }
                    break;
                    case "radio":           
                        coche = false;      
                        radio = document.getElementsByName(input.name);                 
                        for (var j=0; j<radio.length;j++) {                         
                            if (radio[j].checked) {
                                coche = true;                           
                            break;
                            }
                        }
                        if ( !coche ) {
                            flag = false;  
                            error += " - Cocher une case du champ [" + strFieldName + "] est obligatoire.\n";
                        }                   
                    break;
                    case "codePostal":
                        if(input.value == ""){
                            flag = false;
                            error += " - Le champ [" + strFieldName + "] n'est pas rempli.\n";
                        }else{
                            if(!checkCodePostal(input.value)){
                                flag = false;
                                error += " - Le codePostal du champ [" + strFieldName + "] n'est pas au bon format.\n";
                            }
                        }
                    break;
                    case "codePostalSansDOMTOM":
                        if(input.value == ""){
                            flag = false;
                            error += " - Le champ [" + strFieldName + "] n'est pas rempli.\n";
                        }else{
                            if(!checkCodePostal(input.value)){
                                flag = false;
                                error += " - Le codePostal du champ [" + strFieldName + "] n'est pas au bon format.\n";
                            }else if(input.value.length != 5){
                                flag = false;
                                error += " - Désolé, surinvitation.com livre uniquement en France métropolitaine (Corse comprise).\n";
                            }else{
        
                                //Pas CP des DOM TOM
                                if((input.value >= 97000 && input.value <=97999) || (input.value >= 98700 && input.value <=98999)){
                                    flag = false;
                                    error += " - Désolé, surinvitation.com livre uniquement en France métropolitaine (Corse comprise).\n";
                                }
                            }
                        }
                    break;
                    
           case "naf":
                        if(input.value){
                          
                retour=false;
                            if (input.value.length == 6) {
                    
                    if (!(isNaN(input.value.substr(0,2))) && (input.value.charAt(2)==".") && !(isNaN(input.value.substr(3,2))) && isletter(input.value.charAt(5))) {
                  retour=true;
                  }
               }
                                      
                            if(!retour){
                                flag = false;
                                error += " - Le champ [" + strFieldName + "] est incorrect.\n exemple code NAF 55.55B";
                            } 
                            
                    }   
                    break;  
                    default : break;
                }
            }
        }

        for(i=0; (textarea = id_form.getElementsByTagName("textarea")[i]); i++) {       
            if(code = textarea.getAttribute("code")) {  
                
                strFieldName = textarea.getAttribute("field") ? textarea.getAttribute("field") : input.name;

                switch (code){
                    case "sans":break;
                    case "obligatoire":
                        if(textarea.value == ""){
                            flag = false;
                            error += " - Le champ [" + strFieldName + "] n'est pas rempli.\n";
                        }
                    break;
                }
            }
        }

    for(i=0; (balise_select = id_form.getElementsByTagName("select")[i]); i++) {        
            if(code = balise_select.getAttribute("code")) { 
                
                strFieldName = balise_select.getAttribute("field") ? balise_select.getAttribute("field") : balise_select.name;
                
                switch (code){
                    case "sans":   break;
                    case "obligatoire":
                        if(balise_select.value == ""){
                            flag = false;
                            error += " - Le champ [" + strFieldName + "] n'est pas rempli.\n";
                        }
                    break;
                }
            }
        }

    if( !flag){     
        alert (error);
  }
    
    return flag;
}

function beforeInscription(aForm,type) {
  if (document.getElementById(type).value == "") {
    alert("Vous devez remplir au moins un champ");
    return;
  }
    switch(type) {
        case 'parrain':
        case 'email1':
        if (!checkMail(document.getElementById(type).value)) {
            alert("Le champ '"+type+"' est incorrect.");
                return;
        }
        break;
    }
    document.forms[aForm].submit();
}


//verif adresse
function choixRnvp(fForm){
    var rnvpWin = window.open("", "RNVP", "toolbar=0,location=0,directories=0,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=0,menuBar=0,width=640,height=700,left=50,top=150"); 
    if (rnvpWin == null) {
        var txtComment = document.getElementById("BlockFormContact").innerHTML;
        txtComment = txtComment+'<p class="comment"><b>Vous utilisez un bloqueur de popup <a href="#" onclick="javascript: choixRnvp(\''+fForm+'\');"><u>cliquez ici</u></a> pour valider votre adresse</b></p>';
        document.getElementById("BlockFormContact").className = "messageErreur";
        document.getElementById("BlockFormContact").innerHTML = txtComment;
    } else {
        document.forms[fForm].target = "RNVP";
        document.forms[fForm].submit(); 
        rnvpWin.focus();
    }
    return rnvpWin  ;
}   

function validAdrRnvp(rnvpForm, val){           
    document.forms[rnvpForm].adrSelectedRnvp.value = val;
    document.forms[rnvpForm].submit();
}   

function validAdrRnvp2(rnvpForm, val1, val2){           
    document.forms[rnvpForm].adrListProfil.value = 1;
    document.forms[rnvpForm].adrSelectedRnvp.value = " ";
    document.forms[rnvpForm].adrSelectedRnvpIndex.value = val1;
    document.forms[rnvpForm].adrSelectedRnvpIndex2.value = val2;
    document.forms[rnvpForm].submit();
}

function RnvpNonValid(){
    fromForm = document.getElementById("fromForm").value;
    window.opener.document.forms[fromForm].adresse1.value = document.getElementById("adr1").value;
    window.opener.document.forms[fromForm].adresse2.value = document.getElementById("adr2").value;
    if ( window.opener.document.forms[fromForm].adresse3 != undefined) {
        window.opener.document.forms[fromForm].adresse3.value = document.getElementById("adr3").value;
    }
    if ( window.opener.document.forms[fromForm].adresse4 != undefined) {
        window.opener.document.forms[fromForm].adresse4.value = document.getElementById("adr4").value;
    }
    window.opener.document.forms[fromForm].codePostal.value = document.getElementById("zip").value;
    window.opener.document.forms[fromForm].ville.value = document.getElementById("city").value;  
    window.opener.document.forms[fromForm].reecritureAdr.value = document.getElementById("reecritureAdr").value;    
    window.opener.document.forms[fromForm].validRnvp.value = 0;
    
    //Pour afficher un message d'erreur
    window.opener.document.forms[fromForm].submit();
     
    self.close();   
}

function sendAdrRnvp(){                 
    //mettre a jour les champ ds le opener et valider le opener ss la verif rnvp        
    fromForm = document.getElementById("fromForm").value;
    
    adresse1 = document.getElementById("adr1").value;
    adresse2 = document.getElementById("adr2").value;
    adresse3 = document.getElementById("adr3").value;
    adresse4 = document.getElementById("adr4").value;
    code_postal = document.getElementById("zip").value;
    ville = document.getElementById("city").value;  
    reecritureAdr = document.getElementById("reecritureAdr").value;
    
    window.opener.document.forms[fromForm].adresse1.value = adresse1;
    window.opener.document.forms[fromForm].adresse2.value = adresse2;
    if ( window.opener.document.forms[fromForm].adresse3 != undefined) {
        window.opener.document.forms[fromForm].adresse3.value = adresse3;
    }
    if ( window.opener.document.forms[fromForm].adresse4 != undefined) {
        window.opener.document.forms[fromForm].adresse4.value = adresse4;
    }
    
    window.opener.document.forms[fromForm].codePostal.value = code_postal;
    window.opener.document.forms[fromForm].ville.value = ville;
    window.opener.document.forms[fromForm].reecritureAdr.value = reecritureAdr;
    if(
        
        (adresse1 == '' && adresse2 == '' && adresse3 == '' && adresse4 == '') ||
        code_postal.length != 5 ||
        (code_postal >= 97000 && code_postal <=97999) || 
        (code_postal >= 98700 && code_postal <=98999) ||
        ville == ''
    ){
        window.opener.document.forms[fromForm].validRnvp.value = 0;
        //On n'envoie pas les données au paiement
    }else{
        window.opener.document.forms[fromForm].validRnvp.value = 1;
        //window.opener.document.forms[fromForm].action = window.opener.document.forms[fromForm].actionValidRnvp.value; 
    }
    
    window.opener.document.forms[fromForm].submit();
    self.close();
}   

function sendAdrRnvp2(rnvpForm, indexAdr){      
    fromForm = document.getElementById("fromForm").value;
    nbAdr = document.getElementById("nbAdr").value;
    idAdr = document.getElementById("adrSelectedRnvpIndex").value;
    idAdr = idAdr.substring(3,idAdr.length);
    action ="0";
    for(i=0;i<nbAdr;i++) {
        adresse = window.opener.document.getElementById("adresses["+i+"][id]").value;
        if(adresse == idAdr) {
              window.opener.document.getElementById("adresses["+i+"][adresse1]").value = document.getElementById("adr1").value;
              window.opener.document.getElementById("adresses["+i+"][adresse2]").value = document.getElementById("adr2").value;
              if ( window.opener.document.getElementById("adresses["+i+"][adresse3]").value != undefined) {
                window.opener.document.getElementById("adresses["+i+"][adresse3]").value = document.getElementById("adr3").value;
                }
                if ( window.opener.document.getElementById("adresses["+i+"][adresse4]").value != undefined) {
                window.opener.document.getElementById("adresses["+i+"][adresse4]").value = document.getElementById("adr4").value;
                }
              window.opener.document.getElementById("adresses["+i+"][codePostal]").value = document.getElementById("zip").value;
              window.opener.document.getElementById("adresses["+i+"][ville]").value = document.getElementById("city").value;  
                window.opener.document.getElementById("adrList[adr"+idAdr+"]").value="";
                window.opener.document.getElementById("adrList[adr"+idAdr+"]").disabled = "true";
                window.opener.document.getElementById("rnvpAdrlistForm").submit();  
        } 
    }
    
}
function ForcerVerifRNVP(){
 document.getElementById("validRnvp").value="";
}

// identification
function inscriptionNouv(inscriptForm) {
    if ( check_form(inscriptForm) ) {
        msgError ="";
        flag = true;
        //les 2 emaisl valides
        if ( document.forms[inscriptForm].email1.value != document.forms[inscriptForm].email2.value ){          
            msgError += "Les champs 'Email' ne sont pas identiques.\n";
            flag = false;
        }               
        //les 2 mots de passe valides
        if ( document.forms[inscriptForm].password1.value != document.forms[inscriptForm].password2.value ){                
            msgError += "Les champs 'Mot de passe' ne sont pas identiques.\n";
            flag = false;
        }
        if ( flag ) {
            document.forms[inscriptForm].familleList.value = "";
            //maj des champs hidden xxxList en fonction des checkBox xxxs           
            if ( document.forms[inscriptForm].familles != undefined) {
                for (i=0; i< document.forms[inscriptForm].familles.length ;i++) { 
                    if ( document.forms[inscriptForm].familles[i].checked == true) { 
                    document.forms[inscriptForm].familleList.value +=document.forms[inscriptForm].familles[i].value +";";               
                }
            }
        } 
        if ( document.forms[inscriptForm].interets != undefined) {
            document.forms[inscriptForm].interetList.value = "";
            for (i=0; i< document.forms[inscriptForm].interets.length ;i++) { 
                if ( document.forms[inscriptForm].interets[i].checked == true) { 
                    document.forms[inscriptForm].interetList.value +=document.forms[inscriptForm].interets[i].value +";";               
                }
            } 
        }

            document.forms[inscriptForm].submit();
        } else {
            alert( msgError);
        }
    }       
}
// Fonction de confirmation d'annulation de commande
function AnnulationCommande(LeMsg,leretour) {
    if (confirm(LeMsg)){
    window.location=leretour;
    } 
}

// Fonction d'affichage des facture
function EditionFactur(Lacom,Laliste, lURL) {
    var elements = Laliste.split(";");
    if (elements.length-1 > 1) {
    height = 100;
    width = 300;
    if(window.innerWidth){
      lPos = (window.innerWidth-width)/2;
        tPos = ((window.innerHeight-height)/4)-50;
    } else{
        lPos = (parseInt(window.screen.width)-  width)/2;
        tPos = ((parseInt(window.screen.height)-height)/2)-50;
    }    
    attr = 'resizable=no,scrollbars=yes,width=' + width + ',height=' + height + ',screenX=300,screenY=200,left=' + lPos + ',top=' + tPos + '';
    popWin=open('', 'invoiceWindow', attr);
    popWin.document.write('<head><title>Edition de factures</title></head>');
    popWin.document.write('<body><font face="Verdana,Arial,Helvetica,sans-serif" size="1"><div align=center>');
    popWin.document.write('<b>Liste des factures disponibles pour cette commande</b></div><br><br>');
    for(i = 0; i < elements.length-1; i++) {
      popWin.document.write('<a href="javascript: opener.location=\''+lURL+elements[i]+"&cdid="+Lacom+'\'; this.close();">Facture n° '+(i+1)+'</a><br />');
    }
    popWin.document.write('</font></div></body></html>');
  } else {
        fenetreFacture = window.open(lURL+elements[0]+"&cdid="+Lacom,"pdf"+elements[0]);
        fenetreFacture.location=lURL+elements[0]+"&cdid="+Lacom;
  }
}

// Fonction de modification de la quantite pour les bons de retour
function Quantite(champs,action,valeurmax, prixunitaire, TauxTVA, champsdestination) {
    MonChamps=document.getElementById(champs);
    Valeur=parseFloat(MonChamps.value); 

    if (Valeur>-1) {
        Valeur=Valeur+action;
        if ((Valeur < valeurmax+1) && (Valeur > -1)){
            MonChamps.value=Valeur;
            if (champsdestination!="") {
                
                QuantitePrix(action,Valeur,prixunitaire,TauxTVA,champsdestination)
            }
        }
    }
}

function QuantitePrix(action, Valeur, prixunitaire,TauxTVA, champsdestination) {
    NouvelleValeur=parseFloat(prixunitaire);
    latva=parseFloat(TauxTVA.replace(',','.'));
    latva=1+(latva/100);
    NouvelleValeur=NouvelleValeur * latva;
    NouvelleValeur=Math.round(NouvelleValeur*100)/100;
    MajTotal(NouvelleValeur*action);
    NouvelleValeur=NouvelleValeur*Valeur;
    document.getElementById(champsdestination).value=deuxDecimalePrix(NouvelleValeur);
}

function MajTotal(valeur){
    valeurT=document.getElementById('ChampsTotal').value;
    valeurT=parseFloat(valeurT.replace(',','.'));
    valeurT=valeurT+valeur;
    valeurT=Math.round(valeurT*100)/100;
    document.getElementById('ChampsTotal').value=deuxDecimalePrix(valeurT);
}
function deuxDecimalePrix(monNombre){
    valeur=monNombre.toString();
    valeur=valeur.replace(".",",");
    if (valeur.indexOf(",")<0){valeur=valeur+",00";}
    if (valeur.length-valeur.indexOf(",")==2){valeur=valeur+"0";}
    return valeur;
}
//mail invite
function inviteHome(fInvitezVosAmis) {
    if ( document.forms[fInvitezVosAmis].emailAmi.value != "" && checkMail(document.forms[fInvitezVosAmis].emailAmi.value) ) {
        document.forms[fInvitezVosAmis].submit();
    } else {
        alert("Le champ 'Adresse Email' est incorrect.");
    }
}

// verification des champs obligatoire pour le bon de retour;
function checkFormBonRetour(formulaire) 
{

    MonForm=document.forms[formulaire];
    MonFormOk = true;
    liste=MonForm.getElementsByTagName('select');
    
    listedeschamps="";
    
    Msgtext="";
            
    //on recupere le nombre de ligne ; 
    for(i=0;i<liste.length;i++)
    {
        recupID=liste[i].id;

        //on verifi que les deux champs motif et precision on bien été reseigné.
        if (MonFormOk) 
        {
            
            if (document.getElementById('quantite'+recupID).value!='0') 
            {
            
                listedeschamps=listedeschamps+recupID+";";

                if (document.getElementById(recupID).value=='') 
                {
                    MonFormOk = false;
                    Msgtext='Veuillez indiquer le motif\n';
                }
                if ((document.getElementById('motif_precision'+recupID).value=='Préciser') || (document.getElementById('motif_precision'+recupID).value=='')) 
                {
                    MonFormOk = false;
                    Msgtext=Msgtext+'Veuillez préciser le motif';
                }
            }
        }
    }
    
    if (MonFormOk) 
    {
        document.forms[formulaire].validation.value=listedeschamps;
        document.forms[formulaire].submit();
    }
    else 
    {
        alert(Msgtext);
    }
}

//mail invite
function inviteAmis(fInvitezVosAmis) {
    adrIdent = false;
   if (( document.getElementById("emailAmi1").value != "" && checkMail(document.getElementById("emailAmi1").value)) ||
			 (document.getElementById("emailAmi2").value != "" && checkMail(document.getElementById("emailAmi2").value)) ||
			 (document.getElementById("emailAmi3").value != "" && checkMail(document.getElementById("emailAmi3").value)) ||
			 (document.getElementById("emailAmi4").value != "" && checkMail(document.getElementById("emailAmi4").value)) ||
			 (document.getElementById("emailAmi5").value != "" && checkMail(document.getElementById("emailAmi5").value)) ) {
			 	//verif pas 2 adresse identiques
			 	if ( document.getElementById("emailAmi1").value != "") {
			 		if ( document.getElementById("emailAmi1").value == document.getElementById("emailAmi2").value ||
					 			document.getElementById("emailAmi1").value == document.getElementById("emailAmi3").value ||
					 			document.getElementById("emailAmi1").value == document.getElementById("emailAmi4").value ||
					 			document.getElementById("emailAmi1").value == document.getElementById("emailAmi5").value ) {
							adrIdent = true;
					}
				}
		 		if ( document.getElementById("emailAmi2").value != "" ) {
					if ( document.getElementById("emailAmi2").value == document.getElementById("emailAmi3").value ||
				 				document.getElementById("emailAmi2").value == document.getElementById("emailAmi4").value ||
				 				document.getElementById("emailAmi2").value == document.getElementById("emailAmi5").value ) {
						adrIdent = true;
					}
				}
 				if ( document.getElementById("emailAmi3").value != "" ) {
					if ( document.getElementById("emailAmi3").value == document.getElementById("emailAmi4").value ||
				 				document.getElementById("emailAmi3").value == document.getElementById("emailAmi5").value ) {
						adrIdent = true;
				 	}
				}
		 		if ( document.getElementById("emailAmi4").value != "" ) {
					if ( document.getElementById("emailAmi4").value == document.getElementById("emailAmi5").value ) {					
						adrIdent = true;
				 	}
				}				
		 		if ( adrIdent) {
			 		alert("Des adresses sont identiques.");
			 	} else {
					go(1,22,'','','','')
				}							
	} else {
		alert("Un champ 'Adresse Email' est incorrect.");
	}
}

// deconnexion
function deconnexion(deconnectForm) {
    document.forms[deconnectForm].submit();
}

// modif profil
function modifProfil(profilForm) {
    if ( check_form(profilForm)) {
        document.forms[profilForm].submit();
    }   
}

function addAdresse(profilForm) {   
    document.forms[profilForm].newAdresse.value = "1";
    document.forms[profilForm].profil.value = "0";
    document.forms[profilForm].submit();
    
}

function rmAdresse(profilForm, adrId) { 
    document.forms[profilForm].rmAdresse.value = adrId;
    if ( adrId != -1) {//uniquement qd on supprime une adresse enregistrer
        document.forms[profilForm].rmAdresseList.value += adrId+";";
    }
    document.forms[profilForm].profil.value = "0";
    document.forms[profilForm].submit();
}

function passwordForgotten() {
    window.open("index.php?tpl=23", "pwdForget", "toolbar=0,location=0,directories=0,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=0,menuBar=0,width=400,height=200,left=50,top=150");
}

function sendPwdForget(pwdForgetForm) {
    if ( check_form(pwdForgetForm)) {
        document.forms[pwdForgetForm].submit();
    } 
}


function sendTicket(formContactForm) {
    if ( check_form(formContactForm)) {
        document.forms[formContactForm].submit();
    }   
}

function AffvisuModele(direction,nbimages){  
    if(nbimages>3){
        liste=document.getElementById('mobile');
        pos=parseInt(liste.style.top.replace('px;',''));
        if(pos%63==0){
        max=-(nbimages-3)*63;
        if ((!pos<=0 && direction==1) || (direction==-1 && pos>max)){
            for(i=1;i<=63;i++){
                pos=pos+direction;
                setTimeout("liste.style.top='"+pos+"px';",8*i);
            }
        }
        }
    }
}

function AjoutPanier(nomForm){  
    form=document.getElementById(nomForm);
    document.getElementById('PPpanier').style.display = 'none';
    form.submit();
} 

function sendAdrLivraison(fForm) {  
    if (check_form(fForm) ) {           
        if ( document.forms[fForm].validRnvp.value == 1) {
            document.forms[fForm].action = document.forms[fForm].actionValidRnvp.value;    
        }       
        document.forms[fForm].submit();
    } else return false;
}

function confirmCancelCmd(fForm) {
    if ( confirm("Souhaitez-vous annuler votre commande?")) {
        document.forms[fForm].cancelCmd.value = 1;
        document.forms[fForm].action = document.forms[fForm].actionCancelCmd.value;     
        document.forms[fForm].submit();
    }
}

function choixAdresseForm(fForm) {
    if (document.getElementById('texteJoint')) {
    document.forms[fForm].texteJoint.value = document.getElementById('texteJoint').value;
  }
  document.forms[fForm].modifAdr.value=0;
    document.forms[fForm].submit();
}

function validerAdresseForm(fForm){
    document.forms[fForm].validerADR.value = 1;
    document.forms[fForm].submit();
}

function majAdresseForm(fForm) {    
    document.forms[fForm].submit();
}
ActivationPaiement = true;
function valideCmd(idformulaire){ 
    retourOK=false;
  if (ActivationPaiement){
        if (check_form(idformulaire)){
            ActivationPaiement=false;
            MasquerValidationAnnulation()
            document.forms[idformulaire].submit();
            retourOK=true;
        }
    }
    //return retourOK ;
}
function MasquerValidationAnnulation(){
    document.getElementById('lienvalider').style.visibility='hidden';
    if (document.getElementById('lienannuler')) {
    document.getElementById('lienannuler').style.visibility='hidden';
  }
}

function textCounter(field, maxlimit) {
    if (field.value.length > maxlimit) { 
        field.value = field.value.substring(0, maxlimit);
    } 
}

function LotAffStock(key,aSize,complement) {
    if (key == 0) {
        //zoneAjoutPanier.style.visibility='hidden';
        zoneInfoStock.innerHTML="";
        zoneInfoStock.style.visibility='hidden';
        return;
    }

    zoneAjoutPanier=document.getElementById("PPpanier"+complement);
    zoneInfoStock=document.getElementById("PPinfomodelestock"+complement);

    if(aSize[key]<=0){
        //zoneAjoutPanier.style.visibility='hidden';
        zoneInfoStock.innerHTML="";
        zoneInfoStock.innerHTML="<strong>STOCK : <\/strong>produit indisponible";
        zoneInfoStock.style.visibility='visible';
    }
    else if(aSize[key]>5){
        //zoneAjoutPanier.style.visibility='visible';
        zoneInfoStock.innerHTML="";
        zoneInfoStock.innerHTML="<strong>STOCK : <\/strong>disponible";
        zoneInfoStock.style.visibility='visible';
    }
    else{
        //zoneAjoutPanier.style.visibility='visible';       
        if(aSize[key]==1){
          zoneInfoStock.innerHTML="<strong>STOCK : <\/strong> plus que <span class=\"nbStock\" id=\"stock\">1<\/span> disponible";
        }
        else{
          zoneInfoStock.innerHTML="<strong>STOCK : <\/strong> plus que <span class=\"nbStock\" id=\"stock\">"+aSize[key]+"<\/span> disponibles";
        } 
        zoneInfoStock.style.visibility='visible';
    }
}

function AffRef(refid,modeAffPrix,references,complement){
    txtprix=document.getElementById("prix"+complement);
    txtprixpublic=document.getElementById("prixpublic"+complement);
    txtremisepercent=document.getElementById("remisepercent"+complement);
    txtremise=document.getElementById("remise"+complement);
    //zoneAjoutPanier=document.getElementById("PPpanier"+complement);
    zoneInfoStock=document.getElementById("PPinfomodelestock"+complement);
    zoneAttributsRef=document.getElementById("attributsRef");
    if (refid != 0 && references[refid]) {
    
        if (txtprix!=null) txtprix.innerHTML=references[refid][0]+'&euro;';
        if (txtprixpublic!=null) txtprixpublic.innerHTML=references[refid][1]+'&euro;';
        if (txtremisepercent!=null) txtremisepercent.innerHTML=references[refid][2]+'%';
        if (txtremise!=null) txtremise.innerHTML=references[refid][3]+'&euro;';
    
        if(references[refid][4]<=0){
            //zoneAjoutPanier.style.visibility='hidden';
            zoneInfoStock.innerHTML="";
            zoneInfoStock.innerHTML="<strong>STOCK : <\/strong>produit indisponible";
            zoneInfoStock.style.visibility='visible';
        }
        else if(references[refid][4]>5){
            //zoneAjoutPanier.style.visibility='visible';
            zoneInfoStock.innerHTML="";
            zoneInfoStock.innerHTML="<strong>STOCK : <\/strong>disponible";
            zoneInfoStock.style.visibility='visible';
        }
        else{
            //zoneAjoutPanier.style.visibility='visible';       
            if(references[refid][4]==1){
                zoneInfoStock.innerHTML="<strong>STOCK : <\/strong> plus que <span class=\"nbStock\" id=\"stock\">1<\/span> disponible";
            }
            else{
                zoneInfoStock.innerHTML="<strong>STOCK : <\/strong> plus que <span class=\"nbStock\" id=\"stock\">"+references[refid][4]+"<\/span> disponibles";
            } 
            zoneInfoStock.style.visibility='visible';
        }
        txtstock=document.getElementById("stock");
        if (txtstock!=null) txtstock.innerHTML=references[refid][4];
        zoneAttributsRef.innerHTML=references[refid][5];
    
    } else {
        //zoneAjoutPanier.style.visibility='hidden';
        zoneInfoStock.innerHTML="";
        zoneInfoStock.style.visibility='hidden';
    }
    zoneAttributsRef.style.visibility='hidden';
}

function panierAffichage(index){
    if(tabPanier.length!=0){
        document.visuPanier.src = tabPanier[index]['image'].src;
        var divQte = document.getElementById('quantite');
        if(tabPanier[index]['qte']==1){
            divQte.style.display = 'none';
        }else{
            divQte.innerHTML = 'x'+tabPanier[index]['qte'];
            divQte.style.display = 'block';
        }
        if(index==0){
            document.getElementById('flecheGaucheA').className = 'desactive';
        }else{
            document.getElementById('flecheGaucheA').className = '';
        }
        if(index==tabPanier.length-1){
            document.getElementById('flecheDroiteA').className = 'desactive';
        }else{
            document.getElementById('flecheDroiteA').className = '';
        }
    }   
}
function panierPrecedent(){
    if(panierIndex > 0){
        panierIndex--;
    }
    panierAffichage(panierIndex);
}
function panierSuivant(){
    if(panierIndex < tabPanier.length-1){
        panierIndex++;
    }
    panierAffichage(panierIndex);
}

function openPopIn(width, height, name){
  var popIn = dojo.byId(name);
  var alpha = dojo.byId('fondAlphaNoir');
  if(document.compatMode && document.compatMode != "BackCompat"){
    var theHeight = document.documentElement.scrollHeight;
    var w = document.documentElement.offsetHeight;
    if(theHeight < w) theHeight = w;
  }else{
    var theHeight = document.body.scrollHeight;
  } 
   //document.documentElement.scrollHeight
  //document.documentElement.offsetHeight
  alpha.style.cssText = 'display:block;height: '+theHeight + 'px';
  var offsetY = window.pageYOffset;
  if(isNaN(offsetY)) offsetY = document.documentElement.scrollTop; //IE6
  if(isNaN(offsetY)) offsetY = 0; //cas inconnu

   
  popIn.style.width = width+"px";
  popIn.style.height = height+"px";
  
  //var top = (Math.round(height/2) - offsetY) * -1;
  var top = (Math.round(height/2.2) - offsetY) * -1;
  popIn.style.marginLeft = "-"+Math.round(width/2)+"px";
  popIn.style.marginTop = top+"px";

  hideCategorieSelect();
  
  alpha.style.display = "block";
  popIn.style.display = "block";   
}

function closePopIn(name){
  var popIn = dojo.byId(name);
  var alpha = dojo.byId('fondAlphaNoir');
  displayCategorieSelect();
  alpha.style.display = "none";
  popIn.style.display = "none"; 
}

function displayCategorieSelect(){

  dojo.query("select").forEach(function(node, index, arr){
    node.style.visibility = "visible";
  });
  
}

function hideCategorieSelect(){

  dojo.query("select").forEach(function(node, index, arr){
    node.style.visibility = "hidden";
  });
  
}


function afficherAdrForm(){
  var d = dojo.byId('autreAdresse');
  d.style.display = 'block';
}

/////////
var thumWidth = 85;
var thumWidthLine = 300;
var thumView = 3;

var currentAnimation;
var currentTransition;
var currentImgUrl;
var currentImgB;
function alerieNavLeft(n){
  var bR = dojo.byId(n);
  var newPos = (galerieGetPos(bR.style.left) + thumWidth * thumView);
  if(!galMaxPos('left',newPos)) {
    galDoAnimation( n, newPos);
    //bR.style.left = newPos + "px";
  }
}
function galerieNavRight(n){
  var bR = dojo.byId(n);
  var newPos = (galerieGetPos(bR.style.left) - thumWidth * thumView);
  if(!galMaxPos('right',newPos)){
    galDoAnimation(n, newPos)
  }
}  
//, onEnd: galerieDisplay2(src, n)
function galerieDisplay(src, n){
  currentImgUrl = src;
  currentImgB = n;
  currentTransition = dojo.fadeOut({node: n,duration: 250, onEnd:function(){ galerieDisplay2()}});
  currentTransition.play();  
}

function galerieDisplay2(){
  dojo.byId(currentImgB).src=currentImgUrl;
  currentTransition = dojo.fadeIn({node: currentImgB,duration: 250});
  currentTransition.play(); 
}

function galerieGetPos(t){
  return new Number(t.replace("px",""));
} 

function galCenterThumb(n){
   var bR = dojo.byId(n);
   bR.style.left = Math.round(thumWidthLine/2 - (thumWidth * nbThumbTotal)/2)+"px";
}

function galMaxPos(dir, newPos){
  if(dir == "left"){
    if(newPos > 0) return true;
    else return false;
  }else if(dir == "right"){
    var minX = -1 * thumWidth * (nbThumbTotal - 1);
    if(newPos < minX) return true;
    else return false;
  }
  
}

function galInitDisplay(){
  if(thumView >= nbThumbTotal ){
    galCenterThumb("thumbP");
    galCenterThumb("thumbPZ");
    
    dojo.query(".navL").forEach(function(node, index, arr){
      node.style.visibility = "hidden";
    }); 
    dojo.query(".navR").forEach(function(node, index, arr){
      node.style.visibility = "hidden";
    });         
  }
}

function afficherZoom(){
  openPopIn(760,740,'cPopInGal');
  var src = dojo.byId('imgSlideShow').src.replace('.44.','.45.');
  var srcZ = dojo.byId('imgSlideShowZ').src;
  if(src != srcZ)
  galerieDisplay(src, 'imgSlideShowZ');
}

function galDoAnimation(n, newPos) {

  if(currentAnimation && currentAnimation.status() != "stopped"){
    return;//do not interrupt a running animation
  }

  currentAnimation = dojo.fx.slideTo({node: n,duration: 300, left: newPos, top:0});
  if (currentAnimation) {
    dojo.connect(currentAnimation, "onEnd", function(){
      currentAnimation = null;
    });
    currentAnimation.play();
  }
}

function parrainerRapide(nomForm){
 
    if ( document.forms[nomForm].emailAmi.value != "" && checkMail(document.forms[nomForm].emailAmi.value) ) {
    dojo.xhrPost(
    {
      url:'/index_remote.php?remote=parrainerRapide',
      handleAs : 'xml',
      form:nomForm,
      load: function(reponse, ioArgs){
        var m = reponse.getElementsByTagName("message");
        var cMessage = dojo.byId('parrainageMessage');
        cMessage.innerHTML = m[0].childNodes[0].nodeValue;
        var inp = dojo.byId('emailAmi');
        inp.value = 'Email filleul';
      }
    }
    );
    } else {
      var cMessage = dojo.byId('parrainageMessage');
        cMessage.innerHTML = "<span style=\"color:#DD0519\">Le champ 'Adresse Email' est incorrect.</span>";
    }

}

function majPrixCate(id, vid, index){
  if(id > 0){
  dojo.xhrGet(
    {
      url:'/index_remote.php?remote=refInfo',
      content : {'id': id, 'vid':vid},
      handleAs : 'xml',
      load: function(reponse, ioArgs){

        var prixVente = reponse.getElementsByTagName("prixVente")[0].childNodes[0].nodeValue;
        var prixPublic = reponse.getElementsByTagName("prixPublic")[0].childNodes[0].nodeValue;
        var remisePourcent = reponse.getElementsByTagName("remisePourcent")[0].childNodes[0].nodeValue;
        var remise = reponse.getElementsByTagName("remise")[0].childNodes[0].nodeValue;
        
        
        var oPv = dojo.byId("jsPrixVente_"+index);
        var oPc = dojo.byId("jsPrixPublic_"+index);
        var oRp = dojo.byId("jsRemisePour_"+index);
        var oR = dojo.byId("jsRemise_"+index);
        if(oPv) oPv.innerHTML = prixVente + " €";
        if(oPc) oPc.innerHTML = prixPublic + " €";
        if(oRp) oRp.innerHTML = "- "+Math.floor(remisePourcent) +"%";
        if(oR) oR.innerHTML = remise +" € de remise";
      }
    }
  );  
  }
}


function parseXmlAjout(reponse){

  var retour = {};
  var k;
  var v;
  var rteNode;
  
  rteNode = reponse.getElementsByTagName("root").item(0);   
  
  for(var i = 0 ; i < rteNode.childNodes.length ; i++){ 
    k = rteNode.childNodes.item(i).tagName;
    if(rteNode.childNodes.item(i).firstChild) v = rteNode.childNodes.item(i).firstChild.nodeValue;
    else v = '';
    retour[k] = v;
  }
  
  return retour;
  
}


function verification_inscription() {
  if (checkMail(dojo.byId('email_contact').value))   {
    dojo.xhrGet({
      url: 'index_remote.php?remote=contact',
      content:{email:dojo.byId('email_contact').value},
      handleAs: 'text',
      load: function(reponse, ioArgs){
          
              switch(reponse){ 
                case "3": 
                  window.location.href = '/index.php?tpl=2&email1='+ dojo.byId('email_contact').value;
                  break;
                  
                case "2": 
                  alert(" Adresse email non renseignée. ");
                  break;
                
                case "1": 
                  dojo.byId('PopInContent').innerHTML= '<div class="popin_inscription">    Vous êtes déjà membre de Surinvitation.com. Merci de vous identifier.</div> <br/> <div class="popin_inscription2">  Si vous souhaitez recevoir votre mot de passe par email, <a id="lien_couleur" href="javascript:send_mail('+ "'"  + dojo.byId('email_contact').value + "'" +')">cliquez ici. </a></div>';
                  openPopIn(500,100,'cPopIn'); 
                  break;
              }  
            }
    });
  } else {
    alert(" L'adresse email ' "+dojo.byId('email_contact').value+" ' n'est pas au bon format. ");
  }   
}
 
 
 function send_mail(email) {
 
 dojo.xhrGet({
    url: 'index_remote.php?remote=emailSend',
    content:{'email':email},
    handleAs: 'text',
    load: function(reponse, ioArgs){
  
      switch(reponse){ 
      
          case "1":
            dojo.byId('PopInContent').innerHTML='<div class="popin_inscription3">L\'email comportant votre mot de passe a été envoyé à : '+ email +'   </div><br/>  <div class="popin_inscription4" >Vous allez le recevoir dans quelques instants. </div>'      
          break;
     
          case "2":
             alert(" Une erreur est survenue lors de l'envoi de l'email. ");
          break;
      
          case "3":
               alert(" Adresse email non renseignée. ");
          break;
            
       
      }
    }
  });
}

function verification_email(Form,Email){
  if ( checkMail(document.getElementById(Email).value) ){
    document.forms[Form].submit();  
  }else{
    alert(" L'adresse email ' "+document.getElementById(Email).value+" ' n'est pas au bon format. ");
  } 
}

function submitFormContact(formName){
  //var form = dojo.byId(formId);
  if(checkFormContact(formName)){
    document.forms[formName].submit();
  }
}



function contactValidMessage(){
  var cForm = dojo.byId('cContactForm');
  cForm.style.display = 'none';
  var cMessage = dojo.byId('cContactMessage');
  cMessage.innerHTML = messageValideContact;
}
function contactErrorMessage(){
  var cMessage = dojo.byId('cContactMessage');
  cMessage.innerHTML = "<span class=\"error\">Un problème est survenue lors de l'enregistrement de votre message</span>";
  
}

function checkMail(pMail){
  //var modele = /^[a-z0-9\-_\.]+@[a-z0-9\-]+\.[a-z]{2,5}$/i;
  var modele = /^[a-z0-9\-_\.]+@[a-z0-9\-\.]+\.[a-z]{2,5}$/i;
  if (modele.test(pMail)){
        return true;
    }else{
        return false;
    }
}   

function checkCodePostal(cCodeP){
    var cpModel =  /^\d{4,6}$/;
    return  ( cpModel.test(cCodeP) ) ;
}



function checkFormContact(formName){
  var form = document.forms[formName];

  var civility_id = form.civility_id
  var last_name = form.last_name.value;
  var first_name = form.first_name.value;
  var phone = form.phone.value;
  var email = form.email.value;
  var message = form.message.value;
  var cp = form.cp.value;
  
  var error = '';
  
  if(!civility_id[0].checked && !civility_id[1].checked && !civility_id[2].checked){
    error += "La civilité n'est pas renseignée.\n";
  }
  if(!last_name){
    error += "Le nom n'est pas renseigné.\n";
  }
  if(!first_name){
    error += "Le prénom n'est pas renseigné.\n";
  }
  if(!phone){
    error += "Le numéro de téléphone n'est pas renseigné.\n";
  }
  if(!email){
    error += "L'adresse email n'est pas renseignée.\n";
  }
  if(email && !checkMail(email)){
    error += '"' + email + '"' + " n'est pas une adresse email valide.\n";
  }
  if(!cp){
    error += "Le code postal n'est pas renseigné.\n";
  }      
  if(cp && !checkCodePostal(cp)){
    error += '"'+cp + '"' + " n'est pas un code postal valide.\n";
  }
  if(message.length > 2000){
    error += "Votre message est trop long.\n";
  }
  
  
  if(error){
    alert(error);
    return false;
  }else{
    return true;
  }
}


function afficher(theid)
{
  if(document.compatMode && document.compatMode != "BackCompat"){
	theHeight = document.documentElement.clientHeight;
  }else{
	theHeight = document.documentElement.clientHeight;
  }
			 
  document.getElementById(theid).style.display = 'block';
  document.getElementById('fondAlphaNoir').style.cssText = 'display:block;height: '+theHeight + 'px';
}
			
function cacher(theid)
{
  document.getElementById(theid).style.display = 'none';
  document.getElementById('fondAlphaNoir').style.display = 'none';
}

function mailMdpForget()
{
	if(document.getElementById("email").value!="")
	{
		if(checkMail(document.getElementById("email").value))
		{
			document.getElementsByName('mailaction')[0].value="forgottenMail";
			go(1,104,'','','','');
		}
		else
		{
			alert('l\'adresse email ne semble pas valide');
		}
	}
	else
	{
		alert('Aucune adresse email n\'a ete saisie');
	}
} 

function focus_mail(){
  document.getElementById('email').focus();
}

function desabonneMoi()
{
	if(document.getElementById("enr2").value!="")
	{
		if(checkMail(document.getElementById("enr2").value))
		{
			setEnr(40,2,1,'');
			go(1,40,'','','','');
		}
		else
		{
			alert('Une erreur a ete detectee');
		}
	}
	else
	{
		alert('Une erreur a ete detectee');
	}
}
