
function S_trier() {
listeGroupes =
lib.getById(this.identifiant).getElementsByTagName("OPTGROUP");
listeOptions =
lib.getById(this.identifiant).getElementsByTagName("OPTION");
listeElements = new Array();
for (var i = 0; i < listeOptions.length; i++) {
listeElements[listeElements.length] = listeOptions[i];
}
for (var i = 0; i < listeGroupes.length; i++) {
listeElements[listeElements.length] = listeGroupes[i];
}
for (var j = (listeGroupes.length - 1); j >= 0; j--) {
var noeud = listeGroupes[0];
lib.getById(this.identifiant).removeChild(noeud);
}
try {
for (var j = (lib.getById(this.identifiant).options.length - 1); j >= 0; j--) {
lib.getById(this.identifiant).options[j] =  null;
}
} catch(exception) {
throw new ExceptionAEF('ES001');
}
listeElements.sort(F_trierListeElements);
var indexOptions = 0;
for (var i = 0; i < listeElements.length; i++) {
typeElement = listeElements[i].nodeName;
if ( typeElement == "OPTGROUP" ) {
groupe = document.createElement("optgroup");
groupe.setAttribute("label",
listeElements[i].getAttribute("label")
);
groupe.setAttribute("id", listeElements[i].id);
if ( i < (listeElements.length - 1)
&& listeElements[i + 1].nodeName == "OPTION") {
lib.appendChild(this.identifiant, groupe);
}
} else if( typeElement == "OPTION" ) {
var aCreer = 0;
if (listeElements[i+1] && listeElements[i+1].value) {
if (listeElements[i].value != listeElements[i+1].value) {
aCreer = 1;
}
} else if (listeElements[i].value) {
aCreer = 1;
}
if (aCreer == 1) {
nouvelleOption = document.createElement("option");
nouvelleOption.text = listeElements[i].text;
nouvelleOption.setAttribute(
"value", listeElements[i].value);
nouvelleOption.setAttribute('title', listeElements[i].text);
try {                 
lib.appendChild(this.identifiant, nouvelleOption);
} catch(e) {
lib.getById(this.identifiant).options[indexOptions] =
nouvelleOption;
indexOptions++;
var e = new ExceptionAEF("W0002");
e.afficher();
}
}
}
}
}
function getSelectionById(p_identifiant) {
return new Selection(p_identifiant);
}
function S_contientDateCreation() {
var expression = /^infoDateCreation*/;
return this.contient(expression);
}
function S_contientCapitalSocial() {
var expression = /^donneesChiffreesCapitalSocial*/;
return this.contient(expression);
}
function S_contient(p_expression) {
var texte = "";
var liste = this.objet.getElementsByTagName("OPTION");
for (var i = 0; i < liste.length; i++) {
texte = liste[i].value;
if( texte.search(p_expression) >= 0 ) {
return 1;
}
}
return 0;
}
function S_charger(p_liste) {
var p_listeChoix = this.toListeChoix(p_liste);
for (var i=0; i < p_listeChoix.length; i++) {
this.objet.options[i] = p_listeChoix[i].getOption();
this.listeChoix[i] = p_listeChoix[i];        
}
page.formulaire.supprimerOptionsSuperflues(this.identifiant);
}
function S_toListeChoix(p_dictPython) {
var liste = eval(p_dictPython);	
var listeChoix = new Array();
for (var i = 0; i < liste.length; i++) {
listeChoix[i] = new Choix(
liste[i][1], 
liste[i][0], 
liste[i][1]
);
} 
return listeChoix;
}
function S_autocharger() {
url = page.construireURL(this.identifiant, '', '');
client = new ClientListe();
client.setUrl(url);
client.service = this.identifiant;
client.executer();
return this.identifiant;
}
function S_recharger() {	
this.setListeOptions(this.listeChoix);
}
function S_estVide() {
return (this.objet.options.length <= 0 || (
this.objet.options.length > 0 && this.objet.options[0].value.length <= 0
)
);
}
function S_setListeOptions(p_listeChoix) {
for (var i = 0; i < p_listeChoix.length; i++) {
this.objet.options[i] = p_listeChoix[i].getOption();        
}
}
function S_setListeChoix(p_listeChoix) {
for (var i=0; i < p_listeChoix.length; i++) {
this.listeChoix[i] = p_listeChoix[i];        
}
}
function Selection_estFiltreeParListe() {
var idFiltre = '';
var idSelection = this.identifiant.toLowerCase();
var listeFiltres = page.formulaire.getFiltresTypeListe();
for(var i=0; i<listeFiltres.length; i++) {
idFiltre = listeFiltres[i].identifiant.toLowerCase();		
if (idSelection.indexOf(idFiltre) >= 0) {
return true;
}
}
return false;
}
function Selection(p_identifiant) {
this.identifiant = p_identifiant;
this.objet = document.getElementById(p_identifiant);
this.listeChoix = new Array();
this.trier = S_trier;
this.contientCapitalSocial = S_contientCapitalSocial;
this.contientDateCreation = S_contientDateCreation;
this.contient = S_contient;
this.charger = S_charger;
this.autocharger = S_autocharger;
this.recharger = S_recharger;
this.estFiltreeParListe = Selection_estFiltreeParListe;
this.estVide = S_estVide;
this.setListeOptions = S_setListeOptions;
this.setListeChoix = S_setListeChoix;
this.toListeChoix = S_toListeChoix;
}
