var kla_class_to_id = jQuery.parseJSON('{"osp_subject_chi":"1","osp_subject_eng":"2","osp_subject_math":"3","osp_subject_sci":"4","osp_subject_te":"5","osp_subject_pshe":"6","osp_subject_ae":"8","osp_subject_pe":"7","osp_subject_pre-pri":"13","osp_subject_gs":null,"osp_subject_ls":null,"osp_subject_it-for-il":null,"osp_subject_apl":"15","osp_subject_reading-to-learn":null,"osp_subject_crosskla":null,"osp_subject_ge":null,"osp_subject_mce":"17","osp_subject_lwll":null,"osp_subject_sen":null}'); var res_type_class_to_id = jQuery.parseJSON('{"osp_res_type_etv":"21","osp_res_type_lesson_plan":"2","osp_res_type_pack":"4","osp_res_type_worksheet":"1","osp_res_type_note":"5","osp_res_type_project":"19","osp_res_type_activity":"3","osp_res_type_experiment":"10","osp_res_type_reference":"20","osp_res_type_authoring":"14","osp_res_type_story":"11","osp_res_type_e_book":"12","osp_res_type_game":"13","osp_res_type_material":"6","osp_res_type_experience":"15","osp_res_type_article":"16","osp_res_type_work":"17","osp_res_type_report":"18","osp_res_type_software":"7","osp_res_type_diagram":"8","osp_res_type_picture":"9","osp_res_type_other":"10000"}'); // entry point of button function searchAction() { processSearch(false); } // entry point of button function searchAction_suggestion(){ processSearch(true); } // read the webpage and redirect to the search page function processSearch(is_suggestion){ // get selected kla, spot, keys var kla = []; var checked_dom = jQuery('#edbosp-search ul[class*="edbosp-advance-search scope"] input[class^="osp_subject_"]:checked'); jQuery.each(checked_dom, function(index, value) { var className = jQuery(value).attr('class');//console.log(className); var kla_id = kla_class_to_id[className];//className e.g. osp_subject_chi if (kla_id != undefined) { kla.push(kla_id + ""); //console.log(kla_id); } }); // get selected res_type var res_type = []; var checked_dom = jQuery('#edbosp-search ul[class*="edbosp-advance-search scope"] input[class^="osp_res_type_"]:checked'); jQuery.each(checked_dom, function(index, value) { var className = jQuery(value).attr('class');//console.log(className); var res_type_id = res_type_class_to_id[className];//className e.g. osp_res_type_worksheet if (res_type_id != undefined) { res_type.push(res_type_id + ""); //console.log(res_type_id); } }); // get search key var search_key = jQuery("#cs-input").val(); if ((search_key == "") && (kla.length === 0) && (res_type.length === 0)) { // not display error message and do nothing } else { var search_object = {}; if (kla.length > 0) search_object["edbosp_kla_id"] = kla; if (res_type.length > 0) search_object["edbosp_res_type_id"] = res_type; if (is_suggestion === true) search_object["edbosp_label_id"] = ["1"]; pageRedirectTest(search_key, search_object); } } // redirect to the search page function pageRedirect(search_key, search_type) { var req = ""; if ((typeof search_key != 'undefined') && (search_key != "")) { req = "search_key=" + encodeURIComponent(search_key); } if (typeof search_type != 'undefined') { var _temp = "search_type=" + encodeURIComponent(JSON.stringify(search_type)); if (req.length > 0) { req = req + "&" + _temp; } else { req = _temp; } } window.location.href = "//www.hkedcity.net/edbosp/search/" + "?" + req; } function pageRedirectTest(search_key, search_type) { var req = ""; if (typeof search_type != 'undefined') { req = "search_type=" + encodeURIComponent(JSON.stringify(search_type)); } if ((typeof search_key != 'undefined') && (search_key != "")) { var _temp = "search_key=" + encodeURIComponent(search_key); if (req.length > 0) { req = req + "&" + _temp; } else { req = _temp; } } window.location.href = "//www.hkedcity.net/edbosp/search/" + "?" + req; } jQuery(document).ready(function() { jQuery.get("count_handler.php", {}, function(data, textStatus, jqXHR) { for (var i in data) { var _label = jQuery("li.subject-listing-item span.osp_subject_" + i); if (_label.length > 0) { _label.css("display", ""); _label.html(data[i]); } } }, "json"); });