var currentPrices = new Hash();
function newElement(val) {
	var elmt = document.createElement('span');
	elmt.id = val;
	return elmt;
}
function getId(val) {
	if (!document.getElementById)
		return newElement(val);
	var fld = document.getElementById(val);
	if (fld)
		return fld;
	return newElement(val);
}
function updatePrices(fieldName, val) {
	var selectedItem = productOptions.get('priceDeltas').get(fieldName).get(val);
	var valValue = parseInt(val);
	var options = productOptions.get('priceDeltas').get(fieldName);
	options.each(
		function(n) {
			var useValue = "";
			var itemValue = parseInt(n.value.get('num'));
			if (itemValue < valValue) {
				useValue = '[Subtract $' + (selectedItem.get('price') - n.value.get('price')) + ']';
			} else if (itemValue == valValue) {
				useValue = "[Included]";
				$(fieldName + "_" + val).checked = true;
			} else {
				useValue = "[Add $" + (n.value.get('price') - selectedItem.get('price')) + "]";
			}
			var elem = $(n.value.get('id'));
			elem.innerHTML = useValue;
		}
	)
	if ($('specs_' + fieldName + '_amount'))
		$('specs_' + fieldName + '_amount').update(selectedItem.get('amount'));
	currentPrices.set(fieldName, parseInt(selectedItem.get('price')));
	updateTotals();
}
function updateTotals() {
	var total = 0;
	currentPrices.each(
		function(n) {
			total += parseInt(currentPrices.get(n.key));
		}
	);
	var grandTotal = parseInt(productOptions.get('basePrice')) + parseInt(total);
	$('monthly_price').update(grandTotal + ".00");
	$('quarterly_price').update((grandTotal * 3) + ".00");
	$('biannual_price').update((grandTotal * 6) + ".00");
	$('annual_price').update((grandTotal * 12) + ".00");
	document.forms.cart1.price.value = grandTotal;
}
function adjustServerSize(val) {
	updatePrices('server_size', val);
}
function adjustPowerRequirements(val) {
	updatePrices('power_requirements', val);
}
function adjustAdditionalPower(val) {
	updatePrices('additional_power', val);
}
function adjustInternetConnections(val) {
	updatePrices('internet_connections', val);
}
function adjustCappedBandwidth(val) {
	updatePrices('capped_bandwidth', val);
}
function adjustIPAddresses(val) {
	updatePrices('ip_addresses', val);
}
function adjustDdosProtection(val) {
	updatePrices('ddos_protection', val);
}
function adjustFirewallProtection(val) {
	updatePrices('firewall_protection', val);
}
function adjustHandsOnDemand(val) {
	updatePrices('hands_on_demand', val);
}
function adjustNetworkView(val) {
	updatePrices('network_view', val);
}
function adjustDataback(val) {
	updatePrices('databack', val);
}
function onBodyLoad() {
	adjustServerSize(0);
	adjustPowerRequirements(0);
	adjustAdditionalPower(0);
	adjustInternetConnections(0);
	adjustCappedBandwidth(0);
	adjustIPAddresses(0);
	adjustDdosProtection(0);
	adjustFirewallProtection(0);
	adjustHandsOnDemand(0);
	adjustNetworkView(0);
	adjustDataback(0);
}
var productOptions = new Hash();
productOptions.set('priceDeltas', 
	new Hash({
		'server_size' : new Hash({ 0 : new Hash({'id' : 'server_size_price_0', 'amount' : '1U', 'num' : 0, 'price' : 150.00}), 1 : new Hash({'id' : 'server_size_price_1', 'amount' : '2U', 'num' : 1, 'price' : 200.00}), 2 : new Hash({'id' : 'server_size_price_2', 'amount' : '3U', 'num' : 2, 'price' : 250.00}), 3 : new Hash({'id' : 'server_size_price_3', 'amount' : '4U', 'num' : 3, 'price' : 300.00}), 4 : new Hash({'id' : 'server_size_price_4', 'amount' : '5U', 'num' : 4, 'price' : 350.00}), 5 : new Hash({'id' : 'server_size_price_5', 'amount' : '6U', 'num' : 5, 'price' : 400.00}), 6 : new Hash({'id' : 'server_size_price_6', 'amount' : '7U', 'num' : 6, 'price' : 450.00 })}),
		'power_requirements' : new Hash({0 : new Hash({'id' : 'power_requirements_price_0', 'amount' : '110V', 'num' : 0, 'price' : 0.00}), 1 : new Hash({'id' : 'power_requirements_price_1', 'amount' : '208V', 'num' : 1, 'price' : 0.00}),2 : new Hash({'id' : 'power_requirements_price_2', 'amount' : '220V', 'num' : 2, 'price' : 0.00})}),
		'additional_power' : new Hash({0 : new Hash({'id' : 'additional_power_price_0', 'amount' : 'None', 'num' : 0, 'price' : 0.00}),1 : new Hash({'id' : 'additional_power_price_1', 'amount' : '2nd Power Supply Connection', 'num' : 1, 'price' : 20.00}),2 : new Hash({'id' : 'additional_power_price_2', 'amount' : '3rd Power Supply Connection', 'num' : 2, 'price' : 40.00}),3 : new Hash({'id' : 'additional_power_price_3', 'amount' : '4th Power Supply Connection', 'num' : 3, 'price' : 60.00}),4 : new Hash({'id' : 'additional_power_price_4', 'amount' : '5th Power Supply Connection', 'num' : 4, 'price' : 80.00}),5 : new Hash({'id' : 'additional_power_price_5', 'amount' : '6th Power Supply Connection', 'num' : 5, 'price' : 100.00})}),
		'internet_connections' : new Hash({0 : new Hash({'id' : 'internet_connections_price_0', 'amount' : '1 Cat5e', 'num' : 0, 'price' : 0.00}),1 : new Hash({'id' : 'internet_connections_price_1', 'amount' : '2 Cat5e', 'num' : 1, 'price' : 50.00}),2 : new Hash({'id' : 'internet_connections_price_2', 'amount' : '3 Cat5e', 'num' : 2, 'price' : 75.00}),3 : new Hash({'id' : 'internet_connections_price_3', 'amount' : '4 Cat5e', 'num' : 3, 'price' : 100.00})}),
		'capped_bandwidth' : new Hash({0 : new Hash({'id' : 'capped_bandwidth_price_0','amount' : '1 Mbps UNMETERED CAPPED','num' : 0,'price' : 0.00}),1 : new Hash({'id' : 'capped_bandwidth_price_1','amount' : '2 Mbps UNMETERED CAPPED','num' : 1,'price' : 100.00}),2 : new Hash({'id' : 'capped_bandwidth_price_2','amount' : '3 Mbps UNMETERED CAPPED','num' : 2,'price' : 200.00}),3 : new Hash({'id' : 'capped_bandwidth_price_3','amount' : '4 Mbps UNMETERED CAPPED','num' : 3,'price' : 300.00}),4 : new Hash({'id' : 'capped_bandwidth_price_4','amount' : '5 Mbps UNMETERED CAPPED','num' : 4,'price' : 400.00}),5 : new Hash({'id' : 'capped_bandwidth_price_5','amount' : '10 Mbps UNMETERED CAPPED','num' : 5,'price' : 900.00}),6 : new Hash({'id' : 'capped_bandwidth_price_6','amount' : '20 Mbps UNMETERED CAPPED','num' : 6,'price' : 1900.00}),7 : new Hash({'id' : 'capped_bandwidth_price_7','amount' : '30 Mbps UNMETERED CAPPED','num' : 7,'price' : 2900.00}),8 : new Hash({'id' : 'capped_bandwidth_price_8','amount' : '40 Mbps UNMETERED CAPPED','num' : 8,'price' : 3900.00}),9 : new Hash({'id' : 'capped_bandwidth_price_9','amount' : '50 Mbps UNMETERED CAPPED','num' : 9,'price' : 4900.00}),10 : new Hash({'id' : 'capped_bandwidth_price_10','amount' : '100 Mbps UNMETERED CAPPED','num' : 10,'price' : 9900.00})}),
		'ip_addresses' : new Hash({0 : new Hash({'id' : 'ip_addresses_price_0','amount' : '1 Block (5 usable)','num' : 0,'price' : 0.00}),1 : new Hash({'id' : 'ip_addresses_price_1','amount' : '2 Blocks (13 usable)','num' : 1,'price' : 16.00}),2 : new Hash({'id' : 'ip_addresses_price_2','amount' : '3 Blocks (21 usable)','num' : 2,'price' : 32.00}),3 : new Hash({'id' : 'ip_addresses_price_3','amount' : '4 Blocks (29 usable)','num' : 3,'price' : 48.00}),4 : new Hash({'id' : 'ip_addresses_price_4','amount' : '5 Blocks (37 usable)','num' : 4,'price' : 64.00}),5 : new Hash({'id' : 'ip_addresses_price_5','amount' : '6 Blocks (45 usable)','num' : 5,'price' : 80.00})}),
		'ddos_protection' : new Hash({0 : new Hash({'id' : 'ddos_protection_price_0','amount' : 'None','num' : 0,'price' : 0.00}),1 : new Hash({'id' : 'ddos_protection_price_1','amount' : 'RioRay VLAN DDoS Protection','num' : 1,'price' : 50.00})}),
		'firewall_protection' : new Hash({0 : new Hash({'id' : 'firewall_protection_price_0','amount' : 'None','num' : 0,'price' : 0.00}),1 : new Hash({'id' : 'firewall_protection_price_1','amount' : 'Dolphini Firewall (shared manged firewall)','num' : 1,'price' : 50.00}),2 : new Hash({'id' : 'firewall_protection_price_2','amount' : 'Cisco PIX 501 Hardware Firewall (unmanaged dedicated firewall)','num' : 2,'price' : 50.00}),3 : new Hash({'id' : 'firewall_protection_price_3','amount' : 'Cisco PIX 501 Hardware Firewall (managed dedicated firewall)','num' : 3,'price' : 75.00})}),
		'hands_on_demand' : new Hash({0 : new Hash({'id' : 'hands_on_demand_price_0', 'amount' : 'None', 'num' : 0, 'price' : 0.00}),1 : new Hash({'id' : 'hands_on_demand_price_1', 'amount' : 'Hourly as Needed - $75.00 per hour (no up front cost - discounted rate)', 'num' : 1, 'price' : 0.00}),2 : new Hash({'id' : 'hands_on_demand_price_2', 'amount' : '3 Hours per month - $225.00 per month', 'num' : 2, 'price' : 225.00}),3 : new Hash({'id' : 'hands_on_demand_price_3', 'amount' : '5 Hours per month - $375.00 / mo', 'num' : 3, 'price' : 375.00})}),
		'network_view' : new Hash({0 : new Hash({'id' : 'network_view_price_0', 'amount' : 'None', 'num' : 0, 'price' : 0.00}),1 : new Hash({'id' : 'network_view_price_1', 'amount' : '1 Dolphini Network View License - $50.00 / mo', 'num' : 1, 'price' : 50.00})}),
		'databack' : new Hash({0 : new Hash({'id' : 'databack_price_0', 'amount' : 'None', 'num' : 0, 'price' : 0.00}),1 : new Hash({'id' : 'databack_price_1', 'amount' : '5 GB - $25.00 per month', 'num' : 1, 'price' : 25.00}),2 : new Hash({'id' : 'databack_price_2', 'amount' : '10 GB - $50.00 per month', 'num': 2, 'price' : 50.00}),3 : new Hash({'id' : 'databack_price_3', 'amount' : '20 GB - $100.00 per month', 'num': 3, 'price' : 100.00}),4 : new Hash({'id' : 'databack_price_4', 'amount' : '100 GB - $500.00 per month', 'num' : 4, 'price' : 500.00}),5 : new Hash({'id' : 'databack_price_5', 'amount' : '200 GB - $1000.00 per month', 'num' : 5, 'price' : 1000.00}),6 : new Hash({'id' : 'databack_price_6', 'amount' : '500 GB - $2500.00 per month', 'num' : 6, 'price' : 2500.00})})
	})
);