// JScript File String.prototype.replaceAll = function(token, newToken, ignoreCase) { var str, i = -1, _token; if((str = this.toString()) && typeof token === "string") { _token = ignoreCase === true? token.toLowerCase() : undefined; while((i = ( _token !== undefined? str.toLowerCase().indexOf( _token, i >= 0? i + newToken.length : 0 ) : str.indexOf( token, i >= 0? i + newToken.length : 0 ) )) !== -1 ) { str = str.substring(0, i) .concat(newToken) .concat(str.substring(i + token.length)); } } return str; }; function toShowSearchBox(language, showSuggestionKW) // language,suggestionKW,strTarget,tips { if(language == undefined) language = "ch"; if(showSuggestionKW == undefined) showSuggestionKW = true; language = language.toLowerCase(); var strImgPath=iypCommonAPI_HostURL+"/iypCommonAPI/SearchBox/e12/"+language+"/images/"; var pulldowndata = ""; var keywordTitle = ""; var whereTitle = ""; if (language=="en"){ keywordTitle = "Company, Shop, Category, Phone Number ..."; whereTitle = "All Districts"; pulldowndata = pulldowndataEN; } else if (language=="sc") { keywordTitle = "公司/商舖名稱、行業分類關鍵字或電話號碼"; whereTitle = "所有地區"; pulldowndata = pulldowndataSC; } else { // ch version keywordTitle = "公司/商舖名稱、行業分類關鍵字或電話號碼"; whereTitle = "所有地區"; pulldowndata = pulldowndataCH; } //var box_width="0"; var suggestionBoxWidth = 413; // search page for search box //var ypsearchurl=iypCommonAPI_HostURL+"/iypCommonAPI/SearchBox/e10/"+clientEncode+"/ypsearchbox.aspx"; // if(showSuggestionKW) // { // iypKeySuggestParam.Lang = language; // iypKeySuggestParam.HostURL = iypCommonAPI_HostURL; // iypKeySuggestParam.HostURL_IK = iypKeywordSuggestion_HostURL; // iypKeySuggestParam.Width = suggestionBoxWidth; // } document.write("
"); document.write(""); document.write("
"); document.write("
"); document.write(""); document.write(""); document.write("
"); document.write("
"); if(language == "en"){ document.write("
"); document.write(" "); document.write(" "); document.write(" "); document.write(" "); document.write(" "); document.write(" "); document.write(" "); document.write("
 
"); document.write("
"); } else { document.write("
"); document.write(" "); document.write(" "); document.write(" "); document.write(" "); document.write(" "); document.write(" "); document.write(" "); document.write("
 
"); document.write("
"); } document.write("
"); document.write(" "); document.write(" "); document.write(" "); document.write(" "); document.write(" "); document.write(" "); document.write("
"); document.write("  "); document.write(" "); document.write(" "); document.write(" "); document.write(" "); document.write(" "); document.write(" "); document.write(" "); document.write(" "); document.write(" "); document.write("
"); document.write(" "); document.write(" "); // document.write("
"); document.write("
"); document.write(""); document.write("
"); // keyword suggestion starts //document.write("
"); document.write("
"); document.write("
"); document.write("\x3Cscript type=\"text/javascript\">"); document.write("if(" + showSuggestionKW + ")"); document.write("{"); document.write("iypKeywordSuggest_Load(\"ID_KeywordSuggest\", \"keyword_txtbox\", \"noToSearch()\", '" + suggestionBoxWidth + "', '" + language + "');"); document.write("}"); document.write("\x3C/script>"); document.write("
"); document.write("
"); //document.write("
"); // keyword suggestion ends document.write("
"); document.write(" "); document.write(" "); document.write("
"); document.write("
"); document.write("
"); document.write(""); document.write("
"); document.write("
"); document.write(" \"\"
"); document.write(" "); document.write(pulldowndata); document.write(" "); document.write("
"); document.write("
"); document.write("
"); document.write(" "); document.write("
"); document.write("
"); document.write("  "); document.write("
"); document.write("
"); document.write("
"); document.write("
"); document.write("
"); // document.write("
"); // document.write(" "); // document.write(" "); // document.write(" "); // document.write(" "); // document.write("
"); // read params from url starts var cUrl = $(location).attr('href'); var isRewrite = true; if (cUrl.indexOf("search_result.aspx?") > 0){ isRewrite = false; } var urlKeyword = ""; var urlWhere = ""; var urlClassNature = ""; if (isRewrite){ urlKeyword = getParameterUrlRewriter(cUrl, "keyword"); urlKeyword = urlKeyword.replaceAll("%2F","/"); urlKeyword = urlKeyword.replaceAll("%5C", "\\"); //urlKeyword = urlKeyword.replaceAll("%2D", "-"); urlWhere = getParameterUrlRewriter(cUrl, "where"); urlWhere = urlWhere.replaceAll("%2F","/"); urlWhere = urlWhere.replaceAll("%5C", "\\"); //urlWhere = urlWhere.replaceAll("%2D", "-"); //alert(urlWhere); urlClassNature = getParameterUrlRewriter(cUrl, "class_nature"); }else{ urlKeyword = getParameterByName("keyword"); urlWhere = getParameterByName("where"); urlClassNature = getParameterByName("class_nature"); if (urlKeyword == keywordTitle){ urlKeyword = ''; } if (urlWhere == whereTitle){ urlWhere = ''; } } $('#search_form #keyword_txtbox').val(urlKeyword); $('#search_form #district_pulldown').val(urlWhere); if (urlClassNature == ''){ urlClassNature = 'ALL'; } $('#search_form input:radio').each(function () { if (urlClassNature.toUpperCase() == $(this).val()){ $(this).attr('checked',true); } }); // read params from url ends //common_at_bottom() starts; var _DISTPULLDOWNFOCUS = false; $(".ypSrh_SelDist_btn, .ypSrh_SelDist_pulldown").mouseover(function () { _DISTPULLDOWNFOCUS = true; }); $(".ypSrh_SelDist_btn, .ypSrh_SelDist_pulldown").mouseout(function () { _DISTPULLDOWNFOCUS = false; }); $(document).click(function () { if (_DISTPULLDOWNFOCUS == false) { $('.ypSrh_SelDist_pulldown').hide(); $('.ypSrh_SelDist_div').css('visibility', 'visible'); $('div.ypSrh_SubDT_div.SubDT_div_hl').find('.ypSrh_SmlDT_div.SmlDT_hl').hide(); } }); $('input[type="text"]').each(function () { if (this.value == ''){ this.value = $(this).attr('title'); $(this).addClass('text-label'); } $(this).focus(function () { if (this.id == 'dist_pulldown') { this.blur() } else { if (this.value == $(this).attr('title')) { this.value = ''; $(this).removeClass('text-label'); } } }); $(this).blur(function () { if (this.value == '') { this.value = $(this).attr('title'); $(this).addClass('text-label'); } }); }); $('textarea').each(function () { this.value = $(this).attr('title'); $(this).addClass('text-label'); $(this).focus(function () { if (this.value == $(this).attr('title')) { this.value = ''; $(this).removeClass('text-label'); } }); $(this).blur(function () { if (this.value == '') { this.value = $(this).attr('title'); $(this).addClass('text-label'); } }); }); //common_at_bottom() ends; } // JavaScript Document $(document).ready(function(){ // function for top search box radio button $('.srhbox_radio_caption').click(function(){ $(this).siblings('input:radio').attr('checked',true) }); // function for top search box pulldown $(".ypSrh_SelDist_btn").click(function(){ $('.ypSrh_SelDist_pulldown').hide(); $(this).parent().find('.ypSrh_SelDist_pulldown').slideDown(400); }); $('.ypSrh_SubDT').hover(function(){ $(this).toggleClass('DT_o') }, function(){ $(this).toggleClass('DT_o') }); $('.ypSrh_SubDT').click(function(){ if ($(this).hasClass('pulldown')) { if ($(this).siblings('.ypSrh_SubDT').hasClass('DT_hl')) { $(this).parents('.ypSrh_SelDist_pulldown').children('.ypSrh_SubDT.pulldown').removeClass('DT_hl') $(this).parents('.ypSrh_SelDist_pulldown').children('.ypSrh_SubDT.pulldown').next().hide() } $(this).next().toggle(300); $(this).toggleClass('DT_hl') } else { $(this).parent().parent().find('.ypSrh_input_dist').attr('value', $(this).attr('alt')); $(this).parent().parent().find('.ypSrh_input_dist').removeClass('text-label'); $(this).parent().parent().find('.ypSrh_SelDist_pulldown').hide(); $('.ypSrh_SelDist_div').css('visibility','visible'); $(this).parents('.ypSrh_SelDist_pulldown').children('.ypSrh_SubDT.pulldown').removeClass('DT_hl') $(this).parents('.ypSrh_SelDist_pulldown').children('.ypSrh_SubDT.pulldown').next().hide() } }); $('.ypSrh_SmlDT_div li').hover(function(){ $(this).css('color','#0572ad'); }, function(){ $(this).css('color','#999'); }); $('.ypSrh_SmlDT_div li').click(function(){ $(this).parents('#srh_dist_pulldown').children().find('.ypSrh_input_dist').attr('value', $(this).attr('alt')); $(this).parents('#srh_dist_pulldown').children().find('.ypSrh_input_dist').removeClass('text-label'); $(this).parents('#srh_dist_pulldown').children().find('.ypSrh_SelDist_pulldown').hide(); $(this).parents('#srh_dist_pulldown').children('.ypSrh_SelDist_div').css('visibility','visible'); $(this).parents('.ypSrh_SmlDT_div').prev().toggleClass('DT_hl') $(this).parents('.ypSrh_SelDist_pulldown').children('.ypSrh_SubDT.pulldown').next().hide() }); }); function noToSearch(){ } function toSearch(language) { $(document).ready(function(){ var keywordTips = $('#search_form #keyword_txtbox').attr('title'); var districtTips = $('#search_form #district_pulldown').attr('title'); if (language == "en") { var strAlert0 = enAlert0; var strAlert1 = enAlert1; var strAlert2 = enAlert2; var strAlert3 = enAlert3; } else if (language == "sc") { var strAlert0 = scAlert0; var strAlert1 = scAlert1; var strAlert2 = scAlert2; var strAlert3 = scAlert3; } else { var strAlert0 = chAlert0; var strAlert1 = chAlert1; var strAlert2 = chAlert2; var strAlert3 = chAlert3; } var strKW = toTrim($("#search_form #keyword_txtbox").val()); if (strKW == "" || strKW == keywordTips) { alert(strAlert0); $("#search_form #keyword_txtbox").focus(); return; } //逗號與雙引號不能同時使用 if (strKW.search(/[,]/g) != -1 && strKW.search(/[\"]/g) != -1) { alert(strAlert1); return; } //最後是空格,避免出現兩個符號間有空格的情況 if (strKW.search(/[^&\"+-.,\'`~!@#$%^*()\=|\\{}\[\]<>?\/:; ]+/) == -1) { //alert(strAlert2 + "\n&\".,-+\'`~!@#$%^*()\=|\\{}\[\]<>?\/:;"); alert(strAlert2); return; } var strK = strKW.toLowerCase() if (strK == "and" || strK == "or" || strK == "not") { //alert(strAlert3 + "and,or,not"); alert(strAlert3); return; } //if (language == "sc") { // strKW = formatHKword(strKW); //} var district = toTrim($("#search_form #district_pulldown").val()); if (district == "" || district == districtTips) { district = ""; } var srhType = getSearchType(); // submit var searchResultUrl = iypSearchResult_Server; //if ("sc" == language) // searchResultUrl = iypSearchResult_Server_SC; var isCache = true; var strCache = getParameterByName("cache"); if (strCache.toUpperCase() == 'N') isCache = false; if (isCache){ strKW = strKW.replaceAll("/","%2F"); strKW = strKW.replaceAll("\\", "%5C"); //strKW = strKW.replaceAll("-", "%2D"); searchResultUrl += "/s-" + encodeURIComponent(strKW); if (district == ''){ searchResultUrl += "/p1/" + language + "/"; }else{ district = district.replaceAll("/","%2F"); district = district.replaceAll("\\", "%5C"); //district = district.replaceAll("-", "%2D"); searchResultUrl += "/w-" + encodeURIComponent(district); searchResultUrl += "/p1/" + language + "/"; } if (srhType != ''){ searchResultUrl += "?class_nature=" + srhType; } } else{ // not url rewrite searchResultUrl += "/IYP_E12/k_search/" + language + "/search_result.aspx?"; searchResultUrl += "&keyword=" + encodeURIComponent(strKW); searchResultUrl += "&where=" + encodeURIComponent(district); searchResultUrl += "&class_nature=" + srhType; searchResultUrl += "&cache=N"; var strRCajax = getParameterByName("ajax"); searchResultUrl += "&ajax=" + strRCajax; } // start statistics function webTraffic(43, sLang, strKW, district, srhType); // end statistics function setIypKeySuggestHistory("keyword_txtbox"); //for keyword suggestion by nienianjun //window.location = searchResultUrl; setTimeout("searchlocation('" + escape(searchResultUrl) + "');", 1); //alert(searchResultUrl); // $("#submit_box").attr("action",searchResultUrl); // $("#submit_box").submit(); }); } function searchlocation(_searchResultUrl) { window.location = unescape(_searchResultUrl); } function toYPMapSeacher(language) { if (language == undefined){ language = "ch"; } var lang = language.toLowerCase(); var strKW = toTrim($("#search_form #keyword_txtbox").val()); var keywordTips = $('#search_form #keyword_txtbox').attr('title'); if (strKW == keywordTips) { strKW = ""; } var ypMapsearchResultUrl = "http://www.ypmap.com/"; if (lang == "sc") { ypMapsearchResultUrl = "http://gb.yp.com.hk/han3/7/6/9/0/0/0/0/www.yp.com.hk/ypmap/"; } ypMapsearchResultUrl += lang; if (strKW == ""){ ypMapsearchResultUrl += "/default.aspx"; }else{ ypMapsearchResultUrl += "/default.aspx?txtKeyword=" + encodeURIComponent(strKW); } webTraffic(84,sLang,ypMapsearchResultUrl); window.open(ypMapsearchResultUrl); } function getSearchType() { var type = ""; var searchTypes = $("#search_form :radio") for (var j = 0; j < searchTypes.length; j++) { if (searchTypes[j].checked) { type = searchTypes[j].value; } } if (type == "ALL") type = ''; return type; } function getParameterByName(name) { name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); var regexS = "[\\?&]" + name + "=([^&#]*)"; var regex = new RegExp(regexS); var results = regex.exec(window.location.search); if(results == null) return ""; else return decodeURIComponent(results[1].replace(/\+/g, " ")); } function getParameterUrlRewriter(url, name) { var value = ""; var re1 = new RegExp("/s-([^/]{1,1000})/([a-z]{2})", "ig"); var re2 = new RegExp("/s-([^/]{1,1000})/p([0-9]{1,3})/([a-z]{2})", "ig"); var re3 = new RegExp("/s-([^/]{1,1000})/w-([^/]{1,1000})/p([0-9]{1,3})/([a-z]{2})", "ig"); if ("class_nature" == name){ var arrP = new Array(); var arrP1 = new Array(); var nature = ''; url= url.replace(/\+/g, " "); arrP = url.split("?"); for (var i = 0; i < arrP.length; i++) { arrP1 = arrP[i].split("=") if (arrP1[0] == "class_nature") { nature = decodeURIComponent(arrP1[1]); } } return nature; }else{ if (re1.exec(url) != null) { switch (name) { case "keyword": value = RegExp.$1; break; case "language": value = RegExp.$2; break; } } else if (re2.exec(url) != null) { switch (name) { case "keyword": value = RegExp.$1; break; case "page": value = RegExp.$2; break; case "language": value = RegExp.$3; break; } } else if (re3.exec(url) != null) { switch (name) { case "keyword": value = RegExp.$1; break; case "where": value = RegExp.$2; break; case "page": value = RegExp.$3; break; case "language": value = RegExp.$4; break; } } } return decodeURIComponent(value); } function toTrim(obj) { obj = obj.replace(/^ */, "") obj = obj.replace(/ *$/, "") return obj }