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);
}
function findPosX(obj) {
    var curleft = 0;

    if (obj.offsetParent) {
        while (1) {
            curleft += obj.offsetLeft;
            if (!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    } else if (obj.x) {
        curleft += obj.x;
    }

    obj.style.position = "static";

    return curleft;
}

function findPosY(obj) {
    var curtop = 0;

    if (obj.offsetParent) {
        while (1) {
            curtop += obj.offsetTop;
            if (!obj.offsetParent)
                break;
            obj = obj.offsetParent;
        }
    } else if (obj.y) {
        curtop += obj.y;
    }

    return curtop;
}

function findPos(obj) {
    var left = findPosX(obj);
    var top = findPosY(obj);

    return [left, top];
}

function findPosition(oElement) {
    if (typeof (oElement.offsetParent) != 'undefined') {
        for (var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent) {
            posX += oElement.offsetLeft;
            posY += oElement.offsetTop;
        }
        return [posX, posY];
    } else {
        return [oElement.x, oElement.y];
    }
}

function ffzAdPos() {
    for (var i = 0; i < AdArr.length; i += 2) {
        var oX = AdArr[i];
        var o = AdArr[i + 1];

        var xy = findPosition(oX);
        o.style.left = (xy[0] /*- 16*/) + "px";
        o.style.top = xy[1] + "px";
    }
}

function getIE()
{
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
}

var AdArr = new Array();

var az_r = Math.floor(Math.random() * 99999999);
function az_adjs_i(z, ov, oid, w, h, opa) {
    setTimeout("az_adjs_j('" + z + "', '" + ov + "', '" + oid + "', '" + w + "', '" + h + "', '" + opa + "')", 100);
}
function az_adjs_j(z, ov, oid, w, h, opa) {
    var oX = ffz_GetObj(oid); if (oX == null) return;
    oX.style.width = '' + w + 'px';
    oX.style.height = '' + h + 'px';
    oX.style.margin = 'auto';
    var o = document.createElement('div');
    var t = 1;
    if (w == 120) t = 4;
    else if (w == 300) t = 2;
    else if (w == 178) t = 3;
    var ifr = document.createElement('iframe');
    ifr.id = 'i' + oid;
    ifr.name = 'i' + oid;
    ifr.src = 'http://freeforumzone.leonardo.it/adx.aspx?t=' + t + '&z=' + z + '&s=' + w + 'x' + h + '&ov=' + ov + '&oid=' + oid + '&az_r=' + az_r + '&target=_blank';
    ifr.allowTransparency = true;
    ifr.frameSpacing = '0';
    ifr.frameBorder = '0';
    ifr.scrolling = 'no';
    ifr.width = '' + w;
    ifr.height = '' + h;
    ifr.hspace = 0;
    ifr.vspace = 0;
    ifr.marginHeight = 0;
    ifr.marginWidth = 0;
    o.style.textAlign = 'center';
    o.style.width = '' + w + 'px';
    o.style.height = '' + h + 'px';
    o.appendChild(ifr);
    ifr.style.width = '' + w + 'px';
    ifr.style.height = '' + h + 'px';
    ifr.style.margin = '0px';
    ifr.style.padding = '0px';
    ifr.style.border = '0px';
    var iev = getIE();
    if (opa && opa == "1" && (iev < 0 || iev >= 7)) {
        o.style.position = 'absolute';
        o.style.zIndex = 100;
        var ffzAdDiv = ffz_GetObj('ffzAdDiv');
        ffzAdDiv.appendChild(o);
        AdArr.push(oX);
        AdArr.push(o);
        ffzAdPos();
    }
    else {
        oX.appendChild(o);
    }
}