//gallerie favole
function Show(img,a){
document.getElementById("bigimage").src=img;
t=document.getElementById("titolo");
t.removeChild(t.lastChild);
t.appendChild(document.createTextNode("Loading...")); 
}

function Show4(titolo){
t=document.getElementById("titolo");
t.removeChild(t.lastChild);
t.appendChild(document.createTextNode(titolo)); 
}

//galleria boschi
var crossFadeDuration = 3
var j = 0
var titoloBosco 

function Show2(img,i,tit){
document.getElementById("bigimageB").src= "immagini/layout/loading.gif";
document.getElementById("bigimageB").src=img;
document.getElementById("bigimageB").alt=tit;
document.getElementById("bigimageB").title=tit;
//document.getElementById("bigimageB").style.filter="blendTrans(duration=2)"
//document.getElementById("bigimageB").style.filter="blendTrans(duration=crossFadeDuration)"
//document.getElementById("bigimageB").filters.blendTrans.Apply() 
//document.getElementById("bigimageB").filters.blendTrans.Play()
document.getElementById("minipicsB"+i).src= "immagini/layout/empty2.gif";
t=document.getElementById("note");
t.removeChild(t.lastChild);

t.appendChild(document.createTextNode("loading..."));
j=i 
titoloBosco = tit
}


function Show3(){
if(j>0){
document.getElementById("minipicsB"+j).src= "immagini/layout/empty3.gif";
t=document.getElementById("noteB");
t.removeChild(t.lastChild);
t.appendChild(document.createTextNode(titoloBosco));
}
}

//card
function Show5(){
t=document.getElementById("noteC");
t.removeChild(t.lastChild);
t.appendChild(document.createTextNode(""));
}

//Emotics
function Emotics(smilie){
document.modulo.book_msg.value += smilie+" ";
}

//popup
function viewImg( img, autore,titolo) {
		w = window.open('','','toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=yes,copyhistory=no,width=200,height=200');	
		w.document.write( "<html><head><title>"+autore+"</title>" );
		w.document.write( "<script language='JavaScript'>\n");
		w.document.write( "function autoSize() {\n");
		w.document.write( "resizeTo(document.images[0].width+27,document.images[0].height+122)\n");
		w.document.write( "	self.focus()\n");
		w.document.write( "}\n</script>\n");
		w.document.write( "</head><body style='margin:0px:padding:0px;text-align:center;' onLoad='javascript:autoSize();'>" );
		w.document.write( "<div style='margin:0px;padding:0px;'>");
		w.document.write("<a href='javascript:top.window.close();'>");
		w.document.write(" <img src='"+img+"' border=0 alt='"+titolo+"' title='"+titolo+"' style='margin:0px:padding:2px;border:1px solid #ccc;'/></a>" );
		w.document.write( "<p style='font:11px Verdana, sans-serif;color:#999;text-align:center;margin:0px;padding:2px 2px 0px;'>Tutti i diritti riservati a<br />"+autore+"</p></div></body></html>" );
		w.document.close();
}


function select_all(obj,nome){
  var ff = document.corsi;
	/*se selezionato*/
	if(obj.checked){
		for (var i=0;i<ff.elements.length;i++) {	
			el = ff.elements[i];	
			if (el.type=="checkbox" && el.name== nome && el.value != 0) {
			  el.checked = true ;
			  el.disabled = true;			
			}
		}
	/*se nn è selezionato*/
	}else{
		for (var i=0;i<ff.elements.length;i++) {	
			el = ff.elements[i];	
			if ((el.type=="checkbox") && (el.name== nome) && (el.value != 0)) {
				el.disabled = false;	
				el.checked = false ;		
			}
		}
	}
}
var map = null;
var geocoder = null;
var html;

var illAr = new Array();
var latAr = new Array();
var lngAr = new Array();
var dirAr = new Array();
var sitAr = new Array();
var emaAr = new Array();
var drIAr = new Array();


function prendiElementoDaId(id_elemento) {

 var elemento;
 if(document.getElementById)
  elemento = document.getElementById(id_elemento);
 else
  elemento = document.all[id_elemento];

  return elemento;
}


function assegnaXMLHttpRequest() {
	var	XHR = null;
	var browserUtente = navigator.userAgent.toUpperCase();


	if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object")
		XHR = new XMLHttpRequest();

	else if(window.ActiveXObject &&	browserUtente.indexOf("MSIE 4") < 0 ) {
	
		if(browserUtente.indexOf("MSIE 5") < 0)
			XHR = new ActiveXObject("Msxml2.XMLHTTP");
		else
			XHR = new ActiveXObject("Microsoft.XMLHTTP");
	}

	return XHR;
}

function caricaIll(marker,nomeFile) {
	// variabili di funzione
	var	ajax = assegnaXMLHttpRequest();
	var elemento = prendiElementoDaId("contenuto-dinamico");
	var response = "";
	// se l'oggetto XMLHttpRequest non è nullo
	if(ajax) {

		// impostazione richiesta asincrona in GET
		// del file specificato
		ajax.open("get", nomeFile);

		// rimozione dell'header "connection" come "keep alive"
		ajax.setRequestHeader("connection", "close");

		
		// impostazione controllo e stato della richiesta
		ajax.onreadystatechange = function() {	  
		// verifica dello stato
			if(ajax.readyState === 4) {
			// verifica della risposta da parte del server
			if(ajax.status == 200){
				 // operazione avvenuta con successo
				marker.openInfoWindowHtml( ajax.responseText);	
				 
			}else {
				  // errore di caricamento
				 // marker.openInfoWindowHtml( "Impossibile effettuare l'operazione richiesta.<br />Errore riscontrato: " + ajax.status);
				 
			}
		} 	
	}

		// invio richiesta
		ajax.send(null);
	}else{
		alert("non esiste l'oggetto");
	}

	return response;
} 




//inserisco i dati in un array
function pushArrayGeo(lat,lng,ill){
	latAr.push(lat);
	lngAr.push(lng);
}
//una volta caricata la pagina scrolla l'array e creo i marker
function scrollArrayGeo(){
	for(var i=0;i<latAr.length;i++){
		showMarker(latAr[i],lngAr[i]);
	}
}
function showMarker(lat,lng){
	var point = new GLatLng(lat,lng);
	if(point){
		map.addControl(new GMapTypeControl());		
		// Crea il marker
		createMark(point);
	}else{
		alert(map);
	}
}

function loadImg(nomeFile2,ico){
var	ajax = assegnaXMLHttpRequest();
	// se l'oggetto XMLHttpRequest non è nullo
	if(ajax) {
		// impostazione richiesta asincrona in GET
		// del file specificato
		ajax.open("get", nomeFile2);

		// rimozione dell'header "connection" come "keep alive"
		ajax.setRequestHeader("connection", "close");
		
		// impostazione controllo e stato della richiesta
		ajax.onreadystatechange = function() {	  
		// verifica dello stato
			if(ajax.readyState === 4) {
			// verifica della risposta da parte del server
				if(ajax.status == 200){
					 // operazione avvenuta con successo
					
					ico.image = ajax.responseText;	
					ico.iconSize = new GSize(20, 20);
					ico.iconAnchor = new GPoint(10, 10);
					ico.infoWindowAnchor = new GPoint(10, 10); 
				}else {
					  // errore di caricamento
					  //alert("Impossibile effettuare l'operazione richiesta.<br />Errore riscontrato: " + ajax.status);
					 
				}
			}
		} 	
		// invio richiesta
		ajax.send(null);
	}else{
		alert("non esiste l'oggetto");
	}
}

function createMark(point){
	var lat2 = point.lat();
	var lng2 = point.lng();
	var nomeFile2 = "ajax.php?lat="+lat2+"&lng="+lng2+"&A";		
	
	var ico = new GIcon();	
	var aja = loadImg(nomeFile2,ico);
	var marker = new GMarker(point);
	GEvent.addListener(marker, "click", function() {
		var lat = point.lat();
		var lng = point.lng();
		var nomeFile = "ajax.php?lat="+lat+"&lng="+lng;
		caricaIll(marker,nomeFile);
			
			
	});
	
	map.addOverlay(marker);
	
	
}


	  
window.onunload = function () {
GUnload();
}




window.onload=function(){
	if(document.corsi){
		var ff = document.corsi;
		for (var i=0;i<ff.elements.length;i++) {	
   			el = ff.elements[i];	
			if (el.type=="checkbox" && el.value == 0) {
			 select_all(el,el.name);		
 			}
		}
	}
	var go =false;
	if (document.getElementById){
		if(document.getElementById("map")) go = true;
	}
	if (document.all){
		if(document.all("map")) go = true;
	}
	if (document.layers){
		if(document.layers("map")) go = true;
	}
	if(go && GBrowserIsCompatible()) {


	map = new GMap2(document.getElementById("map"));
	/*mappa - satellite - ibrida */
	map.addControl(new GMapTypeControl());
	/*controller con barra vert*/
	map.addControl(new GLargeMapControl());		
	/*zoom box, in basso a dx*/
	map.addControl(new GOverviewMapControl(),
	new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(9, 9)));	
	/*COORDINATE DI PARTENZA DELLA MAPPA*/
	map.setCenter(new GLatLng(41.90, 12.49), 1);
	map.enableDoubleClickZoom();
	geocoder = new GClientGeocoder();	
	scrollArrayGeo();
		
	}else if(document.getElementById("map")){
	alert("Le api di google non sono compatibili coni l tuo browser");
	}
	
	
	
}