/****** POP UP WINDOW SCRIPT *****/
function popWin(url,name,features)
{
 	var the_win;
	the_win = window.open(url,name,features);
  	the_win.focus();
}


/**
 *  author:		Timothy Groves - http://www.brandspankingnew.net
 *	version:	1.3 - 2006-11-02
 *				1.2 - 2006-11-01
 *				1.1 - 2006-09-29
 *				1.0 - 2006-09-25
 *
 *	requires:	nothing
 *
 */

var useBSNns;

if (useBSNns)
{
	if (typeof(bsn) == "undefined")
		bsn = {}
	var _bsn = bsn;
}
else
{
	var _bsn = this;
}





_bsn.Crossfader = function (divs, fadetime, delay )
{	
	this.nAct = -1;
	this.aDivs = divs;
	
	for (var i=0;i<divs.length;i++)
	{
		document.getElementById(divs[i]).style.opacity = 0;
		document.getElementById(divs[i]).style.position = "absolute";
		document.getElementById(divs[i]).style.filter = "alpha(opacity=0)";
		document.getElementById(divs[i]).style.visibility = "hidden";
	}
	
	this.nDur = fadetime;
	this.nDelay = delay;
		
	this._newfade();
}


_bsn.Crossfader.prototype._newfade = function()
{
	if (this.nID1)
		clearInterval(this.nID1);
	
	this.nOldAct = this.nAct;
	this.nAct++;
	if (!this.aDivs[this.nAct])	this.nAct = 0;
	
	if (this.nAct == this.nOldAct)
		return false;
	
	document.getElementById( this.aDivs[this.nAct] ).style.visibility = "visible";
	
	this.nInt = 50;
	this.nTime = 0;
	
	var p=this;
	this.nID2 = setInterval(function() { p._fade() }, this.nInt);
}


_bsn.Crossfader.prototype._fade = function()
{
	this.nTime += this.nInt;
	
	var ieop = Math.round( this._easeInOut(this.nTime, 0, 1, this.nDur) * 100 );
	var op = ieop / 100;
	document.getElementById( this.aDivs[this.nAct] ).style.opacity = op;
	document.getElementById( this.aDivs[this.nAct] ).style.filter = "alpha(opacity="+ieop+")";
	
	if (this.nOldAct > -1)
	{
		document.getElementById( this.aDivs[this.nOldAct] ).style.opacity = 1 - op;
		document.getElementById( this.aDivs[this.nOldAct] ).style.filter = "alpha(opacity="+(100 - ieop)+")";
	}
	
	if (this.nTime == this.nDur)
	{
		clearInterval( this.nID2 );
		
		if (this.nOldAct > -1)
			document.getElementById( this.aDivs[this.nOldAct] ).style.visibility = "hidden";	
		
		var p=this;
		this.nID1 = setInterval(function() { p._newfade() }, this.nDelay);
	}
}



_bsn.Crossfader.prototype._easeInOut = function(t,b,c,d)
{
	return c/2 * (1 - Math.cos(Math.PI*t/d)) + b;
}

function openWin(url, w, h)
{
var winprop = "width=" + w + ",height=" + h;
openwin = window.open(url,'',winprop);
}


/* FAQ Section */
showing = new Array("none","");
function show(id)
{
	el = document.getElementById(id);
	if (el.style.display == 'none')
	{
		el.style.display = '';
		el = document.getElementById('more' + id);
	} else {
		el.style.display = 'none';
		el = document.getElementById('more' + id);
	}
}
function show_all(){
	if(document.getElementById('hideall').style.visibility == 'hidden'){
		document.getElementById('showall').style.visibility = 'hidden';
		document.getElementById('hideall').style.visibility = 'visible';
	} else {
	document.getElementById('showall').style.visibility = 'visible';
	document.getElementById('hideall').style.visibility = 'hidden';
	}
	for (i=0;i<=100;i++){
		if(document.getElementById('info'+i)!=null){
		//show('info'+i);
		id = "info"+i
		el = document.getElementById(id);
		el.style.display = showing[1];
		
			}
	}
	showing.reverse();
}
function show(id)
{
	el = document.getElementById(id);
	if (el.style.display == 'none')
	{
		el.style.display = '';
		el = document.getElementById('more' + id);
	} else {
		el.style.display = 'none';
		el = document.getElementById('more' + id);
	}
}

/***************************************
****************************************
       HEALTH SAVINGS CALCULATOR
****************************************
****************************************
****************************************
 * A real helper function to calculate
 * future value of a periodic investment
 * Parameters:
 * 	Please note that the rate, payments and amount
 *	correspond to the same frequency of investment
 *	deposits. For example, if payments are monthly
 *	then rate and amount are also monthly
 *	'prin' is intial principle, if applicable. Set to '0' otherwise
 ***************************************/
function FV(rate, payments, amount, prin) {
   var newprin = 0;
   for(var count=0; count < payments; count++) {
        newprin = prin + amount;
        prin = (newprin * rate) + eval(prin + amount);
   }//for

   return prin;
}
/* Original: Cyanide_7 (leo7278@hotmail.com) 
 Web Site: http://www7.ewebcity.com/cyanide7
 The JavaScript Source!! http://javascript.internet.com */

function currencyFormat( num) {
 
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$ ' + num + '.' + cents);
}

function formUpdate(form)  {
	//Calculate the monthly interest rate
	var mi_rate = form.annIntRate.value;
	if (mi_rate > 1.0) {
		mi_rate = form.annIntRate.value / 100;
	} else {
		mi_rate = form.annIntRate.value;
	}
	
	mi_rate = mi_rate/12; //Monthly interest rate
	
	//Calculate monthly Invstment (without fedral income tax)
	form.moneyInvested.value = form.mipT.value - form.mipH.value;

	if( form.moneyInvested.value < 0 )
		form.moneyInvested.value = 0; //Making sure it is not negative

	//Calculate monthly fedral taxed investment
	form.taxedInvested.value = form.moneyInvested.value * (1 - form.fedTax.value);
	
	//Calculate no of years
	form.n1.value = 65-(form.age.value);

	/***********************************************
	 * Find out savings without fedral income
	 * and fedral capital gains taxes
	 **********************************************/
	var payments = form.n1.value * 12;			//Calculate number of monthly payments
	var amount = form.moneyInvested.value * 1;	//Multiplying by 1 fixes some buggy behavior

	//Now caculate the future value and show in the form
	form.hsfh.value = Math.round( FV(mi_rate, payments , amount, 0)*100 )/100;

	

	/**************************************************
	 *  Find out savings WITH fedral income
	 *  and fedral capital gains taxes
	 **************************************************/
	var taxedAmt = form.taxedInvested.value * 1;		//Monthly payment after income tax
	var taxedFV = FV(mi_rate, payments , taxedAmt, 0);	//Future value of this monthly payment
	var gainTax = form.cgt.value;					//Fedral tax on capital gains
	
	//Effective gain after applying fedral capital gain on the post income tax payments
	form.acgt.value = Math.round( (taxedFV - ((taxedFV - (payments * taxedAmt) ) * gainTax) )*100 )/100;

	//Update HSA savings
	form.hsa_savings.value = Math.round( (form.hsfh.value - form.acgt.value) * 100) / 100;
	
	//Format the calculator values
	form.moneyInvested.value = currencyFormat(form.moneyInvested.value);
	form.taxedInvested.value = currencyFormat(form.taxedInvested.value);
	form.hsfh.value = currencyFormat(form.hsfh.value);
	form.acgt.value = currencyFormat(form.acgt.value);
	form.hsa_savings.value = currencyFormat(form.hsa_savings.value);
	/*
	*/
}



function formReset(){
    var x=document.forms.myForm
    x.reset()
}


