/*
 * Apre popup per la home page
 */

function popup() {
    window.open("importante.htm", "", "width=456,height=500,resizable=1");
}


/**
 *
 * FUNZIONI per la sfumatura del banner nelle pagine interne
 *
 */

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 99.9; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}


currImage = 1;
max_images = 2;
id_img = "img-home";
id_div = "div-img-home";
change_image_time = 10000; // 10 secondi di attesa prima del cambio immagine
fade_time = 1000; // 1 secondo per sfumare tra un'immagine e l'altra


function sfumatura() {
    setTimeout("cambia_img()", change_image_time);
}

function cambia_img() {
	if (currImage < max_images) {
		currImage ++;
	}
	else {
		currImage = 1;
	}
	blendimage(id_div, id_img, "img/banner_interna_" + currImage + ".jpg", fade_time);
    setTimeout("cambia_img()", change_image_time);
}




/*
 * Codice per creare l'id dei documenti in base al titolo
 */

function setId(title_field) {

MAX_LENGTH = 30;

mapping = {138: 's', 140: 'OE', 142: 'z', 154: 's', 156: 'oe', 158: 'z', 159: 'Y', 
192: 'A', 193: 'A', 194: 'A', 195: 'A', 196: 'A', 197: 'a', 198: 'E', 199: 'C', 
200: 'E', 201: 'E', 202: 'E', 203: 'E', 204: 'I', 205: 'I', 206: 'I', 207: 'I', 
208: 'D', 209: 'n', 211: 'O', 212: 'O', 214: 'O', 216: 'O', 217: 'U', 218: 'U', 
219: 'U', 220: 'U', 221: 'y', 223: 'ss', 224: 'a', 225: 'a', 226: 'a', 227: 'a', 
228: 'a', 229: 'a', 230: 'e', 231: 'c', 232: 'e', 233: 'e', 234: 'e', 235: 'e', 
236: 'i', 237: 'i', 238: 'i', 239: 'i', 240: 'd', 241: 'n', 242: 'o', 243: 'o', 244: 'o', 
246: 'o', 248: 'o', 249: 'u', 250: 'u', 251: 'u', 252: 'u', 253: 'y', 255: 'y'};	
	
	
	title = title_field.value;
	id_field = document.edit_form.id;

// Creo l'id solo se non esiste gia'
	if (id_field.value == '') {
		title = title.toLowerCase(); // tutto minuscolo
		title = title.replace(/^ +/g, ''); // elimino spazi iniziali
		title = title.replace(/ +$/g, ''); // elimino spazi finali
		title = title.replace(/ +/g, '-'); // converto spazi multipli in trattino

// Converto i caratteri accentati nei corrispondenti caratteri senza accento
		id = "";
		for (i = 0; i<title.length; i++) {
			charCode = title.charCodeAt(i);
			if (charCode < 256 && mapping[charCode] != null) {
				id += mapping[charCode];
			}
			else {		
				id += title.charAt(i);
			}
		}

		id = id.replace(/\W+/g, '-'); // Converto caratteri non alfanumerici in trattini
		id = id.replace(/^-/, ''); // elimino l'eventuale trattino iniziale
		id = id.replace(/-$/g, ''); // elimino l'eventuale trattino finale

// Se l'id e' troppo lungo tengo i primo MAX_LENGTH caratteri
		if (id.length > MAX_LENGTH) {
			id = id.substring(0, MAX_LENGTH);
		}

		if (id) {
			id_field.value = id;
		}
	}

}
