new WOW().init(); 

$(".packagebox").click(function () {
    $(".packagebox").removeClass("packageactive");
    var qty = $(this).data("id");
    var cid = $(this).data("camp");
    var price = $(this).data("price");
    $(this).addClass("packageactive");
    $("#campId").val(cid);
    $("#upsellQty").val(qty);
    $('.spn-qty').text(qty);
    $('.font-price').text('$'+price);
    //$(".packageprice").text('$'+price);
    $(".spn-sub-total").text(price);
    $(".spn-total-price").text(price);
    console.log(cid+':'+qty+':'+price);
});

$('body').on("click",'[name=billing]', function () {
    if($(this).prop('checked') === true){
        $('input[name=billingSameAsShipping]').val('yes');
        $('input[name=billingSameAsShipping]').trigger('change');
        $('.billing-info').slideUp("slow");
    }else{
        $('input[name=billingSameAsShipping]').val('no');
        $('input[name=billingSameAsShipping]').trigger('change');
        $('.billing-info').slideDown("slow");
    }
});

$('body').on("click",'[name=protection-check]', function() {
    if($(this).prop('checked')){
        $('#upsellId').val('4');
    }
    else{
        $("#upsellId").val('');
    }
});

$('#complete-order').off('click');
$('#complete-order').click(function(e){
    cb.beforeFormSubmitEvents.push(function(e){
        form_submit();
        /*if($('[name=protection-check]').prop('checked')==true)
        {
            //form_submit();
            $('#express-Modal').modal('show');
            $('#express-Modal').modal({backdrop: 'static', keyboard: false});
        }
        else
        {
            $('#protection-Modal').modal('show');
            $('#protection-Modal').modal({backdrop: 'static', keyboard: false});  
        }*/
    });
});

$('#accept-express').click(function(){
    $('#expId').val('6');
    form_submit()
});

$('#decline-express').click(function(){
    $("#expId").val('');
    form_submit();    
});

$('#accept-protection').click(function(){
    $('#upsellId').val('5');
    $('#protection-Modal').modal('hide');    
    $('#express-Modal').modal('show');
});

$('#decline-protection').click(function(){
    $("#upsellId").val('');
    $('#protection-Modal').modal('hide');
    $('#express-Modal').modal('show');     
});

function form_submit()
{
    $('#loading-indicator').show();
    $.ajax({
        url: AJAX_PATH + 'checkout',
        method: 'post',
        data: $('[name=checkout_form]').serialize()
    }).success(function(data) {
        console.log(data);
        if (data.success) {
            window.location.href = data.redirect;
        } else {
            $('#loading-indicator').hide();
            $('#protection-Modal').modal('hide');
            $('#express-Modal').modal('hide');
            cb.errorHandler(data.errors);
        }
    });
}