/* ----------- */
function calcNumYears( nPayments )
	{
	return Math.round( (nPayments / 12) * 100 ) /100;
	}
/* ----------- */
	


/* ----------- */
function isNumericField( fField, fName )
	{
	if( ( fField.value == "" ) )
		{
		alert( "\"" + fName + "\" cannot be blank." );
		fField.value = global_originalFieldValue;
		fField.focus();
		return false;
		}

	
	
	if(fieldNotChanged( fField ))
		return false;
		
	if( !fieldNotNum( fField ))		
		return false;
		
	return true;	
	}	
	
/* ----------- */




/* ----------- */
// set by setFieldColor function
function fieldNotChanged( fField )
	{
	if( fField.value == global_originalFieldValue )
		{
		return true;
		}
			else
				return false;
	}
/* ----------- */



/* ----------- */
// set true or false from text.
function setBool( fValue )
	{
	if( fValue == "true" )
		return true;
			else
				return false;
	}
/* ----------- */




/* ----------- */
function fieldNotNum( fField )
	{
	if( isNaN(fField.value) )
		{
		fField.value = global_originalFieldValue;
		fField.focus();
		alert( "You must input a numeric value." );
		return false;
		}
		else
			return true;
				

	}
/* ----------- */




/* ----------- */
function getNowDateStr()
	{
	var months = new Array(12);
	months[0]  = "January";
	months[1]  = "February";
	months[2]  = "March";
	months[3]  = "April";
	months[4]  = "May";
	months[5]  = "June";
	months[6]  = "July";
	months[7]  = "August";
	months[8]  = "September";
	months[9]  = "October";
	months[10] = "November";
	months[11] = "December";

	date = new Date();
	this.NAVdate = months[date.getMonth()] + "/" + date.getDate() + "/" + date.getYear();
	}		
/* ----------- */


/* ----------- */
function getInputField( size, fieldID, fValue, dbID, fAttribute, isReadOnly, css, actionFor )
	{
	var updateAction = "";
	var readOnly = "";
	var cssClass = "";

	if( isReadOnly == "true" )
		{
		readOnly = " readonly";
		}
		else
			{
			if( actionFor != "" )
				{
				updateAction =  " onFocus=\"setFieldColor( this.id )\"";
				updateAction += " onBlur=\"reSetFieldColor( this.id );";
				updateAction += " action_" + actionFor + "_update( this.form, this.id, " + dbID + ", \'" + fAttribute + "\', this.value )\"";
				}
			}

	if( css != "" )
		cssClass = " class=\"" + css + "\"";

	var field = "";
		field = "<input" + cssClass + " type=\"text\"" + updateAction + " name=\"" + fieldID + "\" id=\"" + fieldID + "\" size=\""+size+"\" value=\""+ fValue + "\""+readOnly+">";	

	return field;
	}	
/* ----------- */


/* ----------- */
function reSetField(f, fieldID, value)
	{
	f.elements[fieldID].value = value;
	f.elements[fieldID].select();
	f.elements[fieldID].focus();
	}
/* ----------- */



// show and hide panels
var ids = new Array( 'inputs', 'portfolio', 'scenarios', 'lookup', 'submited', 'saved' );

/* ----------- */
function switchid( id, tid )
	{	

	document.getElementById("inputs_tab").className = "taboutline_off";
	document.getElementById("portfolio_tab").className = "taboutline_off";
	document.getElementById("scenarios_tab").className = "taboutline_off";
	document.getElementById("lookup_tab").className = "taboutline_off";
	if( tid )
		document.getElementById(tid).className = "taboutline_on";

	hideallids();

	showdiv( id );
	}
/* ----------- */


/* ----------- */
function hideallids()
	{
	for (var i = 0; i < ids.length; i++ )
		hidediv( ids[i] );
	}	
/* ----------- */


/* ----------- */
function hidediv( id ) 
	{

	if( document.getElementById ) 
		{ // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
		if( id != "submited" && id != "saved" )
			document.getElementById("ursButtons").style.display = 'block';
		}
		else 
			{
			if( document.layers ) 
				{ // Netscape 4
				document.id.display = 'none';
				if( id != "submited" && id != "saved" )
					document.ursButtons.style.display = 'block';
				}
				else 
					{ // IE 4
					document.all.id.style.display = 'none';
					if( id != "submited" && id != "saved" )
						document.all.ursButtons.style.display = 'block';
					}
			}
	}
/* ----------- */

//submited, saved
/* ----------- */
function showdiv( id ) 
	{
	if ( document.getElementById ) 
		{ // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'block';
		if( id == "submited" || id == "saved" )
			document.getElementById("ursButtons").style.display = 'none';
			
		}
		else 
			{
			if(	document.layers ) 
				{ // Netscape 4
				document.id.display = 'block';
				if( id == "submited" || id == "saved" )
					document.ursButtons.style.display = 'none';
				}
				else 
				{ // IE 4
				document.all.id.style.display = 'block';
				if( id == "submited" || id == "saved" )
					document.all.ursButtons.style.display = 'none';
				}
			}
	}
/* ----------- */
	
// end show hide panels	


	
/* ----------- */
function setFieldColor( fID )
	{
	global_originalFieldValue = document.getElementById( fID ).value;
	document.getElementById( fID ).style.background = "#ffcc00";
	document.getElementById( fID ).select();
	setFieldBorderColor( fID );
	}
/* ----------- */


/* ----------- */
function reSetFieldColor( fID )
	{
	document.getElementById( fID ).style.background = "white";
	reSetFieldBorderColor( fID );
	}
/* ----------- */


/* ----------- */
function setFieldBorderColor( fID )
	{
	document.getElementById( fID ).style.borderColor = "black";
	}
/* ----------- */


/* ----------- */
function reSetFieldBorderColor( fID )
	{
	document.getElementById( fID ).style.borderColor = "silver";
	}
/* ----------- */
	


/* ----------- */
function getLoanAmount( potentialSavingPerMonth, interestR )
	{
	if( potentialSavingPerMonth > 0 )
		return ( ( potentialSavingPerMonth * 12) / (interestR * .01)).toFixed(2);

	return 0;
	}
/* ----------- */



/* ----------- */
function getNewPortfolioFunds( changedDate, hLoanPrincipal )
	{
	var gf = global_Portfolio.pFundArr;
	var tempFund = new Array();

	for( var i = 0; i < gf.length; i ++ )
		{
		tempFund[ i ] = new portfolioFund( gf[i].fund.dataBaseID, gf[i].fund.fundName, gf[i].fund.assestAllocation, gf[i].fund.monthlyDistributionFactor, gf[i].fund.NetAssetValue, changedDate, hLoanPrincipal );
		}

	return tempFund;
	}
/* ----------- */



/* ----------- */
function getNewMarginalTaxRateAttributes()
	{
	var mt = global_Lookups.attributes.MTRarr;
	var tempAttrs = new Array();

	for( var i = 0; i < mt.length; i ++ )
		{
		tempAttrs[ i ] = new marginalTaxRateAttributes( mt[i].databaseID, mt[i].annualIncome, mt[i].otherIncome, mt[i].capitalGains, mt[i].taxRate);
		}

	return tempAttrs;
	}
/* ----------- */




/* ----------- */
function getNewMoneyFilterAttributes()
	{
	var fa = global_Lookups.attributes.filtersArr;
	var tempAttrs = new Array();

	for( var i = 0; i < fa.length; i ++ )
		{
		tempAttrs[ i ] = new moneyFilters( fa[i].id, fa[i].name, fa[i].percentage);
		}

	return tempAttrs;
	}
/* ----------- */



/* ----------- */
function resetValues()
	{
	if(confirm("WARNING: Resetting Initial Values cannot be undone, any changes will be lost.\n Click OK to continue and Reset to the initial values."))
		init();
	}
/* ----------- */
	
	
	
/* ----------- */
function findParam( name )
	{  
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
	var regexS = "[\\?&]"+name+"=([^&#]*)";  
	var regex = new RegExp( regexS );  
	var results = regex.exec( window.location.href );  
	
	if( results == null )    
		return "";  
			else    
	return results[1];
	}
/* ----------- */

		
/* ----------- */
function testURL()
	{
	var results = findParam( "view" );
	if( results == "saved" )
		switchid('saved')
	}	
/* ----------- */
	