// JScript source code
	
var capacity = new Array(0.5, 1, 1.5, 2, 2.5, 3,3.5, 4, 4.5, 5, 5.5, 6, 6.5, 7, 7.5, 8, 8.5, 9, 9.5, 10);
var price = new Array(9.95, 14.95, 15.95, 16.95, 17.95, 18.95, 19.95, 20.95, 21.95, 22.95, 23.95, 24.95, 25.95, 26.95, 27.95, 28.95, 29.95, 30.95, 31.95, 32.95);

function CalculateStoragePrice()
{
	//get the desired space amount
	var desiredSpace = document.getElementById("DesiredSpaceAmount").value;

	//verify that the desired space was entered
	if(desiredSpace == "")
	{
		alert("Please enter the amount of space required.");
		return;
	}
	
	//the total price for the customer
	var totalPrice = 0;
	
	//convert the space into gigabytes if needed
	if(document.getElementById("DesiredSpaceUnit").value == "MB")
	{
		desiredSpace = desiredSpace / 1024;
	}
	
	//compute the space requirement accounting for compression
	desiredSpace = desiredSpace * 0.75;
	
	//check if we are exceeding the maximum that can be priced
	if (desiredSpace > capacity[capacity.length-1])
	{
		document.getElementById("CalculatedPriceText").value = "Please Call";
		alert("For capacities over " + capacity[capacity.length-1] + "GB please contact us for pricing");
		return;
	}
	
	//convert the space requirement into a price and add it to the total
	for (var i = 0;i < capacity.length; i++)
	{
		if (desiredSpace <= capacity[i])
		{
			totalPrice += price[i];
			break;
		}
	}

	//sum up the price of all the selected add-ons and add it to the running total
	var addOnPrice = 0;
	var addOnCheckList = document.getElementsByName("AddOn");
	for (var i = 0;i < addOnCheckList.length;i++)
	{
		if(addOnCheckList[i].checked)
		{
			addOnPrice += 1;
		}
	}
	totalPrice += addOnPrice;

	//display the final price in the text box
	document.getElementById("CalculatedPriceText").value = "$" + totalPrice;	
}

function validateNumericInput(e)
{
	var keybDecimal = "01234567890.";
	for(var i = 0;i < keybDecimal.length;i++)
	{
		if(e.keyCode)
		{
			if(e.keyCode == keybDecimal.charCodeAt(i)) 
			{
				return true;
			}
		}
		else if(e.which)
		{
			if(e.which == keybDecimal.charCodeAt(i)) 
			{
				return true;
			}
		}
		else
		{
			return true;
		}
	}
	
	return false;
}

