function debug(testo)
	{
	var generator=window.open('','name','height=400,width=500');
	generator.document.write(testo);
	generator.document.close();
	}

function VerificaInt(Obj)
	{
	Num=parseInt(Obj.value);
	if (isNaN(Num))
		{
		alert("Il campo deve essere un numero intero.");
		Obj.focus();
		return false;
		}
	Obj.value=Num;
	return true;
	}
function EvOverOut(NomeOggetto,Classe,Stato) // 
	{
	//Questa funzione serve per cambiare la classe dell'oggetto passato in caso di passaggio
	// del mouse sopra viene richiamata dalla funzione php "EvidenziaOverOut" presente
	// in "FunzioniGeneriche.php"
	ObjBoxOggetto=document.getElementById(NomeOggetto);
	if (Stato==1)
		{
		//ObjBoxOggetto.className=Classe+"Hover";
		ObjBoxOggetto.className=Classe+" "+Classe+"Hover";
		}
	else
		{
		ObjBoxOggetto.className=Classe;
		}
	}

function CampoOraChange(NomeCampo)
	{
	ObjCampo=document.getElementById("id"+NomeCampo+"_Ora");
	ObjCampoOre=document.getElementById("id"+NomeCampo+"_OreSelect").value;
	ObjCampoMinuti=document.getElementById("id"+NomeCampo+"_MinutiSelect").value;
	
	if (ObjCampoOre!="" && ObjCampoMinuti!="")
		{
		ObjCampo.value=ObjCampoOre+":"+ObjCampoMinuti+":00";
		}
	else
		{
		ObjCampo.value="";
		}
	}

function WdgTabs_MN(MostraId,ElencoId)
	{
	//Ciclo ElencoId con valori separati da ","
	ArrayId=ElencoId.split(",");
	for (i=0;i<ArrayId.length;i++)
		{
		NomeId=ArrayId[i];
		
		if (MostraId==NomeId)
			{
			//Linguetta e div TAB attivati
			NomeClasseLabel="WdgTabs_LabelActive";
			DisplayTab="";
			}
		else
			{
			//Linguetta e div TAB disattivati
			NomeClasseLabel="WdgTabs_Label";
			DisplayTab="none";
			}
		Obj=document.getElementById("idWdgTabs_Label_"+NomeId);
		Obj.className=NomeClasseLabel;
		Obj=document.getElementById("idWdgTabs_Tab_"+NomeId);
		Obj.style.display=DisplayTab;
		}
	}

function MapsAggiorna()
	{
	CriteriTxt="";
	IDRegione="";
	ObjRegione=document.getElementById("idMapsRegione");
	if (ObjRegione!=null)
		{
		IDRegione=ObjRegione.value;
		}
	else
		{
		IDRegione=0;
		}
	$.get("FunzioniAjax.php?Esegui=MapsAggiorna&UsaAjax=Si&IDRegione="+IDRegione,function(data)
		{
		$("#idMaps_BoxElencoDati").html(data);
		eval($("#idDatiAjaxGoogleMapsScript").html());
		});
	}

function MappaAggiornaPosizione(SKU_Mappa)
	{
	IDRegione=$("#idMapsRegione").val();
	if (IDRegione==undefined) {IDRegione=0;}
	
	$.get("FunzioniAjax.php?UsaAjax=Si&Esegui=MappaAggiornaPosizione&IDRegione="+IDRegione,function(data)
		{
		MappaTogliMarker();
		$("#boxMappaScripts").html(data); // Script che aggiorna la posizione
		MappaRecuperaDati(SKU_Mappa);
		});
	}
function MappaTogliMarker()
	{
	if (marker!="")
		{
		//Ciclo i marker e li elimino dalla cartina con il comando "setMap(null)"
		for (i in marker)
			{
			marker[i].setMap(null);
			}
		marker=[];
		}
	}

function MappaRecuperaDati(SKU_Mappa,IDCategoriaCorrente)
	{
	//if (IDCategoriaCorrente>0) {alert(IDCategoriaCorrente);}
	IDRegione=$("#idMapsRegione").val();
	if (IDRegione==undefined) {IDRegione=0;}
	$.get("FunzioniAjax.php?UsaAjax=Si&Esegui=MappaRecuperaDati&SKU_Mappa="+SKU_Mappa+"&IDRegione="+IDRegione+"&IDCategoriaCorrente="+IDCategoriaCorrente,function(data)
		{
		//alert(data); 
		$("#boxMappaElenco").html(data);
		});
	}

function MapsCreaPuntoMappa(IDOggetto,Latitudine,Longitudine,Nome,Descrizione,PathImgMarker)
	{
	latlng = new google.maps.LatLng(Latitudine,Longitudine);
	if (PathImgMarker!="")
		{
		image=PathImgMarker;
		// In caso di icona personalizzata disabilito l'animazione perchè prima appaiono le icone e poi
		//   cadono dall'alto
		animation=null;
		}
	else
		{
		image=null;
		animation=google.maps.Animation.DROP;
		}
	marker[IDOggetto] = new google.maps.Marker(
		{
		position:latlng,
		map:map,
		animation: animation,
		title:Nome,
		icon:image		
		});
	MapsCreaInfowindow(IDOggetto,marker[IDOggetto],Descrizione);
	}

function MapsCreaInfowindow(IDOggetto,marker,Descrizione)
	{
	Descrizione='<div class="mapsDataInfo" style="color:black;width:240px;height:100px;">'+Descrizione+'</div>';
	infowindow[IDOggetto]=new google.maps.InfoWindow({ content: Descrizione});
	google.maps.event.addListener(marker, 'click', function() {infowindow[IDOggetto].open(map,marker);});
	}

function MapsApriChiudiInfowindow(IDOggetto)
	{
	for (var i=1;i<infowindow.length;i++)
		{
		infowindow[i].close(map,marker[i]);
		}
	infowindow[IDOggetto].open(map,marker[IDOggetto]);
	}

function MostraAvvisoNoDownload(IDDownload)
	{
	ObjAvvisoNoDownload=document.getElementById("idAvvisoNoDownload_"+IDDownload);
	ObjAvvisoNoDownload.style.display="";
	}

function ValidaFormEC(Nome) // Usato in "Widget_EC_Login.phps"
	{
	ObjUsername=document.getElementById("idAP_Username_"+Nome);
	ObjPassword=document.getElementById("idAP_Password_"+Nome);
	
	if (ObjUsername.value=="")
		{
		alert("Il campo Login \xE8 obbligatorio");
		ObjUsername.focus();
		return false;
		}
	if (ObjPassword.value=="")
		{
		alert("Il campo Password \xE8 obbligatorio");
		ObjPassword.focus();
		return false;
		}
	ObjModulo=document.getElementById("idModuloEC_"+Nome);
	ObjModulo.submit();
	}

function KeyDown(Nome,event) //Usato in "Widget_EC_Login.phps"
	{
	var keyCode=event.which;
	if (keyCode == undefined)
		{
		keyCode = event.keyCode;
		}
	if (keyCode=="13")
		{
		ObjUsername=document.getElementById("idAP_Username_"+Nome);
		ObjPassword=document.getElementById("idAP_Password_"+Nome);
		if (ObjUsername.value!="" && ObjPassword.value=="") {ObjPassword.focus();}
		if (ObjUsername.value=="" && ObjPassword.value!="") {ObjUsername.focus();}
		if (ObjUsername.value!="" && ObjPassword.value!="") {ValidaFormEC(Nome);}
		}
	}
function InputDefaultText(idNomeCampo,Evento,TestoDefault)
	{
	// Funzione per far togliere o mettere una eventuale label messa su una casella di testo
	// Se l'utente clicca sulla casella di testo, la label sparisce
	// Se l'utente esce dalla casella di testo e questa è vuota allora ritorna la label
	if (TestoDefault!="")
		{
		if (Evento==1) //"OnClick"
			{
			//Corrisponde a
			if ($("#"+idNomeCampo).val()==TestoDefault) {$("#"+idNomeCampo).val("");}
			}
		if (Evento==0) //"OnBlur"
			{
			//Corrisponde a
			if ($("#"+idNomeCampo).val()=="") {$("#"+idNomeCampo).val(TestoDefault);}
			}
		}
	}

function JQ_ApriPoPup(idDiv,Funzione,larghezzaBox)
	{
	if (larghezzaBox=="" || larghezzaBox==undefined) {larghezzaBox=600;}
	
	// Dialog
	if (Funzione==null || Funzione=="" || Funzione==undefined)
		{
		$('#'+idDiv).dialog({
			width: larghezzaBox,
			modal: true,
			buttons: {
					"Chiudi": function() {$(this).dialog("close");}
					}
				});
		}
	else
		{
		$('#'+idDiv).dialog({
			width: larghezzaBox,
			modal: true,
			buttons: {
					"Annulla": function() {$(this).dialog("close");},
					"Ok": function() {eval(Funzione);} 
					}
				});
		}
	}

function JQ_ApriModale(Selettore,Funzione,larghezzaBox,IDLingua) // 03/11/2011 funzione che sostituisce la precedente "JQ_ApriPoPup"
	{
	if (larghezzaBox=="" || larghezzaBox==undefined) {larghezzaBox=600;}
	if (IDLingua=="" || IDLingua==undefined) {IDLingua=1;}
	
	// Dialog
	if (Funzione==null || Funzione=="" || Funzione==undefined)
		{
		$(Selettore).dialog(
			{
			width: larghezzaBox,
			modal: true
			});
		if (IDLingua==1) {$(Selettore).dialog({buttons:{Chiudi: function() {$(this).dialog("close");}}});} // Italiano
		if (IDLingua>=2) {$(Selettore).dialog({buttons:{Close: function() {$(this).dialog("close");}}});} // Inglese
		}
	else
		{
		$(Selettore).dialog({
			width: larghezzaBox,
			modal: true,
			buttons: {
					"Annulla": function() {$(this).dialog("close");},
					"Ok": function() {eval(Funzione);} 
					}
				});
		}
	}


function number_format(number,decimals,dec_point,thousands_sep)
	{
    var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
    var d = dec_point == undefined ? "." : dec_point;
    var t = thousands_sep == undefined ? "," : thousands_sep, s = n < 0 ? "-" : "";
    var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
    
    return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
	}

function ConvertToEuro(Numero)
	{
	NumeroOk=number_format(Numero,2,",",".");	
	return NumeroOk + " €";
	}

function SommaCampiText(Selettore) // 29/07/2011
	{
	var add = 0;
	$(Selettore).each(function()
		{
		Valore=$(this).val();
		//alert("Valore="+Valore);
		add += Number(Valore);
		});
	return add;
	}

function ValoreDefaultEdit(Selettore)
	{
	$(Selettore).val("");
	$(Selettore).removeClass("ValoreDefaultReset");
	$(Selettore).addClass("ValoreDefaultEdit");
	}
function ValoreDefaultReset(Selettore,ValoreDefault)
	{
	$(Selettore).val(ValoreDefault);
	$(Selettore).removeClass("ValoreDefaultEdit");
	$(Selettore).addClass("ValoreDefaultReset");
	}

function TastoKeyPress(event,Funzione,CodiceTasto,Shift) // 06/12/2011
	{
	// Funzione per catturare il tasto premuto e richiamare una funzione passando uno o più parametri
	var keyCode=event.which;
	if (keyCode == undefined)
		{
		keyCode = event.keyCode;
		}
	
	TastiAggiuntivi=true;
	if (Shift=="0" || Shift=="1")
		{
		// Shift solitamente è vuoto; se specificato significa che il codice da catturare deve verificare lo shift
		shiftPressed=event.shiftKey;
		if (shiftPressed) {TastiAggiuntivi=false;}
		}
	
	if (keyCode==CodiceTasto && TastiAggiuntivi)
		{
		return eval(Funzione);
		}
	return true;
	}

function CommentCR(Sorgente,IDOggetto)
	{
	Selettore1="#idNickname_"+IDOggetto;
	Selettore2="#idCommentText_"+IDOggetto;
	Nickname=$(Selettore1).val();
	CommentText=$(Selettore2).val();
	
	NicknamePopolato=(($(Selettore1+".ValoreDefaultEdit").length==1 && Nickname!="") || Nickname==undefined);
	CommentTextPopolato=($(Selettore2+".ValoreDefaultEdit").length==1 && CommentText!="");
	
	//alert(NicknamePopolato);alert(CommentTextPopolato);
	
	if (Sorgente==1)
		{
		$(Selettore2).click();
		$(Selettore2).focus();
		}
	else
		{
		if (!NicknamePopolato && CommentTextPopolato)
			{
			$(Selettore1).click();
			$(Selettore1).focus();
			return false;
			}
		if (NicknamePopolato && CommentTextPopolato)
			{
			// Chiamata ajax per registrare il commento
			StringaDati=$("#idStringaDati_"+IDOggetto).val();
			$.post("FunzioniAjax.php?UsaAjax=Si&Esegui=SalvaCommento&StringaDati="+StringaDati+"&Nickname="+encodeURIComponent(Nickname)+"&Commento="+encodeURIComponent(CommentText)+"",function(data)
				{
				ArrayRighe=data.split("\n");
				IDCommento=0;
				if (ArrayRighe[0]=="OK")
					{
					IDCommento=ArrayRighe[1];
					ArrayRighe.splice(0,2);
					}
				
				Struttura="";
				for (x in ArrayRighe)
					{
					Struttura+=ArrayRighe[x];
					}
				
				if (IDCommento>0)
					{
					// Se non era popolato, vado a popolare il campo Nickname
					Nickname=$("#idNickname_"+IDOggetto).val();
					if (Nickname!="")
						{
						$("#idNickname_"+IDOggetto+"_Txt").html(Nickname);
						}
					$("#idNickname_"+IDOggetto).remove();
					$(Selettore1).val("");
					$(Selettore2).val("");
					$("#idCommentList_"+IDOggetto).append(Struttura);
					$("#idCommentObject_"+IDCommento).slideDown(500);
					}
				else
					{
					alert(data);
					}
				});

			return false;
			}
		$(Selettore2).blur();
		}
	return false;
	}


function VerificaNickname(Obj,Testo)
	{
	Nickname=Obj.value;
	if (Nickname!="")
		{
		$.post("FunzioniAjax.php?UsaAjax=Si&Esegui=VerificaNickname&Nickname="+encodeURIComponent(Nickname),function(data)
			{
			if (data=="NO")
				{
				Obj.focus();
				alert(Testo);
				Obj.value="";
				}
			});
		}
	}

function BackgroundFullScreen(ElencoImg,t1,t2) // 22/12/2011 utilizza BackStretch per mettere come background immagini fullscreen 
	{
	
	var index = 0;
	//var images=["Img1.jpg","Img2.jpg"];
	images=ElencoImg.split(",");
	$(images).each(function() {$('<img/>')[0].src = this;});
	$.backstretch(images[index], {speed: 1500,centeredY:false});
	
	setInterval(function()
		{
		index = (index >= images.length - 1) ? 0 : index + 1;
		$.backstretch(images[index],{speed: 1500,centeredY:false});
		}, 6500);
	}




