// ================================================================
// GetYear: Get the year. 
// Redefinition de la fonction GetYear car:
// Avec Netscape: 2000 => 100
// Avec IE:       2000 => 2000
// ================================================================ 
function GetTheYear(date)
{
  year = date.getYear();

  if (year <= 1900)
    {
      year += 1900;
    }

  return year;
}

// ================================================================
// UpdateSelect: Update un object SELECT d'un formulaire
// ================================================================ 
function UpdateSelect(name, value)
{
  selname = eval("document.forms[0]."+name);

  if (selname != null)
    {
      for (idx=0; idx<selname.length; idx++)
	{
	  if (selname.options[idx].value == value)
	    {
	      selname.selectedIndex = idx;
	    }
	}
    }
}

// =========================
// openNewWindow
// =========================
function openNewWindow(theURL,winName,features) { 
  h=window.open(theURL,winName,features);
  h.opener=self ;
  return h;
}

// =========================
// DisplayInfo
// =========================
function DisplayInfo(type, message)
{
  switch (type)
    {
    case 'status':  // Display message in the navigation bar 
      self.status=message;
      break;
    case 'window':  // Display message in a new window
      alert(message);
      break;
    default:        // No display
      alert(message);
      break;
    }
}

// =========================
// putFocus
// =========================
function putFocus(Element)   {
  Element.select();
  Element.focus();
}

// =========================
// get_PhoneNumberFormat:
// 
// Get the phone number format
// =========================
function get_PhoneNumberFormat(sCountry)
   {
     var sPhoneNumFormat="";

     switch (sCountry)
       {
       case "FR":
	 sPhoneNumFormat="##########";
	 break;
       case "CA":
	 sPhoneNumFormat="(###) ###-####";
	 break;
       case "UK":
	 sPhoneNumFormat="(###) ###-####";
	 break;
       case "DE":
	 sPhoneNumFormat="###/### ## ##";
	 break;
       case "IT":
	 sPhoneNumFormat="(###) ### ## ##";
	 break;
       case "CH":
	 sPhoneNumFormat="## ## ### ## ##";
	 break;
       default:
	 break;
       }

     return sPhoneNumFormat;
   }

// =========================
// get_AreaCodeFormat
// 
// Get the zip code format
// =========================
function get_AreaCodeFormat(sCountry)
   {
     var sAreaCodeFormat="";

     switch (sCountry)
       {
       case "FR":
	 sAreaCodeFormat="#####";
	 break;
       case "CA":
	 sAreaCodeFormat="?#?#?#";
	 break;
       case "UK":
	 sAreaCodeFormat="#####";
	 break;
       case "DE":
	 sAreaCodeFormat="#####";
	 break;
       case "IT":
	 sAreaCodeFormat="#####";
	 break;
       case "CH":
	 sAreaCodeFormat="#####";
	 break;
       default:
	 break;
       }

     return sAreaCodeFormat;
   }

// =========================
// get_DateFormat
// 
// Get the date format
// =========================
function get_DateFormat(sCountry)
   {
     var sDateFormat="";

     switch (sCountry)
       {
       case "FR":
	 sDateFormat="##/##/####";
	 break;
       case "CA":
	 sDateFormat="##/##/####";
	 break;
       case "UK":
	 sDateFormat="##/##/####";
	 break;
       case "DE":
	 sDateFormat="##/##/####";
	 break;
       case "IT":
	 sDateFormat="##/##/####";
	 break;
       case "CH":
	 sDateFormat="##/##/####";
	 break;
       default:
	 break;
       }

     return sDateFormat;
   }

// =========================
// mask
// =========================
function mask (InString, Mask)  {
        LenStr = InString.length;
        LenMsk = Mask.length;
        if ((LenStr==0) || (LenMsk==0))
                return(false);
        if (LenStr!=LenMsk)
                return(false);
        TempString="";
        for (Count=0; Count<=InString.length; Count++)  {
                StrChar = InString.substring(Count, Count+1);
                MskChar = Mask.substring(Count, Count+1);
                if (MskChar=='#') {
                        if(!isNumberChar(StrChar))
                                return(false);
                }
                else if (MskChar=='?') {
                        if(!isAlphabeticChar(StrChar))
                                return(false);
                }
                else if (MskChar=='!') {
                        if(!isAlphaNumChar(StrChar))
                                return(false);
                }
                else if (MskChar=='*') {
                }
                else {
                        if (MskChar!=StrChar) 
                                return(false);
                }
        }
        return true;
}

function stripNonNumbers (InString)  
   {
     OutString="";
     for (Count=0; Count < InString.length; Count++)  {
       TempChar=InString.substring (Count, Count+1);
       Strip = false;
       CharString="0123456789";
       for (Countx = 0; Countx < CharString.length; Countx++) {
	 StripThis = CharString.substring(Countx, Countx+1)
	   if (TempChar == StripThis) {
	     Strip = true;
	     break;
	   }
       }
       if (Strip)
	 OutString=OutString+TempChar;
     }
     return (OutString);
   }


// Supprime les espaces devant et derrière une chaine
function DeleteSpaces (OutString)  
   {
     InString = OutString;
     // Enlève les espaces devant la chaine
     while (InString.substring(0,1) == " ")
       {
	 InString = InString.substring(1,InString.length)
       }
     // Enlève les espaces derrière la chaine
     while (InString.substring(InString.length-1,1) == " " )
       {
	 InString = InString.substring(1,InString.length)
       }

     return (InString);
   }

// Supprime TOUS les espaces dans une chaine
function stripSpaces (InString)  
   {
     OutString="";
     for (Count=0; Count < InString.length; Count++)  
       {
	 TempChar=InString.substring (Count, Count+1);
	 Strip = true;

	 if (TempChar == ' ') {
	   Strip = false;
	 }
	 if (Strip)
	   OutString=OutString+TempChar;
       }
     return (OutString);
   }



function SubmitIfCR(form, key)
{
  if (changedfield != 0 && (key == 13 || key == 65293)) {
    form.submit();
  } else {
    changedfield = 1;
  }
}
 <!-- Hide script

//
// Ascii (or Character) to Hexidecimal
//        string = hex(numeric)
//        string = hex(character)
//        (returns empty string on error or empty string)
//
// Character (or Hexidecimal )to Ascii
//        numeric = asc(character)
//        numeric = asc(string)
//        (returns -1 on error or empty string)
//
// Ascii (or Hexidecimal) to Character
//        character = chr(numeric)
//        character = chr(string)
//        (returns empty string on error or 0 or "%00")
//
// internal function
//        chrListInit()
//        (creates chrList and hexList, returns nothing)
//
// Ascii must be numeric from 0 through 255.999999
// Hexidecimal must be a string of length 3 and prefix '%'
// Character must be a string of at least length 1
//
// All variables used are local except for chrList and hexList
// which is are global string of lengths 255 and 22
//
// Note: a character of ascii 0 terminates a string so
// converting %00 or 0 to a charcter returns an empty string
//
// -->
function chr(i) {
   if (typeof i == "number") {                          // invalid if not numeric
      if ((i >= 1) && (i < 256)) {                      // invalid if out of range
         if (typeof chrList != "string") chrListInit()  // init chrList if undefined
         return chrList.charAt(i-1)                     // chrList.charAt(0) = ascii 1
      }
   }
   if (typeof i == "string") {                          // if a string, might be hex
      if (i.length == 3) {                              // hex must be length 3
         if (i.charAt(0) == "%") {                      // hex must have prefix %
            var k = "0123456789ABCDEFabcdef"            // legal hex digits
            var j = i.charAt(1)                         // first digit
            var l = i.charAt(2)                         // second digit
            if ((k.indexOf(j) >= 0) && (k.indexOf(l) >= 0))
               return unescape("%"+j+l)
         }
      }
   }
   return ""                                            // fail, invalid
}

function hex(i) {
   if (typeof i == "number") {                          // invalid if not numeric
      if ((i >= 0) && (i < 256)) {                      // invalid if out of range
         var k = "0123456789ABCDEF"                     // hex digits
         var j = parseInt(i/16)                         // upper eight bits
         var l = parseInt(i) % 16                       // lower eight bits
         return "%" + k.charAt(j) + k.charAt(l)         // return result
      }
   }
   if (typeof i == "string") {                          // invalid if not string
      if (i.length > 0) {                               // invalid if null string
         if (typeof chrList != "string") chrListInit()  // init chrList if undefined
         var l = chrList.indexOf(i.charAt(0))+1
         var j = parseInt(l/16)                         // upper eight bits
         l %= 16                                        // lower eight bits
         return "%" + hexList.charAt(j) + hexList.charAt(l)
      }
   }
   return ""                                            // fail, invalid
}

function asc(i) {
   if (typeof i == "string") {                          // invalid if not string
      if (i.length == 3) {                              // invalid if incorrect string length
         if (i.charAt(0) == "%")  {                     // invalid if not prefixed with %
            var k = "0123456789ABCDEFabcdef"
            var j = k.indexOf(i.charAt(1))
            var l = k.indexOf(i.charAt(2))
            if ((j >= 0) && (l >= 0)) {                 // invalid if non-hex characers found
               if (j > 15) j -= 6                       // adjust for lower case
               if (l > 15) l -= 6
               return j * 16 + l
            }
         }
      }
   }
   if (typeof i == "string") {                          // invalid if not string
      if (i.length > 0) {                               // invalid if null string
         if (typeof chrList != "string") chrListInit()  // init chrList if undefined
         return chrList.indexOf(i.charAt(0))+1          // chrList.charAt(0) = ascii 1
      }
   }
   return -1                                            // fail, invalid
}

function chrListInit() {
   chrList = ""
   hexList = "0123456789ABCDEFabcdef"
   for (var i=0; i<16; i++)
      for (var j=0; j<16; j++)
         chrList += unescape("%" + hexList.charAt(i) + hexList.charAt(j))
}
// =========================================================
// Fonction qui permet de tout selectionner 
// ou tout déselectionner les checkbox du formulaire FormsNumber
// set bUpdateForms à true si bUpdate == 1
// En entrée :
//    FormsNumber : numéro du formulaire
//    ElementName : ElementName=nom des checkbox
//    nb : nombre d'éléments
//    value : true ou false
//    bUpdate : true ou false
// En sortie :
//  rien
// ex : SetAllCheckBox(0,'check_box[0]',".$nbLANG.",false,bUpdateForms,bUpdate,true)
// avec check_box[0],check_box[1],check_box[2], ...
// =========================================================
function SetAllCheckBox(FormsNumber,ElementName, nb, value, bUpdateName1, bUpdateName2, bUpdateValue)
{
  idx = GetIndexElement(FormsNumber,ElementName);
  for( idx2=idx; idx2<nb+idx; idx2++)
    {
    data = eval("document.forms["+FormsNumber+"].elements["+idx2+"]");
    data.checked = value;
    }
  if (bUpdateValue == 1)
    {
    idx = GetIndexElement(FormsNumber,bUpdateName1);
    element = eval("document.forms["+FormsNumber+"].elements["+idx+"]");
    element.value = 1;
    idx = GetIndexElement(FormsNumber,bUpdateName2);
    element = eval("document.forms["+FormsNumber+"].elements["+idx+"]");
    element.value = 1;
    }
}
// =========================================================
// Fonction qui permet de tout selectionner 
// ou tout déselectionner les checkbox du formulaire FormsNumber
// En entrée :
//    FormsNumber : numéro du formulaire
//    CHECKBOX_NAME : tableau contenant les noms des checkbox
//    value1 : true ou false
//    bUpdate : tableau contenant les noms de champs à affecter à bUpdateValue
//    value2 : true ou false
// En sortie :
//  rien
// ex : SetAllCheckBox2(0,CHECKBOX_NAME,false,bUpdate,true)
// avec CHECKBOX_NAME[0] = "checkbox_42",CHECKBOX_NAME[1] = "checkbox_26", CHECKBOX_NAME[2] = "checkbox_29" ...
// =========================================================
function SetAllCheckBox2(FormsNumber,CHECKBOX_NAME, value1, ElementName, value2)
  {
  for (i=0;i<CHECKBOX_NAME.length;i++)
    {
    idx = GetIndexElement(FormsNumber,CHECKBOX_NAME[i]);
    if (idx > -1)
      {
      element = eval("document.forms["+FormsNumber+"].elements["+idx+"]");
      element.checked = value1;
      }
    }
  for (i=0;i<ElementName.length;i++)
    {
    idx = GetIndexElement(FormsNumber,ElementName[i]);
    if (idx > -1)
      {
      element = eval("document.forms["+FormsNumber+"].elements["+idx+"]");
      if (value2)
        { element.value = 1; }
      else
        { element.value = 0; }
      }
    }
  }

// Fonction qui permet de selectionner ou déselectionner les checkbox du tableau
function SelectAllCheckBoxForm(noforms, begin, end, value) 
{
  for( idx=begin; idx<=end; idx++)
    {
      data = eval("document.forms["+noforms+"].elements["+idx+"]");
      data.checked = value;
    }
}

// Fonction qui permet de selectionner ou déselectionner les checkbox du tableau
function SelectAllCheckBoxFormByElemName(noforms, elemname, begin, end, value) 
{
  for( idx=begin; idx<=end; idx++)
    {
      data = eval("document.forms["+noforms+"]."+elemname+idx);
      data.checked = value;
    }
}

function SelectCheckBoxFormByElemName(nameforms, elemname, value) 
{
  iNbElem = eval("document."+nameforms+".length");
  var elemnameField = new String(elemname);
  for (idxelem = 1; idxelem <=iNbElem; idxelem++)
    {
      myelem = document.forms[0].elements[idxelem];
      if (typeof(myelem) != "undefined" && myelem.type == "checkbox")
	{
	  var nameField = new String(myelem.name);
	  if (nameField.substring(0, elemnameField.length) == elemnameField)
	    {
	      myelem.checked = value;
	    }
	}
    }
}

// =========================================================
// Fonction qui permet de selectionner 
// ou déselectionner les checkbox suivant les valeurs d'un
// tableau
// ex : SetCheckBox(0,"check_box", nb_checkbox, PART_LANG_INIT);
// En entrée :
//    FormsNumber : numéro du formulaire
//    ElementName : ElementName=nom des checkbox
//    nb : nombre d'éléments
//    tableau : array qui contient des chaînes
// En sortie :
//  rien
// =========================================================
function SetCheckBox(FormsNumber,ElementName, nb, tableau)
{
  idx = GetIndexElement(FormsNumber,ElementName);
  for( idx2=idx; idx2<nb+idx; idx2++)
    {
    data = eval("document.forms["+FormsNumber+"].elements["+idx2+"]");
    if (data.value == tableau[idx2-idx])
      {data.checked = true;}
    else
      {data.checked = false;}
    }
}
// ================================================
// Fonction qui permet de positionner l'index d'un
// objet select avec une valeur donnée
// introduit pour forms_identity.js.2.php
// En entrée :
//    ObjetSelect : objet select
//    Objet : objet avec lequel on récupère la valeur
// En sortie :
//  rien
// ================================================
function SetIndexSelect(ObjetSelect, Objet) 
{
idx = 0; taille = ObjetSelect.length;
while (idx < taille)
  {
  if (ObjetSelect.options[idx].value == Objet.value)
    { ObjetSelect.selectedIndex = idx; idx = taille;}
  idx++;
  }
}

// =========================================================
// Fonction qui retourne l'index d'un élément dans un
// formulaire donné, suivant son nom, -1 sinon
// En entrée :
//    FormsNumber : numéro du formulaire
//    ElementName : nom de l'élément recherché
// En sortie :
//  son index
//  - sinon
// ex : 
// =========================================================
function GetIndexElement(FormsNumber,ElementName)
  {
  idx =0;
  while (document.forms[FormsNumber].elements[idx].name != ElementName)
    { idx++;}
  if (document.forms[FormsNumber].elements[idx].name == ElementName)
    return (idx)
  else return(-1);
  }
// =========================================================
// Fonction qui pour un élément dans un
// formulaire donné, empêche l'utilisateur de modifier la
// valeur
// En entrée :
//    Element : élément recherché
// En sortie :
//    rien
// ex : 
// =========================================================
function ProtectElement(Element,flag)
  {
  if (flag == 1)
    { Element.blur(); }
  }

function SelectAllElemInSelectList(fname, name, bcheck)
{
  var bFound = false;
  if (fname != null)
    {
      elem = eval('document.'+fname+"."+name);

      if (elem == null)
	{
	  myforms = eval('document.'+fname);
	  
	  idx=1;
	  while(!bFound && idx<=myforms.length)
	    {
	      //alert(myforms.elements[idx].name);
	      if (myforms.elements[idx] != null && 
		  (myforms.elements[idx].name == name ||
		   myforms.elements[idx].name == name+'[]'))
		{
		  bFound= true;
		  elem = myforms.elements[idx];
		}
	      else
		{
		  idx++;
		}
	    }
	}

      if (elem != null)
	{
	  bFlag = true;
	  if (bcheck == 0) bFlag = false; 
	  for (iIdx=0; iIdx<elem.length; iIdx++)
	    {
	      elem.options[iIdx].selected = bFlag;
	    }
	}
    }
}

// =========================================================
// Fonction permettant d'afficher une URL dans une fenetre "popup"
// =========================================================
function DisplayUrlInWindows(url, width, height)
{
  windowOptions="toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,copyhistory=no,width="+width+",height="+height+",scrollbars=yes";
  window.open(url,"",windowOptions);
}

// =========================================================
// Fonction permettant d'afficher une popup centree dans l'ecran
// =========================================================
function DisplayPopupCenter(page,options,width,height) {
  if (width == 0) width = 490;
  if (height == 0) height = 580;
  if (screen.height > 720) height = 720;
  
  var top=(screen.height-height)/2;
  var left=(screen.width-width)/2;
  window.open(page, "_map","top="+top+",left="+left+",width="+width+",height="+height+","+options);
}

// =========================================================
// Fonction permettant d'afficher le didacticiel
// =========================================================
function DisplayDidacticiel(page,options) {
  width = 750;
  height = 470;
  
  var top=(screen.height-height)/2;
  var left=(screen.width-width)/2;
  window.open(page, "_map","top="+top+",left="+left+",width="+width+",height="+height+","+options);
}

function tjs_haut(l) {
	var indice=l.selectedIndex
	if (indice<0) {
		alert("Aucune ligne n'est sélectionnée");
	}
	if (indice>0) {	// Il reste une ligne au-dessus
		tjs_swap(l,indice,indice-1);
	}
}

function tjs_bas(l) {
	var indice=l.selectedIndex
	if (indice<0) {
		alert("Aucune ligne n'est sélectionnée");
	}
	if (indice<l.options.length-1) {	// Il reste une ligne en-dessous
		tjs_swap(l,indice,indice+1);
	}
}

function tjs_swap(l,i,j) {
	var valeur=l.options[i].value;
	var texte=l.options[i].text;
	l.options[i].value=l.options[j].value;
	l.options[i].text=l.options[j].text;
	l.options[j].value=valeur;
	l.options[j].text =texte;
	l.selectedIndex=j
	//tjs_ordre(l.form);
}

function tjs_ordre(f) {
	var l=f.liste;
	var ordre="";
	for(var i=0;i<l.options.length;i++) {
		if (i>0) {ordre+="-";}
		ordre+=l.options[i].value;		
	}
	f.ordre.value=ordre;
}

function PreSelectCheckBox(formname, fieldname, flag) 
{
  var sFieldName = new String(fieldname);
  for (idx = 0; idx < document.forms[formname].length; idx++)
    {
      var nameField = new String(document.forms[formname].elements[idx].name);
      if (nameField.substring(0, sFieldName.length) == fieldname)
	{
	  document.forms[formname].elements[idx].checked = flag;
	}
    }
}
