/*
 * Cambia l'opacita' per tutti i browser
 */
function setOpacity(id, opacity) {
    object = document.getElementById(id).style;
    object.opacity = opacity;
	object.MozOpacity = opacity;
	object.KhtmlOpacity = opacity;
	object.filter = "alpha(opacity=" + (opacity * 100) + ")";

    if (opacity < .9) {
        object.filter= object.filter + " Gray()"
    }

}


/*
 * Apre/chiude un menu della colonna sinistra
 */

MAX_SEZ = 200;

function apri(id) {
	sezione = document.getElementById("sezione_" + id);
	if (sezione) {
		if (sezione.style.display == "none")
			sezione.style.display = "";
		else
			sezione.style.display = "none";
    }

    for (i=1; i<=MAX_SEZ; i++) {
    	currSez = document.getElementById("sezione_" + i);
        if (currSez && i != id) {
            currSez.style.display = "none";
        }
    }
    return false;
}

/*
 * Cambia la pagina corrente nei menu a tendina
 */

function cambia_pagina(select) {
	docs = select.options;
	indice = select.selectedIndex;
	if (indice > 0) {
		url = docs[indice].value;
		location.href = url;
	}
}


var nuova = null;

/*
 * Apre una nuova finestra e le da' il focus
 */
function apri_nuova(url) {
	if (nuova == null) {
		nuova = window.open(url);
	} else {
		nuova.location.replace(url);
	}
	nuova.focus();
	return false;
}


/*
 * dim | body {font-size: }
 *  1  |  .8em
 *  2  |  1em
 *  3  |  1.2em
 *  4  |  1.4em
 */

function setSize(dim) {
    body = document.getElementsByTagName("body").item(0);
    if (dim != 0) {
        size = 1 + (dim - 3) * 0.2;
        fontSize = size + "em";
        body.style.fontSize = fontSize;
        createCookie ("fontSize", dim, 300);
    }

    if (dim == 0) {
        cookie = readCookie("fontSize");
        if (cookie != null) {
			cookie = cookie.replace(/[^0-9]/g , '');
            size = parseInt(cookie, 10);
            size = 1 + (size - 3) * 0.2;
            fontSize = size + "em";
            body.style.fontSize = fontSize;
        }
    }

}

/*
 * Esegue il rollover sui blocchi grigi alti per le tre sezioni del sito
 */


function swap(img) {
    src = img.src;
    dotPos = src.lastIndexOf('.');
    basePath = src.substring(0, dotPos)
    ext = src.substring(dotPos)

    if (src.lastIndexOf("_ro.") == src.length - 7) {
        nuova = basePath.substring(0, basePath.length - 3) + ext
    }
    else {
        nuova = basePath + "_ro" + ext
    }

    img.src = nuova;

}

/*
 * Mostra nasconde il menu dei servizi informatici
 */

aperto = 0;

function show_servizi() {
	menu_servizi = document.getElementById("servizi_informatici");
	form_ricerca = document.getElementById("searchForm");
	menu_servizi.style.display = "block";
	form_ricerca.style.visibility = "hidden";
	aperto = 1;
}

function gestione_servizi(evt) {
	menu_servizi = document.getElementById("servizi_informatici");
	form_ricerca = document.getElementById("searchForm");

	if (!evt)
		evt = window.event;

	source = "";
	if (evt.srcElement)
		source= evt.srcElement;
	if (evt.target)
		source = evt.target;

	sopra = 0;

	if (source == menu_servizi || source.parentNode == menu_servizi || source.parentNode.parentNode == menu_servizi) {
		sopra = 1;
		aperto = 0;
	}

	if (aperto == 1){
		sopra = 1;
	}

	if (!sopra) {
		menu_servizi.style.display = "none";
		form_ricerca.style.visibility = "visible";
	}

}
