function ajaxConnect( strURL, method, formID ) {
	if ( method == undefined ) {
		method = "get";
	}
	var xmlHttpReq = false;
	var self = this;
	if ( window.XMLHttpRequest ) {
		self.xmlHttpReq = new XMLHttpRequest();
	} else if ( window.ActiveXObject ) {
		self.xmlHttpReq = new ActiveXObject( "Microsoft.XMLHTTP" );
	} else {
		alert( "Il browser in uso non supporta la tecnologia Ajax" );
	}
	if ( method.toLowerCase() == "get" && formID != undefined ) {
	    strURL += ( ( strURL.indexOf( "?" ) == - 1 ) ? "?" : "&" ) + getquerystring( formID );
	}
	self.xmlHttpReq.open( method, strURL );
	self.xmlHttpReq.setRequestHeader( "Content-Type", "application/x-www-form-urlEncoded" );
	if ( formID != undefined && method.toLowerCase() == "post" ) {
	    self.xmlHttpReq.send( getquerystring( formID ) ); 
	} else {
	    self.xmlHttpReq.send( null ); 
	}
	self.xmlHttpReq.onreadystatechange = function() {
		if ( self.xmlHttpReq.readyState == 4 ) {
			eval( self.xmlHttpReq.responseText );
		}
	}
}
sfHover = function() {
	var sfEls = document.getElementById("menu_inf").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
function externalLinks() {
	if ( ! document.getElementsByTagName ) {
		return;
	}
	var anchors = document.getElementsByTagName( "a" );
	for ( var i = 0; i < anchors.length; i++ ) {
		var anchor = anchors[i];
		if ( anchor.getAttribute( "href" ) && anchor.getAttribute( "rel" ) == "external" ) {
			anchor.target = "_blank";
		}
	}
}
function addOnloadFunction( functionName ) {
	if ( window.addEventListener ) {
		window.addEventListener( "load", functionName, false );
	}
	if ( window.attachEvent ) {
		window.attachEvent( "onload", functionName );
	}
}
if ( window.attachEvent ) {
	window.attachEvent( "onload", sfHover );
}
addOnloadFunction( externalLinks );
function mappe( pageName ) {
	win = window.open( pageName, "", "width=680,height=550,left=430,top=250,scrollbars=1,resizable=1" );
	win.focus();
}
function zoom( pageName ) {
	win = window.open( pageName, "", "width=850,height=650,left=430,top=250,scrollbars=1,resizable=1" );
	win.focus();
}
function spedisci( email ) {
	location = "mailto:" + email.replace( "[presso]", "@" );
}
function toggle( divID ) {
	if ( div = document.getElementById( divID ) ) {
		div.style.display = ( div.style.display == "none" ) ? "block" : "none";
	}
}
function enableField( enable, formID, fieldName ) {
	if ( form = document.getElementById( formID ) ) {
		form[fieldName].disabled = enable;
	}
}
function validateEmail( email ) {
	var emailReg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
	var emailReg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,6}|[0-9]{1,3})(\]?)$/;
	return ! emailReg1.test( email ) && emailReg2.test( email );
}
function convalidaPrenotaForm( form, tipo ) {
	campiObbligatori = {	"email" : "Email",
							"nome" : "Nome",
							"cognome" : "Cognome",
							"countryID" : "Paese",
							"localita" : "Località",
							"selectDay" : "Giorno",
							"selectMonth" : "Mese",
							"selectYear" : "Anno",
							"selectYear" : "Anno",
							"persone" : "Persone",
							"days" : "Notti" };
	if ( tipo != "hotel" ) {
		campiObbligatori.municipalityID = "LocalitÃ ";
	}
	errore = "";
	for ( i in campiObbligatori ) {
		switch ( i ) {
			case "email":
				if ( ! validateEmail( form[i].value ) ) {
					errore += "Inserire un indirizzo e-mail valido\n"
				}
			break;
			case "countryID":
			case "selectDay":
			case "selectMonth":
			case "selectYear":
				if ( form[i].selectedIndex == 0 ) {
					errore += "Selezionare il " + campiObbligatori[i] + "\n";
				}
			break;
			case "municipalityID":
				if ( form.municipalityID && form.municipalityID.selectedIndex == 0 ) {
					errore += "Specificare la localitÃ  in cui si desidera soggiornare";
				}
			break;
			case "days":
				if ( form[i].value == "" || isNaN( form[i].value ) || form[i].value == 0 ) {
					errore += "Compilare correttamente il campo Notti\n";
				}
			break;
			default:
				if ( form[i].value == "" ) {
					errore += "Compilare correttamente il campo " + campiObbligatori[i] + "\n";
				}
			break;
		}
	}
	if ( errore ) {
		alert( errore );
		return false;
	}
}
function checkRadio( radioObject ) {
	if ( radioObject.length == undefined ) {
		return radioObject.checked;
	} else {
		for ( var i = 0; i < radioObject.length; i++ ) {
			if ( radioObject[i].checked ) {
				return true;
			}
		}
	}
}
function convalidaModulo( form, tipo ) {
	campiObbligatori = {	"email" : "Email",
							"username" : "Username",
							"categoriaContattoID" : "Categoria",
							"nome" : "Nome",
							"cognome" : "Cognome",
							"countryID" : "Paese" };
	if ( tipo == "informazioni" ) {
		campiObbligatori["richieste"] = "Richieste";
	} else {
		campiObbligatori["username"] = "Username";
	}
	errore = "";
	for ( i in campiObbligatori ) {
		if ( form[i] != undefined ) {
			switch ( i ) {
				case "email":
					if ( ! validateEmail( form[i].value ) ) {
						errore += "Inserire un indirizzo e-mail valido\n"
					}
				break;
				case "categoriaContattoID":
					if ( ! checkRadio( form[i] ) ) {
						errore += "Selezionare la " + campiObbligatori[i] + "\n";
					}
				break;
				case "countryID":
					if ( form[i].selectedIndex == 0 ) {
						errore += "Selezionare il " + campiObbligatori[i] + "\n";
					}
				break;
				default:
					if ( form[i] && form[i].value == "" ) {
						errore += "Compilare correttamente il campo " + campiObbligatori[i] + "\n";
					}
				break;
			}
		}
	}
	if ( errore ) {
		alert( errore );
		return false;
	}
}
function settaZoneID( formID, valore ) {
	if ( form = document.getElementById( formID ) ) {
		form.zonaID.value = valore;
		form.submit();
	}
}
function gallery( foto,entityID) {
	var win = window.open( "galleria-det.html?foto=" + foto + "&entityID=" + entityID, "GalleriaFotografica", "width=820,height=620" );
	win.focus();
}
function ruotaLastMinute() {
	if ( lastMinuteAttivo < lastMinutes ) {
		++lastMinuteAttivo;
	} else {
		lastMinuteAttivo = 1;
	}
	for ( i = 1; i <= lastMinutes; i++ ) {
		lastMinuteDiv = document.getElementById( "lastMinute" + i );
		lastMinuteDiv.style.display = ( i == lastMinuteAttivo ) ? "block" : "none";
	}
	setTimeout( "ruotaLastMinute()", 10000 );
}
function recuperaPassword() {
	email = prompt( "Inserire l'indirizzo email inserito durante la registrazione" );
	if ( email != "" && email != null ) {
		ajaxConnect( "/js/recupera-password.php?email=" + email );
	} 
}
window.name = "carniamain";
function apriGalleria() {
	var containerGalleria = document.getElementById( "containerGalleria" );
	containerGalleria.style.display = "block";
	containerGalleria.style.height = ( document.height || document.body.offsetHeight ) + "px";
	document.getElementById( "galleriaObject" ).innerHTML = '<object type="application/x-shockwave-flash" data="/swf/gallery.swf" width="880" height="660"><param name="movie" value="/swf/gallery.swf" /></object>';
}
function chiudiGalleria() {
	document.getElementById( "containerGalleria" ).style.display = "none";
}
function paginaGuestbook( pagina, identificatoreStrutturaRicettiva ) {
	ajaxConnect( "/js/pagina-guestbook.php?pagina=" + pagina + "&identificatoreStrutturaRicettiva=" + identificatoreStrutturaRicettiva );
}
function apriGuestbook() {
	document.getElementById( "guestbook" ).style.display = "block";
	maschera = document.getElementById( "mascheraGuestbook" );
	maschera.style.display = "block";
	maschera.style.height = ( document.height || document.body.offsetHeight ) + "px";
}
function chiudiGuestbook() {
	document.getElementById( "guestbook" ).style.display = "none";
	document.getElementById( "mascheraGuestbook" ).style.display = "none";
}