//funzioni javascript

/*questa funzione serve per far aprire le immagini un nuova finestra
indirizzo =url
titolo=titolo della finestra
larg= la larghezza della finestra in px
altezza= l'altezza della finestra in px
coordinate_x=la coordine x in px in cui la finestra si apre , si riferisce all'agolo sinistro della finestra
coordinate_y=la coordine y in px in cui la finestra si apre , si riferisce all'agolo sinistro della finestra
esempio di utlizzo: <a href="javascript:apri('http://www.vulcanoidee.it', 'vulcano', '600', '400', '100', '300')">apri</a>:
*/

function PopupCentrata(pagina) {
   var w = 800;
   var h = 600;
   var l = Math.floor((screen.width-w)/2);
   var t = Math.floor((screen.height-h)/2);
      window.open(pagina,"","width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);
 }

function apri(indirizzo, titolo,esiste){
	if (!esiste) 
		alert("Questa immagine non ha un equivalente piu grande");
	else{	
		w=window.open(indirizzo, titolo,"scroolbar=yes,status=no,width=700,height=600,outerWidth=700,outerHeight=600,top=0,left=0,screeny=0,screenx=0");
		w.focus();
	}
}

function chiudi(iddiv,url){
	
	node = document.getElementById(iddiv);
	objOverlay = document.getElementById('overlay');
	objOverlay.style.display = 'none';
	node.setAttribute('class','invisibile');
	node.setAttribute('className','invisibile');
	
	if(url!="")
		document.location.href=url
	
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function setCost(chooser, elem, arr) {
    var newElem;
    var arr;
    var elem;
    var where = (navigator.appName == "Microsoft Internet Explorer") ? -1 : null;
    var costChooser = chooser.form.elements[elem];
    //var costChooser = chooser.form.elements["expa"];
    while (costChooser.options.length) {
        costChooser.remove(0);
    }
    var choice = chooser.options[chooser.selectedIndex].value;
    var db = arr[choice];
    //var db = att_exp[choice];
    newElem = document.createElement("option");
    newElem.text = "Attivita correlate";
    newElem.value = "";
    costChooser.add(newElem, where);
    if (choice != "") {
        for (var i = 0; i < db.length; i++) {
            newElem = document.createElement("option");
            newElem.text = db[i].text;
            newElem.value = db[i].value;
            costChooser.add(newElem, where);
        }
    }
}

