// JavaScript Document
$(document).ready(function()	{

$('#tariff_form').submit(function(event){
    event.preventDefault();  // stop the form from submitting and refreshing the page
    var form = this;               // in jQuery, this refers to the current element, which is #article_form

    // grab each form value
    var data = {};
    gallons = $('#id_gallons').val();
    tariff = $('#id_tariff').val();

    //alert(gallons);
    
    // now send the data to the server via AJAX
    if(gallons && tariff)
    {
        $.ajax({
            type: "POST",
            url: "/tariff-calculator/",
            data: "gallons="+gallons+"&tariff="+tariff,
            dataType: "json",
            success: function(json){
                $('#gallons_cont').html(json['gallons']);
                $('#area_cont').html(json['area']);
                $('#usage_cont').html(json['usage']);
                $('#results_json').show('slow');            
            }
            });
    }
    else
    {
        alert('Please Fill All Fields');
    }
});	
	
});