/*
FUNZIONI JAVASCRIPT PER LE FINTE POPUP A LAYER SOVRAPPOSTI
##############################################################

CSS da gestire 
################
<style type="text/css">
<!--
#blanket {background-color:#111;opacity:0.65;filter:alpha(opacity=65);position:absolute;z-index:9001;top:0px;left:0px;width:100%;}
#popUpDiv {position:absolute;background-color:#EEE;width:300px;height:300px;z-index:9002;}
-->
</style>

APERTURA POPUP 
###############
(chiamare funzione javascript)
popUrl(divID,div_width,div_height,callUrl); 

CHIUSURA POPUP
################
(chiamare funzione javascript)
popUrl(divID,0,0,'');

HTML DIVs
###########
(da mettere nella pagina dovunque si voglia)
<div id="blanket" style="display:none;"></div>
<div id="popUpDiv" style="display:none;"></div>
*/

function toggle(div_id, div_height) {
	var el = document.getElementById(div_id);
	if ( el.style.display == 'none' ) {	el.style.display = 'block';}
	else {el.style.display = 'none';}
}

function blanket_size(blanket) {
	if (typeof window.innerWidth != 'undefined') {
		viewportheight = window.innerHeight;
	} else {
		viewportheight = document.documentElement.clientHeight;
	}
	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		blanket_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			blanket_height = document.body.parentNode.clientHeight;
		} else {
			blanket_height = document.body.parentNode.scrollHeight;
		}
	}
	var blanketDiv = document.getElementById(blanket);
	blanketDiv.style.height = blanket_height + 'px';
}

function centerDiv(Xwidth,Yheight,divID) { 
	
	// First, determine how much the visitor has scrolled 
	var scrolledX, scrolledY; 
	if( self.pageYOffset ) { 
		scrolledX = self.pageXOffset; 
		scrolledY = self.pageYOffset; 
	} else if( document.documentElement && document.documentElement.scrollTop ) { 
		scrolledX = document.documentElement.scrollLeft; 
		scrolledY = document.documentElement.scrollTop; 
	} else if( document.body ) { 
		scrolledX = document.body.scrollLeft; 
		scrolledY = document.body.scrollTop; 
	} 
	
	// Next, determine the coordinates of the center of browser's window 
	
	var centerX, centerY; 
	if( self.innerHeight ) { 
		centerX = self.innerWidth; 
		centerY = self.innerHeight; 
	} else if( document.documentElement && document.documentElement.clientHeight ) { 
		centerX = document.documentElement.clientWidth; 
		centerY = document.documentElement.clientHeight; 
	} else if( document.body ) { 
		centerX = document.body.clientWidth; 
		centerY = document.body.clientHeight; 
	} 
	
	// Xwidth is the width of the div, Yheight is the height of the 
	// div passed as arguments to the function: 
	var leftOffset = scrolledX + (centerX - Xwidth) / 2; 
	var topOffset = scrolledY + (centerY - Yheight) / 2; 
	// The initial width and height of the div can be set in the 
	// style sheet with display:none; divid is passed as an argument to // the function 
	var o=document.getElementById(divID); 
	var r=o.style; 
	//r.position='absolute'; 
	r.top = topOffset + 'px'; 
	r.left = leftOffset + 'px'; 
	//r.display = "block"; 
}

function popUrl(divID,w,h,callUrl) { // Da chiamare per aprire o chiudere la popup
	var popDiv=F_getId(divID);
	// Ridimensiona il div
	popDiv.style.width=w+"px";
	popDiv.style.height=h+"px";
	// Aggiorna il contenuto del div con il file indicato
	if (callUrl.length>10) F_richiestaGet(divID,callUrl);
	// Mostra il layer div
	blanket_size('blanket');
	centerDiv(w,h,divID);
	toggle('blanket');
	toggle(divID);
}

