/* Set up browser values */
HM_DOM = (document.getElementById) ? true : false;
HM_NS4 = (document.layers) ? true : false;
HM_IE = (document.all) ? true : false;
HM_IE4 = HM_IE && !HM_DOM;
HM_Mac = (navigator.appVersion.indexOf("Mac") != -1);
HM_IE4M = HM_IE4 && HM_Mac;
HM_IsMenu = (HM_DOM || HM_NS4 || (HM_IE4 && !HM_IE4M));
HM_BrowserString = HM_NS4 ? "NS4" : HM_DOM ? "DOM" : "IE4";

/* Event kickoff */
if(window.event + "" == "undefined") event = null;
function HM_f_PopUp(){return false};
function HM_f_PopDown(){return false};
popUp = HM_f_PopUp;
popDown = HM_f_PopDown;

/* Sub Menu define */
HM_PG_MenuWidth = 150;
HM_PG_FontFamily = "Arial";
HM_PG_FontSize = 8;
HM_PG_FontBold = 1;
HM_PG_FontItalic = 0;
HM_PG_FontColor = "#426563";
HM_PG_FontColorOver = "#426563";
HM_PG_BGColor = "#A1CCCA";
HM_PG_BGColorOver = "#A1CCCA";
HM_PG_ItemPadding = 3;

HM_PG_BorderWidth = 1;
HM_PG_BorderColor = "black";
HM_PG_BorderStyle = "solid";
HM_PG_SeparatorSize = 1;
HM_PG_SeparatorColor = "#426563";
HM_PG_ImageSrc = "images/tri.gif";
HM_PG_ImageSrcLeft = "images/triL.gif";

HM_PG_ImageSize = 5;
HM_PG_ImageHorizSpace = 0;
HM_PG_ImageVertSpace = 2;

HM_PG_KeepHilite = false; 
HM_PG_ClickStart = 0;
HM_PG_ClickKill = false;
HM_PG_ChildOverlap = 20;
HM_PG_ChildOffset = 10;
HM_PG_ChildPerCentOver = null;
HM_PG_TopSecondsVisible = .1;
HM_PG_StatusDisplayBuild =1;
HM_PG_StatusDisplayLink = 0;
HM_PG_UponDisplay = null;
HM_PG_UponHide = null;
HM_PG_RightToLeft = false;

HM_PG_CreateTopOnly = 1;
HM_PG_ShowLinkCursor = 1;
HM_PG_NSFontOver = true;


function HM_f_CenterMenu(topmenuid) {
	var TheMenu = HM_DOM ? document.getElementById(topmenuid) : HM_IE4 ? document.all(topmenuid) : eval("window." + topmenuid);
	var TheMenuWidth = HM_DOM ? parseInt(TheMenu.style.width) : HM_IE4 ? TheMenu.style.pixelWidth : TheMenu.clip.width;
	var TheWindowWidth = HM_IE ? document.body.clientWidth : window.innerWidth;
	return ((TheWindowWidth-TheMenuWidth) / 2);
}

if(HM_IsMenu) {
	document.write("<SCR" + "IPT LANGUAGE='JavaScript1.2' SRC='../script/HM_Arrays.js' TYPE='text/javascript'><\/SCR" + "IPT>");
	document.write("<SCR" + "IPT LANGUAGE='JavaScript1.2' SRC='../script/HM_Script"+ HM_BrowserString +".js' TYPE='text/javascript'><\/SCR" + "IPT>");
}

/******************************************************/
/* General function to warn users */
/******************************************************/
function open_window(url) {
 var msg='You are about to visit a website outside of the Linn Area Credit Union site. Linn Area Credit Union is not responsible or liable for the contents of this site. Click OK to confirm that you want to open this page'
	if(confirm(msg)){
  	window.open(url,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=750,height=425');
 }
}

/******************************************************/
/* Calculator functions */
/******************************************************/
function tonum(str) 
{
	ret = "";
	str = "" + str;
	
	for(i = 0; i < str.length; i++){
		ch = str.substring(i,i+1);
		if ((ch >= "0" && ch <= "9") || ch == '.')
			ret += ch;
	}
	
	if(ret == "") ret = "0";
	return parseFloat(ret);
}

function format(val, decimal)
{
	scale = 1;
	
	if(decimal == null) decimal = 2;
	
	for(i = 0;i < decimal;i++) scale*=10;
	
	str = "" + Math.round(parseFloat(val) * scale);
	while(str.length <= decimal) str = "0" + str;
	
	point = str.length - decimal;
	num = "";
	i = point-3;
	while(i >= 0){
		num1 = str.substring(i,i+3);
		if(i != point-3) num1 += "," + num;
		num = num1;
		i-=3;
	}
	if(i != -3){
		num1 = str.substring(0,i+3);
		if(point > 3) num1 += "," + num;
		num = num1;
	}
	return "$" + num + "." + str.substring(point, str.length);
}

function balance(form) 
{
	rate = tonum(form.rate.value)/100;
	years = tonum(form.years.value);
	contrib = tonum(form.contrib.value);
	ans = 0;
	for(j = 0;j < years;j++){
		ans = ans + contrib;
		ans = ans + ans*rate;
	}
	form.finalval.value = format(ans);
}

function contribution(form) 
{
	rate = tonum(form.rate.value)/100;
	years = tonum(form.years.value);
	finalval = tonum(form.finalval.value);
	
	answer = 0;
	for(i = 1;i <= years;i++){
		answer = answer + Math.pow(1+rate,i);
	}
	if(answer == 0)
		answer = 0;
	else
		answer = finalval/answer;
	
	form.contrib.value = format(answer);
}

function principal(form) 
{
	rate = tonum(form.rate.value)/1200;
	pow = 1;
	
	for(j = 0;j < tonum(form.months.value);j++)
		pow = pow * (1 + rate);
	if(pow != 0 && rate != 0)
		form.prin.value = format((tonum(form.pay.value)-.009) / pow / rate * (pow - 1));
	else
		form.prin.value = format(tonum(form.pay.value) * tonum(form.months.value));
}

function payment(form) 
{
	rate = tonum(form.rate.value)/1200;
	pow = 1;
	
	for(j = 0;j < tonum(form.months.value);j++)
		pow = pow * (1 + rate);
	if(pow != 1)
		form.pay.value = format(tonum(form.prin.value) * pow * rate / (pow - 1) +.009);
	else
		form.pay.value = format(tonum(form.prin.value) / tonum(form.payments.value));
}

