﻿
var xmlHttp;

function createXMLHttpRequest()
{
	if (window.ActiveXObject)
	{
		try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e)
		{
			try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); }
			catch (e) {}
		}
	} 
	else {
		if (window.XMLHttpRequest)
			xmlHttp = new XMLHttpRequest();
	}
	
	if (!xmlHttp)
    {
        alert('Errore: impossibile votare!');
        return false;
    }
}

function VotaDocumento(valore,id,uid)
{
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = function() { ricevi(id); }
	xmlHttp.open("GET", "/tesi/salva_voto.asp?v=" + valore + "&id=" + id + "&uid=" + uid, true);
	xmlHttp.send(null);
}

function ricevi(id)
{
	if (xmlHttp.readyState == 4)
	{
		if (xmlHttp.status == 200) {
		
		    var returnVal = xmlHttp.responseText;
		    
		    if (returnVal == 1) {
		        alert("Grazie per il voto!");
		        location.href = "/tesi/dettaglio.asp?id=" + id;
		    }
		    else if (returnVal == -1) {
		        alert("Hai gia' votato per questo evento!");
		    }
		    else if (returnVal == -2) {
		        alert("Devi effettuare il login per poter votare!");
		    }	
		    else if (returnVal == -3) {
		        alert("Errore durante la votazione!");
		    }				
		}
	}
}


