var READY_STATE_UNINITIALIZED = 0;
var READY_STATE_LOADING = 1;
var READY_STATE_LOADED = 2;
var READY_STATE_INTERACTIVE = 3;
var READY_STATE_COMPLETE = 4;
var httpReq;

function initHttpRequest() {
	if ( window.XMLHttpRequest ) {
		return new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
}
/*
 * Función que carga el contenido desde el servidor.
 * url -> Fichero php que carga el contenido
 * metodo -> GET o POST
 * queryString -> Parámetros a enviar al PHP
 * id -> Id del elemento HTML donde cargar el contenido
 */
function loadContenido(url, metodo, queryString, id, sync ) {
	
	httpReq = initHttpRequest();
	
	if ( httpReq ) {
		
		httpReq.onreadystatechange = function () {
			//document.getElementById(id).innerHTML = '<div class="ajax_loader">' + 
			//'<img src="../images/ajax-loader.gif" />Cargando...</div>';
			
			if( httpReq.readyState == READY_STATE_COMPLETE ) {
				if(httpReq.status == 200 ) {
					//alert("");
					document.getElementById(id).innerHTML = httpReq.responseText;
				}
				if(httpReq.status == 500) {
					document.getElementById(id).innerHTML = "No se puede Cargar el motor de gestión de álbumes. Int&eacute;ntelo m&aacute;s tarde";	
				}
			}
		};
		
		httpReq.open( metodo, url, sync);
		
		if ( metodo == "POST" ) {
			httpReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		} else {
			queryString = null;
		}
		
		httpReq.send( queryString );
		
	}

}

function getChatOnlineUsers() {
	url = "chat/whoOnline.php";
	loadContenido(url, "POST", "", "chat_online", true);
}

function timedCount() {
	getChatOnlineUsers();
	chatTimer = setTimeout("timedCount()", 20000);
}

function doTimer() {
	timedCount();
}


