
function trim(strValue)
{
     var ichar = strValue.length - 1,ch;
     while(ichar >= 0 && ((ch = strValue.charAt(ichar))==' '||ch == '\t'||ch == '\r'||ch == '\n'))
         --ichar;
     if (ichar<(strValue.length-1))
         strValue = strValue.slice(0,ichar+1);
     ichar = 0;
     var icount = strValue.length - 1;
     while (ichar < icount && ((ch = strValue.charAt(ichar))==' '||ch == '\t'||ch == '\r'||ch == '\n'))
         ++ichar;
     if (ichar>0)
         strValue = strValue.slice(ichar,strValue.length);
     return strValue;
}

function _epr(oLocale,errorIco,modifiedIco)
{
    this.tUtils={};
    this.tHiddens={};
    this.locale=oLocale;
    this.errorIco=errorIco;
    this.modifiedIco=modifiedIco;
    this.sty={txt:"bos_fieldtext", lst:"bos_fieldselect", nrm:"bos_fieldenabled", loc:"bos_fielddisabled", err:"bos_fielderror"};

    this.Init=_Init;
    this.CreateFmtText=_CreateFmtText;
    this.CreateFmtSelect=_CreateFmtSelect;
    this.Clear=_ClearScr;
    this.ClearScr=_ClearScr;
    this.ClearVal=_ClearVal;
    this.Reset=_ResetScr;
    this.ResetScr=_ResetScr;
    this.ResetVal=_ResetVal;
    this.Check=_CheckScr;
    this.CheckScr=_CheckScr;
    this.CheckVal=_CheckVal;
    this.PutError=_PutError;
    this.PutModified=_PutModified;
    this.FldError=_FldError;
    this.SendRemote=_SendRemoteScr;
    this.SendAll=_SendAllScr;
    this.ExecuteResponse = _ExecuteResponse;
    this.PutScr=_PutScr;
    this.PutVal=_PutVal;
    this.GetScr=_GetScr;
    this.GetVal=_GetVal;
    this.GetEleVal=_GetEleVal;
    this.LockScr=_LockScr;
    this.LockVal=_LockVal;
    this.ActifScr=_ActifScr;
    this.ActifVal=_ActifVal;
    this.LstAdd=_LstAdd;
    this.LstAddAll=_LstAddAll;
    this.LstClear=_LstClear;
    this.AddField=_AddField;
    this.AddFieldStart=_AddFieldStart;
    this.FldFocus=_FldFocus;
    this.RemoveFields=_RemoveFields;
    this.AddFieldHidden=_AddFieldHidden;

    this.ReplParam = _ReplParam;
    this.ReplParamSep = _ReplParamSep;
    this.Srv_Err=_SrvError;
    this.Srv_Msg=_SrvMessage;

//  this.addFieldStartChg = false;
}

function _Init()
{
}

function _AddFieldStart()
{
//    this.addFieldStartChg = false;
}

function _AddField(fldName,fldFmt,fldArg,startCheck)
{
    var oTag = document.getElementById(fldName);
    if (!oTag)
    {
        //alert(fldName+ " not found !");
        return;
    }
/*  if(this.tUtils[oTag.id])
    {
        alert(fldName+ " defined more than one time !");
        return;
    }*/

    if (typeof(fldArg) == 'undefined')
        fldArg = oTag.value;

    var sError="";
    var oElem;
    if (startCheck)
        oElem={src:oTag, newsrc:true, fmt:fldFmt, defaultValue:oTag.value};
    else
        oElem={src:oTag, newsrc:true, fmt:fldFmt, defaultValue:fldArg};
    var sMsg="";
    if(oTag.type.match( /^text|hidden|password|textarea$/ ))
    {
        //oTag.onfocus=Function("this.select()");//
        sMsg=this.CreateFmtText(oElem);
    }
    else if(oTag.type.match( /^select/ ))
        sMsg=this.CreateFmtSelect(oElem);
    else
    {
        alert(fldName+ " has a bad type !");
        return;
    }

    if(sMsg)
    {
        this.FldError(oElem,sMsg);
    }
    else
    {
        oElem.src.value=(((oElem.fctToScr)&&(oElem.typ!="P")) ? oElem.fctToScr(oElem.defaultValue,oElem.Info) : oElem.defaultValue);
        this.FldError(oElem);
        this.tUtils[oTag.id]=oElem;
    }
    if (startCheck)
    {
        if (fldArg != oTag.value)
        {
//          alert("Field "+oTag.id+" has changed");
            this.addFieldStartChg = true;
            if(oTag.fireEvent)
            {
                //On IE
                oTag.fireEvent("onchange");
            }
            else
            {
                //On Gecko based browsers
                var evt = document.createEvent("HTMLEvents");
                evt.initEvent("change", true, true);
                oTag.dispatchEvent(evt);
            }
        }
/*        else
            alert("Field "+oTag.id+" has not changed ("+oTag.value+")");*/
    }
}

function _AddFieldHidden(fldName)
{
    var oTag = document.getElementById(fldName);
    if (!oTag)
    {
        //alert(fldName+ " not found !");
        return;
    }

    var oElem={src:oTag, newsrc:true};
    this.tHiddens[oTag.id]=oElem;
}

function _CreateFmtText(oElem)
{
    var tRes=oElem.fmt.match( /^#([+-]?)(N|D|H|T|SC|SH|M|B|L|IP|ID|IN|P|X)(.*)$/ );
    if(!tRes) return "fieldFormatInvalid@"+oElem.fmt;
    var tOptions=tRes[3].split("#");
    var sError="";
    oElem.objtyp="T";
    oElem.typ=tRes[2];
    oElem.sw={NULL:"", A:"", BR:"", O:"", TI:"", CL:""};
    oElem.maj={};
    oElem.layout="";
    oElem.defaultClass=oElem.src.className;
    oElem._editor = null;
    switch(oElem.typ)
    {
        case "N":   sError=_checkFmtNumeric(oElem,tOptions[0],tRes[1],this.locale); break;
        case "D":   sError=_checkFmtDate(oElem,tOptions[0],this.locale); break;
        case "H":   sError=_checkFmtTime(oElem,tOptions[0],this.locale); break;
        case "T":   sError=_checkFmtText(oElem,tOptions[0],msgLang_fieldFormatMaxChar); break;
        case "SC":  sError=_checkFmtScript(oElem,tOptions[0],msgLang_fieldFormatMaxChar);
                        break;
        case "SH":  sError=_checkFmtScript(oElem,tOptions[0],msgLang_fieldFormatMaxChar);
                        //if (oElem.type == "textarea")
                        {
                            oElem._editor = new HTMLArea(oElem.src);
                            oElem._editor.generate();
                        }
                        break;
        case "X":   sError=_checkFmtFmt(oElem,tOptions[0],msgLang_fieldFormatMaxChar); break;
        case "ID":  sError=_checkFmtID(oElem,tOptions[0],msgLang_fieldFormatMaxChar); break;
        case "IP":  sError=_checkFmtIP(oElem,tOptions[0]); break;
        case "IN":  sError=_checkFmtIN(oElem,tOptions[0],msgLang_fieldFormatMaxChar); break;
        case "M":   sError=_checkFmtMail(oElem,tOptions[0],msgLang_fieldFormatMaxChar); break;
        case "B":   sError=_checkFmtBoolean(oElem,tOptions[0]); break;
        case "L":   sError=_checkFmtList(oElem,tOptions[0]); break;
        case "P":   sError=_checkFmtPass(oElem,tOptions[0],msgLang_fieldFormatMaxChar); break;
    }


    if(sError) return sError;
    for(var iCtr=1; iCtr<tOptions.length; iCtr++)
        if(sError=_checkFmtOption(oElem,tOptions[iCtr])) return sError;
/*  if(oElem.newsrc)
        oElem.src.insertAdjacentHTML("AfterEnd","<label id='l_"+oElem.src.id+"'></label");
    oElem.label=document.getElementById("l_"+oElem.src.id);
    */

    if(oElem.sw.A)
    {
        oElem.label.innerText=(oElem.sw.BR ? "\n" : " ")+oElem.layout+
            (oElem.sw.I && oElem.limits ? " ["+oElem.limits+"]" : "");
    }

    if(oElem.sw.TI)
        oElem.src.title=oElem.layout+(oElem.sw.I && oElem.limits ? "\n["+oElem.limits+"]" : "");

    if(oElem.sw.ML)
    {
        oElem.src.maxLength=oElem.ml;
        if (oElem.typ == "D" || oElem.typ == "N")
            oElem.src.size=oElem.ml;
        if (oElem.typ == "T"|| oElem.typ == "P"|| oElem.typ == "ID")
        {   if (oElem.src.style.width=="")
            {
                if (oElem.ml<=10) {oElem.src.style.width=oElem.ml*9+"px";}
                if (oElem.ml<=20 && oElem.ml>10) {oElem.src.style.width=oElem.ml*7+"px";}
                if (oElem.ml<=50 && oElem.ml>20) {oElem.src.style.width=oElem.ml*5+"px";}
                if (oElem.ml>50 )
                {
                    if(oElem.sw.A)
                        oElem.src.style.width="70%";
                    else
                        oElem.src.style.width="90%";
                }
            }
        }
    }

    if(oElem.sw.CL)
        oElem.defaultClass=this.sty.txt;
    if (oElem.typ == "N")
        oElem.src.style.textAlign = "right";
    return "";
}

function _CreateFmtSelect(oElem)
{
    var tRes=oElem.fmt.match( /^#(L)(.*)$/ );
    if(!tRes) return "fieldFormatInvalid@"+oElem.fmt;
    var tOptions=tRes[2].split("#");
    var sError="";
    oElem.objtyp="S";
    oElem.typ=tRes[1];
    oElem.sw={CL:""};
    oElem.maj={};
    oElem.defaultClass=oElem.src.className;
    sError=_checkFmtSelect(oElem,tOptions[0]);
    if(sError) return sError;
    for(var iCtr=1; iCtr<tOptions.length; iCtr++)
        if(sError=_checkFmtOption(oElem,tOptions[iCtr])) return sError;
    if(oElem.sw.CL)
        oElem.defaultClass=this.sty.lst;
    return "";
}

// <--- Fonctions de vérification des paramètres de chaque `fmt` --->

function _checkFmtNumeric(oElem,sParam,sSgn,oLocale)
{
    var tRes;
    oElem.sgn=sSgn;
    oElem.len=3;
    oElem.dec=2;
    oElem.limits="";
    oElem.min="";
    oElem.max="";
    oElem.sw.I="";
    oElem.sw.ML="";
    if(sParam)
        if(tRes=sParam.match( /^(\d\d)(\d\d)((-?\d+\.?\d*)?\/(-?\d+\.?\d*)?)?$/ ))
        {
            oElem.len=tRes[1]-0;
            oElem.dec=tRes[2]-0;
            if(tRes[3])
                if(tRes[3]!="/")
                {
                    if(tRes[4])
                    {
                        oElem.min=tRes[4];
                        oElem.limits+=oLocale.NumberToScr(tRes[4]);
                    }
                    oElem.limits+=" <= ";
                    if(tRes[5])
                    {
                        oElem.max=tRes[5];
                        oElem.limits+=oLocale.NumberToScr(tRes[5]);
                    }
                }
                else
                    return "fieldNumFormatLimitInvalid@"+oElem.fmt+"@"+tRes[3];
        }
        else
            return "fieldNumFormatInvalid@"+oElem.fmt+"@"+sParam;
    for(iCtr=0; iCtr<oElem.len; iCtr++) oElem.layout+=(iCtr ? "" : sSgn)+"9";
    for(iCtr=0; iCtr<oElem.dec; iCtr++) oElem.layout+=(iCtr ? "" : oLocale.numSep)+"9";
    oElem.ml=oElem.layout.length;
    oElem.locale=oLocale;
    oElem.fctToScr=new Function("sSrc","return this.locale.NumberToScr(sSrc)");
    oElem.fctFromScr=new Function("sSrc","return this.locale.NumberFromScr(sSrc)");
    oElem.check=_checkChampNumeric;
    return "";
}

function _checkFmtDate(oElem,sParam,oLocale)
{
    var tRes;
    oElem.limits="";
    oElem.min="";
    oElem.max="";
    oElem.sw.I="";
    oElem.sw.ML="";
    if(sParam)
        if(tRes=sParam.match( /^((\d{1,2}\/\d{1,2}\/\d{4})?-(\d{1,2}\/\d{1,2}\/\d{4})?)?$/ ))
        {
            if(tRes[1])
            {
                if(tRes[2])
                {
                    oElem.min=oLocale.DateCheck(tRes[2]);
                    if(!oElem.min) return "msgLang_fieldDateFormatLimitInvalid@"+oElem.fmt+"@"+sParam;
                    oElem.limits+=oLocale.DateToScr(tRes[2]);
                }
                oElem.limits+=" <= ";
                if(tRes[3])
                {
                    oElem.max=oLocale.DateCheck(tRes[3]);
                    if(!oElem.max) return "msgLang_fieldDateFormatLimitInvalid@"+oElem.fmt+"@"+sParam;
                    oElem.limits+=oLocale.DateToScr(tRes[3]);
                }
            }
        }
        else
            return "fieldDateFormatInvalid@"+oElem.fmt+"@"+sParam;
    oElem.layout=oLocale.FmtDate;
    oElem.ml=(oLocale.datSep ? 14 : 12);
    oElem.fctToScr=new Function("sSrc","return this.locale.DateToScr(sSrc)");
    oElem.fctFromScr=new Function("sSrc","return this.locale.DateFromScr(sSrc)");
    oElem.locale=oLocale;
    oElem.check=_checkChampDate;
    return "";
}

function _checkFmtTime(oElem,sParam,oLocale)
{
    var tRes;
    oElem.limits="";
    oElem.min="";
    oElem.max="";
    oElem.sw.I="";
    oElem.sw.ML="";
    if(sParam)
        if(tRes=sParam.match( /^((\d{1,2}:\d{2})?-(\d{1,2}:\d{2})?)?$/ ))
        {
            if(tRes[1])
            {
                if(tRes[2])
                {
                    oElem.min=oLocale.TimeCheck(tRes[2]);
                    if(!oElem.min) return "fieldTimeFormatLimitInvalid@"+oElem.fmt+"@"+sParam;
                    oElem.limits+=oLocale.TimeToScr(tRes[2]);
                }
                oElem.limits+=" <= ";
                if(tRes[3])
                {
                    oElem.max=oLocale.TimeCheck(tRes[3]);
                    if(!oElem.max) return "fieldTimeFormatLimitInvalid@"+oElem.fmt+"@"+sParam;
                    oElem.limits+=oLocale.TimeToScr(tRes[3]);
                }
            }
        }
        else
            return "fieldTimeFormatInvalid@"+oElem.fmt+"@"+sParam;
    oElem.ml=(oLocale.timSep ? 5 : 4);
    oElem.layout=oLocale.FmtTime;
    oElem.fctToScr=new Function("sSrc","return this.locale.TimeToScr(sSrc)");
    oElem.fctFromScr=new Function("sSrc","return this.locale.TimeFromScr(sSrc)");
    oElem.locale=oLocale;
    oElem.check=_checkChampTime;
    return "";
}

function _checkFmtPass(oElem,sParam,sLib)
{
    var tRes;
    oElem.len=250;
    oElem.sw.UC="";
    oElem.sw.LC="";
    oElem.sw.TR="";
    oElem.sw.ML="";

    var tKey=sParam.split("§");

    if(tKey.length!=3){return "fieldFormatParamInvalid@"+oElem.fmt+"@"+sParam;}
    sParam = tKey[0];
    sKeyInfo = tKey[1];
    sNb = tKey[2];
    if(sParam)
        if(tRes=sParam.match( /^([1-9][0-9]{0,4})$/ ))
            {oElem.len=tRes[1]-0;
            iLen = (oElem.len-5);
            if(iLen<0){return "fieldFormatParamInvalid@"+oElem.fmt+"@"+sParam;}
            }
        else
            return "fieldFormatParamInvalid@"+oElem.fmt+"@"+sParam;
    if(sKeyInfo)
        if(tRes=sKeyInfo.match( /^([1-9][0-9]{0,10})$/ ))
            oElem.Info=tRes[1]-0;
        else
            return "fieldFormatParamInvalid@"+oElem.fmt+"@"+sKeyInfo;
    if(sNb)
        {if(tRes=sNb.match( /^([0-9][0-9]{0,1})$/ ))
            {oElem.limits=tRes[1]-0;}
        else
            return "fieldFormatParamInvalid@"+oElem.fmt+"@"+sNb;}
    else
            return "fieldFormatParamInvalid@"+oElem.fmt+"@"+sNb;
    oElem.layout=oElem.len+" "+sLib;
    oElem.ml=oElem.len;
    oElem.check=_checkChampPass;
    oElem.fctFromScr=new Function("sSrc","sInfo","return _PassFromScr(sSrc,sInfo)");
    oElem.fctToScr=new Function("sSrc","sInfo","return _PassToScr(sSrc,sInfo)");
    return "";
}

function hexfromdec(num) {
    if (num > 65535) { return ("overflow!") }
    first = Math.round(num/4096 - .5);
    temp1 = num - first * 4096;
    second = Math.round(temp1/256 -.5);
    temp2 = temp1 - second * 256;
    third = Math.round(temp2/16 - .5);
    fourth = temp2 - third * 16;
        return (""+getletter(first)+getletter(second)+getletter(third)+getletter(fourth));
}

function getletter(num) {
    if (num < 10) {
        return num;
    }
    else
    {
        if (num == 10) { return "A" }
                if (num == 11) { return "B" }
                if (num == 12) { return "C" }
                if (num == 13) { return "D" }
                if (num == 14) { return "E" }
                if (num == 15) { return "F" }
        }
}

function he2i(sHex)
{
    ih2i = 0 ;
    iMultJS = 16;
    iResultJS = 0 ;
    for(var ih2i = 0; ih2i<=1; ih2i++)
    {
        sDigit = sHex.substr(ih2i,1)
        if (sDigit == "F") { iResultJS = iResultJS + 15 * iMultJS  }
        if (sDigit == "E") { iResultJS = iResultJS + 14 * iMultJS  }
        if (sDigit == "D") { iResultJS = iResultJS + 13 * iMultJS  }
        if (sDigit == "C") { iResultJS = iResultJS + 12 * iMultJS  }
        if (sDigit == "B") { iResultJS = iResultJS + 11 * iMultJS  }
        if (sDigit == "A") { iResultJS = iResultJS + 10 * iMultJS  }
        if (sDigit == "9") { iResultJS = iResultJS + 9 * iMultJS  }
        if (sDigit == "8") { iResultJS = iResultJS + 8 * iMultJS  }
        if (sDigit == "7") { iResultJS = iResultJS + 7 * iMultJS  }
        if (sDigit == "6") { iResultJS = iResultJS + 6 * iMultJS  }
        if (sDigit == "5") { iResultJS = iResultJS + 5 * iMultJS  }
        if (sDigit == "4") { iResultJS = iResultJS + 4 * iMultJS  }
        if (sDigit == "3") { iResultJS = iResultJS + 3 * iMultJS  }
        if (sDigit == "2") { iResultJS = iResultJS + 2 * iMultJS  }
        if (sDigit == "1") { iResultJS = iResultJS + 1 * iMultJS  }
        iMultJS = iMultJS - 15
    }
    return iResultJS
}

function _PassFromScr(sSrc,sInfo)
{
    sNewKey = "";
    sResultInf = "";
    sInfoVal = new String(sInfo);
    while (sSrc.length>sNewKey.length){sNewKey = sNewKey+sInfoVal;}
    sNewKey = sNewKey.substr(0,sSrc.length)
    for(var iBoucle = 0; iBoucle<sSrc.length; iBoucle++)
    {
        sXOR = hexfromdec(sSrc.substr(iBoucle,1).charCodeAt(0) ^ sInfoVal.substr(iBoucle,1).charCodeAt(0));
        sResultInf = sResultInf+sXOR.substr(sXOR.length-2,sXOR.length);
    }
    return sResultInf;
}

function _PassToScr(sSrc,sInfo)
{
    sNewKey = "";
    sResultInf = "";
    sInfoVal = new String(sInfo);
    while (sSrc.length/2>sNewKey.length){sNewKey = sNewKey+sInfoVal;}
    sNewKey = sNewKey.substr(0,sSrc.length)
    for(var iBoucle = 1; iBoucle<sSrc.length/2+1; iBoucle++)
    {
        sResultInf = sResultInf+String.fromCharCode(he2i(sSrc.substr((iBoucle-1)*2, 2))^sInfoVal.substr(iBoucle-1,1).charCodeAt(0));
    }
    return sResultInf;
}

//MMM: ex tag
function _checkFmtText(oElem,sParam,sLib)
{
    var tRes;
    oElem.len=4096;
    oElem.sw.UC="";
    oElem.sw.LC="";
    oElem.sw.TR="";
    oElem.sw.ML="";
    oElem.sw.EX="";
    if(sParam)
    {
        if(tRes=sParam.match( /^([1-9][0-9]{0,4})$/ ))
            oElem.len=tRes[1]-0;
        else
            return "fieldFormatParamInvalid@"+oElem.fmt+"@"+sParam;
    }
    oElem.layout=oElem.len+" "+sLib;
    oElem.ml=oElem.len;
    oElem.check=_checkChampText;
    return "";
}

function _checkFmtScript(oElem,sParam,sLib)
{
    var tRes;
    oElem.len=4096;
    oElem.sw.UC="";
    oElem.sw.LC="";
    oElem.sw.TR="";
    oElem.sw.ML="";
    oElem.sw.EX="";
    if(sParam)
    {
        if(tRes=sParam.match( /^([1-9][0-9]{0,4})$/ ))
            oElem.len=tRes[1]-0;
        else
            return "fieldFormatParamInvalid@"+oElem.fmt+"@"+sParam;
    }
    oElem.layout=oElem.len+" "+sLib;
    oElem.ml=oElem.len;
    oElem.check=_checkChampScript;
    return "";
}

//MMM: ajout type
function _checkFmtFmt(oElem,sParam,sLib)
{
    var tRes;
    oElem.len=4096;
    oElem.sw.UC="";
    oElem.sw.LC="";
    oElem.sw.TR="";
    oElem.sw.ML="";
    oElem.sw.EX="";
    if(sParam)
    {
        if(tRes=sParam.match( /^([1-9][0-9]{0,4})$/ ))
            oElem.len=tRes[1]-0;
        else
            return "fieldFormatParamInvalid@"+oElem.fmt+"@"+sParam;
    }
    oElem.layout=oElem.len+" "+sLib;
    oElem.ml=oElem.len;
    oElem.check=_checkChampFmt;
    return "";
}

//MMM: ajout type
function _checkFmtID(oElem,sParam,sLib)
{
    var tRes;
    oElem.len=250;
    oElem.sw.UC="";
    oElem.sw.LC="";
    oElem.sw.TR="";
    oElem.sw.ML="";
    oElem.sw.EX="";
    if(sParam)
    {
        if(tRes=sParam.match( /^([1-9][0-9]{0,4})$/ ))
            oElem.len=tRes[1]-0;
        else
            return "fieldFormatParamInvalid@"+oElem.fmt+"@"+sParam;
    }
    oElem.layout=oElem.len+" "+sLib;
    oElem.ml=oElem.len;
    oElem.check=_checkChampID;
    return "";
}

//MMM: ajout type
function _checkFmtIN(oElem,sParam,sLib)
{
    var tRes;
    oElem.len=250;
    oElem.sw.UC="";
    oElem.sw.LC="";
    oElem.sw.TR="";
    oElem.sw.ML="";
    oElem.sw.EX="";
    if(sParam)
    {
        if(tRes=sParam.match( /^([1-9][0-9]{0,4})$/ ))
            oElem.len=tRes[1]-0;
        else
            return "fieldFormatParamInvalid@"+oElem.fmt+"@"+sParam;
    }
    oElem.layout=oElem.len+" "+sLib;
    oElem.ml=oElem.len;
    oElem.check=_checkChampIN;
    return "";
}

function _checkFmtIP(oElem,sParam)
{
    oElem.sw.ML="";
    if(sParam)
        return "fieldIPformatInvalid@"+oElem.fmt+"@"+sParam;
    else
        oElem.layout=msgLang_fieldIPsyntaxe;
    oElem.ml=15;
    oElem.check=_checkChampIP;
    return "";
}

function _checkFmtMail(oElem,sParam,sLib)
{
    var tRes;
    oElem.len=250;
    oElem.sw.UC="";
    oElem.sw.LC="";
    oElem.ML;
    if(sParam)
        if(tRes=sParam.match( /^([1-9][0-9]{0,2})$/ ))
            oElem.len=tRes[1]-0;
        else
            return "fieldMailFormatInvalid@"+oElem.fmt+"@"+sParam;
    oElem.layout=msgLang_fieldMailSyntaxe + " ("+oElem.len+" "+sLib+")";
    oElem.ml=oElem.len;
    oElem.check=_checkChampMail;
    return "";
}

function _checkFmtBoolean(oElem,sParam)
{
    var tRes;
    oElem.items="";
    oElem.sw.UC="";
    oElem.sw.LC="";
    oElem.sw.ML="";
    oElem.ml=0;
    if(tRes=sParam.match( /^[^.]+-[^,]+$/ ))
    {
        oElem.items=sParam.split("-");
        oElem.layout=sParam;
        for(iCtr=0; iCtr<oElem.items.length; iCtr++)
            if(oElem.items[iCtr].length>oElem.ml)
                oElem.ml=oElem.items[iCtr].length;
    }
    else
        return "fieldBoolFormatInvalid@"+oElem.fmt+"@"+sParam;
    oElem.check=_checkChampBoolean;
    return "";
}

function _checkFmtList(oElem,sParam)
{
    oElem.items="";
    oElem.sw.UC="";
    oElem.sw.LC="";
    oElem.sw.ML="";
    if(sParam)
    {
        oElem.items=sParam.split(",");
        oElem.layout=sParam;
        for(iCtr=0; iCtr<oElem.items.length; iCtr++)
            if(oElem.items[iCtr].length>oElem.ml)
                oElem.ml=oElem.items[iCtr].length;
    }
    else
        return "fieldListFormatInvalid@"+oElem.fmt+"@"+sParam;
    oElem.check=_checkChampList;
    return "";
}

function _checkFmtSelect(oElem,sParam)
{
    if(sParam=="") return "";
    var tOptions=sParam.split("§");
    var iCtr,tValeurs;
    while(oElem.src.options.length>0) oElem.src.remove(0);
    for(iCtr=0; iCtr<tOptions.length; iCtr++)
    {
        tValeurs=tOptions[iCtr].split("|");
        if(tValeurs.length<2)
            oElem.src.options.add(new Option(tValeurs[0],tValeurs[0]));
        else
            oElem.src.options.add(new Option(EprUnescape(tValeurs[1]),tValeurs[0]));
    }
    return "";
}

function _checkFmtOption(oElem,sOption)
{
    var tRes;
    if(tRes=sOption.match( /^F([A-Z]+)([0-9]+)$/) )
        oElem.maj[tRes[1]]=tRes[2]-0;
    else if(tRes=sOption.match( /^D(.+)$/ ))
        oElem.defaultValue=tRes[1];
    else if((tRes=sOption.match( /^([A-Z]+)(.+)$/))
        && oElem.sw[tRes[1]]!=null)
    {
//MMM       alert(tRes[1] + " == " +tRes[2]);
        oElem.sw[tRes[1]] = tRes[2];
    }
    else if(oElem.sw[sOption]==null)
        return "fieldListOptInvalid@"+sOption;
    else if(oElem.sw[sOption])
        return "fieldListOptRepeated@"+sOption;
    else
        oElem.sw[sOption]=1;
    return "";
}

// <--- Functions de vérification des la valeur des champs proprement dit --->

function _CheckScr(sForm,sMaj)
{
    var oElem,oFocus,sMsg;
    var sError="";

    for(var sCtr in this.tUtils)
    {
        oElem=this.tUtils[sCtr];
        if (sForm != null && oElem.src.form != sForm) continue;
        if(sMaj && oElem.maj[sMaj]==null) continue;
        sMsg=this.CheckVal(oElem.src);
        if(sMsg && !sError)
        {
            sError=sMsg;
            oFocus=oElem.src;
        }
    }
    if(sError)
    {
        alert(this.ReplParamSep(sError));
        _FldFocus(oFocus);
        return 1;
    }
    return 0;
}

function _appliIdMake(appliIdList)
{
    var arr = appliIdList.split("|"), ret = new Array, cnt=0;
    for(var i = 0; i < arr.length; i++)
    {
        ret[cnt++] = "$f_"+arr[i]+"_";
    }
    return ret;
}

function _appliIdMatch(sCtrName, appliIdList)
{
    for(var i = 0; i < appliIdList.length; i++)
    {
        var sappid = appliIdList[i];
        if (sCtrName.substr(0,sappid.length) == sappid)
            return true;
    }
    return false;
}

function _SendAllScr(sForm,appliId,inputCheck,sMaj)
{
    var oElem,oFocus,sMsg;
    var sError="";
    var params = new Array;
    var _appliPrefix;
    if (appliId)
        _appliPrefix=_appliIdMake(appliId);

    if (inputCheck)
    {
        for(var sCtr in this.tUtils)
        {
            oElem=this.tUtils[sCtr];
    //      if (sForm != null && oElem.src.form != sForm) continue;
            if (_appliPrefix && !_appliIdMatch(sCtr,_appliPrefix))
                continue;
            if(sMaj && oElem.maj[sMaj]==null) continue;
            sMsg=this.CheckVal(oElem.src);
            if(sMsg && !sError)
            {
                sError=sMsg;
                oFocus=oElem.src;
            }
        }
    }
    if(sError)
    {
        bosClickDone();
        alert(this.ReplParamSep(sError));
        _FldFocus(oFocus);
        return false;
    }
//  alert("posting form "+sForm.id);
    sForm.submit();

    return 'nochange';
}

function _RemoveFields(appliId)
{
    var _appliPrefix;
    if (appliId)
        _appliPrefix=_appliIdMake(appliId);
    var newArray = new Array;
    for(var sCtr in this.tUtils)
    {
        if (_appliPrefix && _appliIdMatch(sCtr,_appliPrefix))
            continue;
        oElem=this.tUtils[sCtr];
        newArray[sCtr] = oElem;
    }

    this.tUtils = newArray;

    newArray = new Array;
    for(var sCtr in this.tHiddens)
    {
        if (_appliPrefix && _appliIdMatch(sCtr,_appliPrefix))
            continue;
        oElem=this.tHiddens[sCtr];
        newArray[sCtr] = oElem;
    }

    this.tHiddens = newArray;
}

function _SendRemoteScr(sForm,appliId,remoteFrm,remoteUrl,inputCheck,sMaj)
{
    var oElem,oFocus,sMsg;
    var sError="",limReached=false;
    var params="";
    var _appliPrefix;
    if (appliId)
        _appliPrefix=_appliIdMake(appliId);

    for(var sCtr in this.tHiddens)
    {
        oElem=this.tHiddens[sCtr];
//      if (sForm != null && oElem.src.form != sForm) continue;
        if (_appliPrefix && !_appliIdMatch(sCtr,_appliPrefix))
            continue;
        if(sMaj && oElem.maj[sMaj]==null) continue;
        if (!oElem.src.name)
            continue;
        params += "&" + oElem.src.name + '=' + EprEscape(oElem.src.value);
    }

    for(var sCtr in this.tUtils)
    {
        oElem=this.tUtils[sCtr];
//      if (sForm != null && oElem.src.form != sForm) continue;
        if (_appliPrefix && !_appliIdMatch(sCtr,_appliPrefix))
            continue;
        if(sMaj && oElem.maj[sMaj]==null) continue;
        if (inputCheck)
        {
            sMsg=this.CheckVal(oElem.src);
            if(sMsg && !sError)
            {
                sError=sMsg;
                oFocus=oElem.src;
            }
        }
        if (!oElem.src.name)
            continue;
        if (sError)
            continue;
        var arg = "&" + oElem.src.name + '=' + EprEscape(this.GetEleVal(oElem));
        if (arg.length + params.length > 1700)
        {
            limReached = true;
            continue;
        }
        params += arg;
    }

    remoteUrl += params;
//  alert(params);
    if (limReached)
    {
        alert("Warning: Data to post exceeds size limit !");
    }


    if(sError)
    {
        bosClickDone();
        alert(this.ReplParamSep(sError));
        _FldFocus(oFocus);
        return false;
    }

    var frm = document.getElementById(remoteFrm);
    if (!frm)
    {
        bosClickDone();
        alert("Remote frame '"+remoteFrm+"' not found !");
        return false;
    }
    //alert("Remote url="+remoteUrl);

    frm.src = remoteUrl;

    return 'nochange';
}

function _ExecuteResponse(retobj,url)
{
    var ret;
    if (typeof(retobj) == 'string')
        ret = retobj;
    else
        ret = retobj.return_value;
//  alert('rs: '+ret);
    if (ret == 'nochange')
        return;
    if (ret == 'done')
    {
        if (typeof(url) != 'undefined' && url !='')
            bosPageLoad(url);
        return;
    }
    var pos = ret.indexOf(':');
    if (pos < 0)
    {
        alert('Unknown remote script response: '+ret);
        return;
    }

    var opval=ret.substr(pos+1);
    var opname=ret.substr(0,pos);

    if (opname=='url')
    {
        bosPageLoad(opval);

        return;
    }

    alert('Unknown remote script response(2): '+ret);
}

function _CheckVal(Obj)
{
    var sObj=(typeof(Obj)=="object" ? Obj.id : Obj);
    var oElem=this.tUtils[sObj];
    var sMsg="";
    if(oElem==null) return "";
    if(oElem.check==null) return "";
    if(oElem.sw.TR || oElem.sw.TR==null)
        oElem.src.value=oElem.src.value.replace(/(^\s+|\s+$)/g,"");
    if(oElem.src.value)
        sMsg=oElem.check();
    else if(!oElem.sw.NULL)
        sMsg="fieldValueRequired";
    this.FldError(oElem,sMsg);
    return sMsg;
}
function _FldError(oElem,errmsg)
{
    oElem.src.className=(errmsg ? this.sty.err : oElem.defaultClass);

    if(oElem.sw && oElem.sw.TI)
        return;

    if (errmsg)
        oElem.src.title = this.ReplParamSep(errmsg);
    else
    {
        if (errmsg)
            oElem.src.title = errmsg;
        else
            oElem.src.title = "";
    }
    var divErrId = 'fldErr_'+oElem.src.id;
    var divErr = document.getElementById(divErrId);
    if (!divErr)
    {
        if (divErrId.substr(divErrId.length - 7) == '-handly')
        {
            divErrId = divErrId.substr(0, divErrId.length - 7);
            divErr = document.getElementById(divErrId);
        }
    }
    if (!divErr)
    {
//      if (errmsg)
//          alert(divErrId + " not found (PutError) !");
        return;
    }
    if (errmsg)
    {
        divErr.innerHTML="<img src='"+this.errorIco+"' border=0>";
        divErr.title = oElem.src.title;
    }
    else
    {
        divErr.innerHTML="";
        divErr.title = "";
    }
}

function _FldFocus(sObj)
{
    try
    {
        if (typeof(sObj)=="object")
        {
            if (sObj.focus)
            {
                sObj.focus();
                return true;
            }
            if (sObj.scrollIntoView)
            {
                sObj.scrollIntoView();
                return true;
            }
            return false;
        }
        var obj = document.getElementById(sObj+"-handly");
        if (obj)
            return _FldFocus(obj);
        obj = document.getElementById(sObj);
        if (!obj)
            return false;
        return _FldFocus(obj);
    }
    catch(e)
    {
        return false;
    }
}
function _PutError(Obj,errmsg)
{
    var sObj=(typeof(Obj)=="object" ? Obj.id : Obj);
    var oElem=this.tUtils[sObj];
    var sMsg="";
    if(oElem==null)
    {
        oElem = this.tUtils[sObj+"-handly"];
        if(oElem==null)
        {
            var divErrId = 'fldErr_'+sObj;
            var divErr = document.getElementById(divErrId);
            var divErrInp = document.getElementById(sObj);
            if (divErrInp)
            {
                divErrInp.className = "bos_fielderror";
                divErrInp.title = errmsg;
            }
            if (!divErr)
            {
//              if (errmsg && !divErrInp)
//                  alert(divErrId + " not found (PutError) !");
                return null;
            }
            if (errmsg)
            {
                divErr.innerHTML="<img src='"+this.errorIco+"' border=0>";
                divErr.title = errmsg;
            }
            else
            {
                divErr.innerHTML="";
                divErr.title = "";
            }

            return null;
        }
    }
    this.FldError(oElem,errmsg);
    return oElem;
}

function _PutModified(Obj)
{
    var sObj=(typeof(Obj)=="object" ? Obj.id : Obj);
    var oElem=this.tUtils[sObj];
    if(oElem==null)
    {
        oElem = this.tUtils[sObj+"-handly"];
        if(oElem==null)
        {
            var divErrId = 'fldErr_'+sObj;
            var divErr = document.getElementById(divErrId);
            if (!divErr)
            {
                return null;
            }

            if (this.modifiedIco)
                divErr.innerHTML="<img src='"+this.modifiedIco+"' border=0>";
            else
                divErr.innerHTML="";
            divErr.title = "Modified";
            return null;
        }
    }

    var divErrId = 'fldErr_'+oElem.src.id;
    var divErr = document.getElementById(divErrId);
    if (!divErr)
        return null;

    if (this.modifiedIco)
        divErr.innerHTML="<img src='"+this.modifiedIco+"' border=0>";
    else
        divErr.innerHTML="";
    divErr.title = "Modified";
    return oElem;
}

function _checkChampNumeric()
{
    var tRes=this.src.value.match(/^([+-]?)(\d+)([.,]?)(\d*)$/);
    var iTmp;
    if(!tRes) return "fieldNumStringInvalidNoArg";
    if(this.sgn && (tRes[1]=="-")!=(this.sgn=="-")) return "fieldNumSignInvalid";
    if(tRes[2].length>this.len) return "fieldNumStringInvalid@"+this.layout;
    if(tRes[3])
    {
        if(tRes[3].charAt(0)!=this.locale.numSep) return "fieldNumStringInvalid@"+this.layout;
        if(tRes[4].length>this.dec) return "fieldNumStringInvalid@"+this.layout;
    }
    iTmp=parseFloat(this.fctToScr(this.src.value));
    if( this.min && (iTmp<parseFloat(this.min)) ) return "fieldNumNotInRange@"+this.limits;
    if( this.max && (iTmp>parseFloat(this.max)) ) return "fieldNumNotInRange@"+this.limits;
    return "";
}

function _checkChampDate()
{
    var sValeur=this.locale.DateFromScr(this.src.value);
    if(!sValeur) return "fieldDateStringInvalid";
    if(!this.locale.DateCheck(sValeur))
        return "fieldDateInvalid";
    if(this.min && (this.locale.DateCmp(sValeur,this.min)==-1)) return "fieldDateNotInRange@"+this.limits;
    if(this.max && this.locale.DateCmp(sValeur,this.max)==1) return "fieldDateNotInRange@"+this.limits;
    return "";
}

function _checkChampTime()
{
    var sValeur=this.locale.TimeFromScr(this.src.value);
    if(!sValeur) return "fieldTimeStringInvalid@"+this.src.value;
    if(!this.locale.TimeCheck(sValeur))
        return "fieldTimeInvalid";
    if(this.min && this.locale.TimeCmp(sValeur,this.min)==-1) return "fieldTimeNoInRange@"+this.limits;
    if(this.max && this.locale.TimeCmp(sValeur,this.max)==1) return "fieldTimeNoInRange@"+this.limits;
    return "";
}

function _checkChampPass()
{
    if(this.len < this.src.value.length) return "fieldValueTooLong@"+this.len;
    //if((this.src.value.length-3)<0) return "fieldValueTooLittle@3";
    var tRes;
    if(this.src.value!=""&&this.limits>0)
    {

        tRes=this.src.value.match( /(\d{1})/g );

        if(!tRes) {return "fieldPasswordWithoutNum@"+this.limits;}
        else
            if(tRes.length<this.limits) {return "fieldPasswordWithoutNum@"+this.limits;}
    }
    if(this.sw.UC) this.src.value=this.src.value.toUpperCase();
    else if(this.sw.LC) this.src.value=this.src.value.toLowerCase();
    return "";
}

function _checkChampText()
{
/*  if(this.len < this.src.value.length) return "fieldValueTooLong@"+this.len;*/
    if(this.sw.UC) this.src.value=this.src.value.toUpperCase();
    else if(this.sw.LC) this.src.value=this.src.value.toLowerCase();
    var tRes=this.src.value.match( /(\|+|\§+|\#+|\~+)|\µ+/g );
    if(!tRes)
    {
        tRes = -1;
        var exclChs = this.sw.EX.split(",");
        for(var iex in exclChs)
        {
            if (exclChs[iex] && (tRes = this.src.value.indexOf(EprUnescape(exclChs[iex])))>=0)
                break;
        }
        if (tRes < 0)
            return "";
    }

    var ret = "fieldCharForbidden@|,§,#,~,µ";
    if (this.sw.EX && this.sw.EX != "")
    {
        ret += ","+EprUnescape(this.sw.EX);
    }
    return ret;
}


function _checkChampScript()
{
    if (this._editor != null)
    {
        this.src.value = this._editor.getHTML();
    }
    if(this.len < this.src.value.length) return "fieldValueTooLong@"+this.len;
    if(this.sw.UC) this.src.value=this.src.value.toUpperCase();
    else if(this.sw.LC) this.src.value=this.src.value.toLowerCase();
    return "";
}

function _checkChampFmt()
{
/*  if(this.len < this.src.value.length) return "fieldValueTooLong@"+this.len;*/
    if(this.sw.UC) this.src.value=this.src.value.toUpperCase();
    else if(this.sw.LC) this.src.value=this.src.value.toLowerCase();
    var tRes=this.src.value.match( /\µ+/g );
    if(!tRes)
    {
        tRes = -1;
        var exclChs = this.sw.EX.split(",");
        for(var iex in exclChs)
        {
            if (exclChs[iex] && (tRes = this.src.value.indexOf(EprUnescape(exclChs[iex])))>=0)
                break;
        }
        if (tRes < 0)
            return "";
    }
    var ret = "fieldCharForbidden@µ";
    if (this.sw.EX && this.sw.EX != "")
    {
        ret += ","+EprUnescape(this.sw.EX);
    }
    return ret;
}

//MMM
function _checkChampID()
{
    var tRes=this.src.value.match(/^[A-Za-z_]([0-9A-Za-z_]+)$/);
    if(!tRes) return "fieldCharForbidden@"+this.src.value;

/*  if(this.len < this.src.value.length) return "fieldValueTooLong@"+this.len;*/

    if(this.sw.UC) this.src.value=this.src.value.toUpperCase();
    else if(this.sw.LC) this.src.value=this.src.value.toLowerCase();

    tRes = -1;
    var exclChs = this.sw.EX.split(",");
    for(var iex in exclChs)
    {
        if (exclChs[iex] && (tRes = this.src.value.indexOf(EprUnescape(exclChs[iex])))>=0)
            break;
    }
    if (tRes < 0)
        return "";
    var ret = "fieldCharForbidden@"+this.src.value.charAt(tRes);
    return ret;
}

//MMM
function _checkChampIN()
{
    var tRes=this.src.value.match(/^([0-9A-Za-z =@._-]+)$/);
    if(!tRes) return "fieldCharForbidden@"+this.src.value;

/*  if(this.len < this.src.value.length) return "fieldValueTooLong@"+this.len;*/

    if(this.sw.UC) this.src.value=this.src.value.toUpperCase();
    else if(this.sw.LC) this.src.value=this.src.value.toLowerCase();

    tRes = -1;
    var exclChs = this.sw.EX.split(",");
    for(var iex in exclChs)
    {
        if (exclChs[iex] && (tRes = this.src.value.indexOf(EprUnescape(exclChs[iex])))>=0)
            break;
    }
    if (tRes < 0)
        return "";
    var ret = "fieldCharForbidden@"+this.src.value.charAt(tRes);
    return ret;
}

function _checkChampIP()
{
    var tRes=this.src.value.match(/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/);
    if(!tRes) return "fieldIPinvalid";
    for(iCtr=1; iCtr<=4; iCtr++)
        if(tRes[iCtr]>255) return "fieldIPinvalid";
    return "";
}

function _checkChampMail()
{
    var tRes=this.src.value.match(/^([0-9A-Za-z._-]+)@([0-9A-Za-z._-]+)$/);
    if(!tRes) return "fieldMailInvalid";
    if(this.sw.UC) this.src.value=this.src.value.toUpperCase();
    else if(this.sw.LC) this.src.value=this.src.value.toLowerCase();
    return "";
}

function _checkChampBoolean()
{
    if(this.sw.UC) this.src.value=this.src.value.toUpperCase();
    else if(this.sw.LC) this.src.value=this.src.value.toLowerCase();
    var bFound=false;
    for(var iCtr=0; !bFound && iCtr<this.items.length; iCtr++)
        if(this.items[iCtr]==this.src.value) bFound=true;
    if(!bFound) return "fieldBoolInvalid@"+this.layout;
    return "";
}

function _checkChampList()
{
    if(this.sw.UC) this.src.value=this.src.value.toUpperCase();
    else if(this.sw.LC) this.src.value=this.src.value.toLowerCase();
    var bFound=false;
    for(var iCtr=0; !bFound && iCtr<this.items.length; iCtr++)
        if(this.items[iCtr]==this.src.value) bFound=true;
    if(!bFound) return "fieldListValueInvalid@"+this.items;
    return "";
}

// <---  Functions de contrôle et affichage --->

function _ClearScr(sForm,sMaj)
{
    for(var sCtr in this.tUtils)
    {
        var oElem=this.tUtils[sCtr];
        if (sForm != null && oElem.src.form != sForm) continue;
        if(sMaj && oElem.maj[sMaj]==null) continue;
        this.ClearVal(oElem.src);
    }
}

function _ClearVal(Obj)
{
    var sObj=(typeof(Obj)=="object" ? Obj.id : Obj);
    var oElem=this.tUtils[sObj];
    if(oElem==null) return 1;
    oElem.src.value=(((oElem.fctToScr)&&(oElem.typ!="P")) ? oElem.fctToScr(oElem.defaultValue,oElem.Info) : oElem.defaultValue);
    this.FldError(oElem);
    return 0;
}

function _ResetScr(sForm,sMaj)
{
    for(var sCtr in this.tUtils)
    {
        var oElem=this.tUtils[sCtr];
        if (sForm != null && oElem.src.form != sForm) continue;
        if(sMaj && oElem.maj[sMaj]==null) continue;
        if (oElem.src.readOnly && oElem.src.readOnly==true) continue;
        this.ResetVal(oElem.src);
    }
}

function _ResetVal(Obj)
{
    var sObj=(typeof(Obj)=="object" ? Obj.id : Obj);
    var oElem=this.tUtils[sObj];
    if(oElem==null) return 1;
    oElem.src.value="";
    this.FldError(oElem);
    return 0;
}

function _PutScr(sForm,sMaj,sSrc)
{
    var sCtr,iIndice,oElem,sValeur;
    var tValeurs=sSrc.split("|");
    for(var sCtr in this.tUtils)
    {
        oElem=this.tUtils[sCtr];
        if (sForm != null && oElem.src.form != sForm) continue;
        if(sMaj && oElem.maj[sMaj]==null) continue;
        iIndice=oElem.maj[sMaj];
        sValeur=(iIndice<tValeurs.length ? tValeurs[iIndice] : "");
        this.PutVal(oElem.src,sValeur);
    }
}

function _PutVal(Obj,sValeur)
{
    var sObj=(typeof(Obj)=="object" ? Obj.id : Obj);
    var oElem=this.tUtils[sObj];
    if(oElem==null) return 1;
    sValeur+="";
    if(oElem.sw.TR==null || oElem.sw.TR)
        sValeur=sValeur.replace(/(^\s+|\s+$)/g,"");
    if(oElem.sw.UC)
        sValeur=sValeur.toUpperCase();
    else if(oElem.sw.LC)
        sValeur=sValeur.toLowerCase();
    oElem.src.value=(oElem.fctToScr ? oElem.fctToScr(sValeur,oElem.Info) : sValeur);
    this.FldError(oElem);
    return 0;
}

function _GetScr(sForm,sMaj,iLen)
{
    var oElem;
    var tValeurs=[];
    if(iLen!=null) tValeurs.length=iLen;
    for(var sCtr in this.tUtils)
    {
        oElem=this.tUtils[sCtr];
        if (sForm != null && oElem.src.form != sForm) continue;
        if(sMaj && oElem.maj[sMaj]==null) continue;
        iIndice=oElem.maj[sMaj];
        tValeurs[iIndice]=this.GetEleVal(oElem);
    }
    return tValeurs.join("|");
}

function _GetVal(Obj)
{
    var sObj=(typeof(Obj)=="object" ? Obj.id : Obj);
    var oElem=this.tUtils[sObj];
    if(oElem==null) return "";
    return _GetEleVal(oElem);
}

function _GetEleVal(oElem)
{
    if (oElem._editor != null)
    {
        oElem.src.value = oElem._editor.getHTML();
    }
    if(oElem.sw.TR || oElem.sw.TR==null)
        oElem.src.value=oElem.src.value.replace(/(^\s+|\s+$)/g,"");
    if(oElem.sw.UC)
        oElem.src.value=oElem.src.value.toUpperCase();
    else if(oElem.sw.LC)
        oElem.src.value=oElem.src.value.toLowerCase();

    if(oElem.fctFromScr){  r = oElem.fctFromScr(oElem.src.value,oElem.Info)}
    else{r = oElem.src.value}
    return r;
}

function _LockScr(sForm,sMaj,bVal)
{
    var oElem;
    for(var sCtr in this.tUtils)
    {
        oElem=this.tUtils[sCtr];
        if (sForm != null && oElem.src.form != sForm) continue;
        if(sMaj && oElem.maj[sMaj]==null) continue;

        this.LockVal(oElem.src,bVal);
        this.FldError(oElem);
    }
}

function _LockVal(oObj,bVal)
{
    if(bVal!=null)
    {
        if(oObj.readOnly=bVal)
        {
            oObj.className=this.sty.loc;
            oObj.blur();
        }
        else
        {
            oObj.className=this.sty.txt;
        }
    }
    return oObj.readOnly;
}

function _ActifScr(sForm,sMaj,bVal)
{
    var oElem;
    for(var sCtr in this.tUtils)
    {
        oElem=this.tUtils[sCtr];
        if (sForm != null && oElem.src.form != sForm) continue;
        if(sMaj && oElem.maj[sMaj]==null) continue;
        this.ActifVal(this.tUtils[sCtr].src,bVal);
    }
}

function _ActifVal(oObj,bVal)
{
    if(bVal!=null)
    {
        if(oObj.disabled=!bVal)
            oObj.className=this.sty.loc;
        else
            oObj.className=(oObj.type && oObj.type=="text" ? this.sty.txt : this.sty.lst);
    }
    return !oObj.disabled;
}

function _LstClear(oSel)
{
    while(oSel.options.length>0) oSel.remove(0);
}

function _LstAdd(oSel,sValue,sText)
{
    if(sText==null)
        oSel.options.add(new Option(sValue,sValue));
    else
        oSel.options.add(new Option(sText,sValue));
}

function _LstAddAll(oSel,sParam)
{
    var tOptions=sParam.split("§");
    var iCtr,tValeurs;
    for(iCtr=0; iCtr<tOptions.length; iCtr++)
    {
        tValeurs=tOptions[iCtr].split("|");
        this.LstAdd(oSel,tValeurs[0],tValeurs[1]);
    }
}

//  ==========
//  <--- gestion des messages et libellés suivant les langues --->
//  ==========

function _ReplParam(iIndexMsg)
{
    var sReturn;
    try
    {
        sReturn=eval("msgLang_"+iIndexMsg);
    }
    catch(e)
    {
        sReturn=iIndexMsg;
    }
    if(sReturn==null) return "["+iIndexMsg+"]";
    for(var iCtr=arguments.length-1; iCtr>=1; iCtr--)
        sReturn=sReturn.replace(new RegExp("&&"+iCtr),arguments[iCtr]);
    return sReturn;
}

function _ReplParamSep(sMsg)
{
    var tMsgs=sMsg.split("@");
    var sReturn;
    try
    {
        sReturn=eval("msgLang_"+tMsgs[0]);
    }
    catch(e)
    {
        sReturn=tMsgs[0];
    }
    if(sReturn==null) return "["+sMsg+"]";
    for(var iCtr=tMsgs.length-1; iCtr>=1; iCtr--)
        sReturn=sReturn.replace(new RegExp("&&"+iCtr),tMsgs[iCtr]);
    return sReturn;
}

function _SrvError(Obj,epr)
{
    var sObj=""+(typeof(Obj)=="object" ? Obj.return_value : Obj);
    //MMM 2003/4/4
    if (sObj == "" && Obj.message && Obj.message != "")
    {
        if (Obj.message.indexOf("$flderror|") == 0)
        {
            var fldname = Obj.message.substr(10);
            var pos = fldname.indexOf("|");
            if (pos >= 0)
            {
                var txt=fldname.substr(pos+1);
                fldname = fldname.substr(0,pos);
                if (txt.substr(0,1) == "@")
                    txt = this.ReplParamSep(txt.substr(1));
                else if (epr)
                    txt = txt.replace("&&0",epr.GetVal(fldname));

                var oElem;
                if (epr)
                    oElem = epr.PutError(fldname,txt);

                alert(txt);
                if (oElem)
                    epr.FldFocus(oElem.src);

                return 1;
            }
        }
        alert(Obj.message+"\n\n[Call to remote script has failed !]");
        return 1;
    }
    sObj=sObj.replace(/\n/g,"\\n");
    var tRes=sObj.match(/^@ERR@(ID@)?(.*)$/);
    if(!tRes) return 0;
    tRes[2]=tRes[2].replace(/\\n/g,"\n");
    var sReturn;
    if(tRes[1])
        sReturn=this.ReplParamSep(tRes[2]);
    else
        sReturn=tRes[2];
    alert(sReturn);
    return 1;
}

function _SrvMessage(iMsg)
{
    var sReturn;
    if(iMsg==1)
    {
        sReturn="E_Process - Load...";
    }
    else if(iMsg==2)
    {
        sReturn="E_Process - Ready...";
    }
    window.defaultStatus=sReturn;
    return sReturn;
}

//  =====
//  <--- Objet ´Locale´ : gère les conversions de date, heure, chiffres... --->
//  =====

function _loc(sFormats,sLibs)
{
    this.SetLocale=_SetLocale;

// Date functions
    this.DateCheck=_DateCheck;
    this.DateFromScr=_DateFromScr;
    this.DateToScr=_DateToScr;
    this.DateCmp=_DateCmp;
    this.DateDif=_DateDif;
    this.DateAdd=_DateAdd;
// Time functions
    this.TimeCheck=_TimeCheck;
    this.TimeFromScr=_TimeFromScr;
    this.TimeToScr=_TimeToScr;
    this.TimeCmp=_TimeCmp;
// Number functions
    this.NumberFromScr=_NumberFromScr;
    this.NumberToScr=_NumberToScr;
    this.NumberCmp=_NumberCmp;
    this.NumberCalc=_NumberCalc;

    this.SetLocale(sFormats,sLibs);
}

function _SetLocale(sFormats,sLibs)
{
    var tRes; //=sFormats.match( /^([DMY]{3})([./-]?)@([.:-]?)@([.,])$/ );
    if(!tRes)
        tRes=["","DMY","/",":","."];
    this.dat={};
    this.dat.D=tRes[1].indexOf("D");
    if(this.dat.D<0) return "2";
    this.dat[this.dat.D]=0;
    this.dat.M=tRes[1].indexOf("M");
    if(this.dat.M<0) return "3";
    this.dat[this.dat.M]=1;
    this.dat.Y=tRes[1].indexOf("Y");
    if(this.dat.Y<0) return "4";
    this.dat[this.dat.Y]=2;
    this.datSep=tRes[2];
    this.timSep=tRes[3];
    this.numSep=tRes[4];

    var tLibs=sLibs.split("@");
    if(tLibs.length<3)
        this.FmtDate="DD/MM/YYYY";
    else
        this.FmtDate=tLibs[this.dat[0]]+this.datSep+tLibs[this.dat[1]]+this.datSep+tLibs[this.dat[2]];
    if(tLibs.length<5)
        this.FmtTime="HH:MM";
    else
        this.FmtTime=tLibs[3]+this.timSep+tLibs[4];

    return "";
}

function _DateCheck(sSrc)
{
    var tDat=sSrc.match( /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/ );
    if(!tDat) return "";
    var dt=new Date(tDat[3],tDat[2]-1, tDat[1]);
    if(dt.getDate() != tDat[1]-0) return "";
    if(dt.getMonth() != tDat[2]-1) return "";
    if(dt.getFullYear() != tDat[3]) return "";
    return sSrc;
}

function _DateFromScr(sSrc)
{
    var tRes;
    if(this.datSep)
    {
        switch(this.dat.Y)
        {
            case 0:  tRes=sSrc.match(/^(\d{4})(\D)(\d{1,2})(\D)(\d{1,2})$/); break;
            case 1:  tRes=sSrc.match(/^(\d{1,2})(\D)(\d{4})(\D)(\d{1,2})$/); break;
            default: tRes=sSrc.match(/^(\d{1,2})(\D)(\d{1,2})(\D)(\d{4})$/); break;
        }
        if(!tRes || tRes[2]!=this.datSep || tRes[4]!=this.datSep) return "";
        return tRes[this.dat.D*2+1]+"/"+tRes[this.dat.M*2+1]+"/"+tRes[this.dat.Y*2+1];
    }

    switch(this.dat.Y)
    {
        case 0:  tRes=sSrc.match(/^(\d{4})(\d{2})(\d{2})$/); break;
        case 1:  tRes=sSrc.match(/^(\d{2})(\d{4})(\d{2})$/); break;
        default: tRes=sSrc.match(/^(\d{2})(\d{2})(\d{4})$/); break;
    }
    if(!tRes) return "";
    return tRes[this.dat.D+1]+"/"+tRes[this.dat.M+1]+"/"+tRes[this.dat.Y+1];
}

function _DateToScr(sSrc)
{
    var tRes=sSrc.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/);
    if(!tRes) return "";
    if(tRes[1].length<2) tRes[1]="0"+tRes[1];
    if(tRes[2].length<2) tRes[2]="0"+tRes[2];
    return tRes[this.dat[0]+1]+this.datSep+tRes[this.dat[1]+1]+this.datSep+tRes[this.dat[2]+1];
}

function _DateCmp(sDat1,sDat2)
{
    var tDat1=sDat1.match( /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/ );
    if(!tDat1) return "";
    var tDat2=sDat2.match( /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/ );
    if(!tDat2) return "";
    var dt1=new Date(tDat1[3], tDat1[2]-1, tDat1[1]);
    var dt2=new Date(tDat2[3], tDat2[2]-1, tDat2[1]);
    if(dt1>dt2) return 1;
    if(dt1<dt2) return -1;
    return 0;
}

function _DateDif(sDat1,sDat2)
{
    var t3;

    var tDat1=sDat1.match( /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/ );
    if(!tDat1) return "";
    var tDat2=sDat2.match( /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/ );
    if(!tDat2) return "";
    var dt1=new Date(tDat1[3], tDat1[2]-1, tDat1[1]);
    var dt2=new Date(tDat2[3], tDat2[2]-1, tDat2[1]);

    var MinMilli = 1000 * 60
    var HrMilli = MinMilli * 60
    var DyMilli = HrMilli * 24
    t3 = dt2-dt1;
    r = Math.round(t3 / DyMilli);
    return r;
}

function _DateAdd(sDat1,sNum)
{
    var tDat1=sDat1.match( /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/ );
    if(!tDat1) return "";
    if(!sNum) return "";

    var dt1=new Date(tDat1[3], tDat1[2]-1, tDat1[1]);

    daysup = new Number(tDat1[1])
    sNum = new Number(sNum);
    r2 = (daysup+sNum);

    var dt2=new Date(tDat1[3], tDat1[2]-1, r2);
    r = dt2.getDate()+"/"+(dt2.getMonth()+1)+"/"+dt2.getUTCFullYear();
    return(r);
}

function _TimeCheck(sSrc)
{
    var tRes=sSrc.match(/^(\d{1,2}):(\d{2})$/);
    if(!tRes) return "";
    if(tRes[1]-0>23) return "";
    if(tRes[2]-0>59) return "";
    return sSrc;
}

function _TimeFromScr(sSrc)
{
    var tRes;
    if(this.timSep)
    {
        tRes=sSrc.match(/^(\d{1,2})(\D)(\d{2})$/);
        if(!tRes || tRes[2]!=this.timSep) return "";
        if(tRes[1].length<2) tRes[1]="0"+tRes[1];
        return tRes[1]+":"+tRes[3];
    }

    tRes=sSrc.match(/^(\d{2})(\d{2})$/);
    if(!tRes) return "";
    return tRes[1]+":"+tRes[2];
}

function _TimeToScr(sSrc)
{
    var tRes=sSrc.match(/^(\d{1,2})\D(\d{2})$/);
    if(!tRes) return "";
    if(tRes[1].length<2) tRes[1]="0"+tRes[1];
    return tRes[1]+this.timSep+tRes[2];
}

function _TimeCmp(sTim1,sTim2)
{
    var tTim1=sTim1.match( /^(\d{1,2}):(\d{2})$/ );
    if(!tTim1) return "";
    var tTim2=sTim2.match( /^(\d{1,2}):(\d{2})$/ );
    if(!tTim2) return "";
    if(tTim1[1]-0<tTim2[1]-0) return -1;
    if(tTim1[1]-0>tTim2[1]-0) return 1;
    if(tTim1[2]-0<tTim2[2]-0) return -1;
    if(tTim1[2]-0>tTim2[2]-0) return 1;
    return 0;
}

function _NumberFromScr(sSrc)
{
    var tRes=sSrc.match( /^([+-]?\d+)(\D?)(\d*)$/ );
    if(!tRes || (tRes[2] && tRes[2]!=this.numSep)) return "";
    return tRes[1]+(tRes[2]?"."+tRes[3]:"");
}

function _NumberCmp(sNum1,sNum2)
{
    if(sNum1-0==sNum2-0) return 0;
    else if(sNum1-0<sNum2-0) return -1;
    return 1;
}

function _NumberCalc(sFormul,iDeci)
{
var sReturn=sFormul;
    var cCar;
    for(var iCtr=2; iCtr<arguments.length && iCtr<26; iCtr++)
    {
        cCar=String.fromCharCode(63+iCtr);
        var RegString = new RegExp(cCar,"g");
        sReturn=sReturn.replace(RegString,arguments[iCtr]);
    }
    if(sReturn.match(/[A-Z]/)) return "";
    iDeci = Math.pow(10,eval(iDeci));
    return (eval((Math.round(eval(sReturn) * iDeci))/iDeci));
}

function _NumberToScr(sSrc)
{
    sSrc = new String(sSrc);
    var tRes=sSrc.match( /^([+-]?\d+)(\D?)(\d*)$/ );
    if(!tRes) return "";
    return tRes[1]+(tRes[2]?this.numSep+tRes[3]:"");
}

//  =====
//  <--- Objet gen : Regroupant des fonctions utiles --->
//  =====

function _gen()
{
    this.ToSvr=_ToSvr;
    this.ToHTML=_ToHTML;
    this.FromHTML=_FromHTML;
    this.Chomp=_Chomp;
    this.IENum=_IENum;
}

function _ToSvr(sSrc)
{
    var sRet=""+sSrc;
    if(!sRet) return "";
    sRet=sRet.replace(/[\f\n\r]+/g," ");
    sRet=sRet.replace(/\\/g,"\\\\");
    sRet=sRet.replace(/"/g,'\\"');
    sRet=sRet.replace(/\+/g,"\\+");
    return sRet;
}

function _ToHTML(sSrc)
{
    var sRet=""+sSrc;
    if(!sRet) return "";
    sRet=sRet.replace(/&/g,"&amp;");
    sRet=sRet.replace(/'/g,"&rsquo");
    sRet=sRet.replace(/"/g,"&#34;");
    sRet=sRet.replace(/</g,"&lt;");
    sRet=sRet.replace(/>/g,"&gt;");
    return sRet;
}

function _FromHTML(sSrc)
{
    var sRet=""+sSrc;
    if(!sRet) return "";
    sRet=sRet.replace(/&amp;/g,"&");
    sRet=sRet.replace(/&rsquo/g,"'");
    sRet=sRet.replace(/&#34/g,'"');
    sRet=sRet.replace(/&lt;/g,"<");
    sRet=sRet.replace(/&gt;/g,">");
    return sRet;
}

function _Chomp(sSrc,sCar)
{
    sSrc+="";
    if(sCar==null || sSrc.charAt(sSrc.length-1)==sCar)
        return sSrc.slice(0,-1);
    return sSrc;
}

function _IENum()
{
    var tRes=window.navigator.appVersion.match(/;\s*msie\s*([0-9.]+)\s*;/i);
    if(!tRes) return 0;
    return parseFloat(tRes[1]);
}

// Procédure de gestion des popups -------------------------------------------------------------------->
domok = document.getElementById;
popupX = -1;
popupY = -1;
popupInfo = new Array;
popupInfoLock = false;
popupInfoTime = 0;

if (domok)
{
    if(document.all)
    {
        document.onmousemove = get_mouseIE;
        bosDebugTrace('onmousemove for IE');
    }
    else
    {
        window.addEventListener('mousemove', get_mouseStd , false);
        bosDebugTrace('onmousemove for Std');
    }
}

function get_mouseIE()
{
    try
    {
        popupX = event.clientX;
        popupY = event.clientY;
//        popupX = event.x+document.body.scrollLeft;
//        popupY = event.y+document.body.scrollTop;
//        bosDebugTrace('onmousemove for IE: '+(popupX)+','+(popupY));
    }
    catch (em)
    {
        bosDebugTrace('onmousemove for IE: error');
        //if (debugMode) alert(em);
    }

}

function get_mouseStd(e)
{
    try
    {
        popupX = e.pageX;
        popupY = e.pageY;
//        bosDebugTrace('onmousemove for Std: '+(popupX)+','+(popupY));
    }
    catch (em)
    {
        bosDebugTrace('onmousemove for Std: error');
        //if (debugMode) alert(em);
    }

}

function bosOnElementFocused(e)
{
    try
    {
        if (e && e.target)
            bos_docActiveElement =
                e.target == document ? null : e.target;
    }
    catch (em)
    {
        bosDebugTrace('bosOnElementFocused: error');
        //if (debugMode) alert(em);
    }
}

if (document.addEventListener)
    document.addEventListener("focus", bosOnElementFocused, true);

function popupLevelNo(divlevel)
{
    if (typeof(divlevel) == 'undefined')
        return 0;
    return divlevel;
}

function popupLevel(divlevel)
{
    return popupInfo[popupLevelNo(divlevel)];
}

function popupLevelAccess(divlevel)
{
    var lvlno = popupLevelNo(divlevel);
    if (lvlno < popupInfo.length-1)
        popupLevelClose(lvlno-1);

    var lvl = popupInfo[lvlno];
    if (lvl)
        return lvl;

    if (popupInfo.length != lvlno)
    {
        alert("popupLevelAccess: pb stacklg("+popupInfo.length+") != level("+lvlno+")");
        toto();
    }

    lvl = {popupDiv: null, popupAppliId:null, popupLevel:lvlno, arrWindowedCtrl:null, onPopupClose:null};
    popupInfo[lvlno] = lvl;
    return lvl;
}

function popupLevelOnClose(divlevel,fct)
{
    popupInfo[divlevel].onPopupClose = fct;
}

function popupLevelCloseAll()
{
    popupLevelClose(0);
    popupInfoLock = false;
}

function bosTimeInMs()
{
    return (new Date()).getTime();
}

function popupBodyResize()
{
    if (popupInfoTime && (bosTimeInMs() - popupInfoTime) <= 500)
        return;
    popupLevelCloseAll();
}
function divBodyResize()
{
    var div = document.getElementById("bosSite_mainDiv");
    if (div)
    {
        var div1 = document.getElementById("bosSite_mainDiv1");
        var div2 = document.getElementById("bosSite_mainDiv2");
        var winSz = bosGetWindowSize();
        var minSz = winSz.height;
        var minSzContent = 0;
        if (div1)
            minSzContent += bosGetHeight(div1);
        if (div2)
            minSzContent += bosGetHeight(div2);
        if (typeof(bosSite_footerDivHeight) != "undefined" && bosSite_footerDivHeight)
            minSzContent += bosSite_footerDivHeight;
        if (minSzContent >minSz)
            minSz = minSzContent;
        div.style.height = minSz+"px";
    }
//  if (typeof(divBodyResize2) != "undefined")
//      divBodyResize2();
}

function popupLevelClose(divlevel,nocancel)
{
    var lvlno = popupLevelNo(divlevel);
    if (lvlno < 0)
        lvlno = 0;

    if (lvlno >= popupInfo.length)
        return;

    for(var i = popupInfo.length-1; i >= lvlno; i--)
    {
        _popupLevelClose(popupInfo[i]);
    }

    var newInfo = new Array;
    for(var i = 0; i < lvlno; i++)
    {
        newInfo[i] = popupInfo[i];
    }

    popupInfo = newInfo;
    if (!nocancel)
        bosMCancel();
}

function _popupStyleHide(popupSt)
{
    popupSt.display = "none";
    popupSt.visibility = "hidden";
    popupSt.height = "0%";
}

function _popupStyleShow(popupSt)
{
    popupSt.display = "block";
    popupSt.visibility = "visible";
    popupSt.height = "";
}

function _popupLevelClose(lvl)
{
    if (lvl.popupDiv == null)
        return;
    if (lvl.popupAppliId)
    {
        Epr.RemoveFields(lvl.popupAppliId);
        lvl.popupAppliId = null;
    }
    var _popupDiv = lvl.popupDiv;
    lvl.popupDiv = null;
    _popupStyleHide(_popupDiv.style);
    _popupDiv.innerHTML = "**CLOSED**";

    _popupLevelShowWindowedCtrl(lvl);
    _popupLevelCtrlClose(lvl);
    if (lvl.onPopupClose)
    {
        lvl.onPopupClose();
        lvl.onPopupClose = null;
    }
}

function popupLevel_click(divlevel)
{
    if (popupInfoLock)
    {
        if (divlevel == 0)
        {
            bosDebugTrace("popupLevel_click lock reset");
            popupInfoLock = false;
            popupInfoTime = bosTimeInMs();
        }
        return;
    }
    popupLevelClose(divlevel);
    if (divlevel > 0)
       popupInfoLock = true;
    else
        bosDebugTrace("popupLevel_click not locked");
}

function popupLevelVisible(divlevel,divName)
{
    var lvl = popupLevel(divlevel);
    if (!lvl)
        return false;

    var _div;
    if (typeof(divName) == "string")
        _div = document.getElementById(divName);
    else
        _div = divName;

    if (!_div)
    {
        alert("popupLevelVisible, div ("+divName+"): not found");
        return false;
    }

    return lvl.popupDiv == _div;
}

function popupLevelShow(divlevel,divName,appliId)
{
    if (!domok || popupX == -1 || popupY == -1)
        return;

    var lvl = popupLevelAccess(divlevel);

    var _div;
    if (typeof(divName) == "string")
        _div = document.getElementById(divName);
    else
        _div = divName;

    if (!_div)
    {
        alert("popupLevelShow, div ("+divName+"): not found");
        return;
    }

    if (lvl.popupDiv != _div)
    {
        if (lvl.popupDiv) _popupLevelClose(lvl);
        lvl.popupDiv = _div;
    }

    var _appliId;
    if (typeof(appliId) != "undefined")
        _appliId = appliId;
    else
        _appliId = null;
    if (_appliId != lvl.popupAppliId)
    {
        if (lvl.popupAppliId) Epr.RemoveFields(lvl.popupAppliId);
        lvl.popupAppliId = _appliId;
    }

    _popupMouseAlign(_div);

    _popupStyleShow(_div.style);

    _popupLevelHideWindowedCtrl(_div,lvl,bosGetRect(_div));
}

function popupLevelPlacedShow(divlevel,divName,ctrlName,divContent,popupMode,ctrlStyle,appliId)
{
    if (!domok)
    {
        alert("Popup not supported by your browser !");
        return;
    }

    var _div;
    if (typeof(divName) == "string")
        _div = document.getElementById(divName);
    else
        _div = divName;

    if (divContent && typeof(divContent) != 'undefined' && divContent != '')
    {
        bosMsgLoadingEnd();
        if (divContent == 'default')
            _div.innerHTML = bosDefaultPopupMsg;
        else
            _div.innerHTML = divContent;
    }

    var _ctrl;
    if (typeof(ctrlName) == "string")
    {
        if (ctrlName == "mouse")
        {
            popupLevelShow(divlevel,divName,appliId);
            return;
        }
        _ctrl = document.getElementById(ctrlName);
    }
    else
        _ctrl = ctrlName;
//  alert("div ("+divName+"): "+popupInplaceDiv);
    if (!_div || !_ctrl)
    {
        alert('unknown div :'+divName+', or ctrl:'+ctrlName+' !!');
        return;
    }

    var lvl = popupLevelAccess(divlevel),newpopup;

    if (lvl.popupDiv == _div)
        newpopup = false;
    else
    {
        if (lvl.popupDiv) _popupLevelClose(lvl);
        lvl.popupDiv = _div;
        newpopup = true;
    }

    var _appliId;
    if (typeof(appliId) != "undefined")
        _appliId = appliId;
    else
        _appliId = null;
    if (_appliId != lvl.popupAppliId)
    {
        if (lvl.popupAppliId) Epr.RemoveFields(lvl.popupAppliId);
        lvl.popupAppliId = _appliId;
    }
    if (newpopup)
      _popupStyleShow(_div.style);
    _popupAlign(_div,_ctrl,popupMode);
    _popupLevelCtrl(lvl,_ctrl,ctrlStyle);
    if (newpopup)
    {
//      _popupStyleShow(_div.style);

        _popupLevelHideWindowedCtrl(_div,lvl,bosGetRect(_div));
    }
    else
    {
        popupLevelPlacedUpdate(divlevel,divName);
    }
}

function _popupMouseAlign(_div)
{
    var px = popupX+10,py = popupY+5,divAbs = bosGetAbsPosDiv(_div);

    {
        var winSz,winPx=0,winPy=0;
        if (!divAbs)
            winSz = bosGetWindowSize();
        else
        {
            var r = bosGetRect(divAbs);
            winSz = {width: r.right - r.left, height: r.bottom - r.top};
            winPx = r.left;
            winPy = r.top;
        }
        var rectPopupSz = bosGetSize(_div);
        var rectPopupWidth,rectPopupHeight;
        if (rectPopupSz)
        {
            rectPopupWidth = rectPopupSz.width;
            rectPopupHeight = rectPopupSz.height;
        }

        if (winSz && rectPopupWidth && rectPopupHeight)
        {
//            alert("Before sz: WinSz:"+winSz.width+"x"+winSz.height+", popup:"+rectPopupWidth+"x"+rectPopupHeight+", pos: x:"+px+", y:"+py);

            if (px+rectPopupWidth > winPx+winSz.width-20)
            {
                px = winPx+winSz.width-20 - rectPopupWidth;
                if(px<5)
                    px=5;
            }
            if (py+rectPopupHeight > winPy+winSz.height
                && rectPopupHeight+winPy < popupY-10)
            {
                py = popupY-10 - rectPopupHeight
            }

            // alert("After sz: WinSz:"+winSz.width+"x"+winSz.height+", popup:"+rectPopupWidth+"x"+rectPopupHeight+", pos: x:"+px+", y:"+py);
        }
    }
    bosSetXY(_div,{x:px,y:py});
}

function _popupAlign(_div,_ctrl,popupMode)
{
    var scX = 0, scY = 0, _popupMode = 0;
    if (typeof(popupMode) != "undefined")
        _popupMode = popupMode;

    var rect = bosGetRect(_ctrl);
    var rectPopup = bosGetRect(_div);
    var rectPopupWidth,rectPopupHeight;
    if (rectPopup)
    {
        rectPopupWidth = rectPopup.right - rectPopup.left;
        rectPopupHeight = rectPopup.bottom - rectPopup.top;
    }
/*  if (!rectPopupWidth)
        rectPopupWidth = 200;
    if (!rectPopupHeight)
        rectPopupHeight = 100;
*/
    {
        var px,py;
        if (_popupMode == 1)
        {
            px = rect.right+scX-5;
            py = rect.top+scY;
        }
        else
        {
            px = rect.left+scX;
            py = rect.bottom+scY;
        }
        var divAbs = bosGetAbsPosDiv(_div);
        var winSz,winPx=0,winPy=0;
        //bosDebugTrace("Before sz: divAbs="+divAbs);
        if (!divAbs)
            winSz = bosGetWindowSize();
        else
        {
            var r = bosGetRect(divAbs);
            winSz = {width: r.right - r.left, height: r.bottom - r.top};
            winPx = r.left;
            winPy = r.top;
        }
        if (winSz && rectPopupWidth && rectPopupHeight)
        {
            //bosDebugTrace("Before sz: WinSz:"+winPx+"x"+winPy+"-"+winSz.width+"x"+winSz.height+", popup:"+rectPopupWidth+"x"+rectPopupHeight+", pos: x:"+px+", y:"+py);
            if (px+rectPopupWidth > winPx+winSz.width-20)
            {
                px = rect.right+scX - rectPopupWidth;
                if(px<5)
                    px=5;
                if (_popupMode == 1)
                    py = rect.bottom+scY;
            }
            if (py+rectPopupHeight > winPy+winSz.height)
            {
                py = rect.top+scX - rectPopupHeight;
                if(py<5+winPy)
                    py=5+winPy;
            }

//          bosDebugTrace("After sz: WinSz:"+winSz.width+"x"+winSz.height+", popup:"+rectPopupWidth+"x"+rectPopupHeight+", pos: x:"+px+", y:"+py);
        }
        /*else
        {
            if (winSz)
                winSz = "{width:"+winSz.width+",height:"+winSz.height+"}";
            if (rectPopup)
                rectPopup = "{left:"+rectPopup.left+",top:"+rectPopup.top+" - right:"+rectPopup.right+",bottom:"+rectPopup.bottom+"}";
            alert("auto pos not supported : "+winSz+","+rectPopupWidth+","+rectPopupHeight+","+rectPopup);
        }*/

        bosSetXY(_div,{x:px,y:py});
    }
}

function _popupLevelCtrl(lvl,_ctrl,ctrlStyle)
{
    if (lvl.ctrl)
    {
        if (lvl.ctrl == _ctrl)
            return;
        _popupLevelCtrlClose(lvl);
    }
    if (!ctrlStyle)
        return;
//        ctrlStyle = 'background-color: green';

    lvl.ctrl = _ctrl;
    if (bos_mouseCtrl == _ctrl)
    {
        lvl.ctrlOldStyle = bos_mouseCtrlOldStyle;
        bos_mouseCtrlOldStyle = null;
    }
    else
        lvl.ctrlOldStyle = _ctrl.style.cssText;

    _ctrl.style.cssText = ctrlStyle;
}

function _popupLevelCtrlClose(lvl)
{
    if (!lvl.ctrl)
        return;
    var _ctrl = lvl.ctrl;
    lvl.ctrl = null;
    _ctrl.style.cssText = lvl.ctrlOldStyle;
}

function popupLevelPlacedHideShow(divlevel,divName,ctrlName,divContent,popupMode,ctrlStyle,appliId)
{
    if (!domok)
        return false;

    var _div;
    if (typeof(divName) == "string")
        _div = document.getElementById(divName);
    else
        _div = divName;

    if (!_div)
    {
        alert("popupLevelPlacedHideShow, div ("+divName+"): not found");
        return false;
    }

    var lvl = popupLevelAccess(divlevel);

    if (lvl.popupDiv && lvl.popupDiv == _div)
    {
        popupLevelClose(divlevel);
        return false;
    }

    popupLevelPlacedShow(divlevel,_div,ctrlName,divContent,popupMode,ctrlStyle,appliId);

/*    if (divContent && typeof(divContent) != 'undefined')
    {
        if (_div.all)
            _div.all[_div.all.length-1].scrollIntoView(false);
    }*/
//  alert('show: '+divName+':'+ctrlName);
    return true;
}

function popupLevelPlacedUpdate(divlevel,divName,appliId,ctrlName)
{
    if (!domok)
        return false;

    popupInfoTime = bosTimeInMs();

    var _div;
    if (typeof(divName) == "string")
        _div = document.getElementById(divName);
    else
        _div = divName;

    if (_div.all)
    {
        var widthMax=0,cWidth;
        for(var iCtr=0; iCtr<_div.children.length; iCtr++)
        {
            oTag=_div.children[iCtr];

            cWidth = bosGetWidth(oTag);
            if (cWidth > widthMax)
                widthMax = cWidth;
        }
        if (widthMax > 50)
            _div.style.width=widthMax;
        else
            _div.style.width="100px";
    }
    else
        _div.style.width="";

    while (ctrlName)
    {
        if (ctrlName == "mouse")
        {
            _popupMouseAlign(_div);
            break;
        }

        var _ctrl,_popupMode=0;
        if (typeof(ctrlName) == "string")
        {
            for(;;)
            {
                var spopuMode = ctrlName.substr(0,1);
                if (spopuMode == "0")
                {
                    _popupMode = 0;
                    ctrlName = ctrlName.substr(1);
                    break;
                }
                if (spopuMode == "1")
                {
                    _popupMode = 1;
                    ctrlName = ctrlName.substr(1);
                    break;
                }
                break;
            }
            _ctrl = document.getElementById(ctrlName);
        }
        else
            _ctrl = ctrlName;

        _popupAlign(_div,_ctrl,_popupMode);
        break;
    }

    var lvl = popupLevelAccess(divlevel);
    if (lvl.popupDiv != _div)
        return;

    if (typeof(appliId) != "undefined" && lvl.popupAppliId != appliId)
    {
        if (lvl.popupAppliId) Epr.RemoveFields(lvl.popupAppliId);
        lvl.popupAppliId = appliId;
    }

    var oldArrWindowedCtrl = lvl.arrWindowedCtrl;
    lvl.arrWindowedCtrl = null;
    _popupLevelHideWindowedCtrl(_div,lvl,bosGetRect(_div));

    var oTag,found;
    for(var iCtr=0; iCtr<oldArrWindowedCtrl.length; iCtr++)
    {
        oTag = oldArrWindowedCtrl[iCtr];
        found = false;
        for(var iCtr2=0; iCtr2<lvl.arrWindowedCtrl.length; iCtr2++)
        {
            if (oTag == lvl.arrWindowedCtrl[iCtr2])
            {
                found = true;
                break;
            }
        }
        if (found)
            continue;

        oTag.style.visibility = 'visible';
    }
//  if (_div.all)
//      _div.all[_div.all.length-1].scrollIntoView(false);
    //alert('scroll into view - '+_div.getBoundingClientRect().top + ' - '+ _div.getBoundingClientRect().bottom);
}

function _popupLevelHideWindowedCtrl(div,lvl,rect)
{
    if (lvl.arrWindowedCtrl != null)
    {
        _popupLevelShowWindowedCtrl(lvl)
    }

    lvl.arrWindowedCtrl = new Array();

    return;
    var ix = 0;
    for(var sCtr in Epr.tUtils)
    {
        var oElem=Epr.tUtils[sCtr];
        var oTag = oElem.src;
        if(typeof(oTag.type) == 'undefined' || oTag.type.indexOf('select') < 0)
            continue;
        var crect = bosGetRect(oTag);

        if (rect.top >= crect.bottom ||  rect.bottom < crect.top
            || rect.left >= crect.right ||  rect.right < crect.left)
            continue;
        var par = oTag.parentElement;
        while(par)
        {
            if (par == div)
                break;
            par = par.parentElement;
        }
        if (par)
            continue;

        lvl.arrWindowedCtrl[ix] = oTag;
        oTag.style.visibility = 'hidden';
        ix++;
    }

/*  var oTag,txt = '';
    if (document.all)
    {
        for(var iCtr=0, ix = 0; iCtr<document.all.length; iCtr++)
        {
            oTag=document.all[iCtr];
            if(typeof(oTag.type) == 'undefined' || oTag.type.indexOf('select') < 0)
            {
    //          txt += ',' + oTag.id + ':' +oTag.type;
                continue;
            }

            var crect = bosGetRect(oTag);

            if (rect.top >= crect.bottom ||  rect.bottom < crect.top
                || rect.left >= crect.right ||  rect.right < crect.left)
                continue;
            if (oTag.style.visibility != 'visible' && oTag.style.visibility != '')
                continue;
            var par = oTag.parentElement;
            while(par)
            {
                if (par == div)
                    break;
                par = par.parentElement;
            }
            if (par)
                continue;

            lvl.arrWindowedCtrl[ix] = oTag;
            oTag.style.visibility = 'hidden';
            ix++;
        }
    }
    else
    {
        var body = document.getElementById("bosbody");

        for(var iCtr=0; iCtr<body.length; iCtr++)
        {
            oTag=body.Item(iCtr);
            if(typeof(oTag.type) == 'undefined' || oTag.type.indexOf('select') < 0)
            {
    //          txt += ',' + oTag.id + ':' +oTag.type;
                continue;
            }

            var crect = bosGetRect(oTag);

            if (rect.top >= crect.bottom ||  rect.bottom < crect.top
                || rect.left >= crect.right ||  rect.right < crect.left)
                continue;
            if (oTag.style.visibility != 'visible' && oTag.style.visibility != '')
                continue;
            var par = oTag.parentElement;
            while(par)
            {
                if (par == div)
                    break;
                par = par.parentElement;
            }
            if (par)
                continue;

            lvl.arrWindowedCtrl[ix] = oTag;
            oTag.style.visibility = 'hidden';
            ix++;
        }
    }

//  alert(txt + ':' + arrWindowedCtrl.length);
*/
}

function _popupLevelShowWindowedCtrl(lvl)
{
    if (lvl.arrWindowedCtrl == null)
        return;
    var oTag;
    for(var iCtr=0; iCtr<lvl.arrWindowedCtrl.length; iCtr++)
    {
        oTag = lvl.arrWindowedCtrl[iCtr];
        oTag.style.visibility = 'visible';
    }
    lvl.arrWindowedCtrl = null;
}

function bospopup_click(naviid,divid,url,divlevel,popupMode,ctrlStyle)
{
    popupInfoLock = true;
    popupInfoTime = bosTimeInMs();

    if (!popupLevelPlacedHideShow(divlevel,divid, naviid,'default',popupMode,ctrlStyle))
        return false;

    bosMCancel();
    eval(url);
    bosMsgLoadingEnd();

    return true;
}

function bospopup_clickShow(naviid,divid,url,divlevel,popupMode,ctrlStyle)
{
    popupInfoLock = true;
    popupInfoTime = bosTimeInMs();

    popupLevelPlacedShow(divlevel,divid, naviid,'default',popupMode,ctrlStyle);

    bosMCancel();
    eval(url);
    bosMsgLoadingEnd();

    return true;
}

function boslistbox_view(naviId,url,divlevel,mode)
{
    if (mode == 'edit')
    {
        var curPathVal = document.getElementById(naviId);
        if (curPathVal)
        {
            curPathVal = curPathVal.value;
            if (!curPathVal)
            {
                alert("No link to edit");
                return;
            }
        }
    }
    if (mode == 'findEnd')
    {
//        alert('focusout2');
        var curFndVal = document.getElementById(naviId);
        if (!curFndVal || curFndVal.name == '')
            return;
    }

    popupInfoLock = true;
    popupInfoTime = bosTimeInMs();

    if (!popupLevelPlacedHideShow(divlevel,boslistbox_popupFind(naviId), naviId+'-ctrl',
        'default'))
        return false;

    var prevFnd = document.getElementById(naviId+'-find');
    if (prevFnd)
        prevFnd.value = '??';

    boslistbox_search(naviId,url,divlevel,true,mode);

    return true;
}
function boslistbox_editstart(naviId,noeditreset)
{
    var curFnd = document.getElementById(naviId);
    var curFnd3 = document.getElementById(naviId+'-handly');
    EprFldChanged(curFnd);
    if (!curFnd3)
        return;
    EprFldChanged(curFnd3);
    if (curFnd.value == '')
        return;
    if (noeditreset)
    {
        var oldFnd = document.getElementById(naviId+'-oldval');
        if (oldFnd)
            oldFnd.value = curFnd3.value;
    }
    var curFnd2 = document.getElementById(naviId+'-key');
    if (curFnd3.value != curFnd2.value)
        curFnd3.value = curFnd2.value;
    if (!noeditreset)
        curFnd.value = '';
}
function boslistbox_editcancel(naviId)
{
    var curFnd = document.getElementById(naviId);
    if (curFnd.value == '')
        return;
    var oldFnd = document.getElementById(naviId+'-oldval');
    if (!oldFnd || oldFnd.value == '')
        return;
    var curFnd3 = document.getElementById(naviId+'-handly');
    if (curFnd3.value != oldFnd.value)
        curFnd3.value = oldFnd.value;
    oldFnd.value = '';
//    EprFldChangeCancel(curFnd);
//    EprFldChangeCancel(curFnd3);
}
function boslistbox_popupFind(naviId)
{
    var divname = 'divpopup_'+naviId;
    var div = document.getElementById(divname);
    if (div)
        return div;
    var pos;
    while((pos = divname.lastIndexOf('-'))>=0)
    {
        divname = divname.substr(0,pos);

        div = document.getElementById(divname);
        if (div)
            return div;
    }

    return divname;
}
function boslistbox_search(naviId,url,divlevel,noeditstart,mode)
{
    if (!popupLevelVisible(divlevel,boslistbox_popupFind(naviId)))
    {
        if (!noeditstart)
            boslistbox_editstart(naviId);

        boslistbox_view(naviId,url,divlevel,mode);
        return;
    }

    bosMCancel();

    if (!noeditstart)
        boslistbox_editstart(naviId);

    if (mode == 'edit')
    {
        var curPathVal = document.getElementById(naviId);
        if (curPathVal)
            curPathVal = curPathVal.value;
        eval(url);
        bosMsgLoadingEnd();
        return;
    }

    var curFndVal = document.getElementById(naviId);
    if (mode == 'findEnd')
    {
//      alert('focusout1:'+naviId+"/"+curFndVal+"/"+curFndVal.name);
        if (!curFndVal || curFndVal.name == '')
            return;
//        alert('focusout1b');
    }
    if (curFndVal)
        curFndVal = curFndVal.value;
    if (!curFndVal)
    {
        curFndVal = document.getElementById(naviId+'-handly');
        if (curFndVal)
            curFndVal = curFndVal.value;
        else
            curFndVal = '';
    }
    if (!mode)
    {
        var prevFnd = document.getElementById(naviId+'-find');
        if (prevFnd)
        {
            if (prevFnd.value == curFndVal)
                return;
            prevFnd.value = curFndVal;
        }
    }
    eval(url);
    bosMsgLoadingEnd();
}
function boslistbox_select(naviId,divlevel,mainPath,linkLabel,linkKey,iconUrl,onchg)
{
    var curFnd = document.getElementById(naviId);
    curFnd.value = mainPath;
    EprFldChanged(curFnd);

    curFnd = document.getElementById(naviId+'-handly');
    curFnd.value = linkLabel;
    EprFldChanged(curFnd);

    document.getElementById(naviId+'-key').value = linkKey;
    var prevFnd = document.getElementById(naviId+'-find');
    if (prevFnd)
        prevFnd.value = '??';
    var img = document.getElementById('icon_'+naviId);
    if (img)
        img.src = iconUrl;
    var oldFnd = document.getElementById(naviId+'-oldval');
    if (oldFnd)
        oldFnd.value = '';

    /* alert("changed !"); */
    if (onchg) eval(onchg);
    popupLevelClose(divlevel);
}
function bosaction_popup(naviId,divId,collapseIcon,expandIcon,jsPopup,jsPopupHide)
{
    var dispPopup = document.getElementById(divId);
    if (dispPopup.style.visibility == 'hidden')
    {
        document.getElementById(naviId+'_img').src=collapseIcon;
        dispPopup.innerHTML = bosDefaultPopupMsg;
        dispPopup.style.visibility = 'visible';
        eval(jsPopup);
    }
    else
    {
        document.getElementById(naviId+'_img').src=expandIcon;
        dispPopup.style.visibility = 'hidden';
        eval(jsPopupHide);
    }

    return true;
}

var bos_mouseCtrl = null,bos_mouseCtrlCancelled = null,bos_clickLocked=false,bos_clickSysLocked=false,bos_eventPending=null;
var bos_mouseCtrlOldStyle = null;
var bos_mouseCtrlOldClass = null;
function bosMOver(ctrl,style)
{
    if (bos_mouseCtrl == ctrl)
        return;

    if (bos_mouseCtrl != null)
        return;
    /*bosMOut();*/

    bos_mouseCtrlCancelled = null;
    bos_mouseCtrl = ctrl;
    if (!ctrl)
        return;

    if (style == null)
    {
        bos_mouseCtrlOldStyle = null;
        bos_mouseCtrlOldClass = null;
        return;
    }
    if (style.indexOf(":")<0)
    {
        bos_mouseCtrlOldClass = ctrl.className;
        bos_mouseCtrlOldStyle = null;
        ctrl.className = style;
        return;
    }
    bos_mouseCtrlOldStyle = ctrl.style.cssText;
    bos_mouseCtrlOldClass = null;

    ctrl.style.cssText = style+"; cursor: pointer";
}

function bosMOut(ctrl)
{
    if (typeof(ctrl) == 'undefined')
        ctrl = bos_mouseCtrl;
    if (bos_mouseCtrl == null)
        return;
    bos_mouseCtrlCancelExclude = null;
    if (bos_mouseCtrl != ctrl)
        return;
    bos_mouseCtrl = null;
    if (bos_mouseCtrlOldStyle != null)
        ctrl.style.cssText = bos_mouseCtrlOldStyle;
    else
    {
        if (bos_mouseCtrlOldClass != null)
            ctrl.className = bos_mouseCtrlOldClass;
    }
}
var bos_mouseCtrlCancelExclude = null;
function bosMCancel()
{
    if (!bos_mouseCtrl || bos_mouseCtrl == bos_mouseCtrlCancelExclude)
        return;
    bos_mouseCtrlCancelled = bos_mouseCtrl;
    bosMOut();
}
function bosIsMOver(ctrl)
{
    if (typeof(ctrl) == 'undefined')
        ctrl = window.event.srcElement;//pour ie
    if (ctrl != bos_mouseCtrl && ctrl != bos_mouseCtrlCancelled)
        return false;
    if (!bos_clickLocked)
    {
        bosForceFocus(ctrl);
        return true;
    }
    if (bos_clickSysLocked)
    {
        bos_clickSysLocked = false;
        return false;
    }
    if (!confirm("Page is loading, you should wait. Do you want to proceed your new action anyway ?"))
        return false;

    bos_clickLocked = false;
    bosForceFocus(ctrl);
    return true;
}
function bosForceFocus(ctrl)
{
    if (!ctrl)
        return;

    try
    {
        ctrl.focus();
//      alert("bosForceFocus: Ok");
    }
    catch(e)
    {
//        alert("bosForceFocus: Err");
    }
}

var bos_docActiveElement = null;
function bosCtrlFocused()
{
    var oCtrlFocused = bos_docActiveElement;
    if (!oCtrlFocused)
    {
        try
        {
            oCtrlFocused = document.activeElement;
        }
        catch (em)
        {
            bosDebugTrace('bosCtrlFocused: error');
            //if (debugMode) alert(em);
        }
    }
    return oCtrlFocused;
}
function bosCtrlIdFocused(oCtrl)
{
    var oCtrlFocused = bosCtrlFocused();
    if (!oCtrlFocused)
    {
        //alert("bosCtrlIdFocused - none");
        return "";
    }
    if (oCtrlFocused == oCtrl)
    {
        //alert("bosCtrlIdFocused - self:"+oCtrlFocused.id);
        return "";
    }
    //alert("bosCtrlIdFocused - "+oCtrlFocused.id);
    return oCtrlFocused.id;
}
function bosClickLocked()
{
    return bos_clickLocked;
}
function bosClickLock()
{
    bos_clickLocked = true;
}
function bosClickSysLock()
{
    bos_clickLocked = true;
    bos_clickSysLocked = true;
}
function bosOnChangeLock(sctrl)
{
    //bosClickSysLock();
    bos_eventPending = sctrl+":notify_onchange";
}
function bosClickUnlock()
{
    bos_clickLocked = false;
    bos_clickSysLocked = false;
}
function bosClickDone()
{
    bos_clickLocked = false;
    bos_clickSysLocked = false;
    bos_eventPending = null;
    bosMCancel();
    bosMsgLoadingEnd();
}
function EprRemoveFields(AppId)
{
    Epr.RemoveFields(AppId);
}
function EprAddFieldStart()
{
    Epr.AddFieldStart();
}
function EprAddField(fldName,fldFmt,fldArg,startCheck)
{
    Epr.AddField(fldName,fldFmt,fldArg,startCheck);
}
function EprAddFieldHidden(fldName)
{
    Epr.AddFieldHidden(fldName);
}
function EprFldFocus(sObj)
{
    Epr.FldFocus(sObj);
}
function EprPutError(Obj,errmsg)
{
    Epr.PutError(Obj,errmsg);
}
function EprEventTarget(ev)
{
    return ev.srcElement? ev.srcElement : ev.target;
}
function EprEnterKey(event)
{
    // Compatibilité IE / Firefox
    if(!event && window.event)
        event = window.event;

    // IE
    if (event.keyCode == 13)
    {
        event.returnValue=false;
        event.cancelBubble = true;
        return true;
    }
    // DOM
    if(event.which == 13)
    {
        event.preventDefault();
        event.stopPropagation();
        return true;
    }
    return false;
}
function EprSearchKeyToIgnore(event)
{
    // Compatibilité IE / Firefox
    if(!event && window.event)
        event = window.event;

    // IE
    if (event.keyCode == 9 || event.keyCode == 13)
        return true;
    // DOM
    if(event.which == 9 || event.keyCode == 13)
        return true;
    return false;
}

function EprFldChanged(ctrl)
{
    if (typeof(ctrl) == 'undefined')
        ctrl = window.event.srcElement;//pour ie
    if (!ctrl || typeof(ctrl) == 'undefined')
        return;

//  alert('EprFldChanged: '+ctrl);

    if (ctrl.name != '')
        return;

    ctrl.name = ctrl.id;
    Epr.PutModified(ctrl);
}
function EprFldChangeCancel(ctrl)
{
    if (typeof(ctrl) == 'undefined')
        ctrl = window.event.srcElement;//pour ie
    if (!ctrl || typeof(ctrl) == 'undefined')
        return;
//  alert('EprFldChanged: '+ctrl);

    if (ctrl.name == '')
        return;

    ctrl.name = '';
    Epr.PutError(ctrl,'');
}
function EprFldHdnChanged(ctrl)
{
    if (typeof(ctrl) == 'undefined')
        ctrl = window.event.srcElement;//pour ie

    if (ctrl.name != '')
        return;

    var ctname = ctrl.id.substr(4);
    ctrl.name = ctname;
    Epr.PutModified(ctname);
}
function EprFldChangeVal(ctrl,val)
{
    ctrl.value = val;
    if (ctrl.name != '')
        return;
    ctrl.name = ctrl.id;
    Epr.PutModified(ctrl);
}
function EprEscape(val)
{
//  if (!encodeURIComponent)
//      return escape(val);
    return encodeURIComponent(val);
}
function EprUnescape(val)
{
//  if (!encodeURIComponent)
//      return unescape(val);
    return decodeURIComponent(val);
}

function bosGetStyle(el, property)
{
    var value = null;
    var dv = document.defaultView;

    if (typeof(el) == "string")
        el = document.getElementById(el);

    if (property == 'opacity' && el.filters)
    {// IE opacity
         value = 1;
        try
        {
            value = el.filters.item('DXImageTransform.Microsoft.Alpha').opacity / 100;
        }
        catch(e)
        {
            try {
                value = el.filters.item('alpha').opacity / 100;
            }
            catch(e)
            {}
         }
    }
    else if (el.style[property])
        value = el.style[property];
    else if (el.currentStyle && el.currentStyle[property])
        value = el.currentStyle[property];
    else if ( dv && dv.getComputedStyle )
    {  // convert camelCase to hyphen-case
        var converted = '';
        for(i = 0, len = property.length;i < len; ++i)
        {
            if (property.charAt(i) == property.charAt(i).toUpperCase())
                converted = converted + '-' + property.charAt(i).toLowerCase();
            else
                converted = converted + property.charAt(i);
        }

        if (dv.getComputedStyle(el, '').getPropertyValue(converted))
            value = dv.getComputedStyle(el, '').getPropertyValue(converted);
    }
    if (value == null && property == "z-index")
    {
        try
        {
            value = el.style.zIndex;
        }
        catch(e)
        {
        }
    }

    return value;
};

function bosSetStyle(el, property, val)
{
    if (typeof(el) == "string")
        el = document.getElementById(el);
    switch(property)
    {
    case 'opacity' :
        if (el.filters)
        {
            el.style.filter = 'alpha(opacity=' + val * 100 + ')';
        }
        else
        {
           el.style.opacity = val;
           el.style['-moz-opacity'] = val;
           el.style['-khtml-opacity'] = val;
        }
        break;
    default :
        el.style[property] = val;
    }
};

function bosGetXY(el)
{
    if (typeof(el) == "string")
        el = document.getElementById(el);

    if (el.parentNode === null || bosGetStyle(el, 'display') == 'none')
        return false;

    if (el.getBoundingClientRect)
    { // IE
        box = el.getBoundingClientRect();

        var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
        var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;

        return {x:box.left + scrollLeft, y:box.top + scrollTop};
    }

    var parent = null;
    var pos = [];
    var box;

    if (document.getBoxObjectFor)
    { // gecko
        box = document.getBoxObjectFor(el);
        pos = {x:box.x, y:box.y};
    }
    else
    { // safari/opera
        pos = {x:el.offsetLeft, y:el.offsetTop};
        parent = el.offsetParent;
        if (parent != el)
        {
            while (parent)
            {
               pos.x += parent.offsetLeft;
               pos.y += parent.offsetTop;
               parent = parent.offsetParent;
            }
        }

         // opera & (safari absolute) incorrectly account for body offsetTop
         var ua = navigator.userAgent.toLowerCase();
         if (ua.indexOf('opera') != -1
            || ( ua.indexOf('safari') != -1 && bosGetStyle(el, 'position') == 'absolute' ))
            pos.y -= document.body.offsetTop;
      }

      if (el.parentNode)
        parent = el.parentNode;
      else
        parent = null;

    while (parent && parent.tagName != 'BODY' && parent.tagName != 'HTML')
    {
        pos.x -= parent.scrollLeft;
        pos.y -= parent.scrollTop;

        if (parent.parentNode) parent = parent.parentNode;
        else parent = null;
    }

    return pos;
};

function bosGetAbsPosDiv(el)
{
    var parent = null;
    if (el.parentNode)
        parent = el.parentNode;

    while (parent && parent.tagName != 'BODY' && parent.tagName != 'HTML')
    {
        if (parent.tagName == 'DIV')
        {
            var val = bosGetStyle(parent, 'position');
            if (val == 'relative' || val == 'absolute')
            {
                val = bosGetStyle(parent, 'z-index');
                if (!val || (val >= 1 && val <= 100))
                    return parent;
            }
        }
        if (parent.parentNode)
            parent = parent.parentNode;
        else
            parent = null;
    }

    return null;
}

function bosGetRect(el)
{
    if (typeof(el) == "string")
        el = document.getElementById(el);

    if (el.parentNode === null || bosGetStyle(el, 'display') == 'none')
        return false;

    if (el.getBoundingClientRect)
    { // IE
        box = el.getBoundingClientRect();

        var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;
        var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;

        return {left:box.left + scrollLeft, top:box.top + scrollTop, right:box.right + scrollLeft, bottom: box.bottom + scrollTop};
    }

    var parent = null;
    var box;

/*    if (document.getBoxObjectFor)
    { // gecko
        box = document.getBoxObjectFor(el);
    }
    else*/
    { // safari/opera
        box = {left:el.offsetLeft, top:el.offsetTop, right: el.offsetLeft+el.offsetWidth, bottom: el.offsetTop+el.offsetHeight};
        parent = el.offsetParent;
        if (parent != el)
        {
            while (parent)
            {
               box.left += parent.offsetLeft;
               box.right += parent.offsetLeft;
               box.top += parent.offsetTop;
               box.bottom += parent.offsetTop;
               parent = parent.offsetParent;
            }
        }

         // opera & (safari absolute) incorrectly account for body offsetTop
         var ua = navigator.userAgent.toLowerCase();
         if (ua.indexOf('opera') != -1
            || ( ua.indexOf('safari') != -1 && bosGetStyle(el, 'position') == 'absolute' ))
        {
            box.top -= document.body.offsetTop;
            box.bottom -= document.body.offsetTop;
        }
    }

    if (el.parentNode)
        parent = el.parentNode;
    else
        parent = null;

    while (parent && parent.tagName != 'BODY' && parent.tagName != 'HTML')
    {
        box.left -= parent.scrollLeft;
        box.right -= parent.scrollLeft;
        box.top -= parent.scrollTop;
        box.bottom -= parent.scrollTop;

        if (parent.parentNode)
            parent = parent.parentNode;
        else
            parent = null;
    }

    return box;
};

function bosGetX(el)
{
    return bosGetXY(el).x;
}

function bosGetY(el)
{
    return bosGetXY(el).y;
}

function bosSetXY(el, pos, noRetry)
{
    if (typeof(el) == "string")
        el = document.getElementById(el);

    var pageXY = bosGetXY(el);
    if (pageXY === false) return false; // has to be part of doc to have pageXY

    if (bosGetStyle(el, 'position') == 'static')
    { // default to relative
         bosSetStyle(el, 'position', 'relative');
    }

    var delta = {
     x: parseInt( bosGetStyle(el, 'left'), 10 ),
     y: parseInt( bosGetStyle(el, 'top'), 10 )
    };

    if ( isNaN(delta.x) ) { delta.x = 0; } // defaults to 'auto'
    if ( isNaN(delta.y) ) { delta.y = 0; }

    if (pos.x !== null) { el.style.left = pos.x - pageXY.x + delta.x + 'px'; }
    if (pos.y !== null) { el.style.top = pos.y - pageXY.y + delta.y + 'px'; }

    var newXY = bosGetXY(el);

    // if retry is true, try one more time if we miss
    if (!noRetry && ((pos.x !== null && newXY.x != pos.x) || (pos.y !== null && newXY.y != pos.y)) )
        return bosSetXY(el, pos, true);

    return true;
};

function bosSetX(el, x)
{
    return bosSetXY(el, {x:x, y:null});
}

function bosSetY(el, y)
{
    return bosSetXY(el, {x:null, y:y});
}

function bosGetSize(el)
{
    // return  value: html element position [x,y]
    if (typeof(el) == "string")
        el = document.getElementById(el);

    return {width: el.offsetWidth, height: el.offsetHeight};
}
function bosGetWidth(el)
{
    return bosGetSize(el).width;
}
function bosGetHeight(el)
{
    return bosGetSize(el).height;
}

function bosGetWindowSize()
{
    if( typeof( window.innerWidth ) == 'number' )
    {
        //Non-IE
        return {width:window.innerWidth,height:window.innerHeight};
    }

    if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
    {
        //IE 6+ in 'standards compliant mode'
        return {width:document.documentElement.clientWidth,height:document.documentElement.clientHeight};
    }

    if( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
    {
        //IE 4 compatible
        return {width:document.body.clientWidth, height:document.body.clientHeight};
    }

    return false;
}

function bosGetWindowScrollXY()
{
    if( typeof( window.pageYOffset ) == 'number' )
    {
        //Netscape compliant
        return {x:window.pageXOffset,y:window.pageYOffset};
    }

    if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) )
    {
        //IE6 standards compliant mode
        return {x:document.documentElement.scrollLeft,y:document.documentElement.scrollTop};
    }

    if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) )
    {
        //DOM compliant
        return {x:document.body.scrollLeft,y:document.body.scrollTop};
    }

    return {x:0,y:0};
}

function bosPageLoad(url)
{
    if (typeof(url) == 'undefined' || url ==''  || url =='self')
        document.location.reload(true);
    else
        document.location.href=url;
}
function bosAsyncPageLoad(url)
{
    if (typeof(url) == 'undefined' || url ==''  || url =='self')
        bosAsyncLoad('document.location.reload(true);');
    else
        bosAsyncLoad('document.location.href="'+url+'"');
}
var g_bosAsyncLoadTimer = null;
function bosAsyncLoad(cmd)
{
    bosMsgLoadingStart();
    if (g_bosAsyncLoadTimer != null)
    {
        window.clearTimeout(g_bosAsyncLoadTimer);
    }
    g_bosAsyncLoadTimer = window.setTimeout(cmd,300);
}

function bosDebugTrace(msg)
{
    var div = document.getElementById("bosDebugStatus");
    if (!div)
        return;
    div.innerHTML = msg;
    if (msg && typeof(console) != "undefined" && console.log)
        console.log(msg);
}
function bosReleaseTrace(msg)
{
    var div = document.getElementById("bosReleaseStatus");
    if (!div)
        div = document.getElementById("bosDebugStatus");
    if (!div)
        return;
    div.innerHTML = msg;
    if (msg && typeof(console) != "undefined" && console.log)
        console.log(msg);
}
function bosMsgLoadingStart()
{
    var ua = navigator.userAgent.toLowerCase();
    var isIE7 = !bos_integratedInDevEnv && ua.indexOf('msie 7.') != -1;
    if (isIE7)
    {
        bosReleaseTrace("Page is loading, please wait...");
        return;
    }
    bosDebugTrace("Page is loading, please wait...");
    var div = document.getElementById("bosLoadingWin");
    var winSz = bosGetWindowSize(),scPos = bosGetWindowScrollXY();
//  alert("sc pos: "+scPos.x+"x"+scPos.y);
    div.style.top = (scPos.y + ((winSz.height - parseInt( bosGetStyle(div, 'height'), 10 )) / 3))+"px";
    div.style.left = (winSz.width - parseInt( bosGetStyle(div, 'width'), 10 )) / 2+"px";
//    bosSetStyle(div,'opacity',0.9); -> bug sur IE 7/8 l'image n'apparait plus
    div.style.display = "block";
    div.style.visibility = "visible";
}
function bosMsgLoadingEnd()
{
    var isIE7 = !bos_integratedInDevEnv && ua.indexOf('msie 7.') != -1;
    if (isIE7)
    {
        bosReleaseTrace("");
        return;
    }
    bosDebugTrace("");
    var div = document.getElementById("bosLoadingWin");
    div.style.display = "none";
    div.style.visibility = "hidden";
}
function bosInputTxtClrFocus(oInput,txtVal)
{
    if (typeof(oInput) == "string")
        oInput = document.getElementById(oInput);

    if (oInput.value != txtVal)
        return;
    oInput.value = "";
}
function bosInputTxtClrBlur(oInput,txtVal)
{
    if (typeof(oInput) == "string")
        oInput = document.getElementById(oInput);

    if (oInput.value)
        return;
    oInput.value = txtVal;
}

function bosInputTxtClrFocusLink(lnkId,txtVal)
{
    bosInputTxtClrFocus(lnkId+"-handly",txtVal);
    bosInputTxtClrFocus(lnkId,txtVal);
    bosInputTxtClrFocus(lnkId+"-key",txtVal);
    bosInputTxtClrFocus(lnkId+"-oldval",txtVal);
}

function bosInputTxtClrBlurLink(lnkId,txtVal)
{
    bosInputTxtClrBlur(lnkId+"-handly",txtVal);
    bosInputTxtClrFocus(lnkId,txtVal);
    bosInputTxtClrFocus(lnkId+"-key",txtVal);
    bosInputTxtClrFocus(lnkId+"-oldval",txtVal);
}

function bosInputTxtSet(oInput,txtOldVal,txtNewVal)
{
    if (oInput.value != txtOldVal)
        return;
    oInput.value = txtNewVal;
}
/*
 *  md5.js 1.0b 27/06/96
 *
 * Javascript implementation of the RSA Data Security, Inc. bosMD5
 * Message-Digest Algorithm.
 *
 * Copyright (c) 1996 Henri Torgemane. All Rights Reserved.
 *
 * Permission to use, copy, modify, and distribute this software
 * and its documentation for any purposes bosMd5and without
 * fee is hereby granted provided that this copyright notice
 * appears in all copies.
 *
 * Of course, this soft is provided "as is" without express bosMd5or implied
 * warranty of any kind.
 *
 *
 * Modified with german comments and some information about collisions.
 * (Ralf Mieke, ralf@miekenet.de, http://mieke.home.pages.de)
 * French translation: Serge François, serge@selfhtml.org, http://fr.selfhtml.org
 */

var bosMd5_ascii="01234567890123456789012345678901 !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";

function bosArray(n)
{
  for(i=0;i<n;i++) this[i]=0;
  this.length=n;
}

function bosMd5int(n) { return n%(0xffffffff+1); }

function bosMd5shr(a,b)
{
    a=bosMd5int(a);
    b=bosMd5int(b);
    if (a-0x80000000>=0)
    {
        a=a%0x80000000;
        a>>=b;
        a+=0x40000000>>(b-1);
    }
    else
        a>>=b;
    return a;
}

function bosMd5shl1(a)
{
    a=a%0x80000000;
    if (a&0x40000000==0x40000000)
    {
        a-=0x40000000;
        a*=2;
        a+=0x80000000;
    }
    else a*=2;
    return a;
}

function bosMd5shl(a,b)
{
    a=bosMd5int(a);
    b=bosMd5int(b);
    for (var i=0;i<b;i++) a=bosMd5shl1(a);
    return a;
}

function bosMd5and(a,b)
{
    a=bosMd5int(a);
    b=bosMd5int(b);
    var t1=(a-0x80000000);
    var t2=(b-0x80000000);
    if (t1>=0)
    {
        if (t2>=0)
          return ((t1&t2)+0x80000000);
        return (t1&b);
    }
    if (t2>=0)
        return (a&t2);
    return (a&b);
}

function bosMd5or(a,b)
{
    a=bosMd5int(a);
    b=bosMd5int(b);
    var t1=(a-0x80000000);
    var t2=(b-0x80000000);
    if (t1>=0)
    {
        if (t2>=0)
          return ((t1|t2)+0x80000000);
        return ((t1|b)+0x80000000);
    }
    if (t2>=0)
        return ((a|t2)+0x80000000);
    return (a|b);
}

function bosMd5xor(a,b)
{
    a=bosMd5int(a);
    b=bosMd5int(b);
    var t1=(a-0x80000000);
    var t2=(b-0x80000000);
    if (t1>=0)
    {
        if (t2>=0)
            return (t1^t2);
        return ((t1^b)+0x80000000);
    }
    if (t2>=0)
        return ((a^t2)+0x80000000);
    return (a^b);
}

function bosMd5not(a)
{
    a=bosMd5int(a);
    return (0xffffffff-a);
}

function bosMD5ctx()
{
    this.state = new bosArray(4);
    this.count = new bosArray(2);
    this.count[0] = 0;
    this.count[1] = 0;
    this.buffer = new bosArray(64);
    this.transformBuffer = new bosArray(16);
    this.digestBits = new bosArray(16);

    this.transform=bosMd5_transform;
    this.update=bosMd5_update;
    this.init = bosMd5_init;
    this.finish = bosMd5_finish;
    this.digestToStr = bosMd5_digestToStr;

    this.init();
}

var bosMd5_S11 = 7;
var bosMd5_S12 = 12;
var bosMd5_S13 = 17;
var bosMd5_S14 = 22;
var bosMd5_S21 = 5;
var bosMd5_S22 = 9;
var bosMd5_S23 = 14;
var bosMd5_S24 = 20;
var bosMd5_S31 = 4;
var bosMd5_S32 = 11;
var bosMd5_S33 = 16;
var bosMd5_S34 = 23;
var bosMd5_S41 = 6;
var bosMd5_S42 = 10;
var bosMd5_S43 = 15;
var bosMd5_S44 = 21;

function bosMd5_F(x,y,z)
{
    return bosMd5or(bosMd5and(x,y),bosMd5and(bosMd5not(x),z));
}

function bosMd5_G(x,y,z)
{
    return bosMd5or(bosMd5and(x,z),bosMd5and(y,bosMd5not(z)));
}

function bosMd5_H(x,y,z)
{
    return bosMd5xor(bosMd5xor(x,y),z);
}

function bosMd5_I(x,y,z)
{
    return bosMd5xor(y ,bosMd5or(x , bosMd5not(z)));
}

function bosMd5_rotateLeft(a,n)
{
    return bosMd5or(bosMd5shl(a, n),(bosMd5shr(a,(32 - n))));
}

function bosMd5_FF(a,b,c,d,x,s,ac)
{
    a = a+bosMd5_F(b, c, d) + x + ac;
    a = bosMd5_rotateLeft(a, s);
    a = a+b;
    return a;
}

function bosMd5_GG(a,b,c,d,x,s,ac)
{
    a = a+bosMd5_G(b, c, d) +x + ac;
    a = bosMd5_rotateLeft(a, s);
    a = a+b;
    return a;
}

function bosMd5_HH(a,b,c,d,x,s,ac)
{
    a = a+bosMd5_H(b, c, d) + x + ac;
    a = bosMd5_rotateLeft(a, s);
    a = a+b;
    return a;
}

function bosMd5_II(a,b,c,d,x,s,ac)
{
    a = a+bosMd5_I(b, c, d) + x + ac;
    a = bosMd5_rotateLeft(a, s);
    a = a+b;
    return a;
}

function bosMd5_transform()
{
    var a=0, b=0, c=0, d=0;
    var x = this.transformBuffer;
    var buf = this.buffer;

    a = this.state[0];
    b = this.state[1];
    c = this.state[2];
    d = this.state[3];

    for (i = 0; i < 16; i++)
    {
        x[i] = bosMd5and(buf[i*4],0xff);
        for (j = 1; j < 4; j++)
        {
            x[i]+=bosMd5shl(bosMd5and(buf[i*4+j] ,0xff), j * 8);
        }
    }

    /* tour 1 */
    a = bosMd5_FF ( a, b, c, d, x[ 0], bosMd5_S11, 0xd76aa478); /* 1 */
    d = bosMd5_FF ( d, a, b, c, x[ 1], bosMd5_S12, 0xe8c7b756); /* 2 */
    c = bosMd5_FF ( c, d, a, b, x[ 2], bosMd5_S13, 0x242070db); /* 3 */
    b = bosMd5_FF ( b, c, d, a, x[ 3], bosMd5_S14, 0xc1bdceee); /* 4 */
    a = bosMd5_FF ( a, b, c, d, x[ 4], bosMd5_S11, 0xf57c0faf); /* 5 */
    d = bosMd5_FF ( d, a, b, c, x[ 5], bosMd5_S12, 0x4787c62a); /* 6 */
    c = bosMd5_FF ( c, d, a, b, x[ 6], bosMd5_S13, 0xa8304613); /* 7 */
    b = bosMd5_FF ( b, c, d, a, x[ 7], bosMd5_S14, 0xfd469501); /* 8 */
    a = bosMd5_FF ( a, b, c, d, x[ 8], bosMd5_S11, 0x698098d8); /* 9 */
    d = bosMd5_FF ( d, a, b, c, x[ 9], bosMd5_S12, 0x8b44f7af); /* 10 */
    c = bosMd5_FF ( c, d, a, b, x[10], bosMd5_S13, 0xffff5bb1); /* 11 */
    b = bosMd5_FF ( b, c, d, a, x[11], bosMd5_S14, 0x895cd7be); /* 12 */
    a = bosMd5_FF ( a, b, c, d, x[12], bosMd5_S11, 0x6b901122); /* 13 */
    d = bosMd5_FF ( d, a, b, c, x[13], bosMd5_S12, 0xfd987193); /* 14 */
    c = bosMd5_FF ( c, d, a, b, x[14], bosMd5_S13, 0xa679438e); /* 15 */
    b = bosMd5_FF ( b, c, d, a, x[15], bosMd5_S14, 0x49b40821); /* 16 */

    /* tour 2 */
    a = bosMd5_GG ( a, b, c, d, x[ 1], bosMd5_S21, 0xf61e2562); /* 17 */
    d = bosMd5_GG ( d, a, b, c, x[ 6], bosMd5_S22, 0xc040b340); /* 18 */
    c = bosMd5_GG ( c, d, a, b, x[11], bosMd5_S23, 0x265e5a51); /* 19 */
    b = bosMd5_GG ( b, c, d, a, x[ 0], bosMd5_S24, 0xe9b6c7aa); /* 20 */
    a = bosMd5_GG ( a, b, c, d, x[ 5], bosMd5_S21, 0xd62f105d); /* 21 */
    d = bosMd5_GG ( d, a, b, c, x[10], bosMd5_S22,  0x2441453); /* 22 */
    c = bosMd5_GG ( c, d, a, b, x[15], bosMd5_S23, 0xd8a1e681); /* 23 */
    b = bosMd5_GG ( b, c, d, a, x[ 4], bosMd5_S24, 0xe7d3fbc8); /* 24 */
    a = bosMd5_GG ( a, b, c, d, x[ 9], bosMd5_S21, 0x21e1cde6); /* 25 */
    d = bosMd5_GG ( d, a, b, c, x[14], bosMd5_S22, 0xc33707d6); /* 26 */
    c = bosMd5_GG ( c, d, a, b, x[ 3], bosMd5_S23, 0xf4d50d87); /* 27 */
    b = bosMd5_GG ( b, c, d, a, x[ 8], bosMd5_S24, 0x455a14ed); /* 28 */
    a = bosMd5_GG ( a, b, c, d, x[13], bosMd5_S21, 0xa9e3e905); /* 29 */
    d = bosMd5_GG ( d, a, b, c, x[ 2], bosMd5_S22, 0xfcefa3f8); /* 30 */
    c = bosMd5_GG ( c, d, a, b, x[ 7], bosMd5_S23, 0x676f02d9); /* 31 */
    b = bosMd5_GG ( b, c, d, a, x[12], bosMd5_S24, 0x8d2a4c8a); /* 32 */

    /* tour 3 */
    a = bosMd5_HH ( a, b, c, d, x[ 5], bosMd5_S31, 0xfffa3942); /* 33 */
    d = bosMd5_HH ( d, a, b, c, x[ 8], bosMd5_S32, 0x8771f681); /* 34 */
    c = bosMd5_HH ( c, d, a, b, x[11], bosMd5_S33, 0x6d9d6122); /* 35 */
    b = bosMd5_HH ( b, c, d, a, x[14], bosMd5_S34, 0xfde5380c); /* 36 */
    a = bosMd5_HH ( a, b, c, d, x[ 1], bosMd5_S31, 0xa4beea44); /* 37 */
    d = bosMd5_HH ( d, a, b, c, x[ 4], bosMd5_S32, 0x4bdecfa9); /* 38 */
    c = bosMd5_HH ( c, d, a, b, x[ 7], bosMd5_S33, 0xf6bb4b60); /* 39 */
    b = bosMd5_HH ( b, c, d, a, x[10], bosMd5_S34, 0xbebfbc70); /* 40 */
    a = bosMd5_HH ( a, b, c, d, x[13], bosMd5_S31, 0x289b7ec6); /* 41 */
    d = bosMd5_HH ( d, a, b, c, x[ 0], bosMd5_S32, 0xeaa127fa); /* 42 */
    c = bosMd5_HH ( c, d, a, b, x[ 3], bosMd5_S33, 0xd4ef3085); /* 43 */
    b = bosMd5_HH ( b, c, d, a, x[ 6], bosMd5_S34,  0x4881d05); /* 44 */
    a = bosMd5_HH ( a, b, c, d, x[ 9], bosMd5_S31, 0xd9d4d039); /* 45 */
    d = bosMd5_HH ( d, a, b, c, x[12], bosMd5_S32, 0xe6db99e5); /* 46 */
    c = bosMd5_HH ( c, d, a, b, x[15], bosMd5_S33, 0x1fa27cf8); /* 47 */
    b = bosMd5_HH ( b, c, d, a, x[ 2], bosMd5_S34, 0xc4ac5665); /* 48 */

    /* tour 4 */
    a = bosMd5_II ( a, b, c, d, x[ 0], bosMd5_S41, 0xf4292244); /* 49 */
    d = bosMd5_II ( d, a, b, c, x[ 7], bosMd5_S42, 0x432aff97); /* 50 */
    c = bosMd5_II ( c, d, a, b, x[14], bosMd5_S43, 0xab9423a7); /* 51 */
    b = bosMd5_II ( b, c, d, a, x[ 5], bosMd5_S44, 0xfc93a039); /* 52 */
    a = bosMd5_II ( a, b, c, d, x[12], bosMd5_S41, 0x655b59c3); /* 53 */
    d = bosMd5_II ( d, a, b, c, x[ 3], bosMd5_S42, 0x8f0ccc92); /* 54 */
    c = bosMd5_II ( c, d, a, b, x[10], bosMd5_S43, 0xffeff47d); /* 55 */
    b = bosMd5_II ( b, c, d, a, x[ 1], bosMd5_S44, 0x85845dd1); /* 56 */
    a = bosMd5_II ( a, b, c, d, x[ 8], bosMd5_S41, 0x6fa87e4f); /* 57 */
    d = bosMd5_II ( d, a, b, c, x[15], bosMd5_S42, 0xfe2ce6e0); /* 58 */
    c = bosMd5_II ( c, d, a, b, x[ 6], bosMd5_S43, 0xa3014314); /* 59 */
    b = bosMd5_II ( b, c, d, a, x[13], bosMd5_S44, 0x4e0811a1); /* 60 */
    a = bosMd5_II ( a, b, c, d, x[ 4], bosMd5_S41, 0xf7537e82); /* 61 */
    d = bosMd5_II ( d, a, b, c, x[11], bosMd5_S42, 0xbd3af235); /* 62 */
    c = bosMd5_II ( c, d, a, b, x[ 2], bosMd5_S43, 0x2ad7d2bb); /* 63 */
    b = bosMd5_II ( b, c, d, a, x[ 9], bosMd5_S44, 0xeb86d391); /* 64 */

    this.state[0] +=a;
    this.state[1] +=b;
    this.state[2] +=c;
    this.state[3] +=d;
}

function bosMd5_init()
{
    this.count[0]=this.count[1] = 0;
    this.state[0] = 0x67452301;
    this.state[1] = 0xefcdab89;
    this.state[2] = 0x98badcfe;
    this.state[3] = 0x10325476;
    for (i = 0; i < this.digestBits.length; i++)
        this.digestBits[i] = 0;
}

function bosMd5_update(b)
{
    var index,i;

    index = bosMd5and(bosMd5shr(this.count[0],3) , 0x3f);
    if (this.count[0]<0xffffffff-7)
      this.count[0] += 8;
    else
    {
      this.count[1]++;
      this.count[0]-=0xffffffff+1;
      this.count[0]+=8;
    }
    this.buffer[index] = bosMd5and(b,0xff);
    if (index  >= 63)
        this.transform();
}

function bosMd5_finish()
{
    var bits = new bosArray(8);
    var        padding;
    var        i=0, index=0, padLen=0;

    for (i = 0; i < 4; i++)
    {
        bits[i] = bosMd5and(bosMd5shr(this.count[0],(i * 8)), 0xff);
    }
    for (i = 0; i < 4; i++)
    {
        bits[i+4]=bosMd5and(bosMd5shr(this.count[1],(i * 8)), 0xff);
    }
    index = bosMd5and(bosMd5shr(this.count[0], 3) ,0x3f);
    padLen = (index < 56) ? (56 - index) : (120 - index);
    padding = new bosArray(64);
    padding[0] = 0x80;
    for (i=0;i<padLen;i++)
      this.update(padding[i]);
    for (i=0;i<8;i++)
      this.update(bits[i]);

    for (i = 0; i < 4; i++)
    {
        for (j = 0; j < 4; j++)
        {
            this.digestBits[i*4+j] = bosMd5and(bosMd5shr(this.state[i], (j * 8)) , 0xff);
        }
    }
}
function bosMd5_digestToStr()
{
    var s="";
    var shexa_h = "0123456789ABCDEF",val=0;
    for(var i = 0; i < this.digestBits.length; i++)
    {
/*        if (i && !(i % 4))
            s += " ";*/
        val = this.digestBits[i];

        s += shexa_h.charAt(((val&0xF0)>>4));
        s += shexa_h.charAt((val&0xF));
    }
    return s;
}

function bosMD5caseDep(message)
{
    var ctx = new bosMD5ctx();
    for (k=0;k<message.length;k++)
    {
        ctx.update(bosMd5_ascii.lastIndexOf(message.charAt(k)));
    }
    ctx.finish();
    return ctx.digestToStr();
}

function bosMD5(message)
{
    var ctx = new bosMD5ctx(),_message = message.toLowerCase();
    for (k=0;k<_message.length;k++)
    {
        ctx.update(bosMd5_ascii.lastIndexOf(_message.charAt(k)));
    }
    ctx.finish();
    return ctx.digestToStr();
}

function bosMD5nocvt(message)
{
    var ctx = new bosMD5ctx();
    for (k=0;k<message.length;k++)
    {
        ctx.update(message.charCodeAt(k));
    }
    ctx.finish();
    return ctx.digestToStr();
 }

function bosFldAdd(str,fldPref,fldEnc,fldPwd)
{
    var ret=str,arr = fldEnc.split(',');
    for(var i = 0; i < arr.length;i++)
    {
        ret += document.getElementById(fldPref+arr[i]).value;
    }
    ret += fldPwd;
    return ret;
}

function bosMD5gen(str,fldId,fldPref,fldEnc)
{
    try
    {
        var oFld=document.getElementById(fldId);
        oFld.value = bosMD5(bosFldAdd(str,fldPref,fldEnc,document.getElementById(fldId+"-handly").value));
        EprFldChanged(oFld);
    }
    catch(em)
    {
        alert(em);
    }
}

function bosMD5cgen(str,fldId,fldPref,fldEnc)
{
    try
    {
        var oFld=document.getElementById(fldId);
        oFld.value = bosMD5caseDep(bosFldAdd(str,fldPref,fldEnc,document.getElementById(fldId+"-handly").value));
        EprFldChanged(oFld);
    }
    catch(em)
    {
        alert(em);
    }
}

var globalLstNode = new Array,globalLstNodeEval = new Array;
var globalTreeViewCacheId =null, globalTreeViewSelect=null, globalTreeViewSelectFields=null;
function bosTreeLoad(divToFeed,lstcacheId,lstjsurl,select,selectFields)
{
    if (lstjsurl == "test.js")
    {
        bosTreeTestLoad(lstcacheId);
        bosTreeDivFeed(divToFeed,lstcacheId);
        return;
    }

    globalTreeViewCacheId = lstcacheId;
    globalTreeViewSelect = select;
    globalTreeViewSelectFields = selectFields;
    globalLstNodeEval[lstcacheId] = "bosTreeDivFeed('"+divToFeed+"','"+lstcacheId+"')";
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = lstjsurl;
    document.getElementsByTagName('head')[0].appendChild(script);
}

function bosTreeLoaded(lstnode,lstcacheId)
{
    globalLstNode[lstcacheId] = lstnode;
    var str = globalLstNodeEval[lstcacheId];
    if (str)
        eval(str);
}

function bosTreeTestLoad(lstcacheId)
{
    var lstnode = [];
    lstnode[0] = new bosTreeNode(0,"A","A voiture",["A","B"]);
    lstnode[1] = new bosTreeNode(1,"A1","A1 voiture","A1");
    lstnode[2] = new bosTreeNode(1,"A2","A2 voiture","A2");
    lstnode[3] = new bosTreeNode(2,"A21","A21 voiture","A21");
    lstnode[4] = new bosTreeNode(1,"A3","A3 voiture","A3");
    lstnode[5] = new bosTreeNode(0,"B","B voiture","B");
    lstnode[6] = new bosTreeNode(1,"B1","B1 voiture","B1");
    globalLstNode[lstcacheId] = lstnode;
}

function bosTreeNode(level,id,label,vars)
{
    this.level=level;
    this.id=id;
    this.label=label;
    this.vars=vars;
}

function bosTreeExpand(n)
{
    var node = n;
    while ( node.nodeName != "UL" )
        node = node.nextSibling;

    if ( node.style.display == 'block' )
    {
        node.style.display = 'none';
        n.src = '/scriptor/bos/images/divers/plus.gif';
    }
    else
    {
        node.style.display = 'block';
        n.src = '/scriptor/bos/images/divers/minus.gif';;
    }
}

function bosTreeClick(n,ix)
{
    var node = globalLstNode[globalTreeViewCacheId][ix];
    if (!node.vars)
        return;
    var arrFld = globalTreeViewSelectFields.split('|');
    var str = globalTreeViewSelect;
    for(var i = 0; i < arrFld.length; i++)
    {
        var sfnd = "${"+arrFld[i]+"}";
        while(str.indexOf(sfnd)>=0)
        {
            str = str.replace(sfnd,node.vars[i]);
        }
    }
    eval(str);
}

function bosTreeInfo(lstnode)
{
    this.lstnode = lstnode;
    this.divnode = "";
    this.cptexpand = 0;
}
function bosTreeDivFeed(divToFeed,lstcacheId)
{
    var info = new bosTreeInfo(globalLstNode[lstcacheId]);
    bosTreeNodeWrite(info,0,0);
    document.getElementById(divToFeed).innerHTML = info.divnode;
}

function bosTreeNodeWrite(info, i, level)
{
    if (i==0)
        info.divnode += "<ul class='bosPopupTreeView'>";
    else
        info.divnode += "<ul>";

    while (i < info.lstnode.length)
    {
        if(info.lstnode[i].level > level)
        {
            if (bosTreeNodeWrite(info, i, ++level))
                break;
            i++;
            continue;
        }
        if(info.lstnode[i].level < level)
        {
            info.divnode += "</ul>";
            if (info.cptexpand > 0)
            {
                info.cptexpand--;
                info.divnode += "</li>";
            }

            level--;
            continue;
        }

        if((i+1) < info.lstnode.length && info.lstnode[(i+1)].level > level)
        {
            info.cptexpand++;
            info.divnode += "<li><img src='/scriptor/bos/images/divers/plus.gif' onclick='bosTreeExpand(this)'/>";
        }
        else
            info.divnode += "<li>";
        info.divnode += "<span onclick='bosTreeClick(this,"+i+")'>"+info.lstnode[i].label+"</span></li>";
        i++;
    }
    info.divnode += "</ul>";
    if (info.cptexpand > 0)
    {
        info.cptexpand--;
        info.divnode += "</li>";
    }

    return true;
}
function bosUrlGoLink(naviId)
{
    var oEdit = document.getElementById(naviId);
    if (!oEdit)
    {
        alert("Edit '"+naviId+"' not found");
        return;
    }
    var url = oEdit.value;
    if (!url)
    {
        alert("No url to open !");
        return;
    }
    for(;;)
    {
        var pos = url.indexOf(':');
        if (pos < 0)
        {
            url = "http://"+url;
            oEdit.value = url;
            break;
        }
        var sproto = url.substr(0,pos);
        if (sproto == "http" || sproto == "https")
            break;
        url = "http://"+url;
        oEdit.value = url;
        break;
    }
    var newWin = window.open(url,"_blank");
}



/*001*/ var msgLang_fieldFormatInvalid="Invalid format '&&1'";
/*002*/ var msgLang_fieldNumFormatInvalid="Numeric field '&&1' invalid:\nParameter '&&2' incorrect";
/*003*/ var msgLang_fieldNumFormatLimitInvalid="Numeric field '&&1' invalid:\nParameter limit '&&2' incorrect";
/*008*/ var msgLang_fieldDateFormatInvalid="Date field '&&1' invalid :\nParameter '&&2' incorrect";
/*009*/ var msgLang_fieldDateFormatLimitInvalid="Date field '&&1' invalid :\nParameter limit '&&2' incorrect";
/*013*/ var msgLang_fieldTimeFormatInvalid="Time field '&&1' invalid :\nParameter '&&2' incorrect";
/*014*/ var msgLang_fieldTimeFormatLimitInvalid="Time field '&&1' invalid :\nParameter limit '&&2' incorrect";
/*018*/ var msgLang_fieldFormatParamInvalid="Field format '&&1' invalid :\nParameter '&&2' incorrect";
/*023*/ var msgLang_fieldMailFormatInvalid="Mail field '&&1' invalid :\nParameter '&&2' incorrect";
/*026*/ var msgLang_fieldBoolFormatInvalid="Booleen field '&&1' invalid :\nParameter '&&2' incorrect";
/*028*/ var msgLang_fieldListFormatInvalid="List field invalid :\nParameter '&&2' incorrect";
/*027*/ var msgLang_fieldBoolInvalid="Booleen field '&&1' invalid :\nMust show in :\n&&1";
/*030*/ var msgLang_fieldListOptInvalid="Option '&&1' invalid (in this type of field)";
/*031*/ var msgLang_fieldListOptRepeated="Option '&&1' repeated";

/*004*/ var msgLang_fieldNumSignInvalid="Numeric value incorrect :\nErroneous sign";
/*005*/ var msgLang_fieldNumStringInvalid="Numeric value incorrect :\nMust follow format (&&1)";
/*006*/ var msgLang_fieldNumNotInRange="Numeric value incorrect :\nMust be in the interval (&&1)";
/*007*/ var msgLang_fieldNumStringInvalidNoArg="Numeric value incorrect :\nBad format";

/*010*/ var msgLang_fieldDateStringInvalid="Date value incorrect :\nBad format";
/*011*/ var msgLang_fieldDateInvalid="Date value incorrect :\nDate invalid";
/*012*/ var msgLang_fieldDateNotInRange="Date value incorrect :\nMust be in interval &&1";

/*015*/ var msgLang_fieldTimeStringInvalid="Time value incorrect :\nBad format";
/*016*/ var msgLang_fieldTimeInvalid="Time value incorrect :\nTime incorrect";
/*017*/ var msgLang_fieldTimeNoInRange="Time value incorrect :\nMust be in interval &&1";

/*019*/ var msgLang_fieldFormatMaxChar="Max .Char.";

/*020*/ var msgLang_fieldValueTooLong="Field value incorrect :\nMaximum &&1 character(s) authorized";
/*021*/ var msgLang_fieldIPformatInvalid="IP field '&&1' invalid :\nToo many parameters '&&2'";
/*022*/ var msgLang_fieldIPinvalid="IP address invalid";
        var msgLang_fieldIPsyntaxe="<=255.255.255.255";
/*024*/ var msgLang_fieldMailSyntaxe="name@server";
/*025*/ var msgLang_fieldMailInvalid="Mail address invalid";
/*029*/ var msgLang_fieldListValueInvalid="List value incorrect :\nMust show in :\n&&1";
/*032*/ var msgLang_fieldValueRequired="A value is required for this field";
/*033*/ var msgLang_fieldDateSyntaxe="JJ@MM@AAAA@HH@MM";
/*035*/ var msgLang_fieldValueTooLittle="Text value incorrect: \nMinimum &&1 characters authorized";
/*036*/ var msgLang_fieldPasswordWithoutNum="Your password must contain at least one number";
/*037*/ var msgLang_fieldCharForbidden="Characters '&&1' are forbidden";

