// JavaScript Document

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

function ajax_carica(pagina,idLayer){ // "pagina" = url da visualizzare all'interno del layer "idLayer"
		d = document;
		preloadText = "";
		if (typeof XMLHttpRequest != "undefined") {
			x = new XMLHttpRequest();
		}else{ 
			try {
				x = new ActiveXObject("Msxml2.XMLHTTP");
			} 
			catch (e) { 
				try {
					x = new ActiveXObject("Microsoft.XMLHTTP");
				} 
				catch (e){
					x = null;
				}
			}
		}
		if (x){
			d.getElementById(idLayer).innerHTML = preloadText;
			x.onreadystatechange = function(){ 
				if (x.readyState == 4 && x.status == 200){ 
					var el=d.getElementById(idLayer);el.innerHTML = x.responseText;
				}
			}
			x.open("GET", pagina, true);
			x.send(null);
		}
		return false;
	}
	
	
/* DIMENSIONI FINESTRA */

function GetWidth(){
	  var x = 0;
	  if (self.innerHeight){
			  x = self.innerWidth;
	  }else if (document.documentElement && document.documentElement.clientHeight){
			  x = document.documentElement.clientWidth;
	  }else if (document.body){
			  x = document.body.clientWidth;
	  }
	  return x;
}

function GetHeight(){
	  var y = 0;
	  if (self.innerHeight){
			  y = self.innerHeight;
	  }else if (document.documentElement && document.documentElement.clientHeight){
			  y = document.documentElement.clientHeight;
	  }else if (document.body){
			  y = document.body.clientHeight;
	  }
	  return y;
}

function popupApri(tipo,param,w,h){
	popupCenter();
	winW = GetWidth();
	winH = GetHeight();
	document.getElementById(div).style.position='absolute';
	document.getElementById(div).style.left=((winW/2)-(w/2))+"px";
	document.getElementById(div).style.top=(winH/2)-(h/2)+"px";
	document.getElementById(div).style.visibility='visible';
	document.getElementById(div).style.width=w+"px";
	document.getElementById(div).style.height=h+"px";
	document.getElementById(div).style.zIndex='1000';
	ajax_carica("popup_"+tipo+".php?"+param+"&random="+Math.random(),div);
	intPopup = setInterval(popupCenter,100);
	intPopup;
}
function popupChiudi(div){
	document.getElementById(div).style.visibility='hidden';
	clearInterval(intPopup);
}

function popupCenter(){
	div = 'divpopup';
	w = document.getElementById(div).style.width;
	h = document.getElementById(div).style.height;
	w=w.replace("px", "");
	h=h.replace("px", "");
	winW = GetWidth();
	winH = GetHeight();
	document.getElementById(div).style.left=(winW/2)-(w/2)+"px";
	document.getElementById(div).style.top=(winH/2)-(h/2)+"px";
}