﻿// setup

var ffz_a_target="_blank";
var ffz_t_align="center";
var ffz_t_cellSpacing=1;
var ffz_t_cellPadding=1;
var ffz_t_width="";
var ffz_t_fontsize="";
var ffz_msg_s1="Entra nel Forum: ";
var ffz_msg_s2="Messaggi: ";
var ffz_msg_s3="Discussioni: ";
var ffz_msg_s4="Utenti: ";
var ffz_msg_s5="Non sei registrato? ";
var ffz_msg_s6="Clicca qui";
var ffz_msg_s7=" by ";
var ffz_msg_s8="Annulla";
var ffz_msg_s9="Caricamento in corso...";
var ffz_msg_s10="Messaggio del: ";
var ffz_msg_s11="Autore: ";
var ffz_msg_s12="Continua";
var ffz_msg_s13="Indietro";
var ffz_msg_s14="Nessun messaggio presente nella discussione";
var ffz_msg_s15="Errore nel recupero dei messaggi, o diritti di accesso non verificati";

var ffz_lc_descrizione="no"; // ListaCartelle - mostra descrizione
var ffz_ld_ultimoagg="no"; // ListaDiscussioni - mostra ultimo aggiornamento
var ffz_ld_ultimoagg_sep="yes"; // ListaDiscussioni - separatore br ultimo aggiornamento
var ffz_ld_colonne=1; // ListaDiscussioni - numero colonne
var ffz_ld_last="no"; // ListaDiscussioni - link a ultimo post della discussione
var ffz_ld_newsboard="no"; // ListaDiscussioni - esegue newsboard delle discussioni (le apre in locale)
var ffz_lm_ffz="yes"; // ListaMessaggi - utilizza codice ffz
var ffz_lm_html="yes"; // ListaMessaggi - utilizza codice html
var ffz_lm_url="yes"; // ListaMessaggi - utilizza codice url automatici

var ffz_color_border="";
var ffz_color_background="";
var ffz_color_text="";
var ffz_color_link="";

// uty
function ffz_GetInt(str,defaultval)
{
    try{
        var val = parseInt(str);
        if(isNaN(val)) return defaultval;
        return val;
    }
    catch(ex) {
        alert(ex);
        return defaultval;
    }
}
function getObjAPI(name) {
 if (document.getElementById) { // For Level 1 DOM (Netscape 6, Explorer 5)
  return document.getElementById(name);
 }
 else if (document.all) { // For IE4 DOM
  return document.all[name];
 }
 else if (document.layers) { // For NS4 DOM
  var obj = getObjNN4API(document,name);
  obj.style = obj;
  return obj;
 }
 return null;
}

function getObjNN4API(obj,name) {
 var x = obj.layers;
 var foundLayer;
 for (i=0;i<x.length;i++) {
  if (x[i].id == name)
   foundLayer = x[i];
  else if (x[i].layers.length)
   var tmp = getObjNN4(x[i],name);
  if (tmp) foundLayer = tmp;
 }
 return foundLayer;
}
function ffz_GetObj(objid)
{
    return getObjAPI(objid);
}

function ffz_isYes(o)
{
    if(!o || o == null) return false;
    
    if(o==1) return true;
    if(o=="yes") return true;
    if(o=="Yes") return true;
    if(o=="YES") return true;
    if(o=="si") return true;
    if(o=="Si") return true;
    if(o=="SI") return true;
    if(""+o=="true") return true;
    return false;
}

// HashTable 

Hashtable.prototype.hash	 	= null;
Hashtable.prototype.keys		= null;
Hashtable.prototype.location	= null;

function Hashtable(){
	this.hash = new Array();
	this.keys = new Array();

	this.location = 0;
}

Hashtable.prototype.put = function (key, value){
	if (value == null)
		return;

	if (this.hash[key] == null)
		this.keys[this.keys.length] = key;

	this.hash[key] = value;
}

Hashtable.prototype.get = function (key){
		return this.hash[key];
}

Hashtable.prototype.remove = function (key){
	for (var i = 0; i < this.keys.length; i++){
		if (key == this.keys[i]){
			this.hash[this.keys[i]] = null;
			this.keys.splice(i ,1);
			return;
		}
	}
}

Hashtable.prototype.size = function (){
    return this.keys.length;
}

Hashtable.prototype.next = function (){
	if (++this.location < this.keys.length)
		return true;
	else
		return false;
}

Hashtable.prototype.moveFirst = function (){
	try {
		this.location = -1;
	} catch(e) {}
}

Hashtable.prototype.moveLast = function (){
	try {
		this.location = this.keys.length - 1;
	} catch(e) {}
}

Hashtable.prototype.getKey = function (){
	try {
		return this.keys[this.location];
	} catch(e) {
		return null;
	}
}

Hashtable.prototype.getValue = function (){
	try {
		return this.hash[this.keys[this.location]];
	} catch(e) {
		return null;
	}
}

Hashtable.prototype.getKeyOfValue = function (value){
	for (var i = 0; i < this.keys.length; i++)
		if (this.hash[this.keys[i]] == value)
			return this.keys[i]
	return null;
}

Hashtable.prototype.toString = function (){

	try {
		var s = new Array(this.keys.length);
		s[s.length] = "{";

		for (var i = 0; i < this.keys.length; i++){
			s[s.length] = this.keys[i];
			s[s.length] = "=";
			var v = this.hash[this.keys[i]];
			if (v)
				s[s.length] = v.toString();
			else
				s[s.length] = "null";

			if (i != this.keys.length-1)
				s[s.length] = ", ";
		}
	} catch(e) {

	}finally{
		s[s.length] = "}";
	}

	return s.join("");
}

Hashtable.prototype.add = function(ht){
	try {
		ht.moveFirst();
		while(ht.next()){
			var key = ht.getKey();
			this.hash[key] = ht.getValue();
			if (this.get(key) != null){
				this.keys[this.keys.length] = key;
			}
		}
	} catch(e) {

	} finally {
		return this;
	}
};

// ffz

var list_C=new Array();
var list_K=new Array();
var list_D=new Array();
var list_DC=new Array();
var list_M=new Array();
var hash_C=new Hashtable();
var hash_K=new Hashtable();
var ffz_r=null;
var t_cache=new Array(); 
t_cache[0]=null;
t_cache[1]=null;

function ffzRichiesta()
{
    this.TypeName="ffzRichiesta";
    
    this.IDFORUM=0;
    this.nome='';
    this.descrizione='';
    this.url='';
    this.urlForum='';
    this.num_utenti=0;
    this.num_discussioni=0;
    this.num_post=0;
    this.image='';
    this.data_aggiornamento='';
    this.uo_tot=0;
    this.uo_reg=0;
    
    var T=this;
}

function ffzCartella(IDCARTELLA, IDCARTELLA_PADRE, IDCATEGORIAFORUM, url, titolo, descrizione, num_post, num_discussioni, data_aggiornamento, image)
{
    this.TypeName="ffzCartella";
    
    this.IDCARTELLA=IDCARTELLA;
    this.IDCARTELLA_PADRE=IDCARTELLA_PADRE;
    this.IDCATEGORIAFORUM=IDCATEGORIAFORUM;
    this.url=url;
    this.titolo=titolo;
    this.descrizione=descrizione;
    this.num_post=num_post;
    this.num_discussioni=num_discussioni;
    this.data_aggiornamento=data_aggiornamento;
    this.image=image;
    
    var T=this;
    
    hash_C.put(IDCARTELLA, this);
}

function ffzCategoria(IDCATEGORIA, url, titolo, descrizione, image)
{
    this.TypeName="ffzCategoria";
    
    this.IDCATEGORIA=IDCATEGORIA;
    this.url=url;
    this.titolo=titolo;
    this.descrizione=descrizione;
    this.image=image;
    
    var T=this;
    
    hash_K.put(IDCATEGORIA, this);
}

function ffzDiscussione(IDD, IDCARTELLA, url, titolo, sottotitolo, num_post, num_visite, data_aggiornamento, autore, autore_aggiornamento, image, isLink, isGioco, isSondaggio)
{
    this.TypeName="ffzDiscussione";
    
    this.IDD=IDD;
    this.IDCARTELLA=IDCARTELLA;
    this.url=url;
    this.titolo=titolo;
    this.sottotitolo=sottotitolo;
    this.num_post=num_post;
    this.num_visite=num_visite;
    this.data_aggiornamento=data_aggiornamento;
    this.autore=autore;
    this.autore_aggiornamento=autore_aggiornamento;
    this.image=image;
    this.isLink=isLink;
    this.isGioco=isGioco;
    this.isSondaggio=isSondaggio;
    
    var T=this;
}

function ffzMessaggio(IDM, IDD, jso)
{
    this.TypeName="ffzMessaggio";
    
    this.IDM=IDM;
    this.IDD=IDD;
    this.titolo=jso.titolo;
    this.testo=jso.testo;
    this.data_creazione=jso.data_creazione;
    this.autore=jso.autore;
    
    var T=this;
}

var __fout=null;

function ffz_SetupOutput(objid)
{
    var obj=null;
    if(objid && objid!=null) 
    {
        obj=ffz_GetObj(objid);
    }
    
    if(obj && obj!=null) __fout=obj;
    else
    {
        var objid2="_ffzout_0_";
        for(var j=0;j<50;j++)
        {
            objid2="_ffzout_"+j+"_";
            var obj=ffz_GetObj(objid2);
            if(obj==null)
                break;
        }
        
        document.write("<span id='"+objid2+"'></span>");
        
        __fout=ffz_GetObj(objid2);
    }
    if(ffz_r==null || __fout==null) return false;
    return true;
}

function ffz_table(obj, classe)
{
    var t=document.createElement("table");
    t.className="ffz_table "+classe;
    t.align=ffz_t_align;
    t.cellSpacing=ffz_t_cellSpacing=1;
    t.cellPadding=ffz_t_cellPadding=1;
    if(ffz_t_width.length>0) t.style.width=ffz_t_width;
    if(ffz_t_fontsize.length>0) t.style.fontSize=ffz_t_fontsize;
    if(ffz_color_border.length>0) t.style.backgroundColor=ffz_color_border;
    if(obj!=null) obj.appendChild(t);
    var tbody=document.createElement("tbody");
    t.appendChild(tbody);
    if(OnCreateTable!=null) OnCreateTable(t,tbody,obj,classe);
    return t;
}
function ffz_tr(t, classe)
{
    var tr=document.createElement("tr");
    tr.className="ffz_tr "+classe;
    t.firstChild.appendChild(tr);
    return tr;
}
function ffz_td(tr, classe)
{
    var td=document.createElement("td");
    td.className="ffz_td "+classe;
    if(ffz_color_background.length>0) td.style.backgroundColor=ffz_color_background;
    if(ffz_color_text.length>0) td.style.color=ffz_color_text;
    tr.appendChild(td);
    return td;
}
function ffz_a(container, classe, url)
{
    var a=document.createElement("a");
    a.className="ffz_a "+classe;
    a.href=url;
    if(!ffz_isYes(ffz_ld_newsboard)) a.target=ffz_a_target;
    if(ffz_color_link.length>0) a.style.color=ffz_color_link;
    container.appendChild(a);
    return a;
}

// Events

var OnStatRowBound=null;
var OnLCRowBound=null;
var OnLDRowBound=null;
var OnLMRowBound=null;
var OnCreateTable=null;

// API

function ffz_StampaNumUtenti(objid)
{
    if(!ffz_SetupOutput(objid)) return;
    
    __fout.appendChild(document.createTextNode( ""+ffz_r.num_utenti ));
}
function ffz_StampaNumMessaggi(objid)
{
    if(!ffz_SetupOutput(objid)) return;
    
    __fout.appendChild(document.createTextNode( ""+ffz_r.num_post ));
}
function ffz_StampaNumDiscussioni(objid)
{
    if(!ffz_SetupOutput(objid)) return;
    
    __fout.appendChild(document.createTextNode( ""+ffz_r.num_discussioni ));
}

function ffz_StampaStatistiche(objid)
{
    if(!ffz_SetupOutput(objid)) return;     
    
    var t=ffz_table(__fout, "ffz_t_s");
    ffz_StampaStatistiche_t(t);
}
function ffz_StampaStatistiche_t(t)
{
    var tr=ffz_tr(t, "ffz_tr_s_1");
    var td=ffz_td(tr, "ffz_td_s_1");
    var txt=document.createTextNode(ffz_msg_s1);
    td.appendChild(txt);    
    var a=ffz_a(td, "ffz_a_s", ffz_r.url);
    txt=document.createTextNode(""+ffz_r.nome);
    a.appendChild(txt);
    
    if(OnStatRowBound!=null) OnStatRowBound(t,tr,td,1);
    
    tr=ffz_tr(t, "ffz_tr_s_2");
    td=ffz_td(tr, "ffz_td_s_2");
    txt=document.createTextNode(ffz_msg_s2+ffz_r.num_post);
    td.appendChild(txt);
    
    if(OnStatRowBound!=null) OnStatRowBound(t,tr,td,2);
    
    tr=ffz_tr(t, "ffz_tr_s_3");
    td=ffz_td(tr, "ffz_td_s_3");
    txt=document.createTextNode(ffz_msg_s3+ffz_r.num_discussioni);
    td.appendChild(txt);
    
    if(OnStatRowBound!=null) OnStatRowBound(t,tr,td,3);
    
    tr=ffz_tr(t, "ffz_tr_s_4");
    td=ffz_td(tr, "ffz_td_s_4");
    txt=document.createTextNode(ffz_msg_s4+ffz_r.num_utenti);
    td.appendChild(txt);
    
    if(OnStatRowBound!=null) OnStatRowBound(t,tr,td,4);
    
    tr=ffz_tr(t, "ffz_tr_s_5");
    td=ffz_td(tr, "ffz_td_s_5");
    txt=document.createTextNode(ffz_msg_s5);
    td.appendChild(txt);
    
    var a=ffz_a(td, "ffz_a_s_5", "http://freeforumzone.leonardo.it/regc.aspx?c="+ffz_r.IDFORUM+"&f="+ffz_r.IDFORUM);
    txt=document.createTextNode(ffz_msg_s6);
    a.appendChild(txt);
    
    if(OnStatRowBound!=null) OnStatRowBound(t,tr,td,5);
}

function ffz_StampaListaCartelle(objid)
{
    if(!ffz_SetupOutput(objid)) return;
    
    var t=ffz_table(__fout, "ffz_t_lc");
    ffz_StampaListaCartelle_t(t);
}
function ffz_StampaListaCartelle_t(t)
{
    for(var i=0;i<list_C.length;i++)
    {
        var tr=ffz_tr(t, "ffz_tr_lc ffz_tr_lc_"+i);
        var td=ffz_td(tr, "ffz_td_lc ffz_td_lc_"+i);
        
        var a=ffz_a(td, "ffz_a_lc", list_C[i].url);
        //var txt=document.createTextNode(list_C[i].titolo);
        //a.appendChild(txt);
        a.innerHTML=list_C[i].titolo;
        
        if(ffz_isYes(ffz_lc_descrizione))
        {
            var br=document.createElement("br");
            td.appendChild(br);
            
            var span=document.createElement("span");
            span.className="ffz_lc_desc";
            //span.style.fontSize="small";
            td.appendChild(span);
            //txt=document.createTextNode(list_C[i].descrizione);
            //span.appendChild(txt);
            
            span.innerHTML=list_C[i].descrizione;
        }
        if(OnLCRowBound!=null) OnLCRowBound(list_C[i],i,t,tr,td);
    }
}

function ffz_StampaListaDiscussioniCartella(objid)
{
    if(!ffz_SetupOutput(objid)) return;
    
    var t=ffz_table(__fout, "ffz_t_ld");
    ffz_StampaListaDiscussioni_t(t, list_DC, 0);
}
function ffz_StampaListaDiscussioni(objid)
{
    if(!ffz_SetupOutput(objid)) return;
    
    var t=ffz_table(__fout, "ffz_t_ld");
    ffz_StampaListaDiscussioni_t(t, list_D, 1);
}
function ffz_StampaListaDiscussioni_t(t, list, mode)
{
    if(ffz_ld_colonne<=0) ffz_ld_colonne=1;
    
    var tr=null;
    
    for(var i=0, j=ffz_ld_colonne;i<list.length;i++,j++)
    {
        if(j==ffz_ld_colonne) 
        {
            tr=ffz_tr(t, "ffz_tr_ld ffz_tr_ld_"+i);
            j=0;
        }
        var td=ffz_td(tr, "ffz_td_ld ffz_td_ld_"+i);
        
        var a=ffz_a(td, "ffz_a_ld", "");
        if(ffz_isYes(ffz_ld_last))
        {
            list[i].url=list[i].url+"&a=2#Last";
        }
        var txt=document.createTextNode(list[i].titolo);
        
        if(ffz_isYes(ffz_ld_newsboard))
        {
            a.href="javascript:;"; /*"javascript:void(0);";*/
            a.onclick=function() { ffz_StampaListaMessaggi_t(this.DataItem_t, this.DataItem, this.DataItem_mode); };
            //a.appendChild(txt);
            a.DataItem=list[i];
            a.DataItem_t=t;
            a.DataItem_mode=mode;
            a.innerHTML=list[i].titolo;
        }
        else
        {
            a.href=list[i].url;
            a.target=ffz_a_target;
            //a.appendChild(txt);
            a.innerHTML=list[i].titolo;
        }
        
        if(ffz_isYes(ffz_ld_ultimoagg))
        {
        		if(ffz_isYes(ffz_ld_ultimoagg_sep))
        		{
            	var br=document.createElement("br");
            	td.appendChild(br);
          	}
          	
            var span=document.createElement("span");
            span.className="cautore ffz_ld_ultimoagg";
            //span.style.fontSize="small";
            td.appendChild(span);
            txt=document.createTextNode(' '+list[i].data_aggiornamento + ffz_msg_s7 + list[i].autore_aggiornamento);
            span.appendChild(txt);
        }
        
        if(OnLDRowBound!=null) OnLDRowBound(list[i],i,t,tr,td,mode);
    }
}


function ffz_StampaListaMessaggi_t(t, disc, mode)
{
    t_cache[mode]=t;
        
        var t_wait=document.createElement("div");
        t_wait.className="ffz_wait_msg";
        t_wait.style.textAlign="center";
        t_wait.appendChild(document.createElement("br"));
        
        var a=ffz_a(t_wait, "ffz_a_m", "javascript:;" /*"javascript:void(0);"*/);
        a.onclick=function() {  ffz_StampaListaMessaggi_back(this.DataItem_t, this.DataItem_mode); };
        a.DataItem_t=t_wait;
        a.DataItem_mode=mode;
        var txt=document.createTextNode(ffz_msg_s8);
        a.appendChild(txt);
        t_wait.appendChild(document.createElement("br"));
        t_wait.appendChild(document.createElement("br"));      
        txt=document.createTextNode(ffz_msg_s9);
        t_wait.appendChild(txt);
        t_wait.appendChild(document.createElement("br"));
    
    var container=t.parentNode;
    container.removeChild(t);
    container.appendChild(t_wait);
    
    var post_ffz="&post_ffz=0";
    var post_html="&post_html=0";
    var post_url="&post_url=0";
    
    if(ffz_isYes(ffz_lm_ffz)) post_ffz="&post_ffz=1";
    if(ffz_isYes(ffz_lm_html)) post_html="&post_html=1";
    if(ffz_isYes(ffz_lm_url)) post_url="&post_url=1";
    
    var src="http://search.freeforumzone.leonardo.it/feed_js.ashx?c="+ffz_r.IDFORUM+"&disc_post="+disc.IDD+post_ffz+post_html+post_url;
    var script=document.createElement("script");
    script.type="text/javascript";
    script.src=src;
    
    document.body.appendChild(script);
    
    ffz_lm_status=1;
    ffz_lm_cur_t_wait=t_wait;
    ffz_lm_cur_disc=disc;
    ffz_lm_cur_mode=mode;
}

function ffz_StampaListaMessaggi_back(t, mode)
{
    var t_old=t_cache[mode];
    if(!t_old || t_old==null) return;
    t_cache[mode]=t;
    
    var container=t.parentNode;
    container.removeChild(t);
    container.appendChild(t_old);
}

var ffz_lm_status=0;
var ffz_lm_cur_t_wait=null;
var ffz_lm_cur_disc=null;
var ffz_lm_cur_mode=0;

function ffz_StampaListaMessaggi_callback(result)
{
    var t_new=ffz_table(null, "ffz_t_lm");
    ffz_StampaListaMessaggi_callwrite(t_new, ffz_lm_cur_disc, result);
    
    ffz_lm_status=0;
    var container=ffz_lm_cur_t_wait.parentNode;
    container.removeChild(ffz_lm_cur_t_wait);
    container.appendChild(t_new);
}

function ffz_StampaListaMessaggi_callwrite(t, disc, result)
{
    var tr;
    var td;
    var txt;
    var span;
    var spacing;
    var a;
    
    tr=ffz_tr(t, "ffz_tr_lm ffz_tr_lm_z");
    td=ffz_td(tr, "ffz_td_lm ffz_td_lm_z");
    td.style.fontWeight="bold";
    
    a=ffz_a(td, "ffz_a_lm", disc.url);
    //txt=document.createTextNode(disc.titolo);
    //a.appendChild(txt);
    a.innerHTML=disc.titolo;
    
    spacing=document.createElement("span");
    spacing.innerHTML=" &nbsp;&nbsp;&nbsp; ";
    td.appendChild(spacing);
    
    a=ffz_a(td, "ffz_a_lm", "javascript:;" /*"javascript:void(0);"*/);
    a.onclick=function() {  ffz_StampaListaMessaggi_back(this.DataItem_t, this.DataItem_mode); };
    a.DataItem_t=t;
    a.DataItem_mode=ffz_lm_cur_mode;
    txt=document.createTextNode(ffz_msg_s13);
    a.appendChild(txt);
    
    tr=ffz_tr(t, "");
    td=ffz_td(tr, "");
    
    spacing=document.createElement("span");
    spacing.innerHTML="<iframe frameborder='0' marginheight='0' marginwidth='0' scrolling='no' width='468' height='60' src='http://search.freeforumzone.leonardo.it/g.htm'></iframe>";
    td.appendChild(spacing);
    
    if(result==1)
    {
        if(list_M.length>0)
        {
            for(var i=0;i<list_M.length;i++)
            {
                tr=ffz_tr(t, "ffz_tr_lm ffz_tr_lm_"+i);
                td=ffz_td(tr, "ffz_td_lm ffz_td_lm_"+i);
                
                span=document.createElement("div");
                span.className="ffz_lm_autore";
                txt=document.createTextNode(ffz_msg_s10);
                span.appendChild(txt);
                txt=document.createTextNode(list_M[i].data_creazione);
                span.appendChild(txt);
                spacing=document.createElement("span");
                spacing.innerHTML=" &nbsp;&nbsp;&nbsp; ";
                span.appendChild(spacing);
                txt=document.createTextNode(ffz_msg_s11);
                span.appendChild(txt);
                txt=document.createTextNode(list_M[i].autore);
                span.appendChild(txt);
                td.appendChild(span);
                
                span=document.createElement("div");
                span.className="ffz_lm_titolo";
                span.innerHTML=list_M[i].titolo;
                td.appendChild(span);
                
                span=document.createElement("div");
                span.className="ffz_lm_testo";
                span.innerHTML=list_M[i].testo;
                td.appendChild(span);
                
                spacing=document.createElement("span");
                spacing.innerHTML="<br />";
                td.appendChild(spacing);
                
                if(OnLMRowBound!=null) OnLMRowBound(list_M[i],i,t,tr,td,disc);
            }
        }
        else
        {
            tr=ffz_tr(t, "ffz_tr_lm ffz_tr_lm_0");
            td=ffz_td(tr, "ffz_td_lm ffz_td_lm_0");
                
            txt=document.createTextNode(ffz_msg_s14);
            td.appendChild(txt);            
        }
    }
    else
    {
        tr=ffz_tr(t, "ffz_tr_lm ffz_tr_lm_0");
        td=ffz_td(tr, "ffz_td_lm ffz_td_lm_0");
        
        txt=document.createTextNode(ffz_msg_s15);
        td.appendChild(txt);
    }
    
    tr=ffz_tr(t, "ffz_tr_lm ffz_tr_lm_x");
    td=ffz_td(tr, "ffz_td_lm ffz_td_lm_x");
    td.style.textAlign="right";
    
    txt=document.createTextNode("[");
    td.appendChild(txt);
    
    a=ffz_a(td, "ffz_a_lm", disc.url);
    txt=document.createTextNode(ffz_msg_s12);
    a.target=ffz_a_target;
    a.appendChild(txt);
    
    txt=document.createTextNode("]");
    td.appendChild(txt);
    
}
