// // 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; function navigate(sender, e) { if (addingHistoryPoint == true) return; // Run search var where = e.get_state().where; var what = e.get_state().what; if (what && what.length > 0) { $("#what-textbox").val(what); $("#where-textbox").val(where); 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"); $("#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(); }); 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 (s && s.evar20) { var visitorId = s.evar20; $("#search-inner-vid").val(visitorId); } $("#search-progress").show(); return true; } function onSearchFailure() { searchInitiatedByNavigate = false; return true; } function onSearchSuccess() { $("#search-progress").hide(); // Google tracking _gaq.push(['_trackEvent', 'Search', 'Keyword', lastSearchTextBoxValue]); _gaq.push(['_trackEvent', 'Search', 'Location', lastLocationTextBoxValue]); 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; Sys.Application.addHistoryPoint({ what: lastSearchTextBoxValue, where: lastLocationTextBoxValue }); 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"); $.post(href, { ids: ids }, function (data) { $.colorbox({ html: data, opacity: 0.2, overlayClose: false}); }); return false; } function changePage(pageNumber) { $("#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"); $.post(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 (data) { $.colorbox({ html: data, opacity: 0.2, overlayClose: false }); }); 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; }