//////////////////////////////////////////////////////////////////////////////////
//All text, graphic, source code (including, but not limited to, 		//
//JavaScript, HTML, JAVA, VB Script) material found on this server 		//
//can not be published, broadcast, rewritten for broadcast, 			//
//publication or redistributed directly or indirectly in any medium 		//
//without express written permission from Pension Specialists, Inc. 		//
//These materials or any portion thereof may not be stored in any unauthorized	//
//computer.									//
//All materials appearing on this site are protected by copyright as 		//
//a collective work or compilation under copyright and other laws and 		//
//are the property of Pension Specialists, Inc.	exclusively.			//
//										//
//You may not copy, reproduce, distribute, publish, display, perform, 		//
//modify, create derivative works, transmit, or in any way exploit any 		//
//content, nor may you distribute any part of this content over any network, 	//
//including a local area network, sell or offer it for sale, or use such 	//
//content for any kind of database. 					//
//										//
//Content may be used for your own personal, non-commercial use. The 		//
//content may contain certain trademarks and service marks owned by 		//
//Pension Specialists, Inc., or other content providers, including their 	//
//respective logos. You may not alter or remove any trademark, copyright 	//
//or other notice from copies of the content. 					//
//										//
//Copyright © 2003 Pension Specialists, Inc. All rights reserved.		//
//////////////////////////////////////////////////////////////////////////////////

function roundOff(value, precision)
{
        value = "" + value //convert value to string
        precision = parseInt(precision);

        var whole = "" + Math.round(value * Math.pow(10, precision));

        var decPoint = whole.length - precision;

        if(decPoint != 0)
        {
                result = whole.substring(0, decPoint);
                result += ".";
                result += whole.substring(decPoint, whole.length);
        }
        else
        {
                result = whole;
        }
        return result;
}

function calcTotals() {
	var inflationRate = .03;
	var i = inflationRate;
	var c = s1.getValue()/100;
	var r = s2.getValue()/100;
	var B = s3.getValue();
	var A = document.getElementById("txtAge").value;
	var S = document.getElementById("txtAnnualSalary").value;
	var G = roundOff(c*(S* Math.pow((1+i),(65-A))),2);
	document.getElementById("txtGoalRetirementIncome").value = currency(G);
	// D16*((1-(1+E9)^-(F9-65))/E9)
	//var L = roundOff(G*((1-Math.pow((1+r),-(B-65)))/r),2);
	
	var L = 0
	for (cnt=0; cnt<=(B-65); cnt++) {
		tmp = G*Math.pow((1+i), cnt);
		L += tmp/Math.pow((1+r), cnt);
	}
	
	//L=roundOff(L,2);
	//$1,078,707.25
	document.getElementById("txtGoalRetire65").value = currency(L);
	
	//var inflationRate = .02;
	//var i = inflationRate;
	//var c = 1.1;
	//var r = .08;
	//var B = 85;
	//var A = 33;
	//var S = 53000;
	//D9*(C9*(1+G9)^(65-B9))
	//$109,868.72
	//var G = Math.round(c*(S* Math.pow((1+i),(65-A))));
	//print(G);
	
	
	
	//s1.getValue()/100 + s2.getValue()/100 + s3.getValue();
	};

var Request = new QSHandler();
function QSHandler(){
	var qs = location.search.substr(1).split("&");
	this.data = [];
	for(var i = 0; i < qs.length; i++) this.data[qs[i].split("=")[0]] = qs[i].split("=")[1];

	this.QueryString = function(x){
		return this.data[x];
	};
};

function populateText(){
  	var chk = Request.QueryString("chk");
	//current salary - comes from previous page
  	var s = parseFloat(Request.QueryString("s"));
	//current age - comes from previous page
	var a = parseFloat(Request.QueryString("a"));
	var c = parseFloat(Request.QueryString("c"));
	var t = parseFloat(Request.QueryString("t"));
	var b = parseFloat(Request.QueryString("b"));
	var chk = Request.QueryString("chk");
                                             	
	if(isNaN(a) == false){
		if(chk == "false"){
			document.getElementById("chkToolTips").checked = false;
			};
		if(chk == "true"){
			document.getElementById("chkToolTips").checked = true;
			};
		document.getElementById("txtAge").value = a;
		document.getElementById("txtAnnualSalary").value = s;
		s1.setValue(c);
		s2.setValue(t);
		s3.setValue(b);
		calcTotals();		
		};
	};


function SendVars(){
   	var chk = document.getElementById("chkToolTips").checked
   	var i = .03;
	var c = s1.getValue()/100;
	var t = s2.getValue()/100;
	var s = document.getElementById("txtAnnualSalary").value;
	var a = document.getElementById("txtAge").value;
	var b = s3.getValue();
	var g = roundOff(c*(s* Math.pow((1+i),(65-a))),2);
	if (a <= 0){
		alert("Please enter your age.");
		};
	if (s <= 0){
		alert("Please enter your annual salary.");
		};
	if (s > 0){
		if (a > 0){
			location = "retirement2.htm?i=" + i + "&c=" + c + "&t=" + t + "&s=" + s + "&a=" + a + "&b=" + b + "&g=" + g + "&chk=" + chk;
			};
		};
	};
	
function Reset(){
	location = "index.htm";
	};	
       
function getQueryString( sProp ) {
	var re = new RegExp( sProp + "=([^\\&]*)", "i" );
	var a = re.exec( document.location.search );
	if ( a == null )
		return "";
	return a[1];
};

function changeCssFile( sCssFile ) {
	var loc = String(document.location);
	var search = document.location.search;
	if ( search != "" )
		loc = loc.replace( search, "" );
	loc = loc + "?css=" + sCssFile;
	document.location.replace( loc );
}

var cssFile = getQueryString( "css" );
if ( cssFile == "" )
	//cssFile = "css/BlueCurve/BlueCurve.css";
	cssFile = "css/luna/luna.css";

document.write("<link type=\"text/css\" rel=\"StyleSheet\" href=\"" + cssFile + "\" />" );

//]]>

//Currency Function
//-- JavaScript code written by Alan Simpson - www.coolnerds.com
function currency(anynum) {
//-- Returns passed number as string in $xxx,xxx.xx format.
	anynum=eval(anynum)
	workNum=Math.abs((Math.round(anynum*100)/100));workStr=""+workNum
	if (workStr.indexOf(".")==-1){workStr+=".00"}
		dStr=workStr.substr(0,workStr.indexOf("."));dNum=dStr-0
		pStr=workStr.substr(workStr.indexOf("."))
		while (pStr.length<3){pStr+="0"}
			
		//--- Adds comma in thousands place.
		if (dNum>=1000) {
			dLen=dStr.length
			dStr=parseInt(""+(dNum/1000))+","+dStr.substring(dLen-3,dLen)
			}
			
		//-- Adds comma in millions place.
		if (dNum>=1000000) {
			dLen=dStr.length
			dStr=parseInt(""+(dNum/1000000))+","+dStr.substring(dLen-7,dLen)
			}
		retval = dStr + pStr 
		
		//-- Put numbers in parentheses if negative.
		if (anynum<0) {retval="("+retval+")"}
			return "$"+retval
			}
		// -->
