//Animazione flash
function animazione_flash() {
      document.write("<object type='application/x-shockwave-flash' data='slide.swf' width='250' height='188' id='filmato'> ");
      document.write("<param name='movie' value='slide.swf' /> ");
      document.write("<param name='quality' value='high' /><param name='wmode' value='transparent' /> ");
      document.write("</object> ");
}

// Controllo lunghezza campi
function MaxCaratteri(Object,MaxLen)
{return (Object.value.length<=MaxLen);}

// Controllo campi obbligatori
function formCheck(formobj){
	//1) Inserisci il nome che hai assegnato ai tuoi campi con name
	var fieldRequired = Array("nome","citta","telefono","mail","data1","data2","posti","messaggio");
	//2) Inserisci la descrizione del campo da riempire che appare nel messaggio a video
	var fieldDescription = Array("Nome e Cognome", "Citta", "Telefono", "E-mail", "Periodo -dal-", "Periodo -al-", "Posti", "Messaggio");
	//3) Inserisci il messagio che deve precedere l'elenco dei campi non inseriti.
	var alertMsg = "Per favore, riempi i seguenti campi:\n";
	
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}

// Controllo email corretta
function ControllaMail(){
   EmailAddr = document.modulo.mail.value;
   Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
   if (Filtro.test(EmailAddr))
      return true;
   else
      {
		  if(EmailAddr != ""){
			  alert("Indirizzo e-mail non valido!");
			  document.modulo.mail.focus();
			  return false;
		}
      }
}

//Popup a centro pagina
function centerPopUp( url, name, width, height, scrollbars ) {
if( scrollbars == null ) scrollbars = "0"
str = "";
str += "resizable=1,";
str += "scrollbars=" + scrollbars + ",";
str += "width=" + width + ",";
str += "height=" + height + ",";
if ( window.screen ) {
var ah = screen.availHeight - 30;
var aw = screen.availWidth - 10;
var xc = ( aw - width ) / 2;
var yc = ( ah - height ) / 2;
str += ",left=" + xc + ",screenX=" + xc;
str += ",top=" + yc + ",screenY=" + yc;
}
window.open( url, name, str );
}

//JS inserimento Script per Guestbook
function emoticon(text) {
var txtarea = document.modulo.messaggio;
text = ' ' + text + ' ';
if (txtarea.createTextRange && txtarea.caretPos) {
var caretPos = txtarea.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
txtarea.focus();
} else {
txtarea.value += text;
txtarea.focus();
}
}


// Finestra di popup animata
function expandingWindow(website){
var windowprops='width=1,height=1,scrollbars=yes,status=no,resizable=yes,location=no'
var heightspeed = 2; 
var widthspeed = 2; 
var leftdist = 10;   
var topdist = 10; 
var lunghezza = 500;
var altezza = 300;
	if(lunghezza == 0){
		lunghezza = window.screen.availWidth;}
	if(altezza == 0){
		altezza = window.screen.availHeight;}
if (window.resizeTo&&navigator.userAgent.indexOf("Opera")==-1) {
var winwidth = lunghezza;
var winheight = altezza;
var sizer = window.open("","","left=" + leftdist + ",top=" + topdist +","+ windowprops);
for (sizeheight = 1; sizeheight < winheight; sizeheight += heightspeed)
sizer.resizeTo("1", sizeheight);
for (sizewidth = 1; sizewidth < winwidth; sizewidth += widthspeed)
sizer.resizeTo(sizewidth, sizeheight);
sizer.location = website;}
else
window.open(website,'mywindow');}