/* auteur: varman7 */
/* Date de création: 18/12/2002 */

// Validate numeric field
function IsDigit(s) {
   if (s == "0" || s == "1" || s == "2" || s == "3" || s == "4" || s == "5" || s == "6" || s == "7" || s == "8" || s == "9")
      return true;
         return false;
}

function IsAllDigit(pDigit) {
  var str = pDigit.value; 
  for (i=0 ; i < str.length ; i++)  {
    var s = str.substring(i, i+1);
      if (IsDigit(s) == false) { return false; }
  }
  return true;
}

// Vérification de mail
// boolean
// true => valid mail
// false => invalid mail
function VerifForm(Form_Name) {
    adresse = Form_Name.email.value;
    var place = adresse.indexOf("@",1);
    var point = adresse.indexOf(".",place+1);
    if ((place > -1)&&(adresse.length >2)&&(point > 1))    {    return true; }
    else{ return false    }
}

function verifCoord(tmpForm) {
  var pForm = tmpForm;
    var ValidForm = 1;
  // -- Nom
    if ( (pForm.nom.value=="" && ValidForm==1) ) { alert("Veuillez indiquer votre nom..."); ValidForm = 0;  }
  // -- Prenom
    if ( (pForm.prenom.value=="" && ValidForm==1) ) { alert("Veuillez indiquer votre prénom..."); ValidForm = 0; }
    
  // Jour de naissance
    if ( (pForm.ddn_Day.value=="" && ValidForm==1) ) { alert("Veuillez indiquer votre jour de naissance..."); ValidForm = 0; }
    
  // Mois de naissance
    if ( (pForm.ddn_Month.value=="" && ValidForm==1) ) { alert("Veuillez indiquer votre mois de naissance..."); ValidForm = 0; }
    
  // Annee de naissance
    if ( (pForm.ddn_Year.value=="" && ValidForm==1) ) { alert("Veuillez indiquer votre année de naissance..."); ValidForm = 0; }
    

  // Le mail est-il valide ?
  if ( !VerifForm(pForm) && (ValidForm==1) ) { 
    alert("Veuillez indiquer une adresse electronique valide (exemple: mail@fournisseur.com)..."); ValidForm = 0; 
  }
  
  // Le mail est-il confirmé
  if ( pForm.email.value!=pForm.email2.value && (ValidForm==1) ) {    
    alert("Veuillez confirmer votre adresse email..."); ValidForm = 0;
  }
  // -- adresse
    if ( (pForm.adresse1.value=="" && ValidForm==1) ) { alert("Veuillez indiquer au moins un nom de rue..."); ValidForm = 0; }
    // le code postal est-il valide?
    if ( (pForm.cp.value=="" && ValidForm==1) && (IsAllDigit(pForm.cp) && ValidForm==1) ) {
      alert("Veuillez indiquer un code postal correct (sur 5 valeurs)..."); ValidForm = 0; 
    }
  // -- Ville
    if ( (pForm.ville.value=="" && ValidForm==1) ) { alert("Veuillez indiquer votre ville..."); ValidForm = 0; }
  // -- Lieu de livraion
  if( pForm.liv2.value == 1) {
    // -- Nom
      if ( (pForm.liv_nom.value=="" && ValidForm==1) ) { alert("Veuillez indiquer le nom pour la livraison..."); ValidForm = 0;  }
    // -- adresse
      if ( (pForm.liv_adresse1.value=="" && ValidForm==1) ) { alert("Veuillez indiquer au moins un nom de rue pour la livraison..."); ValidForm = 0; }
    // le code postal est-il valide?
      if ( (pForm.liv_cp.value=="" && ValidForm==1) && (IsAllDigit(pForm.cp) && ValidForm==1) ) {
        alert("Veuillez indiquer un code postal de livraison correct (sur 5 valeurs)..."); ValidForm = 0; 
      }
    // -- Ville
      if ( (pForm.liv_ville.value=="" && ValidForm==1) ) { alert("Veuillez indiquer une ville de livraison..."); ValidForm = 0; }
    // Le telephone est-il valide?
    if ( (pForm.liv_tel.value=="" && ValidForm==1) && (IsAllDigit(pForm.liv_tel) && ValidForm==1) ) { 
      alert("Veuillez indiquer un numéro de téléphone de livraison correct (sur 10 valeurs)..."); ValidForm = 0; 
    }
  }
  // --
  // Le telephone est-il valide?
  if ( (pForm.tel.value=="" && ValidForm==1) && (IsAllDigit(pForm.tel) && ValidForm==1) ) { 
    alert("Veuillez indiquer un numéro de téléphone correct (sur 10 valeurs)..."); ValidForm = 0; 
  }
  // Le telephone portable est-il valide?
  /*
     * if ( (pForm.port.value=="" && ValidForm==1) && (IsAllDigit(pForm.port) &&
     * ValidForm==1) ) { alert("Veuillez indiquer un numéro de téléphone
     * portable correct (sur 10 valeurs)..."); ValidForm = 0; }
     */
  // Valider le formulaire si valide
  if (ValidForm) pForm.submit();
}

function verifCoordClub(tmpForm) {
  var pForm = tmpForm;
    var ValidForm = 1;
  // -- Nom
    if ( (pForm.nom.value=="" && ValidForm==1) ) { alert("Veuillez indiquer votre nom..."); ValidForm = 0;  }
  // -- Prenom
    if ( (pForm.prenom.value=="" && ValidForm==1) ) { alert("Veuillez indiquer votre prénom..."); ValidForm = 0; }
  // -- adresse
    if ( (pForm.adresse1.value=="" && ValidForm==1) ) { alert("Veuillez indiquer au moins un nom de rue..."); ValidForm = 0; }
    // le code postal est-il valide?
    if ( (pForm.cp.value=="" && ValidForm==1) && (IsAllDigit(pForm.cp) && ValidForm==1) ) {
      alert("Veuillez indiquer un code postal correct (sur 5 valeurs)..."); ValidForm = 0; 
    }
  // -- Ville
    if ( (pForm.ville.value=="" && ValidForm==1) ) { alert("Veuillez indiquer votre ville..."); ValidForm = 0; }
  // --
  // Le telephone est-il valide?
  if ( (pForm.tel.value=="" && ValidForm==1) && (IsAllDigit(pForm.tel) && ValidForm==1) ) { 
    alert("Veuillez indiquer un numéro de téléphone correct (sur 10 valeurs)..."); ValidForm = 0; 
  }
  // Le telephone portable est-il valide?
  /*
     * if ( (pForm.port.value=="" && ValidForm==1) && (IsAllDigit(pForm.port) &&
     * ValidForm==1) ) { alert("Veuillez indiquer un numéro de téléphone
     * portable correct (sur 10 valeurs)..."); ValidForm = 0; }
     */
  // Le mail est-il valide ?
  if ( !VerifForm(pForm) && (ValidForm==1) ) { 
    alert("Veuillez indiquer une adresse electronique valide (exemple: mail@fournisseur.com)..."); ValidForm = 0; 
  }
  
  
  // Valider le formulaire si valide
  if (ValidForm) pForm.submit();
}

function verifCoord_V2(tmpForm) {
  var pForm = tmpForm;
    var ValidForm = 1;
  // -- Nom
    if ( (pForm.nom.value=="" && ValidForm==1) ) { alert("Veuillez indiquer votre nom..."); ValidForm = 0;  }
  // -- Prenom
    if ( (pForm.prenom.value=="" && ValidForm==1) ) { alert("Veuillez indiquer votre prénom..."); ValidForm = 0; }
  // -- adresse
    if ( (pForm.adresse1.value=="" && ValidForm==1) ) { alert("Veuillez indiquer au moins un nom de rue..."); ValidForm = 0; }
    // le code postal est-il valide?
    if ( (pForm.cp.value=="" && ValidForm==1) && (IsAllDigit(pForm.cp) && ValidForm==1) ) {
      alert("Veuillez indiquer un code postal correct (sur 5 valeurs)..."); ValidForm = 0; 
    }
  // -- Ville
    if ( (pForm.ville.value=="" && ValidForm==1) ) { alert("Veuillez indiquer votre ville..."); ValidForm = 0; }
  // --
  // Le telephone est-il valide?
  if ( (pForm.tel.value=="" && ValidForm==1) && (IsAllDigit(pForm.tel) && ValidForm==1) ) { 
    alert("Veuillez indiquer un numéro de téléphone correct (sur 10 valeurs)..."); ValidForm = 0; 
  }
  // Le telephone portable est-il valide?
  /*
     * if ( (pForm.port.value=="" && ValidForm==1) && (IsAllDigit(pForm.port) &&
     * ValidForm==1) ) { alert("Veuillez indiquer un numéro de téléphone
     * portable correct (sur 10 valeurs)..."); ValidForm = 0; }
     */
  // Le mail est-il valide ?
  if ( !VerifForm(pForm) && (ValidForm==1) ) { 
    alert("Veuillez indiquer une adresse electronique valide (exemple: mail@fournisseur.com)..."); ValidForm = 0; 
  }
  // Valider le formulaire si valide
  if (ValidForm) pForm.submit();
}

function ValidLiv(nameForm) {
    var ValidForm = 0;
    // le code postal est-il valide?
    if (IsAllDigit(nameForm.liv_cp) && nameForm.liv_cp.value!="") { 
        ValidForm = 1; 
        // Le telephone est-il valide?
        if (IsAllDigit(nameForm.liv_tel) && nameForm.liv_tel.value!="") { 
            ValidForm = 1; 
            if(nameForm.liv_nom.value=="") {    
                alert("Veuillez insérer un nom..."); ValidForm = 0;
            } else {
                ValidForm = 1;
                if(nameForm.liv_adresse1.value=="") {
                    alert("Veuillez indiquer une adresse..."); ValidForm = 0;
                } else { 
                    ValidForm = 1;
                    if(nameForm.liv_ville.value=="") {
                        alert("Veuillez indiquer une ville..."); ValidForm = 0;
                    } else { 
                        ValidForm = 1;
                        // Valider le formulaire si valide
                        if (ValidForm) nameForm.submit();
                    }
                }
            }
        } else {
            alert("Veuillez indiquer un numéro de téléphone correct (sur 10 valeurs)..."); 
            ValidForm = 0; 
        }
    } else {
        alert("Veuillez indiquer un code postal correct (sur 5 valeurs)..."); 
        return false; 
    }
}

function verif() { 
    location.href='../order/verifCB.php';
}

//
function supp(form, idx) {
  form.idx2sup.value = idx;
  form.submit();
}

// 
function nb_items(act, ref, id) {
  pForm = document.changeidx;
  pForm.id_pdt.value = id;
  pForm.id_ref.value = ref;
  pForm.whatodo.value = act;
  pForm.submit();
}


$(document).ready(function(){
    $("#form_caddy").find("span[class*='clickable']").click(function(event){
        $.post(
            "/jq_calls/jq_server.php?q=manage_caddy",
            {request:event.currentTarget.id},
            function(data, textStatus){ 
                if(textStatus == 'success') {
                    if(data == 'full') {
                        $(location).attr('href','/order/panier.php');
                    } else {
                        $(location).attr('href','/');
                    }
                }
            }, 
            "text" 
        );
    });
    
    $("#form_order").find("span[class*='clickable']").click(function(event){
        $.post(
            "/jq_calls/jq_server.php?q=manage_caddy",
            {request:event.currentTarget.id},
            function(data, textStatus){ 
                if(textStatus == 'success') {
                    if(data == 'full') {
                        $(location).attr('href','/order/mode.php');
                    } else {
                        $(location).attr('href','/');
                    }
                }
            }, 
            "text" 
        );
    });
});


function MM_openBrWindow_2(theURL,winName,features) { //v2.0
var theURL_2="zzz";
//alert(document.zzz.email.value);
if (document.zzz.email.value=="") {}
else
    {
    theURL_2="newsletter_email.php?email="+document.zzz.email.value;
    window.open(theURL_2,winName,features);
    document.zzz.email.value="";
    }
}