<!-- BEGIN autosuggest.tt -->
    [% # PROCESS site/js/jquery.tt # already loaded in html_wrapper %]
	
	[% UNLESS no_autosuggest_js # in case 2nd call on page %]
    <!-- Loading AutoSuggest js -->
		<script type="text/javascript" src="/js/bsn.AutoSuggest.jQuery.js"></script>
		<script type="text/javascript" src="/js/jquery.watermarkinput.js"></script>
	[% END %]

    [% # set defaults - overridden if necessary:
        DEFAULT varname     = 'location';
        DEFAULT param_id    = 'source_id';
        DEFAULT param_name  = 'location_name';
        DEFAULT method_name = 'get_referral_sources';
        IF optional_params; # MUST end in semi-colon to allow separation from 'varname=foo':
            formatted_params = optional_params.join(';') _ ';'; # can handle array of params
        END;
    %]
    
    <!-- Init autosuggest on Search Input -->
    <script type="text/javascript">
        jQuery( function() {
            // Set autosuggest options
            var options = {
                script:"[% app_url %]/ajax/[% method_name %]?[% formatted_params %]",
                varname:"[% varname %]",
                json:false,						// Returned response type
                shownoresults:true,				// If disable, display nothing if no results
                noresults:"No results found",   // String displayed when no results
                maxresults:10,					// Max num results displayed
                cache:false,					// To enable cache
                minchars:2,						// Start AJAX request with at least x chars
                timeout:10000,					// AutoHide in XX ms
                callback: function (obj) { 	    // Callback after click or selection
                    $('#[% param_id %]').val(obj.id);
                }
            };
            // Init autosuggest
            var as_xml = new bsn.AutoSuggest('[% param_name %]', options);
            [% UNLESS watermark == 'no' %]
			// Display watermark
                $("#[% param_name %]").Watermark("ex : Calderdale, Highfield Surgery...");
            [% END %]
		} );
    </script>
<!-- END autosuggest.tt -->
