//validation des form user
function wuUserFormSubmit(Form, action) {
  window.location.href='#haut'; 
  doRequest('wuAjax.php?phpFile=plugins/wuCommerce/user/wuUser_store.php&location=3&divID=wuContent&wuStoreAction='+action, 'wuContent', getDataFromForm(Form));  
}
//validation des form cmde
function wuCmdeFormSubmit(Form, action) {
  window.location.href='#haut'; 
  doRequest('wuAjax.php?phpFile=plugins/wuCommerce/cmde/wuCmde_store.php&location=3&divID=wuContent&wuStoreAction='+action, 'wuContent', getDataFromForm(Form));  
}
//Paiement de la commande
function wuCmdePaieSubmit(paie, action) {
  window.location.href='#haut'; 
  doRequest('wuAjax.php?phpFile=plugins/wuCommerce/cmde/wuCmde_store.php&location=3&divID=wuContent&wuStoreAction='+action+'&wuPaie='+paie, 'wuContent');  
}
//validation des form account
function wuAccountFormSubmit(Form, action) {
  window.location.href='#haut'; 
  doRequest('wuAjax.php?phpFile=plugins/wuCommerce/account/wuAccount_store.php&location=3&divID=wuContent&wuStoreAction='+action, 'wuContent', getDataFromForm(Form));  
}
//Operations sur le caddy
function wuCaddyStore(id, qte, action, fct) {
  if(document.getElementById('wuCaddyDetail')) wuCaddyDetail = 1;
  else wuCaddyDetail = 0;
  doRequest('wuAjax.php?phpFile=plugins/wuCommerce/caddy/wuCaddy_store.php&location=3&divID=wuCaddy_shortcut&wuObjID='+id+'&wuQte='+qte+'&wuStoreAction='+action+'&wuCaddyDetail='+wuCaddyDetail+'&wuFct='+fct, 'wuCaddy_shortcut');
}
//vers le catalogue
function wuGoCat(id) {
  window.location.href='index.php?ID='+id;
}
//vers ma commande
function wuGoCmde(etape) {
  window.location.href='#haut'; 
  doRequest('wuAjax.php?phpFile=plugins/wuCommerce/cmde/wuCmde_content.php&location=3&divID=wuContent&wuEtape='+etape, 'wuContent');
}
//vers mon panier
function wuGoCaddy() {
  window.location.href='#haut'; 
  doRequest('wuAjax.php?phpFile=plugins/wuCommerce/caddy/wuCaddy_content.php&location=3&divID=wuContent', 'wuContent');
}
//vers mon compte
function wuGoAccount(etape, id, partnerFact, partnerLivr) {
  window.location.href='#haut'; 
  doRequest('wuAjax.php?phpFile=plugins/wuCommerce/account/wuAccount_content.php&location=3&divID=wuContent&wuEtape='+etape+'&wuObjID='+id+'&wuPartnerFact='+partnerFact+'&wuPartnerLivr='+partnerLivr, 'wuContent');
}
//Envoi par mail de la commande
function wuSendCmde(id) {
  window.location.href='#haut'; 
  doRequest('wuAjax.php?phpFile=plugins/wuCommerce/account/wuAccount_store.php&location=3&wuStoreAction=sendCmde&divID=wuCmde_detail&wuObjID='+id, 'wuCmde_detail');
}
//affichage ou non du form contact livraison
function wuShowCmdeContact(div) {
  if(document.getElementById(div).style.display == 'none') {
    document.getElementById(div).style.display = 'block';
  }
  else { document.getElementById(div).style.display = 'none'; }
}
//Changement de couleur des input modifies
function wuViewUpdate(obj) {
  obj.style.color = '#155db0';
}
//Visibilite du resume caddy
function wuViewResumeCaddy() {
  if(document.getElementById('wuCaddy_resume').style.display == 'none') wuOpenResumeCaddy();
  else wuCloseResumeCaddy();
}
//Ouverture resume caddy
function wuOpenResumeCaddy() {
  document.getElementById('wuCaddy_resume').style.display = 'block';
  doRequest('wuAjax.php?phpFile=plugins/wuCommerce/caddy/wuCaddy_resume.php&location=3&divID=wuCaddy_resume', 'wuCaddy_resume');
}
//fermeture resume caddy
function wuCloseResumeCaddy() {
  document.getElementById('wuCaddy_resume').style.display = 'none';
}
//Ouverture alert caddy
function wuOpenAlertCaddy() {
  wuParamMasque('wuCaddy_alert', '450');
  doRequest('wuAjax.php?phpFile=plugins/wuCommerce/caddy/wuCaddy_alert.php&location=3&divID=wuCaddy_alert', 'wuCaddy_alert');
}
//fermeture alert caddy
function wuCloseAlertCaddy() {
  document.getElementById('masque').style.width = 0;
  document.getElementById('masque').style.height = 0;
  document.getElementById('wuCaddy_alert').style.display = 'none';
}
//Ouverture detail de la commande
function wuOpenCmdeDetail(id) {
  window.open('wuCmde_detail.php?wuObjID='+id,'cmde', 'menubar=no, status=no, scrollbars=yes, menubar=no, width=800, height=550');
}
//parametre affichage masque
function wuParamMasque(div, widthDiv) {
  //param en fonction navigateur
  //----------------------------
  if (isIE()) {
    if(document.body.clientHeight > document.getElementById('index').offsetHeight) var height = document.body.clientHeight;
    else var height = document.getElementById('index').offsetHeight;
    var width = document.body.offsetWidth + document.body.scrollLeft;    
  } else { 
    if(window.innerHeight > document.height) var height = window.innerHeight;
    else var height = document.height;
    var width = document.width;
  }
  //affichage du masque et div
  //--------------------------
  document.getElementById('masque').style.width = width+'px';
  document.getElementById('masque').style.height = height+'px';
  document.getElementById('masque').style.backgroundColor = '#cccccc';
  document.getElementById('masque').style.zIndex = '3000';
  document.getElementById('masque').style.left = 0;
  document.getElementById('masque').style.top = 0
  document.getElementById(div).style.zIndex = '5000';
  document.getElementById(div).style.display = 'block';
  //POsitionnement
  //--------------
  if (isIE()) {
    var popupLeft = document.body.scrollLeft + ((document.body.offsetWidth - widthDiv) / 2) ;
    var popupTop = document.body.scrollTop + ((document.body.clientHeight - document.getElementById(div).offsetHeight) / 2) ; 
    document.getElementById('masque').style.filter = 'alpha(opacity=50)';    
  }
  else {       
    var popupLeft = window.pageXOffset + ((window.innerWidth - widthDiv) / 2) ; 
    var popupTop = window.pageYOffset + ((window.innerHeight - document.getElementById(div).offsetHeight) / 2) ; 
    document.getElementById('masque').style.opacity = '0.5';   
  }
  document.getElementById(div).style.left = popupLeft+'px'; 
  document.getElementById(div).style.top = popupTop+'px';
}
//Verification des champ des form contact
function wuVerifContactForm(id) {
  var Form = document.getElementById(id);
  for (key=0;key<Form.elements.length;key++) {
    if(Form.elements[key].id.indexOf('mail') != -1 && Form.elements[key].value != '') {
      var mail = new String(Form.elements[key].value);
      if (!mail.match('^[-_\.0-9a-zA-Z]{1,}@[-_\.0-9a-zA-Z]{1,}[\.][0-9a-zA-Z]{2,}$')) {
        alert('Merci de renseigner une adresse E-mail valide');
        Form.elements[key].focus();
        return false;   
      }      
    }
    if(Form.elements[key].type == 'radio' && Form.elements[key].className.indexOf('oblige') != -1) {                  
      if (document.getElementById('partner_livr') && !document.getElementById('partner_livr').checked && Form.elements[key].name.indexOf('contact_contact') != -1) {
        continue;
      }
      var myRadio = document.getElementsByName(Form.elements[key].name);
      var checked = false;
      for (var cpt = 0 ; (cpt < myRadio.length) && !checked ; cpt++) {
        checked = checked || myRadio[cpt].checked;
      }
      if (!checked) {
        alert('Merci de renseigner tous les champs obligatoires.');
        return false;           
      }
    } 
    if(Form.elements[key].value == '' && Form.elements[key].className.indexOf('oblige') != -1) {
      if (document.getElementById('partner_livr') && !document.getElementById('partner_livr').checked && Form.elements[key].name.indexOf('contact_contact') != -1) {
        continue;
      }
      alert('Merci de renseigner tous les champs obligatoires.');
      Form.elements[key].focus();
      return false;
    }    
  }  
}
