function reset()
{
	document.roiForm.reset();
	document.getElementById('error').innerHTML = '';
	document.getElementById("savingsPerComputer").innerHTML = "$0.00";
	document.getElementById("totalSavings").innerHTML = "$0.00";
	document.getElementById("return").innerHTML = "0%";
	document.getElementById("payback").innerHTML = "0 months";
}
function calculate()
{
	var form = document.roiForm;
	var error = '';
	
	
	var desktops = parseInt(form.desktops.value.replace(',',''));
	var laptops = parseInt(form.laptops.value.replace(',',''));
	var locations = parseInt(form.locations.value.replace(',',''));
	var totalComputers = desktops + laptops;
	
	if (desktops == '' || isNaN(desktops))
	{ desktops = 0; }
	if (laptops == '' || isNaN(laptops))
	{ laptops = 0; }
	if (locations == '' || isNaN(locations))
	{ locations = 0; }
	
	form.desktops.value = desktops;
	form.laptops.value = laptops;
	form.locations.value = locations;
	document.getElementById('error').innerHTML = error;
		
	if (desktops < 0 || isNaN(desktops))
	{
		error += "Invalid value for Desktops.<br />";
	}
	if (laptops < 0 || isNaN(laptops))
	{
		error += "Invalid value for Laptops.<br />";
	}
	if (locations < 0 || isNaN(locations))
	{
		error += "Invalid value for Locations.<br />";
	}
	
	if (totalComputers < 100 || locations == 0)
	{
		error += "You must have at least 100 computers in at least 1 location.<br />";
	}
	
	if (error)
	{
		document.getElementById('error').innerHTML = error;
		return false;
	}
	
	
	var current = new Array(17);
	var webex = new Array();
	webex[0] = 0; // Annual WebEx SW Cost/Computer
	webex[1] = 0; // Total Annual WebEx SW Cost
	webex[2] = 0; // Total Licensed SW Cost
	webex[3] = 0; // On Premise Asset Management SW
	webex[4] = 0; // Total SW Cost
	webex[5] = 0; // Annual Enterprise Server Costs
	webex[6] = 0; // Annual Package Server Costs
	webex[7] = 0; // Annual HW Support Costs
	webex[8] = 0; // Total Annual HW Cost
	webex[9] = 0; // Deployment Cost
	webex[10] = 0; // Annual Asset Management People Costs
	webex[11] = 0; // Annual Security People Costs
	webex[12] = 0; // Annual IT Support People Costs
	webex[13] = 0; // Annual Infrastructure Support People Costs
	webex[14] = 0; // Annual DBA Costs
	webex[15] = 0; // Total Annual People Cost
	webex[16] = 0; // Total Annual Desktop Management Cost
		
	current[0] = 0;
	if (totalComputers > 1000)
	{ webex[0] = 90; }
	else if (totalComputers > 500)
	{ webex[0] = 96; }
	else if (totalComputers > 200)
	{ webex[0] = 114; }
	else
	{ webex[0] = 120; }
		
	current[1] = 0;
	webex[1] = webex[0] * totalComputers;
	
	current[2] = 278 * totalComputers;
	webex[2] = round(current[2] * 0.9, 2);
	
	current[3] = 28.66 * totalComputers;
	webex[3] = 0;
	
	current[4] = roundUp(current[1]  + current[2]  + current[3]);
	webex[4] = roundUp(webex[1]  + webex[2]  + webex[3]);
	
	if (totalComputers > 1249)
	{
		{
			var cheese;
			if (roundUp(totalComputers / 1250) < locations)
				cheese = (roundUp(totalComputers / 1250) < locations);
			else
				cheese = locations;
		}
		round
		(
		
		
			1000 * cheese
				
			/ 3, 2
		)
	}
	else
	{
		
	}
	
	
	if ((totalComputers / 1250) < locations)
	{
		current[5] = round(totalComputers / 1250 * 10000 / 3, 2);
	}
	else
	{
		current[5] = 0;
	}
	webex[5] = 0;
	var mult = 0;
	
	if (locations < 16)
	{
		mult = roundUp(locations / 3);
	}
	else if (locations < 51)
	{
		mult = roundUp((locations - 15) / 5) + 5;
	}
	else if (locations < 151)
	{
		mult = roundUp((locations - 50) / 20) + 10;
	}
	else
	{
		mult = roundUp((locations - 150) / 35) + 15;
	}
	
	mult += roundUp(totalComputers/1000);
	
	//if(totalComputers>1249, ROUND(2500*(if(locations<16,ROUNDUP(locations/3,0),if(locations<51,ROUNDUP((locations-15)/5,0)+5, if(locations<151, ROUNDUP((locations-50)/20, 0)+10, ROUNDUP((locations2-150)/35, 0)+15)))+ROUNDUP(totalComputers/1000, 0))/3, 2), totalComputers/1249*ROUND(2500*(if(locations<16,ROUNDUP(locations/3,0),if(locations<51,ROUNDUP((locations-15)/5,0)+5, if(locations<151, ROUNDUP((locations-50)/20, 0)+10, ROUNDUP((locations2-150)/35, 0)+15)))+ROUNDUP(totalComputers/1000, 0))/3, 2))
	
	
	mult = 0;
	
	if (totalComputers > 1249)
	{
		if (locations<16)
			mult = roundUp(locations / 3);
		else if(locations<51)
			mult = roundUp((locations - 15) / 5) + 5;
		else if(locations<151)
			mult = roundUp((locations - 50) / 20) + 1;
		else 
			mult = roundUp((locations - 150) / 35) + 15;
	}
	else
	{
		if(locations<16)
		 	mult = roundUp(locations/3);
		 else if(locations<51)
		 	mult = roundUp((locations-15)/5)+5;
		 else if(locations<151)
		 	mult = roundUp((locations-50)/20, 0)+10;
		 else
		 {
		 	mult = roundUp
		 	( 
		 		(locations-150) / 35
		 	)
		 	+15
		 	+round(totalComputers/1000,2);
		 }
	}
	
		
	current[6] = round((totalComputers / 1249) * round(2500 * mult / 3, 2),2);
	webex[6] = round(current[6] / 4, 2);
	
	current[7] = round((current[5] + current[6]) * 0.54, 2);
	webex[7] = round((webex[5] + webex[6]) * 0.54, 2);
	
	current[8] = round(current[5] + current[6] + current[7], 0);
	webex[8] = round(webex[5] + webex[6] + webex[7], 0);
	
	current[9] = 0;
	if(totalComputers < 201)
	{
		webex[9] = roundUp(totalComputers / 200 * 2500);
	}
	else if (totalComputers < 501)
	{
		webex[9] = 5000;
	}
	else if (totalComputers < 2001)
	{
		webex[9] = 7500;
	}
	else if (totalComputers < 5001)
	{
		webex[9] = 10000;
	}
	else if (totalComputers < 10001)
	{
		webex[9] = 20000;
	}
	else
	{
		webex[9] = 25000;
	}
		
	current[10] = round(((((176*desktops)+(207*laptops))/60/2000)*75000)+((22.4*totalComputers)/60/2000*125000), 0);
	webex[10] = round(((((176*desktops)+(207*laptops))/60/2000)*40500)+((22.4*totalComputers)/60/2000*93750), 0);
	
	current[11] = round(((74*totalComputers)/60/2000*75000)+((11.2*totalComputers)/60/2000*125000), 0);
	webex[11] = round(((74*totalComputers)/60/2000*28500)+((11.2*totalComputers)/60/2000*112500), 0);
	
	current[12] = round(((300*totalComputers)/60/2000*75000)+((25.2*totalComputers)/60/2000*125000), 0);
	webex[12] = round(((240*totalComputers)/60/2000*75000)+((19.8*totalComputers)/60/2000*125000), 0);

	mult = 0;
	
	if(totalComputers>999)
	{
		if(totalComputers<2500)
			mult = 0.5+((totalComputers-1000)/1500*0.25);
		else if(totalComputers<5000)
			mult = 0.75+((totalComputers-2500)/2500*0.25);
		else if(totalComputers<10000)
			mult = 1+((totalComputers-5000)/5000*0.25);
		else if(totalComputers<15000)
			mult = 1.25+((totalComputers-10000)/5000*0.2);
		else
			mult =1.45+((totalComputers-15000)/5000*0.15)
	}
	else
	{
		mult =  0.5 - ((1000-totalComputers) * 0.00035);
	}
	
	
	if(totalComputers>999)
	{
		current[13] = round(2 / 3 * round(mult * 4 / 3, 2) * 125000, 0);
	}
	else
	{
		current[13] = round(2 / 3 * totalComputers / 999 * round(mult * 4 / 3, 2) * 125000, 0);
	}
	
	webex[13] = round(current[13] / 8,0);
	
	
	mult = 0;

	if(totalComputers>999)
	{
		if(totalComputers<2500)
			mult = 0.5+((totalComputers-1000)/1500*0.25);
		else if(totalComputers<5000)
			mult = 0.75+((totalComputers-2500)/2500*0.25);
		else if(totalComputers<10000)
			mult = 1+((totalComputers-5000)/5000*0.25);
		else if(totalComputers<15000)
			mult = 1.25+((totalComputers-10000)/5000*0.2);
		else
			mult =1.45+((totalComputers-15000)/5000*0.15)
	}
	else
	{
		mult =  0.5 - ((1000-totalComputers) * 0.00035);
	}
	
	
	if(totalComputers>999)
	{
		current[14] = round(mult * 2 / 3 * 8 / 9, 2) * 125000;
	}
	else
	{
		current[14] = round(totalComputers / 999 * round(mult * 2 / 3 * 8 / 9, 2) * 125000, 0);
	}
	
	webex[14] = round(current[14] / 4,0);
	
	current[15] = current[10] + current[11] + current[12] + current[13] + current[14];
	webex[15] = webex[10] + webex[11] + webex[12] + webex[13] + webex[14];
	
	current[16] = current[4] + current[8] + current[9] + current[15];
	webex[16] = webex[4] + webex[8] + webex[9] + webex[15];
	
	var totalAnnualSavings = round(current[16] - webex[16] , 0);
	var returnOnInvestment = totalAnnualSavings - webex[1];
	var totalSavingsPerComputer = round(totalAnnualSavings / totalComputers, 0);
	var payoff = round(webex[1] / (webex[1] + totalAnnualSavings) * 12 , 1);
	returnOnInvestment = roundUp(totalAnnualSavings / webex[1] * 100);
	totalSavingsPerComputer =commaFormatted(totalSavingsPerComputer + '');
	totalAnnualSavings = commaFormatted(totalAnnualSavings + '');
	
	document.getElementById("savingsPerComputer").innerHTML = "$" + totalSavingsPerComputer;
	document.getElementById("totalSavings").innerHTML = "$" + totalAnnualSavings;
	document.getElementById("return").innerHTML = returnOnInvestment + "%";
	document.getElementById("payback").innerHTML = payoff + " months";
	
	//document.getElementById("check").innerHTML = "<table>	 <tr>	  <th>#</th>	  <th>webex</th>	  <th>current</th>	 </tr>	 <tr>	  <th>0</th>	  <td>"+webex[0]+"</td>	  <td>"+current[0]+"</td>	 </tr>	 <tr>	  <th>1</th>	  <td>"+webex[1]+"</td>	  <td>"+current[1]+"</td>	 </tr>	 <tr>	  <th>2</th>	  <td>"+webex[2]+"</td>	  <td>"+current[2]+"</td>	 </tr>	 <tr>	  <th>3</th>	  <td>"+webex[3]+"</td>	  <td>"+current[3]+"</td>	 </tr>	 <tr>	  <th>4</th>	  <td>"+webex[4]+"</td>	  <td>"+current[4]+"</td>	 </tr>	 <tr>	  <th>5</th>	  <td>"+webex[5]+"</td>	  <td>"+current[5]+"</td>	 </tr>	 <tr>	  <th>6</th>	  <td>"+webex[6]+"</td>	  <td>"+current[6]+"</td>	 </tr>	 <tr>	  <th>7</th>	  <td>"+webex[7]+"</td>	  <td>"+current[7]+"</td>	 </tr>	 <tr>	  <th>8</th>	  <td>"+webex[8]+"</td>	  <td>"+current[8]+"</td>	 </tr>	 <tr>	  <th>9</th>	  <td>"+webex[9]+"</td>	  <td>"+current[9]+"</td>	 </tr>	 <tr>	  <th>10</th>	  <td>"+webex[10]+"</td>	  <td>"+current[10]+"</td>	 </tr>	 <tr>	  <th>11</th>	  <td>"+webex[11]+"</td>	  <td>"+current[11]+"</td>	 </tr>	 <tr>	  <th>12</th>	  <td>"+webex[12]+"</td>	  <td>"+current[12]+"</td>	 </tr>	 <tr>	  <th>13</th>	  <td>"+webex[13]+"</td>	  <td>"+current[13]+"</td>	 </tr>	 <tr>	  <th>14</th>	  <td>"+webex[14]+"</td>	  <td>"+current[14]+"</td>	 </tr>	 <tr>	  <th>15</th>	  <td>"+webex[15]+"</td>	  <td>"+current[15]+"</td>	 </tr>	 <tr>	  <th>16</th>	  <td>"+webex[16]+"</td>	  <td>"+current[16]+"</td>	 </tr>	</table>";
	return true;
}

function showList()
{
	document.getElementById('assumptionsList').style.display = 'block';
}
function hideList()
{
	document.getElementById('assumptionsList').style.display = 'none';
}

function round(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

function roundUp(num)
{
	return Math.ceil(num);
}

function isInt(x)
{
	var y = parseInt(x);
	if (isNaN(y))
	{
		return false;
	}
	else
	{
		return x == y && x.toString() == y.toString();
	}
 } 


function commaFormatted(amount)
{
	var delimiter = ","; // replace comma if desired
	amount = parseInt(amount);
	if (isNaN(amount))
	{
		return '';
	}
	var minus = '';
	if(amount < 0) { minus = '-'; }
	var number = new String(amount);
	var a = [];
	while(number.length > 3)
	{
		var nn = number.substr(number.length-3);
		a.unshift(nn);
		number = number.substr(0,number.length-3);
	}
	if(number.length > 0) { a.unshift(number); }
	number = a.join(delimiter);
	amount = minus + number;
	return amount;
}