/* ===================== */
/* <Objects and prototypes> */
/* ===================== */
Object.size = function(obj)
{
  var size = 0, key;
  for (key in obj)
  {
    if (obj.hasOwnProperty(key)) size++;
  }
  return size;
};
/* ===================== */
/* </Objects and prototypes> */
/* ===================== */
 

/* ===================== */
/* <Common Misc functions> */
/* ===================== */
// URL Encoding/Decoding
function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
      output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}
 
function URLDecode (encodedString) {
  var output = encodedString;
  var binVal, thisString;
  var myregexp = /(%[^%]{2})/;
  while ((match = myregexp.exec(output)) != null
             && match.length > 1
             && match[1] != '') {
    binVal = parseInt(match[1].substr(1),16);
    thisString = String.fromCharCode(binVal);
    output = output.replace(match[1], thisString);
  }
  return output;
}
 
function set_display_mode(node, mode, target)
{
  if(node)
  {
    if(typeof node == 'string')
    {
      node = document.getElementById(node);
    }
    if(node)
    {
      if(target)
      {
        var str = 'node.' + target;
        node = eval(str);
      }
      if(node && mode)
      {
        node.style.display = mode;
      }
    }
  }
  return;
}
 
//redirect
function my_user_redirect(orig, page, target)
{
  var redir = true;
  if(page)
  {
    if(orig == 'my_sub_srv')
    {
      if(my_ctes.op != 'activate' && my_ctes.op != 'getinfos' && my_ctes.op != 'update')
      {
        redir = false;
        alert(my_labels.libCompleteSubText);
      }
    }
    if(redir)
    {
      if(target && target == 'opener' && window.opener)
      {
                 window.opener.document.location.href = page;
                 window.self.close();
      }
      else
      {
                 window.document.location.href = page;
      }
    }
  }
  return;
}
/* ===================== */
/* </Common Misc functions> */
/* ===================== */
 

/* ===================== */
/* <Misc String functions> */
/* ===================== */
function trim(orgString)
{
  return LTrim(RTrim(orgString))
}
 
function LTrim(orgString)
{
  return orgString.replace(/^\s+/,'');
}
 
function RTrim(orgString)
{
  return orgString.replace(/\s+$/,'');
}
 
function LZ(x)
{
  x = parseInt(x, 10);
  return(x < 0 || x > 9 ? '' : '0') + x;
}
/* ===================== */
/* </Misc String functions> */
/* ===================== */
 
 
/* ===================== */
/* <Cookies Manage> */
/* ===================== */
function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}
 
function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}
 
function eraseCookie(name) {
  createCookie(name, "", -1);
}
/* ===================== */
/* </Cookies Manage> */
/* ===================== */
 
 
/* ===================== */
/* <Control> */
/* ===================== */
function ctrl_taille(champ, taille_max, zone_maj, zone_ctrl)
{
    if(typeof champ == 'string')
    {
        champ = document.getElementById(champ);
    }
    if(typeof zone_maj == 'string')
    {
        zone_maj = document.getElementById(zone_maj);
    }
    if(typeof zone_ctrl == 'string')
    {
        zone_ctrl = document.getElementById(zone_ctrl);
    }
    if(champ && zone_maj)
    {
        var val = champ.value;
        var longueur = val.length;
        var reste = taille_max - longueur;
        if(longueur == 0)
        {
          zone_maj.innerHTML = '';
        }
        else if(reste >= 0)
        {
            zone_maj.innerHTML = (taille_max - reste) + '/' + taille_max;
        }
        else
        {
            var maj = true;
            if(zone_ctrl)
            {
                if(zone_ctrl.value != val)
                {
                    maj = true;
                }
                else
                {
                    maj = false;
                }
            }
            if(maj)
            {
                champ.value = val.substring(0, taille_max);
                if(zone_ctrl)
                {
                    zone_ctrl.value = champ.value;
                }
            }
            zone_maj.innerHTML = taille_max + '/' + taille_max;
        }
    }
    return;
}

// Vérifie le format d'une date
function VerifDate(chaine, format)
{
    var ret;
    ret = 1;
    if(format == "jj/mm/aaaa")    // 0
    {
      if( (chaine.length != 10) || (chaine.substring(2,3) != "/") || (chaine.substring(5,6) != "/") )
        {
            ret = -1;
        }
        else
        {
            jour = chaine.substring(0,2);
            mois = chaine.substring(3,5);
            annee = chaine.substring(6,10);
        }
    }
    else if(format == "jjmmaaaa")    // 1
    {
      if( (chaine.length != 8) )
        {
            ret = -1;
        }
        else
        {
            jour = chaine.substring(0,2);
            mois = chaine.substring(2,4);
            annee = chaine.substring(4,8);
        }
    }
    else if(format == "jj/mm/aa")    // 2
    {
      if( (chaine.length != 8) || (chaine.substring(2,3) != "/") || (chaine.substring(5,6) != "/") )
        {
            ret = -1;
        }
        else
        {
            jour = chaine.substring(0,2);
            mois = chaine.substring(3,5);
            annee = '20' + chaine.substring(6,8);
        }
    }
    else if(format == "jjmmaa")    // 3
    {
      if( (chaine.length != 6) )
        {
            ret = -1;
        }
        else
        {
            jour = chaine.substring(0,2);
            mois = chaine.substring(2,4);
            annee = '20' + chaine.substring(4,6);
        }
    }

    if(ret > 0)
    {
        if( (isNaN(jour)) || (isNaN(mois)) || (isNaN(annee)) )
        {
            ret = -1;
        }
        else if ((parseInt(mois, 10) < 1) || (parseInt(mois, 10) > 12))
        {
            //alert("MOIS : vous devez saisir un nombre entre 1 et 12...");
            ret = -1;
        }
        else if ( 
                (parseInt(mois, 10) == 1  
                || parseInt(mois, 10) == 3
                || parseInt(mois, 10) == 5
                || parseInt(mois, 10) == 7
                || parseInt(mois, 10) == 8
                || parseInt(mois, 10) == 10
                || parseInt(mois, 10) == 12)
                &&
                (parseInt(jour, 10) < 1 
                || parseInt(jour, 10) > 31)
             )
        {
            //alert("JOUR : vous devez saisir un nombre entre 1 et 31...");
            ret = -1;
        }
        else if ( 
                (parseInt(mois, 10) == 4  
                || parseInt(mois, 10) == 6
                || parseInt(mois, 10) == 9
                || parseInt(mois, 10) == 11)
                &&
                (parseInt(jour, 10) < 1 
                || parseInt(jour, 10) > 30)
             )
        {
            //alert("JOUR : vous devez saisir un nombre entre 1 et 30...");
            ret = -1;
        }
        else if (parseInt(mois, 10) == 2 && ( (annee % 400 == 0) || (annee % 4 == 0 && annee % 100 != 0) ) )
        {
            if( parseInt(jour, 10) < 1 || parseInt(jour, 10) > 29 )
            {
                //alert("JOUR : vous devez saisir un nombre entre 1 et 29...");
                ret = -1;
            }
        }
        else if( (parseInt(mois, 10) == 2) && ( (parseInt(jour, 10) < 1) || (parseInt(jour, 10) > 28) ) )
        {
            //alert("JOUR : vous devez saisir un nombre entre 1 et 28...");
            ret = -1;
        }
    }
    return ret;
}

function valid_pattern(pattern, valeur, sep, field)
{
//  email_pattern = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})$";
//  var test = eval(pattern + '.test(\'' + valeur.replace(/'/g, '\'') + '\')');
//  var test = eval('/' + pattern + '/.test(valeur)');
//  sep est facultatif : c'est soit un array de caractères soit une string
  var test = -1;
  if(valeur)
  {
    if(sep)
    {
      test = 1;
      if(typeof sep == 'object')
      {
        if(sep.length == 1)
        {
          sep = sep[0];
        }
        else
        {
          //Dans le cas du tableau de caractères, on prend comme caractère référent le premier
          var ref_car = sep[0];
          var car = '';
          for(var i = 1; i < sep.length; i++)
          {
            car = sep[i];
            var rgx = eval('/[' + car + ']+/g');
            valeur = valeur.replace(rgx, ref_car)
          }
          //Supprimer les doublons
          var rgx = eval('/[' + ref_car + ']+/g');
          valeur = valeur.replace(rgx, ref_car);
          if(field)
          {
            field.value = valeur;
          }
          sep = ref_car;
        }
      }
      var valeurs = valeur.split(sep);
      for(var i = 0; i < valeurs.length; i++)
      {
        test = trim(valeurs[i]).search(pattern);
        if(test == -1)
        {
          break;
        }
      }
    }
    else
    {
      test = valeur.search(pattern);
    }
  }
  return test;
}
 
function setField(field, mode, select)
{
  if(field)
  {
    switch(mode)
    {
      case 'std':
        field.style.backgroundColor = '#FFFFFF';
        if(field.type && field.type.indexOf('select') == -1)
        {
          field.style.border = '1px solid #7F9DB9';
        }
        break;
      case 'ok':
        field.style.backgroundColor = '#BCFFBF';
        if(field.type && field.type.indexOf('select') == -1)
        {
          field.style.border = '1px solid #49C24F';
        }
        break;
      case 'nok':
        field.style.backgroundColor = '#FFBCBC';
        if(field.type && field.type.indexOf('select') == -1)
        {
          field.style.border = '1px solid #C24949';
        }
        if(select)
        {
          field.focus();
          if(field.type == 'text')
          {
            field.select();
          }
        }
        break;
      default:
        break;
    }
  }
}
 
function LoadCheckOrRadioField(obj, mode, comp_eval)
{
  if(typeof obj == 'object' && Object.size(obj) > 0)
  {
    for(var key in obj)
    {
      if(obj.hasOwnProperty(key))
      {
        var field = obj[key].field;
        //alert('\'' + key + '\'' + '\n\n' + json2str(obj[key]) + '\n\n' + field.type);
        if(field)
        {
          if(comp_eval)
          {
            eval(comp_eval);
          }
          if(field.type == 'checkbox' || field.type == 'radio')
          {
            if(mode == 'load')
            {
              field.checked = obj[key].check;
            }
            else if(mode == 'raz')
            {
              field.checked = false;
              obj[i].check = false;
            }
          }
        }
      }
    }
  }
  return;
}
/* ===================== */
/* <Control> */
/* ===================== */
 
 
/* ===================== */
/* <CAPTCHA> */
/* ===================== */
var re_init_sub_form = new Array();
if(typeof GLOB_caller_zone == 'undefined')
{
  var GLOB_caller_zone = {'name':'', 'obj':{}};
}
if(typeof largCaptcha == 'undefined')
{
  var largCaptcha = 100;
}
function reload_captcha()
{
  //alert('community.js -> reload_captcha() -> largCaptcha = ' + largCaptcha);
  if(document.getElementById('img_code'))
  {
    // strDate permet d'avoir un appel unique, particulièrement important pour le reload de l'image dans le src de la balise img
    var url = my_ctes.ws_domain + '/captcha/CaptchaWS.asmx/Create?width=' + largCaptcha + '&height=50&strDate=' + (new Date()).getTime();
    document.getElementById('img_code').src = url;
  }
  return;
}
 
function captchaLoad(caller_zone)
{
  //alert('community.js -> captchaLoad() -> largCaptcha = ' + largCaptcha);
  if(!caller_zone)
  {
    caller_zone = {'name':'', 'obj':{}};
  }
  GLOB_caller_zone = caller_zone;
  var strDate = (new Date()).getTime();
  var data = "width=" + largCaptcha + "&height=50&strDate=" + strDate;
  // Le fait de passer par un premier appel Ajax dès l'appel de la page est nécessaire pour être identifié,
  // sinon la session est considérée comme New.
  // strDate permet d'avoir un appel unique, particulièrement important pour le reload de l'image dans le src de la balise img
  reqAjax = new Ajax(my_ctes.ws_domain + "/captcha/CaptchaWS.asmx/Create", {
              method: "post", 
              data: data, 
              onComplete: captchaLoadCallBack,
              onFailure: captchaLoadCallBackFailure,
              evalScripts: false});
  reqAjax.request();
}
function captchaLoadCallBackFailure(xhr)
{
  //alert("DDDD captchaLoadCallBackFailure : \n\n" + xhr.status + '\n\n' + xhr.statusText);
  return;
}
function captchaLoadCallBack(responseText, responseXML)
{
  reload_captcha();
}
 
var CaptchaCallbackFunction;
function captchaValidate()
{
  reqAjax = new Ajax(my_ctes.ws_domain + "/captcha/CaptchaWS.asmx/Validate", {
              method: "post", 
              postBody: "captcha=" + code_captcha.value, 
              onComplete: captchaValidateCallBack,
              onFailure: captchaValidateCallBackFailure,
              evalScripts: false});
  reqAjax.request();
}
function captchaValidateCallBackFailure(xhr)
{
  //alert("DDDD captchaValidateCallBackFailure : \n\n" + xhr.status + '\n\n' + xhr.statusText);
  return;
}
function captchaValidateCallBack(responseText, responseXML)
{
  var AjaxResponse = responseXML.getElementsByTagName("AjaxResponse");
  if(AjaxResponse.length > 0)
  {
    var successXml = AjaxResponse[0].getElementsByTagName("Success")[0].firstChild;
    var success = (successXml != null ? successXml.nodeValue : "0");
    var msgXml = AjaxResponse[0].getElementsByTagName("Message")[0].firstChild;
    var msg = (msgXml != null ? msgXml.nodeValue : "");
    if(success == "1")
    {
      //setField(code_captcha, 'ok');
      setField(code_captcha, 'std');
      CaptchaCallbackFunction();
      //alert('DDDD captchaValidateCallBack : \n\nGLOB_caller_zone = ' + json2str(GLOB_caller_zone) + '\n\ntypeof re_init_sub_form[' + GLOB_caller_zone.name + '] = ' + typeof re_init_sub_form[GLOB_caller_zone.name] + '\n\nre_init_sub_form[' + GLOB_caller_zone.name + '] = ' + re_init_sub_form[GLOB_caller_zone.name]);
      if (typeof GLOB_caller_zone != 'undefined' && typeof re_init_sub_form[GLOB_caller_zone.name] == 'function')
      {
        re_init_sub_form[GLOB_caller_zone.name](GLOB_caller_zone.obj);
      }
    }
    else
    {
      setField(code_captcha, 'nok');
      var msg = '\t' + my_labels.libCaptcha + ' : ' + my_labels.libNOK + '\n';
      alert(my_labels.libRequiredFields + ':\n' + msg + '\n');
      return;
    }
  }
}
/* ===================== */
/* </CAPTCHA> */
/* ===================== */
 
 
/* ===================== */
/* <USER> */
/* ===================== */
function raz_userForm()
{
  try
  {
    if(user_id)
    {
      user_id.value = '';
    }
    if(user_hash)
    {
      user_hash.value = '';
    }
    LoadCheckOrRadioField(etats_civils, 'raz');
    if(nom)
    {
        nom.value = '';
    }
    if(prenom)
    {
      prenom.value = '';
    }
    if(email)
    {
      email.value = '';
    }
    if(password)
    {
      password.value = '';
    }
    if(country)
    {
      country.selectIndex = 0;
    }
    LoadCheckOrRadioField(services_user, 'raz', 'display_service_link(obj[key].field, obj[key].id)');
    LoadCheckOrRadioField(infos_user, 'raz');
  }
  catch(e)
  {
    //alert(e);
  }
}
 
// avec les globales :
//  infos_eurosport, infos_partners
//User fields
var userId = -1;
var userSocialTitle = -1;
var userName = '';
var userPseudo = '';
var userRole = -1;
var userFirstname = '';
var userCountry = -1;
var userEmail = '';
var userPassword = '';
var userActivationHash = '';
//user/Service fields
var userInfos = '';
 
function getUserCommentsFromObjectTree(xmlDom, orig)
{
  if(!orig)
  {
    orig = 'ws';
  }
  var list;
  var xotree = new XML.ObjTree();
  var objtree = xotree.parseDOM(xmlDom);
  if(null != objtree)
  {
    //Verify that json_analyser.js is called in the xsl file
    //alert(json2str(objtree));
    try
    {
      var uc_tree;
      if(orig == 'ws')
      {
       uc_tree = objtree["#document"].AjaxResponse.list;
      }
      else
      {
        uc_tree = objtree["#document"].usercommentlist;
      }
      if(uc_tree)
      {
        if(orig == 'ws')
        {
            if(uc_tree.UserComment)
            {
                list = uc_tree.UserComment;
            }
        }
        else
        {
            if(uc_tree.usercomment)
            {
                list = uc_tree.usercomment;
            }
        }
      }
    }
    catch(e)
    {
      //alert(e);
    }
  }
  return list;
}

function getStringFromObjectTree(xmlDom)
{
  var ret = '';
  var xotree = new XML.ObjTree();
  var objtree = xotree.parseDOM(xmlDom);
  var userObject;
  if(null != objtree)
  {
    //Verify that json_analyser.js is called in the xsl file
    //alert(json2str(objtree));
    try
    {
      //userObject représente un userObject de la CommunityBusiness
      stringObject = objtree["#document"].AjaxResponse.Obj;
      if(stringObject)
      {
		ret = stringObject['#text'];
      }
    }
    catch(e)
    {
		//
    }
  }
  return ret;
}

function getUserFromObjectTree(xmlDom, load)
{
  var xotree = new XML.ObjTree();
  var objtree = xotree.parseDOM(xmlDom);
  var userObject;
  if(null != objtree)
  {
    //Verify that json_analyser.js is called in the xsl file
    //alert(json2str(objtree));
    try
    {
      //userObject représente un userObject de la CommunityBusiness
      userObject = objtree["#document"].AjaxResponse.Obj;
      if(userObject)
      {
        //User Id
        if(userObject.id)
        {
          userId = userObject.id;
        }
        //User hash
        if(userObject.activationhash)
        {
          userActivationHash = userObject.activationhash;
        }
        //Social Title
        if(userObject.socialtitle)
        {
          userSocialTitle = userObject.socialtitle.id;
          if(typeof etats_civils == 'object' && etats_civils[userSocialTitle])
          {
            etats_civils[userSocialTitle].check = true;
          }
        }
        else
        {
          userSocialTitle = -1;
        }
        //User pseudo
        if(userObject.pseudo)
        {
          userPseudo = userObject.pseudo;
        }
        //User name
        if(userObject.name)
        {
          userName = userObject.name;
        }
        //User firstname
        if(userObject.firstname)
        {
          userFirstname = userObject.firstname;
        }
        //Country
        if(userObject.country)
        {
          userCountry = userObject.country.id;
        }
        else
        {
          userCountry = -1;
        }
        //User email
        if(userObject.email)
        {
          userEmail = userObject.email;
        }
        //User password
        if(userObject.password)
        {
          userPassword = userObject.password;
        }
        //Services
        if(typeof services_user == 'object' && Object.size(services_user) > 0)
        {
          if(userObject.servicessub)
          {
            //les additionalinfos sont des chaînes "préformatées" nécessitant une transformation préalable pour passer en JSON.
            var obj = userObject.servicessub.servicesub;
            if(obj.length)
            {
              for(var i = 0; i < obj.length; i++)
              {
                if(obj[i].site && my_ctes.sitId == obj[i].site.id)
                {
                  var serviceId = obj[i].service.id;
                  if(services_user[serviceId])
                  {
                    if(typeof obj[i].additionalinfos == 'string' && obj[i].additionalinfos != 'undefined' && obj[i].additionalinfos != '')
                    {
                      services_user[serviceId].infos = obj[i].additionalinfos;
                    }
                    else
                    {
                      services_user[serviceId].infos = '';
                    }
                    services_user[serviceId].check = true;
                    //alert(serviceId + '\n\n' + json2str(services_user[serviceId]));
                  }
                }
              }
            }
            else
            {
              if(obj.site && my_ctes.sitId == obj.site.id)
              {
                var serviceId = obj.service.id;
                if(services_user[serviceId])
                {
                  services_user[serviceId].infos = obj.additionalinfos;
                  services_user[serviceId].check = true;
                  //alert(serviceId + '\n\n' + json2str(services_user[serviceId]));
                }
              }
            }
          }
        }
        //Infos user
        if(typeof infos_user == 'object' && Object.size(infos_user) > 0)
        {
          if(userObject.infos)
          {
            var obj = userObject.infos.info;
            if(obj.length)
            {
              for(var i = 0; i < obj.length; i++)
              {
                if(my_ctes.sitId == obj[i].site)
                {
                  userInfos = obj[i].info;
                  break;
                }
              }
            }
            else
            {
              if(my_ctes.sitId == obj.site)
              {
                userInfos = obj.info;
              }
            }
          }
          if(userInfos)
          {
            //userInfos est une chaîne du type nom_de_l'info + ':' + valeur_de_l'info + séparateur d'infos = '|'
            //Utiliser la fonction KVPToJson(chaine, sep_1, sep_2)
            //userInfos et servicesInfos sont des chaînes "préformatées" nécessitant une transformation préalable pour passer en JSON.
            var userInfos_obj = KVPToJson(userInfos, '|', ':');
            var val, info_field;
            if(userInfos_obj)
            {
              //alert(userInfos + '\n\n' + json2str(userInfos_obj));
              for(var key in userInfos_obj)
              {
                //key contient les clef nom_de_l'info (par exemple infos_eurosport, infos_partners, ...
                if(infos_user[key])
                {
                  val = userInfos_obj[key];
                  if(!val)
                  {
                    val = '0';
                  }
                  infos_user[key].infos = val;
                  info_field = infos_user[key].field;
                  if(info_field)
                  {
                    if(val == '1')
                    {
                      infos_user[key].check = true;
                    }
                    else
                    {
                      infos_user[key].check = false;
                    }
                    //alert(key + '\n\n' + json2str(infos_user[key]));
                  }
                }
              }
            }
          }
        }
        //Groups and roles
        if(userObject.groupssub)
        {
          var obj = userObject.groupssub.groupsub;
          if(obj.length)
          {
            for(var i = 0; i < obj.length; i++)
            {
              if(obj[i].site && my_ctes.sitId == obj[i].site.id)
              {
                var groupId = obj[i].group.id;
                if(my_ctes.usrGroupRef == groupId)
                {
                  var roleId = obj[i].role.id;
                  userRole = roleId;
                }
              }
            }
          }
          else
          {
            if(obj.site && my_ctes.sitId == obj.site.id)
            {
              var groupId = obj.group.id;
              if(my_ctes.usrGroupRef == groupId)
              {
                  var roleId = obj.role.id;
                  userRole = roleId;
              }
            }
          }
        }
      }
      if(load)
      {
        if(user_id)
        {
          user_id.value = userId;
        }
        if(user_hash)
        {
          user_hash.value = userActivationHash;
        }
        LoadCheckOrRadioField(etats_civils, 'load');
        if(pseudo && userPseudo)
        {
          pseudo.value = userPseudo;
        }
        if(nom)
        {
          nom.value = userName;
        }
        if(prenom)
        {
          prenom.value = userFirstname;
        }
        if(password)
        {
          password.value = userPassword;
        }
        if(email)
        {
          email.value = userEmail;
        }
        if(typeof email_tvsub == 'string')
        {
          email_tvsub.value = userEmail;
        }
        if(userCountry != -1)
        {
          country.value = userCountry;
        }
        //alert(services_user + '\n\n' + json2str(services_user));
        LoadCheckOrRadioField(services_user, 'load', 'display_service_link(obj[key].field, obj[key].id)');
        //alert(infos_user + '\n\n' + json2str(infos_user));
        LoadCheckOrRadioField(infos_user, 'load');
      }
    }
    catch(e)
    {
      //alert(e);
    }
  }
  return userObject;
}
 
function userInfo( field, check, infos )
{
    this.field = field;
    this.check = check;
    this.infos = infos;
}
/* ===================== */
/* </USER> */
/* ===================== */
 
 
/* ===================== */
/* <SERVICES> */
/* ===================== */
function serviceInfo( name, id, field, check, urlsub, infos )
{
    this.name = name;
    this.id = id;
    this.field = field;
    this.check = check;
    this.urlsub = urlsub;
    this.infos = infos;
}
/* ===================== */
/* </SERVICES> */
/* ===================== */

  
/* ===================== */
/* <Query String> */
/* ===================== */
function GetHashFromQS()
{
  var ret = '';
  var qs = '';
  var a_url = window.document.location.href.split('?');
  var url = a_url[0];
  if(a_url.length == 2)
  {
    qs = a_url[1];
  }
  if(qs)
  {
    var re = new RegExp(/[&]{0,1}activationhash=([\w]*)[&]{0,1}/);
    var res = re.exec(window.document.location.href);
    if(res && res.length == 2)
    {
      ret = res[1];
    }
  }
  return ret;
}
function GetHashFromCookie()
{
  var ret = readCookie('CommunityUserHash');
  return ret;
}
function GetHashCode(hash)
{
  //alert("DDDDD MyEurosportLoginByHash\n\ttypeoff userActivationHash = " + typeof userActivationHash + "\n\tuserActivationHash = @" + userActivationHash + '@' + '\n\ttypeof hash = ' + typeof hash + '\n\nhash =' + hash);
  /*  Utilise la globale userActivationHash  */
  var ret = '';
  if(typeof userActivationHash == 'string' && userActivationHash != '')
  {
    // userActivationHash est chargé par la fonction getUserFromObjectTree
    // qui suit la récupération du dom XML, provenant de la réponse à un appel Ajax
    ret = userActivationHash;
  }
  else if(typeof hash == 'string' && hash != '')
  {
    ret = hash;
  }
  else
  {
    // récupère le code hashcode de la query-string
    ret = GetHashFromQS();
  }
  if(!ret)
  {
    // récupère le code hashcode du cookie
    ret = GetHashFromCookie();
  }
  return ret;
}
 
function UpdateQueryHash()
{
  var url = '', qs = '';
  var a_url = window.document.location.href.split('?');
  var url = a_url[0];
  if(a_url.length == 2)
  {
    qs = a_url[1];
  }
  if(qs != '')
  {
    var anc = GetHashFromQS();
    if(typeof anc == 'string' && anc != '' && typeof userActivationHash == 'string' && userActivationHash != anc)
    {
      /*  Remplacer l'ancienne valeur de hashcode par la nouvelle:  */
      /*  Se baser sur la globale userActivationHash  */
      url = window.document.location.href.replace(anc, userActivationHash);
    }
  }
  else if(typeof userActivationHash == 'string' && userActivationHash != '')
  {
    url += '?sitegroupeid=' + my_ctes.sgrId + '&siteid=' + my_ctes.sitId + '&activationhash=' + userActivationHash + '&op=4';
  }
  return url;
}
/* ===================== */
/* </Query String> */
/* ===================== */
 
/* ===================== */
/* <JSON> */
/* ===================== */
function json2str(obj)
{
  //Verify that json_analyser.js is called in the xsl file
  return JSON.stringify(obj, null, '\t');
}
 
//Retourne un chaîne contenant des key value pairs en un objet Json
// Exemple : chaine = 'sports:48,13,265,28,51,18,57|ope_id:99|freq:0|optin:1'
// KVPToJson(chaine, '|', ':') => {'sports':'48,13,265,28,51,18,57','ope_id':'99','freq':'0','optin':'1'}
function KVPToJson(chaine, sep_1, sep_2)
{
  var ret = {};
  if(chaine)
  {
    try
    {
      if(!sep_1)
      {
        sep_1 = '&';
      }
      else if(sep_1 == '|')
      {
        sep_1 = '\\' + sep_1;
      }
      if(!sep_2)
      {
        sep_2 = '=';
      }
      var s_regex = "([^" + sep_2 + "]+)(" + sep_2 + ")([^" + sep_1 + "?]+)" + sep_1 + "?";
      var reg = new RegExp(s_regex, "g");
      //$1 représente key, $2 représente sep_2, $3 représente value
      ret = eval('({' + chaine.replace(reg, "'$1':'$3'").replace(/\'\'/g, '\', \'') + '})');
    }
    catch(e)
    {
      //alert(e);
    }
  }
  return ret;
}
/* ===================== */
/* </JSON> */
/* ===================== */


/* ===================== */
/* <DOM> */
/* ===================== */
function Disable_Field(field, val)
{
  if(field)
  {
    if(typeof val == 'undefined')
    {
      val = true;
    }
    field.disabled = val;
  }
}
function Enable_Field(field, val)
{
  Disable_Field(field, false);
}
function RAZ_node(noeud)
{
    if(noeud)
    {
        while(noeud.firstChild)
        {
            noeud.removeChild(noeud.firstChild);
        }
    }
}
function cree_node(parent, nom, texte, classe)
{
    var mon_node;
    mon_node = window.document.createElement(nom);
    if(classe)
    {
      mon_node.setAttribute('class', classe);
      mon_node.setAttribute('className', classe);
    }
    if(texte)
    {
      mon_node.innerHTML = texte;
    }
    parent.appendChild(mon_node);
    return mon_node;
}
function cree_input(parent, nom, texte, classe)
{
    var mon_node;
    mon_node = window.document.createElement('input');
    mon_node.setAttribute('type', nom);
    if(classe)
    {
      mon_node.setAttribute('class', classe);
      mon_node.setAttribute('className', classe);
    }
    if(texte)
    {
      mon_node.innerHTML = texte;
    }
    parent.appendChild(mon_node);
    return mon_node;
}
function cree_radio(parent, id, nom, valeur, fct_click)
{
  var navi = navigator.userAgent.toLowerCase();
  var MODE_NAVI = '';
  if(navi.indexOf('macintosh') != -1 && navi.indexOf('safari') != -1)
  {
      MODE_NAVI = 'safari_mac';
    }
  else if(navi.indexOf('windows') != -1 && navi.indexOf('msie') != -1)
  {
      MODE_NAVI = 'ie6_pc';
    }
    var ma_case = window.document.createElement("input");
    ma_case.setAttribute('type', 'radio');
    ma_case.setAttribute('id', id);
    ma_case.setAttribute('name', nom);
    ma_case.setAttribute('value', valeur);
    if (fct_click)
    {
        if(mode_navi == 'ie6_pc')
        {
            var fct_event = new Function(fct_click);
            ma_case.setAttribute('onclick', fct_event);
        }
        else    //mode_navi = safari_mac
        {
            ma_case.setAttribute('onclick', fct_click);
        }
    }
    if (parent)
    {
        parent.appendChild(ma_case);
    }
    return ma_case;
}
/* ===================== */
/* </DOM> */
/* ===================== */
