// // MVC wire up // Sys.Application.add_init(pageInit); function pageInit() { // Enable history Sys.Application.set_enableHistory(true); // Add Handler for history Sys.Application.add_navigate(navigate); } var addingHistoryPoint = false; var searchInitiatedByNavigate = false; var tracking_what = ""; var tracking_where = ""; var tracking_hasResults = false; var tracking_lastWhat = ""; var tracking_lastWhere = ""; function navigate(sender, e) { if (addingHistoryPoint == true) return; // Run search var where = e.get_state().where; var what = e.get_state().what; var page = e.get_state().page; var empfilt = e.get_state().empfilt; var catfilt = e.get_state().catfilt; var tofilt = e.get_state().tofilt; var typfilt = e.get_state().typfilt; var locfilt = e.get_state().locfilt; if (what && what.length > 0) { $("#what-textbox").val(what); $("#where-textbox").val(where); if(page) { $("#search-form input[name=page]").val(page); } if (empfilt) { $("#search-form input[name=empfilt]").val(empfilt); } if (catfilt) { $("#search-form input[name=catfilt]").val(catfilt); } if (tofilt) { $("#search-form input[name=tofilt]").val(tofilt); } if (typfilt) { $("#search-form input[name=typfilt]").val(typfilt); } if (locfilt) { $("#search-form input[name=locfilt]").val(locfilt); } searchInitiatedByNavigate = true; runSearch(); } } // // JQuery wire up // $(document).ready( function () { $("#what-textbox").unbind("keyup"); $("#what-textbox").unbind("change"); $("#where-textbox").unbind("keyup"); $("#where-textbox").unbind("change"); $("#search-button").unbind("click"); $("#search-button").bind("click", function () { onSearchBegin(); return true; }); $("#what-textbox").bind("keyup", function () { userInput(false); }); $("#what-textbox").bind("change", function () { userInput(true); }); $("#where-textbox").bind("keyup", function () { userInput(false); }); $("#where-textbox").bind("change", function () { userInput(true); }); $("#what-textbox").focus(); // Wire up auto complete $("#where-textbox").autocomplete({ source: '/GetLocations', minLength: 2, delay: 200 }); }); var lastKeyUpTimerID = null; var lastSearchTextBoxValue = ""; var lastLocationTextBoxValue = ""; var currentlySearching = false; var redoSearchOnCompletion = false; // // // function filter() { $("#filter-submit").click(); return true; } function userInput(immediateSearch) { if (immediateSearch) { setTimeout('runSearch();', 0); } else { if (lastKeyUpTimerID != null) clearTimeout(lastKeyUpTimerID); lastKeyUpTimerID = setTimeout('lastKeyUpTimerID = null; runSearch();', 350); } } function onSearchKeyUp() { userInput(false); } function onLocationKeyUp() { userInput(false); } function runSearch() { var searchTextBoxValue = $("#what-textbox").val(); var locationSearchTextBoxValue = $("#where-textbox").val(); var customInputs = $("#search-inner-custom-wrap select,#search-inner-custom-wrap input"); var customInputsWithValue = 0; for(i = 0; i < customInputs.length; i++) { if($(customInputs[i]).val() != '') { customInputsWithValue++; } } if (searchTextBoxValue.length < 2 && customInputsWithValue == 0) return; if(searchTextBoxValue == lastSearchTextBoxValue && locationSearchTextBoxValue == lastLocationTextBoxValue) // Nothing has changed return; if(currentlySearching) { redoSearchOnCompletion = true; return; } lastSearchTextBoxValue = searchTextBoxValue; lastLocationTextBoxValue = locationSearchTextBoxValue; currentlySearching = true; $("#search-button").click(); } function onSearchBegin() { if (!searchInitiatedByNavigate) { // Clear out any lingering hidden filter values $("#search-form input[name=empfilt]").val(""); $("#search-form input[name=catfilt]").val(""); $("#search-form input[name=tofilt]").val(""); $("#search-form input[name=typfilt]").val(""); $("#search-form input[name=locfilt]").val(""); } if (s && s.evar20) { var visitorId = s.evar20; $("#search-form input[name=vid]").val(visitorId); } $("#search-form input[name=emplexp]").val($("#filter-advanced-header-employee-c:visible").length > 0); $("#search-form input[name=toexp]").val($("#filter-advanced-header-turnover-c:visible").length > 0); $("#search-form input[name=locexp]").val($("#filter-advanced-header-location-c:visible").length > 0); $("#search-form input[name=catexp]").val($("#filter-advanced-header-category-c:visible").length > 0); $("#search-form input[name=typexp]").val($("#filter-advanced-header-companytype-c:visible").length > 0); $("#search-progress").show(); return true; } function trackSearch() { if (tracking_what == tracking_lastWhat && tracking_where == tracking_lastWhere) // We have already tracked this return; // Google /* if (_gaq) { _gaq.push(['_trackEvent', 'Search', 'Keyword', tracking_what]); _gaq.push(['_trackEvent', 'Search', 'Location', tracking_where]); } */ // Omniture /* if (s) { s.pageName = "yp_result"; s.server = window.location.host; s.channel = "results"; s.evar2 = "results"; s.prop2 = "results"; s.prop25 = "yp_result_ajax"; if (!tracking_hasResults) { s.events = "event40"; } s.t(); } */ tracking_lastWhat = tracking_what; tracking_lastWhere = tracking_where; } function onSearchFailure() { window.location.href = "/Error"; searchInitiatedByNavigate = false; return true; } function onSearchSuccess() { $("#search-progress").hide(); // Handle banners var bannerUrl = $("#bannerurl").text(); if (bannerUrl && bannerUrl != "") { $.get("/Banner/Search?u=" + escape(bannerUrl), function (data) { $("#search-result-inner-banner").html(data); }); } // Search tracking tracking_what = lastSearchTextBoxValue; tracking_where = lastLocationTextBoxValue; tracking_hasResults = $("#NoResult").length == 0; setTimeout("trackSearch();", 3000); currentlySearching = false; // if (redoSearchOnCompletion) { redoSearchOnCompletion = false; window.setTimeout("runSearch()", 100); } // Only add history point when the search was not initiated by a history navigation event if (searchInitiatedByNavigate == false) { addingHistoryPoint = true; var newTitle = lastSearchTextBoxValue; if (lastLocationTextBoxValue && lastLocationTextBoxValue != '') { newTitle += ' i ' + lastLocationTextBoxValue; } newTitle += ' - ' + defaultTitle; Sys.Application.addHistoryPoint({ what: lastSearchTextBoxValue, where: lastLocationTextBoxValue }, newTitle); addingHistoryPoint = false; } else { searchInitiatedByNavigate = false; } return true; } function onFilterBegin() { $("#search-progress").show(); return true; } function onFilterFailure() { return true; } function onFilterSuccess() { $("#search-progress").hide(); // Update filter counts updateFilterCounts("#filter-counts-employee span", "#filter-advanced-header-employee-c tr"); updateFilterCounts("#filter-counts-turnover span", "#filter-advanced-header-turnover-c tr"); updateFilterCounts("#filter-counts-category span", "#filter-advanced-header-category-c tr"); updateFilterCounts("#filter-counts-companytype span", "#filter-advanced-header-companytype-c tr"); updateFilterCounts("#filter-counts-location span", "#filter-advanced-header-location-c tr"); return true; } function updateFilterCounts(countSelectionText, displaySelectionText) { var filter = $(countSelectionText); var countsById = []; for (i = 0; i < filter.length; i++) { var data = $(filter[i]).text().split(','); countsById[data[0]] = data[1]; } var filterDisplay = $(displaySelectionText); for (i = 0; i < filterDisplay.length; i++) { var value = $(filterDisplay[i]).find("input").attr("value"); var count = countsById[value]; if(count) $(filterDisplay[i]).children("td").last().text(count); } } function sendRequestForProposal(alink) { // Get all selected companies checkedCompanies = $("#page-form input[name=compch][type=hidden],#page-form input:checked[name=compch][type=checkbox]"); ids = checkedCompanies.map(function () { return $(this).val(); }).get().join(','); href = $(alink).attr("href"); $("#tools-content-sendrfp-dialog").dialog({ modal: true, width: 460, autoOpen: false }); $("#tools-content-sendrfp-dialog").load(href, { ids: ids }, function () { var dlg = $("#tools-content-sendrfp-dialog"); dlg.dialog("option", "show", "fade"); dlg.dialog("option", "hide", "fade"); dlg.dialog("open"); }); return false; } function changePage(pageNumber) { // Remember the filters var empfilt = $("#filter-advanced-header input[name=empfilt]:checked"); var tofilt = $("#filter-advanced-header input[name=tofilt]:checked"); var locfilt = $("#filter-advanced-header input[name=locfilt]:checked"); var catfilt = $("#filter-advanced-header input[name=catfilt]:checked"); var typfilt = $("#filter-advanced-header input[name=typfilt]:checked"); $("#page-form input[name=empfilt]").val(toValueString(empfilt)); $("#page-form input[name=tofilt]").val(toValueString(tofilt)); $("#page-form input[name=locfilt]").val(toValueString(locfilt)); $("#page-form input[name=catfilt]").val(toValueString(catfilt)); $("#page-form input[name=typfilt]").val(toValueString(typfilt)); // $("#page-number").val(pageNumber); $("#page-form-submit").click(); return false; } function selectAllCompanies() { $("#search-result-companies input[type=checkbox]").attr('checked', true); return false; } function unselectAllCompanies() { $("#search-result-companies input[type=checkbox]").attr('checked', false); return false; } function toValueString(selection) { return selection.map(function () { return $(this).val(); }).get().join(','); } function saveSearchResult(alink) { href = $(alink).attr("href"); var empfilt = $("#filter-advanced-header input[name=empfilt]:checked"); var tofilt = $("#filter-advanced-header input[name=tofilt]:checked"); var locfilt = $("#filter-advanced-header input[name=locfilt]:checked"); var catfilt = $("#filter-advanced-header input[name=catfilt]:checked"); var typfilt = $("#filter-advanced-header input[name=typfilt]:checked"); $("#tools-content-saveresult-dialog").dialog({ modal: true, width: 460, autoOpen: false }); $("#tools-content-saveresult-dialog").load(href, { what: $("#what-textbox").val(), where: $("#where-textbox").val(), empfilt: toValueString(empfilt), tofilt: toValueString(tofilt), locfilt: toValueString(locfilt), catfilt: toValueString(catfilt), typfilt: toValueString(typfilt) }, function () { var dlg = $("#tools-content-saveresult-dialog"); dlg.dialog("option", "show", "fade"); dlg.dialog("option", "hide", "fade"); dlg.dialog("open"); }); return false; } function exportToExcel(alink) { var empfilt = $("#filter-advanced-header input[name=empfilt]:checked"); var tofilt = $("#filter-advanced-header input[name=tofilt]:checked"); var locfilt = $("#filter-advanced-header input[name=locfilt]:checked"); var catfilt = $("#filter-advanced-header input[name=catfilt]:checked"); var typfilt = $("#filter-advanced-header input[name=typfilt]:checked"); $("#export-to-excel input[name=page]").val($("#page-number").val()); $("#export-to-excel input[name=empfilt]").val(toValueString(empfilt)); $("#export-to-excel input[name=tofilt]").val(toValueString(tofilt)); $("#export-to-excel input[name=locfilt]").val(toValueString(locfilt)); $("#export-to-excel input[name=catfilt]").val(toValueString(catfilt)); $("#export-to-excel input[name=typfilt]").val(toValueString(typfilt)); $("#export-to-excel").submit(); return false; } function textBoxHelp(component, text) { if (component.value == text) { component.value = ""; } else if (component.value == "") { component.value = text; } } function showCat(ctl) { $('#what-textbox').val($(ctl).text().replace(/^\s+|\s+$/g, "")); runSearch(); return false; } function showLoc(ctl) { $('#where-textbox').val($(ctl).text().replace(/^\s+|\s+$/g, "")); runSearch(); return false; } function filterToggle(filterid) { var filterHeader = $(filterid); filterHeader.toggleClass('expanded'); filterHeader.toggleClass('collapsed'); $(filterid + '-c').toggle(0); return false; }