// JavaScript Document

/******************************************************************/

/*
Apertura finestra pop-up
*/
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// Modificare i parametri di: toolbar, location, status, menubar, scrollbar, resizable, width e height
//
// onclick="MM_openBrWindow('consigliasito.html','','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=400,height=200')"

/******************************************************************/

/*
Per variare le dimensioni dei font delle pagine
*/
var tam=12;
function variaFont(tipo){
	if (tipo=="aumenta"){
		if(tam < 20){
			tam += 2;
		}	
	}else if (tipo=="diminuisci"){
		if(tam > 12){
			tam -= 2;
		}
	}
	document.getElementById('tx').style.fontSize=tam+'px' ;
}

/******************************************************************/

/*
Funzione "Aggiungi Segnalibro"
*/
function bookmark(url,title){
	if((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)){
		window.external.AddFavorite(url,title);
	}else if(navigator.appName == "Netscape"){
    	window.sidebar.addPanel(title,url,"");
	}else{
		alert("Premi CTRL+D (Netscape) o CTRL+T (Opera) per aggiungere la pagina ai Preferiti");
	}
}

/******************************************************************/

/*
Funzione disabilita tasto destro del mouse
*/
function disableRightClick(e)
{
	var message = "Spiacenti, il tasto destro del mouse è disabilitato.";
	if(!document.rightClickDisabled) // initialize
	{
		if(document.layers) 
		{
			document.captureEvents(Event.MOUSEDOWN);
			document.onmousedown = disableRightClick;
		}
		else document.oncontextmenu = disableRightClick;
		return document.rightClickDisabled = true;
	}
	if(document.layers || (document.getElementById && !document.all))
	{
    	if (e.which==2||e.which==3)
    	{
			alert(message);
			return false;
		}
	}
	else
	{
		alert(message);
		return false;
	}
}
//disableRightClick();

/******************************************************************/

/*
Funzione "stampa questa pagina"
*/
function printPage(){
	print(document);
}

/******************************************************************/

/*
Per cancellare il testo di un campo di input quando si clicca dentro
*/
function ClearText(txtInput) {
  if (txtInput.value !== "") {
    txtInput.value = "";
  }
}

/******************************************************************/

/*
E-mail consigliasito
*/

// Courtesy of SimplytheBest.net - http://simplythebest.net/scripts/

function consigliasito(){
	/*
	var stb_domain = "html.it"
	var stb_user = "info"
	var stb_recipient = stb_user + "@" + stb_domain
	var stb_url = "mailto:" + stb_recipient
	document.write(stb_recipient.link(stb_url));
	*/
	var tipourl = "<img src='immagini/email_go24.gif' width='24' height='24' border='0' align='middle' alt='Consiglia questo sito a un amico' />"; 
	var url = "mailto:&laquo;&nbsp;E-mail%20del%20tuo%20amico&nbsp;&raquo;?subject=Ti%20consiglio%20un%20sito&body=Ciao,%20ti%20consiglio%20di%20visitare%20il%20sito%20www.sammicarmine.org.%20Io%20l'ho%20trovato%20molto%20utile%20e%20interessante,%20e%20spero%20che%20piaccia%20anche%20a%20te.";
	document.write(tipourl.link(url)+"&nbsp;&nbsp;&nbsp;");
}

/******************************************************************/

/*
Imposta come home page
(questo comando è disabilitato in Firefox e quindi non funziona)
*/
function sethomepage(){
	//var bro = new BrowserInfo();
	
	var link_set_home = "<a href='#' onClick=\"this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.sammicarmine.org');\" class='toolbarlink' title='Imposta come pagina iniziale'><img src='immagini/house.gif' width='24' height='24' border='0' align='middle' alt='Imposta come pagina iniziale' /></a>&nbsp;&nbsp;&nbsp;";
	//if (bro.name == "Microsoft Internet Explorer"){
	if (navigator.appName == "Microsoft Internet Explorer"){
		document.write(link_set_home);
	}
}

/******************************************************************/

/*
Visualizza la data di oggi
*/
function dataoggi(){
	var days = new Array(7)
		days[1] = "Domenica";
		days[2] = "Luned&igrave;";
		days[3] = "Marted&igrave;";
		days[4] = "Mercoled&igrave;";
		days[5] = "Gioved&igrave;";
		days[6] = "Venerd&igrave;";
		days[7] = "Sabato";
	var months = new Array(12)
		months[1] = "Gennaio";
		months[2] = "Febraio";
		months[3] = "Marzo";
		months[4] = "Aprile";
		months[5] = "Maggio";
		months[6] = "Giugno";
		months[7] = "Luglio";
		months[8] = "Agosto";
		months[9] = "Settembre";
		months[10] = "Ottobre";
		months[11] = "Novembre";
		months[12] = "Dicembre";
	var today = new Date()
	var day = days[today.getDay() + 1]
	var month = months[today.getMonth() + 1]
	var date = today.getDate()
	var year = today.getYear()// + 1900 
	if (year < 1000){
		year += 1900;// Aggiungo 1900 perchè altrimenti visualizza l'anno, ad esempio, in questo modo: 2009 => 109. Però IE lo visualizza 3109, allora faccio il controllo.
	}
	document.write(day + " " + date + " " + month + " " + year)
}

/******************************************************************/

/*
Mostra-nascondi articolo - NON VA CON IE
*/
function ShowAndHide(id1,id2){
	if(document.getElementById){
    	el1=document.getElementById(id1);
    	el2=document.getElementById(id2);
    	if(el1.style.display=="none"){
        	el1.style.display="block";
        	el2.style.display="none";
        }else{
        	el1.style.display="none";
        	el2.style.display="block";
        }
    }
}

/******************************************************************/

/*
Form field Limiter script- By Dynamic Drive
For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
This credit MUST stay intact for use
*/
var ns6 = document.getElementById &&! document.all

function restrictinput(maxlength,e,placeholder){
	if (window.event && event.srcElement.value.length >= maxlength)
		return false
	else if (e.target && e.target == eval(placeholder) && e.target.value.length >= maxlength){
		var pressedkey = /[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
		if (pressedkey.test(String.fromCharCode(e.which)))
			e.stopPropagation()
	}
}
function countlimit(maxlength,e,placeholder){
	var theform = eval(placeholder)
	var lengthleft = maxlength-theform.value.length
	var placeholderobj = document.all ? document.all[placeholder] : document.getElementById(placeholder)
	if (window.event || e.target && e.target == eval(placeholder)){
		if (lengthleft < 0)
			theform.value = theform.value.substring(0,maxlength)
			placeholderobj.innerHTML = lengthleft
	}
}
function displaylimit(thename, theid, thelimit){
	var theform = theid != "" ? document.getElementById(theid) : thename
	var limit_text = '<p style="color: #6699cc; font-size: 10px; font-style: normal; font-weight:bold">Puoi inserire ancora <span id="' + theform.toString() + '" style="color: #cc0000;">' + thelimit + '</span> caratteri</p><br>'
	if (document.all || ns6)
		document.write(limit_text)
		if (document.all){
			eval(theform).onkeypress = function(){
				return restrictinput(thelimit,event,theform)
			}
			eval(theform).onkeyup = function(){
				countlimit(thelimit,event,theform)
			}
		}
	else if (ns6){
		document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); 
		document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); 
	}
}


/******************************************************************/
/*
Funzione controllo form newsletter
*/
function ControllaForm()
	{
		var controllo=false;
		var cognome=true;
		var nome=true;
		var email=true;
		var autorizzazione=true;

// Controllo TEXTfields

		if (document.iscrizione.cognome.value == "" ) 
			{
				controllo=true;
				alert("Non hai digitato il tuo COGNOME.\nIl modulo non sarà inviato.\nAS-Webmaster.");
			}

		if (document.iscrizione.nome.value == "" ) 
			{
				controllo=true;
				alert("Non hai digitato il tuo NOME.\nIl modulo non sarà inviato.\nAS-Webmaster.");
			}
			
//	if (document.iscrizione.citta.value == "" ) 
//			{
//				controllo=true;
//				alert("Non hai digitato l'OGGETTO della e-mail,\nche pertanto non sarà inviata.\nAS-Webmaster.");
//			}
			
		if (document.iscrizione.email.value == "" ) 
			{
				controllo=true;
				alert("Non hai digitato il tuo INDIRIZZO DI POSTA ELETTRONICA.\nIl modulo non sarà inviato.\nAS-Webmaster.");
			}			
//Controllo email valida ##### Copyright (C) 2003 Antonio Spinelli Webmaster #####
         else if ((document.iscrizione.email.value.indexOf('@',0)=="-1") ||
			      (document.iscrizione.email.value.indexOf('.',0)=="-1"))
			     {
				   controllo=true;
				   alert("Hai digitato un INDIRIZZO E-MAIL SBAGLIATO.\nIl modulo non sarà inviato.\nAS-Webmaster.");
			     }
//fine controllo email valida ##########
			
// Fine controllo TEXTfield

// Controllo RADIObutton
		for (i=0;i<2;i++)
			//{
			//(document.iscrizione.privacy[i].checked)?riservatezza=false:null
			//}
			//if (riservatezza)
				//{
				//controllo=true;
				//alert("NON CI HAI DETTO cosa fare dei tuoi dati.\nIl form non sarà inviato.");
				//}
				
			var prineg = document.iscrizione.privacy[1]
			if (prineg.checked != prineg.defaultChecked)
			    {
				controllo=true;
				alert("CI HAI NEGATO il trattamento dei tuoi dati personali.\nIl modulo non sarà inviato.\nAS-Webmaster.");
				}	
// Fine controllo RADIObutton


	if (controllo){return false}else{return true}

	}

