// JavaScript Document
function start_agenda() {
	var sport='';
	var provincia=document.select_impianto.provincia.value;
	var comune=document.select_impianto.comune.value;
	var impianto=document.select_impianto.impianto.value;
	if ( document.select_impianto.elements["sport[]"].selectedIndex == -1 ) {
		alert('Selezionare uno sport');
	} else {
		document.select_impianto.submit();
	}
}

function form_ricerca() {
	var sport=document.ricerca_celle.sport.value;
	var filtro=document.ricerca_celle.elements['filtro[]'].selectedIndex;
	if (sport>0 && filtro!=-1) {
		document.ricerca_celle.submit();
	} else {
		alert('selezionare correttamente i parametri di ricerca');
	}
}

function assegnaXMLHttpRequest() {

// lista delle variabili locali
var
 // variabile di ritorno, nulla di default
 XHR = null,
 
 // informazioni sul nome del browser
 browserUtente = navigator.userAgent.toUpperCase();


 // browser standard con supporto nativo
 // non importa il tipo di browser
 if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object")
  XHR = new XMLHttpRequest();

 // browser Internet Explorer
 // è necessario filtrare la versione 4
 else if(
  window.ActiveXObject &&
  browserUtente.indexOf("MSIE 4") < 0
 ) {
 
  // la versione 6 di IE ha un nome differente
  // per il tipo di oggetto ActiveX
  if(browserUtente.indexOf("MSIE 5") < 0)
   XHR = new ActiveXObject("Msxml2.XMLHTTP.3.0");

  // le versioni 5 e 5.5 invece sfruttano lo stesso nome
  else
   XHR = new ActiveXObject("Microsoft.XMLHTTP");
 }

 return XHR;
}

function contenuto_div_post_ajax(url,id,p) {
  if (url.substring(0, 4) != 'http' || 
	  url.substring(0, 5) != 'https' ||
	  url.substring(0, 3) != 'ftp' ||
	  url.substring(0, 3) != 'mms') {
  var ajax = assegnaXMLHttpRequest();
  if(ajax) {
   	ajax.open("POST", url , true);
   	ajax.setRequestHeader("content-type", "application/x-www-form-urlencoded");
   	ajax.setRequestHeader("Content-length", p.length);
   	ajax.setRequestHeader("connection", "close");
   	ajax.onreadystatechange = function() {
  
      // verifica dello stato
      if(ajax.readyState === 4) {
		  if (ajax.status == 200 || ajax.status == 0) {
			  document.getElementById(id).innerHTML = ajax.responseText;
		  } else { document.getElementById(id).innerHTML= "At the moment, information are not available. Try to refresh the page."; } 
	  }
    } 
   ajax.send(p);
 }
  } else { alert("URL unsafe"); }
}
function close_div(id) {
	document.getElementById(id).style.display='none';
}
function open_div(id) {
	document.getElementById(id).style.display='block';
}