/*
**********************************************************************************
*                                                                                *
*                            FUNZIONI PER LE FOTO                                *
*                                                                                *
**********************************************************************************
*/
function zoomFoto(nomeFile) {
	var w = window.open("../upload/" + nomeFile, "_blank", "toolbars=0, resizable");
	w.focus();
}


function zoomFotoNew( imgName, imgCaption) {
	
	textColor = "#000000";
	bgColor = "#ffffff";
	chars = imgCaption.length*10;
		
	w = window.open('','Foto','toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width=800,height=650');
	w.document.write( "<html><head><title>Fondazione Pertini</title>" );
	w.document.write( "	<link href='../css/default1.css' rel='stylesheet' type='text/css'>" );
	w.document.write( "<script language='JavaScript'>\n");
	//w.document.write( "IE5=NN4=NN6=false\n");
	w.document.write( "if(document.all)IE5=true;\n");
	//w.document.write( "else if(document.getElementById)NN6=true\n");
	//w.document.write( "else if(document.layers)NN4=true\n");
	w.document.write( "function autoSize() {\n");
	w.document.write( " imgH=document.images[0].height\n");
	w.document.write( " imgW=document.images[0].width\n");
  w.document.write( "	if(IE5 && (imgH<=800)) { \n");
	w.document.write( " if ("+chars+">imgW) test= 17+18*("+chars+"/imgW)\n");
	w.document.write( "	else if("+chars+"!=0) test=30\n");
	w.document.write( "	else test=0\n");
	w.document.write( " self.resizeTo(document.images[0].width+50,document.images[0].height+108+test)\n");
	w.document.write( " }\n");
	w.document.write( " else { \n");
	w.document.write( " document.all['imgBody'].scroll='yes'; \n");
	w.document.write( " self.resizeTo(document.images[0].width+40,650)\n");
	w.document.write( " }\n");
	// w.document.write( "	else top.window.resizeTo(document.images[0].width,document.images[0].height+55+test)\n");
	w.document.write( "	self.focus()\n");
    w.document.write( "}\n</scr");
	w.document.write( "ipt>\n");
	w.document.write( "</head><body id='imgBody' leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 onLoad=" );
	w.document.write( "'javascript:autoSize();'>");
	w.document.write( "<table cellpadding=5 cellspacing=0 border=0 align='center' width='100%' class='sfondoGrigio'>");
	w.document.write( "<tr><td colspan=2 align='center'>&nbsp;</td></tr>" );
	w.document.write( "<tr><td colspan=2 align='center'><img src='"+imgName+"' border=0></td></tr>" );
	w.document.write( "<tr><td align='center' colspan='2'><b>"+imgCaption+"</b></td></tr>" );
  w.document.write( "<tr><td align='left'></td><td align='right'><a href='javascript:top.window.close();'>[Chiudi]</a></td></tr>");
	w.document.write( "</table>");
  w.document.write( "</body></html>" );
	w.document.close();
}

/*
**********************************************************************************
*                                                                                *
*                   FUNZIONI PER LE CANCELLAZIONE NOTIZIE                        *
*                                                                                *
**********************************************************************************
*/
// Cancellazione Notizie
function elimina() {
	if (!confirm("Procedere con l'eliminazione?")) {
		return false;
	}
}

/*
**********************************************************************************
*                                                                                *
*                            FUNZIONI PER LA RICERCA                             *
*                                                                                *
**********************************************************************************
*/
// Controlla Testo cercato
function controllaTesto(testo){
	if(testo == "") {
		alert("Immettere un testo da cercare");
		return false;
	}
}

function pulisciRicerca(testo) {

	if(testo == "Cerca qui") {
		document.all.ricerca.cerca.value = "";
	}
}
/*
**********************************************************************************
*                                                                                *
*                           FUNZIONI PER LA GESTIONE                             *
*                                                                                *
**********************************************************************************
*/

function visualizzaSezioni(url,idsez) {
	var w = window.location.replace(url + "?idsez=" + idsez);
}

function visualizzaSottoSezioni(url,idsottosez,idsez) {
	var w = window.location.replace(url + "?idsottosez=" + idsottosez + "&idsez=" + idsez);
}

function gestione_sottosez(sottosezione) {
	if(sottosezione == "") {
		alert("Il nome della sottosezione è obbligatorio");
		return false;
	}
	else {
		return true;
	}
}

function gestione_link(nome, nomelink) {
	if(nome == "" || nomelink == "") {
		alert("La il nome e il link sono obbligatori");
		return false;
	}
	else {
		return true;
	}
}

function caricaImmagini(idcontenuto) {
	var w = window.open("gestione_immagini_aggiuntive.asp?idcontenuto=" + idcontenuto, "IMMAGINI", "width=550 height=330");
	w.focus();
}

function caricaDocumenti(idcontenuto) {
	var w = window.open("gestione_documenti_aggiuntivi.asp?idcontenuto=" + idcontenuto, "DOCUMENTI", "width=550 height=330");
	w.focus();
}


function rimuoviImg(valore, i) {
	arrDell = new Array(1);
	arrDell[1] = 'txt_del_img' + i;
	document.forms[0].elements[arrDell[1]].value = valore;
}

function rimuoviDoc(valore, i) {
	arrDell = new Array(1);
	arrDell[1] = 'txt_del_doc' + i;
	document.forms[0].elements[arrDell[1]].value = valore;
}


//Chiusura automatica pagina upload immagini
function chiudiPagina(ChiudiFinestra) {
	if(ChiudiFinestra == 'OK') {
		opener.location.reload();
		self.close();
	}
}

// Imposto il valore dei campi hidden nelle form con upload immagini
function impostaValore(nome, valore) {
	var nomeCampo;
	nomeCampo = "txt_" + nome;

	document.all[nomeCampo].value = valore;
}


function impostaValore2(indice, valore) {
	var nome = "txt_vis" + indice;
	document.all[nome].value = valore;
}

/*
**********************************************************************************
*                                                                                *
*                       FUNZIONI PER I FOGLI DI STILE                            *
*                                                                                *
**********************************************************************************
*/
// La funzione per cambiare i fogli di stile
function templateChange(valore){
	//controllo browser
	if(!document.styleSheets){
		var ss = getAllSheets() //Opera
	}
	else{
		var ss = document.styleSheets; //Dom
	}
	// disabilita tutti i fogli di stile con un titolo 
	// tranne quello passato per argomento alla funzione
	for(var x = 0; x < ss.length; x++ ) {
		if(ss[x].title ) {
			ss[x].disabled=true;
		}
		for( var y = 0; y < arguments.length; y++ ) {
			//controlla ogni titolo ...
			if(ss[x].title == arguments[y]){
				//e riabilita il foglio di stile se ha il titolo scelto
				ss[x].disabled=false;
			}
		}
		//document.all.sel_caratteri.options[document.all.sel_caratteri.selectedIndex].selected;
	}
	if( !ss.length ) { 
		alert( 'Il tuo browser non è abilitato a cambiare i fogli di stile CSS' );
	}
		window.self.location.reload();
//		window.top.frames["serviceFrame"].location.replace("service.asp?font=" + document.all.sel_caratteri.selectedIndex);
		window.top.frames["serviceFrame"].location.replace("service.asp?font=" + valore);		
}

// ---------------------------------------------------------------------------------

// Funzione per Opera
function getAllSheets(){
	if( document.getElementsByTagName ) {
		var Lt = document.getElementsByTagName('LINK');
		var St = document.getElementsByTagName('STYLE');
	} else {
		// browser minori - restituisce array vuoto
		return []; 
	}
	//per tutti i tag link ...
	for( var x = 0, os = []; Lt[x]; x++ ) {
		//controlla l'attributo rel per vedere se contiene 'style'
		if( Lt[x].rel ) {
			var rel = Lt[x].rel;
		} else if( Lt[x].getAttribute ) {
			var rel = Lt[x].getAttribute('rel');
		} else {
			var rel = '';
		}
		if(typeof(rel)=='string'&&rel.toLowerCase().indexOf('style')+1){
			//riempe la variabile os con i stylesheets linkati
			os[os.length] = Lt[x];
		}
	}
	//include anche tutti i tags style e restituisce l'array
	for( var x = 0; St[x]; x++ ) {
		os[os.length] = St[x];
	}
	return os;
}
