// JavaScript Document
function openBrWindow(theURL,winName,features) {
  gwnd=window.open(theURL,winName,features);
  gwnd.focus();
}

// funzioni per il menu laterale-->
var caution = false
function setCookie(name, value, expires, path, domain, secure) {
        var curCookie = name + "=" + escape(value) +
                ((expires) ? "; expires=" + expires.toGMTString() : "") +
                ((path) ? "; path=" + path : "") +
                ((domain) ? "; domain=" + domain : "") +
                ((secure) ? "; secure" : "")
        if (!caution || (name + "=" + escape(value)).length <= 4000)
                document.cookie = curCookie
        else
                if (confirm("Cookie exceeds 4KB and will be cut!"))
                        document.cookie = curCookie
}
function getCookie(name) {
        var prefix = name + "="
        var cookieStartIndex = document.cookie.indexOf(prefix)
        if (cookieStartIndex == -1)
                return null
        var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
        if (cookieEndIndex == -1)
                cookieEndIndex = document.cookie.length
        return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}
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 item(parent, text, depth, geoId) {
        this.parent = parent;
        this.text = text;
        this.depth = depth;
        this.name = text;
        this.geoId = geoId;
        this.style="basictitlenounderline";
}
function makeArray(length) {
        this.length = length
}

function setStates() {
        var storedValue = getCookie("outline")
        if (!storedValue) {
                for (var i = 0; i < outline.length; i=i+1) {
                        if (outline[i].depth == 0)
                                outline[i].state = true
                        else
                              outline[i].state = false
                }
        } else {           
                for (var i = 0; i < outline.length; i=i+1) {
                        if (storedValue.charAt(i) == '1')
                                outline[i].state = true
                        else
                                outline[i].state = false
                }
        }
}

function setTexts() {
var temp
        for (var i = 0; i < outline.length; i=i+1) {

		temp=outline[i].text;

       /* if (outline[i].state)
           if (outline[i].parent){
                if(outline[i].depth==0)
                    outline[i].text ='&nbsp;<a href="javascript:toggle(' + i + ')" style="color:#f09900;"/>'+temp +'</a>';
                else if(outline[i].depth==1)
                    outline[i].text ='&nbsp;&nbsp;&nbsp;<a href="javascript:toggle(' + i + ')" style="color:#f09000;"/>'+temp +'</a>';
                 else if(outline[i].depth==2)
                    outline[i].text ='<a href="javascript:toggle(' + i + ')" style="color:#f09900;"/>'+temp +'</a>';

            } else // outline[i] is only a child (not a parent){*/
                          outline[i].text = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A HREF="JavaScript:selectItem(' + i + ');" ><font color="#f09000">' + temp + '</font></a>'
       }

  }

function setImages() {

        for (var i = 0; i < outline.length; i=i+1) {
              /*  if (outline[i].state)
                        if (outline[i].parent)
                                   if (outline[i + 1].state)
									{// outline[i] is exploded
                                       // outline[i].pic = '<A HREF="javascript:toggle(' + i + ')">-</A>';
										outline[i].bgcol = '#F7E89F'; //0066cc
										outline[i].style = '';
									}
                                     else
									{
									    if(outline[i].depth==0) {
										    outline[i].bgcol = '#F5DEB3'//giallo napoli
										 }
									    if(outline[i].depth==1) {
										    outline[i].bgcol = '#f0f0f0'//'0044aa';
										}
									}
                        else // outline[i] is only a child (not a parent)
							{*/
                               
								outline[i].bgcol ='#FFF5EE' // '0088ee';
							//}

        }
}
function toggle(num) {

        for (var i = 0; i < outline.length; i=i+1){
            if (i != num) {
                if (!isAncestor(i, num) && isExploded(i)) {
                    setExploded(i, false);
                }
            } else {
               setExploded(num, !isExploded(num));
            }
        }
        setStorage()
        history.go(0)
}

function getParent(num) {
        for (var i = num ; i > -1; i=i-1) {
             if (outline[i].depth  < outline[num].depth ) {
                 return i;
             }
        }
        return num;
}

function isAncestor(i, num) {
    var j = num;
    var p = getParent(num);

    if (i>j)
        return false;

    while (j != p) {
        if (i == p) {
            return true;
        }
        j = p;
        p = getParent(j);
    }

    return (i == p);
}

//function isChild(i, num) {
//    return (num == getParent(i));
//}

function isExploded(num) {
    if (outline[num].parent)
        return outline[num + 1].state;
    else
        return false
}

function setExploded(num, state) {
    for (var i = num + 1; (i < outline.length) && (outline[i].depth >= outline[num].depth + 1); i=i+1) {
        if (outline[i].depth == outline[num].depth + 1) {
             outline[i].state = !outline[i].state;
        }
    }
}

function setStorage() {
        var text = ""
        for (var i = 0; i < outline.length; i=i+1) {
                text += (outline[i].state) ? "1" : "0"
        }
        setCookie("outline", text)
}
// fine funzioni per il menu laterale-->

function mostraCampiAvanzati(state){
                if(state){
                    document.all.campiAvanzati.style.display="block";
                } else {
                    document.all.campiAvanzati.style.display="none";
                }
            }
