/* ----------------------------------------------------
 Objet  : Type de navigateur et version
 Création: OCEI - 11/07/02
 __Auteur______________Date_____________Objet__________
 Alex.F & Omar.T   | 11/07/02 | Création
-------------------------------------------------------*/

var ie = (document.all) ? true : false;
var ns6 = (document.getElementById && !document.all) ? true : false;

/* ----------------------------------------------------
 Objet  : Gestion IE 5 & 6  et NS 6
 Création: OCEI - 04/10/2002
 __Auteur_______________Date_____________Objet__________
  Alex.F & Omar.T    | 04/10/02 | Création
-------------------------------------------------------*/

function getElement(idElem){
	
	if (ie)	
		return document.all[idElem];
	else
		return document.getElementById([idElem]);
}



/* ----------------------------------------------------
 Objet  : Affiche la liste despièces détachées
 Création: OCEI - 04/10/2002
 __Auteur_______________Date_____________Objet__________
  Alex.F & Omar.T    | 04/10/02 | Création
-------------------------------------------------------*/

function affiPiece(prm1, prm2) {
	document.forms["formMenu"].action = "pro.asp";
	document.forms["formMenu"].zProd.value = prm1;
	document.forms["formMenu"].zPathProd.value = prm2;

	document.forms["formMenu"].submit();
}



/* ----------------------------------------------------
 Objet  : Lance les opérations de gestion du panier
 Création: OCEI - 04/10/2002
 __Auteur_______________Date_____________Objet__________
  Alex.F & Omar.T    | 04/10/02 | Création
-------------------------------------------------------*/

function gestionPanier(operation, uneLigne,zIdLigne, indice) {

	var qte = getElement("qte" + zIdLigne);	

	if (parseInt(qte.value) >= 0) {
		
		document.forms["formPiece"].action = "gestPanier.asp";
		document.forms["formPiece"].zQte.value = qte.value;	
			
		// Type d'opération A, I, D, U
		document.forms["formPiece"].frmOper.value = operation;
		
	
		switch (operation)
		  { case "A" : { // En ajout au panier
							document.forms["formPiece"].uneLigne.value = uneLigne;
							document.forms["formPiece"].zIdLigne.value = zIdLigne;
					};break;
			default : {	// En modification et suppression
						document.forms["formPiece"].indTab.value = indice;
					  };break;
	
		 }
		
	
		document.forms["formPiece"].submit();
	}
		
}



/* -------------------------------------------------------------
 Objet  : Teste les zones numériques sur la liste des commandes
 Création: OCEI - 04/10/2002
 __Auteur_______________Date_____________Objet__________________
  Alex.F & Omar.T    | 04/10/02 | Création
----------------------------------------------------------------*/

function testNumerique(idLigne) {
	
   var zQte = getElement("qte" + idLigne);
   var nombre=parseInt(zQte.value);
    	 	
   if(isNaN(nombre)) {
		alert('La saisie n\'est pas valide !');
		zQte.value="";
		zQte.focus();
	}

}


/* -------------------------------------------------------------------------------------
 Objet  : formate un chiffre avec 'decimal' chiffres après la virgule et un separateur
 Création: OCEI - 04/10/2002
 __Auteur_______________Date_____________Objet__________________________________________
  Alex.F & Omar.T    | 04/10/02 | Création
----------------------------------------------------------------------------------------*/
function formatNumber(valeur,decimal,separateur) {

	var fn_deci=Math.round(Math.pow(10,decimal)*(Math.abs(valeur)-Math.floor(Math.abs(valeur))));
	var fn_val=Math.floor(Math.abs(valeur));
	
	if ((decimal==0)||(fn_deci==Math.pow(10,decimal))) {val=Math.floor(Math.abs(valeur)); fn_deci=0;}
	
	var fn_val_format=fn_val+"";
	var fn_nb=fn_val_format.length;
	
	for (var i=1;i<4;i++) {
		if (fn_val>=Math.pow(10,(3*i))) {
			fn_val_format=fn_val_format.substring(0,fn_nb-(3*i))+separateur+fn_val_format.substring(fn_nb-(3*i));
		}
	}
	
	if (decimal>0) {
		var fn_decim=""; 
		for (var j=0;j<(decimal-fn_deci.toString().length);j++) {fn_decim+="0";}
		fn_deci=fn_decim+fn_deci.toString();
		fn_val_format=fn_val_format+"."+fn_deci;
	}
	
	if (parseFloat(valeur)<0) {fn_val_format="-"+fn_val_format;}
	
	return fn_val_format;
}



/* ----------------------------------------------------------
 Objet  : Affichage du total HT
 Création: OCEI - 04/10/2002
 __Auteur_______________Date_____________Objet_______________
  Alex.F & Omar.T    | 04/10/02 | Création
-------------------------------------------------------------*/

function afficheTotalHT(totHT) {

	totHT = Math.round(totHT*100)/100 +"";

	var totalHT = getElement("totHT");
	totalHT.innerHTML = formatNumber(totHT,2," ");
}


/* ----------------------------------------------------
   Affiche une nouvelle fenêtre popup
-------------------------------------------------------*/

function windowPopup(imgName, zProd) {

  var monURL;
  var idFenetre;
    
  monURL = "eclate.asp?imgPath=" + imgName.toString() + "&zProd=" + zProd.toString();
  
  idFenetre = window.open(monURL,"","scrollbars=yes,width=600,height=450,location=no,status=no,menubar=no,resizable=yes");
  idFenetre.focus();

}



/* ------------------------------------------------------
   Teste des champs obligatoires du formulaire
----------------------------------------------------------*/

function testFormulaire(type) {
var valid=true;
var msg = "";

var societe=getElement("txtSocieteFact");
var commande=getElement("txtnumCmd");
var rdbCli=getElement("rdbCliOui");
var client=getElement("txtNoClientFact");
var adresse1=getElement("txtAdresseFact");
var adresse2=getElement("txtAdresseFact2");
var ville=getElement("txtVilleFact");
var cp=getElement("txtCPFact");
var contact=getElement("txtNomFact");
var rdbCat=getElement("rdbCat5");
var categorie=getElement("txtAutre");


// Test Société

if (societe.value=="") {
	msg += "Saisie de la Société à facturer obligatoire.\n";
	valid=false;
}

// Numéro de commande

if (commande.value=="") {
	msg += "Saisie des vos références / N° de commande obligatoire.\n";
	valid=false;
}

// Test Client

if (rdbCli.checked == true && client.value=="") {
	msg += "Saisie du N° client obligatoire.\n";
	valid=false;
}

// Test adresse

if (adresse1.value=="" && adresse2.value=="") {
	msg += "Saisie de l'adresse de facturation obligatoire.\n";
	valid=false;
}


// Test Ville

if (ville.value=="") {
	msg += "Saisie de la ville obligatoire.\n";
	valid=false;
}


// Test Code Postal

if (cp.value=="") {
	msg += "Saisie du code postal obligatoire.\n";
	valid=false;
}


// Test Nom du contact

if (contact.value=="") {
	msg += "Saisie du nom du contact obligatoire.\n";
	valid=false;
}


// Test Autre catégorie

if (rdbCat.checked == true && categorie.value=="") {
	msg += "Saisie de la catégorie autre obligatoire.\n";
	valid=false;
}


  if (valid==true) {
    if (type=="E")
       sendEmail();
    else
       windowImpression();
   }
   else
     alert(msg);

}



/* ------------------------------------------------------
   Affiche une nouvelle fenêtre popup pour l'impression
----------------------------------------------------------*/

function windowImpression() {

  var monURL;
  var idFenetre;

  monURL = "impression.asp";
  
  idFenetre = window.open(monURL,"Impression","scrollbars=yes,width=650,height=650,location=no,status=no,menubar=no,resizable=yes,top=20, left=150");
  idFenetre.focus();

  document.forms['formInscription'].target = idFenetre.name;
  document.forms['formInscription'].action = monURL;
  document.forms['formInscription'].submit();

}



/* ------------------------------------------------------
   Envoi la commande par Email
----------------------------------------------------------*/

function sendEmail() {

  var monURL;
    
  monURL = "sendmail.asp";

  document.forms['formInscription'].target = "_self";
  document.forms['formInscription'].action = monURL;
  document.forms['formInscription'].submit();

}


/* ----------------------------------------------------
 Objet  : Lance la validation du Panier
 Création: OCEI - 04/10/2002
 __Auteur_______________Date_____________Objet__________
  Alex.F & Omar.T    | 04/10/02 | Création
-------------------------------------------------------*/

function validerPanier() {
  document.forms["formPiece"].action = "inscription.asp";
  document.forms["formPiece"].submit();
}


/* ----------------------------------------------------
 Objet  : Lance la validation du Panier
 Création: OCEI - 04/10/2002
 __Auteur_______________Date_____________Objet__________
  Alex.F & Omar.T    | 04/10/02 | Création
-------------------------------------------------------*/

function imprimerInscription() {
	
	if ((navigator.userAgent.indexOf("mac")!=-1) || (navigator.userAgent.indexOf("Mac")!=-1)) 
		alert("Votre navigateur ne supporte pas cette fonctionnalité!\nAppuyer sur APPLE + P pour imprimer cette page");
	else
	  {	if (window.print)
	       window.print();
	    else
   		alert("Votre navigateur ne supporte pas cette fonctionnalité!\nAppuyer sur CONTROL + P pour imprimer cette page");

	  }
}


/* ----------------------------------------------------------
   Affiche une nouvelle fenêtre popup pour "login incorrect"
------------------------------------------------------------*/

function windowPwd() {

  var monURL;
  var idpwd;

  monURL = "FR/Source/EspacePro/erreurpwd.asp";
  
  idpwd = window.open(monURL,"pwd","top=200, left=300,titlebar=no, toolbar=no,scrollbars=no,width=300,height=130,location=no,status=no,menubar=no,resizable=no");
  idpwd.focus();

}
