var init=function(countriesUrl, discountUrl) {
    // select all desired input fields and attach tooltips to them
    $('label.hint').labelOver('over');

    $(".errorInField").tooltip({
        position: "center right",
        offset: [-2, 10],
        effect: "fade",
        relative: true,
        opacity: 0.9
    });
    $("#vat").tooltip({
        position: "center right",
        offset: [-2, 10],
        effect: "fade",
        opacity: 0.9,
        tip: '.vat_tooltip'
    });
    $("#remarks").tooltip({
        position: "center right",
        offset: [-2, 10],
        effect: "fade",
        opacity: 0.9,
        tip: '.remarks_tooltip'
    });
    $("#discount_code").tooltip({
        position: "center right",
        offset: [-2, 10],
        effect: "fade",
        opacity: 0.9,
        tip: '.discount_tooltip'
    });
    $("#acceptRefund, #acceptRefund label, #acceptRefund input").tooltip({
        position: "top right",
        offset: [-2, 10],
        effect: "fade",
        opacity: 0.9,
        tip: '.refund_tooltip'
    });

    $("#invoiceMainContact").click(function(event) {
        if (event.target.checked) {
            $("#invoiceContact").slideUp()
        } else {
            $("#invoiceContact").slideDown()

        }
    });

    $('#acceptRefundCheck').click(function() {
        var checked_status=this.checked;
        if (checked_status == true) {
            $("#registerMe").removeAttr("disabled");
        }
        else {
            $("#registerMe").attr("disabled", "disabled");
        }
    });

    $('#registerMe').attr('disabled', 'disabled')
    var search_timeout=undefined;

    $("input[title='Country']").autoComplete({ajax: countriesUrl});
    $('input#discount_code').keyup(function() {
        if (search_timeout) {
            clearTimeout(search_timeout);
        }
        var $this=this; // save reference to 'this' so we can use it intimeout function
        search_timeout=setTimeout(function() {
            search_timeout=undefined;

            $.getJSON(discountUrl, {code: $($this).val()}, function(data) {
                $('#prices').html(data.table)
                $('#discount\\.id').val(data.discount.id)
            })
        }, 500);
    });

}