function Ajax(url, testo, type){

    this.url = url;
    this.type = type;
	
    this.reqTitoliImg = function(){
    
        if (xmlHttp3.readyState == 4) {
            testo[url] = eval('(' + xmlHttp3.responseText + ')');
            load_images(testo[url]);
        }
    }
    
    this.reqBar = function(){
    
        if (xmlHttp0.readyState == 4) {
        
            var titoli = eval('(' + xmlHttp0.responseText + ')');
            var panel = "<ul id=\"page_menu\">";
            for (i = 0; i < titoli.length; i++) {
                if (i == 0) 
                    panel = panel + "<li id=\"current\"\"><a href=\"javascript:cambia(" + i + ")\">" + titoli[i] + "</a></li>";
                else 
                    panel = panel + "<li id=\"page" + i + "\"> <a href=\"javascript:cambia(" + i + ")\">" + titoli[i] + "</a></li>";
                
            }
            panel = panel + "</ul>";
			testo[url] = panel;
            document.getElementById('nav_main').innerHTML = panel;
            
        }
    }
    
    this.reqTesto = function(){
    
        if (xmlHttp1.readyState == 4) {
        
            testo[url] = eval('(' + xmlHttp1.responseText + ')').join(" <br> ");
            document.getElementById('testo1').innerHTML = testo[url];
            
            
        }
    }
    
    this.reqTitoli = function(){
    
        if (xmlHttp2.readyState == 4) {
        
            var titoli = eval('(' + xmlHttp2.responseText + ')');
            
            var panel = "<ul id=\"submenu\">";
            var idx = 1;
            var allTitoli = new Array;
            for (i = 0; i < titoli.length; i++) {
            
                if (titoli[i] instanceof Object) {
                    var subtitle = "<li><a href=\"javascript:mmenu('submenu-" + idx + "')\">" + titoli[i][0] + "</a><ul class=\"submenu\" id='submenu-" + idx + "' style=\"display :none\">";
                    var sub = titoli[i][1];
                    for (j = 0; j < sub.length; j++) {
                        subtitle = subtitle + "<li><a href=\"javascript:cambia_sez(" + idx++ + ")\">" + sub[j] + "</a></li>";
                        allTitoli[idx - 2] = sub[j];
                    }
                    panel = panel + subtitle + "</ul></li>";
                }
                else {
                    panel = panel + "<li><a  href=\"javascript:cambia_sez(" + idx++ + ")\">" + titoli[i] + "</a></li>";
                    allTitoli[idx - 2] = titoli[i];
                }
            }
            panel = panel + "</ul>";
            testo[url] = panel;
            titoliA[url] = allTitoli;
nav.clear();
            if (allTitoli.length == 1  ){
            document.getElementById('col1_content').innerHTML = '';
                nav.cambia_sez(1); 
                } 
            else{
         
                document.getElementById('col1_content').innerHTML = panel;
               }  
           // document.getElementById('titolo1').innerHTML = titoliA[url][0];
            
        }
    }
    
    this.send();
    
}


Ajax.prototype.send = function(){

    switch (this.type) {
        case 0:
			xmlHttp0 = Ajax.prototype.GetXmlHttpObject();
            xmlHttp0.onreadystatechange = this.reqBar;
            xmlHttp0.open("GET", this.url, true);
            xmlHttp0.send(null);
            break;
        case 1:
			xmlHttp1 = Ajax.prototype.GetXmlHttpObject();
            xmlHttp1.onreadystatechange = this.reqTesto;
            xmlHttp1.open("GET", this.url, true);
            xmlHttp1.send(null);
            break;
        case 2:
			xmlHttp2 = Ajax.prototype.GetXmlHttpObject();
            xmlHttp2.onreadystatechange = this.reqTitoli;
            xmlHttp2.open("GET", this.url, true);
            xmlHttp2.send(null);
            break;
		case 3:
			xmlHttp3 = Ajax.prototype.GetXmlHttpObject();
		    xmlHttp3.onreadystatechange = this.reqTitoliImg;
            xmlHttp3.open("GET", this.url, true);
            xmlHttp3.send(null);
            break;	
			
    }
    
    
}


Ajax.prototype.GetXmlHttpObject = function(){
    try {
        // Firefox, Opera 8.0+, Safari
        var xmlHttp = new XMLHttpRequest();
        
    } 
    catch (e) {
        // Internet Explorer
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } 
        catch (e) {
            xmlHttp = new ActiveXObject("MSXML2.XMLHTTP.3.0");
        }
    }
    if (xmlHttp == null) {
        alert("Your browser does not support AJAX!");
        return;
    }
    return xmlHttp
}






