/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function cat_box()
{
    if($('#chosen_cat').val() == '')
        return;
    
    var val = $('#chosen_cat').val();
    var split = val.split("_");

    $('#cat_id').val(split[0]);
    $('#cat_name').val(split[1]);
}

function calc_shipping()
{
    if(document.getElementById('info_form') == null)
        return;
    
    var zip_val = $('#8').val();
    $.post('store.php',
    {
        zip:zip_val,
        ajax:true,
        ajax_func:'shipping_calc'
    },
    function(data)
    {
        var json = new Object;
        json = JSON.parse(data);

        $('#ship_notice').html(json.html+'<br /><span style="color:red;">'+json.shipping_cost+'</span>');

//        if(json.dollar_amount != null)
//        {
//            $('#shipping_cost').val(json.dollar_amount);
//            alert(json.dollar_amount);
//        }
        //alert(json.dollar_amount.length);
    });
    
    
//    var zip = $('#8').val();
//    if(zip == '')
//    {
//        $('#ship_notice').html('Please enter your zip code in the box above to calculate shipping.');
//    }
//    else if(zip.length < 5)
//    {
//        $('#ship_notice').html('Please enter a valid 5 digit zip code into the box above to calculate your shipping charges.');
//    }
//    else if(zip < 50001 || zip > 69363)
//    {
//        $('#ship_notice').html('Your zip code appears to be outside of the SpeeDee delivery zones.  Your order will be shipped via Priority Mail.');
//    }
//    else
//    {
//        $('#ship_notice').html('Your order qualifies for FREE SpeeDee Delivery!');
//    }
}


  $(document).ready(function(){


    calc_shipping();
    $("#info_form").validate({

        invalidHandler: function(form, validator) {
          var errors = validator.numberOfInvalids();
          if (errors) {

            var message = errors == 1
              ? '*Please fill in all required fields.'
              : '*You missed ' + errors + ' fields. They have been highlighted';
            $("div.error span").html(message);
            $("div.error").show();
          } else {
            $("div.error").hide();
          }
        }

    });
  });


