// ************************************************************
// Fonction permettant de modifier le pointeur de la sourie
// --- PARAMETRES
// En entrée : LaLigne(Objet ligne tableau)
// En entrée : LAction(over ou click ou out)
// En sortie : aucun

function ModifPointeur (LaLigne, LAction){
  if (LAction == 'over' || LAction == 'click'){
    LaLigne.style.cursor='pointer';
  }
  else {
    LaLigne.style.cursor='default';
  }
}

// ************************************************************
// Fonction permettant de modifier la valeur DBId
// puis POST le formulaire
// --- PARAMETRES
// En entrée : Formulaire(Nom du formulaire)
// En entrée : DBElement(Nom du champ DBId..... a mettre a jour)
// En entrée : ValeurId(Nouvelle valeur du champ)
// En entrée : ActionFrm(Action que le formulaire doit executer)
// En sortie : aucun

function ValidFormulaire(Formulaire, DBElement, ValeurId, ActionFrm){
  if (Formulaire!='') {

    if (DBElement!='' && ValeurId!=''){
      document.forms[Formulaire].elements[DBElement].value=ValeurId;
    }

    if (ActionFrm!=''){
      document.forms[Formulaire].action=ActionFrm;
    }

    document.forms[Formulaire].submit();
  }
}

// ************************************************************
// Fonction permettant de modifier la virgule en point
// --- PARAMETRES
// En entrée : Le champ a modifier
// En sortie : aucun

function RemplaceVirgule(Champ) {
  var reg=new RegExp("(,)", "g");
  var tmpChaine=Champ.value;
  if (tmpChaine.search(reg)!=-1) {
    Champ.value=tmpChaine.replace(reg,".");
  }
}


// ****************************************************************
// Fonction permettant de calculer les montants de la note de frais
// pendant l'édition ou la création d'un sous-détail
// --- PARAMETRES
// En entrée : aucun
// En sortie : aucun


function CalculMontant() {
  RemplaceVirgule(FormSousDetail.MontantTTC);
  RemplaceVirgule(FormSousDetail.Quantite);

  if (isNaN(FormSousDetail.MontantTTC.value)) {FormSousDetail.MontantTTC.value="";}
  if (isNaN(FormSousDetail.Quantite.value))   {FormSousDetail.Quantite.value="";}

  if (!(isNaN(FormSousDetail.MontantTTC.value)) && !(isNaN(FormSousDetail.Quantite.value))) {

    FormSousDetail.Quantite.value=Math.abs(parseInt(FormSousDetail.Quantite.value)) + '';
    FormSousDetail.MontantTTC.value = Math.round(FormSousDetail.MontantTTC.value * 100)/100;

    var reg=new RegExp("[|]+", "g");
    var tmpNature = FormSousDetail.IdNature.options[FormSousDetail.IdNature.selectedIndex].value;
    var TblParam = tmpNature.split(reg);
    var DBTypeMontant = TblParam[2];
    var DBMontantBas = parseFloat(TblParam[3]);
    var DBMontantTTC = Math.round(parseFloat(FormSousDetail.MontantTTC.value)*100)/100;
    var DBQuantite = parseInt(FormSousDetail.Quantite.value);

    if (DBTypeMontant=='F') {
      FormSousDetail.MontantTTC.value = Math.round(DBMontantBas * DBQuantite * 100) / 100;
    }

    if ((DBTypeMontant=='M') && ((DBMontantTTC / DBQuantite) <= DBMontantBas)) {
      alert("Le montant maximum pour 1 est " + DBMontantBas);
      FormSousDetail.MontantTTC.value = Math.round(DBMontantBas * DBQuantite * 100) / 100;
    }

    DBMontantTTC = parseFloat(FormSousDetail.MontantTTC.value);

    if (FormSousDetail.CodeTVA.value!='') {
      var DBTauxTVA = parseFloat(FormSousDetail.CodeTVA.options[FormSousDetail.CodeTVA.selectedIndex].text)/100+1;
      FormSousDetail.MontantTVA.value = (Math.round(DBMontantTTC * ( 1 - 1 / DBTauxTVA )*100)/100) + "";
    }
  }
}


// ****************************************************************
// Fonction permettant d'ouvrir popup avec un envoi de données par POST
// --- PARAMETRES
// En entrée : le formulaire
// En sortie : aucun
function pop_it(the_form, largeur, hauteur) {
  my_form = eval(the_form)
  window.open("./wait.php", "popup", "height=" + hauteur + ",width=" + largeur + ",menubar='no',toolbar='no',location='no',status='no',scrollbars='yes'");
  my_form.target = "popup";
  my_form.submit();
}

// ****************************************************************
// Fonction permettant d'ouvrir popup avec un envoi de données par POST
// --- PARAMETRES
// En entrée : le formulaire
// En sortie : aucun
function get_nom_fichier(varchemin) {
  var chemincomplet = "" + varchemin;
  var nomfichiercomplet = "";
  var nomfichier = "";

  if (chemincomplet.lastIndexOf("/") > -1)
  {nomfichiercomplet = chemincomplet.substring(chemincomplet.lastIndexOf("/")+1);}
  else {nomfichiercomplet = chemincomplet;}

  if (nomfichiercomplet.lastIndexOf(".") > -1)
  {nomfichier = nomfichiercomplet.substring(0,nomfichiercomplet.lastIndexOf("."));}
  else {nomfichier = nomfichiercomplet;}

  return nomfichier;
}

/******************************************************************************/
/* Fonction permettant de modifier l'état d'une ligne dans une liste          */
/* --- PARAMETRES                                                             */
/* En entrée : la ligne a modifier                                            */
/* En sortie : aucun                                                          */
/******************************************************************************/
var LignePrec = '';

function SelectLigne(LaLigne) {
  if (LignePrec!=LaLigne) {
    if (LignePrec!='') {
      var element1 = document.getElementById('Ligne' + LignePrec);
      element1.className = "ligne_no_select";
    }
    LignePrec=LaLigne;
    var element2 = document.getElementById('Ligne' + LaLigne);
    element2.className = "ligne_select";
  }
}

/******************************************************************************/
/* Fonction permettant de modifier l'état d'une ligne dans une liste          */
/* --- PARAMETRES                                                             */
/* En entrée : la ligne a modifier                                            */
/* En sortie : aucun                                                          */
/******************************************************************************/
var LigneBisPrec = '';

function SelectLigneBis(NomLigne, IdSelect, NomPrec) {
  //if ( document.getElementById( NomPrec ).value != IdSelect ) {
    if (document.getElementById( NomPrec ).value != '') {
      //var element1 = document.getElementById(NomLigne + document.getElementById(NomPrec).value);
      //element1.className = "ligne_no_select";
      document.getElementById( NomLigne + document.getElementById( NomPrec ).value ).className = "ligne_no_select";
    }
    document.getElementById( NomPrec ).value = IdSelect;
    //var element2 = document.getElementById( NomLigne + IdSelect );
    //element2.className = "ligne_select";
    document.getElementById( NomLigne + IdSelect ).className = "ligne_select";
  //}
}

// ****************************************************************
// Fonction permettant afficher correctement les images *.PNG
// --- PARAMETRES
// En entrée : aucun
// En sortie : aucun
function pngfix() {
  var arVersion = navigator.appVersion.split("MSIE")
  var version = parseFloat(arVersion[1])

  if ((version >= 5.5) && (document.body.filters)) 
  {
     for(var i=0; i<document.images.length; i++)
     {
        var img = document.images[i]
        var imgName = img.src.toUpperCase()
        if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
        {
           var imgID = (img.id) ? "id='" + img.id + "' " : ""
           var imgClass = (img.className) ? "class='" + img.className + "' " : ""
           var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
           var imgStyle = "display:inline-block;" + img.style.cssText 
           if (img.align == "left") imgStyle = "float:left;" + imgStyle
           if (img.align == "right") imgStyle = "float:right;" + imgStyle
           if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
           var strNewHTML = "<span " + imgID + imgClass + imgTitle
           + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
           + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
           + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
           img.outerHTML = strNewHTML
           i = i-1
        }
     }
  }
}



