var val=0;
var bloccavoti=0;
var thissite="";

// Shortcut for creating a GET request and get the reply
var xmlhttp=false;
var xml2 = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
	try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (E) {
		xmlhttp = false;
	}
}
@end @*/

if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	xmlhttp = new XMLHttpRequest();
}


function getMyHTML(serverPage, objID) {
	var obj = document.getElementById(objID);
	obj.innerHTML='<img style="float:left; margin-right:4px;" src="./img/wait.gif" style="width:24px; height:24px;" /> Stiamo registrando la tua preferenza.';
	xmlhttp.open("GET", serverPage);
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			resp=xmlhttp.responseText.split(" ");

			obj.innerHTML = '';
			document.getElementById('tuovoto').innerHTML=resp[0];
			document.getElementById('votomedio').innerHTML=resp[1];
			if (resp[2]==1) {
				document.getElementById('numerovoti').innerHTML=resp[2]+" VOTO";
			} else {			
				document.getElementById('numerovoti').innerHTML=resp[2]+" VOTI";
			}
			for (i=1;i<=7;i++) {
				document.getElementById('trim'+i).innerHTML='';
			}
			idd=8-resp[0];
			document.getElementById('trim'+idd).innerHTML='<img src="/img/trim.jpg" alt="" width="26" height="10" />';
			bloccavoti=1;
		} 
	}
	xmlhttp.send(null);
}

function ov(th,val){
	if (bloccavoti!=1){
		th.style.background='url('+thissite+'"/img/trim.jpg") left center no-repeat';
		document.getElementById('votohov').innerHTML=val;
	}
}
function ot(th,tr){
	if (bloccavoti!=1){
		th.style.background='url('+thissite+'"/img/trimmer/_trim'+tr+'.gif") left center no-repeat';
		document.getElementById('votohov').innerHTML='';
	}
}
function fix(th,v,id){
	if (bloccavoti!=1){
		for (i=1;i<=7;i++) {
			document.getElementById('trim'+i).innerHTML='';
		}
		val=v;
		idd=8-v;
		th.style.background='url('+thissite+'"/img/trimmer/_trim'+idd+'.gif") left center no-repeat';
		registra(id);
	}
}
function registra(id){
	if (val!=0){
		getMyHTML(thissite+"/vota.php?v="+val+"&id="+id, "risultato")
	}
}
