
function distantServer() {
};
distantServer.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;
	}
}

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

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

distantServer.prototype.send = 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;
}

distantServer.prototype.post = function(url,datos) {
	if (!this._xh) {
		this.iniciar();
	}
	if (!this.ocupado()) {
		this._xh.open("POST",url,false);
		//Send the proper header information along with the request
		this._xh.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");
		this._xh.setRequestHeader("Content-length", datos.length);
		this._xh.setRequestHeader("Connection", "close");
		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) {
	server = new distantServer;
	nt = server.send(reqseccion,"");
	document.getElementById(divcont).innerHTML = nt;
}



//Estas dos son para guardar

var urlBase = "rating_update.php?";

function rateImg(vote,num_id)  {
	var server = new distantServer;
	nt = server.send('rating_update.php?vote='+vote+'&num_id='+num_id);	
	// On cache le bloc notation et on modifie le bloc texte
	document.getElementById('notation').style.display = 'none';
	document.getElementById('noteVal').style.display = 'none';
	document.getElementById('texte').style.marginTop = '-8px';
	document.getElementById('texte').style.marginLeft = '15px';
	document.getElementById("texte").innerHTML = JS_jeu_merciVote;
	document.getElementById("texte").className = "merci";
	
	// On reloade le vote quelques secondes plus tard
	try {
		setTimeout("reloadVotes(nt)",1000);
	} 
	catch (ex) {}
		
}

function reloadVotes (response) {
	eval(response);
	document.getElementById("texte").style.display = "none";
	document.getElementById("texteVoted").style.display = "";
	document.getElementById("newNoteVal").innerHTML = newNoteVal;
	document.getElementById("currentRating").style.width = newWidth+"px";
	document.getElementById('star-rating').style.display = 'none';
	document.getElementById('star-ratingVoted').style.display = '';
	document.getElementById('notation').style.display = '';
	document.getElementById('noteVal').style.display = '';
}