﻿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_StopPropagation()
{
    if(window.event) window.event.returnValue= false;
    if(typeof ev == 'undefined') return false;
	else if(ev && ev.preventDefault) ev.preventDefault();
	else if(ev && ev.stopPropagation) ev.stopPropagation();
	else return false;
}
function CambiaCartella(oid, bSoloCart)
{
    var ListaCartelle=ffz_GetObj(oid);
    var val=ListaCartelle.value;
    
    if(val=="A") window.top.location.href="comunita.aspx?c="+ffz_idcom;
    if(val=="B") window.top.location.href="forum.aspx?c="+ffz_idcom+"&f="+ffz_idcom;
    if(val=="C") window.top.location.href="regc.aspx?c="+ffz_idcom+"&f="+ffz_idcom;
    if(val=="D") window.top.location.href="partecipazione.aspx?c="+ffz_idcom+"&f="+ffz_idcom;
    if(val=="E") window.top.location.href="c.aspx?c="+ffz_idcom+"&f="+ffz_idcom+"&idc="+ffz_idc+"&idd="+ffz_idd;
    if(val=="F") window.top.location.href="utenti.aspx?c="+ffz_idcom+"&f="+ffz_idcom;
    
    val=ffz_GetInt(val, 0);
    if(val==0) return;    
    if(val<0)
    {
        val=val*(-1);
        if(bSoloCart=='False')
            window.top.location.href="categoria.aspx?k="+val;
    }
    else
    {
        window.top.location.href="cartella.aspx?idc="+val;
    }
}
function CambiaCartellaDPag(oid, idc)
{
    if(idc==0) return;
    var SelectPag=ffz_GetObj(oid);
    
    if(idc<0)
    {
        idc=(-1)*idc;
        window.top.location.href="recenti.aspx?c="+ffz_idcom+"&f="+ffz_idf+"&ev="+idc+"&pnd="+SelectPag.selectedIndex;
    }
    else
        window.top.location.href="cartella.aspx?idc="+idc+"&pnd="+SelectPag.selectedIndex;
}
function CatturaTasto(e, OnTastoCatturato, OnParam, int_ascii) 
{  
   if(!int_ascii || int_ascii==null) 
    int_ascii=13;
   
   if(!e) 
   {
      if( window.event )
      {
         //IE
         e = window.event;
      }
      else
      {
         return;
      }
   }
   if( typeof( e.keyCode ) == 'number'  )
   {
      //DOM
      e = e.keyCode;
   }
   else if( typeof( e.which ) == 'number' )
   {
      //Netscape 4
      e = e.which;
   }
   else if( typeof( e.charCode ) == 'number'  )
   {
      //Mozilla 0.9+ / Netscape
      e = e.charCode;
   }
   else
   {
      return;
   }
   if(e==int_ascii)
   {
      if(OnTastoCatturato && OnTastoCatturato!=null)
      {
        OnTastoCatturato(OnParam);
      }
      return false;
   }
}
function ForumSearch(oid)
{
    var Url = {

        // public method for url encoding
        encode : function (string) {
            return escape(this._utf8_encode(string));
        },

        // public method for url decoding
        decode : function (string) {
            return this._utf8_decode(unescape(string));
        },

        // private method for UTF-8 encoding
        _utf8_encode : function (string) {
            string = string.replace(/\r\n/g,"\n");
            var utftext = "";

            for (var n = 0; n < string.length; n++) {

                var c = string.charCodeAt(n);

                if (c < 128) {
                    utftext += String.fromCharCode(c);
                }
                else if((c > 127) && (c < 2048)) {
                    utftext += String.fromCharCode((c >> 6) | 192);
                    utftext += String.fromCharCode((c & 63) | 128);
                }
                else {
                    utftext += String.fromCharCode((c >> 12) | 224);
                    utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                    utftext += String.fromCharCode((c & 63) | 128);
                }

            }

            return utftext;
        },

        // private method for UTF-8 decoding
        _utf8_decode : function (utftext) {
            var string = "";
            var i = 0;
            var c = c1 = c2 = 0;

            while ( i < utftext.length ) {

                c = utftext.charCodeAt(i);

                if (c < 128) {
                    string += String.fromCharCode(c);
                    i++;
                }
                else if((c > 191) && (c < 224)) {
                    c2 = utftext.charCodeAt(i+1);
                    string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                    i += 2;
                }
                else {
                    c2 = utftext.charCodeAt(i+1);
                    c3 = utftext.charCodeAt(i+2);
                    string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                    i += 3;
                }

            }

            return string;
        }
    }

    var keywords=ffz_GetObj(oid);
    if(keywords.value.length>0)
    {
        window.top.location.href="c.aspx?c="+ffz_idcom+"&f="+ffz_idf+"&search=1&q="+Url.encode(keywords.value);
    }
}
function ImgUpdate(obj, url)
{
    if(url) if(url.length>0) obj.src=url;
}
function SbloccaCensuraPost()
{
    var str = ""+window.top.location.href;
    if(str.indexOf("&showall=")>=0) 
        return;
    window.top.location.href=str+"&showall=1";
}
function ImgAutoResize(imgobj, maxw, maxh)
{
    var doresize=0;
    if(imgobj.width>maxw && maxw>0)
    {
        imgobj.style.width=maxw;
        imgobj.style.maxWidth=maxw;
        imgobj.width=maxw;
        doresize=1;
    }
    if(imgobj.height>maxh && maxh>0)
    {
        imgobj.style.height=maxh;
        imgobj.style.maxHeight=maxh;
        imgobj.height=maxh;
        doresize=1;
    }
    if(doresize=1)
    {
        if(imgobj.parentNode && imgobj.parentNode!=null && imgobj.parentNode.parentNode && imgobj.parentNode.parentNode!=null)
        {
	        imgobj.parentNode.parentNode.style.width=''+maxw+'px';
	    }
    }
}
function ImgAutoResizeIfSmaller(imgobj, maxw, maxh)
{
    if(imgobj.width<maxw && maxw>0)
    {
        imgobj.style.width=maxw;
        imgobj.style.maxWidth=maxw;
        imgobj.width=maxw;
    }
    if(imgobj.height<maxh && maxh>0)
    {
        imgobj.style.height=maxh;
        imgobj.style.maxHeight=maxh;
        imgobj.height=maxh;
    }
}
function ffzimglogoresize()
{
    var el = ffz_GetObj('ffzimglogo');
    if(el!=null)
    {
        var max=window.screen.availWidth-778;
        if(el.width>max) el.width=max;
    }
}
function ffzBodyOnLoad()
{
    ffzOverflowFirme();
    ffzimglogoresize(); 
}


var ffzOverflow=new Array();
var ffzovmax=100;

function ffzOverflowFirma(i) 
{
    var ffzx=ffzOverflow[i][0].scrollHeight; 
    if(ffzx>ffzovmax) 
    { 
        ffzOverflow[i][1].height=ffzovmax; 
        ffzOverflow[i][1].style.height=""+ffzovmax+"px"; 
    }
} 
function ffzOverflowFirme() 
{
    var ffzi; 
    for(ffzi=0;ffzi<ffzOverflow.length;ffzi++) 
    { ffzOverflowFirma(ffzi); }
}

function ffzSetOverflowx(o,z)
{
    ffzOverflow[ffzOverflow.length]=new Array(o,z); 
    ffzOverflowFirma(ffzOverflow.length-1);
}
function ffzSpoilerClick(obj)
{
    if(!obj.firstChild) return;
    if(!obj.firstChild.nextSibling) return;
    var hiddenDiv = obj.firstChild.nextSibling;
    if(hiddenDiv.style.display!='none') 
    {
        hiddenDiv.style.display='none';
        hiddenDiv.style.visibility='hidden';
    }
    else
    {
        hiddenDiv.style.display='';
        hiddenDiv.style.visibility='visible';
    }
}
function RemoveHtml(obj)
{
    if(obj && obj.value && obj.value!=null)
    {
        var s=""+obj.value;
        s=s.replace(/</g," ");s=s.replace(/>/g," ");
        s=s.replace(/>/g," ");s=s.replace(/>/g," ");
        s=s.replace(/&/g," ");
        obj.value=s;
    }
}
function ffz_ForumPopup(value, msg1, msg2, txtExec, txtClose, urlExec)
{
    if (confirm(msg2))
    {
        window.open(urlExec, 'wmail1', 'location=yes,toolbar=yes,menubar=yes,directories=yes,status=yes,resizable=yes,scrollbars=yes', false);
    }
    else
    {
        return;
    }
}

function PNGAdjustAll()
{
    var IsIE6=false;
    var IsIE=(navigator.userAgent.toLowerCase().indexOf('msie')>0);
    if(IsIE)
    {
        var IEArrVersion = navigator.appVersion.split("MSIE");
        var IEVersion = parseFloat(IEArrVersion[1]);
        if(IEVersion<7)
            IsIE6=true;
    }

	if(IsIE && IsIE6)
	{		
		var is = document.getElementsByTagName('IMG'); // get all images
		for(var x=0; x<is.length; x++){ // cycle through those images
			if(is[x].src.indexOf('.png')){ // only do this to png files
	
				var ww = is[x].offsetWidth; if(ww==0) is[x].width;
				var hh = is[x].offsetHeight; if(hh==0) is[x].eeight;
				if(ww==0 || hh==0) continue;
				if(is[x].alphasrc && is[x].alphasrc!=null) continue;
				if(is[x].style.filter && is[x].style.filter!=null) continue;
			    
		        var src=is[x].src;
		        is[x].src = "http://im0.freeforumzone.it/v3/img/z.gif";
		        is[x].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+src+"', sizingMethod='scale')"; 
				is[x].width = ww;
				is[x].height = hh;
			}
		}
	}
}

var ffz_stopWords=new Array();
var ffz_replaceWord="***";
var ffz_idrMax=150;
var m3_ADDLIST=null;

function FilterStopWords(TextObj)
{
    if(ffz_idr>ffz_idrMax) return true;
    if(!TextObj || TextObj==null || !TextObj.value || TextObj.value==null) return true;
       
    var RE; 
    var out=""+TextObj.value;
    var rep="$1"+ffz_replaceWord+"$2";
    for(i=0;i<ffz_stopWords.length;i++)
    {
        RE=new RegExp("(?:^|([^a-zA-Z]))"+ffz_stopWords[i]+"(?:([^a-zA-Z])|$)", "gi");
        out=out.replace(RE,rep);
    }
    TextObj.value=out;
    
    return true;
}

function NascondiBloccoCategoria(obj,url)
{
    obj.stato=2;
    var oggetto=obj.parentNode.parentNode.parentNode.parentNode.parentNode;
    oggetto=oggetto.parentNode.parentNode.nextSibling;
    if (oggetto.nodeType==3) oggetto=oggetto.nextSibling;
    oggetto.style.visibility="hidden";
    oggetto.style.display="none";
    obj.firstChild.src=url;
}

function VisualizzaBloccoCategoria(obj,url)
{
    obj.stato=1;
    var oggetto=obj.parentNode.parentNode.parentNode.parentNode.parentNode;
    oggetto=oggetto.parentNode.parentNode.nextSibling;
    if (oggetto.nodeType==3) oggetto=oggetto.nextSibling;    
    oggetto.style.visibility="visible";
    oggetto.style.display="";
    obj.firstChild.src=url;
}

function SwitchBloccoCategoria(obj,urlon,urloff,statoiniziale)
{
    if (!obj.stato) obj.stato=statoiniziale;
    if (obj.stato==1) NascondiBloccoCategoria(obj,urloff);
    else if (obj.stato==2) VisualizzaBloccoCategoria(obj,urlon);
}

var dl_sep_1 = " ";
var dl_sep_2 = " ";
function dl_create(objid, className)
{
    var obj=ffz_GetObj(objid);
    if(!obj || obj==null) return null;
    
    obj.style.display="";
    if(className && className.length && className.length>0)
        obj.className=className;
    
    return obj;
}
function dl_txt(obj, txt)
{
    obj.appendChild(document.createTextNode(txt));
}
function dl_img(obj, url)
{
    var el=document.createElement("img");
    el.src=url;
    obj.appendChild(el);
    return el;
}
function dl_a(obj, url, txt)
{
    var el=document.createElement("a");
    el.href=url;
    if(txt && txt!=null && txt.length>0)
        dl_txt(el, txt);
	dl_txt(obj, dl_sep_1);
    obj.appendChild(el);
	dl_txt(obj, dl_sep_2);
    return el;
}
function dl_a_img(obj, url_a, url_img, txt)
{
    var el=document.createElement("a");
    el.href=url_a;
    if(url_img && url_img!=null && url_img.length>0)
        dl_img(el, url_img);
    if(txt && txt!=null && txt.length>0)
        dl_txt(el, txt);
    dl_txt(obj, dl_sep_1);
	obj.appendChild(el);
	dl_txt(obj, dl_sep_2);
    return el;
}
function AggiungiItem(_mN, _aI, _copyId)
{
    if(m3_ADDLIST==null)
    {
        m3_ADDLIST=new Array();
        m3_ADDLIST.push(new Array());
        m3_ADDLIST.push(new Array());
        m3_ADDLIST.push(new Array());
    }
    m3_ADDLIST[0].push(_mN);
    m3_ADDLIST[1].push(_aI);
    m3_ADDLIST[2].push(_copyId);
}