var bImageSwap = false;
var sBrowserName = navigator.appName;
var nBrowserVer = parseInt(navigator.appVersion);
var oBL_Window;
var sBL_DispObj_OpenTopMenuID = "";
var sBL_DispObj_OpenTopMenuClass = "";
var sBL_DispObj_OpenSubMenuID = "";
var sBL_DispObj_MenuColumnClass = ""
var sBL_ExpandID = "";
var sBL_Location = location.href;
var bBL_ExtranetHP = false;	

document.unload = ClosePopup();

if (sBrowserName == "Netscape" && nBrowserVer >= 3) {
	bImageSwap = true; }
else if (sBrowserName == "Microsoft Internet Explorer" && nBrowserVer > 3) {
	bImageSwap = true;
}

function Anchor_OnClick(oAnchor, sSource) {
	var sParams = "";
	if (sSource.toLowerCase() == "template") {
		sParams = "&BL_ExpandID=" + sBL_ExpandID;
	}
	oAnchor.href = oAnchor.href + sParams;
}

function ChangeImage(sImageID, sState) {
	if (bImageSwap) {
		oImage = eval('o' + sImageID + sState + '.src');
		document[sImageID].src = oImage;
	}
}

function ChangeLanguage(nLanguageID) {
	//Save change to user's cookies
	Cookie_Set("BL_SiteLanguageID", nLanguageID.toString(), 180)		
	//Reload page in selected language
	if (sBL_Location.indexOf("AA_SiteLanguageID=") >= 0) {
		var oRegExp = /AA_SiteLanguageID=[0-9]*/gi;
		location.href = sBL_Location.replace(oRegExp, "AA_SiteLanguageID=" + nLanguageID.toString());
	}else {
		if (sBL_Location.indexOf("Page.asp") >= 0) {
			if (sBL_Location.indexOf("?PageID=") >= 0) {
				location.href = sBL_Location + "&AA_SiteLanguageID=" + nLanguageID.toString();
			}else {
				if (bBL_ExtranetHP) {
					//this option handles scenario when user logs in and switches langs right away
					location.href = sBL_Location + "?PageID=1012&AA_SiteLanguageID=" + nLanguageID.toString();
				}else {
					location.href = sBL_Location + "?AA_SiteLanguageID=" + nLanguageID.toString();
				}
			}
		}else {
			location.href = sBL_Location + "Page.asp?AA_SiteLanguageID=" + nLanguageID.toString();
		}
	}
}

function ClassificationDropDownChange(oSelect) {
	location.href = "Page.asp?" + oSelect.options[oSelect.selectedIndex].value;
}

function ClassificationEditPopup(sSiteNodeID) {
	ClosePopup();
	oBL_Window = window.open("Page.asp?PageID=814&SiteNodeID=" + sSiteNodeID + "&AA_FormType=Edit&frompub=true", "_blank", "width=750,heigth=600,toolbar=no,location=no,directories=no,resizable=yes,scrollbars=yes");
}

function ClosePopup() {
	if (oBL_Window && oBL_Window.open && !oBL_Window.closed) {
		oBL_Window.close();
	}
}

function ContentEditPopup(sEditLinkPageID, sContentID) {
	ClosePopup();
	oBL_Window = window.open("Page.asp?PageID=" + sEditLinkPageID + "&Content_RecordID=" + sContentID + "&SiteLanguageID=1&AA_FormType=Edit&frompub=true", "_blank", "width=750,heigth=600,toolbar=no,location=no,directories=no,resizable=yes,scrollbars=yes");
}

function Cookie_Get(sName) {
	if (document.cookie.length > 0)  {
		var nPosStart = document.cookie.indexOf(sName + "=");
		if (nPosStart > -1) {
			nPosStart = nPosStart + sName.length + 1;
			var nPosEnd = document.cookie.indexOf(";", nPosStart);
			if (nPosEnd == -1) {
				nPosEnd = document.cookie.length;
			}
			return unescape(document.cookie.substring(nPosStart, nPosEnd));
		}
	}
	return "";
}

function Cookie_Set(sName, vValue, nDaysTillExpiration) {
	var dExpDate = new Date();
	dExpDate.setDate(dExpDate.getDate() + nDaysTillExpiration);
	document.cookie = sName + "=" + vValue + ";expires=" + dExpDate.toGMTString();
}

function CopyrightNotice() {
	PopupWindow("Page.asp?PageID=332");
}

function DatePickerLaunch(sForm, sInputName) {
	var sDate = eval("document." + sForm + "." + sInputName + ".value");
	var remote=open("Page.asp?PageID=2&AA_Target=" + sForm + "." + sInputName + "&AA_Date=" + sDate, "DatePicker", "width=210,height=142,alwaysLowered=0,alwaysRaised=0,channelmode=0,dependent=0,directories=0,fullscreen=0,hotkeys=1,location=0,menubar=0,resizable=0,scrollbars=0,status=0,titlebar=1,toolbar=0,z-lock=0");
	if (remote.opener==null) {remote.opener=window;	remote.opener.name = "TextBody"}
}

function EmailAFriend() {
	var sUrl = "";
	var nAmpLoc = sBL_Location.indexOf("?");
	if (nAmpLoc > -1) {
		sUrl = "&Site" + sBL_Location.substring(nAmpLoc + 1, sBL_Location.length);
	}
	PopupWindow("Page.asp?PageID=247" + sUrl, "600", "550");
}

function ErrorMsgInline(elmId, msg) {
	document.getElementById(elmId).innerHTML = msg;
	if (msg.length > 0) {
		document.getElementById(elmId).style.display = "block";
	}else {
		document.getElementById(elmId).style.display = "none";
	}
}	

function GetPosition(sElement, sPosition) {
	var oElement = document.getElementById(sElement);
	var nPosition = eval("oElement.offset" + sPosition);
	var oTempElement = oElement.offsetParent;
	while (oTempElement != null) {
		nPosition += eval("oTempElement.offset" + sPosition);
		oTempElement = oTempElement.offsetParent;
	}
	return nPosition;
}

function GetQueryParameter(sParam, sConChar) {
	if (sConChar == null) {
		sConChar = "&";
	}
	var nStartPos = sBL_Location.indexOf(sConChar + sParam + "=");
	if (nStartPos > 0) {
		var nEndPos = sBL_Location.indexOf("&", nStartPos + 1);
		if (nEndPos == -1) {
			nEndPos = sBL_Location.length;
		}
		if (sBL_Location.indexOf("<") > -1 || sBL_Location.indexOf(">") > -1 || sBL_Location.toLowerCase().indexOf("%3c") > -1 || sBL_Location.toLowerCase().indexOf("%3e") > -1) {
			return "";
		}else {
			return escape(sBL_Location.substring(nStartPos + sParam.length + 2, nEndPos));
		}
	}else {
		return "";
	}
}

function LinkingPolicy() {
	PopupWindow("Page.asp?PageID=333");
}

function NavHome() {
	location.href = "Page.asp?PageID=" + sBL_HomePageID + "&BL_WebsiteID=" + sBL_WebsiteID;
}

function NavLastSavedURL() {
	var url = Cookie_Get("BL_SavedURL");
	if (url.length > 0) {
		location.href = url;
	}else {
		alert(oBL_General_Pub_Lang.ErrMsg_NoSavedURL);
	}
}

function NavSitemap() {
	location.href = "Page.asp?PageID=" + sBL_SitemapPageID + "&BL_WebsiteID=" + sBL_WebsiteID;
}

function NavSubscriptionForm() {
	location.href = "Page.asp?PageID=340&BL_WebsiteID=" + sBL_WebsiteID;
}

function PopupWindow(sUrl, sWidth, sHeight) {
	ClosePopup()
	if (sWidth == null) {
		sWidth = "500";
	}
	if (sHeight == null) {
		sHeight = "400";
	}		
	oBL_Window = window.open(sUrl, "Popup", "width=" + sWidth + ",height=" + sHeight + ",alwaysLowered=0,alwaysRaised=0,channelmode=0,dependent=0,directories=0,fullscreen=0,hotkeys=1,location=0,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=1,toolbar=0,z-lock=0");
}

function PrinterFriendly() {
	var sLocation = sBL_Location;
	var nAmpLoc = sLocation.indexOf("#");
	if (nAmpLoc > -1) {
		sLocation = sLocation.substr(0, nAmpLoc)
	}
	if (document.getElementById("Content_FontSizeControlSmall")) {
		if (document.getElementById("Content_FontSizeControlSmall").className == "Content_FontSizeControlHover") {
			sLocation += "&BL_FontSize=xx-small";
		}else if (document.getElementById("Content_FontSizeControlLarge").className == "Content_FontSizeControlHover") {
			sLocation += "&BL_FontSize=larger";
		}
	}
	PopupWindow(sLocation + "&AA_PrintFriendlyMode=True", "505", "500");
}

function PrintPage() {
	if (window.print)
	{
		window.print();
	}
	else
	{
		alert(oBL_General_Pub_Lang.ErrMsg_PrintPage);
	}	
	
	return false;
}

function PrivacyPolicy() {
	PopupWindow("Page.asp?PageID=325");
}

function QuestionComment() {
	var sUrl = "Page.asp?PageID=248&RefPageID=" + GetQueryParameter("PageID", "?") + "&ContentID=" + GetQueryParameter("ContentID");
	PopupWindow(sUrl, "600", "550");
}

function SaveURL() {		
	Cookie_Set("BL_SavedURL", location.href, 180);
	alert(oBL_General_Pub_Lang.ErrMsg_URLSavedMessage);
}

function SendContactEmail() {
	location.href = "mailto:" + sBL_ContactEmail;
}

function SetFontSize(sTxtFrameElmID, sFontSize, sIconID) {
	var oTxtFrameArray = new Array("Content_ArticleTextFrame", "Content_EventWhenWhere", "Content_EventTextFrame", "Content_FlashTextFrame", "Content_FormTextFrame", "Content_GMapTextFramePre", "Content_GMapTextFramePost", "Content_ProductPriceSKUFrame", "Content_ProductGraphicRightPane", "Content_ProductDescriptionFrame", "Content_ProfileBioFrame", "Content_QADates", "Content_QATextFrame", "Content_StorageTextFrame");
	for (var i = 0; i < oTxtFrameArray.length; i++) {
		sItem = oTxtFrameArray[i] + sTxtFrameElmID;
		if (document.getElementById(sItem)) {
			document.getElementById(sItem).style.fontSize = sFontSize;
		}
	}
	
	if (sIconID != "") {
		document.getElementById("Content_FontSizeControlSmall").className = "Content_FontSizeControl";
		document.getElementById("Content_FontSizeControlNormal").className = "Content_FontSizeControl";
		document.getElementById("Content_FontSizeControlLarge").className = "Content_FontSizeControl";
		document.getElementById("Content_FontSizeControl" + sIconID).className = "Content_FontSizeControlHover";
	}
}

function StartSearch() {
	location.href = "Page.asp?PageID=258&SearchKeywords=True&SearchTitles=True&SearchIntros=True&SearchContent=True&BL_OrderBy=PublishDate%20DESC&BL_CurrentSearchPg=1&BL_WebsiteID=" + sBL_WebsiteID;
}	

function StoragePopup(nID, nUsageID) {
	ClosePopup();
	oBL_Window = window.open("Page.asp?PageID=1105&StorageID=" + nID.toString() + "&Storage_UsageID=" + nUsageID, "PreviewWin", "width=1,height=1,alwaysLowered=0,alwaysRaised=0,channelmode=0,dependent=0,directories=0,fullscreen=0,hotkeys=1,location=0,menubar=0,resizable=1,scrollbars=1,status=0,titlebar=1,toolbar=0,z-lock=0");
}

function Subscribe(oForm) {
	var email = oForm.Email.value;
	
	if (email.length > 0) {
		email = email.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
		oForm.Email.value = email;
		if (email.length >= 6) {
			var atPos = email.indexOf("@");
			
			if (atPos > -1) {
				var dotPos = email.indexOf(".", atPos);
			
				if (dotPos > (atPos + 1)) {
					return true;
				}
			}
		}
	}
	alert(oBL_General_Pub_Lang.ValidationMsg_Subscribe);
	return false;
}