function richiediConferma(msg,url) {
	var risposta = confirm(msg);
	if (risposta){				
		window.location = url;
	}			
}


function gotopage(x){
	document.location=x;
	
}


/**
 * funzione per inserire almeno la regione
 * @returns {Boolean}
 */
function validate(){
	
	var selezione=document.getElementById("regione").value;
	if ((selezione == "0") || (selezione == "undefined")) {
	   alert("inserire almeno la regione.");
	   return false;
	}
	
	}

/**
 * funzione per far apparire la mappa di google map
 */

function initialize() {
	  var geocoder;
	  var map;
	  var latlng;
  geocoder = new google.maps.Geocoder();
    var address = document.getElementById("address").value;
     geocoder.geocode( { 'address': address}, function(results, status) {
    if (status == google.maps.GeocoderStatus.OK) {
     latlng=results[0].geometry.location;
      var myOptions = {
    zoom: 10,
    center: latlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  }
  map = new google.maps.Map(document.getElementById("mappaGoogle"), myOptions);
  map.setCenter(results[0].geometry.location);
      var marker = new google.maps.Marker({
          map: map, 
          position: results[0].geometry.location
      });

     
    } else {
      alert("Geocode was not successful for the following reason: " + status);
    }
  });
}


/**
 * JsDatePicker per inserire la data in formato calendario
 */
function showcalendar1(){
	new JsDatePick({
		useMode:2,
		target:"DataInizio",
		dateFormat:"%Y-%m-%d"
		/*selectedDate:{				This is an example of what the full configuration offers.
			day:5,						For full documentation about these settings please see the full version of the code.
			month:9,
			year:2006
		},
		yearsRange:[1978,2020],
		limitToToday:false,
		cellColorScheme:"beige",
		dateFormat:"%m-%d-%Y",
		imgPath:"img/",
		weekStartDay:1*/
	});
}


/**
 * Ajax request per visualizzare gli utenti per nome 
 * @param str 
 */
function showUser2(str)
{
if (str=="")
  {
  
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	  $('#utenti').html(xmlhttp.responseText);
    }
  }
  
xmlhttp.open("GET","cercautenti.php?nome="+str,true);
xmlhttp.send();
}

/**
 * Ajax request per visualizzare le provincie a seconda della regione scelta
 * @param str la regione per cui si vuole visualizzare le provincie
 */
function showregion(str)
{

 $.ajax({
    type: "GET",    
    url: "cercaprovincie.php",     
    data: {"regione": str},       
    cache: false,
    success: function (html) {
    $('#provincia').html('<option value=" ">Seleziona provincia</option> '+html);

     $('#citta').html("<option value=\"\">Seleziona citta</option> ");
    },
         error:function (xhr, ajaxOptions, thrownError){
         alert(xhr.status);
         alert(thrownError);
          } 
});

 
  
}
/**
 * Ajax request per visualizzare i comuni di una provincia
 * 
 * @param str la provincia scelta per la request
 */
function showcomuni(str)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
   try {
	        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	    } catch(e) {
	        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	    }
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    $('#citta').html("<option value=\"\">Seleziona citta</option> "+xmlhttp.responseText);
    }
  }
  
xmlhttp.open("GET","cercacitta.php?provincia="+str,true);
xmlhttp.send();
}

/**
 * Ajax request per la visualizzazione dei click della struttura scelta
 */

function getQSParam(ParamName) {
	  // Memorizzo tutta la QueryString in una variabile
	  QS=window.location.toString(); 
	  // Posizione di inizio della variabile richiesta
	  var indSta=QS.indexOf(ParamName); 
	  // Se la variabile passata non esiste o il parametro è vuoto, restituisco null
	  if (indSta==-1 || ParamName=="") return null; 
	  // Posizione finale, determinata da una eventuale &amp; che serve per concatenare più variabili
	  var indEnd=QS.indexOf('&amp;',indSta); 
	  // Se non c'è una &amp;, il punto di fine è la fine della QueryString
	  if (indEnd==-1) indEnd=QS.length; 
	  // Ottengo il solore valore del parametro, ripulito dalle sequenze di escape
	  var valore = unescape(QS.substring(indSta+ParamName.length+1,indEnd)); 
	  // Restituisco il valore associato al parametro 'ParamName'
	  return valore; 
	  }


function showclick()
{
var id=getQSParam("structureid");
var anno=document.getElementById("anno").value;
var mese=document.getElementById("mese").value;
if (anno=="" || mese=="")
  {
  document.getElementById("tabellaclick").innerHTML="";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
     $('#tabellaclick').html(xmlhttp.responseText);
    }
  }

xmlhttp.open("GET","mostralink.php?mese="+mese+"&anno="+anno+"&id="+id,true);
xmlhttp.send();
}


function setImmagineProfilo(id,idCliente)
{
	
if (id=="" || idCliente=="")
  {
  document.getElementById("messaggio").innerHTML="nn va";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
     $('#messaggio').html(xmlhttp.responseText);
    
    }
  }



xmlhttp.open("GET","impostaImmagineProfilo.php?id="+id+"&idCliente="+idCliente,true);
xmlhttp.send();
}


function eliminaImmagineProfilo(id,idCliente)
{
	
	if (id=="" || idCliente=="")
	  {
	  document.getElementById("messaggio").innerHTML="nn va";
	  return;
	  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("messaggio").innerHTML=xmlhttp.responseText;
    }
  }



xmlhttp.open("GET","eliminaImmagineProfilo.php?id="+id+"&idCliente="+idCliente,true);
xmlhttp.send();
}




function setImmagineStruttura(id,idStruttura)
{
	
if (id=="" || idStruttura=="")
  {
  document.getElementById("messaggio").innerHTML="nn va";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	  $('#messagioStruct').html(xmlhttp.responseText);    }
  }



xmlhttp.open("GET","impostaImmagineStruttura.php?id="+id+"&idStruttura="+idStruttura,true);
xmlhttp.send();
}


function aggiungiCommento(id,idCommento,divCommento)
{
	
var testo=document.getElementById(divCommento).value;
if (id=="" || testo=="" || testo=="Scrivi un commento")
  {
  document.getElementById(idCommento).innerHTML="";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
      
     $('#'+idCommento+'').append(xmlhttp.responseText);
    }
  }

xmlhttp.open("GET","aggiungiCommento.php?id="+id+"&testo="+testo+"&commento="+idCommento,true);
xmlhttp.send();

document.getElementById(divCommento).value='Scrivi un commento';
}



function eliminaCommento(id,idCommento)
{
	
if (id=="" )
  {
  document.getElementById(idCommento).innerHTML+="Non va";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById(idCommento).className="hide";
    }
  }

xmlhttp.open("GET","eliminaCommento.php?id="+id,true);
xmlhttp.send();
}

function mostraNotifiche(id)
{
	
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
     $('#notifiche').html(xmlhttp.responseText);
        $('#notifiche').dialog('open');
    }
  }

xmlhttp.open("GET","mostraNotifiche.php?id="+id,true);
xmlhttp.send();
}



function setReadNotifica(id)
{
	
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	  
    }
  
  }

xmlhttp.open("GET","setReadNotifica.php?id="+id,true);
xmlhttp.send();
}


function suggest(inputString){
	if(inputString.length == 0) {
		$('#suggestions').fadeOut();
	} else {
	$('#country').addClass('load');
		$.post("cercaStruttura.php", {queryString: ""+inputString+""}, function(data){
			if(data.length >0) {
				$('#suggestions').fadeIn();
				$('#suggestionsList').html(data);
				$('#country').removeClass('load');
			}
		});
	}
}

function fill(thisValue) {
	$('#country').val(thisValue);
	setTimeout("$('#suggestions').fadeOut();", 10000);
}



function utentiOnline()
{
	
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
     $('#utentiOnline').html(xmlhttp.responseText);
        $('#utentiOnline').dialog('open');
    }
  }

xmlhttp.open("GET","utentiOnline.php",true);
xmlhttp.send();
}

