/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


function updateTotal( key ) {
    
    var quantity = parseInt( $("#quantity_" + key).val() );
    if ( !quantity || quantity < 0 ) {
        if ( quantity < 0 ) {
            $("#quantity_" + key).val( 1 );
        }
        quantity = 1;
    }
        
    var price = parseFloat( $("#price_" + key).text().replace( "$", "") );
    var total = Math.round( quantity * price * 100 ) / 100;
    
    $("#total_" + key).text("$" + total.toFixed( 2 ));
    
    var total_price = 0;
    $('td>div[id^="total_"]').each(function() {
        
        total_price += parseFloat( $(this).text().replace( "$", "") );
        
    });
    
    
    $("#price_total").text("Total: $" + total_price.toFixed( 2 ));
    
    cart_total = total_price;
    sub_total();
    billing_tax();
    order_total();
  
}

function updateQuantity( key ) {
    
    var quantity = parseInt( $("#quantity_" + key).val() );
    
    
    $.ajax({
        url: 'shopping_cart_ajax.php?key=' + key + '&quantity=' + quantity,
        success: function( data ) {
            if( data != quantity) {
                alert("Minimum quantity for selected item is: " + data + ". Shopping cart was automatically adjusted.");
            }
            
            $("#quantity_" + key).val(data);
            
        }
});
    
}


