/* Right Context Menu configuration:
   Menu is built from four array items: title -> link -> show if page or headpage -> show if namespace.
   Link is not created if it's 0, otherwise it's evaluated.
   Second array is displayed only in edit mode.

   Some usefull variables:
   url = node url;
   node.hns = headpage id;
   node.isdir = node is namespace;
   node.dokuid = the DW id (namespace parent in case of headpage);
   id = the DW id (headpage id in case of headpage);
   this.config.sepchar = dokuwiki separator;
*/

var indexmenu_contextmenu=new Array(
				    //Standard right menu
				    new Array(
					      '<b><em>Page action:</em></b>',0,1,0,
					      '<b><em>Namespace action:</em></b>',0,0,1,
					      'New page here','"javascript: indexmenu_reqpage(\'"+this.config.urlbase+"\',\'"+this.config.sepchar+"\',\'"+node.dokuid+"\');"',1,1,
					      'Headpage here','"javascript: indexmenu_reqpage(\'"+url+"\',\'"+this.config.sepchar+"\',\'"+node.dokuid+"\',\'"+node.name+"\');"',0,1,
					      'Edit','url+"&do=edit"',1,0,
					      'Search in this NS','"javascript: indexmenu_srchpage(\'"+this.config.urlbase+"\',\'"+this.config.sepchar+"\',\'"+node.isdir+"\',\'"+node.dokuid+"\');"',1,1,
					      'Toc preview','"javascript: indexmenu_ajax(\'req=toc&id="+id+"\',\'picker_"+this.obj+"\',\'r"+this.obj+"\');"+this.obj+".divdisplay(\'r\',0);"',1,0,
					      'Revisions','url+"&do=revisions"',1,0
					      //'Purge cache','url+"&purge=true"',1,0
					      //'Acls','url+"do=admin&page=acl"',1,1
					      ),

				    //Right menu in edit mode.
				    new Array(
					      '<b><em>Edit action:</em></b>',0,1,0,
					      'Insert as DWlink','"javascript: indexmenu_insertTags(\'"+id+"\',\'"+this.config.sepchar+"\');"+this.obj+".divdisplay(\'r\',0);"',1,0
					      )
				    );

/*Custom User Functions
Insert your custom functions here.
*/
function indexmenu_reqpage(b,s,id,n) {
    var r,u=b;
    if (n) {
	r = n;
    } else {
	r=prompt("Insert the pagename to create","");
	u += id;
    }
    if (r) window.location.href = u+encodeURI(s+r+"&do=edit");
}

function indexmenu_srchpage(u,s,isdir,nid) {
    var r = prompt("Insert the Phrase(s) you want to search on","");
    if (r)
        {
	    var fnid = nid;
	    if (isdir == "0") {
		fnid = fnid.substring(0,nid.lastIndexOf(s));
	    }
	    var re = new RegExp(s, 'g');
	    fnid = fnid.replace(re, ":");
            window.location.href = u+encodeURI(r+"@"+fnid+"&do=search");
	}
}
