
// HTML BASE

var Category_Eventi_Class = "CatEventi";

// SOMMARIO

function Category_Eventi_SchedaHTML(tree, srcImg)
{
	var pippo = "_blank";
	var HTML = "&nbsp;";
	var target = tree.findChild("Scheda");	
	if ( !IsEmpty(target) )
	{
		var title = target.item.value;
		var link = target.findChild("Link");
		if ( !IsEmpty(link.item.value) )
			HTML = '<A ID="Footer_idA_scheda" TITLE="'+ title +'" HREF="'+ link.item.value +'" TARGET="'+ link.item.getAttribute("target") +'"><IMG SRC="'+ srcImg +'" border="0" ></A>';
	}
	else
		HTML = "&nbsp;";
		//alert(link.item.getAttribute("target"))
	return HTML;
}


function Category_Eventi_Sommario_DefaultTable(entry)
{
	var s = new CEntryTableTemplate();

	var i;
	var next = 1;

	next = s.addTextLink(entry, next, 0, "Titolo");
	next = s.addTextLink(entry, next, 0, "Sottotitolo");
	next = s.addText(entry, next, 0, "Testo");
	next = s.addTextLink(entry, next, 0, "Coda");
	next = s.addImg(entry, next, 0, "Immagine");
	next = s.addTextLink(entry, next, 0, "Scheda");

	return s.table;
	

}

function Category_Eventi_SommarioHTML(tree)
{
	var target;
	var col="COLSPAN=2";
	var cls = Category_Eventi_Class +"-Sommario";

	target = tree.root.findChild("Immagine");
	var TD_immagine = Category_ImmagineHTML(target, cls +"-Immagine");
	if ( TD_immagine != "" ){
		TD_immagine = '\n<TD CLASS="'+ cls +'-clsTD-immagine"><DIV width=40>'+ TD_immagine +'</DIV></TD>';
		col="";
	}
	var TD_testo = "";
	TD_testo += '\n<TD CLASS="'+ cls +'-clsTD-testo" ' + col + '>';
 
	target = tree.root.findChild("Titolo");
	TD_testo += Category_TextLinkHTML(target, cls +"-Titolo");
	
	target = tree.root.findChild("Sottotitolo");
	TD_testo += Category_TextLinkHTML(target, cls +"-Sottotitolo");
 
	target = tree.root.findChild("Testo");
	TD_testo += Category_TextHTML(target, cls +"-Testo");
	
	target = tree.root.findChild("Coda");
	TD_testo += Category_TextLinkHTML(target, cls +"-Coda");

	TD_testo += '\n</TD>';
	var TD_scheda = '</TR><TR><TD CLASS="'+ cls +'-clsTD-scheda" COLSPAN=2>'+ Category_Eventi_SchedaHTML(tree.root, LOCAL_URL_SITE+"/images/go.gif") +'</TD></TR>';
	
	var HTML = "";
	HTML += '<TR>';
	HTML += TD_immagine;
	HTML += TD_testo;
	HTML += TD_scheda;
	HTML += '<TR><TD bgcolor=#ffffff height=4></TD></TR>';
	
//window.alert(HTML);
	return HTML; 

}



// PAGINA DEFAULT TABLE

function Category_Eventi_Pagina_DefaultTable(entry)
{
	var p = new CEntryTableTemplate();
	
	var i, parent, sub;
	var next = 1001;

	next = p.addTextLink(entry, next, 0, "Occhiello");
	next = p.addTextLink(entry, next, 0, "Titolo");
	next = p.addTextLink(entry, next, 0, "Sottotitolo");
	next = p.addTextLink(entry, next, 0, "Autore");
	next = p.addTextLink(entry, next, 0, "Epigrafe");

	parent = next;
	next = p.addBlock(entry, next, 0, "Paragrafi", 8);
	for (i=1; i<=8; i++)
	{
		sub = next;
		next = p.addBlock(entry, next, parent, "Paragrafo " + i);
		next = p.addTextLink(entry, next, sub, "Titolo");
		next = p.addTextLink(entry, next, sub, "Testa");
		next = p.addText(entry, next, sub, "Corpo");
		next = p.addList(entry, next, sub, "Elenco");
		next = p.addTable(entry, next, sub, "Tabella", i);
		next = p.addTextLink(entry, next, sub, "Coda");
		next = p.addPicture(entry, next, sub, "Figura");
	}
	
	parent = next;
	next = p.addBlock(entry, next, 0, "Figure", 8);
	for (i=1; i<=8; i++)
		next = p.addPicture(entry, next, parent, "Figura " + i);
	
	next = p.addTextLink(entry, next, 0, "Firma");
	
	return p.table;

}


function Category_Eventi_PaginaHTML(tree)
{

	var i;
	var node;
	var target;
	var tmp;
	
	var cls = Category_Eventi_Class +"-Pagina";	
	var HTML;

	// TOP
	var TableTop = '<TABLE border=0 CLASS="'+ cls +'-clsTABLE-top" CELLPADDING=0 CELLSPACING=0><TR><TD CLASS="'+ cls +'-clsTD-top" COLSPAN=2>';
	
	target = tree.root.findChild("Occhiello");
	TableTop += Category_TextLinkHTML(target, cls +"-Occhiello");

	target = tree.root.findChild("Titolo");
	TableTop += Category_TextLinkHTML(target, cls +"-Titolo");

	target = tree.root.findChild("Sottotitolo");
	TableTop += Category_TextLinkHTML(target, cls +"-Sottotitolo");
	
	target = tree.root.findChild("Autore");
	TableTop += Category_TextLinkHTML(target, cls +"-Autore");

	target = tree.root.findChild("Epigrafe");
	var epigrafe = Category_TextLinkHTML(target, cls +"-Epigrafe");
	if ( epigrafe.length )	
		TableTop += '</TD></TR>\n<TR><TD CLASS="'+ cls +'-clsTD-top-left">&nbsp;</TD><TD CLASS="'+ cls +'-clsTD-top-right">'+ epigrafe;
	
	TableTop += '</TD></TR></TABLE>';
	
	// FIGURE
	var TD_figure;
	tmp = "";
	TD_figure = "";
	target = tree.root.findChild("Figure");
	if ( !IsEmpty(target) )
	{
		for (i=1; i<=8; i++)
		{
			node = target.findChild("Figura "+ i);
			tmp = Category_FiguraHTML(node, cls);
			if ( tmp.length ) 
				TD_figure += "<BR>&nbsp;<BR>" + tmp;
		}
	}
	if ( !IsEmpty(TD_figure) )
		TD_figure = '\n<TD CLASS="'+ cls +'-Figure-clsTD">'+ TD_figure +'</TD>';

	// PARAGRAFI
	var TD_paragrafi = '\n<TD CLASS="' + cls + '-Paragrafi-clsTD" VALIGN=top>';
	target = tree.root.findChild("Paragrafi");
	if ( !IsEmpty(target) )
	{
		for (i=1; i<=8; i++)
		{
			node = target.findChild("Paragrafo " + i);
			if ( !IsEmpty(node) )
				TD_paragrafi += Category_Eventi_ParagrafoHTML(node, cls);
		}	
	}
	TD_paragrafi += '&nbsp</TD>';

	// FIRMA
	var TableFirma = "";
	target = tree.root.findChild("Firma");
	if ( !IsEmpty(target) && !IsEmpty(target.item.value) )
	{
		TableFirma += '<TABLE CLASS="'+ cls +'-clsTABLE-firma" CELLSPACING=0 CELLPADDING=0><TR>';
		TableFirma += '<TD CLASS="'+ cls +'-clsTD-firmaLeft">&nbsp</TD>';		
		TableFirma += '<TD CLASS="'+ cls +'-clsTD-firmaRight">'+ Category_TextHTML(target, cls + "-clsFirma");
		TableFirma += '</TD></TR></TABLE>';
	}		

	// BOTTOM
	var TableBottom = '<TABLE CELLPADDING=0 CELLSPACING=0 CLASS="' + cls + '-clsTABLE-bottom"><TR>';
	var bImgLeft = true;
	if ( bImgLeft )
	{
		TableBottom  += TD_figure;
		TableBottom  += TD_paragrafi;
	}
	else
	{
		TableBottom  += TD_paragrafi;
		TableBottom  += TD_figure;
	}
	TableBottom += '</TR></TABLE>';

	

//	HTML += '<TR><TD COLSPAN=3>' + TableTop + TableBottom + TableFirma + '</TD></TR></TABLE>';	

	HTML = '<TR><TD COLSPAN=3>' + TableTop + TableBottom + TableFirma + '</TD></TR>';	

	return HTML; 

}


function Category_Eventi_ParagrafoHTML(node, clsBase)
{
	var target;
	
	// Top
	var HTML = "";
	
	target = node.findChild("Titolo");
	if ( !IsEmpty(target) )	
		HTML += Category_TextLinkHTML(target, clsBase + "-Paragrafo-Titolo");
	
	target = node.findChild("Testa");
	if ( !IsEmpty(target) )	
		HTML += Category_TextLinkHTML(target, clsBase + "-Paragrafo-Testa");
		
	target = node.findChild("Corpo");
	if ( !IsEmpty(target) )	
		HTML += Category_TextHTML(target, clsBase + "-Paragrafo-Corpo");

	target = node.findChild("Elenco");
	if ( !IsEmpty(target) )	
		HTML += Category_ElencoHTML(target, clsBase + "-Paragrafo-Elenco");
		
	target = node.findChild("Tabella");
	if ( !IsEmpty(target) )	
		HTML += Category_TabellaHTML(target, clsBase + "-Paragrafo-Tabella");
		
	target = node.findChild("Coda");
	if ( !IsEmpty(target) )	
		HTML += Category_TextLinkHTML(target, clsBase + "-Paragrafo-Coda");

	target = node.findChild("Figura");
	if ( !IsEmpty(target) )	
	{	
		target = Category_FiguraHTML(target, clsBase + "-Paragrafo");		
		if ( !IsEmpty(target) )
			HTML += '<TABLE CLASS="'+ clsBase +'-Paragrafo-clsTABLE-figura" CELLSPACING=0 CELLPADDING=0><TR><TD CLASS="'+ clsBase +'-Paragrafo-clsTD-figura">'+ target +'</TD></TR></TABLE>';
	}
	
	if ( IsEmpty(HTML) )
		return "";
	return '<TABLE CLASS="' + clsBase + '-Paragrafo-clsTABLE"><TR><TD CLASS="' + clsBase + '-Paragrafo-clsTD">'+ HTML +'</TD></TR></TABLE>';
}
