﻿function popup(theURL, winName, features) { //v2.0
    window.open(theURL, winName, features);
}

var ua = navigator.userAgent.toLowerCase();
var divw = 0;
var divh = 0;

if (document.getElementById || document.all)
    document.write('<div id="imgtrailer" style="position:absolute; z-index:100; visibility:hidden;"></div>')

function gettrailobject() {
    if (document.getElementById)
        return document.getElementById("imgtrailer")
    else if (document.all)
        return document.all.trailimagid
}
//
function gettrailobj() {
    if (document.getElementById)
        return document.getElementById("imgtrailer").style
    else if (document.all)
        return document.all.trailimagid.style
}

function truebody() {
    return (!window.opera && document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body
}

function trailOff() {
    document.onmousemove = '';
    gettrailobj().visibility = "hidden";
}

function trailOn(thumbimg, imgtitle, username, imgid, imgsize, credit, level, thw, thh) {
    if (ua.indexOf('opera') == -1 && ua.indexOf('safari') == -1) {
        gettrailobj().left = "-500px";
        divthw = parseInt(thw) + 2;
        gettrailobject().innerHTML = '<div style="background-color: #ffffff; layer-background-color: #ffffff;  border: 1px solid #ffffff;  padding:5px; "><div style="background-color: #FFFFFF; layer-background-color: #FFFFFF; border: 1px solid #ffffff;background-repeat: no-repeat;">' + '<img src="' + thumbimg + '" border="0" width="' + thw + '" height="' + thh + '">' + '</div><div class=yazi style="padding:1px;">' + (thw >= 233 ? '<nobr>' : '') + imgid + ' ' + level + (thw >= 233 ? '</nobr>' : '') + '' + imgsize + '</div></div>';
        gettrailobj().visibility = "visible";
        divw = parseInt(thw) + 25;
        divh = parseInt(thh) + 130;
        document.onmousemove = followmouse;
    }
}
function pencereac(thumbimg, imgtitle, thw, thh) {
    if (ua.indexOf('opera') == -1 && ua.indexOf('safari') == -1) {
        gettrailobj().left = "-500px";
        divthw = parseInt(thw) + 2;
        gettrailobject().innerHTML = '<div style="background-color: #ffffff; layer-background-color: #ffffff;  border: 1px solid #ffffff;  padding:10px; "><div style="background-color: #FFFFFF; layer-background-color: #FFFFFF; border: 1px solid #ffffff;">' + '<img src="' + thumbimg + '" border="0"></div>';
        gettrailobj().visibility = "visible";
        divw = parseInt(thw) + 25;
        divh = parseInt(thh) + 130;
        document.onmousemove = followmouse;
    }
}
function jtitle(imgtitle, thw, thh) {
    if (ua.indexOf('opera') == -1 && ua.indexOf('safari') == -1) {
        gettrailobj().left = "-500px";
        divthw = parseInt(thw) + 2;
        gettrailobject().innerHTML = '<div style="background-color: #ffffff;  layer-background-color: #ffffff;  border: 1px solid #ffffff;  padding:5px; "></div>';
        gettrailobj().visibility = "visible";
        divw = parseInt(thw) + 25;
        divh = parseInt(thh) + 130;
        document.onmousemove = followmouse;
    }
}
function followmouse(e) {
    var docwidth = document.all ? truebody().scrollLeft + truebody().clientWidth : pageXOffset + window.innerWidth - 15
    var docheight = document.all ? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(document.body.offsetHeight, window.innerHeight)
    if (typeof e != "undefined") {
        if (docwidth < 15 + e.pageX + divw)
            xcoord = e.pageX - divw - 5;
        else
            xcoord = 15 + e.pageX;
        if (docheight < 15 + e.pageY + divh)
            ycoord = 15 + e.pageY - Math.max(0, (divh + e.pageY - docheight - truebody().scrollTop - 30));
        else
            ycoord = 15 + e.pageY;
    }
    else if (typeof window.event != "undefined") {
        if (docwidth < 15 + truebody().scrollLeft + event.clientX + divw)
            xcoord = truebody().scrollLeft - 5 + event.clientX - divw;
        else
            xcoord = truebody().scrollLeft + 15 + event.clientX;

        if (docheight < 15 + truebody().scrollTop + event.clientY + divh)
            ycoord = 15 + truebody().scrollTop + event.clientY - Math.max(0, (divh + event.clientY - docheight - 30));
        else
            ycoord = truebody().scrollTop + 15 + event.clientY;
    }
    gettrailobj().left = xcoord + "px"
    gettrailobj().top = ycoord + "px"
}

measureUnit = "px"

minSize = 1;

minStyleSize = 10;

maxSize = 6;

maxStyleSize = 30;

startSize = 1;

startStyleSize = 10;

stepSize = 1;

stepStyleSize = 2;

var keyin = 61;
var keyinCAPS = 43;

var keyout = 45;
var keyoutCAPS = 95;

var keyinIe = 46;
var keyinIeCAPS = 62;

var keyoutIe = 44;
var keyoutIeCAPS = 60;

var zoomFactor = 1.1;

var maxZoom = 4.096;

var minZoom = 0.625;

var startDecZoom = 0.7;

var startIncZoom = 1.3;

userExpiry = 365 * 24 * 60 * 60 * 1000;

alertEnabled = false;

allowInputResize = false;

function setCookie(name, value, expires, path, domain, secure) {

    document.cookie = "Enabled=true";
    var cookieValid = document.cookie;

    if (cookieValid.indexOf("Enabled=true") != -1) {
        var curCookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");

        document.cookie = curCookie;
        return (true);
    }
    else {
        return (false);
    }
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else
        begin += 2;
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
        end = dc.length;
    return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function fixDate(date) {
    var base = new Date(0);
    var skew = base.getTime();
    if (skew > 0)
        date.setTime(date.getTime() - skew);
}

function searchTags(childTree, level) {
    var retArray = new Array();
    var tmpArray = new Array();
    var j = 0;
    var childName = "";
    for (var i = 0; i < childTree.length; i++) {
        childName = childTree[i].nodeName;
        if (childTree[i].hasChildNodes()) {
            if ((childTree[i].childNodes.length == 1) && (childTree[i].childNodes[0].nodeName == "#text"))
                retArray[j++] = childTree[i];
            else {
                tmpArray = searchTags(childTree[i].childNodes, level + 1);
                for (var k = 0; k < tmpArray.length; k++)
                    retArray[j++] = tmpArray[k];
                retArray[j++] = childTree[i];
            }
        }
        else
            retArray[j++] = childTree[i];
    }
    return (retArray);
}

function changeFontSize(stepSize, stepStyleSize, useCookie) {

    if (document.body) {
        var myObj = searchTags(document.body.childNodes, 0);
        var myCookieSize = parseInt(getCookie("incrSize"));
        var myCookieStyleSize = parseInt(getCookie("incrStyleSize"));
        var myStepSize = stepSize;
        var myStepStyleSize = stepStyleSize;

        var now = new Date();

        fixDate(now);

        if (isNaN(myCookieSize)) myCookieSize = 0;
        if (isNaN(myCookieStyleSize)) myCookieStyleSize = 0;

        if (useCookie) {
            myStepSize = myCookieSize;
            myStepStyleSize = myCookieStyleSize;
        }

        now.setTime(now.getTime() + userExpiry);

        myObjNumChilds = myObj.length;
        for (i = 0; i < myObjNumChilds; i++) {
            myObjName = myObj[i].nodeName;

            if (myObjName != "#text" && myObjName != "HTML" &&
          myObjName != "HEAD" && myObjName != "TITLE" &&
          myObjName != "STYLE" && myObjName != "SCRIPT" &&
          myObjName != "BR" && myObjName != "TBODY" &&
          myObjName != "#comment" && myObjName != "FORM") {

                if (!allowInputResize && myObjName == "INPUT") continue;

                size = parseInt(myObj[i].getAttribute("size"));

                if (myObj[i].currentStyle)
                    styleSize = parseInt(myObj[i].currentStyle.fontSize);
                else
                    styleSize = parseInt(window.getComputedStyle(myObj[i], null).fontSize);

                if (isNaN(size) || (size < minSize) || (size > maxSize))
                    size = startSize;

                if (isNaN(styleSize) || (styleSize < minStyleSize) || (styleSize > maxStyleSize))
                    styleSize = startStyleSize;

                if (((size > minSize) && (size < maxSize)) ||
             ((size == minSize) && (stepSize > 0)) ||
             ((size == maxSize) && (stepSize < 0)) || useCookie) {
                    myObj[i].setAttribute("size", size + myStepSize);
                }

                if (((styleSize > minStyleSize) && (styleSize < maxStyleSize)) ||
             ((styleSize == minStyleSize) && (stepStyleSize > 0)) ||
             ((styleSize == maxStyleSize) && (stepStyleSize < 0)) || useCookie) {
                    newStyleSize = styleSize + myStepStyleSize;
                    myObj[i].style.fontSize = newStyleSize + measureUnit;
                }
            }
        }

        if (!useCookie) {
            cookieIsSet = setCookie("incrSize", myStepSize + myCookieSize, now);
            cookieIsSet = setCookie("incrStyleSize", myStepStyleSize + myCookieStyleSize, now);
            if (alertEnabled && !cookieIsSet) {
                alert("Per mantenere in memoria la dimensione scelta, abilita i cookie nel browser");
            }
        }
    }
}

function increaseFontSize() {
    if (document.body) {
        changeFontSize(stepSize, stepStyleSize, false);
    }
    else {
        if (alertEnabled) {
            alert("Spiacente, il tuo browser non supporta questa funzione");
        }
    }
}

function decreaseFontSize() {
    if (document.body) {
        myStepSize = -stepSize;
        myStepStyleSize = -stepStyleSize;
        changeFontSize(myStepSize, myStepStyleSize, false);
    }
    else {
        if (alertEnabled) {
            alert("Spiacente, il tuo browser non supporta questa funzione");
        }
    }
}

function zoomin() {
    if (window.parent.document.body.style.zoom < maxZoom) {
        if (window.parent.document.body.style.zoom > 0) {
            window.parent.document.body.style.zoom *= zoomFactor;
        }
        else {
            window.parent.document.body.style.zoom = startIncZoom;
        }
    }
    else {
        if (alertEnabled) {
            alert("Warning: Max size reached");
        }
    }
}

function zoomout() {
    if ((window.parent.document.body.style.zoom > minZoom) ||
       (window.parent.document.body.style.zoom == 0)) {
        if (window.parent.document.body.style.zoom > 0) {
            window.parent.document.body.style.zoom /= zoomFactor;
        }
        else {
            window.parent.document.body.style.zoom = startDecZoom;
        }
    }
    else {
        if (alertEnabled) {
            alert("Warning: Min size reached");
        }
    }
}

function checkzoom(e) {

    if (document.all) {
        myEvent = event.keyCode;
    }
    else {
        myEvent = e.which;
    }

    switch (myEvent) {
        case keyinIe:
        case keyinIeCAPS:
            zoomin();
            break;

        case keyoutIe:
        case keyoutIeCAPS:
            zoomout();
            break;

        case keyin:
        case keyinCAPS:
            increaseFontSize();
            break;

        case keyout:
        case keyoutCAPS:
            decreaseFontSize();
            break;

        default:
            break;
    }
}

if (document.layers) {
    document.captureEvents(Event.KEYPRESS);
}

document.onkeypress = checkzoom;