
var http = createRequestObject();

function createRequestObject() {
	// find the correct xmlHTTP, works with IE, FF and Opera
	var xmlhttp;
	try {
  	xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
  catch(e) {
    try {
    	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch(e) {
    	xmlhttp=null;
    }
  }
  if(!xmlhttp&&typeof XMLHttpRequest!="undefined") {
  	xmlhttp=new XMLHttpRequest();
  }
	return  xmlhttp;
}
  

function handleDivTag(divtag) 
{ 
   var divtag; 
   return divtag; 
} 


// Create the Divtag Handler -- Mainly an IE 6 Fix 
var divhandler = new handleDivTag(null); 

function sendRequest(act,divtag,generator,rubrique) { 
   // Open PHP script for requests 
   //http.open('get', 'genereimagealeatoire.php?from=ajax');
   http.open('get', generator);
   http.setRequestHeader('Content-Type',  "text/xml");
   http.onreadystatechange = function () {
            stageChanged(rubrique);
        };
   divhandler.divtag = divtag; 
   http.send(null); 

} 

function stageChanged(rubrique) { 
	
	if(http.readyState == 4 && http.status == 200)
	{ 
   
    var response = http.responseXML;
	var myresult = '';


	switch(rubrique)
    {
    case 'imagealeatoire' :
        ///// Propre au cas de la photo aléatoire
		var idlot = response.getElementsByTagName("idlot")[0].firstChild.nodeValue;
		var path = response.getElementsByTagName("path")[0].firstChild.nodeValue;
		var author = response.getElementsByTagName("author")[0].firstChild.nodeValue;
		image1= new Image();
		image1.src = path;
		myresult = '<a href="liste_photo.php?lot='+ idlot + '" onclick="javascript:window.open(\'liste_photo.php?lot=' + idlot + '\',\'fen\',\'toolbars=no,scrollbars=yes,width=800,height=600\') ;return false;"><img src=\''+path+'\' height=\'120\' border=\'0\' alt=\'un cliché publié par ' + author + ' ... cliquer pour visualiser la série complète\'></a>'; 
		///////////////////////////////////////////
        break;    
	case 'onaimealeatoire' :
        ///// Propre au cas de la photo aléatoire
		var idonaime = response.getElementsByTagName("idonaime")[0].firstChild.nodeValue;
		var path = response.getElementsByTagName("path")[0].firstChild.nodeValue;
		var libelleonaime = response.getElementsByTagName("libelleonaime")[0].firstChild.nodeValue;
		var categorie = response.getElementsByTagName("categorie")[0].firstChild.nodeValue;
		image1= new Image();
		image1.src = path;
		myresult = libelleonaime+categorie+'<a href="fiche_onaime.php?idchaine='+ idonaime + '" onclick="javascript:window.open(\'fiche_onaime.php?idchaine=' + idonaime + '\',\'fen\',\'toolbars=no,scrollbars=yes,width=800,height=600\') ;return false;"><img src=\''+path+'\' height=\'120\' border=\'0\' alt=\'cliquer pour visualiser la fiche\'></a>'; 
		///////////////////////////////////////////
        break;    
    } 


	if(response) { 
			 // UPDATE ajaxTest content 
			 document.getElementById(divhandler.divtag).innerHTML = myresult;
			} 
	} 

} 




