// 3/27/2007 JKA - Tracker 52831 - Add functions for new banner

// linkOpen - Converts string "aUrl" to a URL on the non-secure server.
function linkOpen(aUrl)
{
	if (aUrl.indexOf(":") >= 0 || location.protocol != "https:")
		return aUrl;
	var url = null;
	var host = location.host;
	var pathpos = location.href.indexOf(host) + host.length;
	var prot = "http://";
	if (host == "nipr-qa.nipr.com:2020" || host == "nipr-qa.naic.org:2020")
		host = "nipr-qa.nipr.com:2021";
	if (aUrl.substring(0, 1) == "/")
		url = prot + host + aUrl;
	else
	{
		var path = location.pathname;
		if (path == null || path == "")
			path = "/";
		else
			path = path.substring(0, path.lastIndexOf("/") + 1);
		url = prot + host + path + aUrl;
	}
	return url;
}

// linkSecure - Converts string "aUrl" to a URL on the secure server.
function linkSecure(aUrl)
{
	if (aUrl.indexOf(":") >= 0 || location.protocol != "http:")
		return aUrl;
	var url = null;
	var host = location.host;
	var pathpos = location.href.indexOf(host) + host.length;
	var prot = "https://";
	if (host == "nipr-qa.nipr.com:2021" || host == "nipr-qa.naic.org:2021")
		host = "nipr-qa.nipr.com:2020";
	if (aUrl.substring(0, 1) == "/")
		url = prot + host + aUrl;
	else
	{
		var path = location.pathname;
		if (path == null || path == "")
			path = "/";
		else
			path = path.substring(0, path.lastIndexOf("/") + 1);
		url = prot + host + path + aUrl;
	}
	return url;
}

// MM_preloadImages - Loads all images the page will use
function MM_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 = MM_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];
			}
	}
}

// MM_swapImgRestore - Returns the image to its default
function MM_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;
}

// MM_findObj - ???
function MM_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 = MM_findObj(n, d.layers[i].document);
	if (!x && d.getElementById)
		x = d.getElementById(n);
	return x;
}

// MM_swapImage - Swaps the image
function MM_swapImage()
{ //v3.0
	var i, j = 0, x, a = MM_swapImage.arguments;
	document.MM_sr = new Array;
	for (i = 0; i < (a.length-2); i+=3)
		if ((x = MM_findObj(a[i])) != null)
		{
			document.MM_sr[j++] = x;
			if (!x.oSrc)
				x.oSrc = x.src;
			x.src = a[i+2];
		}
}

var niprTotalWidth = 750;		// The width of the entire display area.
var niprMenuWidth = 203;		// The width of the menu area.
var tdClassName = "menu_cell";	// The class name of menu cells.
var aClassName = "menu_link";	// The class name of menu links.
var initIndent = 5;				// The initial amount of indentation of menu items.

// getNIPRBanner - Returns the banner HTML. Call this in a document.write() function call. displayText
//	is a string that is displayed dynamically. homeLink is the URL to use for the "Home" link; if this
//	is null or not present, the default home URL will be used (as defined by getNIPRFooterLinks).
function getNIPRBanner(displayText, homeLink)
{
	// 3/27/2007 JKA - Tracker 52831 - New NIPR banner
	MM_preloadImages("/images/header_home_on.jpg", "/images/header_about_on.jpg", 
		"/images/header_search_on.jpg", "/images/header_contact_help_on.jpg");
	var hl = homeLink;
	if (homeLink == null || homeLink == "")
	{
		var links = getNIPRFooterLinks();
		for (var linkNum = 0; linkNum < links.length; linkNum++)
			if (links[linkNum].text == "Home")
			{
				hl = links[linkNum].url;
				break;
			}
	}
	document.nipr_use_menu = false;
	var banner = "";
	banner += "<table width=\"" + niprTotalWidth + "\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">\n";
	banner += "	<tr>\n";
	banner += "		<td>\n";
	banner += "			<table width=\"" + niprTotalWidth + "\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
	banner += "				<tr>\n";
	banner += "					<td width=\"80\"><a href=\"" + hl + "\" onMouseOver=\"MM_swapImage('Image1','','/images/header_home_on.jpg',1)\" onMouseOut=\"MM_swapImgRestore()\"><img src=\"/images/header_home_off.jpg\" name=\"Image1\" width=\"80\" height=\"22\" border=\"0\" id=\"Image1\"></a></td>\n";
	banner += "					<td width=\"101\"><a href=\"" + linkOpen("/about_nipr.htm") + "\" onMouseOver=\"MM_swapImage('Image2','','/images/header_about_on.jpg',1)\" onMouseOut=\"MM_swapImgRestore()\"><img src=\"/images/header_about_off.jpg\" name=\"Image2\" width=\"101\" height=\"22\" border=\"0\" id=\"Image2\"></a></td>\n";
	banner += "					<td width=\"68\"><a href=\"https://external-apps.naic.org/NBP/Basic.jsp\" target=\"_blank\" onMouseOver=\"MM_swapImage('Image3','','/images/header_search_on.jpg',1)\" onMouseOut=\"MM_swapImgRestore()\"><img src=\"/images/header_search_off.jpg\" name=\"Image3\" width=\"68\" height=\"22\" border=\"0\" id=\"Image3\"></a></td>\n";
	banner += "					<td width=\"115\"><a href=\"" + linkOpen("/contacts_help.htm") + "\" onMouseOver=\"MM_swapImage('Image4','','/images/header_contact_help_on.jpg',1)\" onMouseOut=\"MM_swapImgRestore()\"><img src=\"/images/header_contact_help_off.jpg\" name=\"Image4\" width=\"115\" height=\"22\" border=\"0\" id=\"Image4\"></a></td>\n";
	banner += "					<td width=\"386\"><img src=\"/images/header_photo_top.jpg\" width=\"386\" height=\"22\"></td>\n";
	banner += "				</tr>\n";
	banner += "			</table>\n";
	banner += "		</td>\n";
	banner += "	</tr>\n";
	banner += "	<tr>\n";
	banner += "		<td>\n";
	banner += "			<table width=\"" + niprTotalWidth + "\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
	banner += "				<tr>\n";
	banner += "					<td width=\"264\" rowspan=\"2\"><img src=\"/images/header_logo.jpg\" width=\"264\" height=\"106\"></td>\n";
	banner += "					<td><img src=\"/images/header_photo_bottom.jpg\" width=\"486\" height=\"87\"></td>\n";
	banner += "				</tr>\n";
	banner += "				<tr>\n";
	banner += "					<td background=\"/images/header_bottom_black.gif\" align=\"center\" width=\"486\" height=\"19\" class=\"header_text\">" + displayText.toUpperCase() + "</td>\n";
	banner += "				</tr>\n";
	banner += "			</table>\n";
	banner += "		</td>\n";
	banner += "	</tr>\n";
	banner += "</table>\n";
	return banner;
}

// openNIPRMenu - Returns the HTML required to start the menu element. Call this in a document.write() 
//	function call. Menus are optional; if a menu is not desired, call openNIPRBody() instead. Call 
//	this function before calling displayNIPRMenuItem() or displayNIPRMenuSeparator(). getNIPRBanner() 
//	must be called before calling this function.
function openNIPRMenu()
{
	document.nipr_use_menu = true;
	var text = "";
	text += "<table width=\"" + niprTotalWidth + "\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">\n";
	text += "	<tr>\n";
	text += "		<td width=\"" + niprMenuWidth + "\" valign=\"top\" background=\"/images/left_blue_bckgrd.gif\">\n";
	text += "			<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" background=\"/images/left_blue_bckgrd.gif\">\n";
	text += "				<tr><td class=\"" + tdClassName + "\">&nbsp;</td></tr>\n";
	return text;
}

// closeNIPRMenu - Returns the HTML required to end the menu element. Call this in a document.write() 
//	function call. openNIPRMenu() must be called before calling this function. This function must be 
//	called before calling openNIPRBody() *if* openNIPRMenu() was called.
function closeNIPRMenu()
{
	var text = "";
	text += "				<tr><td class=\"" + tdClassName + "\">&nbsp;</td></tr>\n";
	text += "			</table>\n";
	text += "		</td>\n";
	return text;
}

// displayNIPRMenuItem - Returns the HTML that comprises a menu item. Call this in a document.write() 
//	function call. openNIPRMenu() must be called before calling this function. link is the URL to for 
//	the menu link; if this is null or blank, the menu item will be displayed as text only. text is 
//	the text to display for the menu item. hint is the text to display as a tooltip. indent is the 
//	number of pixels to indent the menu item; this is zero by default. target is the target window in 
//	which the link should be opened; this parameter is optional. disabled is a boolean that indicates 
//	whether the item is disabled - it forces the item to be displayed as text-only if present and set 
//	to true. className is the name of the CSS class to use for display; this applies to the <a> 
//	element, or to the <td> element if it is a text-only menu item. style is the style to use for 
//	display; this applies to the <a> element, or to the <td> element if it is a text-only menu item.
function displayNIPRMenuItem(link, text, hint, indent, target, disabled, className, style)
{
	var out = "";
	var tdStyle = "";
	var aIndent = initIndent;
	if (indent != null && indent > 0)
		aIndent += indent;
	tdStyle = "padding-bottom: 3; padding-left: " + aIndent + "; ";
	var tdClass = tdClassName;
	var aText = text;
	if (aText == null)
		aText = "";
	if ((disabled != null && disabled) || link == null || link == "")
	{
		if (className != null)
			tdClass = className;
		if (style != null)
			tdStyle += style;
		if (tdStyle != "")
			tdStyle = " style=\"" + tdStyle + "\"";
		out += "<tr><td class=\"" + tdClass + "\"" + tdStyle + ">" + aText + "</td></tr>\n";
	}
	else
	{
		var aClass = aClassName;
		if (className != null)
			aClass = className;
		var aStyle = "";
		if (style != null && style != "")
			aStyle = " style=\"" + style + "\"";
		if (tdStyle != "")
			tdStyle = " style=\"" + tdStyle + "\"";
		var aHint = hint;
		if (aHint == null || aHint == "")
			aHint = "";
		else
			aHint = " title=\"" + aHint + "\"";
		var aTarget = target;
		if (aTarget == null || aTarget == "")
			aTarget = "";
		else
			aTarget = " target=\"" + aTarget + "\"";
		out += "<tr><td class=\"" + tdClass + "\"" + tdStyle + ">";
		out += "<a href=\"" + link + "\" class=\"" + aClass + "\"" + aStyle + aHint + aTarget + ">" + 
			aText + "</a>";
		out += "</td></tr>\n";
	}
	return out;
}

// displayNIPRMenuSeparator - Returns the HTML that comprises a menu separator. Call this in a 
//	document.write() function call. openNIPRMenu() must be called before calling this function. size 
//	is the size of the <hr> element in pixels - if this is not present or zero, a blank separator 
//	will be displayed. solid is a boolean that indicates whether or not to fill in the separator 
//	(only valid if size is greater than zero). indent is the number of pixels to indent the menu 
//	item; this is zero by default. className is the name of the CSS class to use for display; this 
//	applies to the <hr> element, or to the <td> element if it is a blank separator. style is the 
//	style to use for display; this applies to the <hr> element, or to the <td> element if it is a 
//	blank separator.
function displayNIPRMenuSeparator(size, solid, indent, className, style)
{
	var out = "";
	if (size != null && size > 0)
	{
		var tdStyle = "";
		var aIndent = initIndent;
		if (indent != null && indent > 0)
			aIndent += indent;
		tdStyle = "padding-left: " + aIndent + "; ";
		if (tdStyle != "")
			tdStyle = " style=\"" + tdStyle + "\"";
		var aSolid = "";
		if (solid != null && solid)
			aSolid = " noshade";
		var aClass = "";
		if (className != null && className != "")
			aClass = " class=\"" + className + "\"";
		var aStyle = "";
		if (style != null && style != "")
			aStyle = " style=\"" + style + "\"";
		out += "<tr><td class=\"" + tdClassName + "\"" + tdStyle + ">";
		out += "<hr size=\"" + size + "\"" + aSolid + aClass + aStyle + " />";
		out += "</td></tr>\n";
	}
	else
	{
		var tdClass = tdClassName;
		if (className != null)
			tdClass = className;
		var tdStyle = "";
		if (style != null)
			tdStyle += style;
		if (tdStyle != "")
			tdStyle = " style=\"" + tdStyle + "\"";
		out += "<tr><td class=\"" + tdClass + "\"" + tdStyle + ">&nbsp;</td></tr>\n";
	}
	return out;
}

// openNIPRBody - Returns the HTML required to start the main body element. If a menu was created, 
//	closeNIPRMenu() must be called before calling this function; otherwise, getNIPRBanner() must be
//	called before calling this function. className is the name of the CSS class to use for the body
//	area; by default, this is "niprbody". style is the CSS style settings to use for the body area;
//	this is optional.
function openNIPRBody(className, style)
{
	var text = "";
	var areaWidth = "";
	var bodyClass = "niprbody";
	if (className != null && className != "")
		bodyClass = className;
	var bodyStyle = "border-left: 3px solid black; border-right: 3px solid black; padding: 5px; vertical-align: top";
	if (style != null && style != "")
		bodyStyle += "; " + style;
	if (!document.nipr_use_menu)
	{
		text += "<table width=\"" + niprTotalWidth + "\" align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
		text += "	<tr>\n";
	}
	else
		areaWidth = " width=\"" + (niprTotalWidth - niprMenuWidth) + "\"";
	text += "		<td" + areaWidth + " class=\"" + bodyClass + "\" style=\"" + bodyStyle + "\">\n";
	return text;
}

// closeNIPRBody - Returns the HTML required to end the main body element. openNIPRBody() must be 
//	called before calling this function.
function closeNIPRBody()
{
	var text = "";
	text += "		</td>\n";
	text += "	</tr>\n";
	text += "</table>\n";
	return text;
}

// 3/27/2007 JKA - Tracker 52831 - Add footer functions

// FooterLink - An object that contains the footer link information
function FooterLink(text, url, target)
{
	this.text = text;
	this.url = url;
	this.target = target;
}

// getNIPRFooterLinks - Returns an array of FooterLink objects that describe the standard footer
//	links.
function getNIPRFooterLinks()
{
	var links = new Array();
    links.push(new FooterLink("Home", linkOpen("/index.html")));
	links.push(new FooterLink("NAIC Web Site", "http://www.naic.org/", "_blank"));
	links.push(new FooterLink("About NIPR", linkOpen("/about_nipr.htm")));
	links.push(new FooterLink("Contact Us", linkOpen("/contacts_help.htm")));
	links.push(new FooterLink("Search", "https://external-apps.naic.org/NBP/Basic.jsp", "_blank"));
	links.push(new FooterLink("Help", linkOpen("/contacts_help.htm")));
	links.push(new FooterLink("Privacy Statement", linkOpen("/privacy_statement.htm"), "_blank"));
	return links;
}

// getNIPRFooter - Returns the footer HTML. Call this in a document.write() function call. homeLink is
//	the URL of the home page; if null or not present, a default home page link will be used. helpLink
//	is the URL of the help page; if null or not present, a default help link will be used. addlLinkText 
//	is an additional link that is displayed in the footer (if present and not null). addlLink is the 
//	URL of the additional link (if present and not null). 
function getNIPRFooter(homeLink, helpLink, addlLinkText, addlLink)
{
	var links = getNIPRFooterLinks();
	if (homeLink != null || helpLink != null)
		for (var linkNum = 0; linkNum < links.length; linkNum++)
		{
			if (homeLink != null && links[linkNum].text == "Home")
				links[linkNum].url = homeLink;
			if (helpLink != null && links[linkNum].text == "Help")
				links[linkNum].url = helpLink;
		}
	if (addlLinkText != null && addlLink != null)
		links.push(new FooterLink(addlLinkText, addlLink));
	return createNIPRFooter(links);
}

// createNIPRFooter - Returns the footer HTML. Call this in a document.write() function call. This
//	function takes one or more FooterLink objects, or an array of FooterLink objects.
function createNIPRFooter()
{
	var args = createNIPRFooter.arguments;
	var links = null;
	if (args[0].length != null)
		links = args[0];
	else
	{
		links = new Array();
		for (var argNum = 0; argNum < args.length; argNum++)
			links.push(args[argNum]);
	}
	var banner = "";
	banner += "<table width=\"" + niprTotalWidth + "\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">\n";
	banner += "	<tr>\n";
	banner += "		<td height=\"30\" background=\"/images/footer.jpg\" align=\"center\" class=\"footer_cell\">\n";
	banner += "			[ ";
	for (var linkNum = 0; linkNum < links.length; linkNum++)
	{
		if (linkNum > 0)
			banner += " | ";
		banner += "<a href=\"" + links[linkNum].url + "\"" + (links[linkNum].target == null ? "" : " target=\"" + links[linkNum].target + "\"") + " class=\"footer_link\">" + links[linkNum].text + "</a>";
	}
	banner += " ]<br>\n";
	banner += "			Copyright 1996 - " + (new Date()).getFullYear() + " National Insurance Producer Registry\n";
	banner += "		</td>\n";
	banner += "	</tr>\n";
	banner += "</table>\n";
	return banner;
}

