/*
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;overflow:auto;}
-->
</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 ) == 'number' ) {
		//Non-IE
		blanketHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		blanketHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientHeight ) ) {
		//IE 4 compatible
		blanketHeight = document.body.clientHeight;
	} else blanketHeight=0;
	
	if (document.body.scrollHeight) blanketHeight = Math.max (document.body.scrollHeight,blanketHeight);

	var blanketDiv = document.getElementById(blanket);
	blanketDiv.style.height = blanketHeight + '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,bgColor) { // Da chiamare per aprire o chiudere la popup
	var popDiv=F_getId(divID);
	bgColor = bgColor || "#FFF";
	// Ridimensiona il div
	popDiv.style.width=w+"px";
	popDiv.style.height=h+"px";
	popDiv.style.backgroundColor=bgColor;
	// Aggiorna il contenuto del div con il file indicato
	if (callUrl.length>10) {
		callUrl=replaceQueryString("divID", divID, callUrl);
		callUrl=replaceQueryString("w", w, callUrl);
		callUrl=replaceQueryString("h", h, callUrl);
		F_richiestaGet(divID,callUrl);
	}
	// Mostra il layer div
	blanket_size("blanket");
	centerDiv(w,h,divID);
	toggle("blanket");
	toggle(divID);
	return true;
}

function popFrame(divID,w,h,callUrl,addClose,scrolla) { // Da chiamare per aprire la popup in un Iframe
	var popDiv=F_getId(divID);
	var blanket=F_getId("blanket");
	var html="";
	addClose=addClose || "true";
	scrolla=scrolla || "true";
	// Ridimensiona il div
	if(addClose!="false") hTot=h+20;
	else hTot=h;
	popDiv.style.width=w+"px";
	popDiv.style.height=hTot+"px";
	popDiv.style.background="none";
	if(addClose!="false") {
	html+="<div style='height:20px;opacity:0.65;filter:alpha(opacity=65);'>";
	html+="<div style='width:100px;float:right;text-align:right;'><a href='javascript:void(0);' onclick=\"popUrl('popUpDiv',0,0,'');\" style='color:#F00;' title='close'>close <img src='/club/img/icons/delete.png' alt='close' border='0' width='16' height='16' align='absmiddle' /></a></div>";
	html+="</div>";
	}
	if (scrolla!="false") html+="<iframe src=\""+callUrl+"\" width='"+w+"' height='"+h+"' frameborder='0' class='simpleFrame'>your browser do not support iframes!</iframe>";
	else html+="<iframe src=\""+callUrl+"\" width='"+w+"' height='"+h+"' frameborder='0' scrolling='no' class='simpleFrame'>your browser do not support iframes!</iframe>";
	popDiv.innerHTML=html;
	// Mostra il layer div
	blanket_size("blanket");
	centerDiv(w,h,divID);
	toggle("blanket");
	toggle(divID);
	return true;
}
