
// only do popups if this is true
var popupsEnabled = true;

var WinProps = new Object();
	WinProps.FEATURES_FULL = "toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,";
	WinProps.FEATURES_INFO = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,alwaysRaised,dependent,";
	WinProps.FEATURES_POPUPFORM = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,";
	WinProps.SIZE_FULL = "width=800,height=600,";

/**
 * Opens popup windows, this should be used for ALL popups.
 * TODO: document arguments
 */
function popWin() {
	var url				= arguments[0]; // required - url
	var name			= arguments[1]; // required - window name
	var winProperties	= arguments[2];	// required - window properties
	var isBlockable		= arguments[3]; // required - is the popup blockable ?
	var under			= arguments[4]; // optional - boolean for popunder
	var form			= arguments[5]; // optional - form object

	// only do it if popups are enabled
	if (!popupsEnabled && isBlockable) {
		return null;
	}

	// get form variables
	if (form) {
		url += (url.indexOf("?")==-1) ? "?" : "&";
		url += getFormValueQueryString(form);
	}

	// open the window
	var win = window.open(
		url,
		name,
		winProperties
	);

	// is it a popunder?
	if (under) {
		try { win.blur(); } catch(ex) {}
		self.focus();
	}

	// return
	return win;
}

/**
 * Opens a link in window.opener if it is available, or launches it in a new 800x600 window if window.opener was closed,
 * then closes the current window (useful for popups). If window.opener never existed, loads the link in the same window.
 *
 * Usage: <a href="foo.jsp" onclick="openLinkInOpener(this.href);">
 */
function openLinkInOpener(sUrl) {
	if (window.opener) {
		if (!window.opener.closed) {
			window.opener.location.href = sUrl;
		} else {
			window.open(sUrl, "_blank", WinProps.SIZE_FULL + WinProps.FEATURES_FULL);
		}
		self.close();
	}
}

/*
 * DOM show/hide functions.
 * Do not set display to "block", it breaks things like table rows.
 */
function showElement(strID) {
	try { document.getElementById(strID).style.display = ""; } catch(ex) {}
}
function hideElement(strID) {
	try { document.getElementById(strID).style.display = "none"; } catch(ex) {}
}

function hideElements() {
	if (!arguments.length) { return; }
	for (var i=0; i < arguments.length; i++) {
		hideElement(arguments[i]);
	}
}

function showElements() {
	if (!arguments.length) { return; }
	for (var i=0; i < arguments.length; i++) {
		showElement(arguments[i]);
	}
}

/*
 * CSS2 emulation for MS Internet Explorer.
 * Used for the rounded corners on sidepanel headers.
 */
function constExpression(x) {
   return x;
}
function sidepanelGroupH3MSIE(hNode) {
	try {
		switch(hNode.previousSibling.currentStyle.backgroundColor) {
			case "#ffffff": return "url(/images/common/round_corner_white.gif)"; break;
			case "#ffffcc": return "url(/images/common/round_corner_yellow.gif)"; break;
			case "transparent": return "url()"; break;
		}
	} catch(ex) {}
	return "url()";
}

/*
 * Generic UL-tree functions.
 * Used for calculator tree lists.
 */
function openTree(strIdRoot) {
	hideElement(strIdRoot.concat("-closed"));
	showElement(strIdRoot.concat("-open"));
}
function closeTree(strIdRoot) {
	hideElement(strIdRoot.concat("-open"));
	showElement(strIdRoot.concat("-closed"));
}
function closeAllTrees(arrIds) {
	for (var i=0; i < arrIds.length; i++) {
		closeTree(arrIds[i]);
	}
}

/*
 * Calculator-specific functions.
 */
var arrCalcIds = ["CalcLHP", "CalcLRE", "CalcLDC", "CalcLHE"];
var arrMoreIds = ["CalcMoreLHP", "CalcMoreLRE", "CalcMoreLDC", "CalcMoreLHE"];
function openCalcTree(strIdRoot) {
	closeAllTrees(arrCalcIds);
	openTree(strIdRoot);
	closeAllTrees(arrMoreIds);
}
function openCalcWindow(strFile) {
    var site = "http://www.lowermybills.com/fh/popUps/lending_calculator.jsp?content=https://securetools.leadfusion.com/leadfusion/lowermybills/" + strFile;
	var newCalcWindow = window.open(site, "client3", "width=480,height=600,scrollbars=yes,alwaysRaised,resizable=yes,toolbar,dependent");
}

function openChildWindow(url, width, height, scrollbars, resizable) {
	popWin(
		url,
		"client9",
		"width="+width+",height="+height+",scrollbars="+scrollbars+",alwaysRaised,resizable="+resizable+",dependent",
		 false
	);
}

function opensmallWindow(url) {
	popWin(
		url,
		"wSmInfoPopup",
		"width=350,height=225,scrollbars=yes,alwaysRaised,dependent",
		false
	);
}

function openmidWindow(url) {
	popWin(
		url,
		"wMidInfoPopup",
		"width=300,height=312,scrollbars=yes,alwaysRaised,resizable=yes,dependent",
		false
	);
}

function doExitPopSuppression() {
	if (!document.links) { return; }
	/****************** Issue 37220************************
	This is an inelegant hack
	In order not to get a run time error when user clicks Right Button and chooses Open In New Window for 
	DNC-Terms of Use and Privacy Pledge
	******************************************************/
	for (var i=0; i < document.links.length; i++) {
	//LEND-351 - Revert the fix made for 37220
		//currentLink  = document.links[i].href;
        //if(currentLink.indexOf("termsofuse") == -1 && currentLink.indexOf("privacy") == -1)
		document.links[i].onclick = new Function("popupsEnabled=false");
	}
}

