
	// ------------------------------------------------------------------------------------------------------
	// Libreria di funzioni generiche
	// ------------------------------------------------------------------------------------------------------

	
	// Funzioni per mostrare e nascondere i layer
	function MM_findObj(n, d) { //v4.01
	  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	  if(!x && d.getElementById) x=d.getElementById(n); return x;
	}
	
	function MM_showHideLayers() { //v6.0
	  var i,p,v,obj,args=MM_showHideLayers.arguments;
	  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
	    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
	    obj.visibility=v; }
	}
	
	
	// Funzione per l'invio dei dati di un form ad una finestra popup (che si apre al centro dello schermo)
	function popupform(myform, windowname)
	{
		var my_width = 400;
		var my_height = 230;
		var my_top = ( screen.width / 2) - ( my_width / 2);
		var my_left = ( screen.height / 2) - ( my_height / 2);
		
		if (! window.focus) return true;
		window.open('', windowname, 'height='+my_height+', width='+my_width+', top='+my_top+', left='+my_left+', scrollbars=yes');
		myform.target=windowname;
		return true;
	}
	function popupform2(myform, windowname)
	{		
		if (! window.focus) return true;
		window.open('', windowname);
		myform.target=windowname;
		return true;
	}
	
	// Funzione per l'ingrandimento delle immagini WEBCAM
	function pop_cam(my_cam, windowname)
	{
		window.open('', windowname, "top=0, left=0, width=200, height=200, scrollbar=no, toolbar=no, status=no");
		my_cam.target=windowname;
		return true;
	}
	
	// Funzione per l'apertura dei trailer in una pagina popup
	function pop_cine(trailer, windowname)
	{
		var my_width = screen.width-5;
		var my_height = screen.height-40;
		var my_top = 0;
		var my_left = 0;
		
		window.open('Divertim/Cinema2.php?trailerFilm='+trailer, windowname, 'height='+my_height+', width='+my_width+', top='+my_top+', left='+my_left+', scrollbar=no, toolbar=no, status=no');
		return true;
	}
	
	// Apre una finestra popup in fullscreen
	function popupfull(url)
	{
		var dim=Dimens_schermo();
		//alert(dim[0] + " x " + dim[1]);
		window.open(url, 'AmiciFull', 'height='+dim[1]+', width='+dim[0]+', top=0, left=0, resizable=no,menubar=no,toolbar=no,location=no,status=no,scrollbars=no');
	}
	
	// Funzione per contare il numero di caratteri rimanenti nell'area del guestbook
	function update_count()
	{
		var current_total_length;
		var max_length;

		max_length = 254;
		fm = document.forms['Guestbook_pol'];
		current_total_length = fm.Msg.value.length;
		
		new_size = max_length;
		if (current_total_length > max_length)
		{
			current_total_length = max_length;
			fm.Msg.value = fm.Msg.value.substr(0, new_size);
		}
		fm.characters_left.value = max_length - current_total_length;
	}
	
	
	// Funzione per evidenziare la riga selezionata in una tabella
	function setPointer(theRow, theAction, theDefaultColor, thePointerColor, theMarkColor)
	{
	    var theCells = null;
	
	    // 1. Pointer and mark feature are disabled or the browser can't get the row -> exits
	    if ((thePointerColor == '' && theMarkColor == '') || typeof(theRow.style) == 'undefined') { return false; }
	
	    // 2. Gets the current row and exits if the browser can't get it
	    if (typeof(document.getElementsByTagName) != 'undefined') { theCells = theRow.getElementsByTagName('td'); }
	    else if (typeof(theRow.cells) != 'undefined') { theCells = theRow.cells; }
	    else { return false; }
	
	    // 3. Gets the current color...
	    var rowCellsCnt  = theCells.length;
	    var domDetect    = null;
	    var currentColor = null;
	    var newColor     = null;
	    
	    // 3.1 ... with DOM compatible browsers except Opera that does not return valid values with "getAttribute"
	    if (typeof(window.opera) == 'undefined' && typeof(theCells[0].getAttribute) != 'undefined')
	    { currentColor = theCells[0].getAttribute('bgcolor'); domDetect    = true; }
	    
	    // 3.2 ... with other browsers
	    else { currentColor = theCells[0].style.backgroundColor; domDetect    = false; }
	
	    // 4. Defines the new color
	    // 4.1 Current color is the default one
	    if (currentColor == '' || currentColor.toLowerCase() == theDefaultColor.toLowerCase())
	    {
	        if (theAction == 'over' && thePointerColor != '') { newColor = thePointerColor; }
	        else if (theAction == 'click' && theMarkColor != '') { newColor = theMarkColor; }
	    }
	    
	    // 4.1.2 Current color is the pointer one
	    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()) 
	    {
	        if (theAction == 'out') { newColor = theDefaultColor; }
	        else if (theAction == 'click' && theMarkColor != '') { newColor = theMarkColor; }
	    }
	    
	    // 4.1.3 Current color is the marker one
	    else if ( currentColor.toLowerCase() == theMarkColor.toLowerCase() )
	    { if (theAction == 'click') { newColor = (thePointerColor != '') ? thePointerColor : theDefaultColor; } }
	
	    // 5. Sets the new color...
	    if (newColor)
	    {
	        var c = null;
	        // 5.1 ... with DOM compatible browsers except Opera
	        if (domDetect) { for (c = 0; c < rowCellsCnt; c++) { theCells[c].setAttribute('bgcolor', newColor, 0); } }
	        // 5.2 ... with other browsers
	        else { for (c = 0; c < rowCellsCnt; c++) { theCells[c].style.backgroundColor = newColor; } }
	    }
	    return true;
	}
	
	// Funzione di inserimento numeri di telefono a ogni cambiamento della select
	function Help_num()
	{
		var index_select = document.forms["Cerca_persona"].consiglia_tel.options[document.forms["Cerca_persona"].consiglia_tel.options.selectedIndex].value;
		document.forms["Cerca_persona"].Num_persona.value = index_select;
	}
	
	// Controlla che l'ora e i minuti inseriti in "my_cam" siano corretti
	function check(func_stop)
	{
		inizializza();
		ctr_err=0
		fm = document.forms["my_cam"]
		
		// Controllo eventuali campi vuoti
		if (fm.ore.value=='' || fm.minut.value=='') { ctr_err=1; }
		if (ctr_err==1) {   alert("Non puoi lasciare campi vuoti"); if (fm.ore.value=='') {fm.ore.focus();} else {fm.minut.focus();}   }
		else
		{
			// Controllo eventuali stringhe di testo
			if ( isNaN(fm.ore.value)  ||  isNaN(fm.minut.value) ) { ctr_err=1; }
			if (ctr_err==1) {   alert("Puoi inserire solo numeri."); if (isNaN(fm.ore.value)) {fm.ore.focus();} else {fm.minut.focus();}   }
			else
			{
				// Controllo che ora e minuti siano nel giusto range
				if ( fm.ore.value<0  ||  fm.ore.value>23 ) { ctr_err=1; }
				if ( fm.minut.value<0  ||  fm.minut.value>59 ) { ctr_err=1; }
				if (ctr_err==1) { alert("Errore: \n \n h: 00-23 \n m: 00-59"); }
				else
				{
					window.clearTimeout (func_stop); func_stop = false;
					my_ore = fm.ore.value
					my_min = fm.minut.value
					
					if ( fm.ore.value.length<2) { my_ore = "0" + my_ore; }
					if ( fm.minut.value.length<2) { my_min = "0" + my_min; }
					
					image = "Img/Cam_online/capture_" + my_ore + "." + my_min + ".jpg";
					eval(documento+parA+"refresh"+parB).src = image;
					show_display('cam_live')
				}
			}
		}
	}
	
	// Cambia gli attributi di un layer
	function change_layer(id, mouse, ctrl)
	{
		//ctrl.style.cursor = 'hand';
		
		if (id=='1')
		{
			if (mouse=='over') {
				ctrl.style.borderColor = '#A2B7E9';
				ctrl.style.borderStyle = 'solid';
				ctrl.style.borderWidth = '1px';
				ctrl.style.backgroundColor = '#7393DF';
				ctrl.style.color = '#ffffff';
			}
			if (mouse=='out') {
				ctrl.style.borderColor = '#6487DB';
				ctrl.style.borderStyle = 'solid';
				ctrl.style.borderWidth = '1px';
				ctrl.style.backgroundColor = '#6487DB';
				ctrl.style.color = '#ffffff';
			}
		}
		if (id=='2')
		{
			if (mouse=='over') {
				ctrl.style.borderColor = '#A2B7E9';
				ctrl.style.backgroundColor = '#7393DF';
			}
			if (mouse=='out') {
				ctrl.style.borderColor = '#ffffff';
				ctrl.style.backgroundColor = '#1289D4';
			}
		}
		if (id=='3')
		{
			if (mouse=='over') ctrl.style.backgroundColor = '#5DB6EF';
			if (mouse=='out')	ctrl.style.backgroundColor = '#2DA1EB';
		}
	}
	
	// Apre una immagine in una pagina nuova del browser
	function open_imgNEW(image)
	{
		window.open(image, "")
	}

	// Mostra e nasconde il controllo di MediaPlayer
	function handleControlsOnOffClick()
	{
		inizializza();
		MediaP_bool = eval(documento+parA+"mediaPlayer"+parB+".showControls;");
		MediaP_stat = eval(documento+parA+"mediaPlayer"+parB);
		
		if (MediaP_bool == true)
		{
			MediaP_stat.showControls = false;
			document.forms['playerCtrl'].controls.value = "Mostra controllo";
		}
		else
		{
			MediaP_stat.showControls = true;
			document.forms['playerCtrl'].controls.value = "Nascondi controllo"
		}
	}

	// Cambia cartone a MediaPlayer
	function change(sel)
	{
		inizializza();
		MediaP_stat = eval(documento+parA+"mediaPlayer"+parB);
		
		var list = document.forms['playerCtrl'].streams;						// Percorso select
		var streamURL = list.options[list.selectedIndex].value;			// Value della option
		var streamURL_testo = list.options[list.selectedIndex].text;	// Testo della option
		
		// Metodi x deselezionare la select: la rotella potrebbe cambiar cartone x sbaglio!
		//for (var i=0; i < list.options.length; i++) {list.options[i].selected = false;}					// Modo 1 - l'indice torna all'inizio senza selezionare nulla
		//sel.options[sel.selectedIndex].selected=false;															// Modo 1bis (uguale ma senza ciclo)	
		//list.selectedIndex = -1;																									// Modo 2 - campo vuoto (l'unico che va sia su IE che su NN)
		my_contr = document.forms['playerCtrl'].controls2; my_contr.focus(); my_contr.blur();	// Modo 3 - passo il focus a un altro campo e poi lo levo
		
		MediaP_stat.stop();
		MediaP_stat.fileName = "Divertim/Cartoni/" + streamURL;
	}
	
	// Funzioni di MediaPlayer
	function mediaPlayer_play()
	{
		inizializza();
		MediaP_stat = eval(documento+parA+"mediaPlayer"+parB);
		MediaP_stat.play();
	}
	function mediaPlayer_pause()
	{
		inizializza();
		MediaP_stat = eval(documento+parA+"mediaPlayer"+parB);
		MediaP_stat.pause();
	}
	function mediaPlayer_stop()
	{
		inizializza();
		MediaP_stat = eval(documento+parA+"mediaPlayer"+parB);
		MediaP_stat.stop();
	}
	
	function Dimens_schermo()
	{
		var height=0; var width=0;
		if (self.screen)			// for NN4 and IE4
		{     
			width = screen.width;
			height = screen.height
		}
		else if (self.java)			// for NN3 with enabled Java
		{   
			var jkit = java.awt.Toolkit.getDefaultToolkit();
			var scrsize = jkit.getScreenSize();
			width = scrsize.width;
			height = scrsize.height;
		}
		var my_dim = new Array();
		my_dim[0] = width; my_dim[1] = height;
		
		return my_dim;
		// <script type="text/javascript">var dim=Dimens_schermo(); document.writeln(dim[0], "x", dim[1])</script>
	}
	
	function open_wp(my_home)
	{		
		// Trovo il genere
		radio = document.forms['wallpaper'].genere;
		for (var i=0; i<radio.length;i++) { if (radio[i].checked) { genere = radio[i].value; } }
		// Trovo le altre caratteristiche
		lati = document.forms['wallpaper'].lati.options[document.forms['wallpaper'].lati.selectedIndex].value;
		imgXpag = document.forms['wallpaper'].imgXpag.options[document.forms['wallpaper'].imgXpag.selectedIndex].value;
		num_news = document.forms['wallpaper'].num_news.options[document.forms['wallpaper'].num_news.selectedIndex].value;
		dim_size = document.forms['wallpaper'].dim_size.options[document.forms['wallpaper'].dim_size.selectedIndex].value;
		cerca_nome = document.forms['wallpaper'].cerca_nome.value;
		// lati_sup
		check_lati_sup = document.forms['wallpaper'].lati_sup;
		if (check_lati_sup.checked) { lati_sup = "si"; } else { lati_sup = "no"; }
		// num_news
		check_news = document.forms['wallpaper'].news;
		if (check_news.checked) { news = "si"; } else { news = "no"; }
		// cerca_si
		check_cerca_si = document.forms['wallpaper'].cerca_si;
		if (check_cerca_si.checked) { cerca_si = "si"; } else { cerca_si = "no"; }
		// dimens
		check_dimens = document.forms['wallpaper'].dimens;
		if (check_dimens.checked) { dimens = "si"; } else { dimens = "no"; }
		
		url = my_home + 'index1.php?page=192'+'&genere='+genere+'&lati='+lati+'&lati_sup='+lati_sup+'&imgXpag='+imgXpag+'&news='+news+'&cerca_si='+cerca_si+'&dimens='+dimens+'&num_news='+num_news+'&cerca_nome='+cerca_nome+'&dim_size='+dim_size+'&num_pag=1';		
		return url;
	}
	
	function check_alert_wp(num_tot_wp)
	{
		// controllo la scelta del genere
		radio = document.forms['wallpaper'].genere;
		for (var i=0; i<radio.length;i++) { if (radio[i].checked) { alert_gen = radio[i].value; } }
		
		// controllo le img x pagina
		alert_pag = document.forms['wallpaper'].imgXpag.options[document.forms['wallpaper'].imgXpag.selectedIndex].value;
		
		if ( (alert_pag=="Tutte") && (alert_gen=="Tutte") )
		{ 
			// alert("Attenzione, stai cercando di caricare " + num_tot_wp + " immagini nella stessa pagina, \n l'operazione potrebbe causare forti rallentamenti al pc.");
		}
	}
	
	// Cambia il background color di un div tramite valori rgb
	var RGB = new Array(256);
	var k = 0;
	var hex = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F");
	for (i = 0; i < 16; i++) { for (j = 0; j < 16; j++) { RGB[k] = hex[i] + hex[j]; k++; } }

	
	// Passando i 3 valori rgb cambio il background di un div
	function show_rgb_in_div(r,g,b,my_div)
	{
		inizializza();
		eval(documento+parA+my_div+parB+".style.backgroundColor = 'rgb("+r+","+g+","+b+")';");
	}
	
	// Il valore di quale select mettere in quale div?
	function show_rgb_in_div_2(my_select, my_div)
	{
		inizializza();
		value_select = my_select.options[my_select.selectedIndex].value;
		eval(documento+parA+my_div+parB+".style.backgroundColor = '#"+value_select+"';");
	}
	
	// Controlla i valori RGB e li passa alla funz che stampa
	function change_background_rgb(my_div)
	{
		if (my_div == 1)
		{	
			// Recupero i valori ...
			val_1 = document.forms['vostreFoto_personalizza'].vostreFoto_rgb1;
			val_2 = document.forms['vostreFoto_personalizza'].vostreFoto_rgb2;
			val_3 = document.forms['vostreFoto_personalizza'].vostreFoto_rgb3;
			
			// ... li controllo ...
			if (val_1.value == "")				{ val_1.value = 0;			alert ("Riempire tutti i campi !!!") }
			if (val_2.value == "")				{ val_2.value = 0;			alert ("Riempire tutti i campi !!!") }
			if (val_3.value == "")				{ val_3.value = 0;			alert ("Riempire tutti i campi !!!") }
			if (isNaN(val_1.value))			{ val_1.value = 0;			alert ("Inserisci solo numeri !!!") }
			if (isNaN(val_2.value))			{ val_2.value = 0;			alert ("Inserisci solo numeri !!!") }
			if (isNaN(val_3.value))			{ val_3.value = 0;			alert ("Inserisci solo numeri !!!") }
			if (val_1.value > 255)			{ val_1.value = 255;		alert ("Inserisci solo valori minori di 256 !!!") }
			if (val_1.value < 0)				{ val_1.value = 0;			alert ("Inserisci solo valori maggiori di 0 !!!") }
			if (val_2.value > 255)			{ val_2.value = 255;		alert ("Inserisci solo valori minori di 256 !!!") }
			if (val_2.value < 0)				{ val_2.value = 0;			alert ("Inserisci solo valori maggiori di 0 !!!") }
			if (val_3.value > 255)			{ val_3.value = 255;		alert ("Inserisci solo valori minori di 256 !!!") }
			if (val_3.value < 0)				{ val_3.value = 0;			alert ("Inserisci solo valori maggiori di 0 !!!") }
			
			// Mostro il risultato
			show_rgb_in_div(val_1.value,val_2.value,val_3.value,'vostreFoto_regis_color');
		}
	}
	
	// rgb x la select
	function convert_select_rgb(my_select, my_div)
	{
		inizializza();
		// Recupero i valori RGB
		value_select = my_select.options[my_select.selectedIndex].value;
		var Array_RGB = value_select.split('.');
		show_rgb_in_div(Array_RGB[0], Array_RGB[1], Array_RGB[2], 'vostreFoto_regis_color');
	}
	
	// Pulisco i dati di registrazione inseriti dall'utente
	function clear_scattiReg()
	{
		document.forms['vostreFoto_regis'].vostreFoto_nome.value = "";
		document.forms['vostreFoto_regis'].vostreFoto_login.value = "";
		document.forms['vostreFoto_regis'].vostreFoto_psw.value = "";
		document.forms['vostreFoto_regis'].vostreFoto_email.value = "";
	}
	
	function open_img_select(user)
	{
		my_select = document.forms['Scatti_del'].imgScatti_list;
		img = my_select.options[my_select.selectedIndex].value;
		window.open('public/VostriScatti/'+user+'/'+img);
	}
	
	function Add_A_Favorite() 
	{ 
		if (window.external)		{ external.AddFavorite('http://www.p0l.it/', 'p0l.it - Il sito di Paolo Pancaldi') }
		else if (window.sidebar)	{ window.sidebar.addPanel('p0l.it - Il sito di Paolo Pancaldi', 'http://www.p0l.it/', ""); }
		else {
			alert("Sorry, your browser doesn't support this feature." + 
			"\nPlease use the bookmark feature of your browser to save the location of this page.");
		}
	}
	
	function setMyHomePage(doc) 
	{ 
		if (window.external) { doc.style.behavior='url(#default#homepage)'; doc.setHomePage('http://www.p0l.it/'); }
		else { alert("Sorry, your browser doesn't support this feature."); }
	}
	
	// Reindirizza l'utente nella pagina richiesta con la select
	function RequestUrlCinema(mySelect, myForm)
	{
		var myRequest = mySelect.options[mySelect.selectedIndex].value;
		if (myRequest!="") {
			document.forms[myForm].action = "Divertim/Cinema2.php?trailerFilm=" + myRequest;
			document.forms[myForm].target = 'frame_cinema';
			document.forms[myForm].submit();
		}
	}
	
	// Reindirizza l'utente nella pagina richiesta con la select
	function RequestUrl(mySelect, myForm, mylink)
	{
		var myRequest = mySelect.options[mySelect.selectedIndex].value;
		if (myRequest!="") {
			document.forms[myForm].action = mylink + myRequest;
			document.forms[myForm].submit();
		}
	}
