App.Modul.Fo = 1

function MakeApp(JS) {
	var FoJS, NomFo, T, Fo, S, J, O, Opt
	if (!JS)  return
	if (typeof(JS)=='string') {
		try {
			JS = JSON_Decode(JS);  	//alert(JSW(JS))
		}catch(e){
			alert("Parse données impossible"); return
		}
	}
	var Forms = JS['Forms'];  Opt = {}
	for (NomFo in Forms) {
	  FoJS = Forms[NomFo];		//alert(JSW(FoJS))
	  if (FoJS) {
		  if (FoJS.Table) {
				T  = new TableClass(FoJS.Table, FoJS.NomC, FoJS.TypCle, FoJS.ValCle)
				T.ImportDataJS(FoJS.Data)
			}
			Opt = {Selects:FoJS['Selects']}
		}
		Fo = new FoClass(NomFo, NomFo, T, Opt)
	}
}

var FoGen = function(btn, Pgm) {
	var F, Fo
	F = ElemPAt(btn,'ojs');  Fo = eval(LX(F,'ojs'));  if (!Fo)  return;    //alert(Fo.Nom+crr+Lout(F))
	Fo[Pgm]()
}

var getFo = function(btn) { var F = ElemPAt(btn,'ojs');  return eval(LX(F,'ojs')) }


// ====================================      FO       ===============================
var FoClass = function(Nom, id, Table, Opt) {
  var Fo
	if (!Opt)  Opt={}
	if (typeof(id)=='string')  Fo = LID(id);  else  Fo = id
	if (!(this.id=Fo.name))  this.id = Fo.id
  window['fo_'+Nom] = this;  PX(Fo,'ojs','fo_'+Nom)

	this.Nom		= Nom
	this.Fo     = Fo
	this.isForm = (this.Fo.tagName=='FORM')
	this.Table	= Table;  if (Table)  Table.Fo = this
	this.Opt		= Opt
	this.all		= []
  this.CtlMaj = '_ChampsMaj'
	this.CtlClass = Opt.CtlClass || CtlClass
	this.InitFo()
	return this
}

FoClass.prototype.InitFo = function() {
	var Cto, Ctl, Nom, Os=[], O1, O2, O3, i, T, Ch, Tag
	if (this.isForm) {
  	T = this.Fo.elements;  for (i=0; i<T.length; i++)  Os.push(T[i])
	}else{
		O1 = LTags(this.Fo,'INPUT');  O2 = LTags(this.Fo,'SELECT');  O3 = LTags(this.Fo,'TEXTAREA')
		Os = concat(O1,O2,O3)
	}
	O1 = LTags(this.Fo,'SPAN');
	for (i=0; i<O1.length; i++) {  if (LX(O1[i],'bd'))  Os.push(O1[i]) }

  this.Ctrls = Os
	T = this.Table
	for (i=0; i<Os.length; i++) {
		Ctl = Os[i]
		Tag = Ctl.tagName
		if ("BUTTON,FIELDSET".indexOf(Tag)>=0 || (Ctl.type && Ctl.type=='button'))  continue
		Nom = Ctl.name
		if (T && !T.initie)  Ch = T.Add(Nom)
		this.all[Nom] = Cto = this.Add(Nom, Ctl)
		if (Tag=='SELECT') {
			if (this.Opt.Selects && (O1=this.Opt.Selects[Nom])) {
				setComboBox(Ctl, O1, {ValDef:null,AjDeb:[['','(?)']]})
				Cto.ValDef()
			}else{
				if ((O1=this.getCtl(LX(Ctl,'Source')))) { Hide(Ctl,'DIV');  Aff(O1,'DIV'); }
			}
		}
	}
	for (Nom in this.all) { Cto = this.all[Nom]; if (!Cto.Champ)  Cto.ValDef() }  // pour la prise en compte des meta au cas où le champ JS n'était pas encore rempli au ValDef de création
	if (this.FinInit)  this.FinInit()
}

FoClass.prototype.Add = function(Nom, id) {
	if (!id)  id = Nom
	this.all[Nom] = new this.CtlClass(this, Nom, id)
	return this.all[Nom]
}

FoClass.prototype.Champ = function(Nom) {
	if (this.Table)  return this.Table.all[Nom]
}

FoClass.prototype.getCtl = function(Nom) {
	var Cto, Ctl, S, J
	if (typeof(Nom)=='string') {
		if ((O=this.all[Nom]))  Ctl = O.Ctrl;  else  Ctl = this.Ctrls[Nom]
	}else
		Ctl = Nom
	return Ctl
}

FoClass.prototype.Changements = function() {
	var O, re, S
	if (this.Table)  re = this.Table.Changements();
  if (O=this.Ctrls[this.CtlMaj])  PVal(O,re)
  return re
}

FoClass.prototype.Url = function() {
	var O, Cto, Ctl, re='', V
	var ValCle = this.ValCle
	for (Nom in this.all) {
		Cto  = this.all[Nom];  Ctl = Cto.Ctrl;  if (LX(Ctl,'noUrl'))  continue;
		V = Cto.Val()
		if (V) {
			re+='&'+Nom+'='+encodeURIComponent(V)
		}
	}
	return re
}

FoClass.prototype.Rech = function()   {
	var Li, a, O
	Li = this.Url();  if (!Li)  return
	O = this.all['_action'];  a = O.Val();		//alert(a+crr+Li)
	ExecAction(a, Li)
}

FoClass.prototype.PreparSov = function() {
	Edit_to_Memo()
}
FoClass.prototype.Sov = function(Opt)   { if (this.Table)  this.Table.Sov(Opt) }
FoClass.prototype.Suppr = function() { if (this.Table)  this.Table.Suppr() }

FoClass.prototype.toString = function() {
	var C, H=''
	for (Nom in this.all) {
		C = this.all[Nom]
		H+= Nom+', '+C.V+cr
	}
	return H+cr
}


// ====================================      CTL       ===============================
var CtlClass = function (Fo, Nom, id, TypAff) {
	var Ctl, T, Ch
	if (typeof(id)=='string')  Ctl = LID(id);  else  Ctl = id
	if (!(this.id=Ctl.name))  this.id = Ctl.id
	if (!TypAff)  TypAff = LX(Ctl,'TypAff')
	PX(Ctl,'ojs','fo_'+Fo.Nom+'.all.'+Nom)

	this.Fo			= Fo
	this.Nom		= Nom
	this.TypAff = TypAff
	this.Ctrl		= Ctl
	this.V			= null
  this.Champ	= null

	if (!Ctl.onchange)  Ctl.onchange = onChange
	if (!Ctl.onfocus)  Ctl.onfocus = onFocus
	if (!Ctl.onblur)  Ctl.onblur = onBlur
	if ((T=this.Fo.Table)) {
		if ((Ch=T.all[Nom])) {
			this.Champ = Ch;  Ch.Cto = this;  Ch.Ctrl = this.Ctrl
		}
	}
	this.ValDef()
}

CtlClass.prototype.Init = function() {
	var Fo, Ctl, O, M, S
	Fo  = this.Fo;  Ctl = this.Ctrl
}

CtlClass.prototype.ValDef = function() {
	var V, S, Ctl, Ch
	Ctl = this.Ctrl;		//alert(Lout(Ctl))
	if ((S=LX(Ctl,'meta'))) {
	  if ((Ch=this.Fo.Ctrls[S]))  PVal(Ctl, Meta(Ch, this.Nom))
	}
	V = LVal(Ctl)
	if (!V) {
		if ((S=LX(Ctl,'Valeur'))) {   // Contrairement à ValDef, Valeur ne dépend pas de ValCle
			if (S.substr(0,1)=='=')  V = Eval(S.substr(1));  else  V = S
		  if (!Ch || (Ch && !Ch.Table.ValCle))  PX(Ctl,'adUrl',1)
		}
		Ch = this.Champ
		if (!Ch || (Ch && !Ch.Table.ValCle)) {
			if ((S=LX(Ctl,'ValDef'))) {
				if (S.substr(0,1)=='=')  V = Eval(S.substr(1));  else  V = S
			}
		  PX(Ctl,'adUrl',1)
		}
		if (Ch && (S=Ch.V))  V = S
	}
	PVal(Ctl,V);
}

CtlClass.prototype.Format = function() {
	var O, V, C, Ch, Typ, TypAff, Opt={}
	O = this.Ctrl
	TypAff = this.TypAff
	if ((Ch=this.Champ)) { Typ = Ch.Typ; }
	V = LVal(O)
	V = FormatChamp(V, Typ, TypAff, Opt)
	return V
}

CtlClass.prototype.Verif = function() {
}

CtlClass.prototype.Traite = function() {  // Traite un champ, en principe après la maj d'un autre champ Source
	var Ctl, T, Sql, S, i, Cto, V, re, n
	Ctl = this.Ctrl
	// CB Ajax
	if ((Sql=LX(Ctl,'Data'))) {
		if ((T=LX(Ctl,'Source').split(','))) {
			re = Sql.split('|')
			Sql = "SELECT " + re[1] + ', ' + re[2] + " FROM " + re[0] + " WHERE " + re[4];		//alert(Sql+crr+JSW(re))
			re = Sql.match(/@[0-9]+/g)
			if (re) {
				for (i=0; i<re.length; i++) {
				  V = ''
					S = re[i].substr(1)-1;		//alert(i+':'+re[i]+','+T[S]);
					if (T[S] && (Cto=this.Fo.all[T[S]]))  V = Cto.Val()
					Sql = Replace(Sql,re[i],V);   //alert(Sql+AjUrl+cr+V)
					var NomC = Mot(Sql,2)
					var Param = { Cto:this }
					var Pgm = function(re, Param) {
					  var JS, C
						var Cto = Param.Cto;  C = Cto.Ctrl
						JS = JSOND(re)
						Aff(C,'DIV');  Hide(LX(Ctl,'Source'),'DIV')
						Focus(C)
						setComboBox(C, JS, {ValDef:null,Clear:1,AjFin:['(Nouvelle sélection)']});		//alert(Lout(C))
						n = C.options.length - 1
						if (n!=1)  setComboBox(C, ['('+ n + ' correspondances)'],{pos:0})
						//C.selectedIndex = 0
					}
					XmlPost2('&Pgm=LitSql&NomC='+NomC+'&Sql='+encodeURIComponent(Sql)+AjUrl, '', Pgm, Param)
				}
			}
		}
	}
}

CtlClass.prototype.Change = function() {
	var Cto, Ctl, M, S, V;			//alert(this.Nom)
	V = this.Format()
	this.Val(V)
	Ctl = this.Ctrl
	if ((S=LX(Ctl,'ChSuit'))) {
		if ((S=LX(S,'ojs'))) {
			Cto = eval(S);  Cto.Traite()
		}
	}
	if ((S=LX(Ctl,'Source'))) {
		if ((S=LX(S,'ojs'))) {
			Cto = eval(S);  if (V==0) { Aff(Cto.Ctrl,'DIV');  Hide(Ctl,'DIV');  Focus(Cto.Ctrl) }
		}
	}
	if ((S=LX(Ctl,'meta'))) {
		if ((Cto=this.Fo.all[S]))  M = Cto.Ctrl;  else  M = this.Fo.Ctrls[S]
		if (M) {
			Meta(M, this.Nom, LVal(Ctl));  if (Cto)  Cto.Val(LVal(M))
		}
	}
	if (this.Fo.Change)  this.Fo.Change(this)
	if (this.FinChange)  this.FinChange()
	PX(this.Ctrl,'Interactif','change')
}

CtlClass.prototype.Focus = function() { PX(this.Ctrl,'Interactif','focus') }

CtlClass.prototype.Blur = function() {
	var O = this.Ctrl;  if (O.type=='text' && LX(O,'Interactif')=='focus') { PX(O,'Interactif','blur');  this.Change(); }   // pour régler le cas du choix d'une valeur déjà saisie dans un champ texte (onchange n'est pas appelé)
}

CtlClass.prototype.Val = function(V) {
	var Ch, Ctl
	 Ctl = this.Ctrl
	if (V===undefined)  return LVal(Ctl)
	if ((Ch=this.Champ)) {
		Ch.Val(V)
	}else
		PVal(Ctl,V);
}



// ====================================      BD       ===============================
var BDClass = function(Nom) {
	this.Nom = Nom
}


// ====================================      TABLE       ===============================
var TableClass = function(Nom, Cle, Typ, ValCle, Opt) {
	if (!Opt)  Opt={}
	this.Nom		= Nom
  this.ChCle	= null
  this.NomC		= Cle
  this.TypCle	= Typ
  this.ValCle	= ValCle
  this.Fo			= null
	this.all		= []
	this.nbMaj	= 0
	this.ChampClass = Opt.ChampClass || ChampClass
	if (Tables[Nom])  delete(Tables[Nom]);  Tables[Nom] = this
	return this
}

TableClass.prototype.Add = function(Nom, Typ, Taille, V, Opt) {
	if (!this.all[Nom])  this.all[Nom] = new this.ChampClass(this, Nom, Typ, Taille, V, Opt)
	return this.all[Nom]
}

TableClass.prototype.ImportDataJS = function(TJS) {
	var Nom, V, R
	if (!TJS)  return
	for (Nom in TJS) {
		R = TJS[Nom];  V = R.V;     //alert(JSONS(R))
		switch (R.Typ) {
		  case 'N':  if (V==0)  V='';  break;
		  case 'D':  V = ConvDate(V);  break;
		}
		this.Add(Nom, R.Typ, R.Siz, V)
	}
	this.ChCle = this.all[this.NomC]
	this.initie = 1
}

TableClass.prototype.Changements = function() {
	var O, re='', V, O
	for (Nom in this.all) {
	  //if (Nom=='Rang')  alert(aa)
		Ch = this.all[Nom]
		V = Ch.V || '';  O = Ch.oldV || '';
		if (V!=O) {
			re+=';'+Nom //+ '='+Ch.V+','+Ch.oldV
		}
	}
	if (re)  re = re+';'
	return re
}

TableClass.prototype.Url = function(noMaj) {
	// champs maj de la table + ctrl avec req ou adUrl ou commence par _. req = toujours, adUrl = seulement si champs importants modifiés
	var O, Cto, Ctl, Ch, i, re=rc=ms='', V
	var ValCle = this.ValCle
	for (Nom in this.all) {
		Ch  = this.all[Nom];
		Ctl = Ch.Ctrl;    ms+= Nom+','+Ch.V+','+Ch.oldV+'\n'
		if (Ch.V!=Ch.oldV || (!ValCle && Ch.V) || (noMaj && Ch.V)) {
		  V = Ch.Val();  //V = Replace(V,'&','%26amp;');
			V = encodeURIComponent(V)
			re+='&'+Nom+'='+V
		}
	}
  	//alert(ms+crr+re)
	if (this.Fo) {
		S = this.ChCle.Nom;  if (re.indexOf('&'+S+'=')<0)  re ='&'+S+'='+this.ChCle.Val() + re
		for (Nom in this.Fo.all) {
			Cto = this.Fo.all[Nom];  Ctl = Cto.Ctrl;  if (LX(Ctl,'noUrl') || re.indexOf('&'+Nom+'=')>=0)  continue;		//alert(Nom+crr+Lout(Ctl))
			if (LX(Ctl,'req'))
				re+='&'+Nom+'='+Cto.Val()
			else{
				if ((Nom.substr(0,1)=='_' || LX(Ctl,'adUrl'))) { rc+='&'+Nom+'='+Cto.Val() }    //|| LX(Ctl,'Verif').indexOf('NonVide')>=0
			}
		}
		if (!re && !noMaj)  rc=''
	}
	re = AddStr(re,rc,'&') + AjUrl
	return re
}

TableClass.prototype.Sov = function(Opt) {
	var Fo, O, Cs, S
	Opt = Opt || {}
	Fo = this.Fo
	Cs = Fo.Ctrls;  if ((S=VerifChamps(Cs))) { alert(S);  return }
	Fo.PreparSov()
	Fo.Changements()
	var Param = this.Url(Opt.Toujours);  if (!Param) { this.SovBack();  return }
	//alert(Param);  return
	if (this.Fo && (O=Cs['_action'])) {
	  ExecAction(O.value, Param)
		return
	}
	XmlPost2(Param, '/SIP/iview/appli.php?Action=Sov:'+Fo.id+'&BugH='+Bug+AjUrl, this.SovBack);
}

TableClass.prototype.SovBack = function(re, Param) {
	if (re==undefined)  return;		//alert(re)
	if (Bug)  DivOther.innerHTML = re
}

TableClass.prototype.Suppr = function() {
	if (!this.ValCle) { alert("Rien à supprimer");  return }
	if (!confirm("D'accord pour supprimer cette fiche ?"))  return
	var Param = this.Url(1);  if (!Param) { this.SupprBack();  return }
	//alert(Param);  return
	XmlPost2(Param, '/SIP/iview/appli.php?Action=Suppr'+'&BugH='+Bug+AjUrl, this.SupprBack);
}

TableClass.prototype.SupprBack = function(re, Param) {
	if (re==undefined)  return;		//alert(re)
	if (Bug)  DivOther.innerHTML = re
}

TableClass.prototype.toString = function() {
	var Ch, H=''
	for (Nom in this.all) {
		Ch = this.all[Nom]
		H+= Nom+', '+Ch.V+cr
	}
	return H+cr
}

// ====================================      CHAMP       ===============================
var ChampClass = function(Table, Nom, Typ, Siz, Valeur, Opt) {
	var Fo, Cto
	this.Table  = Table
	this.Nom	= Nom
	this.Lib	= Nom
	this.Typ	= Typ || 'T';
	this.Siz	= Siz;
	this.Cto	= null
	this.Ctrl	= null
	this.V		= this.InitV(Valeur)
	this.oldV	= this.V
	this.Maj	= 0

	if ((Fo=this.Table.Fo)) {
		if ((Cto = Fo.all[Nom])) {
			Cto.Champ = this;  this.Cto = Cto;  this.Ctrl = Cto.Ctrl
		}
	}
}

ChampClass.prototype.InitV = function(Valeur) {
	var V
	if (Valeur==undefined)
		V = null
	else
		switch(this.Typ) {
			case 'T': V = Valeur;  break
			case 'M': if (!(V=Valeur) && this.Table)  V = LVal(this.Table.Nom+"_"+this.Nom);  break
			case 'B': if (typeof(Valeur)=="string")  V = eval(Valeur.toLowerCase());  else  V = Valeur;  break
			default:	V = Valeur
		}
	return V
}

ChampClass.prototype.Val = function(Valeur) {
	if (Valeur==undefined) {
		if (this.Ctrl)  return LVal(this.Ctrl);  else  return this.V
	}
	this.V = Valeur
	if (this.Ctrl)  PVal(this.Ctrl, Valeur)
	if (this.Cto)  this.Cto.Fo.Changements()
}




// ====================================      ss-PGM       ===============================
function onChange(e) {
	var O, Cto, S
  if ((Cto=EventCto(e)))  Cto.Change()
  if (window.onChange2)  window.onChange2(e)
}

function onFocus(e) { var Cto;  if ((Cto=EventCto(e)))  Cto.Focus() }
function onBlur(e) { var Cto;  if ((Cto=EventCto(e)))  Cto.Blur() }
function EventCto(e) { var O = EventCtrl(e);  if ((S=LX(O,'ojs')))  return Eval(S) }


function FormatChamp(V,Typ,TypAff,Opt) {
	var O, V, C, Test, p
	if (!Opt)  Opt = {}
	if (typeof(V)=='string') { C = V.substr(0,1);  if (C=='=')  V = V.substr(1) }
	if (!V)  return V
		//alert(Typ+cr+TypAff+cr+V)
	switch (Typ) {
		case 'N':
			V = Replace(V,",",".");  S = parseFloat(V);
			if (S!=V) { if (isNaN(S)) S='';  if (V) Opt.MsgErr = V + " n'est pas un nombre. Conversion automatique en '" + S + "'";  V=S }
			break
	}
	switch (TypAff) {
    case 'D':  V = ConvDate(V);  break
		case 'email':
			Test = new RegExp("^([a-zA-Z0-9_-])+([.]?[a-zA-Z0-9_-]{1,})*@([a-zA-Z0-9-_]{2,}[.])+[a-zA-Z]{2,3}$");
			if (!Test.exec(V))  Opt.Msg = "Adresse invalide (format : nom@domaine.dom)"
		  break
		case 'minus':  if (C!="=")  V = V.toLowerCase();  break
		case 'majus':  if (C!="=")  V = V.toUpperCase();  break
    case 'minus2':  V = Minus(V);  break
    case 'majus2':  V = Majus(V);  break
    case 'NP':  	 if (C!='=')  V = NomPropre(V);  		break
		case 'tel':
			V = ClearText (V, "!isNaN(Car) || Car=='.'");  if (V.length!=10)  break
			V = V.substr(0,2) + "." + V.substr(2,2) + "." + V.substr(4,2) + "." + V.substr(6,2) + "." + V.substr(8,2)
			break
	}
	return V
}

function Meta(Ctl, Nom, V) {
	var Cto, Ctl, S, J, e, Pg
	O = LID(Ctl)
	if (!(S=LVal(O)))
		J = {}
	else{
		S = Replace(S,'\r\n','\\n');  S = Replace(S,'\n','\\n');
		J = JSOND(S);  //alert(Nom+crr+S+crr+JSONS(J))
	}
	if (V===undefined)  return J[Nom]
	if ((Pg=window['debMaj_'+O.name])) {
		Opt = { Nom:Nom, V:V }
		if (!(e=Pg(J,Opt)))  return
		Nom = Opt.Nom;  V = Opt.V
		//alert(Nom+cr+V+crr+JSW(J))
	}
	if (V)  J[Nom] = V;  else  delete(J[Nom])
	S = JSONS(J);  if (S=='{}' || S=='[]')  S=''
	PVal(O,S)
}

function VerifChamps(Ctrls) {
	var Ctl, V, S, Msg="", i
  for (i=0; i<Ctrls.length; i++) {
		Ctl = Ctrls[i];  //alert(Lout(Ctl))
  	Msg += VerifChamp(Ctl)
  }
	return Msg
}

function VerifChamp(Ctl) {
	var Ctl, V, S, Msg="", Termin="", i, j, p, l, Err, Lib, T, O2

	Lib = LX(Ctl,"title");  if (!Lib)  Lib = LX(Ctl,"Lib");
	if (!Lib) { O2 = Elem(Ctl, "O.tagName=='LABEL'", true);	 if (O2)  Lib = LText(O2); }
	if (!Lib)  Lib = Ctl.name
	V = LVal(Ctl)
	S = LX(Ctl,"Verif") + ""
	T = S.split(",")
	for (j=0; j<T.length; j++) {
		//alert(T[j])
		switch (T[j]) {
			case "NonVide":
				Err = false
				switch (Ctl.type) {
					case "radio":
						var doc_ctl
						if (ie)  doc_ctl = Ctl.document;  else  doc_ctl = document
						if (Ctl==doc_ctl.getElementsByName(Ctl.name)[0] && !LitRadio(Ctl))  Err=true;  break
					case "checkbox":  if (!Ctl.checked)  Err=true;  break
					default:  if (!Ctl.value)  Err=true
				}
				if (Err) {
					if (Ctl.type=="checkbox") { Msg = "La case à cocher ";  Termin="e" }
					Msg += Lib + " doit être renseigné"
					Msg += Termin
				}
				break
			case "IP":
				var regexp = /\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/ ;
				//\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b
				if (V.match(regexp))  Msg = "L'adresse ip " + Lib + " n'est pas valide"
				break
			case "eMail":
				if (!V) break
				var Test = new RegExp("^([a-zA-Z0-9_-])+([.]?[a-zA-Z0-9_-]{1,})*@([a-zA-Z0-9-_]{2,}[.])+[a-zA-Z]{2,3}$");
				if (!Test.exec(V))  Msg = V + " n'est pas une e-mail valide.\nVous devez entrer un mail de la forme : nom@domaine.dom"
				break
		}
	}
	if (Msg)  Msg+="\n"
	return Msg
}

function SelectOpt(Ctl) {
	Ctl = LID(Ctl);  if (!Ctl)  return
	if (!Ctl.options || Ctl.selectedIndex<0)  return null
  return Ctl.options[Ctl.selectedIndex];
}

function setComboBox(CB, Liste, Opt) {
	var CB, Cod, Li, S, O, V, N, i, ValDef
	CB = LID(CB);  if (!CB)  return
	if (typeof Liste=='string')  Liste = Tableau2D(Liste);		//alert(JSW(Liste))
	Opt = Opt || {}
	if (Opt.Clear) { delete(Opt.Clear);  CB.innerHTML='' }
	if (Opt.AjDeb)  setComboBox(CB, Opt.AjDeb)
	ValDef = Opt.ValDef

	for (Cod in Liste) {
		Li = Liste[Cod];			//alert(Cod+crr+S)
		O = document.createElement('OPTION')
		if (typeof(Li)=='object') {
			i = 0
			for (N in Li) {
				S = Li[N]
				if (i==0)  Cod = S
				else if (i==1)  V = S
				else{
					PX(O,N,S)
				}
				i++
			}
		}else{
			V = Li
		}
		O.value = Cod;  O.text = V
		//if (document.all)  CB.add(O,1);  else  CB.add(O,null)
		CB.add(O,Opt.pos)
	}
	nb = CB.options.length
	if (nb==1)  ValDef = Cod
	if (Opt.AjFin)  setComboBox(CB, Opt.AjFin)
	if (ValDef!==undefined)  PVal(CB,ValDef)
}

function Edit_to_Memo() {
	var n, inst, S, Ctl, Cto
	if (App.tinyMCE) {  
		for (n in tinyMCE.instances) {
			inst = tinyMCE.instances[n];  if (!tinyMCE.isInstance(inst))  continue;
			if (!inst.isDirty())  continue
			//inst.triggerSave(true, true);  //alert(inst.isDirty())
			inst.triggerSave(false, false);  //alert(inst.isDirty())
			Ctl = LID(inst.formTargetElementId);  Cto = eval(LX(Ctl,'ojs'))
			Cto.Val(LVal(Ctl))
			//inst.startContent   = tinyMCE.trim(inst.getBody().innerHTML);  inst.isNotDirty     = true;
		}
	}
}
