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_gs":"9","osp_subject_ls":null,"osp_subject_crosskla":"12","osp_subject_pre-pri":"13","osp_subject_ge":"14","osp_subject_apl":"15","osp_subject_lwll":"16","osp_subject_sen":"11","osp_subject_mce":"17","osp_subject_reading-to-learn":"18","osp_subject_pl":"19","osp_subject_it-for-il":"20"}'); var kla_unspecified_id = jQuery.parseJSON('"0"'); 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"}'); var res_type_unspecified_id = jQuery.parseJSON('"0"'); // 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); } else { kla.push("0"); //console.log("no 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); } else { res_type.push("0"); //console.log("no 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 { // push "Not specified" if empty if(kla.length === 0) kla.push(kla_unspecified_id + ""); if(res_type.length === 0) res_type.push(res_type_unspecified_id + ""); // redirect to the search page if (is_suggestion === true){ pageRedirectTest(search_key, {edbosp_kla_id: kla, edbosp_res_type_id: res_type, edbosp_label_id: ["1"]}); }else{ pageRedirectTest(search_key, {edbosp_kla_id: kla, edbosp_res_type_id: res_type}); } } } // 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; }