// Esta es para llamado de datos remotos via xmlHttpRequest

function datosServidor() {
};
datosServidor.prototype.iniciar = function() {
	try {
		// Mozilla / Safari
		this._xh = new XMLHttpRequest();
	} catch (e) {
		// Explorer
		var _ieModelos = new Array(
		'MSXML2.XMLHTTP.5.0',
		'MSXML2.XMLHTTP.4.0',
		'MSXML2.XMLHTTP.3.0',
		'MSXML2.XMLHTTP',
		'Microsoft.XMLHTTP'
		);
		var success = false;
		for (var i=0;i < _ieModelos.length && !success; i++) {
			try {
				this._xh = new ActiveXObject(_ieModelos[i]);
				success = true;
			} catch (e) {
				// Implementar manejo de excepciones
			}
		}
		if ( !success ) {
			// Implementar manejo de excepciones, mientras alerta.
			return false;
		}
		return true;
	}
}

datosServidor.prototype.ocupado = function() {
	estadoActual = this._xh.readyState;
	return (estadoActual && (estadoActual < 4));
}

datosServidor.prototype.procesa = function() {
	if (this._xh.readyState == 4 && this._xh.status == 200) {
		this.procesado = true;
	}
}

datosServidor.prototype.enviar = function(urlget,datos) {
	if (!this._xh) {
		this.iniciar();
	}
	if (!this.ocupado()) {
		this._xh.open("GET",urlget,false);
		this._xh.send(datos);
		if (this._xh.readyState == 4 && this._xh.status == 200) {
			return this._xh.responseText;
		}
		
	}
	return false;
}


// Este es un acceso rapido, le paso la url y el div a cambiar
function _gr(reqseccion,divcont) {
	remotos = new datosServidor;
	nt = remotos.enviar(reqseccion,"");
	document.getElementById(divcont).innerHTML = nt;
}


var urlBase = "/communicate.php?";

function setCounter(value){ 
	var countervalues = document.getElementsByTagName('span');
	for (var i=0; i<countervalues.length; i++){
		var countervalue = countervalues[i];
		if(countervalue.getAttribute("rel") == "counter")
			countervalue.innerHTML = value;		
	}
	urchinTracker("/made_aware");
}

function getCounter(pageId){
		remotos = new datosServidor;
		nt = remotos.enviar(urlBase+'pageId='+pageId+'&getCounter=1');
		setCounter(nt);
		setTimeout('initCounter(\'5\');',20000);
}

function initCounter(pageId){
		remotos = new datosServidor;
		nt = remotos.enviar(urlBase+'pageId='+pageId+'&getCounter=1');
		setCounter(nt);
		// + 1;
	
}

function increaseaware(){
	alert('Thank you! Your souls awareness has been added to our total of one million.\n');
	//update counter
	urchinTracker("/made_aware");
		
}
function addEvent(elm, evType, fn, useCapture)
{
  if (elm.addEventListener){
    elm.addEventListener(evType, fn, useCapture);
    return true;
  } else if (elm.attachEvent){
    var r = elm.attachEvent("on"+evType, fn);
    return r;
  } else {

  }
} 


addEvent(window, "load", getCounter);