var url="phpAjax/AjaxShoppingCart.php";

// sp_shopping_cart_table.tpl
function Cart_Updated()
{

new Ajax.Updater('sp_shopping_cart_table','phpAjax/stemplate.php?id=sp_shopping_cart_ajax', {method: 'get' });
}

function update_promocode()
{

}

function cart_set_zip()
{
var form = $('shopping_cart_estimate');
input_var=form.getInputs('text','shipzip');
itemnum=input_var[0].value
new Ajax.Updater('sp_shopping_cart_table','phpAjax/stemplate.php?id=sp_shopping_cart_table&run=shopping:shipping_estimator&arg1='+itemnum, {method: 'get'});

}

function cart_update_item(itemnum,old_count)
{
// CHECK TO SEE IF KEY FIRST

var form = $('shopping_cart_form');

input_var=form.getInputs('text','input_'+itemnum);
newcount=(input_var[0].value);
if (newcount!=parseInt(newcount)) {
	input_var[0].value=old_count;
	return;
	}
if (newcount<0) {
	input_var[0].value=old_count;
	return;
	}


// SKIP
if (newcount==old_count) return; 

	new Ajax.Updater('sp_storebuttons','phpAjax/stemplate.php?id=sp_storebuttons&run=shopping:Ajax_update_cart&arg1='+itemnum+'&arg2='+newcount, {method: 'get',onComplete: 'Cart_Updated'});

var url='phpAjax/stemplate.php?id=sp_shopping_cart_ajax&run=shopping:Ajax_update_cart&arg1='+itemnum+'&arg2='+newcount;
var tag='sp_shopping_cart_table';

new Ajax.Request(url, {
	method: 'GET',
	crossSite: true,
	onLoading: function() {
		//things to do at the start
	},
	onSuccess: function(transport) {
		//things to do when everything goes well
		notice=$(tag);
		notice.update(transport.responseText || "Server Communication Error: Try Refreshing Page");
		},
	onFailure: function(transport) {
		//things to do when we encounter a failure
		notice=$(tag);
		notice.update("Server Communication Error: Try Refreshing Page");
	}
});

}




function shopping_continue()
{
alert("Test");

return false;
}

function on_calc_code(e)
{

var key;


     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

     if(key == 13) {
	cart_set_zip();
          return false;
                }
     else
          return true;


}

function on_key_code(e,itemnum,old_count)
{
var key;


     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

     if(key == 13) {
          cart_update_item(itemnum,old_count);
          return false;
		}
     else
          return true;

}

