function unique(a, key) {
    var tmp = eval("[{" + key + ":\"scegli\"}];")
    for (i = 0; i < a.length; i++) {
        if ((!contains(tmp, a[i], key)) && (trim(a[i][key]) != "")) {
            tmp.push(a[i])
        }
    }
    return tmp;
}
function contains(a, e, key) {
    for (j = 0; j < a.length; j++)
    if (a[j][key] == e[key]) return true;
    return false;
}
function splitvalue(a, key) {
    var tmp = eval("[{" + key + ":\"scegli\"}];")
    var vettore = [];
    for (i = 0; i < a.length; i++) {
        vettore = a[i][key].split(",")
        for (j = 0; j < vettore.length; j++) {
            var nuovovettore = "[{" + key + ":\" " + vettore[j] + "\"}]";
            var vettoreeval = eval(nuovovettore);
            tmp.push(vettoreeval[0]);
        }
    }
    return tmp;
}
function trim(stringa) {
    while (stringa.substring(0, 1) == ' ') {
        stringa = stringa.substring(1, stringa.length);
    }
    while (stringa.substring(stringa.length - 1, stringa.length) == ' ') {
        stringa = stringa.substring(0, stringa.length - 1);
    }
    return stringa;
}
function editStyle(id, styleName, value) {
	
	obj = getObject(id);
	if (obj != null) obj.style[styleName] = value;
}
function setVisible(id, visible) {
	if (id != null && id.length > 0) {
		if (visible) {
			editStyle(id, "display", "block");
		} else {
			editStyle(id, "display", "none");		
		}
	}
}
function switchVisible(id2Show, id2Hide) {
	
	setVisible(id2Show, true);
	setVisible(id2Hide, false);	
	return id2Show;
}
function getObject(id) {
    var object = null;
    if (document.layers) {
        object = document.layers[id];
    } else if (document.all) {
        object = document.all[id];
    } else if (document.getElementById) {
        object = document.getElementById(id);
    }
    return object;
}
function addLoadEvent(func) {
	
	/* ESEMPIO addLoadEvent */
	//addLoadEvent(nameOfSomeFunctionToRunOnPageLoad);
	
	//addLoadEvent(function () {
		/* more code to run on page load */
	//});
	var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function () {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}
function refreshIframeSrc( frameId )
{
	frame = document.getElementById( frameId );
	uri = getUrlVar('IfUri');
	frame.setAttribute('src', uri );
}
function getUrlVars()
{
	var vars = [], hash;
	var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	for(var i = 0; i < hashes.length; i++)
	{
		hash = hashes[i].split('=');
		vars.push(hash[0]);
		vars[hash[0]] = hash[1];
	}
	return vars;
}
function getUrlVar(name){
	return getUrlVars()[name];
}

