var P123_QstMerge=new Array();
var P123_QstJump=new Array();
var P123_InpBt=null;
var P123_InpSt=null;
var P123_Qst=null;
var global_t;

function showMoreChoice2(t) {
    global_t=t;

    var entry=encodeURIComponent(t.options.paramName)+'='+encodeURIComponent(t.getToken());
    t.options.parameters=t.options.callback?t.options.callback(t.element,entry):entry;
    if(t.options.defaultParams) { t.options.parameters+='&'+t.options.defaultParams; }
    if(t.options.parameters.indexOf("&nbl=")== -1) {
        t.options.parameters+='&nbl=all';
    } else {
        var ind_nbl=t.options.parameters.indexOf("&nbl=");
        var ind_nbl2=t.options.parameters.indexOf("&",ind_nbl+1);
        if(ind_nbl2== -1) { ind_nbl2=t.options.parameters.length; }
        t.options.parameters=t.options.parameters.substring(0,ind_nbl)+"&nbl=all"+t.options.parameters.substring(ind_nbl2);
    }

    new Ajax.Request(""+t.url,{
        evalScripts: true,
        parameters: t.options.parameters,
        onSuccess: function(transport) {
            document.getElementById("div_wait2").style.position="absolute";
            document.getElementById("div_wait2").style.top="0px";
            document.getElementById("div_wait2").style.left="0px";
            document.getElementById("div_wait2").style.width=""+document.body.scrollWidth+"px";
            document.getElementById("div_wait2").style.height=""+document.body.scrollHeight+"px";
            document.getElementById("div_wait2").style.background="url("+webquizz_path+"images/grise.gif)";
            document.getElementById("div_wait2").innerHTML="&nbsp;";
            var tmp=document.createElement("div");
            var tmp2="<div style=\"width:100%;height:90px;overflow-y:scroll;overflow-x:hidden;\">";
            tmp.innerHTML=""+transport.responseText;
            for(var i=0;i<tmp.firstChild.childNodes.length;i++) {
                tmp2=tmp2+"<div style=\"width:100%;cursor:pointer;\" onclick=\"parent.global_t.element.value='"+tmp.firstChild.childNodes[i].innerHTML.gsub("'","\'")+"';parent.HideMoreChoice();\">"+tmp.firstChild.childNodes[i].innerHTML+"</div>";
            }
            tmp2=tmp2+"<div>&#160;</div></div>";
            document.getElementById("div_wait2").style.visibility="visible";
            document.getElementById("div_wait2").style.display="block";


            setContent(tmp2,"ipopup",250,120);
            show_popup("ipopup");
        },
        onFailure: function() { }
    });
}
function HideMoreChoice() {
    document.getElementById("div_wait2").style.visibility="hidden";
    document.getElementById("div_wait2").style.display="none";
    hide_popup("ipopup");
    var o=$$('input.'+global_t.element.className);
    if((o.length>0)&&((o.indexOf(global_t.element)+1)<o.length)) {
        eval('at'+o[o.indexOf(global_t.element)+1].id).activate();
    }
}

function gestion_scorm() {
    if(findAPI!=null) {
        scorm_LMSinit();
        var tab_sign="";
        var i=0;
        var str_tmp="";
        tab_sign=page_cookie.split("$$");
        for(i=0;i<tab_sign.length;i++) {
            str_tmp=tab_sign[i];
            if(""+str_tmp!="") {
                num=str_tmp.substring(0,str_tmp.indexOf("="));
                str_tmp=str_tmp.substring(str_tmp.indexOf("=")+1);
                page_cookie=page_cookie.replace("$$"+num+"="+str_tmp+"$$","$$"+num+"="+doLMSGetValue(str_tmp)+"$$");
            }
        }
    }
}

function ManagerImg(obj,src,width,height,border) {
    var img=new Image();
    img.src=""+src+"";
    var objet=document.createElement("img");
    objet.src=""+src+"";
    objet.alt="";
    if(typeof (width)!="undefined"&&width!="") {
        objet.width=width;
    }
    if(typeof (height)!="undefined"&&height!="") {
        objet.height=height;
    }
    if(typeof (border)!="undefined"&&border!="") {
        objet.border=border;
    }
    $(""+obj+"").appendChild(objet);
}

function MergeLinkQst(q) {
    var qst=q.split(',');
    var i=0;
    var j=0;
    var k=0;
    var s=parseInt((1/qst.length)*$('table_form').getWidth());
    var t=0;
    var v=false;
    var a=null;
    var c=null;
    var e=null;
    var sc=null;
    var q=null;
    for(i=0;i<P123_QstMerge.length;i++) {
        for(j=0;j<qst.length-1;j++) {
            a=P123_QstMerge[i].split(",");
            if(a.indexOf(""+qst[j]+"")!= -1) {
                c=$('ClassQuestion'+qst[j]);
                e=c.ancestors()[0].next('.ClassEmpty',0);
                if(e) {
                    sc=c.ancestors()[0].ancestors()[0];
                    if(!sc.visible()) {
                        v=true;
                        sc.show();
                    } else {
                        v=false;
                    }
                    t=0;
                    for(k=0;k<a.length;k++) {
                        q=$('ClassQuestion'+a[k]);
                        if(!q.visible()) {
                            q.show();
                            v=true;
                        } else {
                            v=false;
                        }
                        t+=q.getWidth();
                        if(v) {
                            q.hide();
                        }
                    }
                    if((s-t)>0) {
                        e.setStyle({ width: s-t+'px' });
                    } else {
                        e.setStyle({ width: '0px' });
                    }
                    if(v) {
                        sc.hide();
                    }
                }
            }
        }
    }
}

function LinkQst(q,w) {
    var qst=q.split(',');
    var i=0;
    if(qst.length>1) {
        $('ClassQuestion'+qst[0]).style.clear='both';
        //$('ClassQuestion'+qst[qst.length-1]).style.float="";
    }
    for(i=0;i<qst.length;i++) {
        $('ClassQuestion'+qst[i]).style.width=w-1+'%';
        $('ClassQuestion'+qst[i]).down(0).style.width='100%';
    }
}

function MergeQst(q) {
    var qst=q.split(',');
    var i=0;
    var j=0;
    var tab=null;
    // Only IE
    /*
    if(qst.length>1) {
    $('ClassQuestion'+qst[0]).style.clear='both';
    }
    for(i=0;i<qst.length;i++) {
    tab=$('ClassQuestion'+qst[i]).select('table[width="100%"]');
    for(j=0;j<tab.length;j++) {
    tab[j].setStyle({ width: 'auto' });
    }
    }
    return false;
    */
    // Recent browser
    if(qst.length>1) {
        $('ClassQuestion'+qst[0]).style.clear='both';
        $('ClassQuestion'+qst[0]).select('.ClassSubTitle')._each(function(e) {
            e.setStyle({ whiteSpace: 'nowrap',overflow: 'hidden' });
        });
    }
    for(i=0;i<qst.length;i++) {
        if($('QstItem'+qst[i])) {
            $('QstItem'+qst[i]).select('.ClassInput')._each(function(e) {
                e=e.up('td',0);
                if(e) {
                    e=e.next('td',0);
                    if(e) {
                        e.setStyle({ whiteSpace: 'nowrap',overflow: 'hidden' });
                    }
                }
            });
        }
        $('QstTitle'+qst[i]).setStyle({ whiteSpace: 'nowrap',overflow: 'hidden' });
        tab=$('ClassQuestion'+qst[i]).select('table');
        for(j=0;j<tab.length;j++) {
            if(typeof (tab[j].width)!='undefined') {
                if((''+tab[j].width)=='100%') {
                    tab[j].setStyle({ width: '1px' });
                }
            }
            if(typeof (tab[j].style.width)!='undefined') {
                if((''+tab[j].style.width)=='100%') {
                    tab[j].setStyle({ width: '1px' });
                }
            }
        }
    }
}

function sizeQstTd(q) {
    var rows=0;
    var tab=null;
    var qst=$('ClassQuestion'+q[0]);
    var s=qst.ancestors()[1];
    var o=null;
    var v=s.visible();
    if(!v) {
        s.show();
    }
    q.each(function(e1) {
        qst=$('ClassQuestion'+e1);
        qst.select('td.ClassTdItem'+e1).each(function(e2) {
            if(!qst.visible()) {
                qst.show();
                rows=Math.max(rows,(e2.empty())?0:e2.getHeight());
                qst.hide();
            } else {
                rows=Math.max(rows,(e2.empty())?0:e2.getHeight());
            }
        });
    });
    if(rows!=0) {
        q.each(function(e1) {
            $("ClassQuestion"+e1).select("td.ClassTdItem"+e1).each(function(e2) {
                e2.setStyle({ height: rows+"px" });
            });
        });
    }
    rows=0;
    q.each(function(e1) {
        $("ClassQuestion"+e1).select("td.ClassSubTitle").each(function(e2) {
            o=$('ClassQuestion'+e1);
            if(!o.visible()) {
                o.show();
                rows=Math.max(rows,(e2.empty())?0:e2.getHeight());
                o.hide();
            } else {
                rows=Math.max(rows,(e2.empty())?0:e2.getHeight());
            }
        });
    });
    if(rows!=0) {
        q._each(function(e1) {
            $("ClassQuestion"+e1).select("td.ClassSubTitle")._each(function(e2) {
                //o=e2.next('td');
                o=e2.next(0);
                if(o) {
                    o.setStyle({ height: rows+"px" });
                } else {
                    e2.setStyle({ height: rows+"px" });
                }
            });
        });
    }
    rows=0;
    if(!v) {
        s.hide();
    }
}

function sizeQst() {
    var i=0;
    var j=0;
    var k=0;
    var qst=null;
    var rows=null;
    var tab=null;
    var q=null;
    var s=null;
    var o=null;
    var v=true;
    P123_QstMerge.each(function(e) {
        qst=e.split(",");
        if(qst.length!=0) {
            q=$('ClassQuestion'+qst[0]);
            s=q.ancestors()[1];
            v=s.visible();
            if(!v) {
                s.show();
            }
            tab=$("QstItem"+qst[0]);
            if(tab) {
                qst.each(function(e1) {
                    o=$("QstItem"+e1);
                    if(o) {
                        rows=o.rows;
                        for(k=0;k<rows.length;k++) {
                            if(k<tab.rows.length) {
                                if(!q.visible()) {
                                    q.show();
                                    rows[k].style.height=$(tab.rows[k]).getHeight()+"px";
                                    q.hide();
                                } else {
                                    rows[k].style.height=$(tab.rows[k]).getHeight()+"px";
                                }
                            }
                        }
                    }
                });
            }
            o=$("QstTitle"+qst[0]);
            if(!q.visible()) {
                q.show();
                tab=(o.empty())?0:o.getHeight();
                q.hide();
            } else {
                tab=(o.empty())?0:o.getHeight();
            }
            qst.each(function(e1) {
                q=$('ClassQuestion'+e1);
                o=$("QstTitle"+e1);
                if(!q.visible()) {
                    q.show();
                    tab=Math.max(tab,(o.empty())?0:o.getHeight());
                    q.hide();
                } else {
                    tab=Math.max(tab,(o.empty())?0:o.getHeight());
                }
            });
            if(tab!=0) {
                qst.each(function(e1) {
                    $("QstTitle"+e1).setStyle({ height: tab+"px" });
                });
            }
            if(!v) {
                s.hide();
            }
            sizeQstTd(qst);
        }
    });
}

function ManagerVisible(o,b) {
    if(o) {
        (b)?$(o).show():$(o).hide();
    }
}

function ManagerJump(d,v,m,b) {
    d=parseInt(d);
    var qst=$(document.body).select("div.ClassQuestion");
    if(!b) {
        if(qst[d]) {
            if(''+qst[d].getStyle('display')=='') {
                ManagerVisible(qst[d],1);
            }
        }
    } else {
        var i=0;
        var k=0;
        v=parseInt(v);
        m=parseInt(m);
        if(v<m) {
            for(i=d+1;i<v;i++) {
                ManagerVisible(qst[i-1],0);
            }
            for(i=v;i<m;i++) {
                if(P123_QstJump[i-1]=="") {
                    ManagerVisible(qst[i-1],1);
                } else {
                    ManagerVisible(qst[i-1],1);
                    var j=P123_QstJump[i-1].split(",");
                    if(j.length==1) {
                        for(k=i+1;k<parseInt(j[0]-1);k++) {
                            ManagerVisible(qst[k-1],0);
                        }
                        i=parseInt(j[0]-1);
                    } else {
                        for(k=parseInt(j[0]);k<parseInt(j[j.length-1]);k++) {
                            ManagerVisible(qst[k-1],0);
                            i=k;
                        }
                    }
                }
            }
        } else {
            for(i=d+1;i<v;i++) {
                ManagerVisible(qst[i-1],0);
            }
            for(i=v;i>=m;i--) {
                ManagerVisible(qst[i-1],0);
            }
            ManagerVisible(qst[v-1],1);
            i=v;
            while(i<qst.length) {
                if(P123_QstJump[i]=='') {
                    ManagerVisible(qst[i],1);
                    i+=1;
                } else {
                    i=qst.length;
                }
            }
        }
    }
}

function ManagerDisplay(i,e,c) {
    var qst=$(document.body).select(e+"."+c);
    value=HtmlDecode(qst[i].innerHTML);
    value=value.stripScripts();
    value=value.stripTags();
    value=value.gsub(String.fromCharCode(13),"");
    value=value.gsub(String.fromCharCode(10),"");
    value=value.gsub("\\'","'");
    if(value.length>43) {
        value=value.substring(0,40)+" ...";
    }
    if(c=="ClassSubTitle") {
        value="\n\t"+value;
    } else {
        value="\n\n"+value;
    }
    return value;
}

function GetParentByClass(o,c) {
    return $(o).up("div."+c);
}

function ClearQuestion(id) {
    var obj=$(id);
    if(obj) {
        obj.show();
        ClearElementFrom(id);
    }
}

function ClearElementFrom(id) {
    var ok=false;
    var obj=null;
    var i=0;
    var objs=$("q").elements
    for(i=0;i<objs.length;i++) {
        obj=objs[i];
        if((obj.tagName.toLowerCase()=="input")||(obj.tagName.toLowerCase()=="select")||(obj.tagName.toLowerCase()=="textarea")) {
            ok=false;
            while((obj)&&(!ok)) {
                if(obj.id) {
                    if(obj.id!=""+id+"") {
                        obj=obj.parentNode;
                    } else {
                        ok=true;
                    }
                } else {
                    obj=obj.parentNode;
                }
            }
            if(obj) {
                if(obj.visible()) {
                    obj=objs[i];
                    if(!obj.disabled) {
                        switch(obj.type.toLowerCase()) {
                            case "radio":
                                obj.checked=false;
                                break;
                            case "checkbox":
                                obj.checked=false;
                                break;
                            case "text":
                                obj.value="";
                                break;
                            case "select-one":
                                obj.selectedIndex=0;
                                break;
                            case "textarea":
                                obj.value="";
                                break;
                            case "select-multiple":
                                var j=0;
                                for(j=0;j<obj.options.length;j++) {
                                    obj.options[i].selected=false;
                                }
                                break;
                            case "hidden":
                                if(obj.id.indexOf("var_")!= -1) {
                                    obj.value="0";
                                }
                                break;
                            default:
                                break;
                        }
                    }
                }
            }
        }
    }
}

function EmptyScreen(i) {
    var ok=true;
    var j=0;
    if($("ClassScreen"+i)) {
        var qst=$("ClassScreen"+i).select("div.ClassQuestion");
        while((ok)&&(j<qst.length)) {
            if($(qst[j]).visible()) {
                ok=false;
            }
            j++;
        }
        return ok;
    } else { return ok; }
}

function Previous(i) {
    if(i==0) {
        $('previous').hide();
    } else {
        if(typeof (boolS)!='undefined') {
            if(((''+typeof ($('QstItem0'))=='undefined')||!boolS)&&(i==1)) {
                $('previous').hide();
            } else {
                $('previous').show();
            }
        } else {
            $('previous').show();
        }
    }
}

function Next(i) {
    if(i==(nb_screen-1)) {
        $('next').hide();
        $('send').show();
    } else {
        $('next').show();
        $('send').hide();
    }
}

function traite_ajourner(st) {
    st=st.gsub(String.fromCharCode(13),'<BR');
    st=st.gsub(String.fromCharCode(10),'');
    st=st.gsub(String.fromCharCode(92)+String.fromCharCode(92),'\\\\');
    st=st.gsub(String.fromCharCode(34),'\\\"');
    return st;
}

function traite_lescript(st) {
    st=st.gsub(String.fromCharCode(60),'<<');
    st=st.gsub(String.fromCharCode(13),'<BR');
    st=st.gsub(String.fromCharCode(10),'');
    st=st.gsub(String.fromCharCode(9),'&nbsp');
    st=st.gsub(String.fromCharCode(32),'&nbsp');
    st=st.gsub(String.fromCharCode(133),'...');
    st=st.gsub('%3B',';');
    st=st.gsub('%3b',';');
    return st;
}

function cookie(nom) {
    var i,j;
    var st="";
    i=page_cookie.indexOf(nom);
    if(i> -1) {
        st=page_cookie.substring(i+nom.length+1);
        st=st.substring(0,st.indexOf("$$"));
        return st;
    }
    return "";
}

function page_nom(m) {
    var n=""+m;
    if(n.lastIndexOf("?")>0) {
        n=n.substring(0,n.lastIndexOf("?"));
    }
    n=n.substring(n.lastIndexOf("/")+1,n.lastIndexOf("."));
    if(n.lastIndexOf(".")>0) {
        n=n.substring(0,n.lastIndexOf("."));
    }
    return n;
}

function getCookieVal(offset) {
    var endstr=document.cookie.indexOf(";",offset);
    if(endstr== -1) endstr=document.cookie.length;
    return unescape(document.cookie.substring(offset,endstr));
}

function GetCookie(name) {
    var arg=name+"=";
    var alen=arg.length;
    var clen=document.cookie.length;
    var i=0;
    while(i<clen) {
        var j=i+alen;
        if(document.cookie.substring(i,j)==arg)
            return getCookieVal(j);
        i=document.cookie.indexOf(" ",i)+1;
        if(i==0) break;
    }
    return "";
}

function SetCookie(name,value) {
    var argv=SetCookie.arguments;
    var argc=SetCookie.arguments.length;
    var expires=(2<argc)?argv[2]:null;
    var path=(3<argc)?argv[3]:null;
    var domain=(4<argc)?argv[4]:null;
    var secure=(5<argc)?argv[5]:false;
    document.cookie=name+"="+escape(value)+((expires==null)?"":(";expires="+expires.toGMTString()))+((path==null)?"":(";path="+path))+((domain==null)?"":(";domain="+domain))+((secure==true)?";secure":"");
}

function txtapp_check(form) {
    var i,j,aux;
    i=1;
    j=0;
    while((aux=$("q"+form+standardize(i)))!=null) {
        j+=aux.selectedIndex;
        i++;
    }
    return j;
}

/*function lire_resultat_trou(form){
var obj=$("q"+form);
var st=cookie("q"+form);
if(st!=""){
//var qst=GetParentByClass(obj,'ClassQuestion');
//var scr=GetParentByClass(qst,'ClassScreen');
obj.value=HtmlDecode(st.gsub('<BR','\n'));
//if(qst.visible()&&scr.visible()){
//    obj.focus();
//}
}
}*/

/*function lire_resultat_txtapp(form){
var aux="",i=1,j=0,val;
var st=cookie("q"+form);
if(st!=""){
while((aux=$("q"+form+standardize(i)))!=null){
val=st.substring(j,st.indexOf(";",j));
aux.selectedIndex=val;
j=st.indexOf(";",j)+1;
i++;
}
}
}*/

/*function lire_resultat_tri(form){
var st=cookie("q"+form);
if(st!=""){
Sortable.setSequence("q"+form+standardize(0),st.toArray().without(";"));
}
}*/

/*function lire_resultat_cur(form){
var st=cookie("q"+form);
var i=0;
var aux=window.P123_SCALES;
if(st!=""){
$("q"+form).value=st;
for(i=0;i<aux.length;i++){
if(""+aux[i].s_name=="q"+form){
aux[i].e_slider.style.display='';
aux[i].f_setValue(st);
if(typeof(aux[i].f_setInit)!="undefined"){
aux[i].f_setInit(st);
}
i=aux.length;
}
}
}
}*/

function ecrire_sign() {
    var aux="",st="",i=1;
    for(i=1;i<10;i++) {
        aux=$("sign"+i);
        if(aux!=null) {
            page_cookie1+="s"+i+"="+aux.value+"$$";
        }
    }
}

function ecrire_resultat_qcm(form) {
    var aux="",st="",i=1;
    while((aux=$("q"+standardize(form)+standardize(i)))!=null) {
        if(aux.checked==true) { st+="1"; } else { st+="0"; }
        i++;
    }
    page_cookie1+="q"+standardize(form)+"="+st+"$$";
}

function ecrire_resultat_trou(form) {
    var st=$("q"+form).value;
    page_cookie1+="q"+form+"="+st+"$$";
}

function ecrire_resultat_txtapp(form) {
    var aux="",st="",i=1;
    while((aux=$("q"+form+standardize(i)))!=null) {
        st+=aux.selectedIndex+";";
        i++;
    }
    page_cookie1+="q"+form+"="+st+"$$";
}

function ecrire_resultat_tri(form) {
    var st="";
    var aux=$("q"+form+standardize(0));
    if(aux) {
        st=Sortable.sequence(aux.id)+";";
        st=st.gsub(",",";");
    }
    page_cookie1+="q"+form+"="+st+"$$";
}


function temps(now) {
    return now.getSeconds()+60*now.getMinutes()+3600*now.getHours();
}

function cb2(gr2,num2,nb,qru) {
    var gr=""+standardize(gr2);
    var num=""+standardize(num2);
    if(""+num=="001") {
        document.write("<INPUT TYPE='hidden' NAME=var_"+gr+" id=var_"+gr+" value=0>");
    }
    if((nb==1)&&(qru)) {
        document.write("<INPUT TYPE='RADIO' NAME=q"+gr+" id=q"+gr+num+" onClick='controle_cb2(\""+gr+"\",\""+num+"\","+nb+");'>");
    } else {
        document.write("<INPUT TYPE='CHECKBOX' NAME=q"+gr+num+" id=q"+gr+num+" onClick='controle_cb2(\""+gr+"\",\""+num+"\","+nb+");'>");
    }
}

function txtarea(t,d,v,h,b) {
    document.write("<center><TEXTAREA ID='"+t+"' NAME='"+t+"' CLASS='ClassInput' ROWS='7' STYLE='width:75%;'");
    document.write(" wrap='PHYSICAL'><\/TEXTAREA><\/center>");
}

function CheckLen(Target,Deb,Jump,To,Bool) {
    StrLen=Target.value.length;
    if(StrLen>0) {
        ManagerJump(""+Deb+"",""+Jump+"",""+To+"",Bool)
        return true;
    } else {
        if(Bool) {
            ManagerJump(""+Deb+"",""+To+"",""+Jump+"",Bool)
        } else {
            ManagerJump(""+Deb+"",""+To+"",""+(parseInt(Deb)+1)+"",true)
        }
        return false;
    }
}

function standardize(nb) {
    var aux=""+nb;
    if(nb<10) { aux="00"+nb; }
    else if(nb<100) { aux="0"+nb; }
    return aux;
}

function nb_check(nb) {
    var nb_c=0,i=1,aux;
    while((aux=$("q"+standardize(nb)+standardize(i)))!=null) {
        if(aux.checked==true) { nb_c++; }
        i++;
    }
    return nb_c;
}

function check_qcm(id,fn) {
    Event.observe($('s'+id+''),'click',new Function("$('"+id+"').checked=!$('"+id+"').checked;"+fn));
    Event.observe($(id),'click',new Function(fn));
}

function lecture_qcm(form) {
    var num_screen=GetParentByClass($("q"+standardize(form)+"001"),"ClassScreen").id.replace("ClassScreen","");
    var is_visible=false;
    if(""+typeof (P123_Historik)=="undefined") {
        if(GetParentByClass($("q"+standardize(form)+"001"),"ClassQuestion").visible()) { is_visible=true; }
    } else {
        if((GetParentByClass($("q"+standardize(form)+"001"),"ClassQuestion").visible())&&((","+P123_Historik.join()+",").indexOf(","+num_screen+",")>=0)) { is_visible=true; }
    }
    if(is_visible) {
        var aux="",i=1,n=0,aux1="",nnj=0,k=0;
        while($("q"+standardize(form)+standardize(i))!=null) { i++; }
        for(j=1;j<i;j++) {
            if($("q"+standardize(form)+standardize(j)).checked==true) {
                nn=1;
                for(k=0;k<(j-1);k++) { nn=nn*2; }
                n+=nn;
            }
        }
        while(n>15) {
            if(Math.ceil(n/16)==(n/16)) { aux=0;n=n/16; }
            else { aux=(n/16-(Math.ceil(n/16)-1))*16;n=Math.ceil(n/16)-1; }
            if(aux==15) { aux1="F"+aux1; }
            else if(aux==14) { aux1="E"+aux1; }
            else if(aux==13) { aux1="D"+aux1; }
            else if(aux==12) { aux1="C"+aux1; }
            else if(aux==11) { aux1="B"+aux1; }
            else if(aux==10) { aux1="A"+aux1; }
            else { aux1=""+aux+aux1; }
        }
        if(n==15) { aux1="F"+aux1; }
        else if(n==14) { aux1="E"+aux1; }
        else if(n==13) { aux1="D"+aux1; }
        else if(n==12) { aux1="C"+aux1; }
        else if(n==11) { aux1="B"+aux1; }
        else if(n==10) { aux1="A"+aux1; }
        else { aux1=""+n+aux1; }
        aux1=form+carac1+aux1+carac2;
        return aux1;
    } else {
        return "";
    }
}

function lecture_trou(form) {
    var num_screen=GetParentByClass($("q"+form),"ClassScreen").id.replace("ClassScreen","");
    var is_visible=false;
    if(""+typeof (P123_Historik)=="undefined") {
        if(GetParentByClass($("q"+form),"ClassQuestion").visible()) { is_visible=true; }
    } else {
        if((GetParentByClass($("q"+form),"ClassQuestion").visible())&&((","+P123_Historik.join()+",").indexOf(","+num_screen+",")>=0)) { is_visible=true; }
    }
    if(is_visible) {
        var aux=form+carac1;
        aux+=$("q"+form).value+carac2;
        return aux;
    } else {
        return "";
    }
}

function lecture_txtapp(form) {
    var num_screen=GetParentByClass($("q"+form+"001"),"ClassScreen").id.replace("ClassScreen","");
    var is_visible=false;
    if(""+typeof (P123_Historik)=="undefined") {
        if(GetParentByClass($("q"+form+"001"),"ClassQuestion").visible()) { is_visible=true; }
    } else {
        if((GetParentByClass($("q"+form+"001"),"ClassQuestion").visible())&&((","+P123_Historik.join()+",").indexOf(","+num_screen+",")>=0)) { is_visible=true; }
    }
    if(is_visible) {
        var aux="",i,j=0,aux1;
        aux=form+carac1;
        while((aux1=$("q"+form+standardize(j+1)))!=null) {
            j++;
        }
        for(i=1;i<(j+1);i++) {
            aux1=$("q"+form+standardize(i));
            aux+=aux1.selectedIndex;
            if(i!=j) { aux+=carac1; } else { aux+=carac2; }
        }
        return aux;
    } else {
        return "";
    }
}

function lecture_tri(form) {
    var num_screen=GetParentByClass($("q"+form+"000"),"ClassScreen").id.replace("ClassScreen","");
    var is_visible=false;
    if(""+typeof (P123_Historik)=="undefined") {
        if(GetParentByClass($("q"+form+"000"),"ClassQuestion").visible()) { is_visible=true; }
    } else {
        if((GetParentByClass($("q"+form+"000"),"ClassQuestion").visible())&&((","+P123_Historik.join()+",").indexOf(","+num_screen+",")>=0)) { is_visible=true; }
    }
    if(is_visible) {
        var aux=form+carac1;
        var aux1=$("q"+form+"000");
        if(aux1) {
            aux+=Sortable.sequence(aux1.id)+""+carac2;
            aux=aux.gsub(",",carac1);
        }
        return aux;
    } else {
        return "";
    }
}

function lire_resultat_qcm(form2) {
    var aux="";
    var i;
    var form=standardize(form2);
    var st=cookie("q"+form);
    for(i=1;i<=st.length;i++) {
        if(st.substring(i-1,i)=="1") {
            try {
                $("q"+form+standardize(i)).click();
            } catch(e) { }
        }
    }
}

function question(ob) {
    var i=1,j=1,val=0;
    var aux=null;
    while(val==0) {
        while(((aux=$("q"+i+standardize(j)))!=null)&&(val==0)) {
            if(aux==ob) { val=i; }
            j++;
        }
        i++;
        j=1;
    }
    return val;
}

function test_key_pressed(sign,type,evt) {
    var evt=evt||window.event;
    var key=evt.keyCode||evt.which;
    if((key==13)&&(sign.length>0)) {
        if($(""+sign)!=null) {
            $(""+sign).focus();
        }
    }
    if((key==9)||(key==37)||(key==39)||(key==8)) {
        //tab, fleche gauche, droite, backspace
        return true;
    }
    if(type==1) {
        var keychar=String.fromCharCode(key);
        switch(keychar) {
            case ',': case '.': case '+': case '-':
                return true;
                break;
            default:
                reg=new RegExp(/\d/);
                return reg.test(keychar);
                break;
        }
    }
    return true;
}

function ActionQst(q,a) {
    var qst=P123_Qst[q];
    switch(a) {
        case 'hide':
            qst.hide();
            break;
        case 'show':
            qst.show();
            break;
        default:
            qst.select('input').invoke(a);
            qst.select('textarea').invoke(a);
            qst.select('select').invoke(a);
            ActionElement(qst.select('span'),a);
            ActionElement(qst.select('td.ClassSubTitle'),a);
            ActionElement(qst.select('div.ClassTitle'),a);
            qst.disabled=a.include('disable');
            break;
    }
}

function ValueQst(q) {
    var r=new Array();
    var qst=P123_Qst[q];
    var t=qst.select('td.'+qst.id.gsub('ClassQuestion','ClassTdItem')).length;
    var e=qst.select('input[type="checkbox"]');
    e.push(qst.select('input[type="radio"]'));
    e=e.compact().flatten().compact();
    e.each(function(s,index) {
        if(s.checked) {
            if(t==0) {
                r.push(index+1);
            } else {
                r.push((index%t)+1);
            }
        }
    });
    if(r.length!=0) {
        return r;
    }
    e=qst.select('input[type="text"]').each(function(s) {
        r.push($F(s));
    });
    if(r.length!=0) {
        return r;
    }
    e=qst.select('textarea').each(function(s) {
        r.push($F(s));
    });
    if(r.length!=0) {
        return r;
    }
    e=qst.select('input[type="hidden"]').each(function(s) {
        if(!s.id.include('var_')) {
            r.push($F(s));
        }
    });
    return r;
}

function ActionSubQst(q,s,a) {
    var qst=P123_Qst[q];
    var sqst=qst.select('td.ClassSubTitle')[s].ancestors()[0];
    sqst.select('input').invoke(a);
    sqst.select('textarea').invoke(a);
    sqst.select('select').invoke(a);
    ActionElement(sqst.select('span'),a);
    ActionElement(sqst.select('td.ClassSubTitle'),a);
    ActionElement(sqst.select('div.ClassTitle'),a);
}

function ValueSubQst(q,s) {
    var r=new Array();
    var qst=P123_Qst[q];
    var sqst=qst.select('td.ClassSubTitle')[s].ancestors()[0];
    var t=sqst.select('td.'+qst.id.gsub('ClassQuestion','ClassTdItem')).length;
    var e=sqst.select('input[type="checkbox"]');
    e.push(sqst.select('input[type="radio"]'));
    e=e.compact().flatten().compact();
    e.each(function(s,index) {
        if(s.checked) {
            if(t==0) {
                r.push(index+1);
            } else {
                r.push((index%t)+1);
            }
        }
    });
    if(r.length!=0) {
        return r;
    }
    e=sqst.select('input[type="text"]').each(function(s) {
        r.push($F(s));
    });
    if(r.length!=0) {
        return r;
    }
    e=sqst.select('textarea').each(function(s) {
        r.push($F(s));
    });
    if(r.length!=0) {
        return r;
    }
    e=sqst.select('input[type="hidden"]').each(function(s) {
        if(!s.id.include('var_')) {
            r.push($F(s));
        }
    });
    return r;
}

function ActionElement(e,a) {
    e.each(function(s) {
        switch(a) {
            case 'disable':
                s.disabled=true;
                if(s.tagName.toLowerCase()=='span') {
                    s.setStyle({ cursor: 'text' });
                }
                break;
            case 'enable':
                s.disabled=false;
                if(s.tagName.toLowerCase()=='span') {
                    s.setStyle({ cursor: 'pointer' });
                }
                break;
            case 'show':
                s.show();
                break;
            case 'hide':
                s.hide();
                break;
        }
    });
}

function aicc_getparam() {
    if(""+aicc_url!="") {
        var xhr_object=get_ajax_xmlhttp();
        if(xhr_object==null) {
            alert("ERROR : no XMLHTTP, please contact administrator");
            return;
        }
        xhr_object.onreadystatechange=function() {
            if(xhr_object.readyState==4) {
                if(xhr_object.responseText.indexOf("error=0")>0) { is_aicc=true; }
                if(document.getElementById("recup_cookie_div")) {
                    document.getElementById("recup_cookie_div").style.visibility="hidden";
                    document.getElementById("recup_cookie_div").style.display="none";
                }
            }
        }
        xhr_object.open("POST",""+aicc_url,true);
        xhr_object.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        xhr_object.send("session_id="+aicc_sid+"&command=getparam&version=2.2");
    } else {
        if(document.getElementById("recup_cookie_div")) {
            document.getElementById("recup_cookie_div").style.visibility="hidden";
            document.getElementById("recup_cookie_div").style.display="none";
        }
    }
}

function aicc_putparam(aicc_score,aicc_time) {
    var xhr_object=get_ajax_xmlhttp();
    if(xhr_object==null) {
        alert("ERROR : no XMLHTTP, please contact administrator");
        return;
    }
    xhr_object.onreadystatechange=function() {
        if(xhr_object.readyState==4) {
            aicc_exitau();
        }
    }
    var aicc_data;
    aicc_data="[core]%0D%0Alesson_location%3d%0D%0Alesson_status%3dc%0D%0Ascore%3d"+aicc_score+"%0D%0Atime%3d"+aicc_time;
    xhr_object.open("POST",""+aicc_url,true);
    xhr_object.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xhr_object.send("session_id="+aicc_sid+"&command=putparam&version=2.2&AICC_Data="+aicc_data);
}

function aicc_exitau() {
    var xhr_object=get_ajax_xmlhttp();
    if(xhr_object==null) {
        alert("ERROR : no XMLHTTP, please contact administrator");
        return;
    }
    xhr_object.onreadystatechange=function() {
        if(xhr_object.readyState==4) {
            redirect_quest();
        }
    }
    xhr_object.open("POST",""+aicc_url,true);
    xhr_object.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xhr_object.send("session_id="+aicc_sid+"&command=exitau&version=2.2");
}

function encode_like_java(str) {
    var str2="";
    var i;
    for(i=0;i<str.length;i++) {
        str2=str2+str.charCodeAt(i).toString(16);
    }
    return str2;
}

function redirect_quest() {
    document.location.href=""+url_fin;
}

function post_lescrip3_ajax() {
    var alang_js2="";
    if(typeof (alang_js)!="undefined") { alang_js2=""+alang_js; }
    else { alang_js2=get_location_lang(document.location); }

    var p1v_js2="";
    if(typeof (t_moins_vide)!="undefined") { p1v_js2=""+t_moins_vide; }

    if(document.getElementById("recup_cookie_div")&&(p1v_js2=="")) {
        document.getElementById("recup_cookie_div").style.visibility="visible";
        document.getElementById("recup_cookie_div").style.display="block";
        document.body.scroll="no";
    }

    var xhr_object=get_ajax_xmlhttp();
    if(xhr_object==null) {
        alert("ERROR : no XMLHTTP, please contact administrator");
        return;
    }
    xhr_object.onreadystatechange=function() {
        if(xhr_object.readyState==4) {
            var result=xhr_object.responseText;
            //alert("result="+result);
            var aicc_score="";
            var aicc_time="00:00:00";
            if(p1v_js2=="") {
                if(result.indexOf("erreur="+String.fromCharCode(13))== -1) {
                    //un erreur est survenu
                    alert("AN ERROR HAS OCCURED ("+xhr_object.status+") : "+xhr_object.getAllResponseHeaders()+" / "+result);
                }
                if(result.indexOf("ID_sign=")>0) {
                    ID_sign=result.substring(result.indexOf("ID_sign=")+8);
                    if(ID_sign.indexOf(String.fromCharCode(13))>0) {
                        ID_sign=ID_sign.substring(0,ID_sign.indexOf(String.fromCharCode(13))-1);
                    }
                }
                if(result.indexOf("score=")>0) {
                    aicc_score=result.substring(result.indexOf("score=")+6);
                    if(aicc_score.indexOf(String.fromCharCode(13))>0) {
                        aicc_score=aicc_score.substring(0,aicc_score.indexOf(String.fromCharCode(13))-1);
                    }
                }
                if(url_fin.indexOf("?")>0) {
                    url_fin=url_fin+"&alang="+alang_js2+"&";
                } else {
                    url_fin=url_fin+"?alang="+alang_js2+"&";
                }
                if($("is_ajourner").value=="true") {
                    url_fin=url_fin+"ID_sign=-15";
                } else {
                    url_fin=url_fin+"ID_sign="+ID_sign;
                }

                if((is_aicc)&&($("is_ajourner").value!="true")) {
                    var i;
                    i=temps_mis/3600;
                    if(i<10) { aicc_time="0"+i+":"; } else { aicc_time=""+i+":"; }
                    temps_mis=temps_mis-i*3600;
                    i=temps_mis/60;
                    if(i<10) { aicc_time+="0"+i+":"; } else { aicc_time+=""+i+":"; }
                    i=temps_mis-i*60;
                    if(i<10) { aicc_time+="0"+i; } else { aicc_time+=""+i; }
                    aicc_putparam(aicc_score,aicc_time);
                } else {
                    redirect_quest()
                }
            }
        }
    }
    var post_url=""+document.location;
    if(post_url.indexOf("?")>0) { post_url=post_url.substring(0,post_url.indexOf("?")); }
    post_url=post_url.substring(0,post_url.lastIndexOf("/")+1);
    post_url=post_url+webquizz_path+"lescript3.aspx?launch="+launch+"&current="+current_screen;
    if(document.getElementById('id_doublon')) {
        post_url+="&id_doublon="+document.getElementById('id_doublon').value;
    }
    xhr_object.open("POST",""+post_url,true);
    xhr_object.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xhr_object.send("f="+encode_like_java(file_name2)+"&p1="+encode_like_java(traite_for_html_js(t_moins))+"&p2="+encode_like_java(traite_for_html_js(t_plus))+"&ID_sign="+ID_sign+"&lg="+alang_js2+"&p1v="+encode_like_java(p1v_js2));
}

function get_location_lang(m) {
    var n=""+m;
    var lg="";
    if(n.lastIndexOf("?")>0) {
        n=n.substring(0,n.lastIndexOf("?"));
    }
    n=n.substring(n.lastIndexOf("/")+1,n.lastIndexOf("."));
    if(n.lastIndexOf(".")>0) {
        lg=n.substring(n.lastIndexOf(".")+1);
    }
    return lg;
}

function ajourner() {
    $("is_ajourner").value="true";
    if(controle_final()) {
        post_lescrip3_ajax();
    }
}

function envoyer() {
    if(controle_final()) {
        post_lescrip3_ajax();
    }
}

function traite_table_name(table_name_tmp) {
    var table_name=""+table_name_tmp;
    if(table_name.indexOf("./")==0) {
        table_name=table_name.substring(3)
    }
    while(table_name.indexOf("/./")>=0) { table_name=table_name.replace("/./","/"); }
    while(table_name.indexOf("../")>=0) { table_name=table_name.replace("../","_"); }
    while(table_name.indexOf("/")>=0) { table_name=table_name.replace("/","_"); }
    while(table_name.indexOf(" ")>=0) { table_name=table_name.replace(" ","_"); }
    while(table_name.indexOf("-")>=0) { table_name=table_name.replace("-","_"); }
    while(table_name.indexOf("|")>=0) { table_name=table_name.replace("|","_"); }
    return table_name.toLowerCase();
}


//re-remplissage après ajournement ou crash
var tab_cookie_recup;
var is_scroll_before=true;
var current_screen=0;
function recup_cookie(num) {
    if(""+num=="") {
        if((""+page_cookie!="")&&(page_cookie.indexOf("$$")>=0)) {
            if(document.getElementById("recup_cookie_div2")) {
                document.getElementById("recup_cookie_div2").innerHTML="";
                document.getElementById("recup_cookie_div2").style.width="0px";
                document.getElementById("recup_cookie_div2").style.backgroundColor="#C0C0C0";
            }
            lire_resultat(true);
        } else {
            if(document.getElementById("recup_cookie_div")) {
                document.getElementById("recup_cookie_div").style.visibility="hidden";
                document.getElementById("recup_cookie_div").style.display="none";
            }
        }
    } else {
        document.body.scrollTop=0;
        document.body.scrollLeft=0;
        document.documentElement.scrollTop=0;
        document.documentElement.scrollLeft=0;
        if(""+document.body.scroll=="no") { is_scroll_before=false; }
        document.body.scroll="no";
        if(document.getElementById("recup_cookie_div2")) {
            document.getElementById("recup_cookie_div2").innerHTML="<img src=\""+webquizz_path+"\\images\\WebResource.axd.gif\"/>";
        }
        var xhr_object=get_ajax_xmlhttp();
        if(xhr_object==null) {
            alert("ERROR : no XMLHTTP, please contact administrator");
            return;
        }
        xhr_object.onreadystatechange=function() {
            if(xhr_object.readyState==4) {
                page_cookie=""+xhr_object.responseText;
                //alert("page_cookie="+page_cookie.substring(200));
                if(document.getElementById("recup_cookie_div2")) {
                    document.getElementById("recup_cookie_div2").innerHTML="";
                    document.getElementById("recup_cookie_div2").style.width="0px";
                    document.getElementById("recup_cookie_div2").style.backgroundColor="#C0C0C0";
                }
                lire_resultat(true);
            }
        }
        xhr_object.open("POST",""+webquizz_path+"/ajax/ajax.aspx",true);
        xhr_object.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        var data="table_name="+traite_table_name(strPath_var)+"&todo=get_adjourn&ID_sign="+num;
        xhr_object.send(data);
    }
}

var recup_cookie_div2_is_null="1";
function lire_resultat(recup) {
    if(recup==true) {
        current_screen=0;
        tab_cookie_recup=page_cookie.split("$$");
        if(document.getElementById("recup_cookie_div2")) {
            recup_cookie_div2_is_null="0";
        }
        lire_resultat_progress(0);
    }
}

function find_disabled_parent(obj) {
    var disabled_obj=null;
    //on recherche le TR parent
    while((""+obj!="null")&&(""+obj!="undefined")&&(obj.tagName.toLowerCase()!="tr")) { obj=obj.parentNode; }
    if((""+obj!="null")&&(""+obj!="undefined")) {
        if(obj.disabled) { disabled_obj=obj;obj.disabled=false; }
    }
    //on recherche le TABLE parent
    while((""+obj!="null")&&(""+obj!="undefined")&&(obj.tagName.toLowerCase()!="table")) { obj=obj.parentNode; }
    if((""+obj!="null")&&(""+obj!="undefined")) {
        if(obj.disabled) { disabled_obj=obj;obj.disabled=false; }
    }
    return disabled_obj;
}

function lire_resultat_progress(i) {
    var i,j,k,t,v,tn,tnt,obj,typeq,c,obj_disabled;
    if(recup_cookie_div2_is_null=="0") {
        document.getElementById("recup_cookie_div2").style.width=""+parseInt(document.getElementById("recup_cookie_div2").parentNode.childNodes[0].offsetWidth*(i+1)/tab_cookie_recup.length)+"px";
    }
    if(document.getElementById("recup_cookie_div")) {
        document.getElementById("recup_cookie_div").style.visibility="visible";
        document.getElementById("recup_cookie_div").style.display="block";
    }
    var cookie_recup=""+tab_cookie_recup[i];
    if(cookie_recup.indexOf("=")>0) {
        v=cookie_recup.substring(cookie_recup.indexOf("=")+1);
        t=cookie_recup.substring(0,1).toLowerCase();
        //j=cookie_recup.substring(1).split("=")[0];   //ex : j=059
        j=cookie_recup.substring(1,cookie_recup.indexOf("="));
        while(j.substring(0,1)=="0") { j=j.substring(1); }   //on supprime les "0" en debut car parseInt("059")=5 et parseInt("59")=59
        j=parseInt(j);
        //alert("tjv="+t+" / "+j+" / "+v);
        if(t=="i") {
            if(""+v!="") {
                if(!isNaN(v)) { current_screen=parseInt(v); }
            }
        } else if(t=="s") {
            obj=$("sign"+j);
            if((typeof (obj)=="object")&&(""+obj!="null")) {
                tn=obj.tagName.toLowerCase();
                tnt=obj.type;
                if(tn=="select") { obj.value=v; }
                else if((tn=="input")&&(tnt=="radio")) { obj.value=v; }
                else if((tn=="input")&&(tnt=="checkbox")) { obj.value=v; }
                else { obj.value=HtmlDecode(v); }
            }
        } else if(t=="q") {
            typeq=""
            obj=$("var_"+standardize(j));
            if((""+obj!="null")&&(""+obj!="undefined")) {
                typeq="QCM";
            }
            if(""+typeq=="") {
                obj=$("q"+j+"001");
                if((""+obj!="null")&&(""+obj!="undefined")) {
                    if(obj.tagName.toLowerCase()=="select") { typeq="TXTAPP"; }
                }
            }
            if(""+typeq=="") {
                obj=$("q"+j);
                if((typeof (obj)!="object")||(""+obj=="null")) { obj=$("q"+standardize(j)); }
                if((""+obj!="null")&&(""+obj!="undefined")) {
                    if((obj.tagName.toLowerCase()=="input")&&(""+obj.type.toLowerCase()=="text")&&((""+obj.onfocus).indexOf("P123_CalendarDateFormat")>0)) { typeq="DATE"; }
                    else if((obj.tagName.toLowerCase()=="input")&&(""+obj.type.toLowerCase()=="text")) { typeq="TXT"; }
                    else if(obj.tagName.toLowerCase()=="textarea") { typeq="TXT"; }
                    else if((obj.tagName.toLowerCase()=="input")&&(""+obj.type.toLowerCase()=="hidden")) { typeq="CURSOR"; }
                }
            }
            if(""+v!="") {
                if(""+typeq=="QCM") {
                    //QCM
                    for(k=1;k<=v.length;k++) {
                        if(v.substring(k-1,k)=="1") {
                            try {
                                obj=$("q"+standardize(j)+standardize(k));
                                obj_disabled=find_disabled_parent(obj); //recherche le TR ou TABLE parent qui est disabled et le enabled
                                obj.click();
                                if(obj_disabled!=null) { obj_disabled.disabled=true; }
                            } catch(e) { }
                        }
                    }
                } else if(""+typeq=="TXTAPP") {
                    //TXTAPP
                    c=v.split(";")
                    for(k=0;k<c.length;k++) {
                        try {
                            $("q"+j+standardize(k+1)).selectedIndex=c[k];
                        } catch(e) { }
                    }
                } else if(""+typeq=="TXT") {
                    //TXTTROU ou TXTAREA
                    obj.value=HtmlDecode(v);
                } else if(""+typeq=="DATE") {
                    //DATE
                    obj.value=v;
                } else if(""+typeq=="CURSOR") {
                    //CURSOR
                    var aux=window.P123_SCALES;
                    obj.value=v;
                    for(k=0;k<aux.length;k++) {
                        if(""+aux[k].s_name=="q"+j) {
                            aux[k].e_slider.style.display='';
                            aux[k].f_setValue(v);
                            if(typeof (aux[k].f_setInit)!="undefined") {
                                aux[k].f_setInit(v);
                            }
                            k=aux.length;
                        }
                    }
                }
            }
        }

        //puisque la question est dans le recup cook, elle a été affiché, donc on la montre (cela controurne les sauts et les filtres)
        if((t=="q")&&(typeq!="")&&(obj!=null)) {
            GetParentByClass(obj,"ClassQuestion").show();
        }
    }
    if(i<tab_cookie_recup.length-1) {
        setTimeout("lire_resultat_progress("+(i+1)+")",10);
    } else {
        if(document.getElementById("recup_cookie_div")) {
            document.getElementById("recup_cookie_div").style.visibility="hidden";
            document.getElementById("recup_cookie_div").style.display="none";
        }
        if(is_scroll_before==true) {
            document.body.scroll="yes";
        }
        //if (""+current_screen!="") {
        try {
            InitScreen(parseInt(current_screen));
            if(typeof (CheckAllFiltre)!='undefined') { CheckAllFiltre(); }
            if(typeof (ReportQst)!='undefined') { ReportQst(); }
        }
        catch(e) { }
        //}
    }
}
//fin re-remplissage

function get_nbrep_by_row(gr) {
    var o=$("var_"+standardize(gr)).up("div.ClassQuestion");
    var p123qst2=o.select('input[class_l=c'+standardize(gr)+']');
    var nb=0;
    var i;
    for(i=0;i<p123qst2.length;i++) {
        if(p123qst2[i].checked) { nb+=1; }
    }
    return nb;
}
function get_nbrep_by_col(gr,num) {
    var o=$("var_"+standardize(gr)).up("div.ClassQuestion");
    var p123qst2=o.select('input[class_c=c'+standardize(num)+']');
    var nb=0;
    var i;
    for(i=0;i<p123qst2.length;i++) {
        if(p123qst2[i].checked) { nb+=1; }
    }
    return nb;
}

function controle_date_interval(d,f,min,max) {
    //d=date à controler
    //f=format de la date (ex : dd/mm/yyyy)
    //min=date min
    //max=date max
    //valeur en retour, -2=erreur de format, -1=date < min, 0=date entre min et max inclus, +1=supérieur au max
    var i,d_new,min_new,max_new;
    if(""+d=="") { return "0"; }
    if(f.length!=10) { return "-2"; }
    if(d.length!=10) { return "-2"; }
    if((min.length!=10)&&(min.length!=0)) { return "-2"; }
    if((max.length!=10)&&(max.length!=0)) { return "-2"; }
    if(d.split("/").length!=f.split("/").length) { return "-2"; }
    for(i=0;i<d.split("/").length;i++) { if(d.split("/")[i].length!=f.split("/")[i].length) { return "-2"; } }
    //maintenant le format est bon, reste a controler si on  est dans l'interval
    //on redéfinie les date au format yyyymmdd pour permettre une comparaison facile
    d_new="";
    min_new="";
    max_new="";
    for(i=0;i<11;i++) {
        if(""+f.substring(i,i+1)=="y") {
            d_new=d_new+d.substring(i,i+1);
            if(min!="") { min_new+=min.substring(i,i+1); }
            if(max!="") { max_new+=max.substring(i,i+1); }
        }
    }
    for(i=0;i<11;i++) {
        if(""+f.substring(i,i+1)=="m") {
            d_new=d_new+d.substring(i,i+1);
            if(min!="") { min_new+=min.substring(i,i+1); }
            if(max!="") { max_new+=max.substring(i,i+1); }
        }
    }
    for(i=0;i<11;i++) {
        if(""+f.substring(i,i+1)=="d") {
            d_new=d_new+d.substring(i,i+1);
            if(min!="") { min_new+=min.substring(i,i+1); }
            if(max!="") { max_new+=max.substring(i,i+1); }
        }
    }
    if(min!="") {
        if(d_new<min_new) { return "-1"; }
    }
    if(max!="") {
        if(d_new>max_new) { return "1"; }
    }
    return "0";
}

function ReportQst() {
    var v="";
    var o=null;
    var e=$$('span.ClassReportQst').each(function(s) {
        o=s.down(0);
        if(o.className.include('_')) {
            v=''+ReportValueSubQst(o.className.split('_')[0],o.className.split('_')[1]);
        } else {
            v=''+ReportValueQst(o.className);
        }
        o.update(v.escapeHTML());
    });
}

function ReportValueQst(q) {
    var v="";
    var r=new Array();
    var qst=P123_Qst[q];
    var e=qst.select('input[type="checkbox"]');
    e.push(qst.select('input[type="radio"]'));
    e=e.compact().flatten().compact();
    e.each(function(s,index) {
        if(s.checked) {
            v=($('s'+s.id))?$('s'+s.id):s.ancestors()[0];
            v=HtmlDecode(v.innerHTML);
            v=v.stripScripts();
            v=v.stripTags();
            v=v.gsub(String.fromCharCode(13),"");
            v=v.gsub(String.fromCharCode(10),"");
            r.push(v);
        }
    });
    if(r.length!=0) {
        if(r.length==1) {
            return r;
        } else {
            return r.join(', ');
        }
    }
    e=qst.select('input[type="text"]').each(function(s) {
        r.push($F(s));
    });
    if(r.length!=0) {
        return r;
    }
    e=qst.select('textarea').each(function(s) {
        r.push($F(s));
    });
    if(r.length!=0) {
        return r;
    }
    e=qst.select('input[type="hidden"]').each(function(s) {
        if(!s.id.include('var_')) {
            r.push($F(s));
        }
    });
    return r;
}

function ReportValueSubQst(q,s) {
    var v="";
    var r=new Array();
    var qst=P123_Qst[q];
    var sqst=null;
    var t=null;
    if(qst.select('td.ClassSubTitle').length!=0) {
        //Question Groupé
        sqst=qst.select('td.ClassSubTitle')[s].ancestors()[0];
        t=qst.select('td.'+qst.id.gsub('ClassQuestion','ClassTdItem')).length;
    } else {
        //Question Signalètique
        if(s=='3') {
            //Sexe
            if(!$('QstItem0')) {
                if($('sign'+s).tagName.toLowerCase()=="select") {
                    return $('sign'+s).options[$('sign'+s).selectedIndex].text;
                } else {
                    return $('sign'+s).value;
                }
            }
            sqst=$('QstItem0').select('table')[0];
            if(sqst==null) {
                return $('sign'+s).value;
            }
        } else {
            //Autre
            return $('sign'+s).value;
        }
    }
    var e=sqst.select('input[type="checkbox"]');
    e.push(sqst.select('input[type="radio"]'));
    e=e.compact().flatten().compact();
    e.each(function(s,index) {
        if(s.checked) {
            if(qst.select('td.ClassSubTitle').length!=0) {
                //Question Groupé
                v=qst.select('td.'+qst.id.gsub('ClassQuestion','ClassTdItem'));
                if(t==0) {
                    v=v[index];
                } else {
                    v=v[index%t];
                }
            } else {
                //Question Signalètique
                v=($('s'+s.id))?$('s'+s.id):s.ancestors()[0];
            }
            v=HtmlDecode(v.innerHTML);
            v=v.stripScripts();
            v=v.stripTags();
            v=v.gsub(String.fromCharCode(13),"");
            v=v.gsub(String.fromCharCode(10),"");
            r.push(v);
        }
    });
    if(r.length!=0) {
        if(r.length==1) {
            return r;
        } else {
            return r.join(', ');
        }
    }
    e=sqst.select('input[type="text"]').each(function(s) {
        r.push($F(s));
    });
    e=sqst.select('textarea').each(function(s) {
        r.push($F(s));
    });
    if(r.length!=0) {
        return r;
    }
    if(r.length!=0) {
        return r;
    }
    e=sqst.select('input[type="hidden"]').each(function(s) {
        if(!s.id.include('var_')) {
            r.push($F(s));
        }
    });
    return r;
}

function AutocompleterValue(element,entry) {
    var o=$$('input.'+element.className);
    var i=0;
    var j=1;
    var v='';
    while(o[i].id!=element.id) {
        v+=o[i].readAttribute('q')+'$$'+encodeURIComponent(o[i].value).gsub("'","\'")+'$$';
        i+=1;
        j=i;
    } for(i=j;i<o.length;i++) {
        if(o[i].id!=element.id) {
            o[i].value='';
        }
    }
    v='q='+element.readAttribute('q')+'&v='+encodeURIComponent($F(element)).gsub("'","\'")+'&l='+P123_Lang+'&r='+v;
    return v;
}

function AutocompleterValueByHeader(element,entry) {
    var o=$$('input.'+element.className);
    var i=0;
    var j=1;
    var v='';
    while(o[i].id!=element.id) {
        v+=o[i].readAttribute('q')+'$$'+encodeURIComponent(o[i].value).gsub("'","\'")+'$$';
        i+=1;
        j=i;
    }
    v='q='+element.readAttribute('q')+'&v='+encodeURIComponent($F(element)).gsub("'","\'")+'&l='+P123_Lang+'&r='+v;
    return v;
}

function GoToScreen(i) {
    $('ClassScreen'+current_screen).hide();
    var j=0;
    for(j=(current_screen+1);j<i;j++) {
        $('ClassScreen'+j).hide();
        current_screen+=1;
    }
    if($('ClassScreen'+(current_screen+1))) {
        $('ClassScreen'+(current_screen+1)).show();
        $('ClassScreen'+(current_screen+1)).select('.ClassQuestion').invoke('show');
    }
}

function CheckCurrentScreenQst(q) {
    return GetParentByClass(P123_Qst[q],'ClassScreen').id=='ClassScreen'+current_screen;
}

function CheckQstInCurrentScreen(q) {
    return parseInt(GetParentByClass(P123_Qst[q],'ClassScreen').id.replace('ClassScreen',''))<=current_screen;
}

function traite_for_html_js(s) {
    var i,s_return,c,carac,c_plus,c_plus_plus,j;
    s_return="";
    for(i=0;i<s.length;i++) {
        c=s.charCodeAt(i);
        carac="";
        if((c==240)||(c==254)) {
            //il s'agit des caractères de séparation des questions, on ne fait rien
            carac=String.fromCharCode(c);
        } else if(c<128) {
            if(c==34) { carac="&#34;"; }
            else if(c==39) { carac="&#39;"; }
            else if(c<32) { carac="&#"+c+";"; }
            else if(c==58) { carac="&#58;"; }
            else { carac=String.fromCharCode(c); }
        } else if((c>=192)&&(c<=223)&&(i<s.length-1)) {
            c_plus=s.charCodeAt(i+1);
            if((c_plus>=128)&&(c_plus<=191)) {
                carac="&#"+((c-192)*64+c_plus-128)+";"
                i=i+1;//on viens de lire 2 caractères, il faudra donc en sauté un
            } else {
                carac="&#"+c+";";
            }
        } else if((c>=224)&&(c<=255)&&(i<s.length-2)) {
            c_plus=s.charCodeAt(i+1);
            c_plus_plus=s.charCodeAt(i+2);
            if((c_plus>=128)&&(c_plus<=191)&&(c_plus_plus>=128)&&(c_plus_plus<=191)) {
                j=(c-240)*4096;
                if(j<0) { j=(c-224)*4096; }
                j=j+(c_plus-128)*64;
                j=j+(c_plus_plus-128);
                carac="&#"+j+";";
                i=i+2;//on viens de lire 3 caractères, il faudra donc en sauté un
            } else {
                carac="&#"+c+";";
            }
        } else {
            carac="&#"+c+";";
        }
        s_return=s_return+carac;
    }
    return s_return;
}

function UnicodetoString_js(str) {
    var s_return,i,j,n;
    s_return=""+str;
    i=s_return.indexOf("&#");
    j=s_return.indexOf(";",i);
    while((i>=0)&&(j>i)) {
        n=s_return.substring(i+2,j);
        s_return=s_return.substring(0,i)+String.fromCharCode(parseFloat(n))+s_return.substring(j+1);
        i=s_return.indexOf("&#");
        j=s_return.indexOf(";",i);
    }
    return s_return;
}