	var myRequest = null;
	var myRequest2 = null;
	var myRequest3 = null;

	function CreateXmlHttpReq(handler) {
	  var xmlhttp = null;
	  try {
		xmlhttp = new XMLHttpRequest();
	  } catch(e) {
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	  }
	  xmlhttp.onreadystatechange = handler;
	  return xmlhttp;
	}
	
	function myHandler() {
		if (myRequest.readyState == 4 && myRequest.status == 200) {
			//document.getElementById("info").innerHTML = myRequest.responseText;
			if (myRequest.responseText == '0')
				document.getElementById("faves").innerHTML = "ELIMINA DAI PREFERITI";
			else
				document.getElementById("faves").innerHTML = "AGGIUNGI AI PREFERITI";
		}
	}
	
	function myHandler_challenge() {
		if (myRequest.readyState == 4 && myRequest.status == 200) {
			//document.getElementById("info").innerHTML = myRequest.responseText;
			if (myRequest.responseText == '0')
				document.getElementById("faves").innerHTML = "Cancella Il tuo voto a questa immagine";
			else
				document.getElementById("faves").innerHTML = "Dai il tuo voto a questa immagine";
		}
	}
		
	function add_to_faves(topic_id, user_id){
		var r = Math.random();
		alert("add");
		myRequest = CreateXmlHttpReq(myHandler);
		myRequest.open("GET","/forum/faves.php?action=add&topic_id="+topic_id+"&user_id="+user_id+"&rand="+escape(r));
		myRequest.send(null);
	}
	
	function rem_to_faves(topic_id, user_id){
		var r = Math.random();
		alert("rem");
		myRequest = CreateXmlHttpReq(myHandler);
		myRequest.open("GET","/forum/faves.php?action=rem&topic_id="+topic_id+"&user_id="+user_id+"&rand="+escape(r));
		myRequest.send(null);
	}
	
	function faves(topic_id, user_id, forum_id){
		var r = Math.random();
		if (forum_id != 41)
			myRequest = CreateXmlHttpReq(myHandler);
		else
			myRequest = CreateXmlHttpReq(myHandler_challenge);
		myRequest.open("GET","/forum/faves.php?topic_id="+topic_id+"&user_id="+user_id+"&rand="+escape(r));
		myRequest.send(null);
	}