var Rate
var threeYrMonth,fourYrMonth,fiveYrMonth,threeYrQuarter,fourYrQuarter,fiveYrQuarter;

// Set default to SME values
threeYrMonth = 33.00;
fourYrMonth = 26.54;
fiveYrMonth = 22.51;
threeYrQuarter = 98.00;
fourYrQuarter = 78.58;
fiveYrQuarter = 66.61;

function checkRate(tmp)
{
  switch (tmp)
  {
    case "gov":
	  threeYrMonth = 32.01;	//NHS, LEA, GOV, 100k
	  fourYrMonth = 25.15;
	  fiveYrMonth = 21.07;
	  threeYrQuarter = 95.11;
	  fourYrQuarter = 74.73;
	  fiveYrQuarter = 62.58;
	  break
	case "sme":
	  threeYrMonth = 33.00;		//SME's
	  fourYrMonth = 26.54;
	  fiveYrMonth = 22.51;
	  threeYrQuarter = 98.00;
	  fourYrQuarter = 78.58;
	  fiveYrQuarter = 66.61;
	  break
	case "professions":
	  threeYrMonth = 32.44;	//Professions
	  fourYrMonth = 25.61;
	  fiveYrMonth = 21.54;
	  threeYrQuarter = 96.32;
	  fourYrQuarter = 76.01;
	  fiveYrQuarter = 63.91;
	  break
	case "tier":
	  threeYrMonth = 35.00;	//Tier 2
	  fourYrMonth = 28.45;
	  fiveYrMonth = 24.51;
	  threeYrQuarter = 103.69;
	  fourYrQuarter = 83.85;
	  fiveYrQuarter = 72.50;
	  break
	default:
	  alert("Sorry there has been an error");

}
//alert(Rate);
}

function twoDec(num)
{
// rounds postage to two decimal places
	num = "" + ((Math.round(num * 100)) / 100);
	dec1 = num.substring(num.length-3, num.length-2);
	dec2 = num.substring(num.length-2, num.length-1);

	if (dec1 != '.') { // adds trailing zeroes if necessary
	if (dec2 == '.') num += "0";
	else num += ".00";
	}
	return num;
}

function calculate_ccform()
{
var Amount = document.forms[0].amount.value;
var Users = document.forms[0].cc_users.value;

//This section validates the user input

	if ((Amount == "") || (Amount == null))
	{ 
	alert("Please enter an amount, making sure you exclude the pound sign.");
	document.forms[0].amount.focus();
	return false;
	}
	
	if ((Users == "") || (Users == "0"))
	{ 
	Users = "1";
	return false;
	}
	
	else
	{
	TOTALthreeyrmonthly = (threeYrMonth*Amount)/1000;
	TOTALfouryrmonthly = (fourYrMonth*Amount)/1000;
	TOTALfiveyrmonthly = (fiveYrMonth*Amount)/1000;
	TOTALthreeyrperuser = TOTALthreeyrmonthly/Users;
	TOTALfouryrperuser = TOTALfouryrmonthly/Users;
	TOTALfiveyrperuser = TOTALfiveyrmonthly/Users;
	TOTALthreeyrquaterly = (threeYrQuarter*Amount)/1000;
	TOTALfouryrquaterly = (fourYrQuarter*Amount)/1000;
	TOTALfiveyrquaterly = (fiveYrQuarter*Amount)/1000;
	
	TOTALthreeyrmonthly = twoDec(TOTALthreeyrmonthly);
	TOTALfouryrmonthly = twoDec(TOTALfouryrmonthly);
	TOTALfiveyrmonthly = twoDec(TOTALfiveyrmonthly);
	
	TOTALthreeyrperuser = twoDec(TOTALthreeyrperuser);
	TOTALfouryrperuser = twoDec(TOTALfouryrperuser);
	TOTALfiveyrperuser = twoDec(TOTALfiveyrperuser);
	
	TOTALthreeyrquaterly = twoDec(TOTALthreeyrquaterly);
	TOTALfouryrquaterly = twoDec(TOTALfouryrquaterly);
	TOTALfiveyrquaterly = twoDec(TOTALfiveyrquaterly);
	
	document.forms[0].threeyrmonthly.value=TOTALthreeyrmonthly;
	document.forms[0].fouryrmonthly.value=TOTALfouryrmonthly;
	document.forms[0].fiveyrmonthly.value=TOTALfiveyrmonthly;
	document.forms[0].threeyrperuser.value=TOTALthreeyrperuser;
	document.forms[0].fouryrperuser.value=TOTALfouryrperuser;
	document.forms[0].fiveyrperuser.value=TOTALfiveyrperuser;
	document.forms[0].threeyrquaterly.value=Math.round(TOTALthreeyrquaterly);
	document.forms[0].fouryrquaterly.value=Math.round(TOTALfouryrquaterly);
	document.forms[0].fiveyrquaterly.value=Math.round(TOTALfiveyrquaterly);
if (typeof(Sarissa)!="undefined")
 {
  var xmlhttp =  new XMLHttpRequest();
  xmlhttp.open("POST","../requestvalues.asp", false);
  xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  xmlhttp.send("Amount="+escape(Amount)+"&Users="+escape(Users));
 }
	return false;
	}
}

function calculate_cpuform()
{
var CostPerUser = document.forms[1].amount.value
var Users = document.forms[1].users.value
var Term = document.forms[1].term.value

	if ((CostPerUser == "") || (CostPerUser == null))
	{ 
	alert("Please enter the cost per user, making sure you exclude the pound sign.");
	document.forms[1].amount.focus();
	return false;
	}
	
	if ((Users == "") || (Users == "0"))
	{ 
	Users = "1";
	}
	
	if (document.forms[1].term[0].checked)
	{document.forms[1].capitalcost.value=Math.round(CostPerUser*Users/33*1000);
	return false;
	}
	
	if (document.forms[1].term[1].checked)
	{document.forms[1].capitalcost.value=Math.round(CostPerUser*Users/27*1000);
	return false;
	}
	
	else
	{document.forms[1].capitalcost.value=Math.round(CostPerUser*Users/22.51*1000)
	return false;
	}	
}
