function toplette(id)
{
	div = document.getElementById('toplette').getElementsByTagName('DIV');
	for (i=0; i<div.length; i++) if (div[i].id.substring(0,1)=='t') div[i].className = (div[i].id==div[i].id.substring(0,2)+id) ? div[i].className.replace('none', '') : 'none'+div[i].className.replace('none', '');
}

function createClient()
{
	client = false;
	if (window.XMLHttpRequest) client = new XMLHttpRequest();
	else
	{ 
		if (window.ActiveXObject) client = new ActiveXObject("Microsoft.XMLHTTP");
	    if (!client) client = new ActiveXObject("Msxml2.XMLHTTP");
	}
	return client;
}

function vota(form, id)
{
	risp = false;
	for (i=0; i<document.forms[form].idrisposta.length; i++) if (document.forms[form].idrisposta[i].checked) risp = (document.forms[form].idrisposta[i].value);
	if (risp)
	{
		document.getElementById('button_'+form).disabled = true;
		client = createClient();
		client.onreadystatechange = function(){
			if (client.readyState == 4 && client.responseText!=null) document.getElementById('handler_txt_'+form).innerHTML = client.responseText;
			if (client.readyState == 4 && client.status != 200)
			{
				document.getElementById('handler_txt_'+form).innerHTML = "Errore di sistema"; // azione conclusa ma pagina con errore
				document.getElementById('button_'+form).disabled = false;
			}
			if (client.readyState == 4) { clearTimeout(xmlHttpTimeout); document.getElementById('handler_txt_'+form).style.display = 'block'; document.getElementById('handler_'+form).style.display = 'none'; } 
			if (client.readyState == 1) { document.getElementById('handler_'+form).style.display = 'block'; document.getElementById('handler_txt_'+form).style.display = 'none'; }
		};
		client.open("GET", "/?action=sondaggiosend&idsondaggio="+id+"&idrisposta="+risp);
		client.send();

		xmlHttpTimeout = setTimeout(function() { client.abort(); },5000);
	}
	else
	{
		document.getElementById('handler_txt_'+form).innerHTML = "Non hai selezionato alcuna risposta";
		document.getElementById('handler_txt_'+form).style.display = 'block';
	}
}
function checkMobile()
{
	if( ((navigator.userAgent.match(/Android/)) && (navigator.userAgent.match(/Mobile/))) || (navigator.userAgent.match(/iPhone/)) )
  {
//	var x = document.createElement('div');
//	x.innerHTML='<div style="background-color:#990000;padding:6px;border-bottom:3px solid #FFFFFF"><label style="font-size:20px;"><a  href="http://'+document.domain.replace(/www/, "m")+'" style="color:#FFFFFF;">VERSIONE MOBILE</a></label></div>';
//	document.body.insertBefore(x,document.body.childNodes[0]);
	document.write('<div style="background-color:#990000;padding:12px;border-bottom:3px solid #FFFFFF"><label style="font-size:20px;"><a  href="http://'+document.domain.replace(/www/, "m")+'" style="color:#FFFFFF;"><b>VERSIONE MOBILE</b></a></label></div>')
	document.body.style.backgroundPosition = "center 52px";
  }
}
