/* // remplacé par la redex:
function Trim(s)  { // Remove leading spaces and carriage returns
        while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r')) {
                s = s.substring(1,s.length);
        }
        // Remove trailing spaces and carriage returns
        while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r')) {
                s = s.substring(0,s.length-1);
        }
        return s;
}
*/
var compiledCheckNumberRedex = new RegExp(/(^[0-9]+$)|(^[0-9]+\.[0-9]*$)/);
var compiledSearchSpaceRedex = new RegExp(/ /g);
var compiledSearchVirguleRedex = new RegExp(/,/g);

function removeAllSpaces(str)
{
  return str.replace(compiledSearchSpaceRedex, '');
}

function Pluriel(nb)
{
   if (nb > 1)
       return 's';
   else
       return '';
}

function PlurielX(nb, str)
{
   if (nb > 1)
       return str;
   else
       return '';
}

function LeastOne(nb, str)
{
   if (nb > 0)
       return str;
   else
       return '';
}

function cleanNumber(str) {
  // suppression des espaces et convertion des "," en "." (sans redex)
  var result = '';
  var i;
  for (i=0; i < str.length; i++)
  {
    if (str.substr(i, 1) == ' ')
      ;// rien
    else if (str.substr(i, 1) == ',')
      result += '.';
    else result += str.substr(i, 1);
  }
  //result = result.replace(compiledSearchVirguleRedex, '.');
  //result = result.replace(compiledSearchSpaceRedex, '');

  return result;
}

function checknumber(str){
        var chaine = cleanNumber(str);
        return compiledCheckNumberRedex.test(chaine);
}

function pdix(i) {
    if (i == 0)
        return 1;
    else return 10*pdix(i-1);
}

function DigestNumberFormat(number, nb_decimals) {
    return Math.round( number*pdix(nb_decimals) ) / pdix(nb_decimals);
}

function catchJSonError(str)
{
    // alert("evalJSON fail on: "+str);
}

function EvalJSon(str)
{
    return str.evalJSON(true);     
}
/*
// dans body.onload ==> if (parent.adjustIFrameSize) parent.adjustIFrameSize(window); 
// appellé par le onload des frames 
function adjustIFrameSize(sender)
{
    var offsetHeight = 0;
    if (Prototype.Browser.IE)
        offsetHeight = 5;

    if (document)
    
        $(sender.name).style.height = (sender.document.body.scrollHeight+offsetHeight)+'px';
    //document.getElementById(sender.name)
}
*/
// source: http://www.editeurjavascript.com/scripts/scripts_navigation_3_183.php
// Utilisation: spop( 'monfichier.html', 'MaPopup', 100, 100, 'Mes options (Facultatif)' )
// spop( fichier, nom, largeur, hauteur, options )
var temp = 0;
function kamaPopup( fichier, nom, largeur, hauteur, options )
{
    //window.open ('fenetre_popup.html', 'nom_interne_de_la_fenetre', config='height=100, width=400, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no')

	var gauche = ( screen.width - largeur ) / 2;
  	var haut = ( screen.height - hauteur ) / 2;
  	var optionsOut = 'width=' + largeur + 'px,height=' + hauteur + 'px,top=' + haut + ',left=' + gauche;
  	if (options)
  	 optionsOut = optionsOut + ',' + options;
  	
  	var newwindow = window.open(fichier, nom, optionsOut);
    newwindow.focus();
    
    return false;
}

var uniqueID_autoIncremente = 0;
function generateUniqueID()
{
    return ('uniqueGeneratedID_'+(++uniqueID_autoIncremente));
}

function EnumToTxt(data, source)
{
    var result = '';
    
    if (data.length > 0)
    {
        for (var i = 0; i < data.length; ++i)
        {
            if (source[data[i]] && source[data[i]] != '')
                result += source[data[i]] + ' ';
            /*
            else
                if (! source[data[i]] && source[data[i]] != '')
                    alert('EnumToTxt: ->'+data[i]+'<- n\'existe pas dans '+Object.toJSON(source));
            */
        }
    }
    return result;
}


