$(function() {

// Company suggest plugin
$.fn.CompanySuggest = function(options) {
  if (!options) options = {};
  if (!options.select) options.select = function(event,ui) {};
  var CWR = options.cwr+''=='undefined' ? 'NULL' : (options.cwr?'1':'0');
  $(this).autocomplete({
    html: true,
    source: function( request, response ) {
      $.ajax({
        url: BASE_URL+"/_ajx",
        dataType: "json",
        data: {cmd: 'suggest_companies', max: 20, cwr:CWR, key: request.term, industry: (options.industry?options.industry:'')},
        success: function( data ) {
          response($.map(data.results, function(item) {return {id:item.id,label: item.label,value: item.name,respond: item.respond,pending: item.pending,country: item.country,industry: item.industry}}));
          }
        });
      },
    minLength: 2,
    select:options.select,
    open: function() {},
    close: function() {}
    });
};


});

