//variable globales pouvant servir sur un script
var globa;var globb;var globc;var globd;var globe;
var globi=0;var globj=0;var globk=0;
var globx;var globy;

// Fonctions générales
String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, ''); 
};

// Marquise de séléction ©Guns le plus mauvais codeur du siècle ...
function startSel(el,ev)
{
    el.setAttribute('drawing','started');
    scrollTop = document.documentElement.scrollTop;
    el.setAttribute('x',ev.clientX);
    el.setAttribute('y',ev.clientY + scrollTop);
    var newdiv = document.getElementById('selbox');
    var limite = document.getElementById('drawme');
    var thx = document.getElementById('thx');
    var thy = document.getElementById('thy');
    thx.value = ev.clientX - limite.parentNode.offsetLeft - parseInt(limite.style.marginLeft);
    thy.value = ev.clientY + scrollTop - limite.parentNode.offsetTop;
    newdiv.style.width = "0px";
    newdiv.style.height = "0px";
    newdiv.style.top = (ev.clientY + scrollTop)+"px";
    newdiv.style.left = ev.clientX+"px";    
    newdiv.style.display = "none";
    newdiv.style.zIndex = 2;
}
function drawSel(el,ev)
{
    var newdiv = document.getElementById('selbox');
    var limite = document.getElementById('drawme');
    scrollTop = document.documentElement.scrollTop;
    if(el.getAttribute('drawing') == 'started')
    {
        if(document.all)
        {
            var w = (ev.clientX - 8) - parseInt(el.getAttribute('x'));
            var h = (ev.clientY + scrollTop - 8) - parseInt(el.getAttribute('y'));
        }
        else
        {
            var w = (ev.clientX - 2) - parseInt(el.getAttribute('x'));
            var h = (ev.clientY  + scrollTop- 2) - parseInt(el.getAttribute('y'));        
        }
        if (h > w) { w = h; } else { h = w; }
        if(w >= 0)
        {
            if(
                ((newdiv.offsetLeft + w) < ((limite.parentNode.offsetLeft - parseInt(limite.style.marginLeft)) + limite.parentNode.offsetWidth)) &&
                ((newdiv.offsetTop + h) < (limite.parentNode.offsetTop + limite.parentNode.offsetHeight))
            )
            {
                newdiv.style.display = "block";
                newdiv.style.width = w+"px";
                newdiv.style.height = h+"px";
                var thw = document.getElementById('thw');
                var thh = document.getElementById('thh');
                thw.value = w;
                thh.value = h;
            }
        }
    }
}
function endSel(el)
{
    el.removeAttribute('drawing');
    el.removeAttribute('x');
    el.removeAttribute('y');
    var newdiv = document.getElementById('selbox');
    if(newdiv != undefined)
    {
        newdiv.style.zIndex = 10;
    }
}
function moveSel(el,ev)
{
    var limite = document.getElementById('drawme');
    var thx = document.getElementById('thx');
    var thy = document.getElementById('thy');
    if(el.getAttribute('movable') == 'on')
    {
        var dx = ev.clientX - el.getAttribute('x');
        var dy = ev.clientY - el.getAttribute('y');
        newtop = (parseInt(el.getAttribute('itop')) + dy);
        newleft = (parseInt(el.getAttribute('ileft')) + dx);
        if(
            (newtop > limite.parentNode.offsetTop) &&
            ((newtop + el.offsetHeight) < (limite.parentNode.offsetTop + limite.parentNode.offsetHeight))
        )
        {
            el.style.top = newtop + 'px';
            thy.value = newtop - limite.parentNode.offsetTop;
        }
        if(
            (newleft > (limite.parentNode.offsetLeft + parseInt(limite.style.marginLeft))) &&
            ((newleft + el.offsetWidth) < ((limite.parentNode.offsetLeft - parseInt(limite.style.marginLeft)) + limite.parentNode.offsetWidth))
        )
        {
            el.style.left = newleft + 'px' ;
            thx.value = newleft - limite.parentNode.offsetLeft - parseInt(limite.style.marginLeft);
        }        
    }
}
function makeMovable(el,ev)
{
    if(el.getAttribute('movable') != 'on')
    {
        el.setAttribute('movable','on');
        el.setAttribute('x',ev.clientX);
        el.setAttribute('y',ev.clientY);
        el.setAttribute('itop',parseInt(el.style.top));
        el.setAttribute('ileft',parseInt(el.style.left));
    }
}
function removeAble(el)
{
    el.removeAttribute('movable');
    el.removeAttribute('x');
    el.removeAttribute('y');
    el.removeAttribute('itop');
    el.removeAttribute('ileft');
}
// Fin du code mega pourri ....

//Début de l'autre code méga pourri
function mar(fil)
{
    fil = top.document.getElementById(fil);
    if (fil.className == "unread")
    {
        fil.className = 'read';
        if(top.document.getElementById('nm0'))
        {
            var m = top.document.getElementById('nm0').firstChild.nodeValue;
            m = parseInt(m) - 1;
            top.document.getElementById('nm0').innerHTML = m;
            top.document.getElementById('nm1').innerHTML = m;
        }
    }
}

function permute(o,t)
{
    document.getElementById(o).className = "hidden";
    document.getElementById(t).className = "shown";
}

function swapVis(e)
{
    (document.getElementById(e).className == "hidden") ? document.getElementById(e).className="shown":document.getElementById(e).className="hidden";
}

function popmeup(o,p,a)
{
    var pop = document.getElementById(p);
    if (a == 's')
    {
        pop.style.top = (o.offsetTop + 5)+"px";
        pop.style.left = (o.offsetLeft + 28)+"px";
        pop.style.visibility = "visible";
    }
    else
    {
        document.getElementById(p).style.visibility = "hidden";
    }
}
function reloadHomePix()
{
    var e = document.getElementById('shootingstar');
    var prev = e.innerHTML;
    function ajaxReq() {
        var xhr = createXHR();
        xhr.onreadystatechange = function() { 
                if (xhr.readyState == 4) {
                if (xhr.status == 200) {
                    e.innerHTML = (xhr.responseText);
                } else if (xhr.status == 404) {
                    alert('Le contenu n\'est pas accessible (404).');
                    e.innerHTML = prev;
                } else {
                    alert('Un problème inconnu est survenu avec la requête. (Code : '+xhr.status+')');
                    e.innerHTML = prev;
                }
            }
            else
            {
                e.innerHTML = '<img src="gui/ajax_load.gif" style="margin: 34px" alt="" title="On chope l\'image..." />';
            }
        };
        xhr.open("GET","./inc/modal.inc.php?t=shootingstar",true);
        xhr.send(null);
    }
    ajaxReq();
}
function getEd(id)
{
    var e = document.getElementById('editoholder');
    function ajaxReq() {
        var xhr = createXHR();
        xhr.onreadystatechange = function() { 
                if (xhr.readyState == 4) {
                if (xhr.status == 200) {
                    e.innerHTML = (xhr.responseText);
                } else if (xhr.status == 404) {
                    alert('Le contenu n\'est pas accessible (404).');
                    e.innerHTML = '';
                } else {
                    alert('Un problème inconnu est survenu avec la requête. (Code : '+xhr.status+')');
                    e.innerHTML = '';
                }
            }
            else
            {
                e.innerHTML = '<img src="gui/ajax_load.gif" style="display: block;margin: 30px auto" alt="" title="Récupération de l\'édito..." />';
            }
        };
        xhr.open("GET","./inc/modal.inc.php?t=edito&ta="+id,true);
        xhr.send(null);
    }
    ajaxReq();
}
function getThread(fil)
{
    var e = document.getElementById("global"+fil);
    var prev = e.innerHTML;
    function ajaxReq() {
        var xhr = createXHR();
        xhr.onreadystatechange = function() { 
                if (xhr.readyState == 4) {
                if (xhr.status == 200) {
                    e.innerHTML = (xhr.responseText);
                } else if (xhr.status == 404) {
                    alert('Le contenu n\'est pas accessible (404).');
                    e.innerHTML = prev;
                } else {
                    alert('Un problème inconnu est survenu avec la requête. (Code : '+xhr.status+')');
                    e.innerHTML = prev;
                }
            }
            else
            {
                e.innerHTML = '<img src="gui/wait.gif" alt="" title="fil en cours de construction" /> patientez ...';
            }
        };
        xhr.open("POST","./inc/makethread.inc.php",true);
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");                  
        xhr.send("t="+fil);
    }
    ajaxReq();
}
function putPBg(v)
{
    el = document.getElementById("photoviewer");
    if(v<0)
    {
        el.style.backgroundColor = 'transparent';
    }
    else
    {
        el.style.backgroundColor = 'rgb('+v+','+v+','+v+')';
    }
}
function modText(id,way)
{
    e = document.getElementById(id);
    if(e.style.fontSize.length == 0) { var base = 100; } else { var base = parseInt(e.style.fontSize); }
    base = (way=="up") ? base+20:base-20;
    e.style.fontSize = base+"%";
}
function doVoteBACK(e)
{
    var childs = e.childNodes;
    if(childs.length > 1)
    {
        e.className = 'notetoftoolbg pointer';
        while (e.childNodes[1])
        {
            e.removeChild(e.childNodes[1]);
        }
        e.firstChild.style.display = 'block';
    }
    else
    {
        e.className = 'notetoftoolbgvoting';
        e.firstChild.style.display = 'none';
        e.innerHTML = e.innerHTML+'<div onclick="alert(0);" class="votenum">0</div><div class="votenum">1</div><div class="votenum">2</div><div class="votenum">3</div><div class="votenum">4</div><div class="votenum">5</div><div class="votenumof">X</div>';
    }
}
function doVote(cat,item,cur)
{
    var e = document.getElementById('votetool');
    var childs = e.childNodes;
    if(cat == "tof")
    {
        if(childs.length == 1)
        {
            e.className = 'notetoftoolbgvoting';
            e.firstChild.style.display = 'none';
            e.innerHTML = e.innerHTML+'<div onclick="vote(\'tof\','+item+',0);" class="votenum'+((cur==0)?' delme':'')+'" title="'+((cur==0)?'Supprimer votre note de 0':'0/5 (pourri)')+'">0</div><div onclick="vote(\'tof\','+item+',1);" class="votenum'+((cur==1)?' delme':'')+'" title="'+((cur==1)?'Supprimer votre note de 1':'1/5 (médiocre)')+'">1</div><div onclick="vote(\'tof\','+item+',2);" class="votenum'+((cur==2)?' delme':'')+'" title="'+((cur==2)?'Supprimer votre note de 2':'2/5 (moyen)')+'">2</div><div onclick="vote(\'tof\','+item+',3);" class="votenum'+((cur==3)?' delme':'')+'" title="'+((cur==3)?'Supprimer votre note de 3':'3/5 (bon)')+'">3</div><div onclick="vote(\'tof\','+item+',4);" class="votenum'+((cur==4)?' delme':'')+'" title="'+((cur==4)?'Supprimer votre note de 4':'4/5 (très bon)')+'">4</div><div onclick="vote(\'tof\','+item+',5);" class="votenum'+((cur==5)?' delme':'')+'" title="'+((cur==5)?'Supprimer votre note de 5':'5/5 (excellent)')+'">5</div><div onclick="vote(\'tof\','+item+',-1);" class="votenumof" title="Annuler">X</div>';
        }
    }
    else if(cat == "film")
    {
        if(childs.length == 3)
        {
            e.className = 'notefilm floatright rel notefilmh';
            var voted = (cur>=0)?'<img src="gui/tri_asc.png" style="position: absolute; top: 20px;left: '+((cur*10)+6)+'px;" title="Votre note actuelle - Choisir pour annuler votre note" />':'';
            e.innerHTML = '<div>'+voted+'<img onclick="vote(\'film\','+item+',-1);" src="gui/bgnotfclose.png" style="position: absolute; top: 0px;right: 0px; cursor: pointer;" title="Annuler" /><div class="film_note_holder_v"><div class="fn_note fn4" onclick="vote(\'film\','+item+',4);" title="4/4 claps, ce film est excellent, y\'a pas mieux"></div><div class="fn_note fn3" onclick="vote(\'film\','+item+',3);" title="3/4 claps, ce film est très bien"></div><div class="fn_note fn2" onclick="vote(\'film\','+item+',2);" title="2/4 claps, ce film est pas mal du tout"></div><div class="fn_note fn1" onclick="vote(\'film\','+item+',1);" title="1/4 clap, ce film est visible"></div><div class="fn_note fn0" onclick="vote(\'film\','+item+',0);" title="0/4 clap, ce film est pourri"></div></div></div>';
        }
    }
}
function vote(cat,item,note)
{       
    var e = document.getElementById('votetool');
    function ajaxReq() {
            var xhr = createXHR();
            xhr.onreadystatechange = function() { 
                    if (xhr.readyState == 4) {
                        if (xhr.status == 200) {
                            var ans = xhr.responseText.split("#");
                            if(cat == "tof") {
                                e.innerHTML = ans[0];
                                e.className = 'notetoftoolbg pointer';
                                if(note >= 0) { 
                                    e.title = ans[1];
                                    for (var i = 0; i < e.attributes.length; i++) {
                                        if(e.attributes[i].nodeName == "onclick") {
                                            e.attributes[i].nodeValue = "doVote('tof',"+item+","+ans[2]+");";
                                        }
                                    }
                                }
                            } else if (cat == "film") {
                                e.innerHTML = ans[0];
                                e.className = 'notefilm floatright rel';
                                if(note >= 0) { 
                                    for (var i = 0; i < e.attributes.length; i++) {
                                        if(e.attributes[i].nodeName == "onclick") {
                                            e.attributes[i].nodeValue = "doVote('film',"+item+","+ans[1]+");";
                                        }
                                    }
                                }
                            }
                        } else if (xhr.status == 404) {
                            alert('Le contenu n\'est pas accessible (404).');
                            if(cat == "tof") {
                                e.className = 'notetoftoolbg pointer';
                                while (e.childNodes[1]) {
                                    e.removeChild(e.childNodes[1]);
                                }
                                e.firstChild.style.display = 'block';
                            }
                        } else {
                            alert('Un problème inconnu est survenu avec la requête. (Code : '+xhr.status+')');
                            if(cat == "tof") {
                                e.className = 'notetoftoolbg pointer';
                                while (e.childNodes[1]) {
                                    e.removeChild(e.childNodes[1]);
                                }
                                e.firstChild.style.display = 'block';
                            }
                        }
                } else {
                    if(cat == "tof") {
                        e.innerHTML = '<span></span><img style="display: block; margin:auto;" src="gui/wait.gif" alt="" title="Validation" />';
                    } else if(cat == "film") {
                        e.innerHTML = '<img style="display: block; margin:auto;" src="gui/ajax_load.gif" alt="" title="Validation" />';
                    }
                }
            };
            xhr.open("POST","./inc/processvote.php",true);
            xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
            xhr.send("cat="+cat+"&item="+item+"&note="+note);
    }
    ajaxReq();
}

//début des conneries pour l'admin cinoche
function scrollMe(el,dir)
{
    el = document.getElementById(el);
    if(dir == "up") { 
        var newtop = parseInt(el.style.top) + 1; 
        if(newtop <= 0) { el.style.top = newtop+"px"; }
    } else {
        var newtop = parseInt(el.style.top) - 1; 
        if(el.offsetHeight + newtop > 90) { el.style.top = newtop+"px"; }
    }
}
function ucwords(str) {
    return str.replace(/^(.)|\s(.)/g, function ( $1 ) { return $1.toUpperCase ( ); } );
}
function checkYear(year,ev,max)
{
    var e = document.getElementById("filmyearok");
    if(year.length == 0)
    {
        e.innerHTML = ""; return;
    }
    if((year.length == 4) && (parseInt(year) > 1896) && (parseInt(year) <= parseInt(max))) {
        e.innerHTML = '<img src="gui/icon_form_valid.png" alt="" title="" />'; 
    } else {
        e.innerHTML = '<img src="gui/icon_form_error.png" alt="" title="" />';
    }
}
function getMovieLength(tp,ev)
{
    tp = parseInt(tp);
    if(ev.keyCode == 38) { tp += 1; document.getElementById("duree").value = tp; }
    if(ev.keyCode == 40) { tp -= 1; document.getElementById("duree").value = tp; }
    var e = document.getElementById("filmduree");
    if((tp.length == 0) || !(parseInt(tp) > 0)) {
        document.getElementById("duree").value = "";
        e.innerHTML = ""; return;
    } else {
        h = Math.floor(tp/60);
        m = tp - (h*60);
        if(m < 10) { m = '0'+m; }
        e.innerHTML = h+" h "+m+ " m";
    }
}
function getMovieFlag(pays,ev)
{
    var e = document.getElementById("filmpays");
    if(pays.length == 0)
    {
        e.innerHTML = ""; return;
    }
    else
    {
        e.innerHTML = '<img src="smlflag_'+pays+'.jpg" alt="" title="Pays" />';
    }
}
function addCast()
{
	var b = document.getElementById("cast");
	// var str = "";
	// for (var i = 0; i < b.childNodes.length; i++)
    // {
        // var child = b.childNodes[i];
        // str += i+" "+child.tagName+"\n";
    // }
	// alert(str);
	var c = b.childNodes[4].cloneNode(true);
	b.appendChild(c);
	b.lastChild.firstChild.className = "shown pointer";
    b.lastChild.childNodes[2].value = "";
	b.lastChild.childNodes[3].value = "";
    b.lastChild.childNodes[4].value = "";
    if(b.lastChild.childNodes.length > 5)
    {
        b.lastChild.childNodes[5].value = "";
    }
}
function delMe(el)
{
	el.parentNode.parentNode.removeChild(el.parentNode);
}
function look4posters(title,ev)
{
    var e = document.getElementById("choixaffiches");
    if(title.length == 0) {
        e.innerHTML = '&nbsp;';
    } else {
        function ajaxReq() {
            var xhr = createXHR();
            xhr.onreadystatechange = function() { 
                    if (xhr.readyState == 4) {
                    if (xhr.status == 200) {
                        e.innerHTML = (xhr.responseText);
                    } else if (xhr.status == 404) {
                        alert('Le contenu n\'est pas accessible (404).');
                        e.innerHTML = '&nbsp;';
                    } else {
                        alert('Un problème inconnu est survenu avec la requête. (Code : '+xhr.status+')');
                        e.innerHTML = '&nbsp;';
                    }
                }
                else
                {
                    e.innerHTML = '&nbsp;';
                }
            };
            xhr.open("POST","./inc/getaffiche.inc.php",true);
            xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
            xhr.send("mode=choice&q="+title);
        }
        ajaxReq();
    }
}
function updateAffiche(id,file,title)
{
    document.getElementById("mode").value = 'man';
    var a = document.getElementById("blocaffiche");
    a.innerHTML = '<input type="hidden" name="affid" value="'+id+'" /><div id="imgcont" class="center"><img src="doc/affiches/'+file+'_th.jpg" alt="" title="'+title+'" /></div><p>Votre affiche a été enregistrée</p><div class="center"><a href="javascript:afficheManuel();"><b>Modifier</b></a></div>';

}
function fillMyMovieTitle(title,ev)
{
    var e = document.getElementById("adminfilmtitle");
    var a = document.getElementById("blocaffiche");
    var m = document.getElementById("mode").value;
    if(title.length == 0) {
        e.innerHTML = "new*";
        if(m != 'man') { a.innerHTML = '<div id="imgcont" class="center"></div><p>En attente <img style="vertical-align: inherit;" src="gui/dots.gif" alt="" /></p><div class="center"><b>&nbsp;</b></div>'; }
    } else {
        if(title.length > 50) {
            e.innerHTML = title.substring(0,50)+'...';
        } else {
            e.innerHTML = title;
        }
        if(m != 'man')
        {
            function ajaxReq() {
                var xhr = createXHR();
                xhr.onreadystatechange = function() { 
                        if (xhr.readyState == 4) {
                        if (xhr.status == 200) {
                            a.innerHTML = (xhr.responseText);
                        } else if (xhr.status == 404) {
                            alert('Le contenu n\'est pas accessible (404).');
                            a.innerHTML = '<div id="imgcont" class="center"></div><p>&nbsp;</p><div class="center"><b>&nbsp;</b></div>';
                        } else {
                            alert('Un problème inconnu est survenu avec la requête. (Code : '+xhr.status+')');
                            a.innerHTML = '<div id="imgcont" class="center"></div><p>&nbsp;</p><div class="center"><b>&nbsp;</b></div>';
                        }
                    }
                    else
                    {
                        a.innerHTML = '<div id="imgcont" class="center"><img style="display: block; margin:auto;" src="gui/wait.gif" alt="" title="" /></div><p>&nbsp;</p><div class="center"><b>&nbsp;</b></div>';
                    }
                };
                xhr.open("POST","./inc/getaffiche.inc.php",true);
                xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
                xhr.send("q="+title);
            }
            ajaxReq();
        }
    }
}
function afficheManuel()
{
    openModal("ModalWindow","inc/modal.inc.php?ta=blocaffiche&t=affiche",400,400)
}
function getAfficheTitle()
{
    var a = document.getElementById("title").value;
    document.getElementById("name").value = a;
}
function getCelebSelect(input,ev)
{
	var v = input.value;
    if(v.length == 0) { celebOff(); choseMyCel(input,-1); return; }
	var e = document.getElementById("celebs");
	if(e == null) 
	{
		var newdiv = document.createElement('div');
	    newdiv.id = "celebs";
	    newdiv.className = "selectbox";
		input.parentNode.appendChild(newdiv);
		var e = document.getElementById("celebs");	
	}
    function ajaxReq() {
        var xhr = createXHR();
        xhr.onreadystatechange = function() { 
                if (xhr.readyState == 4) {
                if (xhr.status == 200) {
                    e.innerHTML = (xhr.responseText);
                } else if (xhr.status == 404) {
                    alert('Le contenu n\'est pas accessible (404).');
                    e.innerHTML = "404 :(";
                } else {
                    alert('Un problème inconnu est survenu avec la requête. (Code : '+xhr.status+')');
                    e.innerHTML = "wtf ?";
                }
            }
            else
            {
                e.innerHTML = '<img style="display: block; margin:40px 68px;" src="gui/wait.gif" alt="" title="liste en construction" />';
            }
        };
        xhr.open("POST","./inc/makecelebselect.inc.php",true);
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
        xhr.send("q="+v);
    }
    ajaxReq();
}
function getCriticSelects(input,ev)
{
    var m = input.name;
	var v = input.value;
    if(v.length == 0) { celebOff(); choseMyCelCrit(input,-1); return; }
	var e = document.getElementById("celebs");
	if(e == null)
	{
		var newdiv = document.createElement('div');
	    newdiv.id = "celebs";
	    newdiv.className = "selectboxcrit";
		input.parentNode.appendChild(newdiv);
		var e = document.getElementById("celebs");	
	}
    function ajaxReq() {
        var xhr = createXHR();
        xhr.onreadystatechange = function() { 
                if (xhr.readyState == 4) {
                if (xhr.status == 200) {
                    e.innerHTML = (xhr.responseText);
                } else if (xhr.status == 404) {
                    alert('Le contenu n\'est pas accessible (404).');
                    e.innerHTML = "404 :(";
                } else {
                    alert('Un problème inconnu est survenu avec la requête. (Code : '+xhr.status+')');
                    e.innerHTML = "wtf ?";
                }
            }
            else
            {
                e.innerHTML = '<img style="display: block; margin:40px 68px;" src="gui/wait.gif" alt="" title="liste en construction" />';
            }
        };
        xhr.open("POST","./inc/makecelebselect.inc.php",true);
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
        xhr.send("m="+m+"&q="+v);
    }
    ajaxReq();
}
function celebOff() 
{
	var e = document.getElementById("celebs");
	if(e != null) { e.parentNode.removeChild(e); }
}
function choseMyFilm(div,fid)
{
    if(fid == -1)
    {
        div.parentNode.childNodes[0].value = fid;
        div.focus;
        div.value = '';
    }
    else
    {
        var sel = div.parentNode.parentNode.childNodes[2];
        div.parentNode.parentNode.childNodes[0].value = fid;
        sel.focus();
        sel.value = div.title;
    }
}
function choseMyCelCrit(div,cid)
{
    if(cid == -1)
    {
        div.parentNode.childNodes[0].value = cid;
        div.focus;
        div.value = '';
    }
    else
    {
        var sel = div.parentNode.parentNode.childNodes[2];
        div.parentNode.parentNode.childNodes[0].value = cid;
        sel.focus();
        sel.value = div.title;
    }
}
function choseMyCel(div,cid)
{
    if(cid == -1)
    {
        div.parentNode.childNodes[2].value = cid;
        if(div.parentNode.childNodes.length > 5)
        {
            div.parentNode.childNodes[5].value = Math.floor(Math.random()*100001);
        }
        div.focus;
        div.value = '';
    }
    else
    {
        var sel = div.parentNode.parentNode.childNodes[3];
        div.parentNode.parentNode.childNodes[2].value = cid;
        sel.focus();
        sel.value = div.childNodes[1].innerHTML;
    }
}
function getCelebList(req,ev)
{
    var e = document.getElementById("celeblist");
    var prev = e.innerHTML;
    if((ev.keyCode < 48 || ev.keyCode > 90) && (ev.keyCode != 0) && (ev.keyCode != 8) && (ev.keyCode != 46)) { return; }
    if(req.length == 0) { e.innerHTML = ''; return; }
    if(req.length < 3) { e.innerHTML = '<p>en attente de 3 lettres minimum</p>'; return; }
    function ajaxReq() {
        var xhr = createXHR();
        xhr.onreadystatechange = function() { 
                if (xhr.readyState == 4) {
                if (xhr.status == 200) {
                    e.innerHTML = (xhr.responseText);
                } else if (xhr.status == 404) {
                    alert('Le contenu n\'est pas accessible (404).');
                    e.innerHTML = prev;
                } else {
                    alert('Un problème inconnu est survenu avec la requête. (Code : '+xhr.status+')');
                    e.innerHTML = prev;
                }
            }
            else
            {
                e.innerHTML = '<img style="display: block; margin:auto;" src="gui/wait.gif" alt="" title="liste en construction" />';
            }
        };
        xhr.open("POST","./inc/makeceleblist.inc.php",true);
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
        xhr.send("q="+req);
    }
    ajaxReq();
}
function getFilmList(req,ev)
{
    var e = document.getElementById("filmlist");
    var prev = e.innerHTML;
    if((ev.keyCode < 48 || ev.keyCode > 90) && (ev.keyCode != 0) && (ev.keyCode != 8) && (ev.keyCode != 46)) { return; }
    if(req.length == 0) { e.innerHTML = ''; return; }
    function ajaxReq() {
        var xhr = createXHR();
        xhr.onreadystatechange = function() { 
                if (xhr.readyState == 4) {
                if (xhr.status == 200) {
                    e.innerHTML = (xhr.responseText);
                } else if (xhr.status == 404) {
                    alert('Le contenu n\'est pas accessible (404).');
                    e.innerHTML = prev;
                } else {
                    alert('Un problème inconnu est survenu avec la requête. (Code : '+xhr.status+')');
                    e.innerHTML = prev;
                }
            }
            else
            {
                e.innerHTML = '<img style="display: block; margin:auto;" src="gui/wait.gif" alt="" title="liste en construction" />';
            }
        };
        xhr.open("POST","./inc/makefilmlist.inc.php",true);
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
        xhr.send("q="+req);
    }
    ajaxReq();
}
function getPublicCelebList(req,ev)
{
    document.getElementById("resetme").style.display = "block";
    var e = document.getElementById("celeblisting");
    var prev = e.innerHTML;
    if((ev.keyCode < 48 || ev.keyCode > 90) && (ev.keyCode != 0) && (ev.keyCode != 8) && (ev.keyCode != 46)) { return; }
    req = req.trim();
    if(req.length == 0) { return; }
    document.getElementById("navigation").innerHTML = "";
    document.getElementById("orderby").innerHTML = "";    
    function ajaxReq() {
        var xhr = createXHR();
        xhr.onreadystatechange = function() { 
                if (xhr.readyState == 4) {
                if (xhr.status == 200) {
                    e.innerHTML = (xhr.responseText);
                } else if (xhr.status == 404) {
                    alert('Le contenu n\'est pas accessible (404).');
                    e.innerHTML = prev;
                } else {
                    alert('Un problème inconnu est survenu avec la requête. (Code : '+xhr.status+')');
                    e.innerHTML = prev;
                }
            }
            else
            {
                e.innerHTML = '<img style="display: block; margin:auto;" src="gui/wait.gif" alt="" title="liste en construction" />';
            }
        };
        xhr.open("POST","./inc/makepublicceleblist.inc.php",true);
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
        xhr.send("q="+req);
    }
    ajaxReq();
}
function getPublicList(req,ev,id)
{
    document.getElementById("resetme").style.display = "block";
    var e = document.getElementById(id);
    var prev = e.innerHTML;
    if((ev.keyCode < 48 || ev.keyCode > 90) && (ev.keyCode != 0) && (ev.keyCode != 8) && (ev.keyCode != 46)) { return; }
    req = req.trim();
    if(req.length == 0) { return; }
    document.getElementById("navigation").innerHTML = "";
    function ajaxReq() {
        var xhr = createXHR();
        xhr.onreadystatechange = function() { 
                if (xhr.readyState == 4) {
                if (xhr.status == 200) {
                    e.innerHTML = (xhr.responseText);
                } else if (xhr.status == 404) {
                    alert('Le contenu n\'est pas accessible (404).');
                    e.innerHTML = prev;
                } else {
                    alert('Un problème inconnu est survenu avec la requête. (Code : '+xhr.status+')');
                    e.innerHTML = prev;
                }
            }
            else
            {
                e.innerHTML = '<img style="display: block; margin:auto;" src="gui/wait.gif" alt="" title="liste en construction" />';
            }
        };
        xhr.open("POST","./inc/makepubliclist.inc.php",true);
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
        xhr.send("t="+id+"&q="+req);
    }
    ajaxReq();
}
function insertCeleb(that,target)
{
    var cid = that.parentNode.firstChild.value;
    if(cid > 0)
    {
        var nom = that.parentNode.lastChild.value;
        doTag(target,20,cid,nom);
    }
}
function insertFilm(that,target)
{
    var fid = that.parentNode.firstChild.value;
    if(fid > 0)
    {
        var nom = that.parentNode.lastChild.value;
        doTag(target,22,fid,nom);
    }
}
function setnote(note)
{
    var eln = document.getElementById('note');
    var el = document.getElementById('noteinfo');
    eln.value = note;
    if(note == 0) { el.innerHTML = 'Vous avez noté ce film <b>0</b> clap'; eln.parentNode.childNodes[2].firstChild.style.width = '15px'; }
    else if(note == 1) { el.innerHTML = 'Vous avez noté ce film <b>1</b> clap'; eln.parentNode.childNodes[2].firstChild.style.width = '32px'; }
    else if(note == 2) { el.innerHTML = 'Vous avez noté ce film <b>2</b> claps'; eln.parentNode.childNodes[2].firstChild.style.width = '47px'; }
    else if(note == 3) { el.innerHTML = 'Vous avez noté ce film <b>3</b> claps'; eln.parentNode.childNodes[2].firstChild.style.width = '62px'; }
    else if(note == 4) { el.innerHTML = 'Vous avez noté ce film <b>4</b> claps'; eln.parentNode.childNodes[2].firstChild.style.width = '77px'; }
    else { el.innerHTML = '&nbsp;'; }
}
function infonote(note)
{
    var eln = document.getElementById('note');
    var el = document.getElementById('noteinfo');
    eln.parentNode.childNodes[2].firstChild.style.width = '0px'; 
    var n = eln.value;
    if(note == 0) { el.innerHTML = '<b>0</b> clap, ce film est pourri'; }
    else if(note == 1) { el.innerHTML = '<b>1</b> clap, ce film est visible'; }
    else if(note == 2) { el.innerHTML = '<b>2</b> claps, ce film est pas mal du tout'; }
    else if(note == 3) { el.innerHTML = '<b>3</b> claps, ce film est très bien'; }
    else if(note == 4) { el.innerHTML = '<b>4</b> claps, ce film est excellent, y\'a pas mieux'; }
    else { 
        if(n == 0) { el.innerHTML = 'Vous avez noté ce film <b>0</b> clap'; eln.parentNode.childNodes[2].firstChild.style.width = '15px'; }
        else if(n == 1) { el.innerHTML = 'Vous avez noté ce film <b>1</b> clap'; eln.parentNode.childNodes[2].firstChild.style.width = '32px'; }
        else if(n == 2) { el.innerHTML = 'Vous avez noté ce film <b>2</b> claps'; eln.parentNode.childNodes[2].firstChild.style.width = '47px'; }
        else if(n == 3) { el.innerHTML = 'Vous avez noté ce film <b>3</b> claps'; eln.parentNode.childNodes[2].firstChild.style.width = '62px'; }
        else if(n == 4) { el.innerHTML = 'Vous avez noté ce film <b>4</b> claps'; eln.parentNode.childNodes[2].firstChild.style.width = '77px'; }
        else { el.innerHTML = '&nbsp;'; }
    }
}

// Fin des conneries pour l'admin cinoche


function getClientSize(w)
{
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  if (w == "x") return myWidth;
  if (w == "y") return myHeight;
}

function swap(e)
{
    var childNodes = e.parentNode.childNodes;
    for (var i = 0; i < childNodes.length; i++)
    {
        var child = childNodes[i];
        if (child.tagName == "UL")
        {
            if (child.style.display != "none")
            {
                child.style.display="none";
                e.src="gui/thread_expand.png";
            }
            else
            {
                child.style.display="block";
                e.src="gui/thread_collapse.png";
            }
        }
    }
}

function cleansearch(e,over,focus) 
{
    if (focus != undefined)
    {
        e.setAttribute('foc', focus ? 'foc' : '');
    }
    if (over || (e.getAttribute('foc') == 'foc'))
    {
        e.className = "searchquery_on";
    }
    else
    {
        if (e.value == "")
        {
            e.className = "searchquery_off";
        }
    }
}

function subCheck(c,arr)
{
    for (i = 0;i < arr.length;i++)
    {
        document.getElementById(arr[i]).checked = c;
    }
}

function checkErrs() {
    var e = document.getElementById('querycrit');
    var t = e.parentNode;
    var errors = 0;
    for(var i = 0; i < e.childNodes.length; i++)
    {
        if(e.childNodes[i].tagName == 'SPAN')
        {
            if(e.childNodes[i].className == 'field_error') { errors++; }
        }
    }
    if(errors > 0) { t.className = 'errormode'; } else { t.className = ''; }
}

function cVal(c) {
    var eid = c.id;
    var target = "qf_"+eid;
    var source = eid+"v";
    if(c.checked) {
        var text = document.getElementById(source).value;
        var op = '';
        for(var i = 0; i < c.parentNode.childNodes.length; i++)
        {
            if (c.parentNode.childNodes[i].tagName == 'INPUT')
            {
                if ((typeof(c.parentNode.childNodes[i].title) != 'undefined') && (c.parentNode.childNodes[i].type == 'radio'))
                {
                    if(c.parentNode.childNodes[i].checked)
                    {
                        op = c.parentNode.childNodes[i].title;
                    }
                }
            }
        }
        if((text.length > 0) && (op != ''))
        {
            text = text.trim();
            if(op.substring(0,1) == ' ') {
                text = text.replace(/\s+/g,op);
            } else if(op.substring(0,1) == 'o') {
                text = text.replace(/\s*/g,'');
                text = text+' '+op;
            }
        }
        document.getElementById(target).innerHTML = '<span class="querycritf">'+eid+'</span>="<span class="querycritv">'+text+'</span>"';
        if(text.length <= 0) { document.getElementById(target).className = 'field_error '; } else  { document.getElementById(target).className = ''; }
        c.parentNode.className = 'rowform rbon';
    } else {
        document.getElementById(target).innerHTML = '';
        c.parentNode.className = 'rowform rb';
    }
    checkErrs();
}

function cTypedVal(c) {
    c = document.getElementById(c);
    cVal(c);
}
function cChkVal(c) {
    c = document.getElementById(c);
    cCVal(c);
}

function cSVal(c) {
    var eid = c.id;
    var target = "qf_"+eid;
    if(c.checked) {
        document.getElementById(target).innerHTML = '<span class="querycritf">'+eid+'</span>="<span class="querycritv">OUI</span>"';
        c.parentNode.className = 'rowform rbon';
    } else {
        document.getElementById(target).innerHTML = '';
        c.parentNode.className = 'rowform rb';
    }
    checkErrs();
}

function cCVal(c) {
    var eid = c.id;
    var target = "qf_"+eid;
    if(c.checked) {
        var text = '';
        for(var i = 0; i < c.parentNode.childNodes.length; i++)
        {
            if (c.parentNode.childNodes[i].tagName == 'INPUT')
            {
                if (typeof(c.parentNode.childNodes[i].title) != 'undefined')
                {
                    if(c.parentNode.childNodes[i].checked)
                    {
                        text += c.parentNode.childNodes[i].title+' ';
                    }
                }
            }
        }
        document.getElementById(target).innerHTML = '<span class="querycritf">'+eid+'</span>="<span class="querycritv">'+text.trim()+'</span>"';
        if(text.trim().length <= 0) { document.getElementById(target).className = 'field_error '; } else  { document.getElementById(target).className = ''; }
        c.parentNode.className = 'rowform rbon';
    } else {
        document.getElementById(target).innerHTML = '';
        c.parentNode.className = 'rowform rb';
    }
    checkErrs();
}



function selectAll(c,t)
{
    var inputs = document.getElementsByTagName('input');
    for (i = 0;i < inputs.length; i++)
    {
        if (inputs[i].getAttribute('cible') == t) 
        {
            inputs[i].checked = c;
            if (inputs[i].checked == true) { c++; inputs[i].parentNode.parentNode.style.backgroundColor = "#99A8D1"; } else { inputs[i].parentNode.parentNode.removeAttribute("style"); }
        }
    }
}

function checkAllChecked(p,t)
{
    var p = document.getElementById(p); var c = 0; var j = 0;
    var inputs = document.getElementsByTagName('input');
    for (i = 0;i < inputs.length; i++)
    {
        if (inputs[i].getAttribute('cible') == t) 
        {
            if (inputs[i].checked == true) { c++; inputs[i].parentNode.parentNode.style.backgroundColor = "#99A8D1"; } else { inputs[i].parentNode.parentNode.removeAttribute("style"); }
            j++;
        }
    }
    if (j == c)
    {
        p.checked = true;
    }
    else
    {
        p.checked = false;
    }
}

function activate(id,n)
{
    var e = document.getElementById(id);
    if (typeof(n) != 'undefined')
        {
        var inputs = document.getElementsByTagName('input'); var j = 0;
        for (i = 0;i < inputs.length; i++)
        {
            if (inputs[i].getAttribute('valid') == '1') { j++; }
        }
        if (j == n)
        {
            e.removeAttribute('disabled');
        }
        else
        {
            e.setAttribute('disabled','disabled');
        }
    }
    else
    {
        e.removeAttribute('disabled');
    }
}

function check(e,what)
{
    err = 0;
    if (what == "nickname")
    {
        if (e.value.length < 3) { err++; }
        if (!isAlphanum(e.value)) { err++; }
    }
    if (what == "password")
    {
        if (!isPass(e.value)) { err++; }
    }
    if (what == "passwordchk")
    {
        if (!isPass(e.value)) { err++; }
        if (e.value != document.getElementById('pwd').value) { err++; }
    }
    if (what == "mail")
    {
        if (!isMail(e.value)) { err++; }
    }    
    if (err>0) 
    { 
        e.setAttribute('valid',0);
        document.getElementById(e.id+"_status").src = "gui/icon_form_error.png"; 
        document.getElementById(e.id+"_status").title = "Ce champ est mal saisi"; 
    } 
    else 
    { 
        e.setAttribute('valid',1);    
        document.getElementById(e.id+"_status").src = "gui/icon_form_valid.png"; 
        document.getElementById(e.id+"_status").title = "Champ correctement saisi"; 
    }
}
function collectionToArray(col) {
	a = new Array();
	for (i = 0; i < col.length; i++)
		a[a.length] = col[i];
	return a;
}

// Renvoient des bool après test de type de chaines
function isAlphanum(str) // Bool
{
	for(var i=0; i<str.length; i++)
    {
        var car = str.charAt(i);
        var carhexa = car.charCodeAt(0);
        if((carhexa > 47 && carhexa < 58) || (carhexa > 64 && carhexa < 91) || (carhexa > 96 && carhexa < 123)) { } else { return false; }
    }
    return true;
}
function isPass(str) // Bool
{
    var l = 0; var n = 0; var s = 0;
	for(var i=0; i<str.length; i++)
    {
        var car = str.charAt(i);
        var carhexa = car.charCodeAt(0);
        if((carhexa > 64 && carhexa < 91) || (carhexa > 96 && carhexa < 123)) { l++; } else { }
        if(carhexa > 47 && carhexa < 58) { n++; } else { }
        if((carhexa > 31 && carhexa < 48) || (carhexa > 57 && carhexa < 65) || (carhexa > 90 && carhexa < 97) || (carhexa > 122 && carhexa < 127)) { s++; } else { }
    }
    if ((l > 2) && (n > 1) && (s > 0) && (l+n+s > 5)) {return true; } else { return false; }
}
function isMail(str) // Bool
{
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str)){ return true; }
}

function doTag(target,tag,arg,lbl) {

    var ta = document.getElementById(target);
    var tag_ar = new Array(
                       "[b]","[/b]", // 0
                       "[i]","[/i]", // 2
                       "[u]","[/u]", // 4
                       "[s]","[/s]", // 6
                       "[size=","[/size]",       // 8 -- argument : taille 
                       "[color=","[/color]", // 10 -- argument : rgb
                       "[align=","[/align]", // 12 -- 1 seul arg  (center, justi, rig, code)     // 8
                       "[list=","[/list]", // 14 -- list : argument (ol / ul)
                       "[pix=","[/pix]", // 16 arg : [img={title}]url[/img]
                       "[url=","[/url]", // 18 arg : [url=url]label[/url]
                       "[c=","[/c]", // 20 arg : cid
                       "[f=","[/f]", // 22 arg : fid
                       "[spoiler]","[/spoiler]" // 24
                    );
    var tagArg = (typeof(arg)=='undefined')?"":arg+"]";
    var tagOpen = tag_ar[tag]+tagArg;
    var tagClose = tag_ar[tag+1];
    
    ta.focus();
    if (typeof(document.selection) != 'undefined') { // [IE]
        var selected = document.selection.createRange().text;
        ta.focus();
        var sel = document.selection.createRange();
        if(selected && (typeof(lbl) == 'undefined')) {
            document.selection.createRange().text = tagOpen + selected + tagClose;
        }
        else {
            lblin = (typeof(lbl) == 'undefined') ? '':lbl;
            var text = tagOpen+lblin+tagClose;
            if (ta.createTextRange && ta.caretPos) { 
                var caretPos = ta.caretPos; 
                caretPos.text = (caretPos.text.charAt(caretPos.text.length - 1) == ' ') ? text+caretPos.text + ' ' : text+caretPos.text;
            } 
            else {
                sel.text = sel.text + text;
            }
        }
        ta.focus;
        return;
    }
    else { // [MOZ]
        var lenSel = ta.textLength;
        var startSel = ta.selectionStart;
        var endSel = ta.selectionEnd;
        var oldScrollTop = ta.scrollTop;
        var sizeSel = endSel - startSel;
        if (endSel && (sizeSel > 0) && (typeof(lbl) == 'undefined')) {
            lblin = typeof(lbl) == 'undefined' ? '':lbl;
            sub1 = (ta.value).substring(0,startSel);
            sub2 = (ta.value).substring(startSel,endSel);
            sub3 = (ta.value).substring(endSel,lenSel);
            ta.value = sub1 + tagOpen + sub2 + tagClose + sub3;
        }
        else { 
            lblin = typeof(lbl) == 'undefined' ? '':lbl;
            sub1 = (ta.value).substring(0,startSel);
            sub2 = (ta.value).substring(startSel,endSel);
            sub3 = (ta.value).substring(endSel,lenSel);
            ta.value = sub1 + tagOpen + lblin + tagClose + sub2 + sub3;
        }
        ta.selectionStart = sub1.length;
		ta.selectionEnd = sub1.length + sub2.length + lblin.length + tagOpen.length + tagClose.length;
		ta.scrollTop = oldScrollTop;
		ta.focus();
        return;
    }
}

function doSmile(target,smile) {
    var ta = document.getElementById(target);
    if (document.selection) { // [IE]
        ta.focus();
        var sel = document.selection.createRange();
        var text = ":"+smile+":";
        if (ta.createTextRange && ta.caretPos) { 
            var caretPos = ta.caretPos; 
            caretPos.text = (caretPos.text.charAt(caretPos.text.length - 1) == ' ') ? text+caretPos.text + ' ' : text+caretPos.text;
        } 
        else {
            sel.text = sel.text + text;
        }
        return;
    }
    else { // [MOZ]
        var oldScrollTop = ta.scrollTop; 
        sub1 = (ta.value).substring(0,ta.selectionStart);
        ta.value = (ta.value).substring(0,ta.selectionStart) + ":" + smile + ":" + (ta.value).substring(ta.selectionStart,ta.textLength);
        ta.selectionStart = sub1.length;
		ta.selectionEnd = sub1.length + smile.length + 2;
		ta.scrollTop = oldScrollTop;
		ta.focus();
        return;
    }    
}

function insertList(t) {
    var ta = document.getElementById("listitems");
    var typ = "ul";
    if (document.getElementById("num").checked == true) { typ = "ol"; }
    var str = ta.value.trim();
    if (str.length == 0) { cancelModal("ModalWindow"); return; }
    var reg = new RegExp("\n+","g")
    var arr = "[item]"+str.replace(reg,"[/item][item]")+"[/item]";
    doTag(t,14,typ,arr);
    cancelModal("ModalWindow");
}
function insertUrl(t) {
    var url = document.getElementById("urli").value.trim();
    var linkname = document.getElementById("linkname").value.trim();
    if (url.length == 0) { cancelModal("ModalWindow"); return; }
    linkname = (linkname.length > 0) ? linkname:url;
    doTag(t,18,url,linkname);
    cancelModal("ModalWindow");
}
function insertImg(t) {
    var url = document.getElementById("urli").value.trim();
    var linkname = document.getElementById("linkname").value.trim();
    if (url.length == 0) { cancelModal("ModalWindow"); return; }
    linkname = (linkname.length > 0) ? linkname:url;
    doTag(t,16,linkname,url);
    cancelModal("ModalWindow");
}
function updateAvatar(next,cible) {
    arg = document.getElementsByName("avaprov");
    for (i=0; i<arg.length; i++) {
        if (arg[i].checked) {
            data = "arg="+arg[i].value;
        }
    }
    url = "inc/modal.inc.php?ta="+cible+"&t="+next;
    updateModal("POST",url,"ModalWindow",data);
}
function doAva(uname) {
    if (uname == 0) {
        document.getElementById('av').innerHTML = '<img id="avatar" alt="avatar" src="gui/empty.gif" /><a href="javascript:doModal(\'avatar\',\'ava\');">modifier...</a>';
    }
    else {
        document.getElementById('av').innerHTML = '<img id="avatar" alt="avatar" title="Votre avatar" src="ava/ava_'+uname+'.jpg?'+new Date().getTime()+'" /><a href="javascript:doModal(\'avatar\',\'ava\');">modifier...</a>';
    }
}

// Fonction assignant une valeur à un input
function selectMe(el,val,input,sel,unsel) {
    document.getElementById(input).value = val;
    var firstChild = document.getElementById(el).firstChild;
    var childNodes = document.getElementById(el).parentNode.childNodes;
    for (var i = 0; i < childNodes.length; i++)
    {
        var child = childNodes[i];
        if (child.tagName == "A")
        {
            if (child.firstChild.tagName == "IMG")
            {
                child.firstChild.className=unsel;
            }
        }
    }
    firstChild.className=sel;
    firstChild.blur();
}

function dialogBox(el,msg) {
    e = document.getElementById(el);
    e.className = "floatright";
    e.style.position = "relative";
    e.style.top = "-10px";
    e.style.backgroundColor = "rgb(80,146,62)";
    e.innerHTML = msg;
    a = setTimeout(function(){e.style.display = "none";}, 1000);
}

// AJAX POURRITE MAISON :/

// Exécution d'une fenêtre modale ------------------------------------------------------------------------- DEBUT
function doModal(ta,arg,x,y) {
    x = typeof(x) != 'undefined' ? x : 400;
    y = typeof(y) != 'undefined' ? y : 200;
    openModal("ModalWindow","inc/modal.inc.php?ta="+ta+"&t="+arg,x,y)
}
function openModal(target,url,w,h) {
    var method = "GET";
    deactivateParent(); // desactivation du parent (fenetre appelante)
    createPopup(target,w,h); // création du popup
    makeRequest(method,url,target); // requete ajax;
}
function deactivateParent() {
    if(self != top)
    {
        var pbody = self.frameElement.ownerDocument.getElementById("body");
        var pdiv = self.frameElement.ownerDocument.createElement('div');
        pdiv.id = "poverlay"; // Id du new div
        pdiv.className = "modalbg";
        pbody.appendChild(pdiv);
    }
    var newdiv = document.createElement('div');
    newdiv.id = "overlay"; // Id du new div
    newdiv.className = "modalbg";
    var body = document.getElementsByTagName('body')[0];
    body.appendChild(newdiv);
}
function createPopup(objname,w,h) {
    var newdiv = document.createElement('div');
    newdiv.id = objname; // Id du popup (i.e. ModalWindow)
    newdiv.className = "modaldivbox";
    newdiv.style.width = w+"px";
    newdiv.style.height = h+"px";
    newdiv.style.margin = "-"+(h/2)+"px 0px 0px -"+(w/2)+"px";
    document.getElementById("overlay").appendChild(newdiv);
}
function cancelModal(target) {
    destroyPopup(target);
    activateParent();
}
function destroyPopup(objname) {
    var pop = document.getElementById(objname);
    document.getElementById("overlay").removeChild(pop);
}
function activateParent() {
    var overlay = document.getElementById("overlay");
    document.getElementsByTagName('body')[0].removeChild(overlay);
    if(self != top)
    {
        var poverlay = top.document.getElementById("poverlay");
        top.document.getElementById("body").removeChild(poverlay);
    }
}
function adjustModal(target) {
    var w = document.getElementById("modglobal").clientWidth;
    var h = document.getElementById("modglobal").clientHeight;
    document.getElementById(target).style.width = w+"px";
    document.getElementById(target).style.height = h+"px";
    document.getElementById("ModalWindow").style.background = "rgb(228,228,229)";
}
function updateModal(method,url,target,data) {
    data = typeof(data) != 'undefined' ? data : "";
    method = typeof(method) != 'undefined' ? method : "GET";
    makeRequest(method,url,target,data); // requete ajax;
}
// Exécution d'une fenêtre modale ------------------------------------------------------------------------- FIN



function makeRequest(method,url,target,data) {
    var xhr = createXHR();
    xhr.onreadystatechange = function() { 
        displayContents(xhr,target); 
    };
    xhr.open(method, url, true);
    if (method == "POST") {
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");                  
        xhr.send(data);
    }
    else {
        xhr.send(null);
    }
}

function createXHR() 
{
    var httpRequest = false;
    if (window.XMLHttpRequest) 
    { // Mozilla, Safari,...
        httpRequest = new XMLHttpRequest();
        if (httpRequest.overrideMimeType) 
        {
            httpRequest.overrideMimeType('text/xml');
        }
    } 
    else if (window.ActiveXObject) 
    { // IE
        try 
        {
            httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch (e) 
        {
            try 
            {
                httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } 
            catch (e) {}
        }
    }
    if (!httpRequest) 
    {
        alert('Abandon :( Impossible de créer une instance XMLHTTP');
        return false;
    }
    return httpRequest;
}

function displayContents(xhr,target) {
    if (xhr.readyState == 4) {
        if (xhr.status == 200) {
            document.getElementById(target).innerHTML = (xhr.responseText);
        } else if (xhr.status == 404) {
            alert('Le contenu n\'est pas accessible (404).');
            cancelModal(target);        
        } else {
            alert('Un problème inconnu est survenu avec la requête. (Code : '+xhr.status+')');
            cancelModal(target);
        }
    }
    else
    {
        waitIcon(target);
    }
}

function waitIcon(target) {
    var x = document.getElementById(target).clientWidth;
    var y = document.getElementById(target).clientHeight;
    var newdiv = document.createElement('div');
    newdiv.id = "hidder";
    newdiv.innerHTML = "<img id=\"waiticon\" style=\"position: relative;left:"+(x - 32) / 2+"px\;top:"+(y - 32) / 2+"px\" src=\"gui/ajax_load.gif\" />";    
    newdiv.style.zIndex = 150;
    newdiv.style.width = x+"px";
    newdiv.style.height = y+"px";
    newdiv.style.position = "absolute";
    newdiv.style.left = 0+"px";
    newdiv.style.top = 0+"px";
    newdiv.style.backgroundColor = "rgb(228, 228, 229)";
    document.getElementById(target).appendChild(newdiv);
}
function waitIconStop() {
    var child = document.getElementById('hidder');
    var objparent = child.parentNode.id;
    document.getElementById(objparent).removeChild(child);
}
function waitForm(target) {
    waitIcon(target);
    adjustModal('ModalWindow');
    return true;
}
function startDrag(el,ev)
{
	if (el.className == 'dragme')
	{
		stopDrag(el,ev); return;
	}
	el.className = "dragme"; globa = "move"; globy = ev.clientY; globi = parseInt(document.getElementById('msgholder').offsetHeight);
	el.style.height = (globi + 4) + "px";
}
function stopDrag(el,ev)
{
	if (globa != 'move') { return; } 
	el.className = 'forum_msg_icon'; globa='';globi='';globy='';
	var pp = el.parentNode.parentNode;
	pp.style.height = el.style.height;
	el.style.height = '';
	e = document.getElementById("infosave");
	function ajaxReq() {
		var xhr = createXHR();
		xhr.onreadystatechange = function() { 
				if (xhr.readyState == 4) {
				if (xhr.status == 200) {
					e.innerHTML = (xhr.responseText);
				} else if (xhr.status == 404) {
					alert('Le contenu n\'est pas accessible (404).');
					e.innerHTML = '';
				} else {
					alert('Un problème inconnu est survenu avec la requête. (Code : '+xhr.status+')');
					e.innerHTML = '';
				}
			}
			else
			{
				e.innerHTML = '<img src="gui/wait.gif" alt="" title="Enregistrement de la hauteur" />';
			}
		};
		xhr.open("GET","./inc/modal.inc.php?t=updateDMH&ta="+pp.style.height,true);
		xhr.send(null);
	}
	ajaxReq();	
}
function doDrag(el,ev)
{
	if(globa != 'move') { return; }
	var d = (globy - ev.clientY); var h = globi + d + 4;
	el.style.height = h + "px";
}

// GARBAGE -- GARBAGE -- GARBAGE -- GARBAGE -- GARBAGE -- GARBAGE -- GARBAGE -- 
function move(e,w)
{
    var pp = e.parentNode.parentNode;
    if (w == "up")
    {
        if (pp.offsetHeight <= (getClientSize('y') - 60))
        {
            pp.style.height = (pp.offsetHeight + 50) + "px";
            document.getElementById('framemsg').style.height = (document.getElementById('framemsg').offsetHeight + 50) + "px";
        }
    }
    else if (w == "down")
    {
        if (pp.offsetHeight >= 60)
        {
            pp.style.height = (pp.offsetHeight - 50) + "px";
            document.getElementById('framemsg').style.height = (document.getElementById('framemsg').offsetHeight - 50) + "px";
        }
    }
}
function makedragable(el,ev)
{
    if(el.className == "dragme")
    {
        stopdragable(el,ev);
        return false;
    }
    if(ev.button <= 1)
    {
        el.className = "dragme";
    }
}
function stopdragable(el,ev)
{
    if(el.className == "dragme")
    {
        el.className = "forum_msg_icon";
        e = document.getElementById("infosave");
        var pp = el.parentNode.parentNode;
        globi=0;globj=0;globk=0;
        function ajaxReq() {
            var xhr = createXHR();
            xhr.onreadystatechange = function() { 
                    if (xhr.readyState == 4) {
                    if (xhr.status == 200) {
                        e.innerHTML = (xhr.responseText);
                    } else if (xhr.status == 404) {
                        alert('Le contenu n\'est pas accessible (404).');
                        e.innerHTML = '';
                    } else {
                        alert('Un problème inconnu est survenu avec la requête. (Code : '+xhr.status+')');
                        e.innerHTML = '';
                    }
                }
                else
                {
                    e.innerHTML = '<img src="gui/wait.gif" alt="" title="Enregistrement de la hauteur" />';
                }
            };
            xhr.open("GET","./inc/modal.inc.php?t=updateDMH&ta="+pp.offsetHeight,true);
            xhr.send(null);
        }
        ajaxReq();
    }
}
function dragthis(el,ev)
{
  if (el.className == "dragme")
  {
    var pp = el.parentNode.parentNode;
    y = ev.clientY + document.body.scrollTop  - document.body.clientTop;
    if(globi==0) { globi = pp.offsetTop; globj = y-pp.offsetTop; globk = pp.offsetHeight; }
    pp.style.height = globk - ((y-globj)-globi) + "px";
    document.getElementById('forum_msg_body').style.height = globk - ((y-globj)-globi) - 25 + "px";
    return false;
  }
  return false;
}