/*
    11/07/2006 LChambon
    Variables d'entrées:
        - _maxisite_lang : détermine la langue en cours (exemple : "fr")
        - _maxisite_rooturl : détermine le chemin du site (exemples : "http://localhost/web/" ou "/web/")
*/

var popup_origine="";
var fentree=null;
var popup_ferme="";

if ((typeof _maxisite_lang == "string") || (_maxisite_lang == ''))// Détermine la langue en cours
{
	_maxisite_lang = _maxisite_lang.toLowerCase();
} else
{
	_maxisite_lang = "fr";
}

if ((typeof _maxisite_rooturl != "string") || (_maxisite_rooturl == ''))// Détermine le chemin du site
{
	_maxisite_rooturl = "/";
}

// Charge le fichier de langue
var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");
script.src = _maxisite_rooturl + "BibliRessources/js/JsTree/lang/fr.js";
head.appendChild(script);
if(_maxisite_lang != "fr")
{
    script = document.createElement("script");
    script.src = _maxisite_rooturl + "BibliRessources/js/JsTree/lang/" + _maxisite_lang + ".js";
    head.appendChild(script);
}

script = document.createElement("script");
script.src = _maxisite_rooturl + "BibliThemes/js/JsTree/lang/fr.js";
head.appendChild(script);
if(_maxisite_lang != "fr")
{
    script = document.createElement("script");
    script.src = _maxisite_rooturl + "BibliThemes/js/JsTree/lang/" + _maxisite_lang + ".js";
    head.appendChild(script);
}


if (window.name=='')
{
    window.name="gestion";
    parent.name=window.name;
    parent.parent.name=window.name
}

var nbfldcoord=0;
var alignbasetext="left";
width=380;
offsety=(10);

tabicontrashopen=new Array(""); // 4 : icones poubelle fermée
tabicontrashclosed=new Array(""); // 5 : icones poubelle ouverte
tabiconracineopen=new Array(""); // 7 : icones racine ouverte
tabiconracineclosed=new Array(""); // 8 : icones racine fermée

// pictos "cases à cocher"
if (document.images) {
    // noeud
	var on2=new Image; //coché
	on2.src=ICONPATH+"coche1.gif";
	var mid2=new Image; //semi-coché
	mid2.src=ICONPATH+"case_3.gif";
	var off2=new Image; //non coché
	off2.src=ICONPATH+"case1.gif";

    // éléments simples	
	var on1=new Image;
	var off1=new Image;
	on1.src=ICONPATH+"coche2.gif";
	off1.src=ICONPATH+"case2.gif";
}

//gestion clicks: sélection des éléments dépendants ou non.
var csfauto = true;
var csfmanuel = false;

var rc=0;
var idcoupe=0;
var idcatcoupe=0;
var listidcoupe='';
var nbcoupe=0;
var listidalias='';
var nbalias=0;
var listidcopie='';
var nbcopie=0;

nbfldcoord=214;
alignbasetext='contextmenu';
var url_opener='';
var msginit = '';

USETEXTLINKS = 0;
STARTALLOPEN = 0;
HIGHLIGHT = 0;
PERSERVESTATE = 0;
var counterI = 0;
var indexLine = -1;

/*****************************************************************************************************************/ 

function openpopup(w, h, name, url)
{
	var docdivblock = top.document.getElementById('page_action');
    if (docdivblock)    
      top.show_page_action(url,'Edition',true,true,true,window);
    else
	{
		docdivblock = parent.document.getElementById('page_action');
   	 if (docdivblock)    
   	   parent.show_page_action(url,'Edition',true,true,true,window);
  	  else
  	  { 
   	     name=name.replace(" " ,""); 
		docdivblock = parent.document.getElementById('div_'+name)  
		//alert('name='+name);
		fentree=window.open('', name, 'top=' + (screen.height-h)/2 + ',left=' + (screen.width-w)/2 + ',width=' + w + ',height=' + h + ',resizable=yes,toolbar=no,location=no,menubar=no,scrollbars=yes,status=no');
		fentree.location=url;
		fentree.opener=window;   
		if (docdivblock)
		   docdivblock.className='divShow';  
		fentree.focus();
	    }
	};
}

function popupedit(tn,paramedit)
{ 
    openpopup(840, 700, 'editnode_form', 'nodes/editnode.aspx?name_opener=' + window.name + '&url_opener=' + url_opener+paramedit);
}  

function popupreferencing(id)
{ 
    openpopup(840, 700, 'referencing_form', 'nodes/EditReferencement.aspx?idnode=' + id);
}  

function popuprights(param)
{ 
    openpopup(500, 450, 'editrule_form', 'nodes/editrule.aspx?name_opener=' + window.name + '&url_opener=' + url_opener+param);  
}

function popuprightsaudit(param) {
    openpopup(500, 450, 'editrule_form', 'nodes/editruleaudit.aspx?name_opener=' + window.name + '&url_opener=' + url_opener + param);
}
function popupdel(paramedit)
{ 
    window.location='tree.aspx?name_opener=' + window.name + '&url_opener=' + url_opener+paramedit;
}

function popupcolle(paramedit)
{ 
    window.location='tree.aspx?bo=1&name_opener=' + window.name + '&url_opener=' + url_opener + paramedit;
}

function popupcollealias(paramedit)
{ 
    window.location='tree.aspx?name_opener=' + window.name + '&url_opener=' + url_opener + paramedit;
}

function popupsendmailing(id)
{
    openpopup(840, 700, 'sendmail_form', 'MailingList/ParamSend.aspx?idnode=' + id);
}

function popupsendexport(id) {
    openpopup(840, 700, 'sendexport_form', 'Audit/AuditExport.aspx?idnode=' + id);
}

function popupEditSeo(id) {
    //top.popupDim(500, 450, 'SEO/Edit.aspx?idnode=' + id, 'Edition Referencement', window, 'yes');
    openpopup(750, 550, 'Edition du référencement', 'SEO/Edit.aspx?idnode=' + id);
}

function popupCheckSeo(id) {
    GoTo('SEO/Check.aspx?idnode=' + id, 'mainFrame2');
}

/*****************************************************************************************************************/ 

function edit(tn,paramedit)
{
	parent.frames[1].window.location.href='nodes/editnode.aspx?name_opener=' + window.name + '&url_opener=' + url_opener+paramedit;
}

function createnode(typnode,idparentnode)
{
    var createtypnode = typnode;
    var pos = typnode.indexOf('.', 0);
    if(pos > 0) createtypnode = typnode.substring(0, pos);
    popupedit(typnode, "&idbegin=" + RootId + "&idparentnode=" + idparentnode + "&typnode=" + createtypnode + (pos > 0 ? "&typfolder=" + typnode.substring(pos+1) : ""));
}

function referencing(id)
{
    popupreferencing(id);
}

function editnode(typnode,idnode)
{
    popupedit(typnode,param="&idbegin=" + RootId + "&actions=formupdate&idnode=" + idnode + "&typnode=" + typnode);
}  

function delrub(id,typnode,destroy)
{
    var txtc;
    var param='&idbegin=' + RootId + '&actions=supprimer&id=' + id;

    if (typnode != '1.2')
    {
        if(destroy)
        {
            if(typnode==1) txtc=IntitulesTra["DESTROY_ALLCONFIRM"];  
            else txtc=IntitulesTra["DESTROY_CONFIRM"].replace('{typnodename}', srcName[typnode]);	              
        }
        else 
        {
            if(typnode==1) txtc=IntitulesTra["DELETE_MOVEALLINTRASH"].replace('{typnodename}', srcName[typnode]);  
            else txtc=IntitulesTra["DELETE_MOVEINTRASH"].replace('{typnodename}', srcName[typnode]);
        }
	}
    else txtc=IntitulesTra["DELETE_EMPTYTRASHCONFIRM"]; 
    
    if (confirm(txtc))
    {
        popupdel(param);
    }
}

function openrights(id)
{
    popuprights("&idnode=" + id);
}

function openrightsaudit(id) {
    popuprightsaudit("&idnode=" + id);
}  
 
function coupefiche(id)
{
    var strtmp=',' + listidcoupe + ',';
    var strid='' + id;
    var pos=strtmp.indexOf(',' + id + ',', 0);
    if (pos<0)
    {
        listidcoupe=listidcoupe+id+',';
        nbcoupe++;
    }
    else
    {
        listidcoupe=listidcoupe.substring(0,pos) + listidcoupe.substring(pos+strid.length+1);
        nbcoupe--;
    }
    affpressepapier(nbcoupe);
    cClick();
}

function annulecoupe()
{
    listidcoupe='';
    nbcoupe=0;
    affpressepapier(nbcoupe);
    cClick();
}

function copiefiche(id)
{
    var strtmp=',' + listidcopie + ',';
    var strid='' + id;
    var pos=strtmp.indexOf(',' + id + ',', 0);
    if (pos<0)
    {
        listidcopie=listidcopie + id + ',';
        nbcopie++;
    }
    else
    {
        listidcopie=listidcopie.substring(0,pos) + listidcopie.substring(pos+strid.length+1);
        nbcopie--;
    }
    affpressepapiercopie(nbcopie);
    cClick();
}

function annulecopie()
{
    listidcopie='';
    nbcopie=0;
    affpressepapier(nbcopie);
    cClick();
}  

function collefiche(id)
{
    if (listidcoupe=='' && listidcopie=='') alert(IntitulesTra["PASTE_NONE"]);
    else
    {
        if ((nbcoupe>0) && confirm(IntitulesTra["CUT_CONFIRM"])) popupcolle("&idbegin=" + RootId + "&actions=coller&id=" + id + "&listidpaste=" + listidcoupe + "&coupe=1");
        else if (confirm(IntitulesTra["COPY_CONFIRM"])) popupcolle("&idbegin=" + RootId + "&actions=coller&id=" + id + "&listidpaste=" + listidcopie + "&coupe=0");
    }
    cClick();
} 

function colledessous(id)
{
    if (listidcoupe=='' && listidcopie=='') alert(IntitulesTra["PASTE_NONE"]);
    else
    {
        if ((nbcoupe>0) && confirm(IntitulesTra["CUT_CONFIRM"])) popupcolle("&idbegin=" + RootId + "&actions=coller&type=deplacer&id=" + id + "&listidpaste=" + listidcoupe + "&coupe=1");
        else if (confirm(IntitulesTra["COPY_CONFIRM"])) popupcolle("&idbegin=" + RootId + "&actions=coller&type=deplacer&id=" + id + "&listidpaste=" + listidcopie + "&coupe=0");
    }
    cClick();
} 

function ajoutealias(id)
{
    var strtmp=',' + listidalias + ',';
    var strid='' + id;
    var pos=strtmp.indexOf(',' + id + ',', 0);
    if (pos<0)
    {
        listidalias=listidalias + id + ',';
        nbalias++;
    }
    else
    {
        listidalias=listidalias.substring(0,pos) + listidalias.substring(pos+strid.length+1);
        nbalias--;
    }
    affpressepapieralias(nbalias);
    cClick();
}  

function annuleallalias()
{
    listidalias='';
    nbalias=0;
    affpressepapieralias(nbalias);
    cClick();
}  

function collealias(id)
{
    if (listidalias=='') alert(IntitulesTra["ALIAS_NONE"]);
    else if (confirm(IntitulesTra["ALIAS_CONFIRM"])) popupcollealias("&idbegin=" + RootId + "&actions=alias&id=" + id + "&listidalias=" + listidalias);
    cClick();
}  

function insertlink(id,url)
{
    if (!window.opener) alert(IntitulesTra["WINDOW_NONE"]);
    else 
    {
        window.opener.btnInsertHyperlink_onclick('', url);
        window.opener.focus();
    }
}

/*****************************************************************************************************************/ 

function sepbutton()
{
    return '<tr><td class="contextMenuSeparateur0"><img src="' + ICONPATH + '"shim.gif" border=0 height="1" width="1"></td><td class="contextMenuSeparateur1"><img src="' + ICONPATH + 'shim.gif" border=0 height="1" width="1"></td></tr>';
} 

/* Modification de l'élément */
function lienedit(id,typnode,codeintitule,icone)
{
    var realtypnode = typnode;
    var pos = typnode.indexOf('.', 0);
    if(pos > 0) realtypnode = typnode.substring(0, pos);
    
    if ((nbcoupe<1) && (nbcopie<1) && (nbalias<1)) return sepbutton() + menulineadd(icone,getIntitule(codeintitule),'editnode(' + realtypnode + ',' + id + ')',typnode);
    else return '';
}

/* Suppression de l'élément : transfert vers la corbeille */
function liensuppr(id,typnode,codeintitule,icone)
{
    var realtypnode = typnode;
    var pos = typnode.indexOf('.', 0);
    if(pos > 0) realtypnode = typnode.substring(0, pos);
    
    if ((nbcoupe<1) && (nbcopie<1) && (nbalias<1)) return sepbutton() + menulineadd(icone,getIntitule(codeintitule),'delrub(\'' + id + '\',' + realtypnode + ',false)',typnode);
    else return '';
}

/* Suppression de l'élément : destruction définitive & vidage de la corbeille */
function liensuppr_intrash(id,typnode,codeintitule,icone,emptytrash)
{
    var realtypnode = typnode;
    var pos = typnode.indexOf('.', 0);
    if(pos > 0) realtypnode = typnode.substring(0, pos);
    
    if ((nbcoupe<1) && (nbcopie<1) && (nbalias<1)) return sepbutton() + menulineadd(icone,getIntitule(codeintitule),'delrub(\''+id+'\','+realtypnode+',true)',typnode);
    else return '';
}  

/* Droits sur le l'élément */
function liendroits(id,typnode,codeintitule,icone)
{ 
    if ((nbcoupe<1) && (nbcopie<1) && (nbalias<1)) return sepbutton() + menulineadd(icone,getIntitule(codeintitule),'openrights(' + id + ')',typnode);
    else return '';
}

/* Droits sur le l'élément */
function liendroitsaudit(id, typnode, codeintitule, icone) {
    if ((nbcoupe < 1) && (nbcopie < 1) && (nbalias < 1))
        return sepbutton() + menulineadd(icone, getIntitule(codeintitule), 'openrightsaudit(' + id + ')', typnode);
    else return '';
}

/* Coupe l'élément */
function liencoupefiche(id,typnode,codeintitule,icone)
{
    var strtmp=',' + listidcoupe + ',';
    var strid='' + id;
    var pos=strtmp.indexOf(',' + id + ',', 0);

    if ((nbcopie<1) && (nbalias<1) && (pos<0)) return sepbutton() + menulineadd(icone,getIntitule(codeintitule),'coupefiche(' + id + ')',typnode);
    else return '';
}

/* Annule la coupe de l'élément */
function liencoupeficheannule(id,typnode,codeintitule,icone)
{
    var strtmp=',' + listidcoupe + ',';
    var strid='' + id;
    var pos=strtmp.indexOf(',' + id + ',', 0);

    if ((pos>=0) && (nbcoupe>0)) return sepbutton() + menulineadd(icone,getIntitule(codeintitule),'coupefiche(' + id + ')',typnode);
    else return '';
}

/* Copie l'élément */
function liencopiefiche(id,typnode,codeintitule,icone)
{
    var strtmp=',' + listidcopie + ',';
    var strid='' + id;
    var pos=strtmp.indexOf(',' + id + ',', 0);
    
    if ((nbcoupe<1) && (nbalias<1) && (pos<0)) return sepbutton() + menulineadd(icone,getIntitule(codeintitule),'copiefiche(' + id + ')',typnode);
    else return '';
}

/* Annule la copie de l'élément */
function liencopieficheannule(id,typnode,codeintitule,icone)
{
    var strtmp=',' + listidcopie + ',';
    var strid='' + id;
    var pos=strtmp.indexOf(',' + id + ',', 0);
   
    if ((pos>=0) && (nbcopie>0)) return sepbutton() + menulineadd(icone,getIntitule(codeintitule),'copiefiche(' + id + ')',typnode);
    else return '';
}

/* Colle dedans les éléments coupés */
function liencollecoupefiche(id,typnode,codeintitule,icone)
{
    var strtmp=',' + listidcoupe + ',';
    var strid='' + id;
    var pos=strtmp.indexOf(',' + id + ',', 0);
    
    if ((pos<0) && (nbcoupe>0)) return sepbutton() + menulineadd(icone,getIntitule(codeintitule),'collefiche(' + id + ')',typnode);
    else return '';
}

/* Colle dedans les éléments copiés */
function liencollecopiefiche(id,typnode,codeintitule,icone)
{
    var strtmp=',' + listidcopie + ',';
    var strid='' + id;
    var pos=strtmp.indexOf(',' + id + ',', 0);

    if ((pos < 0) && (nbcopie>0)) return sepbutton() + menulineadd(icone,getIntitule(codeintitule),'collefiche(' + id + ')',typnode);
    else return '';
}

/* Colle dessous les éléments coupés */
function liencollecoupedessous(id,typnode,codeintitule,icone)
{
    var strtmp=',' + listidcoupe + ',';
    var strid='' + id;
    var pos=strtmp.indexOf(',' + id + ',', 0);
    
    if ((pos<0) && (nbcoupe>0)) return sepbutton() + menulineadd(icone,getIntitule(codeintitule),'colledessous(' + id + ')',typnode);
    else return '';
}

/* Colle dessous les éléments copiés */
function liencollecopiedessous(id,typnode,codeintitule,icone)
{
    var strtmp=',' + listidcopie + ',';
    var strid='' + id;
    var pos=strtmp.indexOf(',' + id + ',', 0);
    
    if ((pos<0) && (nbcopie>0)) return sepbutton() + menulineadd(icone,getIntitule(codeintitule),'colledessous(' + id + ')',typnode);
    else return '';
}

/* Annule la coupe de tous les éléments */
function lienannulecoupeall(id,typnode,codeintitule,icone)
{
    var strtmp=',' + listidcoupe + ',';
    var strid='' + id;
    var pos=strtmp.indexOf(',' + id + ',', 0);

    if (((pos < 0) && (nbcoupe > 0)) || ((pos >= 0) && (nbcoupe > 1))) return sepbutton() + menulineadd(icone,getIntitule(codeintitule),'annulecoupe()',typnode);
    else return '';
}

/* Annule la copie de tous les éléments */
function lienannulecopieall(id,typnode,codeintitule,icone)
{
    var strtmp=',' + listidcopie + ',';
    var strid='' + id;
    var pos=strtmp.indexOf(',' + id + ',', 0);
    
    if (((pos < 0) && (nbcopie > 0)) || ((pos >= 0) && (nbcopie > 1))) return sepbutton() + menulineadd(icone,getIntitule(codeintitule),'annulecopie()',typnode);
    else return '';
}

/* Créer un alias à partir de l'élément */
function lienajoutealias(id,typnode,codeintitule,icone)
{
    var strtmp=',' + listidalias + ',';
    var strid='' + id;
    var pos=strtmp.indexOf(',' + id + ',', 0);
    
    if ((nbcoupe<1) && (nbcopie<1) && (pos<0)) return sepbutton() + menulineadd(icone,getIntitule(codeintitule),'ajoutealias(' + id + ')',typnode);
    else return '';
} 

/* Annule la création d'alias de l'élément */
function lienajoutealiasannule(id,typnode,codeintitule,icone)
{
    var strtmp=',' + listidalias + ',';
    var strid='' + id;
    var pos=strtmp.indexOf(',' + id + ',', 0);
    
    if ((pos>=0) && (nbalias>0)) return sepbutton() + menulineadd(icone,getIntitule(codeintitule),'ajoutealias(' + id + ')',typnode);
    else return '';
} 

/* Annule la création des alias */
function lienannuleallalias(id,typnode,codeintitule,icone)
{
    var strtmp=',' + listidalias + ',';
    var strid='' + id;
    var pos=strtmp.indexOf(',' + id + ',', 0);
    
    if (((pos < 0) && (nbalias > 0)) || ((pos >= 0) && (nbalias > 1))) return sepbutton() + menulineadd(icone,getIntitule(codeintitule),'annuleallalias()',typnode);
    else return '';
}

/* Génère les alias dans l'élément */
function liencollealias(id,typnode,codeintitule,icone)
{
    if (nbalias > 0) return sepbutton() + menulineadd(icone,getIntitule(codeintitule),'collealias(' + id + ')',typnode);
    else return '';
}

/* Créer un élément */
function liencreatenode(id,typnode,codeintitule,icone)
{
    if ((nbcoupe<1) && (nbcopie<1) && (nbalias<1)) return menulineadd(icone,getIntitule(codeintitule),'createnode(\'' + typnode + '\',' + id + ')', typnode);
    else return '';
}

/* Gérer le référencement */
function lienreferencing(id,typnode,codeintitule,icone)
{
    if ((nbcoupe<1) && (nbcopie<1) && (nbalias<1))
        return menulineadd(icone,getIntitule(codeintitule),'referencing(' + id + ')', typnode);
    else
        return '';
}

function liensendmailing(id,typnode,codeintitule,icone)
{
    if ((nbcoupe<1) && (nbcopie<1) && (nbalias<1)) 
        return sepbutton() + menulineadd(icone,getIntitule(codeintitule),'popupsendmailing(' + id + ')', typnode);
    else
        return '';
}

function liensendexprot(id, typnode, codeintitule, icone) {
    if ((nbcoupe < 1) && (nbcopie < 1) && (nbalias < 1))
        return menulineadd(icone, getIntitule(codeintitule), 'popupsendexport(' + id + ')', typnode);
    else
        return '';
}

function liencheckseo(id, typnode, codeintitule, icone) {
    if ((nbcoupe < 1) && (nbcopie < 1) && (nbalias < 1))
        return sepbutton() + menulineadd(icone, getIntitule(codeintitule), 'popupCheckSeo(' + id + ')', typnode);
    else
        return '';        
}

function lieneditseo(id, typnode, codeintitule, icone) {
    if ((nbcoupe < 1) && (nbcopie < 1) && (nbalias < 1))
        return menulineadd(icone, getIntitule(codeintitule), 'popupEditSeo(' + id + ')', typnode);
    else
        return '';        
}

/*****************************************************************************************************************/ 

function str(text)
{ 
    var txt = '';
    sw = 1;
    cnt = 0;
    if ((text != '') && (text))
    {
        offsetx=(-40);
        width=180;
        txt = "<table oncontextmenu=\"cClick();return (false)\" cellspacing=0 cellpadding=0 bgcolor=#ffffff style=\"border: 1px solid #aca899;\"><tr ><td><table cellspacing=0 cellpadding=0  oncontextmenu=\"str();\">" + text + " </table></td></tr></table>";
    }   
    layerWrite(txt);
    disp();
    snow = 0;
}

function lib_a(libelle)
{
    if (alignbasetext=="contextmenu") return libelle;
    else return '';
}   

function MenuOver(objet)
{
    objet.getElementsByTagName("td")[0].className="contextMenuOver0";
    objet.getElementsByTagName("td")[1].className="contextMenuOver1";
}

function MenuOut(objet)
{
    objet.getElementsByTagName("td")[0].className="contextMenuOut0";
    objet.getElementsByTagName("td")[1].className="contextMenuOut1";
}

function menulineadd(icon,lib,action,typnode) 
{
    lib=lib.replace("{typnodename}", srcName[typnode]); 
    return '<tr OnClick="' + action + '" class="contextMenuTR" onMouseOver="MenuOver(this)" onMouseOut="MenuOut(this)"><td class="contextMenuOut0"><IMG border="0" src="' + icon + '" align="center"></td class="contextMenuOut1"><td>&nbsp;' + lib_a(lib) + '</td></tr>';
}

function headerlineadd(icon,lib,typnode) 
{
    lib=lib.replace("{typnodename}", srcName[typnode]);
    return '<tr class="contextMenuOver0"><td colspan="2" class="contextMenuOver0"><center><TABLE><TR><TD><IMG border="0" src="' + icon + '" align="center"></td><td>' + lib_a(lib) + '</td></tr></table><center</td></tr>';
}

function GoTo(url,target)
{
    var dbshlash="\/\/";
    if (url.indexOf(dbshlash)==0) url=url.substring(1);
    if (target && (target != 'mainFrame') && (target != 'mainFrame2'))
	{
        if(target == "")
            target = "_SELF";
        if(target.toUpperCase() == "_TOP")
            top.location = url;
        else if(target.toUpperCase() == "_SELF")
            document.location = url;
        else if(target.toUpperCase() == "_PARENT")
            document.parent.location = url;                        
        else if(target.toUpperCase() == "_POPUP") {
            var newW = window.open(url, "", "");
            newW.focus();
        }
        else
            window[target].location = url;	
	}
	else
	{
        if (target=="mainFrame" && parent && parent.frames["mainFrame"])
            parent.frames["mainFrame"].document.location.href=url;
        else if(parent && parent.frames["mainFrame2"])
            parent.frames["mainFrame2"].document.location.href=url;
        else if(parent)
            parent.document.location.href=url;
        else
            document.location.href=url;    
    }        
}

function clicksubfolder()
{
    if (treecoche==true)
    {
        // si auto --> automatique
        // si pas auto et manuel --> confirme avant ss clicks
        if (csfauto==true) return true;
        else
        {
            if (csfmanuel==true) return confirm(IntitulesTra["CHECK_APLLYALL"]);
            else return false;
        }
    }
    else return false;
}

function recherche(tableau, valeur)
{
    var chaine = "|" + tableau.join("|") + "|";
    if (chaine.indexOf("|"+valeur+"|") == -1) return false;
    else return true;
}

function writeencart(text)
{
    var div=  document.getElementById('encart');
    div.innerHTML='<table width="100%" height="100%"><tr><td valign="top" class="TabSheet"><hr>' + getIntitule('INITMSG_INTRO') + '<hr>' + text + '<input type="text" name="keywords" size="20" value="" class="InputCaptionTextField"><br><input type="radio" name="PublishORWorkCopy" value="P" CHECKED>' + getIntitule('INITMSG_VERSIONSTANDARD') + '<br>  <input type="radio" name="PublishORWorkCopy" value="W">' + getIntitule('INITMSG_VERSIONNOPUBLISHED') + '<br>&nbsp;<a href="javascript:if (document.aspnetForm.keywords.value.length>1 || document.aspnetForm.keywords.value.length==0) document.aspnetForm.submit();"><img src="'+ICONPATH+'n_a_search.gif" border="0" alt="' + getIntitule('INITMSG_SEARCH') + '"></a><input type="hidden" name="actionsearch" value="' + getIntitule('INITMSG_SEARCH') + '"><input type="hidden" name="link" value=""><input type="hidden" name="editchps" value=""></td></tr></table>';
    div.style.height='auto';
} 

function affpressepapier(nbc)
{
    var coupeall ='';
	if (nbc>0) coupeall= lienannulecoupeall(1,1,'CLIPBOARD_EMPTY', ICONPATH + 'n_a_coupe_annule.gif');
	writeencart('<table><tr><td colspan=2>' + getIntitule('CLIPBOARD_CONTENT') + '<font class="errormessages">' + nbc + '</font></td></tr>' + coupeall + '</table>');	
}

function affpressepapieralias(nbc)
{
    var coupeall=''; 
	if (nbc>0) coupeall=lienannuleallalias(1,4,'CLIPBOARD_EMPTYALIAS', ICONPATH + 'n_a_alias_annule.gif');
    writeencart('<table><tr><td colspan=2>' + getIntitule('CLIPBOARD_CONTENTALIAS') + '<font class="errormessages">' + nbc + '</font></td></tr>' + coupeall + '</table>'); 
}

function affpressepapiercopie(nbc)
{
    var copieall=''; 
	if (nbc>0) copieall=lienannulecopieall(1,1,'CLIPBOARD_EMPTY', ICONPATH + 'n_a_copier.gif');
	writeencart('<table><tr><td colspan=2>' + getIntitule('CLIPBOARD_CONTENT') + '<font class="errormessages">' + nbc + '</font></td></tr>' + copieall + '</table>');
}

function getIntitule(code) 
{
    if((typeof IntitulesTraParam != 'undefined') && IntitulesTraParam && IntitulesTraParam[code]) return IntitulesTraParam[code];
    else if(IntitulesTra && IntitulesTra[code]) return IntitulesTra[code];
    else return code;
}

/*****************************************************************************************************************/ 

function mcIns(key, value) 
{
    MatriceMenuContextuel[key] = value;     
}

//function m_fld(typn,id,id0,rule)
// Appels généré par la classe C# Isagri.Ingenierie.Maxisite.Bibli.Tree
function m_fld(idnode,typnode,typnodeparent,accesrule,inTrash,iddefault,isAdminIsagri)
{
    indexLine = -1;
    var s = '';
    
    var typfolder = '0';
    typnode = '' + typnode;
    var indexOf = typnode.indexOf('.');
    if(indexOf >= 0)
    {
        if(indexOf <= typnode.length-1) typfolder = typnode.substr(indexOf+1);;
        typnode = typnode.substr(0, indexOf);
    }
    
    var typfolderparent = '0';
    typnodeparent = '' + typnodeparent;
    indexOf = typnodeparent.indexOf('.');
    if(indexOf >= 0)
    {
        if(indexOf <= typnodeparent.length-1) typfolderparent = typnodeparent.substr(indexOf+1);;
        typnodeparent = typnodeparent.substr(0, indexOf);
    }
             
    var isAlias = ((typnode != '1') && (iddefault != idnode) && (iddefault > 0));
    var actions=prepareAllActions(filtreAll(idnode,typnode,typfolder,typnodeparent,typfolderparent,accesrule,(inTrash == 1),isAlias,isAdminIsagri),idnode,typnode,typfolder,iddefault);
//alert(typfolder);
    if(actions != '') eval('s+=' + actions + ';');      
  
    str(s);
} 

function filtreAll(idnode,typnode,typfolder,typnodeparent,typfolderparent,accesrule,inTrash,isAlias,isAdminIsagri)
{
    var matrix = MC_Matrix;       
    matrix = filtreAllowActions(matrix, idnode);
    
    matrix = filtre(matrix, "listtypnode", typnode); 
    if(typnode == '1')  
        matrix = filtre(matrix, "listtypfolder", typfolder);     
        
    matrix = filtre(matrix, "listtypnodeparent", typnodeparent);  
    if(typnodeparent == '1')  
        matrix = filtre(matrix, "listtypfolderparent", typfolderparent);       
        
    matrix = filtre(matrix, "listdroits", accesrule);        
    matrix = filtreCondition(matrix, "condition", inTrash, "INTRASH");            
    matrix = filtreCondition(matrix, "condition", isAlias, "ISALIAS");            
    matrix = filtreCondition(matrix, "condition", isAdminIsagri, "ISADMINISAGRI");                  
    return matrix;
}

function filtreAllowActions(matrix,idnode)
{
    if(typeof MC_NodeRestitution['' + idnode] == 'undefined') return matrix;
    listActions = ',' + MC_NodeRestitution['' + idnode] + ',';

    var new_matrix=new Array();
    for(var i=0; i<matrix.length; i++)
    {
        var matrixvalue = ',' + matrix[i]["id"] + ',';
        if(
            (listActions.indexOf(matrixvalue) >= 0)
            || (
                (listActions.indexOf(',+,') >= 0)
                && (listActions.indexOf(',-' + matrixvalue + ',') < 0)
            )
        )
        {
            new_matrix[new_matrix.length] = matrix[i];
        }
    }
    return new_matrix;
}

function filtre(matrix,field,value)
{
    var new_matrix=new Array();
    for(var i=0; i<matrix.length; i++)
    {
        var matrixvalue = ',' + matrix[i][field] + ',';
        if(
            (matrixvalue.indexOf(',' + value + ',') >= 0)
            || (
                (matrixvalue.indexOf(',+,') >= 0)
                && (matrixvalue.indexOf(',-' + value + ',') < 0)
            )
        )
        {
            new_matrix[new_matrix.length] = matrix[i];
        }       
    }
    return new_matrix;
}

function filtreCondition(matrix,field,value,conditionName)
{
    var new_matrix=new Array();
    for(var i=0; i<matrix.length; i++)
    {
        if(matrix[i][field] == '')
        {
            new_matrix[new_matrix.length] = matrix[i];
            continue;
        }
        var matrixvalue = ',' + matrix[i][field] + ',';
        
        var indexOfPositive = matrixvalue.indexOf(',' + conditionName + ',');
        var indexOfNegative = matrixvalue.indexOf(',!' + conditionName + ',');
        if((indexOfPositive < 0) && (indexOfNegative < 0))
        {
            new_matrix[new_matrix.length] = matrix[i];
            continue;
        }     
           
        if(
            (value && (indexOfPositive >= 0))
            ||(!value && (indexOfNegative >= 0))
        )
        {
            new_matrix[new_matrix.length] = matrix[i];
        }       
    }
    return new_matrix;
}

function prepareAllActions(matrix,idnode,typnode,typfolder,iddefault)
{
    var actions = "";
    if(typfolder == '0') typfolder = '';
    for(var i=0; i<matrix.length; i++)   
        actions += (actions != '' ? ' + ' : '') + prepareAction(matrix[i]["actionJS"],idnode,typnode,typfolder,matrix[i]["icone"],matrix[i]["codeintitule"],iddefault);

    return actions;
}

function prepareAction(action,idnode,typnode,typfolder,icone,codeIntitule,iddefault)
{
    action = action.replace(new RegExp("{id}", "g"), idnode);
    action = action.replace(new RegExp("{typnode}", "g"), typnode);
    action = action.replace(new RegExp("{typfolder}", "g"), ((typeof typfolder != 'undefined') && (typfolder != '') ? '.' + typfolder : ''));
    action = action.replace(new RegExp("{codeintitule}", "g"), codeIntitule);
    action = action.replace(new RegExp("{icone}", "g"), (icone != '' ? ICONPATH + icone : ''));
    action = action.replace(new RegExp("{headericone}", "g"), srciconopen[typnode + (typfolder != '' ? '.' + typfolder : '')]);   
    action = action.replace(new RegExp("{iddefault}", "g"), iddefault);       
    return action;
}