	var popupVisible = false;
	var popupDrag;
	
	function maximizeWindow()
	{
		window.moveTo(0,0);
		/* Ingrandisci a tutto schermo*/
		/*
		if (document.all) 
		{
				window.resizeTo(screen.availWidth,screen.availHeight);
		}
		else if (document.layers||document.getElementById) 
		{
			if (window.outerHeight<screen.availHeight||window.outerWidth<screen.availWidth)
			{
				window.outerHeight = screen.availHeight;
				window.outerWidth = screen.availWidth;
			}
		}
		*/
		window.focus();
	}
	
	function showPopup(pTop,pWidth,pFocus,pMaximize)
	{
		var DivRef = document.getElementById('popup');
   		var IfrRef = document.getElementById('popupFrame');
   		var w
   		var t
   		var winl
		
		//Crea draggable
		popupDrag = new Draggable(DivRef, { revert: false,
											starteffect:null, 
											reverteffect:null, 
											endeffect:null, 
											onStart: function(){
												document.onselectstart = function(){
													return false;
												};
											}, 
											onEnd: function(){
												IfrRef.style.top = DivRef.style.top;
	    										IfrRef.style.left = DivRef.style.left;
												document.onselectstart = null;
											},
											onDrag: function(){
												 IfrRef.style.top = DivRef.style.top;
	    										 IfrRef.style.left = DivRef.style.left;
												}

										});

		if(pMaximize)
			maximizeWindow();
			
		//Creo un elemento sotto il popup per vincolare l'utente a cliccare solo su quello
		createPopupDiv(0);
		createPopupDiv(1);
		
		//Posiziona al centro dello schermo in orizzontale ed in verticale
		t = 200; 
		w = 450;
		if(pTop > 0) t = pTop;
		if(pWidth > 0) w = pWidth;

		/*t = (document.body.offsetHeight-t)/2.7;*/
		if (t < 0) t = 0;
		
		winl = (document.body.offsetWidth-w)/2;
		if (winl < 0) winl = 0;
		
		//Visualizza
		DivRef.style.top = t;
		DivRef.style.left = winl;
		DivRef.style.width = w;
	    DivRef.style.display = "block";
		DivRef.style.zIndex = 9999;

	    IfrRef.style.width = DivRef.offsetWidth;
	    IfrRef.style.height = DivRef.offsetHeight;
	    IfrRef.style.top = DivRef.style.top;
	    IfrRef.style.left = DivRef.style.left;
	    IfrRef.style.display = "block";
		
		popupVisible = true;

		if(pFocus)
			document.getElementById(pFocus).focus();

	}

	function hidePopup()
	{
		//Nascondi
		document.getElementById('popup').style.display='none';
		document.getElementById('popupFrame').style.display='none';

		//Elimina draggable
		popupDrag.destroy();
		
		//Rimuovo il div di blocco se esiste
		createPopupDiv(0);
  
		popupVisible = false;
	}
	
	function createPopupDiv(pOnOff)
	{
		var eDivPopup;
		if(pOnOff)
		{
			try
			{
				eDivPopup = document.createElement("div");
				eDivPopup.setAttribute("id", "popupblock");
				eDivPopup.style.position = "fixed";
				eDivPopup.style.top = "0px";
				eDivPopup.style.left = "0px";
				eDivPopup.style.width = '100%';
				eDivPopup.style.height = '100%';
				eDivPopup.style.zIndex = 8999;
				eDivPopup.style.backgroundColor = '#fff';
				eDivPopup.style.opacity = '0.5';
				eDivPopup.style.filter = 'alpha(opacity=50)';
				eDivPopup.style.display = "block";
				eDivPopup.style.cursor = "wait";

				document.body.appendChild(eDivPopup);	
			}
			catch(e)
			{
				eDivPopup = "";
			}				
		}
		else
		{
			try
			{
				eDivPopup = document.getElementById('popupblock');
				document.body.removeChild(eDivPopup);		
			}
			catch(e)
			{
				eDivPopup = "";
			}
		}
	}
	
