function RechMb()
{
    advAJAX.get({
        url        : "ajax.php",
        parameters : {
            "Fich"   : "ad_rechmb",
            "Method" : (document.getElementById("RechNom").checked ? "m_nom" : "m_id"),
            "Rech"   : document.getElementsByName("rech")[0].value,
            "s"      : "portail"
        },
        onLoading  : function (obj)
        {
            document.getElementById("LogMessMb").innerHTML = "<" + "img src='/sites/admin/skins/images/process.gif' alt='' style='vertical-align: middle;' />";
        },
        onComplete : function(obj) {
            document.getElementById("LogMessMb").innerHTML = "";
        },
        onSuccess  : function(obj) {
            eval (obj.responseText);
            
            if (Res["Err"])
            {
                alert (Res["Err"]["Mess"]);
                return;
            }
            
            document.getElementById("Resultat").innerHTML = Res["Resultat"];
        }
    });
    
}

function CachAccSel (Id)
{
    document.getElementById(Id).style.display = 'none';
    document.getElementById('d_portail').style.display = '';
}

function AffAccSel (Id)
{
    document.getElementById('affich_desc').innerHTML = document.getElementById(Id).innerHTML;
}

function AffichLogo (NodeLien)
{
    NodeLien.getElementsByTagName('span')[0].style.display = '';
}

function CacherLogo (NodeLien)
{
    NodeLien.getElementsByTagName('span')[0].style.display = 'none';
}

function toggle (Id)
{
    var Dis = document.getElementById(Id).style.display;
    document.getElementById(Id).style.display = Dis == 'none' ? '' : 'none';

}

function VerifPass()
{
    FormAjax ("/ajax.php", "connect", document.getElementById("FormLog"), {
        NodeLoad : document.getElementById("LogMess"),
        onSuccess : function (NodeForm, Res)
        {
            if (Res["IsLog"] == "false")
                document.getElementById("LogMess").innerHTML = "<img src='/sites/portail/skins/images/non.gif' alt='' style='vertical-align: middle;' />";
            else
                document.getElementById('ProfilBox').innerHTML = Res["Affich"];
        }
    });
    
}

function Deconnect()
{
    advAJAX.post ({
        url : "/ajax.php",
        parameters : {
            "s"     : "portail",
            "Fich"  : "deconnect"
        },
        onSuccess : function (obj) {
            eval (obj.responseText);

            if (Res["Err"])
            {
                NodeMess.innerHTML = Res["Err"]["Mess"];
                return;
            }
            
            document.getElementById('ProfilBox').innerHTML = Res["Affich"];
            
        }

    });

}

function VerifLien (NodeForm)
{
    FormAjax ("/ajax.php", "lien", NodeForm, {
        NodeLoad : document.getElementById("Load"),
        MessGen  : document.getElementById("Mess"),
        ClassErr : "ErrForm",
        ClassNormal : "",
        Method   : "post"
    });
    
}

function VerifDl (NodeForm)
{
    FormAjax ("/ajax.php", "download", NodeForm, {
        NodeLoad : document.getElementById("Load"),
        MessGen  : document.getElementById("Mess"),
        ClassErr : "ErrForm",
        ClassNormal : "",
        Method   : "post"
    });
    
}

function VerifInscr()
{
    FormAjax ("/ajax.php", "inscr", document.getElementById("Inscr"), {
        NodeLoad : document.getElementById("Load"),
        ClassErr : "ErrForm",
        ClassNormal : ""
    });
    
}

function ValidInscr()
{
    FormAjax ("/ajax.php", "inscr_valid", document.getElementById("ValidInscr"), {
        NodeLoad : document.getElementById("Load"),
        MessGen  : document.getElementById("Mess")
    });
    
}

function VerifProfil (AncienAv)
{
    if (AncienAv && (document.getElementsByName("Avatar")[0].value != AncienAv || document.getElementsByName("file")[0].value != "") 
        && !confirm("La modification de l'avatar entrainera la suppression du fichier de l'ancien avatar.\\nVoulez-vous continuer ?"))
        return;
    
    FormAjax ("/ajax.php", "profil", document.getElementById("Profil"), {
        NodeLoad : document.getElementById("ProfilMess"),
        ClassErr : "ErrForm",
        ClassNormal : ""
    });
    
}

function PopUpload (Width, Height, Redirect)
{
    window.open ("index.php?s=admin&p=up&w=" + Width + "&h=" + Height + "&redirect=" + escape (Redirect),
                 "up",
                 "width=250,height=105");
}

function PopProfil()
{
    var X = 0, Y = 0;
    var width = 630, height = 520;
    if (parseInt (navigator.appVersion) >= 4 )
    {
        X = (screen.width  - width ) / 2;
        Y = (screen.height - height) / 2;
    }
    
    window.open ("index.php?p=profil",
                 "profile",
                 "width="+width+",height="+height+",top="+Y+",left="+X+",scrollbars=yes");
}

function PopEnreg()
{
    var X = 0, Y = 0;
    var width = 630, height = 520;
    if (parseInt (navigator.appVersion) >= 4 )
    {
        X = (screen.width  - width ) / 2;
        Y = (screen.height - height) / 2;
    }
    
    window.open ("index.php?p=inscr",
                 "profile",
                 "width="+width+",height="+height+",top="+Y+",left="+X+",scrollbars=yes");
}

function PopValid()
{
    var X = 0, Y = 0;
    var width = 300, height = 170;
    if (parseInt (navigator.appVersion) >= 4 )
    {
        X = (screen.width  - width ) / 2;
        Y = (screen.height - height) / 2;
    }
    
    window.open ("index.php?p=inscr&mod=vform",
                 "profile",
                 "width="+width+",height="+height+",top="+Y+",left="+X);
}

MenuOuvert = new Array();
function OuvrirMenu(Id)
{
    if (MenuOuvert[Id])
        window.clearInterval (MenuOuvert[Id]);
    
    document.getElementById(Id).style.display = "block";

}

function FermerMenu(Id)
{
    MenuOuvert[Id] = window.setInterval ("DoFermerMenu ('" + Id + "');", 1000);
}

function DoFermerMenu(Id)
{
    window.clearInterval (MenuOuvert[Id]);
    document.getElementById(Id).style.display = 'none';
}

function ValidRelFo()
{
    FormAjax ("/ajax.php", "relfo", document.getElementById("ValidRelFo"), {
        NodeLoad : document.getElementById("Mess"),
        MessGen  : document.getElementById("Mess"),
        ClassErr : "ErrForm",
        ClassNormal : ""
    });
    
}

function VerifArt()
{
    FormAjax ("/ajax.php", "article", document.getElementById("VerifArt"), {
        NodeLoad : document.getElementById("Load"),
        MessGen  : document.getElementById("Mess"),
        ClassErr : "ErrForm",
        ClassNormal : "",
        Method   : "post"
    });
    
}

function VerifBBCode(NodeForm, NodeMess, NodeLoad, Submit)
{
    FormAjax ("/ajax.php", "texte_bbcode", NodeForm, {
        NodeLoad : NodeLoad,
        MessGen  : NodeMess,
        ClassErr : "ErrForm",
        ClassNormal : "",
        Method   : "post"
    });
    
}

function Previsualisation (NodeBut, NodeTextarea, NodeMess, NodeLoad, Site)
{
    advAJAX.post ({
        url : "/ajax.php",
        parameters : {
            "s"     : Site,
            "Fich"  : "texte_prevu",
            "Texte" : NodeTextarea.value
        },
        onLoading : function (obj) {
            NodeLoad.innerHTML = "<img src='/sites/portail/skins/images/process.gif' alt='' style='vertical-align: middle;' />";
            NodeBut.disabled = true;
        },
        onComplete : function (obj) {
            NodeLoad.innerHTML = "";
            NodeBut.disabled = false;
        },
        onSuccess : function (obj) {
            eval (obj.responseText);

            if (Res["Err"])
            {
                NodeMess.innerHTML = Res["Err"]["Mess"];
                return;
            }
            
            NodeMess.innerHTML = Res["Mess"];
            NodeMess.style.display = "";
            
        }

    });

}

function CherchMb()
{
    FormAjax ("/ajax.php", "cherchmb", document.getElementById("CherchMb"), {
        NodeLoad : document.getElementById("Load"),
        MessGen  : document.getElementById("Mess"),
        ClassErr : "ErrForm",
        ClassNormal : ""
    });
    
}

function SuppComm (Id, Site)
{
    if (!confirm ("Êtes-vous sûr de vouloir supprimer ce commentaire ?"))
        return;

    document.getElementById("com_"+Id).parentNode.removeChild (document.getElementById("com_"+Id));
    advAJAX.post ({
        url : "/ajax.php",
        parameters : {
            "s"     : "portail",
            "Fich"  : "suppcomm",
            "id"    : Id,
            "site"  : Site
        },
        onSuccess : function (obj) {
            eval (obj.responseText);

            if (Res["Err"])
            {
                alert (Res["Err"]["Mess"]);
                return;
            }
        }

    });

}

function EditComm (Id, Site)
{
    advAJAX.post ({
        url : "/ajax.php",
        parameters : {
            "s"     : "portail",
            "Fich"  : "editcomm",
            "id"    : Id,
            "site"  : Site
        },
        onSuccess : function (obj) {
            eval (obj.responseText);

            if (Res["Err"])
            {
                alert (Res["Err"]["Mess"]);
                return;
            }

            document.getElementById("edit_com_"+Id).innerHTML = "<textarea style='height: 200px; width: 100%;'>" + Res["Str"] + "</textarea><br /><div style='text-align: right;'><input type='button' value='Enregistrer >>>' onclick='DoEditComm (\"" + Id + "\", \"" + Site + "\");' /></div><div id='com_err'></div>";
        }

    });
    
}

function DoEditComm (Id, Site)
{
    advAJAX.post ({
        url : "/ajax.php",
        parameters : {
            "s"     : "portail",
            "Fich"  : "editcomm",
            "id"    : Id,
            "site"  : Site,
            "texte" : document.getElementById("edit_com_"+Id).getElementsByTagName('textarea')[0].value
        },
        onSuccess : function (obj) {
            eval (obj.responseText);

            if (Res["Err"])
            {
                document.getElementById('com_err').innerHTML = Res["Err"]["Mess"];
                return;
            }

            document.getElementById("edit_com_"+Id).innerHTML = Res["Str"];
        }

    });
    
}

function SelectImgVote (i, Id)
{
    var i = Math.floor (i);

    with (document.getElementById('note_' + Id + '_' + i))
    {
        ImgName = src.substr (src.search(/\/[^/]+$/) + 1, src.length);
        ImgSrc  = src.substr (0, src.search(/\/[^/]+$/) + 1);
    }

    var j = 0;
    for (; j <= i ; ++j)
        document.getElementById('note_' + Id + '_' + j).src = ImgSrc + 'vote_act.gif';

    for (; j < 5; ++j)
        document.getElementById('note_' + Id + '_' + j).src = ImgSrc + 'vote_des.gif';

}

function Voter (i, Id, Type)
{
    with (document.getElementById('note_' + Id + '_' + i))
    {
        ImgName = src.substr (src.search(/\/[^/]+$/) + 1, src.length);
        ImgSrc  = src.substr (0, src.search(/\/[^/]+$/) + 1);
    }

    var Note = parseInt(i);

    advAJAX.post ({
        url : "/ajax.php",
        parameters : {
            "s"     : "portail",
            "Fich"  : "voter",
            "id"    : Id,
            "type"  : Type,
            "note"  : String (Note)
        },
        onSuccess : function (obj) {
            eval (obj.responseText);

            if (Res["Err"])
            {
                alert (Res["Err"]["Mess"]);
                return;
            }

            with (document.getElementById('note_' + Id))
                innerHTML = "<img src='" + ImgSrc + "vote_ok.gif' alt='' /> " 
                            + innerHTML;

            for (var j = 0; j < 5; ++j)
            {
                document.getElementById('note_' + Id + '_' + j).onmouseover  = null;
                document.getElementById('note_' + Id + '_' + j).onmouseout   = null;
                document.getElementById('note_' + Id + '_' + j).onclick      = null;
            }
        }

    });
    
}

function DoRech()
{
    var NodeSite = document.getElementById('SRSite');
    var NodeRes  = document.getElementById('ValSR');

    if (NodeSite.selectedIndex == -1)
    {
        NodeRes.innerHTML = "Vous devez préciser où s'effectue la recherche.";
        return;
    }

    if (document.getElementById('SuperRech').value.length < 3)
    {
        NodeRes.innerHTML = "Votre recherche doit avoir au moins 3 caractères.";
        return;
    }

    advAJAX.get ({
        url : "/ajax.php",
        parameters : {
            "s"     : "portail",
            "Fich"  : "recherche",
            "Mot"   : document.getElementById('SuperRech').value,
            "Site"  : NodeSite.options[NodeSite.selectedIndex].value
        },
        onLoading : function(obj) {
            document.getElementById('SRLien').innerHTML = "<img src='/sites/portail/skins/images/process.gif' alt='' style='vertical-align: middle;' /> Rechercher >>>";
        },
        onSuccess : function (obj) {
            document.getElementById('SRLien').innerHTML = '<a href="#" onclick="DoRech(); return false;">Rechercher >>></a>';
            eval (obj.responseText);

            if (Res["Err"])
            {
                NodeRes.innerHTML = Res["Err"]["Mess"];
                return;
            }

            NodeRes.innerHTML = Res["Resultat"];
        }

    });
    
}

function RAZRech()
{
    document.getElementById('ValSR').innerHTML = 'Aucun résultat';
    document.getElementById('SuperRech').value = 'Recherche';
}

function setSndTrack (File)
{
    document.getElementById('mediaplayer').innerHTML = '<EMBED SRC="'+File+'" HIDDEN=false AUTOSTART=true LOOP=false height="45">';
}

function ChoixUpPort()
{
    if (document.getElementById('_updd').checked)
    {
        document.getElementById('formdd').style.display = 'block';
        document.getElementById('formli').style.display = 'none';
        return true;
    }
    
    document.getElementById('formdd').style.display = 'none';
    document.getElementById('formli').style.display = 'block';

}

function ShowAvat()
{
    document.getElementById('DispAvatAlea').style.display = '';
    document.getElementById('HideAvatAlea').style.display = 'none';
}

function HideAvat()
{
    document.getElementById('DispAvatAlea').style.display = 'none';
    document.getElementById('HideAvatAlea').style.display = '';
}

function AvatAlea(Url)
{
    advAJAX.post({
        url        : "/ajax.php",
        parameters : {
            "Fich"   : "alea_avat",
            "s"      : "portail",
            "url"    : Url
        },
        onLoading  : function (obj)
        {
            toggle ('alea_autre');
            toggle ('alea_chgt');
        },
        onSuccess  : function(obj) {
            eval (obj.responseText);
            
            if (Res["Err"])
            {
                alert (Res["Err"]["Mess"]);
                return;
            }

            var Img = new Image();
            Img.src = Res["UrlImg"];
            Img.onload = function() 
            { 
                toggle ('alea_autre');
                toggle ('alea_chgt');

                var Dis = document.getElementById("DispAvatAlea").style.display != 'none';
                document.getElementById("avat_alea").innerHTML = Res["StrImg"];

                if (Dis) ShowAvat();
            }
        }
    });
    
}
