function popUp(URL,w,h,s,r)
{
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars='+s+',location=0,statusbar=0,menubar=0,resizable='+r+',width='+w+',height='+h+',left = 100,top = 80');");
}

function validateSearch(formName)
{
	if(document.forms[formName].word.value == '') alert('Devi inserire almeno una parola per fare la ricerca.');
	else document.forms[formName].submit();
	return false;
}

function vis(id)
{
	o=document.getElementById('oggi');
	i=document.getElementById('ieri');
	imgo=document.getElementById('img_oggi');
	imgi=document.getElementById('img_ieri');
	
	sel=document.getElementById(id);
	img=document.getElementById('img_'+id);
	
	o.style.display="none";
	i.style.display="none";
	imgo.className="title small";
	imgi.className="title small";
	
	sel.style.display="block";
	img.className="title small selected";
}

function stampa() { this.print(); }

/* il codice è duplicato nel main.js di DEFAULT */
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.php?action=sondaggio&idsondaggio="+id+"&idrisposta="+risp); // percorso diverso, slash prima di action!
		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';
	}
}