bw=new Browser();

// Object: SoftDrawerTree
function SoftDrawerTree(name,def)
{
    this.def=def;
    this.format=def.format;
    this.name=name;
    this.num=0;
    this.anim_ref=0;
    this.id='SDTree'+name;
    this.nodes=[];
    this.root= { "id":name+"_i"};
    this.root.level_format=this.format;
    this.root.format=this.format;
    this.root.sub=def.sub;
    eval("window."+this.id+"=this");
    if (!bw) bw=new Browser();
    pldImg([def.format.e_image,def.format.c_image,def.format.i_image,def.format.b_image]);

    // Function: init
    this.init=function()
    {
        this.code='';
        this.back=new DHTMLObject(this.name+'_back');
        this._init(null,this.root,-1,0);
        document.write(this.back.draw(this.format.left,this.format.top,this.format.width,this.format.height,this.getp(this.root,"back_bgcolor",0),0,1,this.getp(this.root,"back_class",0),this.code,0));
        this.back.init();
        if (this.format.dont_resize_back)this.back.show();        
    };
    
    // Function: _init
    this._init=function(parent,node,lvl,num)
    {
        if(!node) return;
        node.parent=parent;
        node.id=node.id||node.parent.id+"_"+num;
        node.lvl=lvl;
        node.ind=(this.num++)-1;
        if(node!=this.root) {
            this.nodes[node.id]=node;
            var s=this.init_item(node);
            node.obj=new DHTMLObject(node.id);
            this.code+=(node.obj.draw(0,0,this.getp(node,"width","100%"),0,this.getp(node,"bgcolor",0),0,(1000-this.num),this.getp(node,"div_class",0),s));
        }
        if(node.sub) for(var i=0;i<node.sub.length;i++) this._init(node,node.sub[i], lvl+1,i);
    };

    // Function: getp
    this.getp=function(n,name,def,nf)
    {
        return this.format[name]||def
    };

    // Function: ident_code
    this.ident_code=function(n)
    {
        var ident=this.getp(n,"ident",parseInt(this.format.level_ident||0)*n.lvl-this.getp(n,"padding",0))||0;
        return n.lvl&&ident?'\r\t<td><img src="'+this.format.b_image+'" width="'+ident+'" height="1"></td>':'';
    };

    // Function: init_item
    this.init_item=function(n)
    {
        var tc=this.getp(n,"table_class",0);
        var s='\r<table width="'+this.getp(n,"width","100%")+'" cellpadding="'+this.getp(n,"padding",0)+'" cellspacing="'+this.getp(n,"spacing",0)+'" border="0"'+(tc?' class="'+tc+'"':'')+'>\r<tr>';
        var img=this.getp(n,(n.sub?n.exp?"e":"c":"i")+"_image",this.format.b_image);
        var sz=this.getp(n,"img_size",[32,16]);
        sz=!n.sub?[sz[0],1]:sz;
		//s+='<td'+(n.image?'':' class="graydark"')+'><img src="'+(n.image?n.image:'images/space.gif')+'" width="1" height="'+(n.image?'25':'1')+'"></td>'
		// Modification car provoque le passage a la page d'erreur a cause de images/space.gif qui est recherche dans le mauvais dossier
		s+='<td'+(n.image?'':' class="graydark"')+'><img src="'+(n.image?n.image:'/images/space.gif')+'" width="1" height="'+(n.image?'25':'1')+'"></td>'
        s+=this.ident_code(n);
        s+= !this.getp(n,"no_images",0)?'\r\t<td>'+(n.sub?'<a href="javascript:void(0)" onclick="if(this.blur)this.blur();'+this.id+'.togg(\''+n.id+'\')">':'')+'<img '+(bw.ns4?'name="'+n.id+'_img" ':'')+'id="'+n.id+'_img" src="'+img+'" width="'+sz[0]+'" height="'+sz[1]+'" border="0"/>'+(n.sub?'</a>':'')+'</td>':'';
        var bgc=this.getp(n,"item_bgcolor",0);
        bgc=bgc?' bgcolor="'+bgc+'"':' ';
        var targ=n.target||this.format.target||0;
        tc=this.getp(n,"item_class",0);
        var lcname=(n.id==this.selected)?"link_class_selected":"link_class";
        var lcsubname=(n.id==this.subselected)?"sublink_class_selected":"sublink_class";
        var lc=this.getp(n,lcname,0);
        lc=!n.sub?this.getp(n,lcsubname,0):lc;
        s+='\r\t<td width="100%"'+bgc+(tc?'class="'+tc+'"':'')+'><a '+(lc?'class="'+lc+'" ':'')+'href="'+(n.url||'javascript:void(0)')+'"'+(n.sub?' onclick="if(this.blur)this.blur();'+this.id+'.togg(\''+n.id+'\')"':'')+(targ?' target="'+targ+'"':'')+'>'+n.html+'</a>'+'</td>';
        s+="\r</tr>\r</table>";
        return s;
    };

    // Function: get_image
    this.get_image=function(par,name)
    {
        return bw.dom?document.getElementById(name):bw.ie4?document.all[name]:bw.ns4?par.el.document.images[name]:[]
    };

    // Function: update
    this.update=function(n)
    {
        if(this.format.no_images) return;
        var src=this.getp(n,(n.sub?n.exp?"e":"c":"i")+"_image",this.format.b_image);
        var img=this.get_image(n.obj,n.id+'_img')||[];
        img.src=src;
    };

    // Function: close_level
    this.close_level=function(p,n)
    {
        for(var i=0;i<p.sub.length;i++)
            if(p.sub[i]!=n&&p.sub[i].sub&&p.sub[i].exp&&!p.sub[i].selected) {
                p.sub[i].exp=0;
                this.update(p.sub[i]);
                this.collapse_children(p.sub[i],p.sub[i].obj.x,p.sub[i].obj.y,this.format.animation,1,1);
            }
    };

    // Function: select
    this.select=function(id)
    {
        var n=this.nodes[id];
        n.exp=!n.exp;
        n.selected=true;
        if(n.exp&&this.format.one_branch) this.close_level(n.parent,n);
        this.update(n);
        if(this.format.animation&&n.sub&&n.exp) this.collapse_children(n,n.obj.x,n.obj.y,0,0,0);
        if(n.sub&&!n.exp) this.collapse_children(n,n.obj.x,n.obj.y,this.format.animation,1,1);
        this.draw(0);
    };

    // Function: togg
    this.togg=function(id)
    {
        if(this.anim_ref>0) { return };
        var n=this.nodes[id];
        if(n.selected) { return };
        n.exp=!n.exp;
        if(n.exp&&this.format.one_branch) this.close_level(n.parent,n);
        this.update(n);
        if(this.format.animation&&n.sub&&n.exp) this.collapse_children(n,n.obj.x,n.obj.y,0,0,0);
        if(n.sub&&!n.exp) this.collapse_children(n,n.obj.x,n.obj.y,this.format.animation,1,1);
        this.draw(0);
    };

    // Function: collapse_children
    this.collapse_children=function(n,x,y,anim,f,hide)
    {
        if(!n.obj.el) n.obj.init(this.back);
        if(f)if(!anim) {
            n.obj.move(x,y);
            if(hide)n.obj.hide()
        } else this.slide(n,x,y,this.format.anim_step||20,this.format.anim_timer||20,hide?n.obj.name+".hide()":'');
        if(n.sub) 
            for(var i=0;i<n.sub.length;i++)
                this.collapse_children(n.sub[i],x,y,anim,1,hide)
    };

    // Function: draw
    this.draw=function(no_anim)
    {
        if(this.onbeforedraw) this.onbeforedraw(this);
        this.top=0;
        this.dnum=0;
        this._draw(this.root,no_anim);
        if(!(this.format.animation&&!no_anim)) this.resize_back(0,0);
    };

    // Function: resize_back
    this.resize_back=function(x,y)
    {
        if(this.format.dont_resize_back) return;
        var n=this.last_drawed;
        n.bott=n.obj.y+n.obj.h;
        this.back.resize(x||this.format.width, y||n.bott,1);
        this.back.show();
    };

    // Function: expand
    this.expand=function(n,e)
    {
        if(!n.obj.el) n.obj.init(this.back);
        if(n.sub) {
            n.exp=e;
            this.update(n)
        }
    };

    // Function: expandAll
    this.expandAll=function()
    {
        for(var i in this.nodes)this.expand(this.nodes[i],1)
    };

    // Function: collapseAll
    this.collapseAll=function()
    {
        for(var i in this.nodes) {
            this.expand(this.nodes[i],0);
            this.nodes[i].obj.hide()
        }
    };

    // Function: slide
    this.slide=function(n,x,y,speed,step,done,estep)
    {
        this.anim_ref++;
        n.obj.slide(x,y,speed,step,this.id+".anim_ref--;"+done, estep||this.id+".resize_back(0,0)")
    };

    // Function: _draw
    this._draw=function(n,no_anim)
    {
        this.last_drawed=n;
        this.dnum++;
        if(this.root!=n) {
            if(!n.obj.el) n.obj.init(this.back);
            var ident=this.getp(n,"real_ident",0);
            if(ident!=n.obj.x||this.top.y!=n.obj.y) {
                if(a=this.format.animation&&!no_anim) {
                    n.obj.show();
                    this.slide(n,ident,this.top,this.format.anim_step||20,this.format.anim_timer||20,'');
                } else {
                    n.obj.move(ident,this.top);
                    n.obj.show();
                }
            }
            this.top+=n.obj.h+this.getp(n,"offset_y",0);;
        }
        if(n.sub&&(n.exp||this.root==n)) 
            for(var i=0;i<n.sub.length;i++)
                this._draw(n.sub[i], no_anim);
    };
    
    // Function: show
    this.show=function(p,n)
    {
        this.selected=p;
        this.subselected=n;
        this.init();
        this.draw(1);
        if(this.selected) this.select(this.selected);
    };

    return this;
}

// Object: Browser
function Browser()
{
    this.ver=navigator.appVersion;
    this.agent=navigator.userAgent;
    this.dom=document.getElementById?1:0;
    this.opera5=this.agent.indexOf("Opera 5")>-1;
    this.opera6=this.agent.indexOf("Opera 5")>-1;
    this.opera7=(this.agent.indexOf("Opera/7")>-1)||(this.agent.indexOf("Opera 7")>-1);
    this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0;
    this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
    this.ie7=(this.ver.indexOf("MSIE 7")>-1 && this.dom && !this.opera5)?1:0;
    this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
    this.ie=this.ie4||this.ie5||this.ie6||this.ie7;
    this.mac=this.agent.indexOf("Mac")>-1;
    this.ns6=(this.dom && parseInt(this.ver)>=5)?1:0;
    this.ns4=(document.layers && !this.dom)?1:0;
    this.operaOld=window.opera&&!this.opera7;
    this.bw=(this.ie7||this.ie6||this.ie5||this.ie4||this.ns4||this.ns6||this.opera5||this.opera6||this.opera7);
    return this
};

// Object: DHTMLObject
function DHTMLObject(id)
{
    this.id=id;
    if(!bw.bw) return;
    this.name='DHTMLObject_'+this.id;

    // Function: init
    this.init=function(ns4p)
    {
        this.el=bw.dom?document.getElementById(this.id):bw.ie4?document.all[this.id]:bw.ns4?ns4p?ns4p.doc.layers[this.id]:document.layers[this.id]:0;
        if(!this.el) return;
        this.css=bw.dom||bw.ie4?this.el.style:this.el;
        this.doc=bw.dom||bw.ie4?document:this.css.document;
        this.x=parseInt(this.css.left)||this.css.pixelLeft||this.el.offsetLeft||0;
        this.y=parseInt(this.css.top)||this.css.pixelTop||this.el.offsetTop||0;
        this.w=this.el.offsetWidth||this.css.clip.width||this.doc.width||this.css.pixelWidth||0;
        this.h=this.el.offsetHeight||this.css.clip.height||this.doc.height||this.css.pixelHeight||0;
        this.h=bw.opera7?this.el.firstChild.offsetHeight:this.h;
        this.w=bw.opera7?this.el.firstChild.offsetWidth:this.w;
        if(this.initClip)this.initClip()
    };

    // Function: draw
    this.draw=function(x,y,w,h,bg,v,z,css,code,rel,mover,mout)
    {
        return '\r'+(bw.ns4?'<'+(rel?'i':'')+'layer id="'+this.id+'" z-index='+z+' left='+x+' top='+y+' '+(w&&w!='auto'?'width='+w:'')+' height='+h+(!v?' visibility=hidden':'')+(bg!=""?' bgcolor="'+bg+'"':'')+(css!=''?' class="'+css+'"':'')+(mover?' onmouseover="'+mover+'"':'')+(mout?' onmouseout="'+mout+'"':'')+'>'+code+'\r</'+(rel?'i':'')+'layer>':'<div id="'+this.id+'" style="position:'+(rel?'relative':'absolute')+';z-index:'+z+';left:'+x+'px;top:'+y+'px;'+(w?'width:'+w+(w=='auto'?'':'px;'):'')+(h?'height:'+h+'px;':'')+(!v?'visibility:hidden;':'')+(bg!=""?''+(bw.ns4?'layer-':'')+'background-color:'+bg+';':'')+'"'+(css!=''?' class="'+css+'"':'')+'>'+code+'\r</div>')
    };

    // Function: move
    this.move=function(x,y)
    {
        this.css.left=this.x=x;
        this.css.top=this.y=y
    };

    // Function: moveBy
    this.moveBy=function(x,y)
    {
        this.css.left=this.x+=x;
        this.css.top=this.y+=y
    };

    // Function: resize
    this.resize=function(w,h,clip)
    {
        this.css.pixelWidth=this.css.width=this.w=w;
        this.css.pixelHeight=this.css.height=this.h=h;
        if(clip&&this.clip)this.clip(0,w,h,0)
    };

    // Function: show
    this.show=function()
    {
        this.css.visibility="visible"
    };
    
    // Function: hide
    this.hide=function()
    {
        this.css.visibility="hidden"
    };
    
    // Function: bgColor
    this.bgColor=function(color)
    {
        if(bw.opera) this.css.background=color;
        else if(bw.dom || bw.ie4) this.css.backgroundColor=color;
        else if(bw.ns4) this.css.bgColor=color
    };
    
    // Function: write
    this.write=function(s)
    {
        if(bw.ns4) {
            this.doc.open("text/html");
            this.doc.write(s);
            this.doc.close()
        } else this.el.innerHTML=s
    };

    // Function slide
    this.slide=function(toX,toY,step,speed,execDone,execStep)
    {
        if(!this.inWay) {
            var newX=toX-this.x;
            var newY=toY-this.y;
            var num=Math.sqrt(Math.pow(newX,2)+Math.pow(newY,2))/step;
            var stepX=newX/num;
            var stepY=newY/num;
            this.inWay=1;
            this.slideInt(stepX,stepY,toX,toY,speed,execDone,execStep)
        }
    };

    // Function: slideInt
    this.slideInt=function(stepX,stepY,toX,toY,speed,execDone,execStep)
    {
        // Function fabs
        function fabs(v)
        {
            return Math.floor(Math.abs(v))
        };
        
        if(this.inWay&&(fabs(stepX)<fabs(toX-this.x)||fabs(stepY)<fabs(toY-this.y))) {
            this.moveBy(stepX,stepY);
            if(execStep)eval(execStep);
            setTimeout(this.name+".slideInt("+stepX+","+stepY+","+toX+","+toY+","+speed+",'"+execDone+"', '"+execStep+"')",speed)
        } else {
            this.inWay=0;
            this.move(toX,toY);
            if(execStep)eval(execStep);
            if(execDone)eval(execDone)
        }
    };

    // Function: initClip
    this.initClip=function()
    {
        this.clp=[];
        if((bw.dom||bw.ie4)&&this.css.clip) {
            this.clp=this.css.clip.slice(5,this.clp.length-1).split(' ');
            for(var i=0;i<4;i++)this.clp[i]=parseInt(this.clp[i])
        };
        this.ct=this.css.clip.top||this.clp[0]||0;
        this.cr=this.css.clip.right||this.clp[1]||this.w||0;
        this.cb=this.css.clip.bottom||this.clp[2]||this.h||0;
        this.cl=this.css.clip.left||this.clp[3]||0
    };

    // Function: clip
    this.clip=function(t,r,b,l,resize)
    {
        if(bw.ns4) {
            this.css.clip.top=this.ct=t;
            this.css.clip.right=this.cr=r;
            this.css.clip.bottom=this.cb=b;
            this.css.clip.left=this.cl=l
        } else {
            this.ct=t>0?t:0;
            this.cr=r>0?r:0;
            this.cb=b>0?b:0;
            this.cl=l>0?l:0;
            this.css.clip="rect("+this.ct+","+this.cr+","+this.cb+","+this.cl+")"
        }
        if(resize)this.resize(this.cr,this.cb,0)
    };

    eval(this.name+'=this');
    return this;
}

// Function: pldImg
function pldImg(arg)
{
    for(var i in arg)if(arg[i]&&arg[i]!='') {
        var im=new Image();
        im.src=arg[i]
    }
}

// Function: und
function und(val)
{
    return typeof(val)=='undefined'
}


