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 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 aprifin( pageName, titolo ) {
	win = window.open( pageName, "","width=600,height=600,left=430,top=250,scrollbars=1" );
	win.focus();
}
window.onload = function() {
	externalLinks();
}
function spedisci( email ) {
	location = "mailto:" + email.replace( "[presso]", "@" );
}
function galleria( entityID) {
	win = window.open( "galleria-dettaglio.html?entityID=" + entityID, "Galleria", "width=840,height=700" );
	win.focus();
}
function convalidaForm( form ) {
	if ( form.id == "bookingForm" ) {
		var campiObbligatori = {	"nome" : "Nome",
									"cognome" : "Cognome",
									"indirizzo" : "Indirizzo",
									"cap" : "Cap",
									"citta" : "Citta",
									"paese" : "Paese",
									"telefono" : "Telefono",
									"email" : "Email",
									"dataArrivo" : "Data arrivo",
									"dataPartenza" : "Data partenza",
									"adulti" : "Adulti" };
	} else if ( form.ID == "richiestaForm" ) {
		var campiObbligatori = {	"nome" : "Nome",
									"cognome" : "Cognome",
									"email" : "Email",
									"richiesta" : "Richiesta" };
	}
	var errore = "";
	for ( i in campiObbligatori ) {
		switch ( i ) {
			case "email":
				if ( ! validateEmail( form[i].value ) ) {
					errore += "Inserire un indirizzo e-mail valido\n"
				}
			break;
			default:
				if ( form[i].value == "" ) {
					errore += "Compilare correttamente il campo " + campiObbligatori[i] + "\n";
				}
			break;
		}
	}
	if ( errore != "" ) {
		alert( errore );
		return false;
	}
}
function apriZoom( src ) {
	document.getElementById( "zoomContainer" ).style.height = document.getElementById( "container" ).offsetHeight + "px";
	document.getElementById( "zoomImmagine" ).innerHTML = '<img src="' + src + '" alt="zoom" /><br /><a href="javascript:chiudiZoom()">Chiudi</a>';
	document.getElementById( "zoomContainer" ).style.display = "block";
}
function chiudiZoom() {
	document.getElementById( "zoomContainer" ).style.display = "none";
}