

function clearDiv() {
	document.getElementById("lastseen").innerHTML = "";
}


function ajax()
	{
    var xhr=null;
    
    if (window.XMLHttpRequest) { 
        xhr = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) 
    {
        xhr = new ActiveXObject('Microsoft.XMLHTTP');
    }
    //on définit l'appel de la fonction au retour serveur
    xhr.onreadystatechange = function() { affichage_ajax(xhr); };
    
    //on appelle le fichier reponse.txt
    var url = '../../../../infusions/last_seen_users_panel/reponse.php?time=' + (new Date().getTime());
    xhr.open('GET', url, true);
    xhr.send(null);
	
}


function affichage_ajax(xhr)
{
    if (xhr.readyState==4) 
    {
    	var docXML= xhr.responseXML;
    	var items = docXML.getElementsByTagName('user')
    	var html     = ''; /* Présentation HTML de la liste des connectés */
		/* Nombre de membre a afficher */
		count        = items.length;
		clearDiv();
	html += '<table cellpadding="0" cellspacing="0" width="100%">';
		
		for(i = 0; i < count; i++) { 	
    		html += '<tr><td class="side-small" align="left"><img src="../../themes/Maohi Reborn/images/bullet.gif" alt=""> ';
    		html += '<a href="../../profile.php?lookup=' + items[i].getElementsByTagName("user_id")[0].firstChild.nodeValue + '" ';
			html += 'title="' + items[i].getElementsByTagName("user_name")[0].firstChild.nodeValue + '" class="side">';
			
    		if (items[i].getElementsByTagName("user_level")[0].firstChild.nodeValue == "103") {
				html += '<font color="red"><b>' + items[i].getElementsByTagName("user_name")[0].firstChild.nodeValue + '</b></font></a></td>';
   			} 
   			else if (items[i].getElementsByTagName("user_level")[0].firstChild.nodeValue == "102") {
				html += '<font color="orange"><b>' + items[i].getElementsByTagName("user_name")[0].firstChild.nodeValue + '</b></font></a></td>';
   			} 
   			else {
				html += '<font color="orange"><b>' + items[i].getElementsByTagName("user_name")[0].firstChild.nodeValue + '</a></b></td>';
   			}
   			
   			if (items[i].getElementsByTagName("time")[0].firstChild.nodeValue == "En ligne") {
				html += '<td class="side-small" align="right"><font color="lime"><b>' + items[i].getElementsByTagName("time")[0].firstChild.nodeValue + '</b></font></td></tr>';	
			} else {
				html += '<td class="side-small" align="right">' + items[i].getElementsByTagName("time")[0].firstChild.nodeValue + '</td></tr>';
			}	
		}
		html += '</table>';
		
		
		document.getElementById('lastseen').innerHTML += html;
		
		setTimeout("ajax();",10000); // rafraichissement toutes les 10 sec
    }
	
	
}

window.onload=ajax;
