
var feuille = '';

if (addListenner) {
  addListenner(window, "load", loadEducatopRegistration, true);
}

var educatop_inputCp_timer = null;

/**
 * loadEducatopRegistration
 * Assistance à l'inscription pour Educatop
 */
 function loadEducatopRegistration()
 {
    /*var inputCp = document.getElementById('UT_cp_facturation');
    if (inputCp) {
      inputCp.onkeyup = function ()
      {
        if (this.value.length > 3) {
          if (educatop_inputCp_timer) clearTimeout(educatop_inputCp_timer);
          educatop_inputCp_timer = setTimeout('XHR_tell_getTown(\'' + this.value + '\');', 300)
        }
      } // end of function for "inputCp.onChange"
    }*/


    var inputCp = document.getElementById('UT_numero_etablissement');
    if (inputCp) {
      inputCp.onkeyup = function ()
      {
        if (this.value.length > 3) {
          if (educatop_inputCp_timer) clearTimeout(educatop_inputCp_timer);
          educatop_inputCp_timer = setTimeout('XHR_tell_getAll(\'' + this.value + '\');', 300)
        }
      } // end of function for "inputCp.onChange"
    }


    /*var inputSchool = document.getElementById('ENET_patronyme');
    if (inputSchool) {
      inputSchool.onkeyup = function ()
      {
          if (educatop_inputCp_timer) clearTimeout(educatop_inputCp_timer);
          educatop_inputCp_timer = setTimeout('XHR_tell_getSchool(\'' + this.value + '\');', 300)
      } // end of function for "inputCp.onChange"

      inputSchool.onfocus = inputSchool.onkeyup;
    }*/


 } // end of "loadEducatopRegistration()"



/**
 * XHR_tell_getEtab
 */
/*function XHR_tell_getSchool(nameEtab)
 {
        var inputCp = document.getElementById('UT_cp_facturation');
        aQueryData  = {"ENET_patronyme" : nameEtab, 'action' : 'XHR_tell_getSchool'};
        if (inputCp && inputCp.value.length > 2) {
          aQueryData['UT_cp_facturation'] = inputCp.value;
          XHR_post(null, aQueryData, XHR_listen_getSchool);
        }
 } // end of "XHR_tell_getEtab()"
*/


/**
 * XHR_tell_getTown
 */
/*function XHR_tell_getTown(cpValue)
 {
    aQueryData = {"UT_cp_facturation" : cpValue, 'action' : 'XHR_tell_getTown'};
    XHR_post(null, aQueryData, XHR_listen_getTown);

 } // end of "XHR_tell_getTown()"
*/


/**
 * XHR_tell_getAll
 */
 function XHR_tell_getAll(numero)
 {
    aQueryData = {"numero" : numero, 'action' : 'XHR_tell_getAll'};
    XHR_post(null, aQueryData, XHR_listen_getAll);

 } // end of "XHR_tell_getAll()"




/**
 * XHR_listen_getTown
 */
 function XHR_listen_getAll(data)
 {
   setForm(data);
   /*var fieldList = ['ENET_patronyme', 'ENET_localite', 'ENET_cp',
                    'ENET_numero_u', 'ETNA_id', 'AC_id',
                    'ENET_adresse', 'ENET_lieu_dit',
                    'DEFR_id', 'ENET_mention', 'ENET_nature_u',
                    'ENET_bp', 'ENET_fax',
                    'ENET_secteur', 'ENET_numero_telephone'];


    document.getElementById('ENET_patronyme').value = data['ENET_patronyme'];
    document.getElementById('UT_cp_facturation').value = data['ENET_cp'];
    document.getElementById('UT_ville_facturation').value = data['ENET_localite'];
    document.getElementById('UT_rue_facturation').value = data['ENET_adresse'];
    //document.getElementById('UT_numero_etablissement').value = data['ENET_numero_u'];
    document.getElementById('UT_tel_facturation').value = data['ENET_numero_telephone'];

    if (data['ENET_secteur'] == 0) {
      document.getElementById('UT_type_etablissement').checked = null;

    } else if (data['ENET_secteur'] == 1) {
      document.getElementById('UT_type_etablissement').checked = 'checked';
    }

    var select = document.getElementById('ETNA_id');
    for (var i=0; i < select.options.length; i++) {
      if (select.options[i].value == data['ETNA_id']) {
        select.options[i].selected = "selected";
        select.selectedIndex = i;
      }
    }

    var select = document.getElementById('AC_id');
    for (var i=0; i < select.options.length; i++) {
      if (select.options[i].value == data['AC_id']) {
        select.options[i].selected = "selected";
        select.selectedIndex = i;
      }
    }*/
 } // end of "XHR_listen_getAll()"





/**
 * Positionnement des champs du formulaire
 *
 * @param array postvalues valeurs des champs du formulaire
 */
 function setForm(postvalues)
 {
    for (var key in postvalues) {
        var inputValue = postvalues[key];
        var input = document.getElementById(key);

        if (input) {
            if (input.type == 'checkbox' || input.type == 'radio') {
                if (parseInt(inputValue) == 1) {
                    input.checked = 'checked';
                } else {
                    input.checked = null;
                }

            } else if (input.nodeName == 'SELECT') {
                for (var a = 0; a < input.options.length; a++) {
                    if (input.options[a].value == parseInt(inputValue) || input.options[a].value == inputValue) {
                        input.options[a].selected = 'selected';
                    } else {
                        input.options[a].selected = null;
                    }
                }

            }  else if (input.nodeName == 'P') {
                input.innerHTML = inputValue;

            } else {
              input.value = inputValue;
            }
        }
    } // end for
 } // end of "setForm()"





/**
 * XHR_listen_getTown
 */
/*function XHR_listen_getTown(data)
 {
      if (data['ENET_localite']) {
        var inputTown = document.getElementById('UT_ville_facturation');
        inputTown.value = data['ENET_localite'];
      }
 } // end of "XHR_listen_getTown()"
*/




/**
 * XHR_listen_getSchool
 */
/*function XHR_listen_getSchool(data)
 {
        var schoolField = document.getElementById('ENET_patronyme');
        var schoolBox = document.getElementById('etablissements-liste');
        var schoolList = document.getElementById('etablissements-liste-ul');
        schoolList.innerHTML = '';

        var i = 0;
        while (data[i]) {
          var li = document.createElement('li');

          var a = document.createElement('a');
          a.href = "javascript:void(0);";
          a.innerHTML = data[i]['ENET_patronyme'];
          a.adresseEtab = data[i]['ENET_adresse'];
          a.etca_id = data[i]['ETCA_id'];
          a.ac_id = data[i]['AC_id'];
          a.tel = data[i]['ENET_numero_telephone'];
          a.secteur = data[i]['ENET_secteur'];
          a.numeroEtab = data[i]['ENET_numero_u'];

          a.onmousedown = function ()
          {
            document.getElementById('ENET_patronyme').value = this.innerHTML;
            document.getElementById('UT_rue_facturation').value = this.adresseEtab;
            document.getElementById('UT_numero_etablissement').value = this.numeroEtab;
            document.getElementById('UT_tel_facturation').value = this.tel;

            var select = document.getElementById('ETNA_id');
            for (var i=0; i < select.options.length; i++) {
              if (select.options[i].value == this.etca_id) {
                select.options[i].selected = "selected";
                select.selectedIndex = i;
              }
            }

            var select = document.getElementById('AC_id');
            for (var i=0; i < select.options.length; i++) {
              if (select.options[i].value == this.ac_id) {
                select.options[i].selected = "selected";
                select.selectedIndex = i;
              }
            }

            if (this.secteur == 0) {
              document.getElementById('UT_type_etablissement').checked = null;
            } else if (this.secteur == 1) {
              document.getElementById('UT_type_etablissement').checked = 'checked';
            }

            document.getElementById('etablissements-liste').style.visibility = null;
            document.onclick = null;
          } // end of "li.onclick"

          document.onclick = function ()
          {
            document.getElementById('etablissements-liste').style.visibility = null;
            document.onclick = null;
          }

          li.appendChild(a);
          schoolList.appendChild(li);

          i++;

        } // end while

        var coor = getPosition(schoolField, true);
        schoolBox.style.left = coor.x + 'px';
        schoolBox.style.top = (coor.y + schoolField.clientHeight) + 'px';
        schoolBox.style.visibility = 'visible';

 } // end of "XHR_listen_getSchool()"
*/








