function ROI() {
	// set assumed global vars
	var salary_benefits, subscription_length, hours_per_month, hours_per_year, mins_per_hour, days_per_month, months_per_year, hardware_savings_rate;
	var productivity_savings_rate, service_savings_rate, email_cost, downtime_hours, spam_hours, internet_hours, remote_User_cost, wireless_downtime;
	var server_cost, desk_pc_cost, lap_pc_cost, sci_service_pc, sci_service_server, desk_units, desk_units_over, lap_units, lap_units_over, server_units;
	var server_units_over, remote_Users, wireless_computers, gen_salary_cost, it_staff, it_salary, external_msp_hours, msp_cost, empl_assist_hours;
	var growth_percent, gen_salary_per_hour, server_cost_factor, desk_pc_cost_factor, lap_pc_cost_factor, wireless_computer_factor, downtime_factor;
	var remote_user_factor, formatted_growth_factor, sci_standard_cost, sci_current_cost, total_server_standard_cost, total_pc_standard_cost;
	var total_lap_standard_cost, total_msg_standard_cost, total_hardware_standard_cost, total_it_standard_cost, total_external_standard_cost;
	var total_service_standard_cost, total_downtime_standard_cost, total_spam_standard_cost, total_internet_standard_cost, remote_user_standard_cost;
	var wireless_downtime_standard_cost, total_productivity_standard_cost, total_cost_standard_cost, Total_Monthly_Cost_standard_cost, total_server_current_cost;
	var total_pc_current_cost, total_notebook_current_cost, total_msg_current_cost, total_hardware_current_cost, total_it_current_cost;
	var total_external_current_cost, total_service_current_cost, total_downtime_current_cost, total_spam_current_cost, total_internet_current_cost;
	var remote_user_current_cost, wireless_downtime_current_cost, total_productivity_current_cost, total_cost_current_cost, total_monthly_current_cost;
	var total_server_new_cost, total_pc_new_cost, total_notebook_new_cost, total_msg_new_cost, total_hardware_new_costs, total_it_new_costs;
	var total_external_new_costs, sci_new_costs, total_service_new_costs, total_downtime_new_costs, total_spam_new_costs, total_internet_new_costs;
	var remote_user_new_costs, wireless_downtime_new_costs, total_productivity_new_costs, total_cost_new_costs, total_monthly_cost_new_costs;
	var SCI_Revenue_Total, SCI_Revenue_Monthly, old_total_cost, old_monthly_cost, new_total_cost, new_monthly_cost, sub_total_savings, sub_monthly_savings;
	var growth_total_cost, total_savings, yearlyCosts_0, yearlyCosts_1, yearlyCosts_2, yearlyCosts_3, yearlyCosts_total, yearlySavings_0;
	var yearlySavings_1, yearlySavings_2, yearlySavings_3, yearlySavings_total, per_Savings;
	
	salary_benefits=0.25;
	subscription_length=48;
	hours_per_month=160;
	hours_per_year=1920;
	mins_per_hour=60;
	days_per_month=20;
	months_per_year=12;
	hardware_savings_rate=0.9;
	productivity_savings_rate=0.5;
	service_savings_rate=0.8;
	email_cost=15;
	downtime_hours=2;
	spam_hours=0.25;
	internet_hours=1;
	remote_User_cost=1;
	wireless_downtime=1;
	server_cost=6000;
	desk_pc_cost=1000;
	lap_pc_cost=2300;
	sci_service_pc=50;
	sci_service_server=300;
	gen_salary_cost=45000;
	//debugger
	
	server_units = parseInt(stringFilter(document.getElementById('server_units').value));
	server_units_over = parseInt(stringFilter(document.getElementById('server_units_over').value));
	desk_units = parseInt(stringFilter(document.getElementById('desk_units').value));
	desk_units_over = parseInt(stringFilter(document.getElementById('desk_units_over').value));
	lap_units = parseInt(stringFilter(document.getElementById('lap_units').value));
	lap_units_over = parseInt(stringFilter(document.getElementById('lap_units_over').value));
	remote_Users = parseInt(stringFilter(document.getElementById('remote_Users').value));
	wireless_computers = parseInt(stringFilter(document.getElementById('wireless_computers').value));
	gen_salary_cost = parseFloat(stringFilter(document.getElementById('gen_salary_cost').value));
	it_staff = parseInt(stringFilter(document.getElementById('it_staff').value));
	it_salary = parseFloat(stringFilter(document.getElementById('it_salary').value));
	external_msp_hours = parseInt(stringFilter(document.getElementById('external_msp_hours').value));
	msp_cost = parseFloat(stringFilter(document.getElementById('msp_cost').value));
	empl_assist_hours = parseInt(stringFilter(document.getElementById('empl_assist_hours').value));
	growth_percent = parseFloat(stringFilter(document.getElementById('growth_percent').value));
	
	//qty_server = parseInt(document.getElementById('qty_server').value);
	//qty_network = parseInt(document.getElementById('qty_network').value);
	//qty_pc = parseInt(document.getElementById('qty_pc').value);
	//unit_pc = parseInt(document.getElementById('unit_pc').value);
	//qty_notebook = parseInt(document.getElementById('qty_notebook').value);
	//avg_salary = parseFloat(document.getElementById('avg_salary').value);
	//full_time = parseInt(document.getElementById('full_time').value);
	//avg_salary_it = parseFloat(document.getElementById('avg_salary_it').value);
	//hours_external = parseInt(document.getElementById('hours_external').value);
	//rate_external = parseFloat(document.getElementById('rate_external').value);
	//hour_assistance = parseInt(document.getElementById('hours_assistance').value);
	//rate_growth = parseFloat(document.getElementById('rate_growth').value);
	
	//debugger
	gen_salary_per_hour=gen_salary_cost/hours_per_year*(1+salary_benefits);
	if (server_units>0) {server_cost_factor=(server_units-server_units_over)/server_units;} else {server_cost_factor=1;}
	if (desk_units>0) {desk_pc_cost_factor=(desk_units-desk_units_over)/desk_units;} else {desk_pc_cost_factor=1;}
	if (lap_units>0) {lap_pc_cost_factor=(lap_units-lap_units_over)/lap_units;} else {lap_pc_cost_factor=1;}
	if (desk_units+lap_units>0) {wireless_computer_factor=1+(wireless_computers/(desk_units+lap_units));} else {wireless_computer_factor=1;}
	
	if (server_units==0) {downtime_factor=1+(0.5*(desk_units_over+lap_units_over)/(desk_units+lap_units));} 
	else {downtime_factor=1+(0.5*(desk_units_over+lap_units_over)/(desk_units+lap_units))+(0.5*(server_units_over/server_units));}
	
		
	if (remote_Users>0) {remote_user_factor=1+(remote_Users/(desk_units+lap_units-desk_units_over-lap_units_over+remote_Users));} else {remote_user_factor=1;}
	formatted_growth_factor=1 + (growth_percent/100);
	sci_standard_cost=0;
	sci_current_cost=0;
	total_server_standard_cost=server_units*server_cost;
	total_pc_standard_cost=desk_units*desk_pc_cost;
	total_lap_standard_cost=lap_units*lap_pc_cost;
	total_msg_standard_cost=(desk_units+lap_units)*email_cost*subscription_length;
	total_hardware_standard_cost=total_server_standard_cost+total_pc_standard_cost+total_lap_standard_cost+total_msg_standard_cost;
	total_it_standard_cost=it_staff*it_salary/months_per_year * (1 + salary_benefits)*subscription_length;
	total_external_standard_cost=external_msp_hours*msp_cost*subscription_length;
	total_service_standard_cost=total_it_standard_cost+total_external_standard_cost+sci_standard_cost;
	total_downtime_standard_cost=downtime_hours*subscription_length*(desk_units+lap_units)*gen_salary_per_hour;
	total_spam_standard_cost=(desk_units+lap_units)*spam_hours*subscription_length*gen_salary_per_hour;
	total_internet_standard_cost=(desk_units+lap_units)*internet_hours*gen_salary_per_hour*subscription_length;
	remote_user_standard_cost=gen_salary_per_hour*remote_User_cost*subscription_length*remote_Users;
	wireless_downtime_standard_cost=wireless_computers*gen_salary_per_hour*subscription_length*wireless_downtime;
	total_productivity_standard_cost=total_downtime_standard_cost+total_spam_standard_cost+total_internet_standard_cost+remote_user_standard_cost+wireless_downtime_standard_cost;
	total_cost_standard_cost=total_hardware_standard_cost+total_service_standard_cost+total_productivity_standard_cost;
	Total_Monthly_Cost_standard_cost=total_cost_standard_cost/subscription_length;
	total_server_current_cost=server_units*server_cost*server_cost_factor;
	total_pc_current_cost=desk_units*desk_pc_cost*desk_pc_cost_factor;
	total_notebook_current_cost=lap_units*lap_pc_cost*lap_pc_cost_factor;
	total_msg_current_cost=(desk_units+lap_units)*email_cost*subscription_length;
	total_hardware_current_cost=total_server_current_cost+total_pc_current_cost+total_notebook_current_cost+total_msg_current_cost;
	total_it_current_cost=it_staff*it_salary/months_per_year * (1 + salary_benefits)*subscription_length;
	total_external_current_cost=external_msp_hours*msp_cost*subscription_length;
	total_service_current_cost=total_it_current_cost+total_external_current_cost+sci_current_cost;
	total_downtime_current_cost=downtime_hours*subscription_length*(desk_units+lap_units)*gen_salary_per_hour*downtime_factor;
	total_spam_current_cost=(desk_units+lap_units)*spam_hours*subscription_length*gen_salary_per_hour;
	total_internet_current_cost=(desk_units+lap_units)*internet_hours*gen_salary_per_hour*subscription_length*downtime_factor;
	remote_user_current_cost=gen_salary_per_hour*remote_User_cost*subscription_length*remote_Users*remote_user_factor;
	wireless_downtime_current_cost=wireless_computers*gen_salary_per_hour*subscription_length*wireless_downtime*wireless_computer_factor;
	total_productivity_current_cost=total_downtime_current_cost+total_spam_current_cost+total_internet_current_cost+remote_user_current_cost+wireless_downtime_current_cost;
	total_cost_current_cost=total_hardware_current_cost+total_service_current_cost+total_productivity_current_cost;
	total_monthly_current_cost=total_cost_current_cost/subscription_length;
	total_server_new_cost=server_units*server_cost*hardware_savings_rate;
	total_pc_new_cost=desk_units*desk_pc_cost*hardware_savings_rate;
	total_notebook_new_cost=lap_units*lap_pc_cost*hardware_savings_rate;
	total_msg_new_cost=(desk_units+lap_units)*email_cost*subscription_length*hardware_savings_rate;
	total_hardware_new_costs=total_server_new_cost+total_pc_new_cost+total_notebook_new_cost+total_msg_new_cost;
	total_it_new_costs=it_staff*it_salary/months_per_year * (1 + salary_benefits)*subscription_length*service_savings_rate;
	total_external_new_costs=external_msp_hours*msp_cost*subscription_length*service_savings_rate;
	sci_new_costs=((desk_units+lap_units)*sci_service_pc+(server_units*sci_service_server))*subscription_length;
	if (sci_new_costs>(total_it_new_costs+total_external_new_costs)) {total_service_new_costs=sci_new_costs;} else {total_service_new_costs=total_it_new_costs+total_external_new_costs;}
	total_downtime_new_costs=downtime_hours*subscription_length*(desk_units+lap_units)*gen_salary_per_hour*productivity_savings_rate;
	total_spam_new_costs=(desk_units+lap_units)*spam_hours*subscription_length*gen_salary_per_hour*productivity_savings_rate;
	total_internet_new_costs=(desk_units+lap_units)*internet_hours*gen_salary_per_hour*subscription_length*productivity_savings_rate;
	remote_user_new_costs=gen_salary_per_hour*remote_User_cost*subscription_length*remote_Users*productivity_savings_rate;
	wireless_downtime_new_costs=wireless_computers*gen_salary_per_hour*subscription_length*wireless_downtime*productivity_savings_rate;
	total_productivity_new_costs=total_downtime_new_costs+total_spam_new_costs+total_internet_new_costs+remote_user_new_costs+wireless_downtime_new_costs;
	total_cost_new_costs=total_hardware_new_costs+total_service_new_costs+total_productivity_new_costs;
	total_monthly_cost_new_costs=total_cost_new_costs/subscription_length;
	SCI_Revenue_Total=total_service_new_costs;
	SCI_Revenue_Monthly=SCI_Revenue_Total/subscription_length;
	old_total_cost=total_cost_current_cost;
	old_monthly_cost=total_monthly_current_cost;
	new_total_cost=total_cost_new_costs;
	new_monthly_cost=total_monthly_cost_new_costs;
	sub_total_savings=total_cost_current_cost-total_cost_new_costs;
	sub_monthly_savings=total_monthly_current_cost-total_monthly_cost_new_costs;
	
	
	
	//growth_total_cost=(old_monthly_cost * months_per_year) * (1 + formatted_growth_factor + (formatted_growth_factor^2) + (formatted_growth_factor^3));
	//total_savings=(sub_monthly_savings * months_per_year) * (1 + formatted_growth_factor + (formatted_growth_factor^2) + (formatted_growth_factor^3));
	
	
	
	//yearlyCosts_0=(old_monthly_cost * months_per_year) * (formatted_growth_factor^0);
	//yearlyCosts_1=(old_monthly_cost * months_per_year) * (formatted_growth_factor^1);
	//yearlyCosts_2=(old_monthly_cost * months_per_year) * (formatted_growth_factor^2);
	//yearlyCosts_3=(old_monthly_cost * months_per_year) * (formatted_growth_factor^3);
	//yearlyCosts_total=yearlyCosts_0+yearlyCosts_1+yearlyCosts_2+yearlyCosts_3;
	//yearlySavings_0=(sub_monthly_savings * months_per_year) *(formatted_growth_factor^0);
	//yearlySavings_1=(sub_monthly_savings * months_per_year) *(formatted_growth_factor^1);
	//yearlySavings_2=(sub_monthly_savings * months_per_year) *(formatted_growth_factor^2);
	//yearlySavings_3=(sub_monthly_savings * months_per_year) *(formatted_growth_factor^3);
	//yearlySavings_total=yearlySavings_0+yearlySavings_1+yearlySavings_2+yearlySavings_3;
	//per_Savings=(total_cost_current_cost-total_cost_new_costs)/total_cost_current_cost;
	
	
	//switch(document.getElementById('email').value) {
	//	case "Outlook (Exchange)":
	//		rate_msg = rate_exchange;
	//		break;
	//	case "IMAP":
	//		rate_msg = rate_imap;
	//		break;
	//	case "Other":
	//		rate_msg = rate_other_msg;
	//		break;
	//	default:
	//	    rate_msg = 0.0;
	//		//rate_email = 0.0;
	//		break;
	//}
	
	
	// rate_growth is a whole number, e.g. 10; divide by 100 to get the real rate
	//rate_growth = (rate_growth != 0) ? rate_growth / 100 : 0;
	//growth_factor = 1 + rate_growth;
	//total_cost = (monthly_cost * months_year) * (1 + growth_factor + Math.pow(growth_factor, 2) + Math.pow(growth_factor, 3));
	//total_savings = (monthly_savings * months_year) * (1 + growth_factor + Math.pow(growth_factor, 2) + Math.pow(growth_factor, 3));
	//debugger
	yearlyCosts_total = 0;
	var yearlyCosts = [];
	for (i=0;i<4;i++) {
	    yearlyCosts[i] = (old_monthly_cost * months_per_year) * Math.pow(formatted_growth_factor, i);
		yearlyCosts_total = yearlyCosts_total + yearlyCosts[i];
		
	}
	var monthlyCosts_total = yearlyCosts_total/subscription_length;
	
	yearlySavings_total = 0;
	var yearlySavings = [];
	for (i=0;i<4;i++) {
	    yearlySavings[i] = (sub_monthly_savings * months_per_year) * Math.pow(formatted_growth_factor, i);
		yearlySavings_total = yearlySavings_total + yearlySavings[i];
		
	}
	var year1Savings = yearlySavings[0];
	var year4Costs = yearlyCosts[3];
	var monthlySavings_total = yearlySavings_total/subscription_length;
	per_Savings=yearlySavings_total/yearlyCosts_total*100;
	
	
	
	if (isNaN(old_total_cost) || isNaN(old_monthly_cost) || isNaN(sub_total_savings) || isNaN(sub_monthly_savings)) {
		alert("Please complete all fields and remove punctuation.");
	} else {
		if (server_units_over>server_units) {
			alert("The number of server units over cannot be greater than number of server units.");
	} else {
		if (desk_units_over>desk_units) {
			alert("The number of desktop units over cannot be greater than number of desktop units.");
	} else {
		if (lap_units_over>lap_units) {
			alert("The number of notebook units over cannot be greater than number of notebook units.");
	} else {
		if (remote_Users>lap_units+desk_units) {
			alert("The number of remote users cannot be greater than desktop plus notebook users.");
	} else {
		if (wireless_computers>lap_units+desk_units) {
			alert("The number of wireless users cannot be greater than desktop plus notebook users.");	
	} else {
		if (lap_units+desk_units==0) {
			alert("You must have some desktop or laptop computers.");		
	} else {
		document.getElementById('per_Savings').innerHTML = addCommas(per_Savings.toFixed(1) + "%");
		document.getElementById('old_monthly_cost').innerHTML = "$ " + addCommas(old_monthly_cost.toFixed(0));
		document.getElementById('old_total_cost').innerHTML = "$ " + addCommas(old_total_cost.toFixed(0));
		document.getElementById('sub_monthly_savings').innerHTML = "$ " + addCommas(monthlySavings_total.toFixed(0));
		document.getElementById('sub_total_savings').innerHTML = "$ " + addCommas(yearlySavings_total.toFixed(0));
		
		document.getElementById('old_monthly_cost2').innerHTML = "$ " + addCommas(old_monthly_cost.toFixed(0));
		document.getElementById('old_total_cost2').innerHTML = "$ " + addCommas(old_total_cost.toFixed(0));
		document.getElementById('monthlyCosts_total2').innerHTML = "$ " + addCommas(monthlyCosts_total.toFixed(0));
		
if (per_Savings>0) {
		
		
		document.getElementById('roiResultsDiv').style.display = '';
		document.getElementById('roiResultsNeg').style.display = 'none';
	
		
	
		var roiChart = document.getElementById('roiChart');
		var roiNoteDiv = document.getElementById('roiNote');
		
		// Uses google charting api, see http://code.google.com/apis/chart/
		
		// example url, http://chart.apis.google.com/chart?cht=bvg&chd=t:375065,412571,453828,499211|181212,199334,219267,241194&chs=550x200&chl=Year%201|Year%202|Year%203|Year%204&chco=8B2031,45577A&chds=100000,500000&chdl=Costs%20without%20DirectPointe|Savings%20with%20DirectPointe&chbh=25,5,15&chxt=y&chxr=0,100,500
		var charUrl = "http://chart.apis.google.com/chart?";
		// cht (chart type) = bvg (bar vertical graph
		charUrl += "cht=bvg";
		// chd (Chart Data) = t (text encoding): (comma seperated values seperated by | to indicate the series (aka, cost and savings)
		charUrl += "&chd=t:" + yearlyCosts.join(',') +  "|" + yearlySavings.join(',');
		var minScalingFactor = 5;
		// min and max to show on graph
		charUrl += "&chds=" + (year1Savings - year1Savings / minScalingFactor) + "," + year4Costs;
		// On the y asix (0), show the scaling in thousands (k)
		charUrl += "&chxr=0," + ((year1Savings - year1Savings / minScalingFactor) / 1000) + "," + (year4Costs / 1000);
		// chart size
		charUrl += "&chs=550x200";
		// chart series labels
		charUrl += "&chl=" + encodeURI("Year 1|Year 2|Year 3|Year 4");
		// series colors
		charUrl += "&chco=8B2031,45577A";
		// chart title
		charUrl += "&chtt=" + encodeURI("ROI Savings with SCI Canada");
		// chart title color
        charUrl += "&chts=45577A";
		// series labels
		charUrl += "&chdl=" + encodeURI("Costs without SCI Canada") + "|" + encodeURI("Total Savings with SCI Canada");
		// Bar width and spacing, chbh= <bar width in pixels>,<optional space between bars in a group>,<optional space between groups>
		charUrl += "&chbh=25,5,15";
		// Show labels on the y axis
		charUrl += "&chxt=y";
		
		roiChart.src = charUrl;
		roiChart.style.display = "block";
		roiNoteDiv.style.display = "block";}

 	else {	document.getElementById('roiResultsDiv').style.display = 'none'; 
			document.getElementById('roiResultsNeg').style.display = '';}
		
	}
}}}}}}}
function addCommas(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 roundUp(number) {
	if (parseInt(number) == number) {
		number = number;
	} else if (Math.round(number) > number) {
		number = Math.round(number);
	} else {
		number = Math.round(number) + 1;
	}
	return number;
}
function stringFilter (input) {

var filteredValues = "1234567890. ";     // Characters stripped out
var i;
var returnString = "";
for (i = 0; i < input.length; i++) {  // Search through string and append to unfiltered values to returnString.
var c = input.charAt(i);
if (filteredValues.indexOf(c) != -1){ returnString += c;}
}
if (returnString == ""){ returnString = "0";}
return returnString;
}

