function view_link(name)
{
	if(name != 'servizi_fieristici' && document.getElementById('servizi_fieristici').style.display != 'none')
	{
		document.getElementById('servizi_fieristici').style.display = 'none';
	}
	if(name != 'dopo_fiera' && document.getElementById('dopo_fiera').style.display != 'none')
	{
		document.getElementById('dopo_fiera').style.display = 'none';
	}

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

function hide_link()
{
	if(document.getElementById('servizi_fieristici').style.display != 'none')
	{
		document.getElementById('servizi_fieristici').style.display = 'none';
	}
	if(document.getElementById('dopo_fiera').style.display != 'none')
	{
		document.getElementById('dopo_fiera').style.display = 'none';
	}
}

//contaclick
function conta(id_attivita,tipologia)
{
	var jsel = document.createElement('SCRIPT');
	jsel.type = 'text/javascript';
	jsel.src = 'http://admin.abc.sm/register_visit.php?id_attivita=' + id_attivita + '&tipologia=' + tipologia;
	window.document.body.appendChild (jsel);
}

function setHeight()
			{
				tdTotalHeight = document.getElementById('right_eventi').parentNode.offsetHeight;
				tdTextHeight = 	document.getElementById('right_eventi_text').offsetHeight;
				document.getElementById('right_eventi').style.height = (tdTotalHeight + 'px');
				tdPaddingHeight = tdTotalHeight - tdTextHeight - 60;
				document.getElementById('right_eventi_padding').style.height = (tdPaddingHeight + 'px');
			}
			
function posiziona_livelli() {
	var livello_testo = document.getElementById('testo');
	var livello_posizione = document.getElementById('posizioneTesto');
	var livello_header = document.getElementById('header');
	
	livello_posizione.style.height = (livello_testo.offsetHeight) + "px";
	if(document.getElementById('popupeditorheader'))
	{
		livello_testo.style.top = (livello_header.offsetHeight + livello_posizione.offsetTop + 81) + "px";	//aggiunta altezza header rosso
	}
	else
	{
		livello_testo.style.top = (livello_header.offsetHeight + livello_posizione.offsetTop) + "px";
	}
}

function MM_openBrWindow(theURL, winName, features) 
{ //v2.0
	window.open(theURL, winName, features);
}

function showusp()
{
	var el = document.getElementById('usps');
	el.innerHTML = "";
	if(uspnum % 2) 
		el.className = "even"
	else
	  	el.className = "odd"
	el.innerHTML = usp[uspnum % 5];
	uspnum++;
	setTimeout("showusp()", 2000);
}

function countredirect()
{
	if(currentsecond !=1 )
	{
		currentsecond -= 1;
		document.redirect.redirect2.value = currentsecond;
	}
	else
	{
		window.location = targetURL;
		return;
	}
	setTimeout("countredirect()", 1000);
}

var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=&;'";

function decode64(input)
{
   var output = "";
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
   //input = input.replace(/[^A-Za-z0-9\+\/\=\']/g, "");

   do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = keyStr.indexOf(input.charAt(i++));

      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;

      output = output + String.fromCharCode(chr1);

      if (enc3 != 64) {
         output = output + String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
         output = output + String.fromCharCode(chr3);
      }
   } while (i < input.length);

   return output;
}

//calendario popup
var now = new Date();
var cal = new CalendarPopup("calendarDiv"); 
cal.setCssPrefix("CALENDAR"); 
cal.addDisabledDates(null, '2008-06-30'); 
cal.showNavigationDropdowns();

function initialize(lat, lon, map) 
{	
	if (GBrowserIsCompatible())
	{
		var map = new GMap2(document.getElementById(map), { size: new GSize(434, 300) } );
		var center = new GLatLng(lat, lon);
		map.setCenter(center, 16);
		//map.setMapType(G_SATELLITE_MAP);
		map.addControl(new GLargeMapControl());
		var mapControl = new GMapTypeControl();
		map.addControl(mapControl);
		var marker = new GMarker(center, {draggable: false});
		map.addOverlay(marker);        
	}
}

function showAddress(address, map) 
{
	var map = new GMap2(document.getElementById(map), { size: new GSize(434, 300) } );
	var geocoder = new GClientGeocoder();
	geocoder.getLatLng(address,
					   function(point) 
					   {
							if(!point) 
							{
								alert(address + " not found");
							} 
							else 
							{
								map.setCenter(point, 16);
								map.addControl(new GLargeMapControl());
								var mapControl = new GMapTypeControl();
								map.addControl(mapControl);
								var marker = new GMarker(point);
								map.addOverlay(marker);
								//marker.openInfoWindowHtml(address+"<br>"+);
							}
						}
					   );
}
			
function visualizza_mappa_initialize(lat, long)
{
	divId = document.getElementById('contenitore_mappa');	
	if(divId.style.display == 'none')
	{
		Effect.BlindDown(divId, { duration: 0.5 });
		if(document.getElementById('downmap').innerHTML=='')
		{
			initialize(lat, long, 'downmap');
		}
	}
	else
	{
		Effect.BlindUp(divId, { duration: 0.5 });	
	}
}

function visualizza_mappa_showaddress(address)
{
	divId = document.getElementById('contenitore_mappa');
	if(divId.style.display == 'none')
	{
		Effect.BlindDown(divId, { duration: 0.5 });
		if(document.getElementById('downmap').innerHTML=='')
		{
			showAddress(address, 'downmap');
		}
	}
	else
	{
		Effect.BlindUp(divId, { duration: 0.5 });	
	}
}

window.onload = function()
				{
					if(document.getElementById('googlemap'))
					{
						load(lat, long);
						showpoint(lat, long, testo);
					}
					if(document.getElementById('right_eventi'))
					{
						setHeight();	
					}
					if($('info_evento'))
					{
						var idFiera = $('info_evento').innerHTML;
						var url = 'http://www.agendafiera.com/web_services.php';
						
						var params = new Hash;
						params.set('action', 'get_singola_fiera');
						params.set('id_fiera', idFiera);
						
						new Ajax.Request(url, {
												//caricamento dei dati relativi ad una singola fiera
												method: 'post',
												contentType: 'application/x-www-form-urlencoded',
												parameters: params,
												onSuccess: function(transport) {
																				var arrayText = transport.responseText.split('|');
																				
																				$('descrizione_visualizzata').innerHTML = arrayText[0];
																				$('descrizione_visualizzata_settori').innerHTML = arrayText[1];
																			  }
											  });
					}
				}
			
window.onUnload = function()
				  {
					  if(document.getElementById('googlemap'))
					  {
						  GUnload();
					  }
				  }