// JavaScript Document
function Help(url) {
	alert("Il tuo browser non supporta file di script esterni.\nSpiacenti!") ;
}

window.onload = externalLinks;
//window.onload = function() {
//var links = document.links || document.getElementsByTagName('a');
//var n = links.length;
//for (var i = 0; i < n; i++) {
//	if (links[i].title && links[i].title != '') {
// 		add the title to anchor innerhtml
//		links[i].innerHTML += '<span><em>'+links[i].title+'</em><br>'+links[i]+'</span>'; 
//		links[i].title = ''; // remove the title
//	}
//}


function submitPagina(nome, sParametro){
	fObj = document.getElementById(nome);
	fObj.action = sParametro;
	fObj.submit();
}

function mostraFormCommenti () {
	var ele = document.getElementById("toggleText");
	var text = document.getElementById("NuovoCommento");
	var titolo = document.getElementById("form_titolo");
	ele.style.display = "block";
	text.innerHTML = "Inserisci il tuo commento";
	document.anchors["NuovoCommento"].removeAttribute("href");
	titolo.style.backgroundColor = "#806633";
}

function nascondiFormCommenti() {
	var ele = document.getElementById("toggleText");
	var text = document.getElementById("NuovoCommento");
	var titolo = document.getElementById("form_titolo");
	ele.style.display = "none";
	titolo.style.backgroundColor = "#ff8300";
	//titolo.innerHTML = "<a id='NuovoCommento' href='javascript:mostraFormCommenti()'>Clicca per inserire un tuo commento</a>
	document.anchors["NuovoCommento"].setAttribute("href","javascript:mostraFormCommenti()");
	text.innerHTML = "Clicca per inserire un tuo commento";
	//il problema qui è che IE non rileva le anchor se non per id numerico...
}

//popola con valori presi da un array una selectbox
function populateSelectBox(oBox, nIndex, aArray, sNewOption){
	if (aArray.length >= nIndex && aArray[nIndex]){
		for (var i = 0; i < aArray[nIndex].length; i++){
			oBox.options[oBox.options.length] = new Option(aArray[nIndex][i],aArray[nIndex][i]);
		}
	} else {
		oBox.options[oBox.options.length] = new Option(sNewOption, 0);
	}
}

//svuota selectbox
function clearSelectBox(oBox){
	for (var i = oBox.options.length-1; i>=0; i--){
			oBox.options[i] = null;
	}
	oBox.selectedIndex = -1;
}

//escape elementi di un array
function  array_escape(tab) {
    var key;
    for (key in tab) {
		if (is_array(tab[key]))
			array_escape(tab);
		else
			tab[key] = escape(tab[key]);
		}
    return(tab);
}

function externalLinks() {
	if (!document.getElementsByTagName) return; 
	var anchors = document.getElementsByTagName("a"); 
	for (var i=0; i<anchors.length; i++) { 
		var anchor = anchors[i]; 
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
			anchor.target = "_blank";
		}
	}
}
