var httpRequest = false;

 tblCaract = new Array();

tblOrganisation = new Array();
	tblOrganisation[1] = "Auteur";
	tblOrganisation[2] = "Annee";
	tblOrganisation[3] = "ISBN";
	tblOrganisation[4] = "Format";
	tblOrganisation[5] = "Pages";


		
function makeRequest(URL,id) {

       // var httpRequest = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            httpRequest = new XMLHttpRequest();
            // netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserAccess');
            if (httpRequest.overrideMimeType) {
                httpRequest.overrideMimeType('text/xml');
                // Voir la note ci-dessous Ã  propos de cette ligne
            }
        } else if (window.ActiveXObject) { // IE
            try {
                httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!httpRequest) {
            alert('Abandon :( Impossible de crÃ©er une instance XMLHTTP');
            return false;
        }
		
	//alert("makeRequest("+URL+", "+id+")");
        httpRequest.onreadystatechange = function() { alert("onreadystatechange = "+ onreadystatechange); alertContents(httpRequest,id); };
	
        //httpRequest.open('GET', URL, true);
	httpRequest.open('GET', URL, false);
        httpRequest.send(null);
	//alert("makeRequest("+URL+", "+id+")");
	
    }

/*****
var urlBase = '{$base_dir}' ;
   function writeLivre(livre) {
    	var url = urlBase + '/table_matieres/'+ livre +'_tblMatiere.html' ;
    	var id = 'livre-' + livre;
	document.write("<div id=\"" + id + "\"></div>"
	+ "<script type='text/javascript' language='javascript'>makeRequest('" 
	+ url + "','" + id 
	+ "');</script>" 
	);
   }
******/
function writeTableMatiere(livre) {	
	urlBase = document.location;
	alert("document.location = "+urlBase);
	
	var url = 'table_matieres/'+ livre +'_tblMatiere.html' ;
	alert("livre = "+livre+"<br>url = <br>"+url);
	makeRequest( url ,livre);
	document.getElementById("idTabTableMatiere").innerHTML = httpRequest.responseText + "he he he, ca va marcher!";  
}

function writeTableMatierebis(livre, url_base) {

    	//var url ='data_themes_matiere/'+ livre +'_tblMatiere.html' ;
	var url ='/data_themes_matiere/'+ livre +'_tm' ;
    	    	
	var id = 'livre-' + livre;
	
	//alert("reponse table matieres:\n"+ httpRequest.responseText);
	httpRequest.responseText = null;
	makeRequest( url ,livre);
	document.getElementById("idTabTableMatiere").innerHTML = httpRequest.responseText;  
	//alert("URL Table des matières : \n" + url);
	//alert("reponse table matieres:\n"+ httpRequest.responseText);
	
   }

function writeTableTheme(livre, url_base) {


    	//var url = 'data_themes_matiere/'+ livre +'_themes.html' ;
    	var url = '/data_themes_matiere/'+ livre +'_th' ;
	makeRequest( url ,livre);
	//alert("reponse THeme:\n"+ httpRequest.responseText);
	document.getElementById("idTabTheme").innerHTML = httpRequest.responseText ;  
	
   }

 function writeNotes(livre, url_base) {

    	var url = 'data_themes_matiere/'+ livre +'_notes.html' ;
    	var id = 'livre-' + livre;
	makeRequest( url ,livre);
	alert("reponse Note:\n"+ httpRequest.responseText);
	document.getElementById("idTabNotes").innerHTML = httpRequest.responseText;  
	
   }

 function setCaract( identifiant, valeur)
{
	//alert("setCaract("+identifiant+", "+valeur+" )");
	tblCaract[identifiant] = valeur;
}

 function get( identifiant )
{
	return tblCaract[identifiant];
}
 function reorganiseCaracts()
{	
	var agencementCaracts = "";
	
	for (i in tblOrganisation)
	//for (var i=1; i<tblOrganisation.length; i++)	
	{
		//alert("demande pour i = " +i  +"    =>   "+tblOrganisation[i]);
		if (document.getElementById ("idTab"+tblOrganisation[i]) != null)
		{
			//alert("va modifier: idTab"+tblOrganisation[i]  +"     =>    "+get(tblOrganisation[i])+"  , indexOf(ISBN) = "+i.indexOf("ISBN"));
			if (tblOrganisation[i]=="ISBN" || tblOrganisation[i]=="Format" || tblOrganisation[i] == "Annee" )
			 agencementCaracts += "<tab id=\"idTab"+tblOrganisation[i]+"\">"+tblOrganisation[i]+": <strong>"+get(tblOrganisation[i])+"</strong></tab><br>";
			else if ( tblOrganisation[i] == "Pages")
			agencementCaracts += "<tab id=\"idTab"+tblOrganisation[i]+"\">"+tblOrganisation[i]+": <strong>"+get(tblOrganisation[i])+" p.</strong></tab><br>";
			else
			 agencementCaracts += "<tab id=\"idTab"+tblOrganisation[i]+"\"><strong>"+get(tblOrganisation[i])+"</strong></tab><br>";
		  //document.getElementById("idTab"+tblOrganisation[i]).innerHTML = tblOrganisation[i]+": "+ get(tblOrganisation[i]);
		}
	}
	document.getElementById("idTabCaractsPrincipales").innerHTML= agencementCaracts;	
}

function test()
{
	alert("test");
	//document.write("<div id=\"" + id + "\"> REQUETTE FAITE: "+makeRequest(url)+"</div>");	
	var url = 'table_matieres/1234_tblMatiere.html' ;
	//document.getElementById("testDiv").innerHTML =document.write( makeRequest(url) ); ;
}

