/*
 * autocomplete-customer.js
 *
 * used in customers/add.ctp
 *
 * Not an autocomplete anymore, updates a dialog box with similar customer names to try and stop duplicate entries.
 */



$(function() {

    $("#dialog").hide();

    /*If the user has entered 3 or more characters. Check to see if its similar to existing customers. */
    $("#customerName").change(function () {
        getSimilar();
             
    });
       
    
                    
    
    
    function getSimilar() {
        if($("#customerName").val().length >= 3) {

            $.post("/customers/similarCustomers", $("#customerName").serialize(), function(data) {
                $("#similarCustList").html(data);
            });


            $("#dialog").dialog({
                position: 'right',
                width: 400
            });
                    
        }
    }


    $("#CustomerCountryName").autocomplete({
        source: "/countries/completeCountry",
        minLength: 3,
        select: function(event, ui) {
            $("#CustomerCountryId").val(ui.item.id);

            if(ui.item.value == 'Australia') {
                $("#ABN").show();
            }
            else {
                $("#ABN").hide();
            }
        }
    });
});