var iconOK = "/general/images/default/icons/crystal/16x16/actions/apply.png";
var iconTOCOMPLETED = "/general/images/default/icons/crystal/16x16/apps/important.png";
var iconTODEFINED = "/general/images/default/icons/crystal/16x16/actions/button_cancel.png";

// ================================================================
// 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;
	    }
	}
    }
}
// Fonction: UpdateSelectBox
// Objet: Select a HTML SELECT field
// (C) Copyright 2004 Interface Technologies
function UpdateSelectBox(name, bcheck)
{
   elem = eval("document.forms[0]."+name);
	if (elem != null) {
      bFlag = true;
      if (bcheck == 0) bFlag = false; 
      for (iIdx=0; iIdx<elem.length; iIdx++)
		{
	  		elem.options[iIdx].selected = bFlag;
		}
   }
}
// =========================
// 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;
  
  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 DisplayDidacticielPage(page,options,width,height) {

  if (screen.width < 850) width = 750;
  
  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 DisplayDidacticiel(page,options) {
  DisplayDidacticielPage(page,options,850,470);
}

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;
	}
    }
}

function ChangeLang(docname, field, newlang)
{
  oldlang = eval("document."+docname+".currentLang.value").toLowerCase();
  ShowCalc(field+oldlang, 'none');

  myelem = document.getElementsByName("img"+field+oldlang);
  if (myelem)
    {
      myelem[0].className = "opacity";
      ShowCalc(field+newlang, 'block');
    }

  myelem = document.getElementsByName("img"+field+newlang);
  if (myelem)
    {
      myelem[0].className = "";
    }

  eval("document."+docname+".currentLang").value = newlang;
}

function SetNameRooms(fname, fieldName, fieldDesc, langcode)
{
  elemName = eval("document."+fname+".elements[\""+fieldName+langcode+"\"]");
  elemDesc = eval("document."+fname+".elements[\""+fieldDesc+langcode+"\"]");
  elemImg = document.getElementById('in_'+langcode);

  if (elemName && elemDesc && elemImg)
    {
      if (elemName.value != "" && elemDesc.value != "")
	{
	  elemImg.src = iconOK;
	}
      else if (elemName.value != "" || elemDesc.value != "")
	{
	  elemImg.src = iconTOCOMPLETED;
	}
      else
	{
	  elemImg.src = iconTODEFINED;
	}
    }
}

function SetImgFlagWithTextDefinition(langcode,fname, field1, field2, field3,field4)
{

  elem1 = eval("document."+fname+".elements[\""+field1+"\"]");
  elem2 = eval("document."+fname+".elements[\""+field2+"\"]");
  elem3 = eval("document."+fname+".elements[\""+field3+"\"]");
  elem4 = eval("document."+fname+".elements[\""+field4+"\"]");

  elemImg = document.getElementById('in_'+langcode);

  if ((elem1 || elem2 || elem3 || elem4) && elemImg)
    {
      if ((elem1 && elem1.value != "")
	  && (field2=='' || (elem2 && elem2.value != ""))
	  && (field3=='' || (elem3 && elem3.value != ""))
	  && (field4=='' || (elem4 && elem4.value != "")))
	{
	  elemImg.src = iconOK;
	}
      else if ((elem1 && elem1.value != "") || 
	       (elem2 && elem2.value != "") || 
	       (elem3 && elem3.value != "") || 
	       (elem4 && elem4.value != ""))
	{
	  elemImg.src = iconTOCOMPLETED;
	}
      else
	{
	  elemImg.src = iconTODEFINED;
	}
    }
}

fDomOffset = function( oObj, sProp )
{
 var iVal = 0;
 while (oObj && oObj.tagName != 'BODY') {
  eval('iVal += oObj.' + sProp + ';');
  oObj = oObj.offsetParent;
 }
 return iVal;
}

fSwapSelect = function( sId ) 
{ 
 oObj = document.getElementById(sId); 
 if (oObj)
 { 
 Top_Element  = fDomOffset(oObj, 'offsetTop'); 
 Left_Element  = fDomOffset(oObj, 'offsetLeft'); 
 Largeur_Element  = oObj.offsetWidth; 
 Hauteur_Element  = oObj.offsetHeight; 
 oSelects = document.getElementsByTagName('SELECT'); 
 if (oSelects.length > 0) { 
  for (i = 0; i < oSelects.length; i++) { 
   oSlt = oSelects[i]; 
   Top_Select = fDomOffset(oSlt, 'offsetTop'); 
   Left_Select = fDomOffset(oSlt, 'offsetLeft'); 
   Largeur_Select = oSlt.offsetWidth; 
   Hauteur_Select = oSlt.offsetHeight; 
   isLeft = false; 
   if ((Left_Element > (Left_Select - Largeur_Element)) && (Left_Element < (Left_Select + Largeur_Select))) { 
    isLeft = true; 
   } 
   isTop = false; 
   if ((Top_Element > (Top_Select - Hauteur_Element)) && (Top_Element < (Top_Select + Hauteur_Select))) { 
    isTop = true; 
   } 
   if (isLeft && isTop) { 
    sVis = (oObj.style.visibility == 'hidden') ? 'visible' : 'hidden'; 
    if (oSlt.style.visibility != sVis) {oSlt.style.visibility = sVis;} 
   } else { 
    if (oSlt.style.visibility != 'visible') {oSlt.style.visibility = 'visible';} 
   } 
  } 
 }
 } 
}

function CenterMyPopup(page,options) {
  var largeur = 400;
  var hauteur = 300;

  var top=(screen.height-hauteur)/2;
  var left=(screen.width-largeur)/2;
  window.open(page, "_map","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}

Array.prototype.in_array = function(val) {
   for (var i in this) {
      if (this[i] == val) return true;
   }
   return false;
};

function checkFieldsAscii(formName,arrayFieldName,arrayFieldLabel,textValue,textToken) {
  error = "";
  for (idxField = 0;idxField<arrayFieldName.length;idxField++) {
    fieldName = arrayFieldName[idxField];
    checke = checkAsciiCharInField(formName,fieldName);
    if (checke != true) {
      error += textValue.replace(textToken,arrayFieldLabel[idxField])+" aaaa: ["+checke+"]\n";
    }
  }
  if (error != "") {
    alert(error);
    return false;
  }
  else {
    return true;
  }
}

function checkAsciiCharInField(formName,fieldName) {
  return true;
  field = eval("document."+formName+".elements['"+fieldName+"']");
  if (field) {
    value = replaceAsciiChar(field.value);
    field.value = value;
    for (i=0;i<value.length;i++) {
      if (value.charCodeAt(i) > 255) {
	return value.charAt(i);
      }
    }
  }
  return true;
}

function replaceAsciiChar(value) {
  return value;
}

function displayMapFromGoogleMaps(apikey, lat, lng, width, height, bmove)
{  
  if ( typeof(apikey) != "undefined" && apikey != "")
    {
      url = "/scripts/mapshotel.php?apikey="+apikey+"&lat="+lat+"&lng="+lng+"&bmove="+bmove;
    }
  else
    {
      apikey = "ABQIAAAAPVqeWSHf73z5ueq1roWAtRRn37QaJRPSY9WT4qMiSj8LmDTotxRUsv3U6pMewJm7F92zT2yvE5c8Qg";
      url = "http://support.reservit.com/scripts/mapshotel-default.php?apikey="+apikey+"&lat="+lat+"&lng="+lng+"&bmove="+bmove;
    }

  if ( typeof(apikey) != "undefined" && apikey != "" &&
       (parseFloat(lat)!=0 && parseFloat(lng)!=0) )
    {
      if (width == "0" || width == "" || typeof(width) == "undefined") { width = 490; }
      if (height == "0" || height == "" || typeof(height) == "undefined") { height = 600; }
      var top=(screen.height-height)/2;
      var left=(screen.width-width)/2;
      windowOptions  = "toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,copyhistory=yes,scrollbars=yes,top="+top+",left="+left+",width="+width+",height="+height;
      openNewWindow(url,'_map',windowOptions);
    }
}

function displayGeoNamesInfos(lng,lat, width, height)
{
  if (lng != 0 && lat != 0)
    {
      url = "http://ws.geonames.org/countrySubdivision?lng="+lng+"&lat="+lat;
      
      if (width == "0" || width == "" || typeof(width) == "undefined") { width = 490; }
      if (height == "0" || height == "" || typeof(height) == "undefined") { height = 600; }
      var top=(screen.height-height)/2;
      var left=(screen.width-width)/2;
      windowOptions  = "toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,copyhistory=yes,scrollbars=yes,top="+top+",left="+left+",width="+width+",height="+height;
      openNewWindow(url,'_geoname',windowOptions);
    }
}

/*****************************************************
#Objet d'import de javascript .js
******************************************************/
function ImportJS() {
	var nbr_att = arguments.length;
	var js_effets=document.createElement("script");
	js_effets.setAttribute("type", "text/javascript");
	js_effets.setAttribute("src", arguments[0]);
	if(nbr_att>1){
		for (var i = 1; i<nbr_att; i++){
			js_effets.setAttribute(arguments[i][0], arguments[i][1]);
		}
	}
	document.getElementsByTagName("head")[0].appendChild(js_effets);
}
/*****************************************************
#Objet d'import de css .css
******************************************************/
function ImportCSS() {
	var nbr_att = arguments.length;
	var css_style=document.createElement("link");
	css_style.setAttribute("rel", "stylesheet");
	css_style.setAttribute("type", "text/css");
	css_style.setAttribute("href", arguments[0]);
	css_style.setAttribute("media", "screen");
	if(nbr_att>1){
		for (var i = 1; i<nbr_att; i++){
			css_style.setAttribute(arguments[i][0], arguments[i][1]);
		}
	}
	document.getElementsByTagName("head")[0].appendChild(css_style);
}


/***********************************************************
# display shorter text with textlength length or a maximum of nbLetters  
************************************************************/
function displayShortText(text, textlength, nolg, nbLetters) {

        var lt = "<";
        var gt = ">";
        if (nolg) {
            lt = "{@}";
            gt = "{@@}";
        }
        
        var savedlength = textlength;
        
        var returnedString = "";
        if (text != null) {
            if (textlength == null || textlength == 0)
                textlength = nbLetters;
            if (text.length < textlength)
                textlength = text.length;
           
            if (text != null && text.length > 0 && text.length > textlength) {
                text = text.replace("\"", "'");
               	returnedString += lt +"SPAN TITLE=\""+ text +"\""+ gt;
                returnedString += text.substring(0, textlength);
               	returnedString += lt +"/SPAN"+ gt;
                returnedString += "...";
                
            } else {
            	returnedString += text;
            	// add spaces when text is shorter than textlength
				//returnedString += "<PRE>";            	
            	//for (var i = 0; i < (savedlength - text.length); i++) {
            		//returnedString += "&nbsp;";
            	//}
            	//returnedString += "</PRE>";
            }            
        } else { returnedString = "-"; }

        return returnedString;
    }

/***********************************************************
# display shorter text with textlength length or a maximum of nbLetters  
************************************************************/
function addbookmark(title, url) {
  if (document.all) window.external.AddFavorite(url, title);
  else if (window.sidebar) window.sidebar.addPanel(title, url, "");
}


function addItem(theSel, theText, theValue)
{
  var newOpt = new Option(theText, theValue);
  var selLength = theSel.length;
  theSel.options[selLength] = newOpt;
  if (theSel.length == 2) {
    if (theSel.options[0] != null && 
	theSel.options[0].value == "-1") {
      theSel.options[0] = null;
    }
  }
}

function deleteItemLeftToRight(theSel, theIndex, type, text1, text2)
{ 
   var selLength = theSel.length;
  if(selLength>0)
  {
    theSel.options[theIndex] = null;
  }
  if (theSel.length==0) 
	  {
	  if (type == "partner")
	  {
    	var newOpt = new Option(text1, "-1");
	  }
	  else
	  {
		  var newOpt = new Option(text2, "-1");
	  }
    theSel.options[0] = newOpt;
  }
}

function addItemLeftToRight(theSelFrom, theSelTo, type, text1, text2)
{
  var selLength = theSelFrom.length;
  var selectedText = new Array();
  var selectedValues = new Array();
  var selectedCount = 0;
  
  var i;
  
  // Find the selected Options in reverse order
  // and delete them from the 'from' Select.
  for(i=selLength-1; i>=0; i--)
  {
    if(theSelFrom.options[i].selected)
    {
      selectedText[selectedCount] = theSelFrom.options[i].text;
      selectedValues[selectedCount] = theSelFrom.options[i].value;
      deleteItemLeftToRight(theSelFrom, i,type, text1, text2);
      selectedCount++;
    }
  }
  
  // Add the selected text/values in reverse order.
  // This will add the Options to the 'to' Select
  // in the same order as they were in the 'from' Select.
  for(i=selectedCount-1; i>=0; i--)
  {
    addItem(theSelTo, selectedText[i], selectedValues[i]);
  }
}

function resetErrorJS(fname)
{
  if (document.getElementById(fname) && document.getElementById(fname).innerHTML != "")
    {
      document.getElementById(fname).innerHTML="";
    }
}

function PasswordLost(fname)
{
  var answer = window.prompt(msgPasswordLost,"");
  if (answer != null)
    {
	 document.forms[fname].lost.value = answer;
	 document.forms[fname].submit();
    }
}

