(function(){
	var AuctionPurchase_Process = function() {
    return {

    	init: function() {

            $('#wallet-btn').on('click', function(e){
                if(copyFields()) {
                    //copyFields()
                    form = $('#process-form');
                    form.find('input[name="process_type"]').val('wallet');
                    form.submit();
                }
			});

            $('#giftcard-btn').on('click', function(e){
               if(copyFields()) {
                    //copyFields()
                    form = $('#process-form');
                    form.find('input[name="process_type"]').val('giftcard');
                    form.submit();
                }
            });
		}
    };
  }();

	$(document).ready(function() {
        /*$('#toogle-collapse').collapse({
            toggle: false
        });*/
        AuctionPurchase_Process.init();
	});

})();

function copyFields()
{
    var content = $('#shipping-container');

    var first_name = content.find('input[name="first_name"]').val();
    var middle_name = content.find('input[name="middle_name"]').val();
    var last_name = content.find('input[name="last_name"]').val();
    var country = content.find('select[name="country"]').val();
    var zip = content.find('input[name="zip"]').val();
    var state = content.find('input[name="state"]').val();
    var city = content.find('input[name="city"]').val();
    var address = content.find('input[name="address"]').val();
    var phone = content.find('input[name="phone"]').val();
    var comment = content.find('textarea[name="comment"]').val();

    /*if(
        first_name != '' &&
        last_name != '' &&
        country != '' &&
        zip != '' &&
        city != '' &&
        address != '' &&
        phone != ''
    ){*/

        var form = $('#process-form');
        form.find('input[name="form_first_name"]').val(first_name);
        form.find('input[name="form_middle_name"]').val(middle_name);
        form.find('input[name="form_last_name"]').val(last_name);
        form.find('input[name="form_country"]').val(country);
        form.find('input[name="form_zip"]').val(zip);
        form.find('input[name="form_state"]').val(state);
        form.find('input[name="form_city"]').val(city);
        form.find('input[name="form_address"]').val(address);
        form.find('input[name="form_phone"]').val(phone);
        form.find('input[name="form_comment"]').val(comment);
        return true;
    /*}
    else{
        $('#toogle-collapse').collapse({
            toggle: true
        });
        return false;
    }*/
}
