livreDorInterval=120;

//*********** AJAX API ****************

function getXMLHttpRequest() {
	var xhr = null;
	if(window.XMLHttpRequest) xhr = new XMLHttpRequest();
	else if(window.ActiveXObject) {
		try {
			xhr = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	else xhr = false;
	return xhr;
}


// appel? dans la page
function appelLivreDor() {
	createRequestObject(contextPath+"/getLivreDor.do?interval="+livreDorInterval);
	livreDorInterval=livreDorInterval+120;
}

  var ro;
  var which;

function createRequestObject(url) {

    if(window.ActiveXObject){
        try {
        ro = new ActiveXObject("Msxml2.XMLHTTP");
	        	
      	} catch(e) {
      	try {
          		ro = new ActiveXObject("Microsoft.XMLHTTP");
				
        		} catch(e) {
          		ro = null;
        	}
      	}
      	ro.onreadystatechange = handleResponse;
		ro.open("GET", url, true);
		ro.send(""); 
    }else{
        ro = new XMLHttpRequest();
        if (ro.overrideMimeType) 
               ro.overrideMimeType('text/xml');
    ro.onreadystatechange = handleResponse;
    ro.open('GET', url, true);
    ro.send("");
    }
}



  function handleResponse() {
 
    if (ro.readyState == 4) { // Complete
      if (ro.status == 200) { // OK response
        xml = ro.responseXML;
        html = "<ul>";
			// utiliser getHtml	
			dates = xml.getElementsByTagName("date");
			names = xml.getElementsByTagName("name");
			comments = xml.getElementsByTagName("comment");
			for(i=0;i<dates.length;i++){
				thisDate = dates[i].firstChild.data;
				thisName = names[i].firstChild.data;
				thisComment = comments[i].firstChild.data;
				html += "<li>"+thisDate+"&nbsp;&nbsp;"+thisName+"</li>"
				html += "<p>"+thisComment+"</p>";
			}
			html += "</ul>";
			if(i>0)
				html=html+"<p><span class='bold themeTextColor clickable' onclick='javascript:appelLivreDor();'>Voir les commentaires du mois pr&eacute;c&eacute;dent ></span></p>";
			else
				html = "<p>Pas d'autres commentaires dans l'historique !</p>";
        document.getElementById("commentSection").innerHTML = html;
      } else {
        alert("Problem: " + http.statusText);
      }
    }
  }
  
