window.bN_LBFrame = window;

function bN_TestBrowser() {
	var myWidth = 0, myHeight = 0;
	var nMinWinWh = 993, flagMsg = false;

	if(typeof(window.innerWidth) == 'number')
	{
		//Non-IE
		myWidth  = window.innerWidth;
		myHeight = window.innerHeight;
	} else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		//IE 6+ in 'standards compliant mode'
		myWidth  = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if(document.body && (document.body.clientWidth || document.body.clientHeight)) {
		//IE 4 compatible
		myWidth  = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	
	cMsg = "WARNING...\n\n";
	
	if(myWidth < nMinWinWh)
	{
		flagMsg = true;
		cMsg += "Your browser window size is too small to fit the entire website content.\nPlease to resize your browser window to fully use this website!\n\n";
	}
	if(window.opera || navigator.userAgent.toLowerCase().indexOf('opera') + 1)
	{
		flagMsg = true;
		cMsg += "We are sorry but OPERA browser is currently not supported by this website!!\nPlease to use InternetExplorer, Netscape or FireFox.";
	}
	
	if(flagMsg) alert(cMsg);
}
//bN_TestBrowser();

document.loadingTimer = -1;

//
//
/*
function bN_FixY()
{
	var x, y;
	var obj = bN_findObj("layerLoading");
	var IE = navigator.appName.indexOf("Microsoft") != -1;

	if(!obj) return;

	y = (document.documentElement ? document.documentElement.scrollTop : document.body.scrollTop);
	x = (document.documentElement ? document.documentElement.clientWidth : document.body.clientWidth);

	if(y < 0) y = 0;
	obj.style.top  = "" + y + "px";
	obj.style.left = "" + (x - 105) + "px";
}
*/

//
//
function bN_ShowLoading(flagVisible)
{
	var   obj = bN_findObj("layerLoading");

	if(!obj) return;
/*	
	bN_FixY();
	
	if(flagVisible)
	{
		if(document.loadingTimer >= 0) clearInterval(document.loadingTimer);
		document.loadingTimer = window.setInterval("bN_FixY()", 50);
	}
	else {
		if(document.loadingTimer >= 0) clearInterval(document.loadingTimer);
		document.loadingTimer = -1;
	}
*/
	obj.style.visibility = (flagVisible ? "visible" : "hidden");
}


//
//
function bN_SetBodyEvents(obj)
{
	var IE = navigator.appName.indexOf("Microsoft") != -1;
	
	if(IE)
		obj.onresize = IFRAME_resize;
	else {
		window.captureEvents(Event.RESIZE);
		window.onresize = bN_IFRAME_ResizeHandler;
	}
}

function bN_IFRAME_ResizeHandler()
{
	IFRAME_resize();
}


//
//
function bN_IFRAME_Loaded(obj)
{
	var IE = navigator.appName.indexOf("Microsoft") != -1;
	var e = window.event || arguments.callee.caller.arguments[0];
	
	if(!obj)
	{
		if(IE) obj = e.srcElement;
		else   obj = e.target;
	}

	IFRAME_closeFrame(obj.name);
	IFRAME_sizer(obj.name);
//	bN_SetBodyEvents(obj);
}


//
//
function bN_PageLoaded()
{
	bN_preloadImages('/images/menu_news_on.gif','images/menu_files_on.gif','images/menu_chats_on.gif','images/menu_forums_on.gif','/images/menu_news_off.gif','images/menu_files_off.gif','images/menu_chats_off.gif','images/menu_forums_off.gif','images/wait.gif');
}

//
//
function bN_ShowHideTab(nTab, cStato, cFrameNameToReload)
{
	var IE = navigator.appName.indexOf("Microsoft") != -1;
	var obj;
	var cFrameName = (cFrameNameToReload == null || cFrameNameToReload == 'undefined' ? "" : cFrameNameToReload);
	
	id = 'tab' + nTab;
	if(cStato == null || cStato == 'undefined' || cStato == "")
		cStato = "";

	obj = bN_findObj(id);
	if(!obj) return 1;

	obj = obj.style;

	if((obj.display == "" || obj.display != "none") && (cStato=="" || cStato=="open"))
		obj.display = "none";
	else if(cStato=="" || cStato=="close")
	{
		obj.display = "";

		if(cFrameName != "")
			bN_goToURL(cFrameName, bN_GetFrameLocation(cFrameName));
	}
}

//
//
function bN_ChangePSM()
{
	var obj = bN_findObj("psm");
	var cPsm;
	
	if(!obj) return;
	cPsm = escape(obj.value);
	if(cPsm.length == 0) cPsm = "/?/";
	bN_goToURL("whoonline", "who_online.asp?psm=" + cPsm);
}

//
//
function bN_SetUploading(cState)
{
	bN_goToURL("whoonline", "/who_online.asp?up=" + cState);
}

//
//
function bN_ChangeStatus()
{
	var objStatus = bN_findObj("status");

	if(!objStatus) return;
	bN_goToURL("whoonline", "who_online.asp?st=" + objStatus.value);
}

//
//
function bN_ChangeMood()
{
	var objMood = bN_findObj("mood");

	if(!objMood) return;
	bN_goToURL("whoonline", "who_online.asp?md=" + objMood.value);
}

////////////////////////////////////////////
// USERPLANE WEBCHAT...
////////////////////////////////////////////
document.bN_chatWindowHandle = 0;

//
//
function bN_ShowUserProfile(cUserID)
{
	bN_goToURL("content", "/userdata.asp?idu=" + cUserID);
}

//
//
function bN_UpdateWCUser(cSessionID)
{
	bN_goToURL("WCNotifier", "/webchat/userplane/chat/cmd.asp?cmd=User.ForceReload&sid=" + cSessionID);
}
////////////////////////////////////////////
////////////////////////////////////////////

//
//
function bN_UnloadDone(xmlHttpReq, objParams)
{
	// Se terminato...
	if(xmlHttpReq.readyState == 4)
	{
		switch(xmlHttpReq.status)
		{
			// Se andato a buon fine...
			case 200:
				break;

			// Altrimenti...
			default:
				break;
		}
	}
}

//
function bN_ShowPMs()
{
	bN_findObj("bNMessage").innerHTML  = "&nbsp;";
	bN_findObj("bNMsgImage").innerHTML = "&nbsp;";
	bN_showHideLayers("lvMsgs", 0, "hide");
	bN_goToURL("content", "/userpanel.asp?p=/forum/pm_inbox.asp");
	document.gbl_flagAlertType = "";
}

//
function bN_ShowAlert(cType, xParam1)
{
	var cMsg, cImage, cBk;
	
	cImage = "&nbsp;";
	document.gbl_flagAlertType = cType;
	
	if(xParam1.substr(0,1) == "-")
	{
		bN_showHideLayers("lvMsgs", 0, "hide");
		return;
	}
	
	switch(cType)
	{
		case "PMS":
			cMsg   = "You've <B>new</B> Private Message(s)!<br />Click <a href=\"javascript:bN_ShowPMs();\"><B>HERE</B></a> to read them all.";
			cImage = "<img src=\"images/new_inbox.gif\" />";
			cBk    = "url(../images/message_bk.gif)";
			break;

		case "BUYSELL":
			var a = xParam1.split("#%");
			cMsg   = "<div align='center'><B>BUY & SELL</B> area...<BR /><B><font class='piccolo'>" + a[1] + "</font></B></div>";
			cImage = "<img src=\"" + a[0] + "\" />";
			cBk    = "url(../images/message_bk2.gif)";
			break;
/*
		case "BLOGS":
			var a = xParam1.split("#%");
			cMsg   = "<div align='center'>check out the BLOG of <br /><B>" + a[0] + "</B><BR /><br/><a target=\"_blank\" href=\"http://<%=Application("BLOG_FOLDER")%>.heartbeatpleasure.net/" + a[0] + "/Default.aspx\"><B><font class='piccolo'>" + a[1] + "</font></B></div>";
			cImage = "<img src=\"images/alert_blog.png\" />";
			cBk    = "url(../images/message_bk1.gif)";
			break;
*/		

		case "ANNOUNCE":
			cMsg   = "";
			cImage = "";
			cBk    = "url(../images/announce1_bk.png)";
			break;

		default:
			bN_showHideLayers("lvMsgs", 0, "hide");
			return;
	}
	bN_findObj("bNMessage").innerHTML  = cMsg;
	bN_findObj("bNMsgImage").innerHTML = cImage;
	bN_findObj("bNMsgBk").style.backgroundImage = cBk;
	bN_findObj("bNMsgBk").style.backgroundPosition = "370px";
	bN_findObj("bNMsgBk").style.backgroundRepeat = "no-repeat";
	bN_showHideLayers("lvMsgs", 0, "show");
}


function bN_AlertLoaded(xmlHttpReq, objParams)
{
	// Se terminato...
	if(xmlHttpReq.readyState == 4)
	{
		var objRateContainer = bN_findObj("voter" + objParams.id);
		switch(xmlHttpReq.status)
		{
			// Se andato a buon fine...
			case 200:
				bN_ShowAlert(objParams.p, xmlHttpReq.responseText);
				break;
		}
	}
}

function bN_ShowNewAlert()
{
	if(document.gbl_flagAlertType == "PMS")
		return;

	var n = parseInt(Math.random()*3);
	var p = "";
	switch(n)
	{
		case 0:
			bN_ShowAlert("", "");
			return;
	
		case 1:
			p = "BUYSELL";
			break;
			
		case 2:
			p = "BLOGS";
			break;

		case 3:
//			bN_ShowAlert("ANNOUNCE", "");
			return;
	}

	bN_findObj("tipo").value = p;

	var objParams = new Object;
	objParams.p = p;
	bN_postForm("formAlerts", true, bN_AlertLoaded, objParams);
}

//
function bN_ClickShield(nShield)
{
	bN_goToURL("content", "/shields.asp?s=" + nShield);
	bN_goToURL("window", "#topc");
}


//
function bN_FlvLoaded(xmlHttpReq, objParams)
{
	// Se terminato...
	if(xmlHttpReq.readyState == 4)
	{
		switch(xmlHttpReq.status)
		{
			// Se andato a buon fine...
			case 200:
				var objFlv = bN_findObj("flvLayer");
				if(!objFlv) return;
				objFlv.style.height = document.body.scrollHeight + "px";
				objFlv.innerHTML = xmlHttpReq.responseText;
				bN_findObj("tblFlv").style.height = bN_GetDocumentHeight() + "px";
				bN_findObj("flvYOffset").style.height = document.bN_OldTopPosition + "px";
				bN_showHideLayers("flvLayer", 0, "show");
				break;
		}
	}
}


//
function bN_BlockScroll()
{
	window.onscroll = null;
	window.onmousewheel = null;
	window.scrollTo(document.bN_OldLeftPosition, document.bN_OldTopPosition);
	window.onscroll = bN_BlockScroll;
	window.onmousewheel = bN_BlockScroll;
	
	return false;
}

//
function bN_ShowFlv(id, t, lq)
{
	bN_findObj("idf").value = id;
	bN_findObj("t").value = t;

	if(typeof(lq) != "boolean") lq = 0;
	else lq = (lq ? 1 : 0);

	bN_findObj("lq").value = lq;

	var objParams = new Object;
	objParams.id = id;
	bN_postForm("formFlv", true, bN_FlvLoaded, objParams);

	document.bN_OldTopPosition  = bN_GetPageScrollTop();
	document.bN_OldLeftPosition = bN_GetPageScrollLeft();

	bN_BlockScroll();
}

//
function bN_HideFlv()
{
	var objFlv = bN_findObj("flvLayer");
	if(!objFlv) return;
	objFlv.innerHTML = "&nbsp;";
	bN_showHideLayers("flvLayer", 0, "hide");

	window.onscroll = null;
	window.onmousewheel = null;
}

//
function bN_ReloadFlv()
{
	var objParams = new Object;
	objParams.id = bN_findObj("idf").value;
	bN_postForm("formFlv", true, bN_FlvLoaded, objParams);

	document.bN_OldTopPosition  = bN_GetPageScrollTop();
	document.bN_OldLeftPosition = bN_GetPageScrollLeft();
}

