var CheckoutHandler =
{
	'SubmitForm' : function( params )
	{		
		var form = document.getElementById('checkoutForm');
		for (var property in params)
		{
			var newHidden = document.createElement('INPUT');
			newHidden.type = 'hidden';
			newHidden.name = property;
			newHidden.value = params[property];
			form.appendChild(newHidden);
		}
		form.submit();
	},
	'ConfirmDelete' : function( id )
	{
		if (confirm('Are you sure you want to remove this item from your shopping cart?'))
		{
			document.getElementById(id+'_qty').value = 0;
			CheckoutHandler.SubmitForm();
		}
	},
	'ConfirmCoupon' : function()
	{
		if (confirm('Are you sure you do not want to use this coupon?'))
		{
			CheckoutHandler.SubmitForm({ 'removeCoupon' : 1 });
		}
	},
	'SwitchShipping' : function( obj )
	{
		var priceNode = document.getElementById('price');
		
		if (!priceNode)
		{
			return;
		}
		
		var price = new Number(priceNode.firstChild.data);
		
		var shippingPriceNode = document.getElementById('shippingPrice');
		var newPriceString = obj.nextSibling.firstChild.innerHTML;
		
		var index = newPriceString.indexOf('$');
		var newPrice = new Number(newPriceString.substr(index+1));
		
		price -= new Number(shippingPriceNode.value);
		
		var couponValue = document.getElementById('couponDiscount').value;
		if (couponValue.indexOf('$') > -1)
		{
			price += new Number(couponValue.substr(1));
		}
		else if (couponValue.indexOf('%') > -1)
		{
			price *= 100/(new Number(couponValue.substr(1)));
		}
		
		if (couponValue.indexOf('$') > -1)
		{
			price -= new Number(couponValue.substr(1));
		}
		else if (couponValue.indexOf('%') > -1)
		{
			price *= (new Number(couponValue.substr(1)))/100;
		}
		
		price = price + newPrice;
		
		priceNode.firstChild.data = price.toFixed(2);
		shippingPriceNode.value = newPrice;
	},
	'ViewPrinterVersion' : function()
	{
		var receipt = document.getElementById('receipt');
		if (!receipt)
		{
			return false;
		}
		
		var newWindow = window.open("", "newWindow", "width=750,height=700,menubar=1,scrollbars=1");
		newWindow.document.open("text/html","replace");
		newWindow.document.write("<HTML><HEAD><STYLE TYPE='text/css'>.inline { display:inline-block;vertical-align:top;}</STYLE></HEAD><BODY>Beliza Design<br/><br/>" + receipt.innerHTML + "</BODY></HTML>");
		newWindow.document.close();
	}
};

var PaymentHandler = 
{
	'SelectNewCC' : function()
	{
		document.getElementById('past_cc_info').style.display = 'none';
		document.getElementById('new_cc_info').style.display = '';
	},
	'SelectPastCC' : function()
	{
		document.getElementById('past_cc_info').style.display = '';
		document.getElementById('new_cc_info').style.display = 'none';
	}
};

