var map;
var POI_id = new Array();
var POI_nome = new Object();
var POI_citta = new Array();
var POI_url = new Array();
var POI_lon = new Array();
var POI_lat = new Array();
var POI_descriz = new Array();
var POI_tipo = new Array();
var POI_tipo_leg = new Array();
var POI_video = new Array();
var POI_img = new Array();
var POI_main = null;
var POI_calc_perc = new Array();
var MY_mapControl;
var My_mapOverview;
var Markers_display_status = new Array();
var creteGmarkers = [];
var cretePolyline = [];
var map_status;
var MY_percorsi = new Array();
var main_domain = "www.eutoscana.it";
var capture_command = '';
var creteIcon = new Array();
var VAR_PTS = new Array();
var ALL_POI_remove = '';
var MY_maptype = '';
var BCC_asciano = '';

var var_loaded = 0;

var bounds = new GLatLngBounds();

var	logo_cretesenesi;

function include(script_filename) {
    //script_filename += '?' + Math.random(0, 1000) + '=' + Math.random(0, 1000);
    var html_doc = document.getElementsByTagName('head').item(0);
    var js = document.createElement('script');
    js.setAttribute('language', 'javascript');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', '/poi.js?js=js&'+script_filename);
    html_doc.appendChild(js);
}

function wheelevent(e){ 
	if(true){//document.getElementById("prevent").checked 
		if(!e){
			e = window.event;
		}
		if(e.preventDefault){
			e.preventDefault();
		}
		e.returnValue = false; 
	}
} 

function initialize(){
	/*var form_cerca_tipo = document.form_cerca.tipo;
	var form_cerca_cat = document.form_cerca.cat;
	if(form_cerca_tipo.options[form_cerca_tipo.selectedIndex].value != ''){
		select_tipologie(form_cerca_cat,form_cerca_tipo.options[form_cerca_tipo.selectedIndex].value);
	}*/
	/*FEED_loadStars();*/
	include(include_js_poi);
	init_map_load();
  //initLightbox();
}

function capture_command_fnc(){
	if(capture_command!=''){
	  
		eval(capture_command);
		capture_command = '';
	}
}

function init_map_load(){
	if(GBrowserIsCompatible()){
		map = new GMap2(document.getElementById("map"));
		map.setCenter(new GLatLng(open_lat, open_lon), open_zoom);
		//map.enableScrollWheelZoom();
		//GEvent.addDomListener(map.getContainer(), "DOMMouseScroll", wheelevent);
		//map.getContainer().onmousewheel = wheelevent;
		var CopyrightDiv = document.getElementById("map").firstChild.nextSibling;
		var CopyrightImg = document.getElementById("map").firstChild.nextSibling.nextSibling;
		CopyrightDiv.style.display = "none"; 
		CopyrightImg.style.display = "none";
		document.getElementById("map_over").innerHTML = '<a href="#mappa" onclick="zoom_map();"><img src="/images/snap.gif" border="0" alt="Zoom Mappa" /></a>';
		document.getElementById("map_over").style.background = 'transparent'; 
		
		//map.setMapType(G_NORMAL_M);
		// G_SATELLITE_MAP G_HYBRID_MAP 

		capture_command_fnc();

		logo_cretesenesi =	new GScreenOverlay('/images/map_logo.png',
				new GScreenPoint(0, 0, 'pixels', 'fraction'),  // screenXY
				new GScreenPoint(-110, -500),  // overlayXY
				new GScreenSize(100, 68)  // size on screen
			 );

	}
}


function centerMap(lat,lon){
	if(window.map){
		if(map.getZoom() > 8){
			map.panTo(new GLatLng(lat,lon), map.getZoom());
		}else{
			map.setCenter(new GLatLng(lat,lon), map.getZoom());
		}
	}
}

function zoom_on(i){
	if(!window.map || var_loaded==0){ capture_command = "zoom_on("+i+");"; }

	if(window.map && var_loaded==1){
		zoom_map();
		centerMap(POI_lon[i],POI_lat[i]);
		GEvent.trigger(creteGmarkers[i], "click");
	}
}

function special_zoom_on(special){
	if(!window.map || var_loaded==0){ capture_command = "special_zoom_on("+special+");"; }

	if(window.map && var_loaded==1){
		ALL_POI_remove = 'remove';
		map.clearOverlays();
		zoom_map();
		
		var myIcon = new GIcon();
		myIcon.iconSize = new GSize(40,27);
		myIcon.iconAnchor = new GPoint(10,10);
		myIcon.infoWindowAnchor = new GPoint(10,20);
		myIcon.image = 'http://www.cretesenesi.com/icone/cretesenesi.png'; 

		markerOptions = { icon:myIcon };
		
		var point = new GLatLng(43.2121, 11.5391);
		map.addOverlay(new GMarker(point, markerOptions));

		if(special == 'italy'){
			map.setCenter(new GLatLng(open_lat,open_lon), 6);
		}else if(special == 'tuscany'){
			map.setCenter(new GLatLng(open_lat,open_lon), 8);
		}else if(special == 'siena'){
			map.setCenter(new GLatLng(open_lat,open_lon), 10);
		}
		ALL_POI_remove = '';
	}
}

function zoom_map(){
	if(!window.map || var_loaded==0){ capture_command = "zoom_map();"; }

	if(window.map && var_loaded==1){
		var center = map.getCenter(); 
		var this_lat = center.lat();
		var this_lng = center.lng();

		document.getElementById("map").style.width='1002px';
		document.getElementById("map").style.height='500px';
		
		document.getElementById("extra").style.marginTop='520px';

		document.getElementById("wrapper").style.marginTop='520px';

		document.getElementById('map_open').style.display='none';
		document.getElementById('map_close').style.display='block';
		document.getElementById('map_over').style.display='none';

		if(MY_maptype == 'hybrid'){
			map.setMapType(G_HYBRID_MAP);
		}
		
		map.checkResize();
		centerMap(this_lat,this_lng);
		
		MY_mapControl = new GSmallMapControl();
		My_mapOverview = new GOverviewMapControl();
		MY_mapControl_pos = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(30,10)); 

		map.addControl(MY_mapControl,MY_mapControl_pos);
		map.addControl(My_mapOverview);


		//map.addOverlay(logo_cretesenesi);

		if(ALL_POI_remove == ''){
			viewPOI();
		}

		var CopyrightImg = document.getElementById("map").firstChild.nextSibling.nextSibling;
		CopyrightImg.style.display = "block";
		//map.Gsize(1002,500);
		map_status = 'zoom';

		//if(POI_main != null){
		//	for(var i=0;i<POI_nome.length;i++){
		//		if(POI_main != i){
		//			calcola_percorso(POI_lon[POI_main]+','+POI_lat[POI_main] , POI_lon[i]+','+POI_lat[i] , '');
		//		}
		//	}
		//}
	
	}
}

function zoom_close(){
	var center = map.getCenter(); 
	var this_lat = center.lat();
	var this_lng = center.lng();

	document.getElementById("extra").style.marginTop='270px';
	document.getElementById("wrapper").style.marginTop='0';
	document.getElementById('map').style.width='250px';
	document.getElementById('map').style.height='250px';
	document.getElementById('map').style.marginLeft='0';
	document.getElementById('map_close').style.display='none';
	document.getElementById('map_open').style.display='block';
	document.getElementById('map_over').style.display='block';
	map.checkResize();
	map.removeControl(MY_mapControl);
	map.removeControl(My_mapOverview);
	map.clearOverlays();
	centerMap(this_lat,this_lng);
	var CopyrightImg = document.getElementById("map").firstChild.nextSibling.nextSibling;
	CopyrightImg.style.display = "none";
	map_status = 'close';
}

// Calcola un percorso stradale calcola_percorso('Asciano','Siena','');
var gdir_i = 0;;
var this_gdir = new Array();


print_r = function(a, dTab) {
//initiate the return variable
var ret = "";

//the depth tabbing variable helps in indentation
if(!dTab) dTab = "\t";

//If the input variable is a collection object then iterate
if(typeof(a) == 'object'){

//foreach implementation in javascript
for(var sub in a) {
var val = a[sub];
ret += "'" + sub + "' =>";

//incase the value obtained is again a collection
if(typeof(val) == 'object') {

//drill it down by calling the print_r function recurrsively
ret += "\n" + dTab + "[" + print_r(val, dTab + "\t") + "]\n" + (dTab.substring(0, (dTab.length-1)));
} else {
ret += " \"" + val + "\"";
}
}
} else {
//Not a collection
ret = "'" + a + "' is of type '" + typeof(a) + "', not array/object.";
}
return ret;
}


function calcola_percorso(from,to,punti){
	this_gdir++;
	var gdir = this_gdir[gdir_i] = new GDirections();

	GEvent.addListener(gdir, "load", onGDirectionsLoad);
	GEvent.addListener(gdir, "error", handleErrors);
	
	if(punti != ''){
		gdir.loadFromWaypoints(punti, { "locale": "it_IT", "getPolyline": true, "getSteps" : true});
	}else if(from != null && to != null){
		gdir.load("from: " + from + " to: " + to, { "locale": "it_IT", "getPolyline": true, "getSteps" : true});
	}

	function handleErrors(){
		if(gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS){
			alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
		}else if(gdir.getStatus().code == G_GEO_SERVER_ERROR){
			alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
		}else if(gdir.getStatus().code == G_GEO_MISSING_QUERY){
			alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
		}else if(gdir.getStatus().code == G_GEO_BAD_KEY){
			alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);
		}else if(gdir.getStatus().code == G_GEO_BAD_REQUEST){
			//alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
		}else{
			alert("An unknown error occurred.");
		}
	}

	function onGDirectionsLoad(){ 
		var description = '';
		var this_percorso = gdir.getPolyline();
		var this_distanza = parseInt(gdir.getDistance().meters)/1000;
		map.addOverlay(this_percorso);
		document.getElementById('map_legenda').innerHTML = 'Distanza » '+gdir.getSummaryHtml()+' ' + document.getElementById('map_legenda').innerHTML;

		for(var x=0; x<gdir.getNumRoutes(); x++){
			var groute = gdir.getRoute(x); 
			for ( var i=0; i < groute.getNumSteps(); i++ ) { 
				var step = groute.getStep(i); 
				var this_description = step.getDescriptionHtml();
				if(this_description.length > 6){
					description += '» ' + (i+x+1) + ' - ' + this_description + '<br />'; 
				}
			} 
		}

		document.getElementById('map_directions').innerHTML = '<strong>IL PERCORSO</strong><br /></br />' + description;
		document.getElementById('map_directions').style.display='block';
		document.getElementById('map').style.width='700px';
		document.getElementById('map').style.marginLeft='300px';


		
		//var bounds = gdir.getBounds(); 
	    //map.setCenter(bounds.getCenter(),map.getBoundsZoomLevel(bounds)); 
		gdir.clear();
		//alert('Distanza: '+this_distanza+' km')
	}
}

function create_icon(){
	var this_icon_name;
	var myIconName = new Array("baseIcon","bcc","az1","az4","sva1","sva2","sva3","sva4","sva5","sva6","sva7","osp1","osp2","osp3","osp4","osp5","osp8","vis1","vis2","vis3","vis4","vis5","vis6","vis7","vis8","vis9","vis10","vis11","snap2");
	for (k in myIconName){
		this_icon_name = myIconName[k];
		creteIcon[this_icon_name] = new GIcon();
		creteIcon[this_icon_name].iconSize = new GSize(20,20);
		creteIcon[this_icon_name].iconAnchor = new GPoint(10,10);
		creteIcon[this_icon_name].infoWindowAnchor = new GPoint(10,20);
		creteIcon[this_icon_name].image = "/icone/"+this_icon_name+'.png'; 
	}
}




function viewPOI(){
	var first_time_create_icon;
	var previousCenterPoint;
	var previousZoom;
	var map_legenda = new Object();
	swfobject.embedSWF("/flash/FlowPlayer.swf", "FlowPlayer", "250", "200", "9.0.0", "/flash/expressInstall.swf");
	//var flash = new SWFObject("/flash/FlowPlayer.swf", "FlowPlayer", "250", "200", "7", "#ffffff", true);

	if(first_time_create_icon != 1){
		create_icon();
		first_time_create_icon = 1;
	}

	function createMarker(point, i) {

		var this_point_icon = POI_tipo[i];
		if(creteIcon[this_point_icon]){
			markerOptions = { icon:creteIcon[this_point_icon],title:POI_nome[i], zIndexProcess:orderOfCreation };
			map_legenda[this_point_icon] = '<a href="#mappa" onclick="markers_view_hide(\''+POI_tipo[i]+'\');"><img name="img_'+POI_tipo[i]+'" src="/icone/'+this_point_icon+'.png" border="0" align="absmiddle" alt="hide/display" /></a> '+POI_tipo_leg[i]+' ';
		}else{
			markerOptions = { icon:creteIcon['baseIcon'],title:POI_nome[i], zIndexProcess:orderOfCreation };
			map_legenda['baseIcon'] = '<img src="/icone/baseIcon.png" border="0" align="absmiddle" alt="" /> '+POI_tipo_leg[i]+' ';
		}

		function orderOfCreation(marker,b) {
			return 1;
		}

		var marker = new GMarker(point,markerOptions);
		marker.value = i;

		/*immagine_temp = document.createElement("IMG")
		immagine_temp.setAttribute("src","/phpThumb/phpThumb.php?far=c&h=200&wp=250&src="+POI_img[i]+"")
		immagine_temp.setAttribute("alt","Preview")


		var tooltip = new Tooltip(marker,immagine_temp,4);
		marker.tooltip = tooltip;
		map.addOverlay(marker.tooltip);

		GEvent.addListener(marker,'mouseover',function(){
			this.tooltip.show();
		});
		GEvent.addListener(marker,'mouseout',function(){
			this.tooltip.hide();
		});*/

		GEvent.addListener(marker, "click", function() {

			var this_img = '<a href="'+POI_url[i]+'"><img src="/phpThumb/phpThumb.php?far=c&amp;h=200&amp;wp=250&amp;src='+POI_img[i]+'" style="border:1px solid #ccc; display:inline; margin-left:5px; margin-right:5px;" border="0" /></a>';

			if(parseInt(POI_id[i])>0){
				this_preferiti = '<br><img src="/images/favorite.png" align="left" border="0" />&nbsp;&nbsp;<a href="#mappa" onclick="AJAX_loadXMLDoc(\'/preferiti.php?act=add&view='+POI_tipo[i]+'&id='+POI_id[i]+'\',\'preferiti\')">Aggiungi ai punti preferiti</a>';
			}else{
				this_preferiti = '';
			}

			if(POI_url[i] != '#'){
				var collegamento = '<a href="'+POI_url[i]+'">Visualizza </a>';
			}else{
				var collegamento = '';
			}
	
			var tab1 = new GInfoWindowTab("In Sintesi", '<div id="infowindow_tab1" class="bubble"><b>'+POI_nome[i]+'</b><br/><br/>'+POI_citta[i]+'<br/><br/>'+POI_descriz[i]+'...<br /><br /><p style="text-align:right"><img src="/images/entra.png" align="right" border="0" /> '+collegamento+'</p>'+this_preferiti+'</div>');
			var tab2 = new GInfoWindowTab("GeoSat", '<div id="detailmap"></div>');
			var tab3 = new GInfoWindowTab("Video", '<div id="flashvideo">Video</div>');
			var tab4 = new GInfoWindowTab("Immagini", '<div id="imgmap">'+this_img+'</div>');
			
			if(POI_video[i]!='' && POI_video[i]!=null){
				var infoTabs = [tab1,tab3,tab2];
			}else if(POI_img[i]!='' && POI_img[i]!=null){
				var infoTabs = [tab1,tab4,tab2];
			}else {
				var infoTabs = [tab1,tab2];
			}
			marker.openInfoWindowTabsHtml(infoTabs,{suppressMapPan:true,noCloseOnClick:true});

			if(POI_video[i]!='' && POI_video[i]!=null){
				flash.addParam("allowScriptAccess", "always");
				flash.addVariable("config", "{playList:[{url:'/video/"+POI_video[i]+"'}],hideControls:true,loop:false,autoPlay:true,autoBuffering:true,initialScale:'scale'}");
				flash.write("flashvideo");
			}

			var dMapDiv = document.getElementById("detailmap");
			var detailmap = new GMap2(dMapDiv);
			detailmap.setCenter(point , 16);
			detailmap.addControl(new GSmallZoomControl());
			detailmap.setMapType(G_SATELLITE_MAP);
			
			
			// G_SATELLITE_MAP G_HYBRID_MAP 
			markerOptions_detailmap = { icon:creteIcon['snap2'] };
			var point_detailmap = new GLatLng(POI_lon[i],POI_lat[i]);
			detailmap.addOverlay(new GMarker(point_detailmap, markerOptions_detailmap));


			var CopyrightDiv = dMapDiv.firstChild.nextSibling;
			var CopyrightImg = dMapDiv.firstChild.nextSibling.nextSibling;
			CopyrightDiv.style.display = "none"; 
			CopyrightImg.style.display = "none";

			previousCenterPoint = map.getCenter() ;
			previousZoom = map.getZoom() ; 

			//map.savePosition(); 
            //Got this code from Mike: 
 			function subGPoints(a,b) { 
			//returns the distance in pixels between point a and b 
	            return new GPoint(a.x-b.x, a.y-b.y); 
			} 

			//Pixel distance to the center of the map 
			var CDivPixel = map.fromLatLngToDivPixel(map.getCenter()); 
			//Pixel distance from the marker point 
			var pointDivPixel = map.fromLatLngToDivPixel(point); 
			//Difference between the above mentioned distances 
			var fromCenter = subGPoints(pointDivPixel, CDivPixel); 

			//Pan to the corrected location (the -40 and +215 sizes are the distances from my marker to the center of the infowindow 
			map.panBy(new GSize(-fromCenter.x-40,-fromCenter.y+150)) 
		});


		GEvent.addListener(map, "infowindowclose", function() {
			//map.panTo(new GLatLng(previousCenterPoint), previousZoom); 
        }); 

		creteGmarkers[i] = marker;

		bounds.extend(marker.getPoint());

		return marker;
	}

	for (i in POI_nome){
		var point = new GLatLng(POI_lon[i],POI_lat[i]);
		map.addOverlay(createMarker(point, i));
	}

	var map_legenda_write = '';
	var count_legenda = 0;

	for ( keyVar in map_legenda ) {
		if(POI_tipo[POI_main] != keyVar){
			map_legenda_write += map_legenda[keyVar];
			count_legenda++;
		}
	}

	if(POI_calc_perc['from'] != '' && POI_calc_perc['from'] != null){
		calcola_percorso(POI_calc_perc['from'],POI_calc_perc['to'],'');
	}

	if(count_legenda>0){
		document.getElementById('map_legenda').innerHTML = 'Visualizza » '+map_legenda_write+'';
	}


	if(MY_percorsi.length > 0){
		view_percorsi();
	}

	// BANCASCIANO fUNCTION

	if(BCC_asciano != 1){
		markers_view_hide('bcc','view');
	}
	//map.setZoom(map.getBoundsZoomLevel(bounds));
    //map.setCenter(bounds.getCenter());

}

var AJAX_req;
var AJAX_id_elem;

function AJAX_loadXMLDoc(url,element_id){
   var rand_no = Math.random();
   AJAX_id_elem = element_id;
   var url = url+"&daterand="+rand_no;
   try { AJAX_req = new ActiveXObject("Msxml2.XMLHTTP"); }
   catch(e) {
      try { AJAX_req = new ActiveXObject("Microsoft.XMLHTTP"); }
      catch(oc) { AJAX_req = null; }
   }
   if (!AJAX_req && typeof XMLHttpRequest != "undefined") { AJAX_req = new XMLHttpRequest(); }
   if (AJAX_req != null) {
      AJAX_req.onreadystatechange = AJAX_ok;
      AJAX_req.open("GET", url, true);
      AJAX_req.send(null);
   }
}
function AJAX_ok() {
   if (AJAX_req.readyState == 4 && AJAX_req.status == 200) {
	   var response = AJAX_req.responseText;
	  if(response.length > 10){
	      document.getElementById(AJAX_id_elem).innerHTML = response;
		  document.getElementById(AJAX_id_elem).style.display='block';
	  }else{
	      document.getElementById(AJAX_id_elem).innerHTML = '';
		  document.getElementById(AJAX_id_elem).style.display='none';
	  }
   }
}

function remove_preferito(url,element_id){
	if(confirm('Rimuovere dai preferiti?')){
		AJAX_loadXMLDoc(url,element_id);
	}
}

function markers_view_hide(tipo,method){
	var img = 'img_'+tipo;
	for (i in POI_tipo){
		if(POI_tipo[i] == tipo){
			if(Markers_display_status[i] == 'hide' || method == 'view'){
				creteGmarkers[i].show();
				document.images[img].style.MozOpacity=1;
				document.images[img].style.filter = "Alpha(Opacity=100)";  
				Markers_display_status[i] = 'view';
			}else{
				creteGmarkers[i].hide();
				document.images[img].style.MozOpacity=0.4;
				document.images[img].style.filter = "Alpha(Opacity=40)";  
				Markers_display_status[i] = 'hide';
			}
		}
	}
}

function banner_bcc(){
	if(!window.map){ capture_command = "banner_bcc();"; }

	if(window.map){
		if(map_status != 'zoom'){
			zoom_map();
		}
		markers_view_hide('bcc','view');
		//map.setZoom(parseInt(11)) 
	}
}

function view_percorsi(){
	for (r in MY_percorsi){
		if(MY_percorsi[r].indexOf('kml')>-1){
			var kml = new GGeoXml("http://www.cretesenesi.com/percorsi/"+MY_percorsi[r]);
			map.addOverlay(kml);
		}else{
			trk1 = new Array();
			trk1.push (new GPolyline(VAR_PTS[MY_percorsi[r]],"#CC0000",3,0.8));
			map.addOverlay(trk1[trk1.length-1]);
			//var kml = new GGeoXml("http://www.cretesenesi.com/percorsi.php?id="+MY_percorsi[r]);
			//map.addOverlay(kml);
		}
	}
}

function adv_search(){
	if(document.getElementById('adv_search').style.display=='block'){
		document.getElementById('adv_search').style.display='none';
	}else{
		document.getElementById('adv_search').style.display='block';
	}
}

function menu_collapse(ID){
	var all = Array('menu_ospitalita','menu_visitare','menu_dove','menu_svago','menu_entert','menu_az','menu_track');
	for(var i=0; i<7; i++){
		if(ID != all[i]){
			document.getElementById(all[i]).style.display='none';
		}
	}

	if(document.getElementById(ID).style.display=='block'){
		document.getElementById(ID).style.display='none';
	}else{
		document.getElementById(ID).style.display='block';
	}
}

var elementi_select = new Object(

{text:"Tutte le categorie", value:"", indicatore:"1"},
{text:"1 Spiga", value:"1", indicatore:"1"},
{text:"2 Spighe", value:"2", indicatore:"1"},
{text:"3 Spighe", value:"3", indicatore:"1"},

{text:"Tutte le categorie", value:"", indicatore:"2"},
{text:"3° Categoria", value:"3", indicatore:"2"},
{text:"2° Categoria", value:"2", indicatore:"2"},
{text:"1° Categoria", value:"1", indicatore:"2"},

{text:"Tutte le categorie", value:"", indicatore:"3"},
{text:"1 Stella", value:"1", indicatore:"3"},
{text:"2 Stelle", value:"2", indicatore:"3"},
{text:"3 Stelle", value:"3", indicatore:"3"},
{text:"4 Stelle", value:"4", indicatore:"3"},
{text:"5 Stelle", value:"5", indicatore:"3"},

{text:"Tutte le categorie", value:"", indicatore:"4"},
{text:"3° Categoria", value:"3", indicatore:"4"},
{text:"2° Categoria", value:"2", indicatore:"4"},
{text:"1° Categoria", value:"1", indicatore:"4"},

{text:"Tutte le categorie", value:"", indicatore:"5"},
{text:"3° Categoria", value:"3", indicatore:"5"},
{text:"2° Categoria", value:"2", indicatore:"5"},
{text:"1° Categoria", value:"1", indicatore:"5"},

{text:"Tutte le categorie", value:"", indicatore:"8"},
{text:"2 Chiavi", value:"2", indicatore:"8"},
{text:"3 Chiavi", value:"3", indicatore:"8"},
{text:"4 Chiavi", value:"4", indicatore:"8"}

);

function select_tipologie(el, val){
	var k=0;
	var check = 0;
	
	var actual = el.options[el.selectedIndex].value

	for(j=0; j<elementi_select.length; j++){
		if(elementi_select[j].indicatore==val){
			var check = 1;
			el.options[k]=new Option(elementi_select[j].text, elementi_select[j].value);
			if(elementi_select[j].value == actual){
				el.options[k].selected = true;
			}
			k++;
		}
	}

	el.options.length=k;  

	if(check == 0){
		el.options[0]=new Option('Tutte le categorie', '');
		el.disabled = true;
	}else{
		el.disabled = false;
	}
}

function popup(titolo_finestra, website, lunghezza, altezza){
	var windowprops='width='+lunghezza+',height='+altezza+',scrollbars=yes,status=no,resizable=yes,location=no'
	var leftdist = 50;   
	var topdist = 50; 
	window.open(website,titolo_finestra,"left=" + leftdist + ",top=" + topdist +","+ windowprops);
}

function ajax_select_osp(mode,tot){
	if(mode == 'view'){
		for(var i=1;i<=tot;i++){
			document.getElementById('osp_pref_'+i).style.background = '#ccc';
		}
	}else{
		for(var i=1;i<=tot;i++){
			document.getElementById('osp_pref_'+i).style.background = '#eeeddb';
		}
	}
}

function check_cerca_form(field){
	var campo = document.form_cerca.elements[field];
	if(campo.checked == true){
		campo.checked = false;
	}else{
		campo.checked = true;	
	}
}