// --------------------------------------------------------------------
// Parte da impostare
// --------------------------------------------------------------------
var ColoreSfondoMenu = "#FFFF99";
var ColoreSfondoBody   = "#FFFFC6";
var ColoreBordoMenuTop = "red";

var DataModifica = "5 luglio 2010";
var OraModifica = "15";
var MinModifica = "37";
var SecModifica = "14";
var DecModifica = "22";
var CenModifica = "57";

var TimeoutNew = 15;	// Numero giorni per New
// --------------------------------------------------------------------
var DataUltimaModifica = DataModifica + " " + OraModifica + ":" + MinModifica;
var DataUltimaModificaEstesa = DataModifica + " - ore " + OraModifica + " - minuti " + MinModifica + " - secondi " + SecModifica + " - decimi " + DecModifica + " - centesimi " + CenModifica + ", centesimo pił, centesimo meno...";

function addInitPage(url)
{
	if (document.all)
	{
		// navigator.appName == "Microsoft Internet Explorer"

		document.body.style.behavior='url(#default#homepage)';
		document.body.setHomePage('http://www.homoscrivens.it');
	}
	else
	{
		if (window.sidebar)
		{
			if (window.netscape)
			{
				// Mozilla Firefox (navigator.appName == "Netscape")
				try
				{
					netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
					var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
					prefs.setCharPref('browser.startup.homepage', url);
				}
				catch(e)
				{
					alert("L'operazione e' disabilitata nel browser: se vuoi abilitarla, dai i permessi o modifica il valore di <signed.applets.codebase_principal_support> a true richiamando la pagina <about:config>.");
				}
			}
			else
			{
				alert('Sorry, funzione non supportata per questo browser!');
			}
		}
		else
		{
			alert('Sorry, funzione non supportata per questo browser!');
		}
	}
}


function addBookmark(url, title)
{
	if (document.all)
	{
		// Microsoft Internet Explorer
		window.external.AddFavorite(url, title);
	}
	else
	{
		if (window.sidebar)
			// Mozilla Firefox
			window.sidebar.addPanel(title, url, "");
		else
			alert('Sorry, funzione non supportata per questo browser!');
	}
}



function dw(x)
{
	document.write(x);
}

function DrawLine(color, size)
{
	dw('<TABLE width="100%" border="0" cellpadding="0" cellspacing="0">');
	dw('<TR>');
	dw('<TD bgcolor="' + color + '" height="' + size + '">');
	dw('<TABLE border="0" width="100%" cellpadding="0" cellspacing="0">');
	dw('<TR><TD></TD></TR>');
	dw('</TABLE>');
	dw('</TD>');
	dw('</TR>');
	dw('</TABLE>');
}

function DiffSysDateDay(sData)
{
	var SysDate;
	var a1, m1, g1;
	var a2, m2, g2;
	var Data1, Data2;
	var msData1, msData2;
	var ms;
	var dd;

	a1 = sData.substr(0, 4);
	m1 = sData.substr(4, 2);
	g1 = sData.substr(6, 2);

	SysDate = new Date();
	g2 = SysDate.getDate();
	m2 = SysDate.getMonth() + 1;
	a2 = SysDate.getFullYear();

	Data1 = new Date(Date.UTC(a1, m1, g1)); 
	Data2 = new Date(Date.UTC(a2, m2, g2));

	msData1 = Data1.getTime();
	msData2 = Data2.getTime();

	ms = Math.abs(msData1 - msData2);

	dd = parseInt(ms/1000/60/60/24);

	return (dd);
}

function DrawElencoRacconti(Lista, PagePath)
{
	var	TipTitolo = "Clicca per... leggere";

	var	i, j;
	var	Titolo, Descrizione, Autore, Link, DataPubblicazione;
	var	ss;
	var	ws;
	var	IsNew;


	dw('<DIV align="center"><CENTER>');

	dw('<TABLE border="6" width="90%" bgcolor="white" bordercolor="#0000FF" cellpadding="3" bordercolorlight="#00FFFF" bordercolordark="#0000FF">');

	//for (i = 1; i < Lista.length; i++)
	for (i = Lista.length - 1; i >= 1; i--)
	{
		Titolo            =            Lista[i][0];
		Descrizione       =            Lista[i][1];
		Autore            =            Lista[i][2];
		Link              = PagePath + Lista[i][3];
		DataPubblicazione =            Lista[i][4];
		
		if (DiffSysDateDay(DataPubblicazione) <= TimeoutNew)
			IsNew = true;
		else
			IsNew = false;

		//ss = '<' + Titolo + "> di " + Autore;
		ss = TipTitolo;
		ws  = "OnMouseOver=" + '"' + "window.status=" + "'" + ss + "'" + "; return true" + '"';
		ws += " OnMouseOut=" + '"' + "window.status=' '; return true" + '"';

		dw('<TR>');
		dw('<TD width="36%" rowspan="2" height="40">');
		dw('<A href="' + Link + '" target="_new" title="' + TipTitolo + '" ' + ws + '>');
		dw('<DIV STYLE="font-size: 14pt">' + Titolo + '</DIV>');
		dw('</A>');
		dw('</TD>');
		dw('<TD width="64%" style="text-align: justify; border-bottom: thin solid" height="41" valign="top">');
		dw('<P class="ST4">' + Descrizione + '</P>');
		dw('</TD>');
		dw('</TR>');

		dw('<TR>');
		dw('<TD width="64%" height="1" style="text-align: center; border-top: medium none" valign="top">');
		if (IsNew)
			dw('<P class="ST3">' + '<EM>di </EM>' + Autore + '<IMG src="immagini/new.gif" hspace=20 align=middle></P>');
		else
			dw('<P class="ST3">' + '<EM>di </EM>' + Autore + '</P>');
		dw('</TD>');
		dw('</TR>');
	}

	dw('</TABLE>');

	dw('</CENTER></DIV>');
}

function DrawRaccontiScrittore(Lista)
{
	var	TipTitolo = "Clicca per... leggere";
	var	ColoreSfondoTabella = ColoreSfondoBody;
	var	ColoreBordoTabella = "black";

	var	i, j;
	var	Titolo, Genere, Link, DataPubblicazione;
	var	IsNew;
	var	ss;
	var	ws;
	var	ExistNew;

	ExistNew = false;
	for (i = 1; i < Lista.length; i++)
	{
		DataPubblicazione = Lista[i][3];

		if (DiffSysDateDay(DataPubblicazione) <= TimeoutNew)
		{
			ExistNew = true;
			break;
		}
	}

	dw('<DIV align="center"><CENTER>');

	dw('<TABLE border="2" width="70%" bgcolor="' + ColoreSfondoTabella + '" bordercolor="' + ColoreBordoTabella + '" cellpadding="3" bordercolorlight="#00FFFF" bordercolordark="#0000FF">');

	for (i = 1; i < Lista.length; i++)
	{
		Titolo            = Lista[i][0];
		Genere            = Lista[i][1];
		Link              = Lista[i][2];
		DataPubblicazione = Lista[i][3];

		if (DiffSysDateDay(DataPubblicazione) <= TimeoutNew)
			IsNew = true;
		else
			IsNew = false;

		ss = TipTitolo;
		ws  = "OnMouseOver=" + '"' + "window.status=" + "'" + ss + "'" + "; return true" + '"';
		ws += " OnMouseOut=" + '"' + "window.status=' '; return true" + '"';

		dw('<TR>');

		dw('<TD width="55%">');
		dw('<A href="' + Link + '" target="_new" title="' + TipTitolo + '" ' + ws + '>');
		dw('<DIV STYLE="font-size: 14pt">' + Titolo + '</DIV>');
		dw('</A>');
		dw('</TD>');

		if (ExistNew)
			dw('<TD width="35%">');
		else
			dw('<TD width="45%">');

		dw('<DIV STYLE="font-size: 14pt">' + Genere + '</DIV>');
		dw('</TD>');

		if (ExistNew)
		{
			dw('<TD width="10%" align="center">');
			if (IsNew)
				dw('<IMG src="../immagini/new.gif">');
			else
				dw('<DIV STYLE="font-size: 14pt">' + "&nbsp;" + '</DIV>');
			dw('</TD>');
		}

		dw('</TR>');
	}

	dw('</TABLE>');

	dw('</CENTER></DIV>');
}

function DrawTableFoto()
{
       dw('<table width="80%" align="center" cellspacing="1" cellpadding="1" border="1" bordercolor="color: #000080" frame="hsides">');
       dw('<tr>');
       dw('<td align="center" ><FONT COLOR="#000080" size="+1"><B>Galleria fotografica</B></FONT>');
       dw('</td>');
       dw('</tr>');
       dw('</table>');
       dw('<BR>');

if (Spettacolo != "NULL")
       dw('<H3 align="center"><SPAN style="color: #000080">'+Spettacolo+' <EM>(' + Data+' - '+ Luogo+ ')</EM></SPAN></H3>');

       dw('<table width="80%" border="1" cellpadding="2" align="center" cellspacing="2" frame="hsides">');
       dw('<TR>');

      //ogni 3 foto
       var Mod3 =0;
       var DirFotoSmall = "immagini/foto/small/";

       var nNum = ListaFoto.length;
        for (i = 1;  i < ListaFoto.length;  i++)
       {
	Mod3 ++;

	dw('<td width="33%">');
	dw('<DIV align="center">');

	var wStatus = "' '";

	dw('<A href="JavaScript:DisplayFoto(' + i + ')" OnMouseOver="window.status='+wStatus+'; return true" OnMouseOut="window.status='+wStatus+'; return true">');
	dw('<img border="0" src="' + DirFotoSmall+ListaFoto[i][6] + '" width="' + ListaFoto[i][5] + '" height="' + ListaFoto[i][4] + '">');
	dw('</DIV></A>');
	dw('</td>');

	if (Mod3 == 3)
	{
		Mod3 =0;

		dw('</TR>');
		dw('<TR>');
	    	//dw('<td width="33%"><DIV align="center"><FONT COLOR="#000080">' + ListaFoto[i-2][1] + '</DIV></FONT></td>');
		//dw('<td width="33%"><DIV align="center"><FONT COLOR="#000080">' + ListaFoto[i-1][1] + '</DIV></FONT></td>');
    		//dw('<td width="34%"><DIV align="center"><FONT COLOR="#000080">' + ListaFoto[i][1] + '</DIV></FONT></td>');
		dw('<td width="33%"><P class="DF" align="center">' + ListaFoto[i-2][1] + '</P></td>');
		dw('<td width="33%"><P class="DF" align="center">' + ListaFoto[i-1][1] + '</P></td>');
    		dw('<td width="34%"><P class="DF" align="center">' + ListaFoto[i][1] + '</P></td>');
		dw('</TR>');
	}
        }

        if (Mod3 != 0) // le foto non sono un num multiplo di 3
       {
	dw('</TR>');
	dw('<TR>');
	for (i=0;  i<Mod3;  i++)
	{
		//dw('<td width="33%"><DIV align="center"><FONT COLOR="#000080">' + ListaFoto[nNum-2+i][1] + '</DIV></FONT></td>');
		//dw('<td width="33%"><P class="DF" align="center">' + ListaFoto[nNum-2+i][1] + '</P></td>');
		dw('<td width="33%"><P class="DF" align="center">' + ListaFoto[nNum-Mod3+i][1] + '</P></td>');
	}
	dw('</TR>');
       }

        dw('</TR>');
        dw('</TABLE>');
        dw('<BR>');
}

function DisplayFoto(n)
{
	var	wresizable, wscrollbars;
	var	wwidth, wheight, wtop, wleft;
	var	FileImmagine;
	var	Titolo;
	var	Descrizione;
	var	p;

	var DirFoto = "immagini/foto/";

	wresizable = "no";
	wscrollbars = "no";
	wheight = ListaFoto[n][2];
	wwidth = ListaFoto[n][3];
	wtop = "50";
	wleft = "50";

	FileImmagine = ListaFoto[n][6];

if (Spettacolo != "NULL")
	Titolo = 'Foto '+ n + ': "'+Spettacolo+'" ('+Data+')';
else
	Titolo = 'Foto '+ n + ': '+Luogo;

	Descrizione = ListaFoto[n][0] ;

	p = "";
	p = p + "resizable=" + wresizable;
	p = p + ",scrollbars=" + wscrollbars;
	p = p + ",width=" + wwidth;
	p = p + ",height=" + wheight;
	p = p + ",top=" + wtop;
	p = p + ",left=" + wleft;

	w = window.open("about:blank", "", p);

	w.document.open("text/html");

	w.document.writeln("<HTML>");
	w.document.writeln("<HEAD>");
	w.document.write("<TITLE>");
	w.document.write(Titolo);
	w.document.writeln("</TITLE>");
	w.document.writeln('<LINK rel="stylesheet" href="stile.css" type="text/css">');
	w.document.writeln("</HEAD>");
	w.document.writeln("<BODY>");

	w.document.writeln('<P align="center"><img src="' + DirFoto + FileImmagine + '" border=0></P>');
	w.document.writeln('<BR>');
	w.document.writeln('<P class="DF" align="center">' + Descrizione + '</P>');

	w.document.write("</BODY>");
	w.document.write("</HTML>");

	w.document.close();
}

function DisplayImg(FileImmagine, Titolo, wwidth, wheight, wtop, wleft, wresizable, wscrollbars)
{
	var	p;

	p = "";
	p = p + "resizable=" + wresizable;
	p = p + ",scrollbars=" + wscrollbars;
	p = p + ",width=" + wwidth;
	p = p + ",height=" + wheight;
	p = p + ",top=" + wtop;
	p = p + ",left=" + wleft;

	w = window.open("about:blank", "", p);

	w.document.open("text/html");

	w.document.writeln("<HTML>");
	w.document.writeln("<HEAD>");
	w.document.write("<TITLE>");
	w.document.write(Titolo);
	w.document.writeln("</TITLE>");
	w.document.writeln('<LINK rel="stylesheet" href="stile.css" type="text/css">');
	w.document.writeln("</HEAD>");
	w.document.writeln("<BODY>");

	w.document.writeln('<P align="center"><img src="' + FileImmagine + '" border=0></P>');
	w.document.writeln('<BR>');

	w.document.write("</BODY>");
	w.document.write("</HTML>");

	w.document.close();
}