// 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;
}


function rateImg(rating,imgId)  {
		remotos = new datosServidor;
		nt = remotos.enviar('/setRating.php?rating='+rating+'&rid='+imgId);
		document.getElementById('rating').innerHTML = 'Спасибо за оценку, ваше мнение <br>для меня очень важно.';
}

function mainVote(vote, d){
    document.getElementById('voteSubmit').innerHTML = '<img src="/images/loading_16.gif" width="16" height="16" style="margin:0">';
	var f = document.getElementById('vote');
	var res = 0;
	ans = f.getElementsByTagName("input");
	for(i=0;i<ans.length;i++){
		if(ans[i].checked){
			res = ans[i].value;
		}
	}
	if(res > 0){
		remotos = new datosServidor;
		document.getElementById('vote').innerHTML = remotos.enviar('/mainVote.php?vote='+vote+'&a='+res+'&d='+d);
	}

}
function coment_vote(id, vote) {
		document.getElementById("vote_"+id).innerHTML = '<img src="/images/loading_16.gif" width="16" height="16">';
		remote = new datosServidor;
		res = remote.enviar("/lib/vote_set.php?id="+id+"&vote="+vote);
		document.getElementById("vote_"+id).innerHTML = res;
}
function get_coment_text(id) {
		remote = new datosServidor;
		res = remote.enviar("/lib/get_coment_text.php?id="+id);
		document.getElementById("text_"+id).innerHTML = res;
}
