// ---------------------------------------------------------------------------
//  Sistema di gestione help
// ---------------------------------------------------------------------------

var dom_style = new Array();
var is = null;

function Is() {
  var agent  = navigator.userAgent.toLowerCase();
  this.major = parseInt(navigator.appVersion);
  this.minor = parseFloat(navigator.appVersion);
  this.ns    = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)));
  this.ns4   = (this.ns && (this.major == 4));
  this.ns6   = (this.ns && (this.major >= 5));
  this.ie    = (agent.indexOf("msie") != -1);
  this.ie4   = (this.ie && (this.major == 4));
  this.ie6   = (this.ie && (this.major >= 5));
  this.ok    = (this.ns4 ||this.ie4 || this.ns6 || this.ie6 ); 
}

function domObject (nomedoc, oggetto)
{
	var aMemo = new Array()	
	var doc;
	var obj;
	var par1,par2;

	if ( is == null ) is = new Is();
	
	if (is.ns4) {
  	doc = ( nomedoc != "" ) ? (nomedoc + ".document") : "document";
	  obj = "";
  	par1 = "['";
	  par2 = "']";
	} else if (is.ie4) {
  	doc = ( nomedoc != "" ) ? (nomedoc + ".document.all") : "document.all";
	  obj = "." + oggetto;
  	par1 = "['";
	  par2 = "']";
	} else if (is.ok) {
	  doc = ( nomedoc != "" ) ? (nomedoc + ".document.getElementById") : "document.getElementById";
  	obj = "." + oggetto;
	  par1 = "('";
  	par2 = "')";
	}
	
	aMemo['doc'] = doc
	aMemo['obj'] = obj
	aMemo['par1'] = par1
	aMemo['par2'] = par2
	
	return aMemo
}

function layerRef(Nome)
{
	if ( dom_style['doc'] == null ) dom_style = domObject ("", "style")
	return (dom_style['doc'] + dom_style['par1'] + Nome + dom_style['par2'] + dom_style['obj'])
}

function EspandiDiv(Nome, Img, Modo)
{
	var el = eval(layerRef(Nome))
	if ( Modo == '' || Modo == 'none' ) // valori consentiti
		el.display = Modo;
	else // toggle
		el.display = (el.display == 'none') ? '' : 'none';
	el.visibility = (el.display == 'none') ? 'hidden' : 'visible';
		
	if ( Img != null ) {		
		nomeImg = "exp" + Img;
		document.images[nomeImg].src = (el.display == "") ? "images/espandi1.gif" : "images/espandi0.gif";
	}
}


function showPopUp(



	contentDiv,	// Element (to append) or String (to write with innerHTML)

	popupWidth,

	popupHeight

){

	

	// Disabilito le scrollbar
	if (document.body.style.overflowX != '')
	{
		document.body.style.overflowX='hidden';
		document.body.style.overflowY='hidden';
	}
	else document.body.style.overflow ='hidden';	

	

	// Modifico il margine se c'era

	if (document.body.style.marginRight != '')

	{

		// Se ho un margine lo modifico

		var marginWidth = document.body.style.marginRight.substring(0,document.body.style.marginRight.length-2);

		document.body.style.marginRight = (parseInt(marginWidth) + 17) + "px";

	}

	

	

	createPopupBck('container');

	function c(v, pre){return (pre || "").concat(parseInt(v), "px")};

	

	

	var	div = document.getElementById(contentDiv);		



	with(div.style) 

	{

		position = "absolute";

		zIndex = 999;

		

		if(popupWidth) {

			left = "50%";

			width = c(popupWidth);

			marginLeft = c(popupWidth/2, "-");

		}

		if(popupHeight) {

			top = "50%";

			heigth = c(popupHeight);

			marginTop = c(popupHeight/2, "-");

		}

		display = '';

		visibility = 'visible';		

	};

	document.body.appendChild(div);	

	return div;

};





function createPopupBck(backGroundDiv)

{

	var	div = document.getElementById(backGroundDiv);	

	document.body.scrollTop = '0';

	document.body.scrollLeft = '0';

	

	

	with(div.style) 

	{

		left = "0";

		top = "0";

		heigth = "100%";

		// Per firefox metto la larghezza al 100%

		if(navigator.userAgent.indexOf("Firefox")!=-1)

			width = "100%";

		else

			width= document.body.clientWidth;

		marginTop = "0";

		marginLeft = "0";

		position = "absolute";

		display = '';

		visibility = 'visible';		

	};

	document.body.appendChild(div);	

	return div;

};



function resizePoupUpBack()

{

	var	div = document.getElementById('container');		

	if (div != null)

	{

		

		with(div.style) 

		{

			top = '0';

			left = '0';

			// Per firefox metto la larghezza al 100%

			if(navigator.userAgent.indexOf("Firefox")!=-1)

				width = "100%";

			else

				width= document.body.clientWidth;		

			};

	}

}



function nascondiPopup(contentDiv)

{

	EspandiDiv(contentDiv);

	EspandiDiv('container');

	// Riabilito le scrollbar

	if (document.body.style.overflowX != '')

	{

		document.body.style.overflowX='auto';

		document.body.style.overflowY='scroll';

	}

	else document.body.style.overflow='auto';

	

	// Modifico il margine se c'era

	if (document.body.style.marginRight != '')

	{

		// Se ho un margine lo modifico

		var marginWidth = document.body.style.marginRight.substring(0,document.body.style.marginRight.length-2);

		

		document.body.style.marginRight = marginWidth - 17 + "px";

	}

}
