// gestione schede itinerario

function skipTag( str )
{
	var tmp = str;
	str = "";
	offTagFlag = 1;
	for( i=0; i<tmp.length; i++ )
	{
		if( tmp.charAt(i) == '<' )
			offTagFlag = 0;
		if( tmp.charAt(i-1) == '>' )
			offTagFlag = 1;
		if( offTagFlag == 1 )
			str += tmp.charAt(i);
	}
	
	return( str );
}

function onMseOvrStr( ImgFileName, Dida, W )
{
	if( W > 256 ) W = 256;

	Dida = unescape( Dida );
	top.title.document.picture.src=ImgFileName;
	top.title.document.picture.width=W; 

	// get text element containing dida from menu frame
	tmp = top.title.document.getElementById('dida').firstChild;
	var dida = skipTag( Dida );
	tmp.replaceData(0, tmp.length, dida );
}

function onMseOutStr( ImgFileName, Dida )
{
	Dida = unescape( Dida );
	top.title.document.picture.src='../../img/noimage.gif';
	top.title.document.picture.removeAttribute('width');
	
	// get text element containing dida from menu frame
	tmp = top.title.document.getElementById('dida').firstChild;
	tmp.replaceData(0, Dida.length, 'Nessuna immagine selezionata' );
}

function onMseOvrIdx( Idx )
{
	// for delay in loading page; prevent errors
	if( typeof( eval( 'document.img'+Idx ) ) != "undefined" )
	{
		W = eval( 'document.img'+Idx+'.width' );
		onMseOvrStr( Img[Idx], Dida[Idx], W );
	}
}

function onMseOutIdx( Idx )
{
	onMseOutStr( Img[Idx], Dida[Idx] );
}

// link from itinerari
function SetImgLink( Idx )
{
  Idx--;

  text = '<a href="" ';
  text += 'onMouseOver="onMseOvrIdx('+Idx+'); return false;" ';
  text += 'onClick="return false;" ';
  text += 'onMouseOut="onMseOutIdx('+Idx+'); return false;">';
  text += '<img src="../img/pict.gif" border="0"></a>';
  text = text+'<span style="font-size:8pt">'+(Idx+1)+'</span>';
  document.write(text);
  return false;
}

// link from indice
function SetImgLinkIdx( ImgFileName, Dida, IndexFileName, W )
{
	Dida = escape( Dida );

	text = '<a href="'+IndexFileName+'" target="_top"';
	text += 'onMouseOver="onMseOvrStr(\''+ImgFileName+'\',\''+Dida+'\','+W+'); return false;" ';
	text += 'onMouseOut="onMseOutStr(\''+ImgFileName+'\',\''+Dida+'\'); return false;">';
	text += '<img src="../../itinerari/img/pict.gif" border="0"></a> ';
	document.write(text);
	return false;
}

function SetImg( Idx1, Idx2, Idx3 )
{
	text = '<center><table border="0" width="300"><tr>';
	
	// img
	if( Idx1 >= 0 )
	{
		Idx1--;
		var dida1 = skipTag( Dida[Idx1] );
		text += '<td class="itidida" width="50%"><img src="'+Img[Idx1]+'" alt="'+dida1+'" title="'+dida1+'" name="img'+Idx1+'"></td>';
	}
	
	if( Idx2 >= 0 )
	{
		Idx2--;
		var dida2 = skipTag( Dida[Idx2] );
		text += '<td class="itidida" width="50%"><img src="'+Img[Idx2]+'" alt="'+dida2+'" title="'+dida2+'" name="img'+Idx2+'"></td>';
	}

	if( Idx3 >= 0 )
	{
		Idx3--;
		var dida3 = skipTag( Dida[Idx3] );
		text += '<td class="itidida" width="50%"><img src="'+Img[Idx3]+'" alt="'+dida3+'" title="'+dida3+'" name="img'+Idx3+'"></td>';
	}
 
	text += '</tr><tr>';

	// dida
	if( Idx1 >= 0 )
		text += '<td class="itidida" width="50%">'+Dida[Idx1]+'</td>';

	if( Idx2 >= 0 )
		text += '<td class="itidida" width="50%">'+Dida[Idx2]+'</td>';
		
	if( Idx3 >= 0 )
		text += '<td class="itidida" width="50%">'+Dida[Idx3]+'</td>';
	
	text += '</tr></table></center>';
	document.write(text);
}


function SetMap( Map )
{
  text = '<p><center><table cellpadding="5" cellspacing="0"><tr><td style="border-style:solid;border-color:#9bcf6e;border-width:1;">';
  // map
  text += '<img src="map/'+Map+'map.gif">';
  text += '</td></tr></table></center>';
  document.write(text);
}

function Translate()
{
  url = self.location.href;
  pos = url.lastIndexOf( "/" );
  redirToUrl = url.substr( 0, pos+1 );
  redirToUrl = redirToUrl+"index".concat( url.substr( pos+1 ) );

  pos = url.lastIndexOf( "/" );
  num = url.substr( pos+1 );
  itiNum = num.substr( 0, 2 )+"."+num.substr( 2, 2 );
  
  text = '<div align="right">';
  text += '<a href="" onClick="javascript:window.open(\'..\/..\/guestbook\/guestbookform.php?itinum='+itiNum+'\', \'guestbookfrm\', \'width=600,height=570,scrollbars=yes,menubar=no,toolbar=no,screenX=15,screenY=50,top=50,left=15,resizable=no\');return false;" class="lnk">[Commenta l\'itinerario]<\/a> ';
  text += '<a href="" onClick="javascript:window.open(\'..\/itineraricommenti.php?itinum='+itiNum+'\', \'guestbookfrm\', \'width=600,height=570,scrollbars=yes,menubar=no,toolbar=no,screenX=15,screenY=50,top=50,left=15,resizable=no\');return false;" class="lnk">[Leggi i commenti]<\/a> ';
  text += '<a href="javascript:self.print();" class="lnk">[Stampa]<\/a> ';
  text += '<a href="javascript:top.location.href=\'index.htm\'" target="_top" class="lnk">[Chiudi]<\/a> ';
/*
*/
  text += '<a href="javascript:window.location=\'http://www.google.com/translate?hl=it&amp;langpair=it%7Cfr&amp;u='+redirToUrl+'\';" class="lnk" target="_blank"><img src="../../img/fr.gif" border="0" alt="Français" title="Français"></a> ';
  text += '<a href="javascript:window.location=\'http://www.google.com/translate?hl=it&amp;langpair=it%7Cnl&amp;u='+redirToUrl+'\';" class="lnk" target="_blank"><img src="../../img/nl.gif" border="0" alt="Nederlands" title="Nederlands"></a> ';
  text += '<a href="javascript:window.location=\'http://www.google.com/translate?hl=it&amp;langpair=it%7Cde&amp;u='+redirToUrl+'\';" class="lnk" target="_blank"><img src="../../img/de.gif" border="0" alt="Deutsch" title="Deutsch"></a> ';
  text += '<a href="javascript:window.location=\'http://www.google.com/translate?hl=it&amp;langpair=it%7Cen&amp;u='+redirToUrl+'\';" class="lnk" target="_blank"><img src="../../img/gb.gif" border="0" alt="English" title="English"></a> ';
  text += '</div>';
  document.write(text);
}

function Footer()
{
	url = self.location.href;
	pos = url.lastIndexOf( "/" );
	num = url.substr( pos+1 );
	itiNum = num.substr( 0, 2 )+"."+num.substr( 2, 2 );

	text = '<p class="itipar small center"><i>Le informazioni contenute in questo itinerario hanno carattere puramente indicativo. ';
	text += 'Prima di incominciare l\'escursione accertarsi delle effettive condizioni del percorso e delle condizioni meteo.</i>';
   document.write( text );
	//onMouseOver="this.style.cursor=\'pointer\';" OnMouseOut="this.style.cursor=\'auto\';" abilita cursore sui bottoni
   text = '<p class="itipar center"><center><form action="">';
   text += '<input TYPE="button" VALUE="Inizio Pagina" onClick="location.href=\'#\'" class="itibutton"> ';
   text += '<input TYPE="button" VALUE="Stampa" onClick="self.print()" class="itibutton"> ';
   text += '<input TYPE="button" VALUE="Commenta" onClick="win=window.open(\'..\/..\/guestbook\/guestbookform.php?itinum='+itiNum+'\', \'guestbookfrm\', \'width=600,height=570,scrollbars=yes,menubar=no,toolbar=no,screenX=15,screenY=50,top=50,left=15,resizable=no\');return false;" class="itibutton"> ';
   text += '<input TYPE="button" VALUE="Leggi i commenti" onClick="win=window.open(\'..\/itineraricommenti.php?itinum='+itiNum+'\', \'guestbookfrm\', \'width=600,height=570,scrollbars=yes,menubar=no,toolbar=no,screenX=15,screenY=50,top=50,left=15,resizable=no\');return false;" class="itibutton"> ';
//   text += '<input TYPE="button" VALUE="Chiudi" onClick="history.go(-1)" class="itibutton"><p>';
   text += '<input TYPE="button" VALUE="Chiudi" onClick="top.location.href=\'index.htm\'" target="_top" class="itibutton"> ';
   text += '</form>';
	text += '<div class="itipar small center" style="color:#9bcf6e; font-style: italic;">Copyright &copy; Roberto Pockaj. Tutti i diritti riservati.<br>';
	text += 'E\' vietata la riproduzione anche parziale con qualunque mezzo salvo autorizzazione scritta dell\'autore.</i></p>';
   text += '<a href="http://validator.w3.org/check/referer" class="lnk" target="_blank"><img src="../../img/valid-html401.png" border="0" alt="Valid HTML 4.01 Transitional"></a> ';
   text += '<a href="http://jigsaw.w3.org/css-validator/check/referer" class="lnk" target="_blank"><img src="../../img/vcss.png" border="0" alt="Valid CSS!"></a>';
   text += '</center>';
   document.write( text );
}

function LeaveComment( itinum )
{
	text = '<a href="" onClick="win=window.open(\'../../guestbook/guestbookfrm3.php?itinum='+itinum+'\', \'guestbook\',\'width=800,height=530,scrollbars=no,menubar=no,toolbar=no,screenX=15,screenY=50,top=50,left=15,resizable=no\');return false;" class="lnk">[Commenta]</a> ';
   document.write( text );
}

function ReadComments( itinum )
{
	text = '<a href="" onClick="win=window.open(\'../itineraricommenti.php?itinum='+itinum+'\', \'commentiitinerario\',\'width=800,height=530,scrollbars=no,menubar=no,toolbar=no,screenX=15,screenY=50,top=50,left=15,resizable=no\');return false;" class="lnk">[Leggi i commenti]</a>';
   document.write( text );
}

function ItiRand()
{
	var Valley = new Array(
		'valletanaro|17',
		'vallemongia|0',
		'vallecasotto|5',
		'vallecorsaglia|7',
		'vallemaudagna|3',
		'valleellero|7',
		'vallepesio|9',
		'vallejosina|0',
		'vallecolla|1',
		'vallevermenagna|7',
		'vallegesso|25',
		'vallestura|24',
		'vallegrana|6',
		'vallemaira|16',
		'vallevaraita|16',
		'vallebronda|0',
		'vallepo|7',
		'valleinfernotto|0'
	);

	var ValleyName, ValleyNum, TrailNum;
	var numiti;
	
	// select the valley
	do
	{
		idx = randInRange( Valley.length );
		buf = Valley[idx].split("|");
		ValleyName = buf[0];
		numiti = buf[1];
	}
	while( numiti == 0);
	
	idx++;
	if( idx < 10 )
		ValleyNum = '0'+idx;
	else
		ValleyNum = idx;

	// select the trail
	idx = randInRange( numiti );
	idx++;
	if( idx < 10 )
		TrailNum = '0'+idx;
	else
		TrailNum = idx;
			
	Link = ValleyName+'/index'+ValleyNum+TrailNum+'.htm';
	
	text = '<a href="itinerari/'+Link+'" class="lnk" target="_top">';
	
	return( text );
}

function randInRange( Range )
{
	rand = Math.random();
	rand *= (Range-0.0001);
	rand = Math.floor( rand );
	return rand;
}

// non più usate
function Header( Title )
{
	redirPage = 'index'+Title.slice(0,2)+Title.slice(3,5)+'.htm';
	redir( redirPage );
	text = '<table width="100%" border="0"><tr><td align="center" width="15%">';
	text += '<a href="http://www.alpicuneesi.it" class="lnk" target="_top">';
	text += '<img src="../../img/logosm.gif" border="0" alt="www.alpicuneesi.it" title="www.alpicuneesi.it"><br>AlpiCuneesi.it</a></td>';
	text += '<td><div class="itititle">';
	text += Title;
   text += '</div>';
	text += '</td></tr></table>';
   document.write( text );
}

