/////////////////////////////////////////////////////////////////////////////
// GENERAL FUNCTIONS
/////////////////////////////////////////////////////////////////////////////

//
//
function bN_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=bN_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function bN_swapImage() { //v3.0
  var i,j=0,x,a=bN_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=bN_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function bN_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=bN_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function bN_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function bN_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function bN_goToURL() { //v3.0
	var IE = navigator.appName.indexOf("Microsoft") != -1;
	var a = bN_goToURL.arguments;
	var obj;
	
	if(a[0] != "window")
		obj = bN_findObj(a[0]);
	else
		obj = window;
	
	if(typeof(obj.src) == "string")
		obj.src = a[1];
	else
		obj.location = a[1];
}

function bN_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function bN_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = bN_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}

/////////////////////////////////////////////////////////////////////////////
// FLASH FUNCTIONS
/////////////////////////////////////////////////////////////////////////////

//
//
function bN_FlashGotoLabel(objName, levelName, label)
{
	var IE = navigator.appName.indexOf("Microsoft") != -1;
	var obj;
	
	if(typeof(objName) != "object")
		obj=bN_findObj(objName);
	else {
		obj = objName;
	}
	
	if(IE ? obj.PercentLoaded() < 100 : obj[1].PercentLoaded() < 100) {
		setTimeout("bN_FlashGotoLabel('" + objName + "', '" + levelName + "', '" + label + "')", 1000);
		return;
	}

	if(IE) obj.TGotoLabel(levelName,label);
	else obj[1].TGotoLabel(levelName,label);
}

//
//
function bN_FlashSetVariable(objName, levelName, label)
{
	var IE  = navigator.appName.indexOf("Microsoft") != -1;
	var obj;

	if(typeof(objName) != "object")
		obj=bN_findObj(objName);
	else {
		obj = objName;
	}

	if(IE ? obj.PercentLoaded() < 100 : obj[1].PercentLoaded() < 100) {
		setTimeout("bN_FlashSetVariable('" + objName + "', '" + levelName + "', '" + label + "')", 1000);
		return;
	}

	if(IE) obj.SetVariable(levelName,label);
	else obj[1].SetVariable(levelName,label);
}

/////////////////////////////////////////////////////////////////////////////
// IFRAME FUNCTIONS
/////////////////////////////////////////////////////////////////////////////

//
//
function bN_getElement(id, objIframeContainer) {
	return document.getElementById ? objIframeContainer.document.getElementById(id) : objIframeContainer.document.all ? objIframeContainer.document.all(id) : null;
}

//
//
function IFRAME_size_to_content(iframe_id, objIframeContainer, userHeight)
{
	var IE = navigator.appName.indexOf("Microsoft") != -1;
	var obj_iframe = bN_getElement(iframe_id, objIframeContainer);
	
	var ht = parseInt(IE ? obj_iframe.Document.body.scrollHeight : obj_iframe.contentDocument.documentElement.offsetHeight);

	if(userHeight > 0) ht = userHeight;
	bN_last_iFRAME_HT = ht;
	if(IE) obj_iframe.style.height = ht;
	else obj_iframe.height = ht;
}

//
//
function IFRAME_sizer(frameName, parentFrame, flagSizeToFrame, htDelta)
{
	var IE = navigator.appName.indexOf("Microsoft") != -1;

	if(typeof(parentFrame) != 'object')
		parentFrame = top;
	if(typeof(frameName) != 'string')
		frameName = 'content';

	if(flagSizeToFrame) {
		ht = (IE ? parentFrame.Document.body.clientHeight : parentFrame.document.height);
		ht -=  (typeof(htDelta) == 'number' ? htDelta : 0);
	}
	else ht = 0;
   
	IFRAME_size_to_content(frameName, parentFrame, 1);
	IFRAME_size_to_content(frameName, parentFrame, ht);

	// Nascondo il Layer di caricamento presente nel frame padre...
	bN_IFRAME_ShowLoading(parentFrame, false);
}

function bN_IFRAME_ShowLoading(parentFrame, flag)
{
	if(typeof(parentFrame.bN_ShowLoading) != "function") return;
	if(flag) parentFrame.scroll(0,0);
	parentFrame.bN_ShowLoading(flag, bN_last_iFRAME_HT);
}

/////////////////////////////////////////////////////////////////////////////
// GENERAL SCRIPTS
/////////////////////////////////////////////////////////////////////////////
//
var bN_last_iFRAME_HT = 0;
