
function formenus () {};
oMenu = null;

formenus.mDAL = function (pageid, menuname) {
	
	this.serializer = new XMLSerializer(); 	
	this.requestDoc = Sarissa.getDomDocument();
	this.displayDiv = document.getElementById('sidebar');
	this.xmlDoc = null;
	this.tr =  null;
	this.processor = new XSLTProcessor();
	this.pageid = pageid;
	this.menuname = menuname;
	
	//methods
	this.build = formenus._build;
	this.transform = formenus._transform;
	this.display = formenus._displayRequest;

}


formenus.start = function (pageid, menuname) {
	//create
	try {
		oMenu = new formenus.mDAL(pageid, menuname);
	} catch(e) {
		alert('erreur en creant objet oMenu ' + e);	
	}
		
	if (oMenu.pageid=="") {

		oMenu.displayDiv.style.visibility = "hidden";
		oMenu.displayDiv.style.display = "none";

	}else{

		//get stylesheet
		var xslhttp = new XMLHttpRequest();
		xslhttp.open("GET", "/_xml/sidebar.xsl", false);
		xslhttp.send('');
		oMenu.processor.importStylesheet(xslhttp.responseXML);
		
		//get xml
		var xmlhttp = new XMLHttpRequest();
		xmlhttp.open("GET", "/_xml/sidebar.xml", false);
		xmlhttp.send('');
		oMenu.xmlDoc = xmlhttp.responseXML;
			
		oMenu.transform("rightmenu-bk");
		oMenu.build();
	
		oMenu.transform("rightmenu-content");
		oMenu.build();
	
//		Effect.Appear('sidebar', { duration: 0.5 });
	//	oMenu.displayDiv.style.visibility = "visible";
	//	oMenu.displayDiv.style.display = "block";
	
		xmlhttp = null;
		xslhttp = null;
	}	
}

// this one just to make a complete tree of the whole xml
formenus.startfull = function () {
	//create
	try {
		oMenu = new formenus.mDAL("", "");
	} catch(e) {
		alert('erreur en creant objet oMenu ' + e);	
	}

	//get stylesheet
	var xslhttp = new XMLHttpRequest();
	xslhttp.open("GET", "/_xml/allitems.xsl", false);
	xslhttp.send('');
	oMenu.processor.importStylesheet(xslhttp.responseXML);
	
	//get xml
	var xmlhttp = new XMLHttpRequest();
	xmlhttp.open("GET", "/_xml/sidebar.xml", false);
	xmlhttp.send('');
	oMenu.xmlDoc = xmlhttp.responseXML;

	oMenu.tr = oMenu.processor.transformToDocument(oMenu.xmlDoc)
	oMenu.build();

	xmlhttp = null;
	xslhttp = null;

}


formenus._transform = function (divid) {

//	dprint('_transform:',true);
	this.processor.setParameter(null, "pageid", this.pageid);
	this.processor.setParameter(null, "sectionid", "1"); 
	this.processor.setParameter(null, "menuname", this.menuname); 
	this.processor.setParameter(null, "divid", divid); 	
	this.tr = this.processor.transformToDocument(this.xmlDoc)
}


formenus._build = function () {
// dprint(this.tr);
	if (this.tr.childNodes.length == 1) {
		//we are in moz
		this.displayDiv.innerHTML += this.serializer.serializeToString(this.tr);
	} 
	if (this.tr.childNodes.length == 2) {
		//we are in ie
		this.displayDiv.innerHTML += this.serializer.serializeToString(this.tr.firstChild.nextSibling);
	}

}


formenus.htmlEncode = function (s) {
        var str = new String(s);
        str = str.replace(/&/g, "&amp;");
        str = str.replace(/</g, "&lt;");
        str = str.replace(/>/g, "&gt;");
        str = str.replace(/"/g, "&quot;");
        return str;
}

formenus.deleteChildNode = function (n,nom) {
	if (n.selectSingleNode(nom) != null) {
		n.removeChild(n.selectSingleNode(nom));
	}
}


function dprint(txt) {
	alert(txt);
}