/* Copyright 2007 Giacomo Boccardo (email : gboccard@gmail.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
var uid = "";
var nBooks = "";
var curPath = "";
function innerContent(elementid, content){
if (document.getElementById && !document.all)
{
rng = document.createRange();
el = document.getElementById(elementid);
rng.setStartBefore(el);
htmlFrag = rng.createContextualFragment(content);
while (el.hasChildNodes())
{
el.removeChild(el.lastChild);
}
el.appendChild(htmlFrag);
}
}
/*
* XMLtoString: dato un documento XML, lo restituisce sottoforma di stringa
*
* INPUT:
* * xmlDoc: un documento XML
* OUTPUT:
* * Una stringa rappresentante il documento XML
* SIDE-EFFETS:
* * nulla
*/
function XMLtoString(xmlDoc)
{
// Se si usa IE...
if (xmlDoc.xml) {
return xmlDoc.xml;
// ...altrimenti se si usa FF...
} else {
return (new XMLSerializer()).serializeToString(xmlDoc);
}
}
function getElementsByClassName(elementName,className)
{
var allElements = document.getElementsByTagName(elementName);
var elemColl = new Array();
for (var i = 0; i< allElements.length; i++)
{
if (allElements[i].className == className)
elemColl[elemColl.length] = allElements[i];
}
return elemColl;
}
function convert2Xhtml(theHtml)
{
var html;
html = theHtml;
// Make xhtml compatible
html = html.replace(/<.*>?>/g,function(m,p,s){return m.replace(/\s(\w+=)([#\w,;]+)/g,function(m,p,s){return ' ' + p.toLowerCase() + '"' + s+ '"';});});
html = html.replace(/<(\/?\w+)([^>]*>)/g,function(m,p,s){return '<' + p.toLowerCase()+ s;});
html = html.replace(/<(meta|base|basefont|param|link|img|br|hr|area|input)([^>]*)>/g,function(m,p,s){return m.indexOf(' />') == -1 ? '<' + p + s + ' />' : m;});
// Add empty ALT if not present in the IMG tag
html = html.replace(/<(img)([^>]*)\/>/g,function(m,p,s){return m.indexOf('alt=') == -1 ? '<' + p + s + ' alt="" />' : m;});
return html;
}
/*
* getXMLhttp: restituisce un oggetto XMLhttpRequest per IE o per FF&Co.
*
* INPUT:
* * nulla
* OUTPUT:
* * un oggetto XMLhttpRequest per IE o per FF&Co, null in caso di mancato supporto
* SIDE-EFFECTS:
* * nulla
*/
function getXMLhttp()
{
// Se si usa FF&Co. ...
if (window.XMLHttpRequest)
{
return new XMLHttpRequest();
// ...altrimenti se si utilizza IE
} else if (window.ActiveXObject) {
// ...se e' stato specificato un oggetto ActiveX precedentemente...
if (_ms_XMLHttpRequest_ActiveX)
{
return new ActiveXObject(_ms_XMLHttpRequest_ActiveX);
} else {
// ...altrimenti si testano le varie versioni di XMLHTTP per utilizzare la piu' recente...
var versions = ["Msxml2.XMLHTTP.7.0", "Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
for (var i = 0; i < versions.length ; i++)
{
try {
// ...si prova a creare l'oggetto ActiveX...
return new ActiveXObject(versions[i]);
// ...e, se va tutto bene, ci si salva la versione per velocizzare la creazione di richieste successive...
/* if ( self.AJAX )
{
_ms_XMLHttpRequest_ActiveX = versions[i];
break;
}ml2.XMLHT
*/
}
catch (objException)
{
// ...atrimenti si ricomincia il ciclo e si prova una versione meno recente...
};
};
}
if ( _ms_XMLHttpRequest_ActiveX == "" ) return null;
}
}
/*
* AJAXRequest: crea una richiesta AJAX.
*
* INPUT:
* * method => metodo con cui effetturare la richiesta: GET o POST
* * url => URL cui fare la richiesta (con eventuali parametri per la GET)
* * data => eventuali dati da inviare se la richiesta è POST
* * process => funzione da invocare alla ricezione dei dati (di default executeReturn)
* * async => modalita' di invio: true o false per asincrona e sincrona (di default asincrona)
* * dosend => 0 non invia i dati, 1 si' (di default invia)
* OUTPUT:
* * un oggetto XMLhttpRequest
* SIDE-EFFECTS:
* * nulla
*/
function AJAXRequest( method, url, data, process, async, dosend )
{
var self = this;
// Si ottiene un oggetto XMLhttpRequest
self.AJAX = getXMLhttp();
// Se non esiste una funzione di callback, ne viene specificata una di default
// che si limita ad eseguire il codice ottenuto dal server
if ( typeof process == 'undefined' ) process = executeReturn;
// Se viene specificata una funzione di callback da eseguire sui valori di ritorno della richiesta AJAX...
if ( process != null )
{
self.process = process;
// ...si crea una funzione anonima che viene eseguita alla ricezione di una risposta dal server...
self.AJAX.onreadystatechange = function( )
{
//logger("AJAXRequest Handler: Stato = " + self.AJAX.readyState);
if ( self.AJAX.readyState == 4 && self.AJAX.status == 200 )
{
//logger('AJAXRequest completata: ' + self.AJAX.readyState + "/" + self.AJAX.status + "/" + self.AJAX.statusText);
if ( self.AJAX.responseText )
{
//logger(self.AJAX.responseText);
//logger("-----------------------------------------------------------");
}
}
// ...e viene invocata la funzione per gestire i dati ricevuti
self.process(self.AJAX);
}
}
// Se non viene specificato un metodo per l'invio della richiesta, si assume POST
if ( !method ) method = "POST";
method = method.toUpperCase();
// Se non viene specificata la modalita' di invio, si assume ASINCRONA
if (typeof async == 'undefined' || async == null) async = true;
//logger("----------------------------------------------------------------------");
//logger("AJAX Request: " + ((async) ? "Async" : "Sync") + " " + method + ": URL: " + url + ", Data: " + data);
// Si specificano i parametri di connessione
self.AJAX.open(method, url, async);
if (method == "POST")
{
self.AJAX.setRequestHeader("Connection", "close");
self.AJAX.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
self.AJAX.setRequestHeader("Method", "POST " + url + "HTTP/1.1");
}
// Fallisce solo se dosend e' false
// Da utilizzare per l'invio di header particolari
if ( dosend || typeof dosend == 'undefined' )
{
if ( !data | method == "GET") data="";
self.AJAX.send(data);
}
return self.AJAX;
}
function evalRet(httpReq)
{
//alert("HELLO ---> "+ httpReq.readyState +";"+ httpReq.status);
if ( httpReq.readyState == 4 && httpReq.status == 200 ) {
httpReqResult = httpReq.responseText;
// Si evita document.write alla fine
httpReqResult = httpReqResult.substring(0, httpReqResult.indexOf("document"));
// Nella variabile b_txt c'è tutta la stringa con i risultati
eval(httpReqResult);
b_txt = b_txt.replace(/&/g,"&");
// Si corregge il tag in
b_txt = convert2Xhtml(b_txt);
b_txt = "