// visualizza i banner pubblicitari
var adv = new Array(
	"mynav.gif|http://www.mynav.it",
	"mirkocavalleri.gif|guidenaturalistiche/mirkocavalleri/index.htm",
	"robertopockaj.gif|guidenaturalistiche/robertopockaj/index.htm",
	"marcogrillo.gif|guidenaturalistiche/marcogrillo/index.htm",
	"genova.gif|http://www.rifugiogenova.it",
	"lostedoc.gif|",
	"montenebius.gif|http://www.naturavventura.com/docs/hotel/proposte/proposte.php?lang=it",
	"naturavventura.gif|http://www.naturavventura.com/docs/accomp/guida/guida.php?lang=it",
	"questa.gif|http://www.rifugioquesta.it",
	"albergoitalia.gif|http://www.albergoitaliaormea.it",
	"slowtourist.gif|http://www.slowtourist.com",
	"traccenatura.gif|http://www.accompagnatorinaturalistici.it",
	"rifugiovalasco.gif|http://www.rifugiovalasco.it",
	"occelli.gif|http://www.valcasotto.it",
	"garessio2000.gif|http://www.garessio2000.it"
	);

function setAdv( key, flag )
{
	if( key == "random" )
		idx = randAdv();
	else
		idx = matchAdv( key );
	
	if( idx == -1 ) // match not found
		return;

	buf = adv[idx].split("|");
	img = buf[0];
	lnk = buf[1];

	// get path
	switch( flag )
	{
		case 0: //home
			path2root="";
			break;
		case 1: case 2: //elenco itinerari o scheda itinerario
			path2root="../../";
			break;
		case 3:			//elenco servizi o guide naturalistiche
			path2root="../";
			break;
		default:
			alert("wrong flag");
	}

	// get target		
	if( lnk.search("http://" ) == -1 && lnk.search("//localhost") == -1 ) // local url
	{
		target = "_top";
		redirUrl = '../'+lnk;
	}
	else	// remote url
	{
		target = "_blank";
		redirUrl = lnk;  // redirection always called by php from the "count" dir
	}

	// set image and link	
	txt = '<div class="tabadvimg">';
	if( lnk == "" )
	{
		// just an image
		txt += '<img src="'+path2root+'biz/imgadv/'+img+'" border="0">';
	}
	else
	{
		// form
		style = "margin:0px;padding:0px;";
		txt += '<center><form name="form'+idx+'" action="'+path2root+'count/advcnt.php" method="post" target="'+target+'" style="'+style+'">\n';
		txt += '<input type="image" src="'+path2root+'biz/imgadv/'+img+'" title="" alt="" border="0" onMouseOver="this.style.cursor=\'pointer\';" OnMouseOut="this.style.cursor=\'auto\';" onClick="javascript: submit();return false;">\n';
		txt += '<input type="hidden" name="id" value="'+img+'">\n';
		txt += '<input type="hidden" name="lnk" value="'+redirUrl+'">\n';
		txt += '</form></center>';

		}
	txt += '</div>';
	document.write( txt );
}

function matchAdv( key )
{
	for( i=0; i<adv.length; i++ )
	{
		buf = adv[i].split("|");
		img = buf[0];
		if( img.search( key ) != -1 )
			return i;
	}
	return -1;
}

function randAdv()
{
	return( 0 );
	rand = Math.random();
	rand *= (adv.length-0.0001);
	rand = Math.floor( rand );
	return rand;
}

/*
function Vote()
{
	rand = Math.random();
	rand *= (6-0.0001);
	rand = Math.floor( rand );
	
	switch( rand )
	{
		case 0:
			url = "http://rete.comuni-italiani.it/foto/2008/81080";
			break;
		case 1:
			url = "http://rete.comuni-italiani.it/foto/2008/81154";
			break;
		case 2:
			url = "http://rete.comuni-italiani.it/foto/2008/81080";
			break;
		case 3:
			url = "http://rete.comuni-italiani.it/foto/2008/81154";
			break;
		case 4:
			url = "http://rete.comuni-italiani.it/foto/2008/81080";
			break;
		case 5:
			url = "http://rete.comuni-italiani.it/foto/2008/81154";
			break;
		default:
			url = "http://rete.comuni-italiani.it/foto/2008/81080";
	}

	text = '<a href="'+url+'" target="_blank"><img src="img/vota120.jpg" border="0" title="Vota la foto!" alt="Vota la foto!"></a>';
	document.write( text );
}
*/