PositionX = 20;
PositionY = 20;
defaultWidth  = 500;
defaultHeight = 500;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows
var AutoClose = true;

if (parseInt(navigator.appVersion.charAt(0))>=4){
	var isNN=(navigator.appName=="Netscape")?1:0;
	var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var options='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
function popImage(imageURL,imageTitle){
	imgWin=window.open('about:blank','',options);
	with (imgWin.document){
		writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');
		writeln('<sc'+'ript>');
		writeln('var isNN,isIE;');
		writeln('isNN=(navigator.appName=="Netscape")?1:0;');
		writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;');
		writeln('function reSizeToImage(){');
			writeln('if (isIE){');
				writeln('window.resizeTo(300,300);');
				writeln('width=document.images[0].width;');
				writeln('height=document.images[0].height;');
				writeln('window.resizeTo(width,height);}');
			writeln('if (isNN){');
				writeln('window.innerWidth=document.images["George"].width;');
				writeln('window.innerHeight=document.images["George"].height;}}');
		writeln('function doTitle(){document.title="'+imageTitle+'";}');
		writeln('</sc'+'ript>');
		if (!AutoClose)
			writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
		else
			writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
		writeln('<img name="George" src='+imageURL+' style="display:block"></body></html>');
		close();
	}
}

var last_expanded = "";
function nascondiMenu()
{
  if (document.getElementById) { // DOM3 = IE5, NS6
    if (last_expanded != "") {
      var last_obj = document.getElementById(last_expanded);
      last_obj.style.display = "none";
    }
  }
  else {
    if (document.layers) { // Netscape 4
      document.id.display = "none";
    }
    else { // IE 4
      document.all.id.style.display = "none";
    }
  }
}

function mostraSottoMenu(id)
{
  if(document.getElementById(id)){
    var obj = document.getElementById(id);
    if (obj.style.display != "block") {
      if (last_expanded != "") {
        var last_obj = document.getElementById(last_expanded);
        last_obj.style.display = "none";
      }
      obj.style.display = "block";
      last_expanded = id;
  	} else {                      // 071207 codice aggiunto
  	  obj.style.display = "none";
    }
  }
  else {                          // 071207 codice aggiunto
    if (document.layers) { // Netscape 4
      document.id.display = "block";
    }
    else { // IE 4
      document.all.id.style.display = "block";
    }
  }
}

function mostra_originale(id)
{
    var obj = document.getElementById(id);
	if (obj.style.display != "block") {
      if (last_expanded != "") {
        var last_obj = document.getElementById(last_expanded);
        last_obj.style.display = "none";
      }
      obj.style.display = "block";
      last_expanded = id;
    }
}

// classe per la label che cambia colore
var requestedClass = "req";
var requestClass   = "req2";

// Validate()
// valida i vari campi immessi nel form e marca in giallo quelli che mancano
function Validate() {
	var labels = document.getElementsByTagName("label");
	var validationOK = true;
	for(var i = 0; i < labels.length; i++) {
		var lab = labels[i];
		if (lab.className == "req2")
			lab.className = "req";
		if (lab.className == "req") {
			var inp = lab.getElementsByTagName("input");
			if (inp.length > 0 && inp[0].value == "") {	//input vuoto
				lab.className = "req2";
				validationOK = false;
			}
        		if(inp.length > 0 && inp[0].type == "checkbox" && inp[0].checked == false) {
				//checkbox non selezionata
				lab.className = "req2";
				validationOK = false;
			}
			var sel = lab.getElementsByTagName("select");	//select con indice zero
			if(sel.length > 0 && sel[0].value == "") {
				lab.className = "req2";
				validationOK = false;
			}
    }
	}
	if (validationOK == false)
		alert("Compilare tutti i campi evidenziati in giallo");
	return validationOK;
}

// ValidationEmail()
// controllo correttezza indirizzo email
// la variabile 'pos' è la posizione del campo nel form
function ValidationEmail(myemail,pos) {
	var labels = document.getElementsByTagName("label");
	var lab = labels[pos];
	with (myemail) {
		apos = value.indexOf("@");
		dotpos = value.lastIndexOf(".");
		lastpos = value.length - 1;
		if (lab.className == "req2")
			lab.className = "req";
		if (apos < 1 || dotpos - apos < 2 || lastpos - dotpos > 4 || lastpos - dotpos < 2) {
			alert("Inserire un indirizzo email valido");
			lab.className = "req2";
			return false;
		}
		else
			return true;
	}
}

// ValidationLength()
// controllo che la stringa mystring abbia almeno min caratteri
function ValidationLength(mystring, min) {
	if (mystring.value.length < min) {
		alert("Ci sono " + mystring.value.length +
			" caratteri. E' necessario inserire almeno " + min +" caratteri");
		return false;
	}
	return true;
}

// SubmitReload()
// per fare il reload della pagina (ovvero tornare allo step attuale)
// la variabile mystep contiene lo step a cui vogliamo andare con il submit
function SubmitReload(thisform,mystep) {
	thisform.step.value = mystep;	// a che step voglio andare?
	thisform.myreload.value = 1;
	thisform.submit();
	return true;
}

// §§§ navindex.js §§§
//// JavaScript Navigation for index
// Variables from setupIndex.js: nextIndexPageUrl, prevIndexPageUrl, parentIndexPageUrl, firstIndexPageUrl, lastIndexPageUrl 
function nextPage() {
	if ( nextIndexPageUrl) document.location=nextIndexPageUrl;
	takenAction = false;
}
function prevPage() {
	if ( prevIndexPageUrl) document.location=prevIndexPageUrl;
	takenAction = false;
}
function indexPage() {
	if ( parentIndexPageUrl) document.location=parentIndexPageUrl;
	takenAction = false;
}
function firstPage() {
	if ( firstIndexPageUrl) document.location=firstIndexPageUrl;
	takenAction = false;
}
function lastPage() {
	if ( lastIndexPageUrl) document.location=lastIndexPageUrl;
	takenAction = false;
}
function zoom() {
	//Never have zoom on index
	takenAction = false;
}
function navSlideShow() {
	//Never have slide show in index
	takenAction = false;
}
function navToggleInfo() {
	//Never have show info in index
	takenAction = false;
}

// §§§ navslide.js §§§ 
//// JavaScript Navigation for slide
// Variables from setup.js: nextPageUrl, prevPageUrl, indexPageUrl, firstPageUrl, lastPageUrl
function nextPage() {
	document.location=nextPageUrl;
	takenAction = false;
}
function prevPage() {
	document.location=prevPageUrl;
	takenAction = false;
}
function indexPage() {
	document.location=indexPageUrl;
	takenAction = false;
}
function firstPage() {
	document.location=firstPageUrl;
	takenAction = false;
}
function lastPage() {
	document.location=lastPageUrl;
	takenAction = false;
}
function zoom() {
	document.location=zoomPageUrl;
	takenAction = false;
}
function navSlideShow() {
	if (readCookie('slideShow') == 'true') {
		stopSlideShow();
		document.location.reload(false); 
	} else {
		setSlideShowCookie();
		nextPage();
	}
	takenAction = false;
}
function navToggleInfo() {
	toggleEXIFInfo();
	takenAction = false;
}

// §§§ keyboard.js §§§

/*
************************************************************

  Note: Original routine taken from BluPlusPlus 2 see:
  http://www.datadosen.se/jalbum/forum/thread.jspa?threadID=1458

  ExhibitPlus: Keyboard support
    Keys:
      RIGHT arrow  	: next page
      LEFT arrow   	: previous page
      // Page UP     	: index page (no longer used)
      HOME         	: first page
      END          	: last page
      S,s,ESC          	: toggle start/stop slide show
      I,i          	: toggle exif info (when appropriate)
      Z,z			: zoom image (when appropriate)	
    Tested on: IE6, Mozzila 1.4, Netscape 7.1, Opera 7.2
    Bugs:
     - HOME,END, NUM+, NUM-  doesn't work in Opera
************************************************************
*/

var takenAction = false;

//IE&Gecko Code
function IEGeckoKeyPress(oEvent) {
	if (!oEvent) var oEvent = window.event;
	if (oEvent.keyCode) myKeyCode = oEvent.keyCode;
	else if (oEvent.which) myKeyCode = oEvent.which;
	if (oEvent.repeat || takenAction) {	return;	}
	if (myKeyCode >= 16 && myKeyCode <= 18) { return; }
	if (oEvent.shiftKey) { myKeyCode += 1000; }
	if (oEvent.ctrlKey)  { myKeyCode += 2000; }
	if (oEvent.altKey)   { myKeyCode += 4000; }
	//alert(oEvent.type + "=" + myKeyCode);
	myKeyPress(myKeyCode);
}

function myKeyPress(myKeyCode) {
	switch (myKeyCode) {
		case 39:					// RIGHT arrow
		case 107:					// NUM +
			takenAction = true;
			nextPage();
			break;
		case 37:					// LEFT arrow
		case 109:					// NUM -
			takenAction = true; 
			prevPage();
			break;
//		case 33: 					// Page UP
//			takenAction = true;
//			indexPage();
//			break;
		case 36:					// HOME
			takenAction = true;
			firstPage();
			break;
		case 35:					// END
			takenAction = true;
			lastPage();
			break;
		case 83:					// S,s
		case 27:					// ESC
			if ( isSlideShow ) {
				// Only if i have slide show
				takenAction = true;
				navSlideShow();
			}
			break;
		case 73:					// I,i
			takenAction = true;
			navToggleInfo();
			break;
//		case 34:					// Page DOWN
		case 90:					// Z,z
			takenAction = true;
			zoom();
			break;
		default:	 
			//alert(oEvent.type + "=" + myKeyCode);
			break;
		}
}

function initKeyboard() {
	document.onkeydown = IEGeckoKeyPress;
}

