//Mobile Worker Pricing Model constants
var ratio=4;
var license_smc=2000;
var license_smc_cost=12995;
var remote_worker_prod_savings=.8;
var concurrent_license_const=30;

var licenses=new Array(11);
licenses[0]=10; licenses[1]=25; licenses[2]=100;
licenses[3]=250; licenses[4]=500; licenses[5]=1000;
licenses[6]=2000; licenses[7]=5000; licenses[8]=10000; 
licenses[9]=20000; licenses[10]=50000;

var per_seat_cost=new Array(11);
per_seat_cost[0]=350; per_seat_cost[1]=345; per_seat_cost[2]=340;
per_seat_cost[3]=335; per_seat_cost[4]=330; per_seat_cost[5]=325;
per_seat_cost[6]=320; per_seat_cost[7]=310; per_seat_cost[8]=300;
per_seat_cost[9]=280; per_seat_cost[10]=260;

//Max Users TCP connec's per user
var tcperusernum=4;
var lessdatainvest=.2;

//Model array ten items 0-9
var tcperusermax=new Array(10);
tcperusermax[0]=25/tcperusernum; tcperusermax[1]=100/tcperusernum;
tcperusermax[2]=300/tcperusernum; tcperusermax[3]=625/tcperusernum;
tcperusermax[4]=1000/tcperusernum; tcperusermax[5]=2000/tcperusernum;
tcperusermax[6]=3500/tcperusernum; tcperusermax[7]=6000/tcperusernum;
tcperusermax[8]=15000/tcperusernum; tcperusermax[9]=40000/tcperusernum;

//Model list price array ten items 0-9
var modelistprice=new Array(10);
modelistprice[0]=3495; modelistprice[1]=4995; 
modelistprice[2]=8995; modelistprice[3]=12495;
modelistprice[4]=15995; modelistprice[5]=20995;
modelistprice[6]=34995; modelistprice[7]=44995;
modelistprice[8]=69995; modelistprice[9]=119995;

var resultsWindow=null;

var VALIDATED=0;

//Application Usage - Time saved per employee (hours per day)
var appusage_light=.08;
var appusage_medium=.12;
var appusage_heavy=.2;

//Collaboration - Bandwidth saved (%)
var netcollab_average=.6;
var netcollab_high=.8;
var netcollab_veryhigh=.95;

//Consolidation - % Consolidated
consol_high=1;
consol_medium=.6;
consol_low=.3;

//IT Time Spent (hours/month)
itimespent_low=.5
itimespent_medium=1;
itimespent_high=2;

//Weekly Management (hours/week)
//variable names from steelhead excel spreadsheet
var steelB23=.5;
var steelC23=.33;
var steelD23=.5;

var annualmaintenance_const = .18;
var mobilemaintenance_const = .15;

var discount_rate = 1.12;

//Time conversions
var months=12;
var weeks=52;
var days=5;
var hours=8;
var minutes=60;

//percent conversion
var percent=100;

//temporary store variables for computations
//variable names from steelhead excel spreadsheet
var steelH18=0;var steelH29=0;var steelH23=0;
var steelH34=0;var steelH39=0;var steelH42=0;

var steelC19=0;var steelB19=0;
var steelD19=0;var steelE19=0;

var steelC17=0;var steelB17=0;
var steelD17=0;var steelE17=0;

var steelB21=0;var steelC21=0;
var steelD21=0;var steelE21=0;

var steelF15=0; var steelH15=0;
var steelJ15=0; var steelL15=0;

//temporary store variables for computations
var x_productivity=0;
var x_bandwidth=0;
var x_servercosts=0;
var x_tapebackupcosts=0;
var x_steelheadcosts=0;
var x_managementcosts=0;
var x_annualmaintenance=0;
var x_totalsavings=0;
var x_totalcost=0;
var x_annualgain=0;
var x_itmaintenancetime=0;
var x_savingsyear2=0;
var x_annualgainyear2=0;
var x_threeyearvalue=0;
var x_threeyearinvest=0;
var x_enteredcosts=0;
//ADDED 11/12/07 BY PETE B/C WE NEEDED TO USE THIS VALUE IN MULTIPLE PLACES.
var x_mobileworkerprod=0;

//Mobile Worker Pricing Model
var x_total_smc=0;
var x_total_smc_cost=0;
var x_stnd_branch_emply_time_savings=0;
var x_assume_percent_saved_mobile=0;
var x_total_mobile_cost=0;
var x_concurrent_licenses_needed=0;

//For save as utility (MR)
function saveAsMe (filename)
{
	document.execCommand('SaveAs',null,filename)
}

function init()
{
    //temporary store variables for computations
    x_productivity=0;
    x_bandwidth=0;
    x_servercosts=0;
    x_tapebackupcosts=0;
    x_steelheadcosts=0;
    x_managementcosts=0;
    x_annualmaintenance=0;
    x_totalsavings=0;
    x_totalcost=0;
    x_annualgain=0;
    x_itmaintenancetime=0;
    x_savingsyear2=0;
    x_annualgainyear2=0;
    x_threeyearvalue=0;
    x_threeyearinvest=0;
    x_enteredcosts=0;
    x_total_smc=0;
    x_total_smc_cost=0;
    x_stnd_branch_emply_time_savings=0;
    x_assume_percent_saved_mobile=0;
    x_total_mobile_cost=0;
    x_concurrent_licenses_needed=0;
	x_mobileworkerprod=0;
}

//Model of Max Users 4 TCP connec's per user and List Price
function prepare_model()
{
	steelC19=document.form.numberofoffices.value*.4;
	steelB19=steelC19/.4*.3
	steelD19=steelC19*.3/.4;
	steelE19=1;

	steelC17=document.form.pplperbranch.value;
	steelB17=steelC17/2;
	steelD17=steelC17*2;
	steelE17=steelB17*steelB19+steelC17*steelC19+steelD17*steelD19;
	
	var flag1=1; var flag2=1; var flag3=1; var flag4=1;
	
	for(var model_index=0; model_index<tcperusermax.length; model_index++)
	{
		if (flag1)
			if(steelB17 <= tcperusermax[model_index]) { 
				steelF15=modelistprice[model_index];
				flag1=0;
			}
		if (flag2)
			if(steelC17 <= tcperusermax[model_index]) {
				steelH15=modelistprice[model_index];
				flag2=0;
			}
		if (flag3)
			if(steelD17 <= tcperusermax[model_index]) {
				steelJ15=modelistprice[model_index];
				flag3=0;
			}
		if (flag4)
			if(steelE17 <= tcperusermax[model_index]) {
				steelL15=modelistprice[model_index];
				flag4=0;
		}
	}
	
	steelB21=steelF15*steelB19;
	steelC21=steelH15*steelC19;
	steelD21=steelJ15*steelD19;
	steelE21=steelL15*steelE19;
}

function prepare_steelhead()
{
	//modeled from excel hence the number letter scheme for variable names
	steelH18 = document.form.avesalary.value/(weeks*days*hours*minutes);
	steelH23 = document.form.itsalary.value/(weeks*days*hours*minutes);

	if (document.form.select.value == "light")
		steelH29 = appusage_light;
	else if(document.form.select.value == "medium")
		steelH29 = appusage_medium;
	else steelH29 = appusage_heavy;
		
	if (document.form.collaboration.value == "average")
		steelH34 = netcollab_average;
	else if(document.form.collaboration.value =="high")
		steelH34 = netcollab_high;
	else steelH34 = netcollab_veryhigh;
	
	if (document.form.consolidation.value == "low")
		steelH39 = consol_low;
	else if(document.form.consolidation.value == "medium")
		steelH39 = consol_medium;
	else steelH39 = consol_high;

	if (document.form.itimespent.value == "low")
		steelH42 = itimespent_low;
	else if(document.form.itimespent.value == "medium")
		steelH42 = itimespent_medium;
	else steelH42 = itimespent_high;
}

function prepare_mobile() 
{
    x_stnd_branch_emply_time_savings = steelH29;
    x_assume_percent_saved_mobile = x_stnd_branch_emply_time_savings*remote_worker_prod_savings;
    x_total_smc = Math.ceil(document.form.mobile_workers.value/ratio/license_smc);
    x_total_smc_cost = x_total_smc*license_smc_cost;
    x_concurrent_licenses_needed = document.form.mobile_workers.value/ratio-(x_total_smc*concurrent_license_const);
    
    var mobile_flag = 1;
    
    for(var mobile_index=licenses.length-1; mobile_index >= 0; mobile_index--)
    {
    	if (mobile_flag) 
    	{
			if(x_concurrent_licenses_needed > licenses[mobile_index])
			{ 
				x_total_mobile_cost=Math.ceil(per_seat_cost[mobile_index]*x_concurrent_licenses_needed);
				mobile_flag=0;
			}
		}
    }
    
	//add total smc cost
	if (document.form.enteredcosts.value==0) {
	    x_total_mobile_cost += x_total_smc_cost;
	} else {
	    x_total_mobile_cost = 0;
	}
	
}

function format(expr, decplaces)
{
	return add_commas(format_currency(expr, decplaces));
}

function add_commas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	
	var rgx=/(\d+)(\d{3})/;
	while (rgx.test(x1)) 
	{
		x1=x1.replace(rgx,'$1' + ',' + "$2");
	}
	return x1+x2;
}

function format_currency(expr, decplaces)
{
	var str = "" + Math.round(eval(expr) * Math.pow(10, decplaces));
	
	while (str.length <= decplaces)
	{
		str= "0" + str;
	}

	var decpoint = str.length - decplaces;	

	if (decplaces == 0)
		return str.substring(0, decpoint);
	else
		return str.substring(0, decpoint) + "." + str.substring(decpoint, str.length);
}

function isNumberKey(evt)
{
	var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;

    return true;
}


function validate(expr)
{
	VALIDATED=0;
	
	 

	if(trim(document.form.numberofoffices.value)==""){
		alert("Please enter the number of offices!");
		document.form.numberofoffices.focus();
	}
	else if(trim(document.form.pplperbranch.value)==""){
		alert("Please enter the number of people per office!");
		document.form.pplperbranch.focus();
	}
	else if(trim(document.form.avesalary.value)==""){
		alert("Please enter the average employee salary!");
		document.form.avesalary.focus();
	}
	else if(trim(document.form.serversperoffice.value)==""){
		alert("Please enter the number of file servers per office!");
		document.form.serversperoffice.focus();
	}
	else if(trim(document.form.itsalary.value)==""){
		alert("Please enter the IT personnel salary!");
		document.form.itsalary.focus();
	}
	else if(trim(document.form.bandwidthcosts.value)==""){
		alert("Please enter the monthly bandwidth costs!");
		document.form.bandwidthcosts.focus();
	}
	else if(trim(document.form.servercosts.value)==""){
		alert("Please enter the server costs!");
		document.form.servercosts.focus();
	}
	else if(trim(document.form.tapebackupcosts.value)==""){
		alert("Please enter the tape backup costs!");
		document.form.tapebackupcosts.focus();
	}
	else {
		VALIDATED=1;
	}
	
	if (VALIDATED)
	{
        if (calc_mobile())
        {
	        if (trim(document.form.mobile_workers.value)=="") {
	            alert("Please enter total number of mobile workers!");
		        document.form.mobile_workers.focus();
		        VALIDATED = 0;
	        }
	    }
	}

	if (VALIDATED) return true;
	else return false;
}

function trim(stringValue)
{
	return stringValue.replace(/(^\s+|\s+$)/g,"");
}

function calcroi(form)
{
  init();
  validate();
	
  if (VALIDATED) {
	prepare_model();
	
	prepare_steelhead();

    if (calc_mobile()) prepare_mobile();

	calc_productivity();
	calc_prodminutes();
	calc_bandwidth();
	calc_fileservers();
	calc_tapebackups();
	calc_lessdatacenterinvest();
	calc_itmaintenancetime();
	calc_mobileworkerprod();
	//ADDED calc_mobileworkerprod FUNCTION B/C I NEEDED THE FUNCTION VALUE TO BE USED IN SEVERAL PLACES. NOTE THAT THIS FUNCTION MUST PRECEDE THE totalsavings() FUNCTION AS totalsavings USES THE VALUE FROM THIS FUNCTION FOR IT'S CALCULATIONS.- 11/12/07 - PETE
	calc_totalsavings();
	calc_steelheadcosts();
	calc_managementcosts();
	calc_annualmaintenance();
	calc_totalcost();
	calc_annualgain();
	calc_roi();
	calc_paybackperiod();
	calc_savingsyear2();
	calc_annualgainyear2();
	calc_threeyearvalue();
	calc_threeyearinvest();
	calc_enteredcosts();
	//ADDED calc_enteredcosts FUNCTION B/C CODE DID NOT HAVE A WAY TO RETRIEVE ENTERED COSTS - 11/07/07 - PETE
	
	writeOut2();
  }
}

function writeOut2()
{
	resultsWindow = window.open(""+self.location, "roi", "menubar, resizable, scrollbars, width=850, height=600");
	
	resultsWindow.focus();
		
	var newContent = "<html><title>ROI Estimator Results</title>";
	newContent+="<head>";
	newContent+="<link rel='stylesheet' type='text/css' href='/css/styles.css'>";
	newContent+="<script type='text/javascript' src='/js/javascript.js'></script>";
	newContent+="</head>";
	newContent+="<body>";
	newContent+="<center>";
	newContent+="<div class='top'>";
	newContent+="<div class='logodiv'>";
	newContent+="<img src='/images/logo_tredent.gif' style='vertical-align: middle;' alt='Tredent Data Systems' />";
	newContent+="</div>";
	newContent+="<div style='float: left; font-size: 19px; font-weight: bold; margin: 35px 0 0 85px;' class='sectionhdr_normal'>";
	newContent+="<i>Return on Investment Estimator Results</i>";
	newContent+="</div>";
	newContent+="<div class='clear'></div>";
	newContent+="<div style='float: left; text-align: left; margin: 20px 0 0 0; padding: 0 20px 35px 20px; width: 755px;' align='left'>";
	newContent+="<div style='background-color: #FFF9D8; border-bottom: 1px solid #FFE8CD; border-top: 1px solid #FFE8CD; padding: 15px;'>";
	newContent+="The following is an estimation of Return on Investment (ROI) based on your input. Your actual results may vary based on your network, applications, branch offices, or other requirements. For an official quote, please <a href='/contact/' target='_blank'>contact us</a>.<br /><br /><b>To achieve instant return on investment, ask about our Managed WAN Acceleration service.</b>";
	newContent+="</div>";
	newContent+="<div style='margin: 10px 0 0 0; padding: 15px; font-size: 15px; line-height: 1.7em;'>";

	newContent+="<table width='640' border='0' align='center' cellpadding='1' cellspacing='0'>";
	newContent+="<tr><td>";
	newContent+="<table cellpadding='3' cellspacing='0' border='0' width='100%' bordercolor='#E9E9E9' bgcolor='#EFEFEF'><tr><td>";
	newContent+="<table width='100%' border='0' cellpadding='0' cellspace='0'><tr valign='top'><td width='32%' align='left'>";
	newContent+="<b style='font-size:14px; color: #333333;'><u>Return on Investment (ROI)</u>**</b></td><td width='13%'></td>";
	newContent+="<td width='18%' align='left'><b style='font-size:14px; color: #333333;'><u>Year 1</u></b></td><td width='18%' align='left'><b style='font-size:14px; color: #333333;'><u>Year 2</u></b></td>";
	newContent+="<td width='19%' align='left'><b style='font-size:14px; color: #333333;'><u>Year 3</u></b></td>";
	newContent+="</tr><tr height='10'><td></td><td></td><td></td><td></td><td></td></tr>";
	newContent+="<tr><td width='32%' align='left'>Savings &amp; Productivity Gains</td><td width='13%'></td>";	
	newContent+="<td width='18%' align='left'>$" + format(x_totalsavings, 2) + "</td>";
	newContent+="<td width='18%' align='left'>$" + format(x_savingsyear2, 2) + "</td>";
	newContent+="<td width='19%' align='left'>$" + format(x_savingsyear2, 2) + "</td>";
	newContent+="</tr><tr><td align='left'>Total Costs</td><td></td>";
	newContent+="<td align='left'>$" + format(x_totalcost, 2) + "</td>";
	//newContent+="<td align='left'>$" + format(x_annualmaintenance, 2) + "</td>";
	//newContent+="<td align='left'>$" + format(x_annualmaintenance, 2) + "</td>";
	newContent+="<td align='left'>$" + format(x_enteredcosts, 2) + "</td>";
	newContent+="<td align='left'>$" + format(x_enteredcosts, 2) + "</td>";
	//testing the 2 lines above this comment.
	newContent+="</tr><tr><td align='left'>Annual Gain</td><td></td>";
	newContent+="<td align='left'>$" + format(calc_annualgain(), 2) + "</td>";
	newContent+="<td align='left'>$" + format(calc_annualgainyear2(), 2) + "</td>";
	newContent+="<td align='left'>$" + format(calc_annualgainyear2(), 2) + "</td>";
	newContent+="</tr><tr height='10'><td></td><td></td><td></td><td></td><td></td></tr><tr>";
	newContent+="<td width='30%' align='left'><h4 style='font-size:16px;'>Payback Period (Months)</h4></td>";	
	newContent+="<td width='10%' align='left'><h4 style='font-size:16px;'>" + format(calc_paybackperiod(), 2) + "</h4></td>";	
	newContent+="<td width='20%'></td>";
	newContent+="<td colspan='2' width='40%'>Assumes a 12% cost of capital</td></tr><tr>";	
	newContent+="<td align='left'><b style='font-size:14px; color: #333333;'>3-Year Net Present Value</b></td>";	
	newContent+="<td align='left'>$" + format(x_threeyearvalue, 0) + "</td>";		
	newContent+="<td></td><td></td><td></td></tr><tr>";
	newContent+="<td align='left'><b style='font-size:14px; color: #333333;'>3-Year ROI</b></td>";
	newContent+="<td align='left'>" + format(x_threeyearinvest, 2) + "%</td>";
	newContent+="<td></td><td></td><td></td></tr></table></td></tr></table>";
	newContent+="<table width='100%' border='0' cellpadding='5' cellspacing='0'><tr>";	
	newContent+="<td colspan='3' valign='top' height='5'></td></tr><tr>";		
	newContent+="<td colspan='3' class='bottom_border' valign='top' align='left'><span class='style2'>More Detail</span></td>";
	newContent+="</tr><tr><td width='32%' align='left' valign='top'><strong>Productivity Gains</strong></td>";	
	newContent+="<td width='27%'></td><td width='41%' rowspan='2' valign='top' align='left'>";
	newContent+="Productivity gains result from eliminating employee wait time for all key applications, such as ";
	newContent+="file sharing, email, ERP systems, document management, and more.";		
	newContent+="</td></tr><tr><td></td><td></td></tr><tr>";
	newContent+="<td></td><td></td><td></td></tr><tr>";
	newContent+="<td valign='top' align='left'>Enhanced Branch Office Employee Productivity</td>";
	newContent+="<td valign='top' align='left'>$" + format(x_productivity, 2) + "</td>";
	newContent+="<td valign='top' align='left'>Estimated " + format(calc_prodminutes(), 0) + " minutes per employee saved daily.</td>";
	newContent+="</tr><tr>";
	newContent+="<td valign='top' align='left'>Enhanced Mobile Worker Productivity</td>";
	//ADDED x_enhancedmobileprod TO LINE BELOW. PREVIOUS LINE COMMENTED OUT BELOW - 11/12/07 - PETE
	newContent+="<td valign='top' align='left'>$" + format(x_mobileworkerprod, 2) + "</td>";
	//newContent+="<td valign='top' align='left'>$" + format(calc_mobileworkerprod(), 2) + "</td>";
	newContent+="<td valign='top' align='left'>Additional " + format(calc_mobileminutes(), 2) + " minutes per mobile worker saved daily.</td>";
	newContent+="</tr><tr><td colspan='3' class='bottom_border' valign='top'>";
	newContent+="<img src='/images/spacer.gif' width='1' height='1'></td></tr><tr>";
	newContent+="<td align='left'><strong>Bandwidth Savings</strong></td><td></td>";
	newContent+="<td valign='top'></td></tr><tr>";
	newContent+="<td valign='top' align='left'>Annual Bandwidth Costs Saved</td>";
	newContent+="<td valign='top' align='left'>$" + format(x_bandwidth, 2) + "</td>";
	newContent+="<td valign='top' align='left'>You estimated that you spend on average $";	
	newContent+=format(document.form.bandwidthcosts.value, 0) + " per month, per office on bandwidth.</td>";	
	newContent+="</tr><tr><td></td><td></td>";	
	newContent+="<td valign='top' align='left'>Savings can come through bandwidth reductions or upgrade deferrals.</td>";	
	newContent+="</tr><tr><td></td><td></td>";
	newContent+="<td valign='top' align='left'>Estimated " + format(steelH34*percent, 0) + "% reduction in bandwidth utilization</td>";	
	newContent+="</tr><tr><td colspan='3' class='bottom_border' valign='top' align='left'>";
	newContent+="<img src='/images/spacer.gif' width='1' height='1'></td></tr><tr>";
	newContent+="<td valign='top' align='left'><strong>Consolidation Savings</strong></td><td></td><td></td></tr><tr>";
	newContent+="<td valign='top' align='left'>Application and File Servers</td>";
	newContent+="<td valign='top' align='left'>$" +  format(x_servercosts, 2) + "</td>";
	newContent+="<td rowspan='4' valign='top' align='left'>Consolidation savings come from servers, tape backup and IT maintenance time. We assume that some of the savings must be reinvested into the data center.</td>";
	newContent+="</tr><tr><td valign='top' align='left'>Less Additional data center investment</td>";
	newContent+="<td valign='top' align='left'>$";
  	newContent+="(" + format(x_lessdatacenterinvest, 2) + ")</td>";
	newContent+="</tr><tr><td valign='top' align='left'>Tape backup Machines</td>";	
	newContent+="<td valign='top' align='left'>$" + format(x_tapebackupcosts, 2) + "</td></tr><tr>";
	newContent+="<td valign='top' align='left'>IT Maintenance Time</td>";	
	newContent+="<td valign='top' align='left'>$" + format(x_itmaintenancetime, 2) + "</td></tr><tr>";		
	newContent+="<td colspan='3' class='bottom_border' valign='top'><img src='/images/spacer.gif' width='1' height='1'></td></tr>";
	newContent+="<tr><td valign='top' align='left' bgcolor='#FFF9D8'><span class='style2'><b>Total Savings</b></span></td>";	
	newContent+="<td valign='top' align='left' bgcolor='#FFF9D8'><b>$" + format(x_totalsavings, 2) + "</b></td>";		
	newContent+="<td valign='top' align='left' bgcolor='#FFF9D8'></td></tr><tr>";
	newContent+="<td colspan='3' class='bottom_border' valign='top'><img src='/images/spacer.gif' width='1' height='1'></td></tr>";
	newContent+="<tr><td align='left'><strong>Riverbed Steelhead costs</strong></td><td></td> <td></td></tr>";
	newContent+="<tr><td valign='top' align='left'>Your quote (as you entered it)</td>";	
	//ADDED if BELOW B/C THE enteredcosts FORM FIELD IS NOT REQUIRED AND EMPTY STRINGS WERE PASSING VALIDATION
	if (document.form.enteredcosts.value==""){
		newContent+="<td valign='top' align='left'>$" + format("0", 2) + "</td><td></td></tr>";
	} else {
		newContent+="<td valign='top' align='left'>$" + format(document.form.enteredcosts.value, 2) + "</td><td></td></tr>";
	}
	newContent+="<tr><td align='left'><strong>OR a cost estimate:</strong></td><td></td> <td></td></tr>";
	newContent+="<tr><td valign='top' align='left'>Riverbed Steelhead Appliance costs*</td>";
	if (document.form.enteredcosts.value==0) {
	    newContent+="<td valign='top' align='left'>$" + format(x_steelheadcosts, 2) + "</td><td></td></tr>";
	} else {
	    newContent+="<td valign='top' align='left'>$" + format(0, 2) + "</td><td></td></tr>";
	}
    newContent+="<tr><td valign='top' align='left'>Riverbed Steelhead Mobile costs*</td>";	
	newContent+="<td valign='top' align='left'>$" + format(x_total_mobile_cost, 2) + "</td><td></td></tr>";
	newContent+="<tr><td align='left'>Management Costs</td>";
	newContent+="<td align='left'>$" + format(x_managementcosts, 2) + "</td>";
	newContent+="<td valign='top' align='left'>You estimated that IT personnel cost $" + format(document.form.itsalary.value, 0) + " p/y.</td>";	
	newContent+="</tr><tr><td valign='top' align='left'>Annual Maintenance</td>";
	newContent+="<td valign='top' align='left'>$" + format(x_annualmaintenance, 2) + "</td>";
	newContent+="<td valign='top' align='left'>Maintenance is " + format(annualmaintenance_const*percent, 0) + "% for appliances and " + format(mobilemaintenance_const*percent, 0) + "% for Steelhead Mobile software clients</td></tr>";
	newContent+="<tr><td valign='top' class='style2' align='left' valign='top'><span class='style2'>Total Costs</span></td><td valign='top' align='left'>";
	newContent+="$" + format(x_totalcost, 2) + "</td></tr><tr>";
	newContent+="<td colspan='3' valign='top'><img src='/images/spacer.gif' width='1' height='1'></td></tr><tr><td colspan='3' valign='top' align='left'>";
	newContent+="*Product costs are based on list price.<br />Cost is estimated by assuming that you have a range of office sizes and then determining the appropriate Steelhead appliances for your network. This is an estimate and does not represent a formal price quote.<br /><br /><b>**</b> Ask about our Managed WAN Acceleration service.<br /><br />";
	newContent+=" This is an estimation of Return on Investment (ROI). Your actual results may vary based on your network, applications, branch offices, or other requirements. Please <a href='/contact/' target='_blank'>contact us</a> in order to do a full analysis of Return on Investment.<br /><br />";
	newContent+="<strong>Looking for a more in-depth analysis? <a href='/contact/' target='_blank'>Contact Tredent</a></strong>";
		newContent+="<br /><br /><br />";
	newContent+="<table cellpadding=5 cellspacing=5 border=0 width=100%><tr><td><center><form><input type=button value='Print Page' onClick='window.print()'></form></td></tr></table>";
	newContent+="</td></tr></table></td></tr></table></td></tr></table>";			

	newContent+="</div></div>";
	newContent+="<div class='clear'></div>";
	newContent+="</div></div>";
	newContent+="<div class='bottom2'></div>";
	newContent+="<div class='footer' style='color: black;'>";
	newContent+="Copyright 2007 Tredent Data Systems, Inc. All Rights Reserved.";
	newContent+="</div>";
	newContent+="</center></body></html>";

	resultsWindow.document.write(newContent);
	resultsWindow.document.close();
}

function calc_mobile()
{
    if (document.form.mobile_steelhead.value == "yes") return true;
    else return false;
}

function calc_mobileminutes()
{
    return x_assume_percent_saved_mobile*minutes;
}

function calc_mobileworkerprod()
{
	//added x_mobileworkerprod to hold the value to be used elsewhere. - 11/12/07 - Pete
    //return steelH18*x_assume_percent_saved_mobile*days*weeks*minutes*document.form.mobile_workers.value;
	x_mobileworkerprod=steelH18*x_assume_percent_saved_mobile*days*weeks*minutes*document.form.mobile_workers.value;
	return x_mobileworkerprod
}

function calc_productivity()
{
	x_productivity=steelH18*steelH29*days*weeks*minutes*document.form.pplperbranch.value*document.form.numberofoffices.value;
	return x_productivity;
}

function calc_prodminutes()
{
	return steelH29*minutes;
}

function calc_bandwidth()
{
	x_bandwidth=document.form.numberofoffices.value*document.form.bandwidthcosts.value*steelH34;
	return x_bandwidth;
}

function calc_fileservers()
{
	x_servercosts=document.form.numberofoffices.value*document.form.serversperoffice.value*document.form.servercosts.value*steelH39;
	return x_servercosts;
}

function calc_tapebackups()
{
	if (document.form.tapebackup.value == "yes") {
		x_tapebackupcosts=document.form.tapebackupcosts.value*document.form.numberofoffices.value;
		return x_tapebackupcosts;
	}
	else {
		x_tapebackupcosts=0;
		return x_tapebackupcosts;
	}
}

function calc_totalsavings()
{
	x_totalsavings=x_productivity+x_bandwidth+x_servercosts+x_tapebackupcosts+x_itmaintenancetime+x_mobileworkerprod-x_lessdatacenterinvest;
	return x_totalsavings;
	//ADDED x_mobileworkerprod TO FORUMULA ABOVE - 11/12/07 - PETE
}

function calc_steelheadcosts()
{
	if (document.form.enteredcosts.value==0) {
		x_steelheadcosts=steelB21+steelC21+steelD21+steelE21;
	}
	else {
		x_steelheadcosts=document.form.enteredcosts.value;
	}

	return x_steelheadcosts;
}
/*function change by Pete - 11/01/07 - added *steelH23 to formula */
function calc_managementcosts()
{
	x_managementcosts=document.form.numberofoffices.value*steelB23*months*minutes*steelH23;
	return x_managementcosts;
}

function calc_annualmaintenance()
{
    if (document.form.enteredcosts.value==0) {
	    x_annualmaintenance=x_steelheadcosts*annualmaintenance_const + x_total_mobile_cost*mobilemaintenance_const;
	} else {
	    x_annualmaintenance=0;
	}
	return x_annualmaintenance;
}


function calc_totalcost()
{
    if (document.form.enteredcosts.value==0) {
	    //need to normalize x_steelheadcosts by multiplying by 1...not sure why...
	    x_totalcost=(x_annualmaintenance + x_managementcosts + (x_steelheadcosts*1) + x_total_mobile_cost);
	} else {
	    x_totalcost=(x_annualmaintenance + x_managementcosts + x_total_mobile_cost + (x_steelheadcosts*1));
		//alert("enteredcosts are " + (document.form.enteredcosts.value));
		//ADDED (x_steelheadcosts*1) TO LINE ABOVE, FOR YEARS 1,2 AND 3 TOTAL COST - 11/07/07 - PETE
	}
	return x_totalcost;
}

//THIS FUNCTION ADDED TO GET ENTERED COSTS AND USE THAT VALUE FOR THE ROI TOTAL COSTS YEARS 1,2 AND 3. - 11/07/07 - PETE
function calc_enteredcosts()
{
	
	if (document.form.enteredcosts.value==0) {
	    //need to normalize x_steelheadcosts by multiplying by 1...not sure why...
	    x_enteredcosts=(x_annualmaintenance + x_managementcosts);
	} else {
	    x_enteredcosts=x_managementcosts;
		//alert("enteredcosts are " + (document.form.enteredcosts.value));
		//ADDED (x_steelheadcosts*1) TO LINE ABOVE, FOR YEARS 1,2 AND 3 TOTAL COST ROI - 11/07/07 - PETE
	}
	return x_enteredcosts;
}

function calc_annualgain()
{
	x_annualgain=x_totalsavings-x_totalcost;
	
	return x_annualgain;
}

function calc_roi()
{
	return (x_totalsavings/x_totalcost)*percent;
}

function calc_paybackperiod()
{
	return x_totalcost/x_totalsavings*months;
}

function calc_lessdatacenterinvest()
{
	x_lessdatacenterinvest = (x_tapebackupcosts+x_servercosts)*lessdatainvest;
	return x_lessdatacenterinvest;
}

function calc_itmaintenancetime()
{
	x_itmaintenancetime = document.form.serversperoffice.value*document.form.numberofoffices.value*steelH39*steelH42*minutes*months*steelH23;
	return x_itmaintenancetime;
}

function calc_savingsyear2()
{
	x_savingsyear2 = x_productivity+x_bandwidth;
	return x_savingsyear2;
}

function calc_annualgainyear2()
{
	//x_annualgainyear2 = x_savingsyear2-x_annualmaintenance;
	//FORMULA CHANGED TO GET ENTERED COSTS AND USE THAT VALUE FOR THE ROI TOTAL COSTS YEARS 1,2 AND 3. - 11/07/07 - PETE
	x_annualgainyear2 = x_savingsyear2-x_enteredcosts;
	return x_annualgainyear2;
}

function calc_threeyearvalue()
{
	x_threeyearvalue = (x_annualgain/discount_rate)+(x_annualgainyear2/(discount_rate*discount_rate))+ (x_annualgainyear2/(discount_rate*discount_rate*discount_rate));
	return x_threeyearvalue;
}

function calc_threeyearinvest()
{
x_threeyearinvest = format((percent*(x_totalsavings+x_savingsyear2+x_savingsyear2)/(x_totalcost+x_annualmaintenance+x_annualmaintenance)), 2);
	
	return x_threeyearinvest;
}

