/*
 * mpPrisma.js: 
 *		framework js con oggetti e funzioni per accesso e trasformazione di dati prisma via Multiportal
 * 		la variabile _ASPXService identifica, in multiportal, la pagina di servizio che soddisfa le richieste
 * Utilities per caricare e trasformare dati da prisma 
 *
 *	
 *	changelog
 *		ver: 1.0.8
 *		-mpCombo : le combo figlie in cascata inizialmente sono disabilitate
 *		ver: 1.0.7
 *		-mpCombo : il parametro control (ex.controlSelector) accetta sia una stringa come selettore per id (es. #cmb1) sia il controllo combo 
 *		-ShowData: mostra i dati in una nuova finestra del browser
 *		-DataJSON:	carica i dati (se necessario) e li ritorna in formato JSON
 *		ver: 1.0.6
 *		-PrismaDoc: gestisce filtri con operatore BETWEEN (il valore To va come ultimo argomento)
 *			es. P.addFilter("rassegna", "DATA_PUBBLICAZIONE", "BETWEEN", $("#PubFrom").val(), "", $("#PubTo").val())
 *		ver: 1.0.5
 *		-mpCombo: ora crossbrowser (girava solo su ie)
 *		ver: 1.0.4
 *		-Nuovo oggetto mpCombo: genera combo anche in cascata
 *		ver: 1.0.3
 *		-Modifiche alle chiamate ajax dove ogni metodo che le effettua può decidere (o ricevere da argomenti) 
 *		 se la chiamata sarà sincrona o asincrona (migliora la comparsa delle dialog di info caricamento)
 *		ver: 1.0.2
 *		-fix caricamento configurazioni su Firefox
 *		-clearFilter(): ritorna un nuovo PrismaDoc con pulizia filtri su tutti i documenti configurati
 *						se  viene passato un docname agisce solo su quello (es. pd.clearFilter("utenti"))
 *		-ConfDeleteDocumentByName(docname): elimina dalla configurazione il documento richiesto
 *
 *		ver: 1.0.1
 *		----------
 *		-esteso l'oggetto PrismaDoc che oltre a gestire la configurazione del documento
 * 		ne carica i dati e li trasforma
 *
 *
 *
 * References:
 *	-jQuery
 *	-mpUtils.js
 *
*/

var mpPrismaSettings = {_ASPXService: "/script.aspx"}

/*
 * OpenPrismaDoc:
 * 	xmlConf: oggetto XmlConfig o stringa xml
 *
 *
*/ 
function LoadPrismaDoc(_xmlConf, callback_func, callback_args){
	
	var xmlConf = _xmlConf.replace(/</g, "&lt;");
	
	$.ajax({
	   type: "POST",
	   async: true,
	   url: mpPrismaSettings._ASPXService,
	   data: { PRISMADOC: 1, xmlconfig: xmlConf, "param|ASPXService": mpPrismaSettings._ASPXService},
	   success: function(result){
					callback_args.push(result);
					eval(callback_func+"(callback_args)");
				}
	 });
}


/*
 * TransformPrismaDoc:
 * 	_conf: oggetto JSON o stringa xml
 *
 * 	xslt_url: se impostato trasforma i dati e va in sostituzione dell'eventuale xslt definito nella configurazione
 *
*/
function ShowPrismaDoc(_conf, _target, mode, xslt_url){
	
	var xmlConf;
	
	var target = _target;
	if (typeof(target)=="string") target = $("#"+target);
	
	if (mode=="add") target.append("<div align=\"center\"><img src=\""+jq_custom_path+"/images/loading.gif\"/><div>");
	else target.html("<div align=\"center\"><img src=\""+jq_custom_path+"/images/loading.gif\"/><div>");

	//TODO: aggiunge/sostituisce l'url del template xslt nella configurazione (config/parameters/xslt_url)
	if (xslt_url) {
		if (typeof(_conf)=="object") _conf.config.parameters.xslt_url= xslt_url;
		else{
			var xdoc = mpXml.LoadXml(_conf);
			var url = xdoc.selectSingleNode("config/parameters/xslt_url");
			if (url!=null) url.text = xslt_url;
			else{
				var newnode = xdoc.createNode(1, "xslt_url", ""); 
				newnode.text = xslt_url;
				//alert(xdoc.xml);
				//alert(newnode.text);
				xdoc.selectSingleNode("config/parameters").appendChild(newnode);
				
			}
			//alert(xdoc.xml);
			_conf = xdoc.xml;
		}
	
	}
	
	try{
	
	if (typeof(_conf)=="object") xmlConf = json2xml(_conf, "");
	else xmlConf = _conf;
	
	var callback_args = [];
	callback_args.push(_target, mode);
	LoadPrismaDoc(xmlConf, "ShowPrismaDoc_CallBack", callback_args);
	}
	catch(e){
		if (mode=="add") target.append("Errore: "+e.message);
		else target.html("Errore: "+e.message);
	
	}
	
}

function ShowPrismaDoc_CallBack(){

	//alert("args: " + arguments[0].join("-"))

	var target = arguments[0][0];
	if (typeof(target)=="string") target = $("#"+target);
	var html = arguments[0][2];
	if (arguments[0][1]=="add") target.append(html);
	else target.html(html);
}

/*
 * Classe PrismaDoc
 *		name: nome assegnato alla classe
 *		conf: si aspetta un oggetto JSON, se riceve una stringa tenta un eval che da stringa rappresentante 
 *				un oggetto JSON lo crea
 * 
*/
function PrismaDoc(name, JSONconf){
	this.name = name;
	//Internamente mantengo la configurazione in formato JSON
	if (typeof(JSONconf)=="string" && JSONconf!="") {alert("init:"+JSONconf); eval("this.conf="+JSONconf);}
	else this.conf = JSONconf; 
	
	//this.ob = {
	//	name: name,
	//	f: function(){return name;}
	//}
	
	this.status;
	this.ConfLoaded=function(){if (typeof(this.conf)=="object"&&this.conf.config) return true; else return false};
	this.debug = true;
	this.log = [];
	
	this.LogAdd = function(str){
		if (this.debug)
			this.log.push(str);
			//this.log = str + "\r\n" + this.log;
	}
	
	this.Clone = function(){
		return new PrismaDoc(this.name, this.ConfClone())
	}
	
	//Carica la configurazione da un documento xml su file
	this.ConfLoad = function(url){
		try{
			var doc = mpXml.LoadXmlByUrl(url);
			if (doc.xml=="") return false; //file xml NON caricato
			
			this.conf = xml2json(doc, "");
			eval("this.conf="+this.conf);
			
			var normOK = this.conf.config.document instanceof Array;
			if (!normOK){
				//normalizzo l'oggetto document che deve essere un array
				var d = this.conf.config.document;
				
				this.conf.config.document = [];
				this.conf.config.document.push(d);
			}
			
		}
		catch(e){
			alert("PrismaDoc::ConfLoad:" + e.message);
			return false;
		}
		return true;
	}
	
	//da testare: Carica la configurazione da un documento xml in formato stringa
	this.ConfLoadXML = function(str){
		try{
			var doc = mpXml.LoadXml(str);
			this.conf = xml2json(doc.xml, "");
		}
		catch(e){
			alert("PrismaDoc::ConfLoadXML:" + e.message);
			return false;
		}
		return true;
	}
	
	this.ConfToXML = function(){
		var xml;
		try {
			xml = json2xml(this.conf, "");
		}
		catch(e){
		   alert("PrismaDoc::ConfToXML:" + e.message);
		   return;
	   }
	   return xml;
	}
	
	/*
	 * Ritorna un nuovo oggetto clone della configurazione
	 *
	 *
	 */
	this.ConfClone = function(){
		if (!this.ConfLoaded()) return undefined;
		var xml = json2xml(this.conf, "");
		xml = mpXml.LoadXml( xml);
		var jsonString = xml2json(   xml   , "");
		eval("var _temp = "+jsonString);
		if (_temp.config.document.length==undefined)
		{
			var doc = _temp.config.document;
			_temp.config.document = [];
			_temp.config.document.push(doc);
		}
		return _temp;
	}

	/*
	 * Ritorna il o i documenti richiesti. se il parametro boleano cloned è true ritorna un clone e NON il riferimento,
	 * ma un nuovo oggetto
	 *
	 *
	 */
	this.ConfGetDocumentByName = function(docname, cloned){
		//alert("ConfGetDocumentByName  - " + docname);

		var numdocuments = this.conf.config.document.length;
		if (docname=="*"){
			if (cloned)
				this.ConfClone()
			else
				return this.conf.config.document;
		}
		for (i=0; i<numdocuments; i++)
		{
			var d = this.conf.config.document[i];
			if (d.name==docname) 
				if (cloned){
					var xml = json2xml(d, "");
					xml = mpXml.LoadXml( xml);
					var jsonString = xml2json(   xml   , "");
					eval("var _temp = "+jsonString);
					return _temp;
				}
				else
					return d;
		}
		return null;
	}

	/* 
	 * Elimina dalla configurazione un singolo documento richiesto
	 * Arguments: docname=stringa corrispondente al nodo document/name
	 * Return: ritorna true se l'operazione è andata a buon fine: trovato ed eliminato il doc.
	 */
	this.ConfDeleteDocumentByName = function(docname){
		var numdocuments = this.conf.config.document.length;
		var j = -1;
		for (i=0; i<numdocuments; i++)
		{
			var d = this.conf.config.document[i];
			
			if (d.name==docname) {
				j=i;
			}
		}
		if (j>-1) {
			this.conf.config.document.splice(j, 1) 
			return true;
		}	
		return false;
	}
	
	/* DA TESTARE
	 * addDoc	: riceve un documento da aggiugere alla configurazione attuale
	 * Arguments: documento in formato JSON
	 * Return	: nuovo oggetto PrismaDoc
	*/
	this.addDoc = function(doc){
		if (!doc) return;
		var pd = this.Clone(); //verificare se clona anche i parameters
		pd.conf.config.document.push(doc);
		return pd;
	}
	
	
	/* filterDoc: dato un singolo docname (document/name) restitusce un nuovo PrismaDoc
	 * Arguments: docname=stringa corrispondente al nodo document/name
	 * Return: nuovo oggetto PrismaDoc
	 */
	this.filterDoc = function(docname){
		if (typeof(this.conf)!="object") return;
		var newdoc = {config: {}};
		
		newdoc.config.document = [];
		
		var doc = this.ConfGetDocumentByName(docname);
		
		if (doc) newdoc.config.document.push(doc);
		
		newdoc.config.parameters = this.conf.config.parameters;
		
		return new PrismaDoc(name, newdoc);
	}
	
	/* addFilter: Ritorna un nuovo PrismaDoc con l'aggiunta del filtro passato al singolo documento o tutti i documenti configurati
	 * Arguments
	 * 		docname (arguments[0]): nome friendly del documento (nodo name del nodo document di configurazione) sul quale applicare il filtro
	 *   		docname = * aggiunge lo stesso filtro su tutti i documenti presenti
	 *		filtro (arguments[1..3]):
	 *			idfiltro: se esiste un solo argomento dopo il docname è richiesto un filterid (che sovrascrive l'eventuale esistente)
	 *			filtro esplicito: se esistono più di due argomenti è richiesto un filtro escplito così strutturato
	 *				field		: campo sul quale applicare il filtro
	 *				operatore	: EQU, LT, GT, XLIKE, 
	 *				valore		: valore 
	 *				objectid	: object id di "destinazione". se assente il filtro si applica al documento in essere. altrimenti
	 *							il filtro viene fatto sul documento specificato con effetto in cascata sul documento corrente grazie alle relazioni
	 *				Esempio:
	 *					.addFilter('personale', 'USERID', 'EQU', IDPersona)
	 *					.addFilter('dipartimento', 'USERID', 'EQU', IDPersona)
	 * Return:  nuovo oggetto PrismaDoc
	 */
	this.addFilter = function(){
		var docname = arguments[0];
		
		//alert("addFilter: pd="+this.conf);
		var pd = new PrismaDoc(name, this.ConfClone());

		var doc = pd.ConfGetDocumentByName(docname);
		this.LogAdd("addFilter: docname="+docname);
		if (doc!=null) {
			if (doc instanceof Array){

				var numdocuments = doc.length;
				for (i=0; i<numdocuments; i++)
				{
					var d = doc[i];
					this.LogAdd("doc '"+d.name+"': old filters="+d.filters);
					_addFilter(d, arguments, pd);
				}				
			}
			else{		
				this.LogAdd("doc '"+doc.name+"': old filters="+doc.filters);
				_addFilter(doc, arguments, pd);
			}

		}

		/*
		 * Riceve una stringa che compone il filtro da aggiungere al 
		 *
		 *
		*/
		function addFilterByString(doc, sfilter, pd){
			if (doc.filters!=null) doc.filters +=";";
				else doc.filters = "";
			doc.filters += sfilter;
			pd.LogAdd("new filters="+doc.filters);
		}
		
		function _addFilter(doc, args, pd){
			var filterid, field, op, value;
			if (args.length==2) {
				filterid = args[1];
				doc.filterid = filterid;
			}
			else{
				field = args[1];
				op = args[2];
				value = args[3];
				objectid = args[4];
				valueto = args[5]==undefined? '': args[5];
				if (doc.filters!=null) doc.filters +=";";
				else doc.filters = "";
				doc.filters += field+"|"+op+"|"+value+"|"+valueto+"|1|"+(objectid==undefined || objectid==""?doc.objectid: objectid)+"|0";
				pd.LogAdd("new filters="+doc.filters);
			}
		}
		return pd;
	}
	
	/* clearFilter: Ritorna un nuovo PrismaDoc ripulito di tutti i filtri al singolo documento o a tutti i documenti configurati
	 * Arguments
	 * 		arguments[0]-->docname : nome friendly del documento (document/name) sul quale/i pulitre i filtri
	 *   		docname = * (default del l'argomento non è presente): elimina i filtri da tutti i documenti presenti.
	 * Return: nuovo oggetto PrismaDoc
	 */
	this.clearFilter = function(){
		var docname = arguments[0];
		if (docname==undefined) docname = "*";
		
		var pd = new PrismaDoc(name, this.ConfClone());
		var doc = pd.ConfGetDocumentByName(docname);
		if (doc!=null) {
			if (doc instanceof Array){

				var numdocuments = doc.length;
				for (i=0; i<numdocuments; i++)
				{
					var d = doc[i];
					d.filters = "";
					d.filterid = "";
				}				
			}
			else{			
				doc.filters = "";
				doc.filterid = "";
				}
		}
		return pd;
	}

	
	/*contiene i dati caricati dal metodo DataLoad*/
	this._data;

	/* DataLoad: carica i dati richiesti dalla configurazione tramita chiamata asincrona al servizio asp 
	 * Return: true/false
	 */
	this.DataLoad = function(){
		if (!this.ConfLoaded()) {
			this.LogAdd("DataLoad::Configuration not present");
			return false;
			
		}
		//var xmlConf = json2xml(this.conf).replace(/</g, "&lt;");
		var xmlConf = XmlEncode(json2xml(this.conf));
		
		var _this = this;
		/*$.post(mpPrismaSettings._ASPXService, { PRISMADOC_LOADDATA: 1, xmlconfig: xmlConf}, function(d){_this._SaveData(d)});*/
		$.ajax({
			   type: "POST",
			   async: false,
			   url: mpPrismaSettings._ASPXService,
			   data: { PRISMADOC_LOADDATA: 1, xmlconfig: xmlConf},
			   success: function(d){_this._SaveData(d)}
	 	});
		
		return true;
	}
	
	this._SaveData = function(data){
		this._data = data;
		this.LogAdd("Data loaded");
	}
	
	
	this.DataJSON = function(){
		if (!this.DataLoaded()) this.DataLoad();
		
		try{
		
			//Per ogni documento rimpiazza l'objectid che rappresenta ogni nodo xml con "_record"
			//probabilmente con ultime dll diventa inutile perchè invece del objid ora mi trovo Table
			var xmlData = this._data;
			var numdocuments = this.conf.config.document.length;
			for (var i=0; i<numdocuments; i++)
			{
				var d = this.conf.config.document[i];
				xmlData = xmlData.replace(eval("/"+d.objectid+"/g"), "_record")
			}
			//xmlData = xmlData.replace(/ xml:space="preserve"/gi, "");
			
			var xmlDoc = mpXml.LoadXml(xmlData);
			return eval("this._DataJSON = " + xml2json(xmlDoc, ''));
		}
		catch(e){
			return {nodata: true, error: e.message}
		}	
		
	}
	this.DataXmlDoc = function(){
		if (!this.DataLoaded()) this.DataLoad();

		try{

			//Per ogni documento rimpiazza l'objectid che rappresenta ogni nodo xml con "_record"
			var xmlData = this._data;
			var numdocuments = this.conf.config.document.length;
			for (var i=0; i<numdocuments; i++)
			{
				var d = this.conf.config.document[i];
				xmlData = xmlData.replace(eval("/"+d.objectid+"/g"), "_record")
			}

			var xmlDoc = mpXml.LoadXml(xmlData);
			return xmlDoc;
		}
		catch(e){
			return {nodata: true, error: e.message}
		}	
			
	}
	
	
	/*
	 * DataLoaded: dice se ci sono dati caricati in memoria
	 * Return: true/false
	 */
	this.DataLoaded = function(){
		if (this._data!=undefined)	return true;
		else return false;
	}
	
	/*Trasformazione dei dati (già caricati) con il foglio di stile passato
	 * Paramatri:
	 * 		xslt - path del template
	 * 		options - parametri in formato JSON
	 *			asyncTarget: id dell'oggetto nel quale inserire il risultato
	 *			callback:	funzione di callback eseguita al termine della chiamata ajax
	 * Esempio:
	 *		QA = new PrismaDoc("QA");
	 *		QA.ConfLoad("common/custom/CCIAAVE/QuickAccess_Config.xml");
	 *		QA.DataLoad()
	 *		QA.TransformData("common/custom/cciaave/QuickAccess.xslt", {asyncTarget: "MainContent", callback: function (a){alert(a)}})
	 *
	*/ 
	this.TransformData = function(xslt, options){
		if (this.DataLoaded()){
			
			var _result=null;
			
			var _async = (options!=undefined&&(options.asyncTarget!=undefined||options.callback!=undefined)? true: false);
			var _params = "";
			for (i in options.params) {
				_params += "\"param|"+ i + "\" : \""+options.params[i] + "\", ";
			
			}
			
			var sdata = "{ PRISMADOC_TRANSFORM: 1, " + _params + "\"param|xmlconfig\": XmlEncode(this.ConfToXML()), xml: XmlEncode(this._data), xslt_url: xslt}";
			eval("var _data = "+ sdata);
			
			$.ajax({
			   type: "POST",
			   async: _async,
			   url: mpPrismaSettings._ASPXService,
			   data: _data,
			   success: function(result){
			   			_result = result;
							if (options!=undefined){
								if (options.asyncTarget!=undefined) $("#"+options.asyncTarget).html(result);
								if (options.callback!=undefined) options.callback(result);
							}
						}
	 		});
	 		
			this.LogAdd("TransformData('"+xslt+"')");
			return _result;
		}
	}
	
	//carica (sul server) e trasforma (xslt passato) i dati definiti dalla configurazione
		/*
		 * xslt_url	: url del template xslt da utilizzare
		 * callback	: funzione richiamata al termine dell'esecuzione
		 * params	: parametri che verranno passati al template xslt.
		 *			 	Es. per generare differenti trasformazioni sugli stessi dati
	 */
	this.LoadAndTransform = function(xslt_url, callback, params, _async){
		
		var _conf = this.ConfClone();
		
		if (xslt_url) _conf.config.parameters.xslt_url= xslt_url;
				
		
		var xmlConf = XmlEncode(json2xml(_conf, ""));
		
		var request = '{ PRISMADOC: 1, xmlconfig: xmlConf, "param|ASPXService": mpPrismaSettings._ASPXService';
		if (params!=undefined){
			for (var m in params)
				request+= ", \"param|"+m+"\": \""+params[m]+"\""
		}
		request += "}";
		request = eval("("+request+")");
		
		/*$.post(mpPrismaSettings._ASPXService, request, 
			function(result){
				callback(result);
		});
		*/
		
		if (_async==undefined) _async = true;
		
		$.ajax({
		   type: "POST",
		   async: _async,
		   url: mpPrismaSettings._ASPXService,
		   data: request,
		   success: function(result) {
		        if (typeof(callback)=="function") callback(result);
		   }
		 });

		
	}

	this.ShowData = function() {
	    if (!this.DataLoaded()) this.DataLoad();
	    var w = window.open();
	    w.document.write(this._data);
	    w.document.close();
	    //var w=window.open("data:application/xhtml+xml,"+this._data); // in Mozilla apre come un xml
	}
	
	XmlEncode = function(xml){
		return xml.replace(/</g, "&lt;").replace(/>/g, "&gt;");
	}
	
	
}

/*
 * Oggetto mpCombo
 *	control		: selettore del controllo html nel formato jQuery
 * 						es #tipo controllo --> controllo con id=tipo
 *  prismaDoc	: oggetto PrismaDoc che funge da base dati
 *	isChild		: booleano, se true indica che la combo è figlia di un'altra e non viene popolata
 *
 *
 *
 *
 */
function mpCombo(control, prismaDoc, isChild, copySelect){
	if (typeof(control)=="object") 
		this.ctrl = $(control);
	else 
		this.ctrl = $(control+":first");
	
	if (copySelect != null)
	{
		if (typeof(copySelect)=="object") 
			copySelect = $(copySelect);
		else 
			copySelect = $(copySelect+":first");
			
		this.ctrl.html(copySelect.html());
	}
	
	this.pd = prismaDoc;
	this.childs = [];
	/* aggiunge alla collezione di Combo figlie che verranno popolate al variare di questa
	 * alla configurazione presente nella figlia
	*/
	this.addChild = function(child){
		$(child.ctrl).attr("disabled", "disabled");
		this.childs.push(child)
	}
	
	if (this.pd != null) this.predefined_filter = (this.pd.conf.config.document[0].filters!=undefined? this.pd.conf.config.document[0].filters: "");
	
	this.populate = function(currentValue){
	
		//this.ctrl.val(currentValue);
		if (this.pd != null)
		{
			if (!this.pd.DataLoaded()) this.pd.DataLoad();
			var doc = mpXml.LoadXml(this.pd._data);

			if (this.pd.conf.config.document[0].combofields != null)
			{
				var codField = this.pd.conf.config.document[0].combofields.cod;
				var desField = this.pd.conf.config.document[0].combofields.des;
			}
			else
			{
				// se non sono definiti i nomi dei campi, prendo il primo campo come value e il secondo come descrizione
				// il selettore nth-child di jQuery è 1-based
				//var codField = 'Table>*:nth-child(1)';
				var codField = ':first';
				var desField = ':eq(1)';
			}
			var tipi = $(doc);
			var html="<option value=\"\"></option>";
			$(tipi).find("Table").each(function(){
				var _selected = "";
				if ($(this).find(codField).text()==currentValue) _selected="selected='selected'"
				html += "<option " + _selected + "value=\'" + $(this).find(codField).text() + "\'>" + $(this).find(desField).text()  + "</option>";


			});
			this.ctrl.empty()
			this.ctrl.append(html);
		}
		try { $(this.ctrl).trigger('change'); }
		catch (ex) { this.populateChilds(); };
		//this.populateChilds();

		if (typeof _MBOAutocompleteComboCheckRefresh == 'function') _MBOAutocompleteComboCheckRefresh(this.ctrl);
		//this.ctrl.parent().width(this.ctrl.width());
	}
	this.val = function(_value) {
	    if (_value == undefined) return this.ctrl.val()
		
		if (_value==null) _value = "";
		this.ctrl.val(_value);
		this.populateChilds();
		if (typeof _MBOAutocompleteComboCheckRefresh == 'function') _MBOAutocompleteComboCheckRefresh(this.ctrl);
	}
	
	//Popola le combo figlie filtrate con il valore di quella corrente in funzione della configurazione
	this.populateChilds = function(){
		var parentValue = this.ctrl.val();
		for (var i=0; i<this.childs.length; i++){
			var cmb = this.childs[i];
			$(cmb.ctrl).attr("disabled", "disabled");
			cmb.pd = cmb.pd.clearFilter();
			cmb.pd.conf.config.document[0].filters = cmb.predefined_filter;
			
			//ora devo impostare un filtro sul campo preposto su questa combo (la figlia)
			//con il valore della combo padre (parentValue)
			var filterOnField = cmb.pd.conf.config.document[0].combofields.parent;

			cmb.pd = cmb.pd.addFilter("*", filterOnField, "EQU", parentValue);
			cmb.populate();
			if (parentValue!="") $(cmb.ctrl).removeAttr("disabled")
		}
	}

	if (isChild==undefined || !isChild) this.populate();
	var _this = this;
	//if (this.childs.length>0) 
		this.ctrl.bind("change", function(){_this.populateChilds()});

}


/*	MODALITA CLIENT
 *	
 *	allo startup il framework mpJs carica i dati delle configurazioni di base frequentemente utilizzate
 *  i menu vengono generati a runtime
 *
 *
 *
 *
 *
 
 ESEMPIO MENU "QUICK ACCESS"
 //startup: caricamento sul client dell prismadoc del quick access (solo i dati)
 QA = new PrismaDoc("QA");
 QA.ConfLoad("common/custom/CCIAAVE/QuickAccess_Config.xml");

 //caricamento dei dati di tutti i documenti configurati
 QA.DataLoad()
 //esempio di trasformazione dei dati con la generazione delle voci di menu del Quick Access
 $("#m10050280").html(QA.TransformData("common/custom/cciaave/QuickAccess.xslt"))
 
 //FILTRO SOLO I DOC DA APPROVARE E LI SPARO IN NUOVA UNA FINESTRA DEL BROSWER
 var Q = QA.filterDoc('approvare');
 Q.DataLoad()
 var w = window.open()
 w.document.write(Q._data)


 Esempio configurazione JSON
 il nodo parameters è necessario come lo è use_session_prismauser valorizzato con "true" o "false"
 (il lato server dovrebbe prevedere l'assenza del valore e del nodo)
 var jsConf = {config: 
 			{
 			document: [
 				{objectid: "9dbd1f4858d14709b79f9e18581aa968",
 				 name: 		"documenti",
 				 des:		"Documenti",
 				 type:		"NAVIGATOR",
 				 treename:	"9dbd1f4858d14709b79f9e18581aa968",
 				 catid:		"",
 				 filters:	"",
 				 filterid:	"",
 				 filtersfromrequest: ""
 				 }
 				],
 			
 			parameters: {
 				xslt_url: "",
 				use_session_prismauser: "true"
 			}
 			}
	}
*/
