function randomHeader() {
	var divFoto = document.getElementById("foto_header");
	//var nuovoDiv  = document.createElement('div');
	var rand = 1;
	while (rand == 1)
		rand = Math.random();
	alert(rand);
	var nuovoId = "foto_header_" + Math.trunc(rand*10)+1;
	divFoto.id = nuovoId;
	//nuovoDiv.id = nuovoId;
	//divFoto.parentNode.appendChild(nuovoDiv);
	//divFoto.parentNode.removeChild(divFoto);
}
			

function estensione(path) {
   var posizionePunto = path.lastIndexOf(".");
	var ext = path.substring(posizionePunto+1);
	return ext;
			}

function stiliFile() {
	
	var anchors = document.getElementsByTagName("a");
	var cont = 0;
	var arrFile = new Array();
	for(var i=0; i < anchors.length; i++)
	{
		var a = anchors[i];
		var clattr = "";
		var browser = navigator.appName;
		if (browser=="Microsoft Internet Explorer")
		    clattr = "className";
		else
		    clattr = "class";
		var classe = a.getAttribute(clattr);
		
		if ((classe == "download") && (a.parentNode.tagName == "LI")) {
			/*arrFile[cont] = a.parentNode.cloneNode(true);*/
			var listItem = document.createElement('li');			
			var linkFile = a.cloneNode(true);
			listItem.appendChild(linkFile);
			arrFile[cont] = listItem;
			var href = a.getAttribute("href");
			var ext = estensione(href);
			var ucext = ext.toUpperCase();
			var lcext = ext.toLowerCase();
			/*var anchorspdf = arrFile[cont].getElementsByTagName("a");*/
			if ((ucext=='PDF') || (ucext=='RTF') || (ucext=='XLS') || (ucext=='DOC') || (ucext=='DWF') || (ucext=='GIF') || (ucext=='ODP') || (ucext=='ODS') || (ucext=='ODT') || (ucext=='PPT')){
				//a.parentNode.setAttribute("class","download"+lcext);
				a.parentNode.className = "download"+lcext;
				linkFile.innerHTML='<img src="fileadmin/templates/icone/ico_'+lcext+'.gif" alt="icona '+lcext+'" />'+linkFile.innerHTML;
			}
			else{
				//a.parentNode.setAttribute("class","download");
				a.parentNode.className = "download";
				linkFile.innerHTML='<img src="fileadmin/templates/icone/ico_download_generico.gif" alt="icona download file" />'+linkFile.innerHTML;
			}
			cont++;
	   }
	   
	}
	var divDownload = document.getElementById("riquadro_download");
	if (arrFile.length > 0){
		var divInterno  = document.createElement('div');
		//divInterno.setAttribute('class','nome_menu');
		divInterno.className = 'nome_menu';
      var strDownload = document.createTextNode('Download');
      divInterno.appendChild(strDownload);
      divDownload.appendChild(divInterno);
      var ulDownload = document.createElement('ul');
      ulDownload.setAttribute('id','submenu_download');
		for(var i=0; i < arrFile.length; i++)
			ulDownload.appendChild(arrFile[i]);
		divDownload.appendChild(ulDownload);
	}
	else{
		var contenitore = document.getElementById('riquadro_download');
		while (contenitore.hasChildNodes())
		  contenitore.removeChild(contenitore.firstChild);
	}
}

function rmFoto() {
	var divColCenter = document.getElementById("col_center");
	var arrDiv = document.getElementsByTagName("div");
	for(var i=0; i < arrDiv.length; i++)
	{
		var divI = arrDiv[i];
		if (divI.className=="foto_pw"){
			//alert("trovato div foto");
			var anchor = divI.getElementsByTagName("a");
			if (anchor[0].innerHTML=="")
				divI.parentNode.removeChild(divI);
		}
	}
}

function autoResize(id){
    var newheight;
    //var newwidth;

    //if (document.getElementById(id)){
        //newheight = document.getElementById(id).contentWindow.document.body.scrollHeight;
        var newheight = document.getElementById('id').contentWindow.document.body.scrollHeight;
       // newwidth=document.getElementById(id).contentWindow.document.body.scrollWidth;
    //}

    document.getElementById(id).height = (newheight) + "px";
    //document.getElementById(id).width = (newwidth) + "px";
}
/*
function TargetBlank() {
	if(document.getElementsByTagName){
		var msg = " (collegamento in nuova finestra)";
		alert(msg)
		var links = document.getElementsByTagName("a");
		for (i = 0; i < links.length; i++) {
			var link = links[i];
			if (link.className.indexOf("external-link-new-window") != -1){
				link.title = msg;
				var fn = function () {
					window.open(this.href); return false; 
				}
				link.onclick = link.onkeypress = fn;
			}
		}
	}
}
*/

/*
function novita() {
	var divColDx = document.getElementById("col_dx");
	var arrayDiv = divColDx.getElementsByTagName("div");
	var cont = 0;
	offset = -1;
	for (var i=0; i < arrayDiv.length; i++){
		var elementoDiv = arrayDiv[i];
		var classe = elementoDiv.getAttribute(clattr);
		if classe == "date_news_dx" {
			cont++;
			if (offset<0) offset=i;
		}
	}
	arrayDiv[offset+cont].className = "last_date_news_dx";
}
*/


function novita() {
	var divColDx = document.getElementById("col_dx");
	var arrayDiv = divColDx.getElementsByTagName("div");
	var cont = 0;
	var offset = -1;
	for (var i=0; i < arrayDiv.length; i++){
		var elementoDiv = arrayDiv[i];
		var classe = elementoDiv.getAttribute("class");
		if (classe == "date_news_dx") {
			cont++;
			if (offset<0) {
				offset=i;
			}
		}
	}
	var indice = offset+(2*cont)-1;
	arrayDiv[indice].className = "last_date_news_dx";
}


function stileNews(colonnaCentrale) {
	var divCenter = document.getElementById(colonnaCentrale);
	var arrDiv = divCenter.getElementsByTagName("div");
	for(var i=0; i < arrDiv.length; i++){
		var divI = arrDiv[i];
		if (divI.className == "riga_text"){
			var arrHr = divI.getElementsByTagName("hr");
			var hr = arrHr[0];
			var arrImg = divI.getElementsByTagName("img");
			var indComStampa = -1;
			var indNotizie = -1;
			for (var j=0; j < arrImg.length; j++){
				var img = arrImg[j];
				var source = img.src;
				var startIndex = source.lastIndexOf("/")+1;
				var len = source.length;
				var nomeFile = source.substr(startIndex,len);
				/*alert(nomeFile);*/
				if (nomeFile == "ico_comunicato_stampa_01.gif") {
					indComStampa = j;
				}
				if (nomeFile == "ico_notizie.gif") {
					indNotizie = j;
				}
			}
			/*alert ("Comunicato stampa: " + indComStampa + "; Notizie: " + indNotizie );*/
			if (!(indComStampa < 0) && !(indNotizie < 0)) {
				divI.removeChild(arrImg[indNotizie]);
			}
			if (indComStampa < 0 && indNotizie >= 0) {
				hr.className = "hr_blu";
			}
		}
	}
}


function flvplayerpagebrowser() {
	var divEsterno = document.getElementById("flvplayercaption");
	var divs = divEsterno.getElementsByTagName("div");
	var divpaginatore = document.getElementById("divpaginatore");
	var clattr = "";
	var browser = navigator.appName;
	if (browser=="Microsoft Internet Explorer")
		clattr = "className";
	else
		clattr = "class";
	var numdiv = divs.length;
	var iesimo=-1;
	for (var i=0; i < numdiv; i++){
		var divi = divs[i];
		var classediv = divi.getAttribute(clattr);
		if (classediv == "flvplayer_pagebrowser")
			iesimo=i;
			
	}
	var paginatore = divs[iesimo].cloneNode(true);
	divpaginatore.appendChild(paginatore);
}


function init(){
 	stiliFile();
}

function initHome(){
 	rmFoto();
 	stileNews("col_center");
 	novita();
}

function initNews(){
	rmFoto();
	stileNews("col_center_interno");
}

function initfilm(){
 	stiliFile();
 	//flvplayerpagebrowser();
 	
}

