$(function() {
	
    // add copy_address checkbox
    var copy_address = $('#id_copy_address')
    var table = $('#shipping-address table')
    copy_address.change(function() {
        if ($(this).fieldValue() == 'on') {
            table.hide()
        } else {
            table.show()
        }
    })
    copy_address.change()
    // check checkbox if billing and shipping address are equal
    if ($('#id_addressee').fieldValue()[0] == $('#id_ship_addressee').fieldValue()[0]
            && $('#id_street1').fieldValue()[0] == $('#id_ship_street1').fieldValue()[0]
            && $('#id_street_number').fieldValue()[0] == $('#id_ship_street_number').fieldValue()[0]
            && $('#id_postal_code').fieldValue()[0] == $('#id_ship_postal_code').fieldValue()[0]
            && $('#id_city').fieldValue()[0] == $('#id_ship_city').fieldValue()[0]) {
        copy_address.attr('checked', true)
        table.hide()
    }
    
	// Pre-fill shipping address
	var addr_sel = $("#id_addressee")
	var fn_sel = $("#id_first_name")
	var ln_sel = $("#id_last_name")
	if (addr_sel.val() == null || addr_sel.val() == "") {
	    addr_sel.attr({
		    value: fn_sel.val() + " " + ln_sel.val()
		});
	}

    // remove text from submit button
    $('input.button-weiter').attr('value', '')
    $('input.button-bestellung-fertigstellen').attr('value', '')
})

