function onloadScripts()
{
	hideElements();
	writeBookmark();
	adjustWWmenu();

	if (GetCookie("WilaryWinnHotIssues")) document.getElementById("HotIssues").style.display = GetCookie("WilaryWinnHotIssues");
	if (GetCookie("WilaryWinnDownloads")) document.getElementById("Downloads").style.display = GetCookie("WilaryWinnDownloads");
	if (GetCookie("WilaryWinnContactInfo")) document.getElementById("ContactInfo").style.display = GetCookie("WilaryWinnContactInfo");

//	if (document.getElementById("Testimonials")) document.getElementById("testimonylink").style.display = "block";
}

function adjustWWmenu()
{
	document.getElementById("AboutUs").style.left = findPosXY(document.getElementById("AboutUsL"),"x");
	document.getElementById("OurServices").style.left = findPosXY(document.getElementById("OurServicesL"),"x");
	document.getElementById("WhyChooseUs").style.left = findPosXY(document.getElementById("WhyChooseUsL"),"x");
	document.getElementById("AboutUs").style.top = findPosXY(document.getElementById("AboutUsL"),"y") + document.getElementById("AboutUsL").offsetHeight + 2;
	document.getElementById("OurServices").style.top = findPosXY(document.getElementById("OurServicesL"),"y") + document.getElementById("OurServicesL").offsetHeight + 2;
	document.getElementById("WhyChooseUs").style.top = findPosXY(document.getElementById("WhyChooseUsL"),"y") + document.getElementById("WhyChooseUsL").offsetHeight + 2;
}

function findPosXY(obj,dir)
{
	var Tleft = Ttop = 0;
	if (obj.offsetParent)
		do
		{
			Tleft += obj.offsetLeft;
			Ttop += obj.offsetTop;
		}
		while (obj = obj.offsetParent);
	if (dir == "x") return Tleft;
	else return Ttop;
  }

function writeBookmark()
{
	var browser = (document.all ? "MSIE" : "Mozilla");
	var phrase = (browser == "MSIE" ? "add page to Favorites" : "bookmark this page");
	var icon = (browser == "MSIE" ? "bookmarkIE.gif" : "bookmarkFirefox.gif");
	document.getElementById("WWbookmark").innerHTML = "<a href='javascript:addBookmark();'>(" + phrase + ") <img src='images/" + icon + "' height='16' width='16' border='0' /></a>";
}

function addBookmark()
{
	var bookmarkTitle = "";
	var Bs = document.all ? document.all.tags("b") : document.getElementsByTagName("b");
	for (i=0; i<Bs.length; i++)
		if (Bs[i].className == "WWtitle")
			bookmarkTitle = Bs[i].innerHTML;
	bookmarkTitle = (bookmarkTitle != "" ? document.title + " - " + bookmarkTitle : document.title);

	if (document.all)
		window.external.AddFavorite(location.href,bookmarkTitle);
	else if (window.sidebar)
		window.sidebar.addPanel(bookmarkTitle,location.href,"");
	else
		window.alert("This feature isn't supported by your browser.");
}

var WWtoggle;

function showMenu(x)
{
	if (WWtoggle) clearTimeout(WWtoggle);

	var DIVs = document.all ? document.all.tags("div") : document.getElementsByTagName("div");
	for (i=0; i<DIVs.length; i++)
		if (DIVs[i].className == "hidden")
			DIVs[i].style.display = "none";

	var LINKs = document.all ? document.all.tags("a") : document.getElementsByTagName("a");
	for (i=0; i<LINKs.length; i++)
		if (LINKs[i].className == "menu")
		{
			LINKs[i].style.backgroundImage = "URL('TPLimages/menuBG.jpg')";
			LINKs[i].style.color = "#000";
		}

	if (x)
	{
		document.getElementById(x).style.display = "block";
		document.getElementById(x+"L").style.backgroundImage = "URL('')";
		document.getElementById(x+"L").style.color = "#fff";
		document.getElementById(x+"L").style.backgroundColor = "#502";
	}
}

function showDiv(x)
{
	document.getElementById(x).style.display = "block";
}

function hideDiv(x)
{
	document.getElementById(x).style.display = "none";
}

function hideElements()
{
	// Risk Management
	if (document.getElementById("derivatives")) document.getElementById("derivatives").style.display = "none";
	if (document.getElementById("hedging")) document.getElementById("hedging").style.display = "none";
	if (document.getElementById("hedgeaccounting")) document.getElementById("hedgeaccounting").style.display = "none";

	// FHL Bank Manual
	if (document.getElementById("FHLBankText")) document.getElementById("FHLBankText").style.display = "block";
}

function popUp(x)
{
	if (document.getElementById(x).style.display == "none")
	{
		var text = document.getElementById(x).innerHTML;
		document.getElementById(x).style.position = "absolute";
		document.getElementById(x).style.display = "block";
		document.getElementById(x).style.width = document.body.clientWidth / 3;
		document.getElementById(x).style.left = document.body.clientWidth / 3;
	}
}

function cookieWW(x,d)
{
	document.getElementById(x).style.display = d;
	SetCookie("WilaryWinn"+x,d,expireCookie);
}

function FHLBank(x)
{
	document.FHLBankIMG.src = x;
}

var today = new Date();
var expireCookie = new Date(today.getTime() + (10 * 365 * 24 * 60 * 60 * 1000));

function getCookieVal(offset)
{
	var endstr = document.cookie.indexOf(";", offset);
	if (endstr == -1) endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie(name)
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen)
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) return getCookieVal(j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break; 
	}
	return null;
}

function DeleteCookie(name,path,domain)
{
	if (GetCookie(name))
		document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function SetCookie(name,value,expires,path,domain,secure)
{
	document.cookie = name + "=" + escape (value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
}

document.onload = onloadScripts();
