// JavaScript Document

var waiting;
var xmlHttp=createXmlHttpRequestObject();
var Nave=true;

function createXmlHttpRequestObject()
{
	var xmlHttp;
	if(window.ActiveXObject)
	{
		try
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=false;
		}
	}
	else
	{
		try
		{
			xmlHttp=new XMLHttpRequest();
		}
		catch (e)
		{
			xmlHttp=false;
		}
	}
	if(!xmlHttp){
		alert("Impossibile creare l'oggetto XMLHttpRequest!");
		return null;
	}
	else {
		return xmlHttp;
	}
}


function Vota()
{
	if(xmlHttp.readyState==4 || xmlHttp.readyState==0)
	{

		var f=document.getElementById("frmPoll");
		var p=document.getElementById("pol").value;
		var s=new String;
		
		for(x=0;x<f.elements.length;x++)
		{
			s+=(f.elements[x].type=="checkbox" || f.elements[x].type=="radio") &&f.elements[x].checked ?f.elements[x].name + "=" +encodeURI(f.elements[x].value)+"&":"";
		}
		s+="pol="+escape(encodeURI(p));
		xmlHttp.open("POST", "script/ele_pol.php", true);
		//Send the proper header information along with the request
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", s.length);
xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.onreadystatechange=showresult;
		xmlHttp.send(s);
	}
}

function showresult()
{
	var l=document.getElementById("lPOLL");
	var r=document.getElementById("risultati");

	if(xmlHttp.readyState==4)
	{
		if(xmlHttp.status==200)
		{
			xmlResponse=xmlHttp.responseXML;
			Result=xmlResponse.documentElement;
			try
			{
				helloMessage=Result.firstChild.data;
				if(helloMessage.indexOf("rrore")>0)
				{
					l.innerHTML+="<center><span class='TitoloNews'><strong>"+helloMessage+"</strong></span></center>";//xmlResponse.toString();
				}
				else
				{
					l.innerHTML="<center><span class='TitoloNews'><strong>"+helloMessage+"</strong></span></center>";//xmlResponse.toString();
					document.getElementById("risultati").style.display="";
				}
			}
			catch(e)
			{
				l.innerHTML="Errore!"+e.toString();
			}
		}
		else
		{
			l.innerHTML="errore.."+ xmlHttp.statusText;
		}
	}
}
