PageSourceSearch

https://www.austinonline.us/Scripts/Local/GlobalSearch/UsaNewSearch_V1.js

js austinonline.us collected 2026-10-08 16:19:13 UTC 42,604 bytes, 1,019 lines download raw bytes

1
2
3var currentAssistance = [];
4var FocusedTextBoxObj;
5var w = 0;
6var SearchFlag = 0;
7var Flag2FirstPosition = -1;
8//$('[data-searchterm="catcom"]').autocomplete({
9
10$(function () {
11
12    /// hide mic for that browser not supported SpeechRecognition
13    if (window.hasOwnProperty('webkitSpeechRecognition')) { }
14    else {
15        $('[data-id="micicon"]').hide();
16    }
17
18    /// stop page load
19    $('[data-attr="takingucancel"]').on('click', function () {
20        window.stop();
21    });
22
23
24    // HighLightSearchOverRide();
25    $('body').click(function (e) {
26        // $('.ui-autocomplete').hide('');
27        // console.log(e.target);
28        var ClickedObject = $(e.target);
29        if (!ClickedObject.attr('data-searchterm')) {
30            var HintObj = $('.msg');
31            if (HintObj.is(':visible'))
32                HintObj.hide();
33        }
34
35    });
36
37    $('[data-searchterm="catcom"]').on('focus', function (e) {
38        FocusedTextBoxObj = $(this);
39    });
40    $('[data-searchterm="zipcity"]').on('focus', function (e) {
41        FocusedTextBoxObj = $(this);
42    });
43
44    $('[data-searchterm="catcom"]').on('keypress', function (e) {
45        if ($('[data-id="hdn_IsVoice"]').length > 0) {
46            $('[data-id="hdn_IsVoice"]').remove();
47        }
48        var HintObj = $('.msg');
49        if (HintObj.is(':visible'))
50            HintObj.hide();
51
52        var TargetContainerObjValue = $(this).parents('[data-target]').attr('data-target');
53        var TargetContainerObj = $(this).parents('[data-target="' + TargetContainerObjValue + '"]'); /// find the main div that holds search partial
54
55        if (e.keyCode != 13) {
56            var hdnfieldobj = TargetContainerObj.find('[data-id="hdn_autocompleteCompanyCatUrlFlag"]');
57            if ($(hdnfieldobj).length > 0) {
58                $(hdnfieldobj).remove();
59            }
60        }
61
62        /// jump cursor to next textbox when user type 'in' and have space after that
63        if (e.keyCode == 32) {
64            var WordHolder = [];
65            WordHolder = $(this).val().split(' ');
66            if ($.inArray('in', WordHolder) > 0) {
67                TargetContainerObj.find('[data-searchterm="zipcity"]').focus();
68                return false;
69                //   $(this).next('input').focus();
70            }
71
72        }
73
74
75    });
76
77    $('[data-searchterm="zipcity"]').on('keydown', function (e) {
78        // console.log('class ' + e.keyCode + '; len: ' + e.key.length);
79        if (e.key.length > 1 && (e.keyCode != 46 && e.keyCode != 8))
80            return;
81
82        if ($('[data-id="hdn_IsVoice"]').length > 0) {
83            $('[data-id="hdn_IsVoice"]').remove();
84        }
85        var HintObj = $('.msg');
86        if (HintObj.is(':visible'))
87            HintObj.hide();
88
89        /// if category suggestion is opened close it
90        if ($('.searchbdr:visible').length > 0)
91            $('.searchbdr:visible').hide();
92
93        //// remove hidden element '[data-id="hdn_autocompleteZipCity"]'
94        if (e.keyCode != '13') {
95            var TargetContainer = $(this).parents('[data-target]');
96            $(TargetContainer).find('[data-id="hdn_autocompleteZipCity"]').val('');
97            $(TargetContainer).find('[data-id="hdn_autocompletecityid"]').val('');
98        }
99
100    });
101
102    $('[data-searchterm="catcom"]').autocomplete({
103        open: function () {
104            var width = $(this).css('width');
105            $(this).autocomplete("widget").addClass('searchbdr');
106            // $(this).autocomplete("widget").css({ 'width': '100%', 'max-width': width });
107
108            //$(this).autocomplete("widget").css({ 'width': '300px' });
109
110            var TargetContainerObjValue = $(this).parents('[data-target]').attr('data-target');
111            var TargetContainerObj = $(this).parents('[data-target="' + TargetContainerObjValue + '"]'); /// find the main div that holds search partial
112            var hdnfieldobj = TargetContainerObj.find('[data-id="hdn_autocompleteCompanyCatUrlFlag"]');
113            if (TargetContainerObjValue == 'input2') {
114                console.log('input: ' + TargetContainerObjValue)
115                var AutoCompleteTextObj = TargetContainerObj.find('[data-searchterm="catcom"]');
116                $(this).autocomplete("widget").css({ 'width': '300px' });
117
118            }
119            else {
120                $(this).autocomplete("widget").css({ 'width': '100%', 'max-width': width });
121            }
122
123            if ($(hdnfieldobj).length > 0) {
124                // $(hdnfieldobj).remove();
125            }
126            Flag2FirstPosition = -1;
127
128
129        },
130
131        minLength: 2,
132        delay: 500,
133        messages: {
134            noResults: ''
135            // results: function () { }
136        },
137        source: function (request, response) {
138            var TextBoxObj = $(this).attr('id');
139            ShowSearchLoader(FocusedTextBoxObj.siblings('[data-cat-img="loading"]'));
140            var Protocol = window.location.protocol;
141            var categorySuggestionURL = Protocol + '//' + location.host + '/websiteajax
141/UsaNewSearchChan/CategoryCompanyHunt';
142
143            var CityName = '';
144            var TargetContainerObj = FocusedTextBoxObj.parents('[data-target]');
145            var v = $(TargetContainerObj).find('[data-id="hdn_autocompleteZipCity"]').val();
146            
147             if (typeof v != 'undefined' && v) {
148
149                if (v != '' && v.indexOf(';') > -1) {
150                    CityName = v.split(';')[2];
151                    //console.log('=====CityName ===' + CityName);
152                }
153            }
154            /// replace 'in' word from search
155            var TheSearchTerm = '';
156            var CityId = 0;
157            if (FocusedTextBoxObj.siblings('[data-id="hdn_autocompletecityid"]').val().trim() != '') {
158                CityId = FocusedTextBoxObj.siblings('[data-id="hdn_autocompletecityid"]').val().trim();
159            }
160            else {
161                if (typeof v != 'undefined' && v) {
162                    CityId = $('[data-id="hdn_autocompleteOriginalZipCity"]').val().split(';')[3].trim();
163                }
164            }
165
166
167            var pat = /\bin\b/gi;
168            if (pat.test(request.term)) {
169                TheSearchTerm = request.term.replace(pat, '').trim();
170            }
171            else {
172                TheSearchTerm = request.term;
173            }
174
175            $.ajax({
176                url: categorySuggestionURL,
177                type: "GET",
178                data: {
179                    SearchTerm: TheSearchTerm, CityId: CityId
180                },
181                success: function (data) {
182                    //alert(data.data)
183
184
185                    if (data && data.data.length > 0) {
186                        //$('#search-category-btn').data('catname', data[0].catName);
187
188                        currentAssistance = [];
189                        //currentAssistance = ($.map(data.data, function (item) {
190                        //    return item.SearchName;
191                        //}));
192
193                        response($.map(data.data, function (item) {
194                            return {
195                                label: item.SearchName, //(item.Flag == 1) ? item.SearchName + ' (' + item.ParentCatName + ')' : item.SearchName + ' [' + item.CompanyAddress + ' ' + item.Zipcode + ']',
196                                value: item.Url + '~$' + item.Flag,
197                                ParentCatName: item.ParentCatName,
198                                CompanyAddress: item.CompanyAddress,
199                                Zipcode: item.Zipcode,
200                                Flag: item.Flag,
201                                Protocol: item.Protocol,
202                                CityName: CityName
203                            };
204                        }));
205                        // response(data.data);
206                    }
207
208
209                    else {
210                        currentAssistance = [];
211                        $('#search-category-btn').data('catname', '');
212                    }
213                    HideSearchLoader($('[data-cat-img="loading"]'));
214                },
215                error: function (a, b, c) {
216                    $('#search-category-autocomplete-loader').hide();
217                    HideSearchLoader($('[data-cat-img="loading"]'));
218                }
219            })
220        },
221        autoFocus: true,
222        focus: function (event, ui) {
223            event.preventDefault();
224            if ($('[data-id="hdn_IsVoice"]').length > 0) {
225                var CurrentTextBoxObj = event.target;
226                //setTimeout(function () {
227                //    getSelectableCategoryList(CurrentTextBoxObj, ui.item.label, ui.item.value);
228                //}, 300);
229
230                getSelectableCategoryList(CurrentTextBoxObj, ui.item.label, ui.item.value, ui.item.Protocol);
231            }
232
233
234        },
235        select: function (event, ui) {
236            event.preventDefault();
237            // console.log(event);
238            var CurrentTextBoxObj = event.target;
239            getSelectableCategoryList(CurrentTextBoxObj, ui.item.label, ui.item.value, ui.item.Protocol);
240        }
241    })
242
243
244
245    var AutoCompleteObjs = $('[data-searchterm="catcom"]');
246    $.each(AutoCompleteObjs, function (idx, itm) {
247        $(this).data("uiAutocomplete")._renderItem = function (ul, item) {
248            var BusinessHtml = '';
249            SearchFlag = item.Flag;
250            if (Flag2FirstPosition == -1 && SearchFlag == 2) /// item.Flag==2 ==>company
251            {
252                Flag2FirstPosition = w;
253                BusinessHtml = "<li class='ui-menu-item' >" + '<div class="searchlistheading"><b class="companysuggestion">' + 'Businesses in ' + item.CityName + "</div></li>";
254            }
255            BusinessHtml += "<li><a>" + ((item.Flag == 1) ? '<div class="catserch_img"><img src="https://img.usaonline.us/images/cat.png"></div>' + item.label + ((item.ParentCatName == '') ? '' : ' (' + item.ParentCatName + ')') : ((item.Flag == 0) ? item.label : '<div class="bizserch_img"><img src="https://img.usaonline.us/images/biz.png"></div><b class="companysuggestion">' + item.label + '</b>' + '<br/>' + item.CompanyAddress + ' ' + item.Zipcode)) + "</a></li>";
256
257            w++;
258            //  return $("<li><a>" + ((item.Flag == 1) ? '<div class="catserch_img"><img src="https://img.usaonline.us/images/cat.png"></div>' + item.label + ((item.ParentCatName == '') ? '' : ' (' + item.ParentCatName + ')') : ((item.Flag == 0) ? item.label : '<div class="bizserch_img">
258<img src="https://img.usaonline.us/images/biz.png"></div><b class="companysuggestion">' + item.label + '</b>' + '<br/>' + item.CompanyAddress + ' ' + item.Zipcode)) + "</a></li>").appendTo(ul);
259            return $(BusinessHtml).appendTo(ul);
260        };
261    });
262
263    ////// Zipcode & CityName search 
264    $('[data-searchterm="zipcity"]').autocomplete({
265        open: function () {
266            var width = $(this).css('width');
267            $(this).autocomplete("widget").css({ 'width': '100%', 'max-width': width });
268
269            var acData = null;
270            acData = $(this).data('uiAutocomplete');
271            var x = 0;
272            acData.menu.element.find('a').each(function () {
273                var me = $(this);
274                //  var re = new RegExp(acData.term, 'gi');
275                //console.log(me.text() + " == > " + toTitleCase(acData.term))
276                var s = replaceStr(me.text(), toTitleCase(acData.term), '');
277                me.html(s);
278
279            });
280        },
281        minLength: 2,
282        source: function (request, response) {
283            ShowSearchLoader(FocusedTextBoxObj.siblings('[data-zip-img="loading"]'));
284            console.log('imglen ' + FocusedTextBoxObj.siblings('[data-zip-img="loading"]').length);
285            var Protocol = window.location.protocol;
286            var categorySuggestionURL = Protocol + '//' + location.host + '/websiteajax/UsaNewSearchChan/ZipcodeCityHunt';
287
288            $.ajax({
289                url: categorySuggestionURL,
290                type: "GET",
291                data: {
292                    SearchTerm: $.trim(request.term)
293                },
294                success: function (data) {
295                    //alert(data.data)
296
297                    if (data.data.length > 0) {
298                        //$('#search-category-btn').data('catname', data[0].catName);
299
300                        currentAssistance = [];
301                        currentAssistance = ($.map(data.data, function (item) {
302                            return item.ZipCode;
303                        }));
304
305                        response($.map(data.data, function (item) {
306                            return {
307                                label: item.ZipCode,
308                                value: item.Url + ';' + item.StateName + ';' + item.CityName,
309                                Protocol: item.Protocol,
310                                CityId: item.CityId
311                            };
312                        }));
313                    }
314                    else {
315                        currentAssistance = [];
316                        currentAssistance.push('No record found'),
317                         $('[data-searchterm="zipcity"]').val('');
318                        response($.map(currentAssistance, function (item) {
319                            return {
320                                label: 'No record found',
321                                value: '0'
322                            };
323                        }));
324
325                        $('#search-category-btn').data('catname', '');
326                        $('[data-searchterm="zipcity"]').val('');
327                    }
328                    HideSearchLoader($('[data-zip-img="loading"]'));
329                },
330                error: function (a, b, c) {
331                    HideSearchLoader($('[data-zip-img="loading"]'));
332
333                }
334            })
335        },
336        autoFocus: true,
337        focus: function (event, ui) {
338            event.preventDefault();
339            if ($('[data-id="hdn_IsVoice"]').length > 0) {
340                var CurrentTextBoxObj = event.target;
341                getSelectableCityZip(CurrentTextBoxObj, ui.item.label, ui.item.value, ui.item.Protocol, ui.item.CityId);
342            }
343        },
344        select: function (event, ui) {
345            event.preventDefault();
346            var CurrentTextBoxObj = event.target;
347            getSelectableCityZip(CurrentTextBoxObj, ui.item.label, ui.item.value, ui.item.Protocol, ui.item.CityId);
348        }
349    });
350
351
352    ///// Search Btn Click 
353    $(document).on('click', '[data-search-btn="search"]', function (e) {
354        var HintObj = $('.msg');
355        var targetValue = $(this).attr('data-targetinput');
356        var TargetContainerObj = $('[data-target="' + targetValue + '"]');
357        var CurrentTextBoxHdnCompanyCatValue = TargetContainerObj.find('[data-id="hdn_autocompleteCompanyCatUrlFlag"]').val();
358        var CurrentTextBoxHdnZipCityValue = TargetContainerObj.find('[data-id="hdn_autocompleteZipCity"]').val();
359        var Flag = '';
360
361      /*  var Protocol = $(TargetContainerObj).find('[data-id="hdn_autocompletedynamicprotocol"]').val();*/
362         var  Protocol = "https";
363        var ObjTextBoxFirst = TargetContainerObj.find('[data-searchterm="catcom"]');
364        var ObjTextBoxMyZip = TargetContainerObj.find('[data-searchterm="zipcity"]');
365        if ($(ObjTextBoxMyZip).val().trim() == '') {
366            SetElementPosition($(ObjTextBoxMyZip), HintObj);
367            $(ObjTextBoxMyZip).focus()
368            return;
369        }
370        if ($(ObjTextBoxFirst).val().trim() == '') {
371            SetElementPosition($(ObjTextBoxFirst), HintObj);
372            $(ObjTextBoxFirst).focus()
373            return;
374        }
375
376        if (CurrentTextBoxHdnCompanyCatValue == null) {
377            var ObjTextBox = TargetContainerObj.find('[data-searchterm="catcom"]');
378
379            if ($(ObjTextBox).val().trim() == '') {
380                //alert('Please enter category or company name 11');
381                /// custom tooltip hide
382                $(ObjTextBox).unbind('blur').bind('blur', function () {
383                    if (HintObj.is(':visible'))
384                        HintObj.hide();
385                });
386
387                /// custom tooltip position
388                SetElementPosition($(ObjTextBox), HintObj);
389                $(ObjTextBox).focus()
390                return;
391            }
392        }
393        else if (CurrentTextBoxHdnCompanyCatValue == '') {
394            var ObjTextBox = TargetContainerObj.find('[data-searchterm="catcom"]')
395            //alert('Please enter category or company name 12');
396            /// custom tooltip hide
397            $(ObjTextBox).unbind('blur').bind('blur', function () {
398                if (HintObj.is(':visible'))
399                    HintObj.hide();
400            });
401
402            /// custom tooltip position
403            SetElementPosition($(ObjTextBox), HintObj);
404            $(ObjTextBox).focus()
405            return;
406        }
407        else if (CurrentTextBoxHdnCompanyCatValue.split('~$')[0] == '' && typeof CurrentTextBoxHdnZipCityValue == 'undefined') {
408            // alert('no profile url and no zipcode or city');
409            var ObjTextBox = TargetContainerObj.find('[data-searchterm="zipcity"]');
410
411            /// custom tooltip hide
412            $(ObjTextBox).unbind('blur').bind('blur', function () {
413                if (HintObj.is(':visible'))
414                    HintObj.hide();
415            });
416
417            /// custom tooltip position
418            SetElementPosition($(ObjTextBox), HintObj);
419            $(ObjTextBox).focus()
420            return;
421
422        }
423        else {
424            Flag = CurrentTextBoxHdnCompanyCatValue.split('~$')[1];
425        }
426        // alert('Flag ' + Flag);
427        if (Flag == '' || Flag == 1) {
428            if (CurrentTextBoxHdnZipCityValue == null || CurrentTextBoxHdnZipCityValue == '') {
429                var ObjTextBox = TargetContainerObj.find('[data-searchterm="zipcity"]');
430
431                /// custom tooltip hide
432                $(ObjTextBox).unbind('blur').bind('blur', function () {
433                    if (HintObj.is(':visible'))
434                        HintObj.hide();
435                });
436
437                /// custom tooltip position
438                // SetElementPosition($(ObjTextBox), HintObj);
439                //   $(ObjTextBox).focus()
440                //   return;
441            }
442        }
443
444
445        // alert('comcat ' + CurrentTextBoxHdnCompanyCatValue)
446        //  alert('Protocol ' + Protocol)
447        var CityUrl = '';
448        var IsZipCode = false; //alert('CurrentTextBoxHdnZipCityValue ' + CurrentTextBoxHdnZipCityValue);
449        var ObjTextBoxCity = TargetContainerObj.find('[data-searchterm="zipcity"]');
450        IsZipCode = IsZipCode_fn($(ObjTextBoxCity).val().trim().split(' ')[0]);
451        console.log('IsZipCode==== ' + IsZipCode + $(ObjTextBoxCity).val())
452        if ($(ObjTextBoxCity).val().trim() == '') {
453            CityUrl = Protocol + '://' + $('[ data-id="hdn_autocompleteOriginalZipCity"]').val().split(';')[0];
454        }
455        else if (Flag == '' || Flag == 1) {
456            console.log('enter floag==1 or flag=""')
457            if (CurrentTextBoxHdnZipCityValue.split(';')[0] != '')
458                CityUrl = Protocol + '://' + CurrentTextBoxHdnZipCityValue.split(';')[0];
459            else {
460                CityUrl = Protocol + '://' + $('[data-id="hdn_autocompletelocaldomain"]').val();
461
462            }
463        }
464        else if (Flag == '2' && typeof CurrentTextBoxHdnZipCityValue != 'undefined') {
465            if (CurrentTextBoxHdnZipCityValue.split(';')[0] == '') {
466                CityUrl = Protocol + '://' + $('[data-id="hdn_autocompletelocaldomain"]').val();
467                IsZipCode = true;
468            }
469            else {
470                // alert('t1')
471                CityUrl = Protocol + '://' + CurrentTextBoxHdnZipCityValue.split(';')[0];
472            }
473        }
474        else if (Flag == '2' && typeof CurrentTextBoxHdnZipCityValue == 'undefined') {
475            CityUrl = Protocol + '://' + $('[data-id="hdn_autocompletelocaldomain"]').val();
476            IsZipCode = true;
477        }
478
479        // alert('CityUrl ' + CityUrl);
480
481        var LocationUrl = ''
482
483        var ObjTextBox = TargetContainerObj.find('[data-searchterm="catcom"]');
484        var ObjZipCodeTextBox = TargetContainerObj.find('[data-searchterm="zipcity"]');
485        var SearchTerm = $(ObjTextBox).val().trim();
486        var Zipcode = ''
487        if (IsZipCode)
488            Zipcode = $(ObjZipCodeTextBox).val().replace(/ *\([^)]*\) */g, '').trim();
489
490        if (CurrentTextBoxHdnCompanyCatValue == null) {
491            /// replace 'in' word from search
492            var pat = /\bin\b/gi;
493            if (pat.test(SearchTerm)) {
494                SearchTerm = SearchTerm.replace(pat, '').trim();
495            }
496
497            LocationUrl = CityUrl + '/search-result?name=' + encodeURIComponent(SearchTerm) + ((IsZipCode) ? '&zipcode=' + Zipcode : '');
498            // alert('LocationUrl ' + LocationUrl)
499        }
500        else if (CurrentTextBoxHdnCompanyCatValue.split('~$')[1] == '1') {  //// category url when Flag=1
501            LocationUrl = ((IsZipCode) ? CityUrl + '/' + CurrentTextBoxHdnCompanyCatValue.split('~$')[0] + '?zip=' + Zipcode : CityUrl + '/' + CurrentTextBoxHdnCompanyCatValue.split('~$')[0]);
502        }
503        else {
504            if (IsZipCode)
505                Zipcode = $(ObjZipCodeTextBox).val().replace(/ *\([^)]*\) */g, '').trim();
506
507            LocationUrl = ((IsZipCode) ? CityUrl + '/search-result?name=' + encodeURIComponent(SearchTerm) + ((IsZipCode) ? '&zipcode=' + Zipcode : '') : CityUrl + '/search-result?name=' + encodeURIComponent(SearchTerm) + ((IsZipCode) ? '&zipcode=' + Zipcode : ''));  /// profile url
508            //alert('LocationUrl2 ' + LocationUrl)
509        }
510        // alert('LocationUrl3 ' + LocationUrl)
511        window.location.href = LocationUrl;
512        ShowModalDialog($(ObjTextBoxFirst).val().trim(), $(ObjTextBoxMyZip).val());
513
514
515
516    });
517
518
519    //// Searchbox Enter Key Event
520    $(document).on('keypress', '[data-searchterm="catcom"],[data-searchterm="zipcity"]', function (e) {
521
522        
523        
524        var HintObj = $('.msg');
525        var TargetContainerObjValue = $(this).parents('[data-target]').attr('data-target');
526        var TargetContainerObj = $(this).parents('[data-target="' + TargetContainerObjValue + '"]'); /// find the main div that holds search partial
527
528        if ($(this).attr('data-searchterm') == 'catcom') {
529            var v = $(TargetContainerObj).find('[data-id="hdn_autocompleteZipCity"]').val();
530           
531            if (typeof v === 'undefined') {
532                $('[data-searchterm="zipcity"]').val('');
533                $('[data-searchterm="catcom"]').val('');
534                var ObjTextBox = TargetContainerObj.find('[data-searchterm="zipcity"]');
535                SetElementPosition($(ObjTextBox), HintObj);
536                $(ObjTextBox).focus();
537                return false;
538            }
539            else if (v == '') {
540                $('[data-searchterm="zipcity"]').val('');
541                $('[data-searchterm="catcom"]').val('');
542                var ObjTextBox = TargetContainerObj.find('[data-searchterm="zipcity"]');
543                SetElementPosition($(ObjTextBox), HintObj);
544                $(ObjTextBox).focus();
545                return false;
546            }
547        }
548
549        var Flag = '';
550        var hiddenCatCom = TargetContainerObj.find('[data-id="hdn_autocompleteCompanyCatUrlFlag"]');
551        if ($(hiddenCatCom).length > 0)
552            Flag = $(hiddenCatCom).val().split('~$')[1];
553
554
555        if (e.keyCode == 13) {
556            if ($(this).val().trim() == '') {
557                if ($(this).attr('data-searchterm') == 'catcom') {
558                    //alert('Please enter category or company name 22');
559                    var ObjTextBox = TargetContainerObj.find('[data-searchterm="catcom"]');
560                    SetElementPosition($(ObjTextBox), HintObj);
561                    $(this).focus();
562                    return;
563                }
564                else if (Flag == 1) {
565                    /// only for category case ZipCodeCityName validation is mandatory
566                    /// It should not be blank
567
568                    //  alert('Please provide Zipcode or City name 22');
569
570                    /// custom tooltip position
571                    // var ObjTextBox = TargetContainerObj.find('[data-searchterm="zipcity"]');
572                    //  SetElementPosition($(ObjTextBox), HintObj);
573                    //  $(this).focus();
574                    //   return;
575
576                    var SearchBtnObj = TargetContainerObj.find('[data-search-btn="search"]');
577                    SearchBtnObj.trigger('click');
578                }
579                else {
580                    // case when user select company from autocomplete and then press enter => then profile url should open 
581                    // bypassing ZipCodeCityName TextBox validation 
582                    var SearchBtnObj = TargetContainerObj.find('[data-search-btn="search"]');
583                    SearchBtnObj.trigger('click');
584                }
585
586            }
587            else {
588                var SearchBtnObj = TargetContainerObj.find('[data-search-btn="search"]');
589                SearchBtnObj.trigger('click');
590
591            }
592        }
593    });
594
595
596
597});
598
599function replaceStr(str, find, replace) {
600    try {
601        var termTemplate = "<b>%s</b>";
602        var styledTerm = '';
603        find = find.trim();
604        if (find.indexOf(' ') > -1) {
605            // find = find.split(' ').join('|');
606            for (var i = 0; i < find.split(' ').length; i++) {
607                styledTerm = termTemplate.replace('%s', find.split(' ')[i].trim());
608                str = str.replace(new RegExp('\\b' + find.split(' ')[i].trim(), 'gi'), styledTerm);
609                // console.log('str:  ' + str)
610
611            }
612
613        }
614        else {
615            styledTerm = termTemplate.replace('%s', find.trim());
616            str = str.replace(new RegExp('\\b' + find.trim(), 'gi'), styledTerm);
617        }
618    }
619    catch (err) {
620
621    }
622    return str;
623};
624
625
626function getSelectableCategoryList(textBoxObj, Name, UrlFlagCombo, Protocol) {
627    var TargetContainerObjValue = $(textBoxObj).parents('[data-target]').attr('data-target');
628    var TargetContainerObj = $(textBoxObj).parents('[data-target="' + TargetContainerObjValue + '"]');
628 /// find the main div that holds search partial
629    var ZipCityTextBox = TargetContainerObj.find('[data-searchterm="zipcity"]');
630
631    if (UrlFlagCombo == '~$0') {  // case 'no record found' keep the textbox value as user typed. (do not change)  
632        if ($('[data-id="hdn_IsVoice"]').length > 0) {  /// for voice search search is fired immediately even if no records found
633            var SearchBtn = $(TargetContainerObj).find('[data-search-btn="search"]');
634            SearchBtn.trigger('click');
635            return;
636        }
637        $(ZipCityTextBox).focus();
638        return;
639    }
640    $(textBoxObj).val(Name);
641    if ($(TargetContainerObj).find('[data-id="hdn_autocompleteCompanyCatUrlFlag"]').length == 0) {
642        var hdnObj = $('<input/>').attr({
643            type: 'hidden',
644            'data-id': 'hdn_autocompleteCompanyCatUrlFlag',
645            value: UrlFlagCombo
646        });
647        //debugger;
648        $(TargetContainerObj).append(hdnObj);
649
650    }
651    else {
652        $(TargetContainerObj).find('[data-id="hdn_autocompleteCompanyCatUrlFlag"]').val(UrlFlagCombo);
653    }
654
655    if (UrlFlagCombo.indexOf('~$') > -1) {
656        if (UrlFlagCombo.split('~$')[1] == '2') {  /// company click case
657            if (UrlFlagCombo.split('~$')[0] == '') {
658                $(ZipCityTextBox).focus();
659            }
660            else {
661                window.location = Protocol + '://' + UrlFlagCombo.split('~$')[0];
662                ShowModalDialog(Name, $(ZipCityTextBox).val());
663                // alert(Protocol + '://' + UrlFlagCombo.split('~$')[0]);
664
665            }
666            return;
667        }
668        else if (UrlFlagCombo.split('~$')[1] == '1')  /// category click case
669        {
670            var ZipCityHiddenVal = $(TargetContainerObj).find('[data-id="hdn_autocompleteZipCity"]').val().trim(); /// holds url;statename;cityname
671            var OriginalZipCityHiddenVal = $('[data-id="hdn_autocompleteOriginalZipCity"]').val().trim();  /// onload original city
672            if (ZipCityHiddenVal == '') {  /// no city selected
673                $(ZipCityTextBox).focus();
674            }
675            else {
676                if (UrlFlagCombo.split('~$')[0] == '') {
677                    $(ZipCityTextBox).focus();
678                }
679                else {
680                    var localurl = ZipCityHiddenVal.split(';')[0];
681                    if (localurl == '') {
682                        var Zipcodeval = $(ZipCityTextBox).val().trim().split(' ')[0];
683                        var IsZipCode = IsZipCode_fn($(ZipCityTextBox).val().trim().split(' ')[0]);
684                        if (IsZipCode) {
685                            localurl = OriginalZipCityHiddenVal.split(';')[0];
686                            window.location = Protocol + '://' + localurl + '/' + UrlFlagCombo.split('~$')[0] + ((IsZipCode) ? '?zip=' + Zipcodeval : '');
687                            ShowModalDialog(Name, $(ZipCityTextBox).val());
688                            return;
689                        }
690                    }
691                    //  alert(Protocol + '://' + localurl + '/' + UrlFlagCombo.split('~$')[0] + ((IsZipCode)?'?zipcode=' +Zipcodeval:'' ));
692                    //  console.log('caturl ' + Protocol + '://' + localurl + '/' + UrlFlagCombo.split('~$')[0]);
693                    window.location = Protocol + '://' + localurl + '/' + UrlFlagCombo.split('~$')[0];
694                    ShowModalDialog(Name, $(ZipCityTextBox).val());
695                    return;
696                }
697            }
698        }
699    }
700
701
702
703    /// focusing ZipCity Box////  
704    $(ZipCityTextBox).focus();
705
706};
707
708function getSelectableCityZip(textBoxObj, Name, UrlStateCity, Protocol, CityId) {
709
710    var TargetContainerObjValue = $(textBoxObj).parents('[data-target]').attr('data-target');
711    var TargetContainerObj = $(textBoxObj).parents('[data-target="' + TargetContainerObjValue + '"]'); /// find the main div that holds search partial
712    if (UrlStateCity == '0')
713        return;
714
715    $(textBoxObj).val(Name);
716    var TargetInputValue = $(textBoxObj).attr('data-target')
717    if ($(TargetContainerObj).find('[data-id="hdn_autocompleteZipCity"]').length == 0) {
718        var hdnObj = $('<input/>').attr({
719            type: 'hidden',
720            'data-id': 'hdn_autocompleteZipCity',
721            value: UrlStateCity
722        });
723        $(TargetContainerObj).append(hdnObj);
724    }
725    else {
726        $(TargetContainerObj).find('[data-id="hdn_autocompleteZipCity"]').val(UrlStateCity);
727    }
728
729    /// set Protocol
730    if (Protocol == '') {
731        $(TargetContainerObj).find('[data-id="hdn_autocompletedynamicprotocol"]').val(window.location.protocol.replace(':', ''));
732    }
733    else {
734        $(TargetContainerObj).find('[data-id="hdn_autocompletedynamicprotocol"]').val(Protocol);
735    }
736
737    /// Set CityId
738    $(TargetContainerObj).find('[data-id="hdn_autocompletecityid"]').val(CityI
738d);
739
740    //// trigger search after select
741    //var TargetContainerObjValue = $(textBoxObj).parents('[data-target]').attr('data-target');
742    //var TargetContainerObj = $(textBoxObj).parents('[data-target="' + TargetContainerObjValue + '"]'); /// find the main div that holds search partial
743    var SearchBtn = TargetContainerObj.find('[data-search-btn="search"]');
744
745    setTimeout(function () { SearchBtn.trigger('click'); }, 50);
746
747    /// if voice search=> delay search btn click
748    if ($('[data-id="hdn_IsVoice"]').length > 0) {
749        setTimeout(function () { SearchBtn.trigger('click'); }, 300);
750    }
751    else {
752
753    }
754
755};
756
757function GetLeftPosition(textboxobj) {
758    var leftpos = textboxobj.offset().left;
759    return leftpos;
760};
761function GetTopPosition(textboxobj) {
762    var toptpos = textboxobj.offset().top;
763    return toptpos;
764}
765function GetWidth(ElementObj) {
766    var outerwidth = ElementObj.outerWidth();
767    return outerwidth;
768};
769function GetHeight(ElementObj) {
770    var outerheight = ElementObj.outerHeight();
771    return outerheight;
772};
773function SetElementPosition(textboxobj, HintObj) {
774    var TopHeaderObj = $('#logo-header');
775    var leftpos = GetLeftPosition(textboxobj);
776    var toppos = GetTopPosition(textboxobj); //console.log('toppos ' + toppos)
777    var TextBoxHeight = GetHeight(textboxobj); //console.log('TextBoxHeight ' + TextBoxHeight)
778    var finaltoppos = parseInt(toppos) - parseInt(TextBoxHeight);
779    if (parseInt(finaltoppos) < 0) {
780        finaltoppos = parseInt(toppos) + parseInt(TextBoxHeight);
781    }
782
783    if (TopHeaderObj.hasClass('fixedArea')) {
784        finaltoppos = parseInt(toppos) + parseInt(TextBoxHeight);
785    }
786    HintObj.css({ 'left': leftpos, 'top': finaltoppos, 'display': 'block' });
787}
788
789function ShowSearchLoader(imgobj) {
790    imgobj.show();
791}
792function HideSearchLoader(imgobj) {
793    imgobj.hide();
794}
795
796function IsZipCode_fn(zipcode) {
797    var pat = /^\d{5}$/gi;
798    if (pat.test(zipcode))
799        return true;
800    else
801        return false;
802}
803
804///// get Autodetected State/City Name Domain, Url ,State Abbr. etc and set to default fields for search
805//// the Auto detection is added on CommonHeader Cshtml Page ////
806
807function SetAuoDetectedValues(CityName, StateAbbr, StateName, CityUrl, CityId) {
808    var ZipCitytextBoxes = $('[data-searchterm="zipcity"]')
809    $.each(ZipCitytextBoxes, function (idx, itm) {
810        $(this).val(CityName + ' (' + StateAbbr + ')');
811        //getSelectableCityZip(CurrentTextBoxObj, ui.item.label, ui.item.value, ui.item.Protocol, ui.item.CityId);
812
813        var HttProtocall = new MynewProtocol(CityUrl);
814        var Protocol = HttProtocall.getprotocol().replace('://', '');
815
816        if (CityUrl.indexOf('www.') > -1)
817            CityUrl = 'local.' + CityUrl.replace('www.', '');
818        else
819            CityUrl = CityUrl + '/local';
820
821        var TheVal = CityUrl + ';' + StateName + ';' + CityName;
822        getSelectableCityZip($(this), CityName + ' (' + StateAbbr + ')', TheVal, Protocol, CityId);
823
824    });
825
826};
827
828function toTitleCase(str) {
829    return str.replace(/(?:^|\s)\w/g, function (match) {
830        return match.toUpperCase();
831    });
832};
833
834function ShowModalDialog(name, city) {
835    $('#search-process').find('[data-attr="takingu"]').html('Taking you to <b>' + name + '</b>' + ' in <b>' + city + '</b>');
836    $('#search-process').modal('show');
837}
838/*******************************_largeSearch_ES.cshtml*********************************/
839function startDictation(obj, targetName) {
840    // alert($(obj).parent().find('input[type="text"]').attr('id'));
841    if (window.hasOwnProperty('webkitSpeechRecognition')) {
842        var MainConatinerObj = $('[data-target="' + targetName + '"]');
843        var imgobj = $(obj).parent().find('img[data-id="micicon"]');
844        $(imgobj).attr('src', 'https://img.usaonline.us/images/mic-animate.gif');
845        setTimeout(function () { $(imgobj).attr('src', 'https://img.usaonline.us/images/mic.gif'); }, 5000);
846        var recognition = new webkitSpeechRecognition();
847
848        recognition.continuous = false;
849        recognition.interimResults = false;
850
851        recognition.lang = "en-US";
852        recognition.start();
853
854        recognition.onresult = function (e) {
855            var SearchBox = $(obj).parent().find('[data-searchterm="catcom"]');
856
857            var s = e.results[0][0].transcript;
858            var locationWord = '';
859            //// break 'in' word
860            WordHolder = s.split(' ');
861            if ($.inArray('in', WordHolder) >= 0) {
862                var IndexPos = $.inArray('in', WordHolder);
863                var NewWordArrayBeforeIn = WordHolder.slice(0, IndexPos);
864                var NewWordArrayFromIn = WordHolder.slice(IndexPos);
865                //console.log('NewWordArray  ' + NewWordArrayFromIn + '; ' + NewWordArrayBeforeIn);
866                s = NewWordArrayBeforeIn.join(' ');
866 /// category main search
867                locationWord = NewWordArrayFromIn.slice(1).join(' ');
868                //console.log('Main: ' + s + ' ==> ' + location);
869
870                MainConatinerObj.find('[data-searchterm="zipcity"]').val(locationWord);
871                MainConatinerObj.find('[data-searchterm="zipcity"]').focus();
872
873                //   $(this).next('input').focus();
874            }
875            /// break 'in' word ends
876
877            var hdnfieldobj = MainConatinerObj.find('[data-id="hdn_autocompleteCompanyCatUrlFlag"]');
878            if ($(hdnfieldobj).length > 0)
879                $(hdnfieldobj).remove();
880
881            var hdnfieldobjZip = MainConatinerObj.find('[data-id="hdn_autocompleteZipCity"]');
882            //if ($(hdnfieldobjZip).length > 0)
883            //    $(hdnfieldobjZip).remove();
884
885
886            $(SearchBox).val(s);
887            if ($(SearchBox).val().trim() != '') {
888                if ($('[data-id="hdn_IsVoice"]').length == 0) {
889                    var hdnObj = $('<input/>').attr({
890                        type: 'hidden',
891                        'data-id': 'hdn_IsVoice',
892                        value: '1'
893                    });
894                    //debugger;
895                    $('body').append(hdnObj);
896
897                }
898            }
899
900            FocusedTextBoxObj = $(obj);
901            $(SearchBox).autocomplete('search', s);
902            if (locationWord != '') {
903                MainConatinerObj.find('[data-searchterm="zipcity"]').autocomplete('search', locationWord);
904            }
905
906            recognition.stop();
907            $(imgobj).attr('src', 'https://img.usaonline.us/images/mic.gif');
908            return;
909
910
911        };
912
913        recognition.onerror = function (e) {
914            console.log('er: not supported');
915            console.log('er: ' + e.error);
916            recognition.stop();
917            $(imgobj).attr('src', 'https://img.usaonline.us/images/mic.gif');
918        }
919
920    }
921    else {
922        //  alert('not supported')
923        imgobj.hide();
924    }
925
926
927
928}
929/***************************************END*******************************************/
930/*******************************_HeaderSmallSearch.cshtml*********************************/
931function startDictationSmall(obj, targetName) {
932    // alert($(obj).parent().find('input[type="text"]').attr('id'));
933    if (window.hasOwnProperty('webkitSpeechRecognition')) {
934        var MainConatinerObj = $('[data-target="' + targetName + '"]');
935        var imgobj = $(obj).parent().find('img[data-id="micicon"]');
936        $(imgobj).attr('src', 'https://img.usaonline.us/images/mic-animate.gif');
937        setTimeout(function () { $(imgobj).attr('src', 'https://img.usaonline.us/images/mic.gif'); }, 5000);
938        var recognition = new webkitSpeechRecognition();
939
940        recognition.continuous = false;
941        recognition.interimResults = false;
942
943        recognition.lang = "en-US";
944        recognition.start();
945
946        recognition.onresult = function (e) {
947            var SearchBox = $(obj).parent().find('[data-searchterm="catcom"]');
948
949
950            var s = e.results[0][0].transcript;
951            var locationWord = '';
952            //// break 'in' word
953            WordHolder = s.split(' ');
954            if ($.inArray('in', WordHolder) >= 0) {
955                var IndexPos = $.inArray('in', WordHolder);
956                var NewWordArrayBeforeIn = WordHolder.slice(0, IndexPos);
957                var NewWordArrayFromIn = WordHolder.slice(IndexPos);
958                //console.log('NewWordArray  ' + NewWordArrayFromIn + '; ' + NewWordArrayBeforeIn);
959                s = NewWordArrayBeforeIn.join(' ');
959 /// category main search
960                locationWord = NewWordArrayFromIn.slice(1).join(' ');
961                //console.log('Main: ' + s + ' ==> ' + location);
962
963                MainConatinerObj.find('[data-searchterm="zipcity"]').val(locationWord);
964                MainConatinerObj.find('[data-searchterm="zipcity"]').focus();
965
966                //   $(this).next('input').focus();
967            }
968            /// break 'in' word ends
969
970            var hdnfieldobj = MainConatinerObj.find('[data-id="hdn_autocompleteCompanyCatUrlFlag"]');
971            if ($(hdnfieldobj).length > 0)
972                $(hdnfieldobj).remove();
973
974            var hdnfieldobjZip = MainConatinerObj.find('[data-id="hdn_autocompleteZipCity"]');
975            //if ($(hdnfieldobjZip).length > 0)
976            //    $(hdnfieldobjZip).remove();
977
978
979            $(SearchBox).val(s);
980            if ($(SearchBox).val().trim() != '') {
981                if ($('[data-id="hdn_IsVoice"]').length == 0) {
982                    var hdnObj = $('<input/>').attr({
983                        type: 'hidden',
984                        'data-id': 'hdn_IsVoice',
985                        value: '1'
986                    });
987                    //debugger;
988                    $('body').append(hdnObj);
989
990                }
991            }
992
993            FocusedTextBoxObj = $(obj);
994            $(SearchBox).autocomplete('search', s);
995            if (locationWord != '') {
996                MainConatinerObj.find('[data-searchterm="zipcity"]').autocomplete('search', locationWord);
997            }
998
999            recognition.stop();
1000            $(imgobj).attr('src', 'https://img.usaonline.us/images/mic.gif');
1001            return;
1002
1003
1004        };
1005
1006        recognition.onerror = function (e) {
1007            console.log('er: not supported');
1008            recognition.stop();
1009            $(imgobj).attr('src', 'https://img.usaonline.us/images/mic.gif');
1010        }
1011
1012    }
1013    else {
1014        imgobj.hide();
1015    }
1016
1017}
1018
1019/***************************************END*******************************************/

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.