function buy(item, amount)
{
	$.ajax({ 
		url: "ajax.aspx", 
		cache: false,
		data: "buy=" + item + "&amount=" + amount,
		success: function (data) {
			$('#cart').html(data);
			$('.cost').fadeIn(150).delay(1500).animate( { opacity: 0, top : '-=100' }, 750, 'swing' );
			getcart();
		}
	});
	
}

function remove(item)
{
	$.ajax({ 
		url: "ajax.aspx", 
		cache: false,
		data: "remove=" + item,
		success: function (data) {
			$('#content').html(data);
		}
	});
}

function getcart()
{
	//$('#outer_content').css( { height: $('#content').height() } );
	$.ajax({
		url : 'ajax.aspx',
		cache: false,
		data : "cart=true",
		success: function (data) {
			window.location.hash = "#cart";
			$('#content').html(data);
			/*
			if($('#content').innerHeight() < $('#outer_content').innerHeight())
				$('#outer_content').animate( { height: $('#content').height() }, 300, 'swing' );
			else
				$('#outer_content').css( { height: $('#content').height() } );
			*/
		}
	});
}

function orderit()
{
	order_data = 'orderit=true&' + prepareForm('.order_detail');
	
	$.ajax({
		type : 'POST',
		url : 'ajax.aspx',
		cache: false,
		data : order_data,
		success: function (data) {
			$('#content').html(data);
			//$('#outer_content').animate( { height: $('#content').height() }, 300, 'swing' );
		},
		error: function(o,s,e){
			alert('' + o + s + e);
		}
	});
	return false;
}

function payWithPayson(url)
{
    document.forms[0].action = url;
    $('input:not(.paysonField)').remove();    
}

function payWithPaypal(url)
{
    document.forms[0].action = url;
    $('input:not(.paypalField)').remove();    
}

function prepareForm(selector) {
    data = "";
    elements = $(selector);
    for (var i = 0; i < elements.length; i++) {
        el = elements[i];
        name = el.name;
        
        value = $(el).val();
        if (value != null && value != "undefined")
            value = $.trim(value + ""); //added "" to fix IE 6 bug for empty select     
        if (el.type == "checkbox")
            value = el.checked ? $(el).val() : "";
        else if (el.type == "radio" && !el.checked)
            value = "";
        if (!(value == "" || value == "undefined" || name == "" || name == "undefined"))
            data += "&" + name + "=" + value;
    }

    return data;
}
