// JavaScript Document
$(document).ready(function () {
    var shippingcountryID = $('#shippingCountryID').val();
    var shippingstateID = $('#shippingstatehidValue').val();
    listshippingStates(shippingcountryID, shippingstateID);
});

function listshippingStates(shippingcountryID, shippingstateID) {
    $('#shippingstatehidValue').val(shippingstateID);
    if (shippingcountryID != '') {
        var data = {
            "shippingcountryID": shippingcountryID,
            "shippingstateID": shippingstateID
        };
        $.ajax({
            type: "POST",
            url: GLOBAL_BASE_PATH + "/user/shippingstatesAjax/",
            data: data,
            beforeSend: function () {
                $("#loadProcessImage1").append('<img src="' + GLOBAL_ROOT_PATH + '/public/default/manage/standard/images/ajax-loader.gif" id="loading_gif2"  />');
            },
            success: function (msg) {
                $("#loadProcessImage1").empty();
                var data = $.trim(msg);
                if (data != '') {
                    $("#shippingstateInput").show();
                    $('#shippingstateID').empty();
                    $("#shippingstateProvinceInput").hide();
                    $("#shippingstateID").append('<option value="">Select</option>' + msg);
                    $("#shippingStateSelectedType").val("state");
                    $('#shippingProvince').val('');
                    $("#div_err_frmBusiness_provincehidden").css("display", "none");
                } else if (data == '') {
                    $("#shippingstateInput").hide();
                    $("#shippingstateProvinceInput").show();
                    $('#shippingstateID').val(0);
                    $("#shippingStateSelectedType").val("province");
                    $("#div_err_frmBusiness_provincehidden").css("display", "none");
                }
            }
        });
    }
}

function getshippingStateHiddenValue(val) {
    $('#shippingstatehidValue').val(val);
}
$(document).ready(function () {
    var addForm = $(".addnewAddressForm").html();
    $(".addnewAddressForm").remove();
    $('.panelmenu a[rel=shipping]').addClass('active');
    $(".addnewAddress").click(function () {
        var position = $(".addnewAddressFormNew").position();
        scroll(0, position.top);
        $(".controller").hide();
        $("#formUserShippingEdit").remove()
        $(".addnewAddressFormNew").html(addForm);
        $("#submit").val(lblSave);
    });
    $(document).on('click', ".formAddCancel", function () {
        $("#formUserShippingEdit").remove();
        $(".controller").show();
    });
    $(".editAddress").click(function () {
        $(".controller").hide();
        $("#formUserShippingEdit").remove();
        $(this).closest('li').find('.editForm').html(addForm);
        var data = address[$(this).attr('rel')];
        $("#userID").val(data.userID);
        $("#shippingstatehidValue").val(data.shippingStateID);
        $("#userShippingID").val(data.userShippingID);
        $("#shippingFname").val(data.shippingFname);
        $("#shippingLname").val(data.shippingLname);
        $("#shippingAddress1").val(data.shippingAddress1);
        $("#shippingAddress2").val(data.shippingAddress2);
        $("#shippingCity").val(data.shippingCity);
        $("#shippingProvince").val(data.shippingProvince);
        $("#shippingZip").val(data.shippingZip);
        $("#shippingCountryID").val(data.shippingCountryID);
        listshippingStates(data.shippingCountryID, data.shippingStateID);
        $("#submit").val(lblUpdate);
        if (data.addressPrimary == 'Yes') {
            $("#makeAddressAsPrimary").prop('checked' ,true);
        } else {
            $("#makeAddressAsPrimary").prop('checked',false);
        }
    });
    $(".makePrimaryRadio").click(function () {
        var data = new Object();
        data.userShippingID = $(this).val();
        $.ajax({
            type: "POST",
            data: data,
            url: GLOBAL_BASE_PATH + "/user/changeAddressStatus/",
            success: function (data) {}
        });
    });
});