	//	Texas Sensations
	//	/js/ts.js
	
	function add_to_cart (product_id)
	{
		var rand			=	Math.floor(Math.random()*9999999999999);
		var product_qty		=	$('item_qty_' + product_id).value;
		var div_pricebox	=	'product_pricebox_' + product_id;
		
		var ajax_uri		=	'/ajax'
		var ajax_pars		=	'do=add_to_cart&id=' + product_id + '&qty=' + product_qty + '&ts=' + rand;
			
		Element.hide(div_pricebox);
		
		var ajax_request	=	new Ajax.Request(ajax_uri, {method: 'get', parameters: ajax_pars, onComplete: add_to_cart__complete});
	}
	
	function add_to_cart__complete (response)
	{
		var xml				=	xml_dom(response.responseText);
		var xml_root		=	xml.getElementsByTagName('ajax_response')[0];
		
		var product_id		=	xml_root.getElementsByTagName('id')[0].firstChild.nodeValue;
		var msg				=	xml_root.getElementsByTagName('msg')[0].firstChild.nodeValue;
		
		var div_pricebox	=	'product_pricebox_' + product_id;
		
		Element.update(div_pricebox,msg);
		Effect.Appear(div_pricebox);
	}
	
	function remove_from_cart (cart_id)
	{
		var rand			=	Math.floor(Math.random()*9999999999999);
		
		var ajax_uri		=	'/ajax'
		var ajax_pars		=	'do=remove_from_cart&id=' + cart_id + '&ts=' + rand;
			
		var ajax_request	=	new Ajax.Request(ajax_uri, {method: 'get', parameters: ajax_pars, onComplete: remove_from_cart__complete});
	}
	
	function remove_from_cart__complete (response)
	{
		var xml				=	xml_dom(response.responseText);
		var xml_root		=	xml.getElementsByTagName('ajax_response')[0];
		
		var status			=	xml_root.getElementsByTagName('status')[0].firstChild.nodeValue;
		
		if (status == 1)
			{
				document.location	=	'/cart';
			}
	}
	
	function update_qty (cart_id)
	{
		var rand			=	Math.floor(Math.random()*9999999999999);
		var product_qty		=	$('item_qty_' + cart_id).value;
		var ajax_uri		=	'/ajax'
		var ajax_pars		=	'do=update_qty&id=' + cart_id + '&qty=' + product_qty + '&ts=' + rand;
		
		var ajax_request	=	new Ajax.Request(ajax_uri, {method: 'get', parameters: ajax_pars, onComplete: update_qty__complete});
	}
	
	function update_qty__complete (response)
	{
		var xml				=	xml_dom(response.responseText);
		var xml_root		=	xml.getElementsByTagName('ajax_response')[0];
		
		var status			=	xml_root.getElementsByTagName('status')[0].firstChild.nodeValue;
		
		if (status == 1)
			{
				document.location	=	'/cart';
			}
	}
	
	function checkout ()	
	{
		var rand			=	Math.floor(Math.random()*9999999999999);
		var ajax_uri		=	'/ajax?do=checkout'
		var ajax_pars		=	'in_cart=' + $('in_cart').value + '&cc_name=' + $('cc_name').value + '&cc_num=' + $('cc_num').value + '&cc_exp=' + $('cc_exp').value + '&b_address_line1=' + $('b_address_line1').value + '&b_address_line2=' + $('b_address_line2').value + '&b_city=' + $('b_city').value + '&b_state=' + $('b_state').value + '&b_zipcode=' + $('b_zipcode').value + '&receivers_name=' + $('receivers_name').value + '&s_address_line1=' + $('s_address_line1').value + '&s_address_line2=' + $('s_address_line2').value + '&s_city=' + $('s_city').value + '&s_state=' + $('s_state').value + '&s_zipcode=' + $('s_zipcode').value + '&email=' + $('email').value + '&phone=' + $('phone').value + '&ts=' + rand;
		
		var ajax_request	=	new Ajax.Request(ajax_uri, {method: 'post', parameters: ajax_pars, onComplete: checkout__complete});
	}
	
	function checkout__complete (response)
	{
		var xml				=	xml_dom(response.responseText);
		var xml_root		=	xml.getElementsByTagName('ajax_response')[0];
		
		var error			=	xml_root.getElementsByTagName('error')[0].firstChild.nodeValue;
		var error_header	=	xml_root.getElementsByTagName('error_header')[0].firstChild.nodeValue;
		var error_msg		=	xml_root.getElementsByTagName('error_msg')[0].firstChild.nodeValue;
		var key				=	xml_root.getElementsByTagName('key')[0].firstChild.nodeValue;
		
		if (error > 0)
			{
				Element.update('cart_error_header',error_header);
				Element.update('cart_error_msg',error_msg);
				Effect.Appear('cart_error');
			}
		if (error == 0)
			{
				document.location	=	'/order_details?key=' + key + '&redirect=1';
			}
	}
	
	function set_zipcode ()
	{
		var zipcode			=	$('zipcode').value;
		document.location	=	'/cart?zipcode=' + zipcode;
	}
	
	function xml_dom (data)
	{
		return Try.these
			(
				function() {var xmldom = (new DOMParser()).parseFromString(data,"text/xml"); return xmldom;},
				function() {var xmldom = new ActiveXObject('Microsoft.XMLDOM'); xmldom.loadXML(data); return xmldom;}
			);
	}
