/* String */ String.prototype.trim = function(){ return this.replace(/^\s+|\s+$/g,''); } String.prototype.ltrim = function() { return this.replace(/^\s+/,''); } String.prototype.rtrim = function() { return this.replace(/\s+$/,''); } function change_language(lang) { if (typeof localStorage!=='undefined') localStorage.removeItem('ui_currency_rate'); $.cookie('ui_lang_pref',lang,{domain:'.price.com.hk', path:'/'}); location.reload(); } /* Image */ function imgOvr(){ obj = getTarget(); pos = obj.src.lastIndexOf('.'); if (pos>=0) obj.src = obj.src.substring(0,pos)+'_o'+obj.src.substring(pos); } function imgOut(){ obj = getTarget(); obj.src = obj.src.replace('_o.','.'); } function getEvent(){ if (document.all) return window.event; func = getEvent.caller; while (func!=null){ var arg0=func.arguments[0]; if (arg0){ if((arg0.constructor==Event||arg0.constructor==MouseEvent)||(typeof(arg0)=='object'&&arg0.preventDefault&&arg0.stopPropagation)) return arg0; } func=func.caller; } return null; } function getTarget(){ var evt = getEvent(); return evt.srcElement||evt.target; } /* Add custom events to mootools */ //Element.NativeEvents.push('propertychange','input'); /* If value is empty, param will be removed */ function replaceQueryString(url, param, value){ var preUrl = ''; var postUrl = ''; var newUrl = ''; start = url.indexOf(param+'='); if(start>-1){ if (value==''){ preUrl = url.substring(0,start-1); }else{ end = url.indexOf('=', start); preUrl = url.substring(0,end)+'='+value; } startRest = url.indexOf('&',start); postUrl = ''; if(startRest>-1){ postUrl = url.substring(startRest); } }else{ if (value=='') return url; preUrl = url; if (url.indexOf('?')>-1) postUrl = '&'+param+'='+value; else postUrl = '?'+param+'='+value; } newUrl = preUrl+postUrl; return newUrl; } function getObjectPos(obj){ var curleft = curtop = 0; if (obj.offsetParent){ do { curleft += obj.offsetLeft; curtop += obj.offsetTop; } while (obj = obj.offsetParent); } return {x:curleft,y:curtop}; } function setRecentView(k,v,max){ k = 'ui_recent_'+k; var sep = '\n'; var oValue = $.cookie(k); var nValue = v+(oValue==null?'':sep+oValue.split(sep,max-1).join(sep)); $.cookie(k,nValue,{domain:'.price.com.hk', path:'/'}); } function setCurrCategory(c){ $.cookie('ui_curr_category',c,{domain:'.price.com.hk', path:'/'}); } function addBookmark(type,type_id,target) { var btn = $(target).parent('li.function-bookmark'); if (type != '' && type_id != '') { $.getJSON("bookmark_add.php", { type: type, type_id: type_id }, function(j) { if(j[0].type == 'error') { alert(j[0].message); $(btn).removeClass('active'); if (type == 'ec'){ // $(target).html('收藏項目'); }else if (type == 'trade'){ $(target).attr('value', '收藏項目'); } return false; } if(j[0].type == 'success'){ if (type == 'product' || type == 'merchant'){ $(btn).addClass('active'); $(btn).find('a').text($(target).attr('data-deletebookmark')); $(btn).find('a').attr('onclick', $(btn).find('a').attr('onclick').replace('addBookmark', 'deleteBookmark')); }else{ $(target).addClass('active'); if (type == 'ec'){ $(target).attr('alt','已收藏').attr('title','已收藏'); } } } if(j[0].code=='login'){ location = '/login.php'; } }); } } function deleteBookmark(type,type_id,target) { var btn = $(target).parent('li.function-bookmark'); if (type != '' && type_id != '') { $.getJSON("bookmark_delete.php", { type: type, type_id: type_id }, function(j) { if(j[0].type == 'error') { alert(j[0].message); $(btn).addClass('active'); return false; } if(j[0].type == 'success'){ if (type == 'product' || type == 'merchant'){ $(btn).removeClass('active'); $(btn).find('a').text($(target).attr('data-addbookmark')); $(btn).find('a').attr('onclick', $(btn).find('a').attr('onclick').replace('deleteBookmark', 'addBookmark')); }else{ $(target).removeClass('active'); if (type == 'ec'){ $(target).attr('alt','收藏').attr('title','收藏'); } } } //alert(j[0].message); }); } } function preSubmitForm(f){ f.action = f.action+(f.action.indexOf('?')>=0?'&':'?')+'f='+Math.random(); } function selectRows(c){ obj = document.getElementsByName('key_list[]'); if (obj.length){ for (i=0; i'+col[1]+''; } }else{ content = '
沒有任何瀏覽記錄
'; } content += ''; RP_lyr.innerHTML = content; } } function hideRP(){ RP_timer = setTimeout('showRP(false)',350); } function randomStr() { var text = ""; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for( var i=0; i < 10; i++ ) text += possible.charAt(Math.floor(Math.random() * possible.length)); return text; } function showBrowseHistory(s){ var content = ''; var RP_lyr = document.getElementById('browse-history-box'); if (s==true){ if(!$('[data-caret="history"]').parent().hasClass('dropup')){ //clearTimeout(RP_timer); if (RP_list){ var row = RP_list.split(RP_sep1); var count = row.length; for (i=1;i'+col[1]+''; } $(RP_lyr).find(".list-empty").hide(); $(RP_lyr).find("ul.list-unstyled").html(content); }else{ $(RP_lyr).find(".list-empty").show(); $(RP_lyr).find("ul.list-unstyled").html(''); } if(getCookie('ui_lang_pref') == 'zh_CN'){ //lang to zh_CN StranBody(RP_lyr); } //$(RP_lyr).show(); $(RP_lyr).slideDown(function(){ $(document).on('click',closeHandler); }); $('[data-caret="history"]').parent('.browse-history-a').addClass('dropup'); var closeHandler = function (e) { var container = $("#browse-history-box"); if (!container.is(e.target) // if the target of the click isn't the container... && container.has(e.target).length === 0) // ... nor a descendant of the container { e.stopPropagation(); $(document).off('click',closeHandler); $('[data-caret="history"]').parent('.browse-history-a').removeClass('dropup'); container.slideUp(); } } } else { $(RP_lyr).slideUp(); $('[data-caret="history"]').parent('.browse-history-a').removeClass('dropup'); } }else{ $(RP_lyr).slideUp(); $('[data-caret="history"]').parent('.browse-history-a').removeClass('dropup'); } } function hideBrowseHistory(){ RP_timer = setTimeout(function(){showBrowseHistory(false)},350); } function setRpCookie(pid,pname){ var maxList = 10, count = 1; var newList = RP_sep1+pid+RP_sep2+pname; if (RP_list){ var row = RP_list.split(RP_sep1); var needle = pid+RP_sep2; for (i=1;i=0?1:0); loginStatusNew = $.cookie('ui_authcode')?1:0; if (loginStatusNew!=loginStatus){ if (loginStatusNew==1){ var site = String($.cookie('ui_forum')).toUpperCase(); txt = ' '+$.cookie('ui_uname')+ ' | 我的賬戶'+ ' '; }else{ txt = '遊客 '; } oLogin.innerHTML = txt; } } } /*function logout(){ $.cookie('ui_authcode',null,{domain:'.price.com.hk', path:'/'}); $.cookie('ui_autologin_str',null,{domain:'.price.com.hk', path:'/'}); $.cookie('ui_uid',null,{domain:'.price.com.hk', path:'/'}); $.cookie('ui_uname',null,{domain:'.price.com.hk', path:'/'}); $.cookie('ui_forum',null,{domain:'.price.com.hk', path:'/'}); $.cookie('ui_last_page_access',null,{domain:'.price.com.hk', path:'/'}); if (location.href.indexOf('member.php')>=0 || location.href.indexOf('logout.php')>=0){ location.href = '/'; }else if (location.href.indexOf('#')>=0){ location.href = window.location.href.split('#')[0]; } else{ location.href = location.href; } }*/ // Cookie test var cookieEnabled = false; if (navigator.cookieEnabled){ $.cookie('ui_cookietest','1',{domain:'.price.com.hk', path:'/'}); if ($.cookie('ui_cookietest')) cookieEnabled = true; $.cookie('ui_cookietest',null,{domain:'.price.com.hk', path:'/'}); } function set_cookie(key,val){ $.cookie(key,val,{domain:'.price.com.hk'}); } function fbs_click(page,url){ if (url==null) u = location.href; else u = url; w = window.open('https://www.facebook.com/sharer.php?u='+encodeURIComponent(u),'sharer',centralize(626,436)+',toolbar=0,status=0'); w.focus(); return false; } // google analytics event tracking function ga_trackEvent(link,category,action){ var is_new_tab = false; try{ var event = window.event || arguments.callee.caller.arguments[0]; if( (event.button == 0 && event.ctrlKey == true) || (event.button == 1) || (event.button == 0 && event.metaKey == true) ) is_new_tab = true; }catch(err){ } try{ pageTracker._trackEvent(category,action); if (link && link.target!='_blank' && !is_new_tab) { setTimeout('document.location = "' + link.href + '"', 100); return false; } }catch(err){ return true; } if(link && is_new_tab){ window.open(link.href, "_blank"); window.focus(); return false; }else if (link) { return link.target!='_blank'?false:true; } else { return false; } } function centralize(w,h){ l = Math.floor((screen.width-w)/2); t = Math.floor((screen.height-h-100)/2); s = 'left='+l+',top='+t+',height='+h+',width='+w; return s; } // Fix IE6 background image problem try { document.execCommand("BackgroundImageCache", false, true); } catch(err) {} // Fix firefox history.back issue window.onunload = function(){}; // Load fancybox var _fb_iframe_opt = { 'onStart' : function(obj){ if ($(obj).data('id') == 'popup_login'){ $('#fancybox-outer').hide(); } $('body').css({'overflow':'hidden'}); if(this.href.match(/forms\/order.php(.*)/)){ this.width = 680; this.height = 630; }else if(this.href.match(/map.php(.*)/)){ this.width = 780; this.height = 440; } }, 'onComplete' :function(){ //setTimeout(function(){ $.fancybox.showActivity(); }, 0); $.fancybox.showActivity(); //fix fancybox 1.3.1 double call iframe bug var self = this; setTimeout(function(){ if(!$("#fancybox-frame").attr('src')){ $("#fancybox-frame").attr('src', self.href); } }, 100); if(typeof im_sidebarshowed != 'undefined' && im_sidebarshowed){ im_fancybox_open = true; hideSidebar(); } /* var timeoutfunction; $( window ).resize(function() { $.fancybox.showActivity(); clearTimeout(timeoutfunction); timeoutfunction = setTimeout(function(){ resizeFancyBox();}, 1000); }); */ }, 'onClosed': function(){ if(typeof im_fancybox_open != 'undefined' && im_fancybox_open){ im_fancybox_open = false; showSidebarEffect(); } $('body').css({'overflow':'auto'}); $( window ).unbind( 'resize' ); $( window ).unbind( 'resize' ); $('.fancy-bg').css('display',''); $('#fancybox-outer').css('background',''); }, 'hideOnOverlayClick':false, 'hideOnContentClick':false, 'type':'iframe', 'autoScale':false, 'autoDimensions':false, 'titleShow':false, 'height' : "90%", 'width' : 840, }; $(document).ready(function(){ $('a.fb').fancybox({ 'padding':15 }); //add this prevent fancybox clicking before docement ready $('a.fb_iframe').each(function() { if($(this).attr('href')=='javascript:void(0)') $(this).attr('href', $(this).attr('data-tmp-href')); }); // disable pop up new window for referral buy, when ads are loaded $('a.fb_iframe.-fast').each(function(){ $(this).prop('onclick', null); $(this).attr('target', '_self'); }); $('a.fb_iframe').fancybox(_fb_iframe_opt); }); /* var timer; $(".zone").live({ mouseenter: function(event){ var self = $(this); timer = setTimeout(function(){ self.children(".zoneName").addClass("active"); self.children(".group").slideDown(200).removeClass("hidden"); },100); }, mouseleave: function(event){ var self = $(this); clearTimeout(timer); self.children(".zoneName").removeClass("active"); self.children(".group").slideUp(200).addClass("hidden"); } }).ready(function(){ $(this).find(".group").addClass('hidden'); }); */ function isPositiveInt(s) { i = parseInt(s,10); if (isNaN(i)){ return false; }else if (i<=0){ return false; }else{ if (i.toString().length!=s.length) return false; } return true; } function isPhone(s){ var valid = true; var lastChar = ""; var repeat = 1; if (!s.match(/^[2-9]\d{7}$/)) return false; for (i = 0 ; i < s.length ; i++) { chr = s.charAt(i); // check repeat phone number eg:11111111, 22222222 repeat = (chr == lastChar) ? repeat + 1 : 1 lastChar = chr; } if (repeat == s.length) valid = false; return valid; } function isMobile(s){ var rtn = s.length==8?(!/[\D \-]/.test(s)):false; if (rtn){ var firstNum = s.substring(0,1); if (firstNum!='4'&&firstNum!='5'&&firstNum!='6'&&firstNum!='7'&&firstNum!='9') rtn = false; } return rtn; } function isEmail(email){ var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return email.match(re); } function gotoPage(max) { var url = location.pathname + location.search; var page = document.getElementById('pager_page').value; if (page != undefined || page != "") { if (page>max) page = 1; url = replaceQueryString(url, 'page', page); location.href = url; } } function textOverflowEllipsis(){ $(".text-overflow").each(function(i){ var divH = $(this).outerHeight(); var $p = $("a,span", $(this)).eq(0); var i = 0; if($p.outerHeight() > divH){ while ($p.outerHeight() > divH) { if(i > 256) break; $p.text($p.text().replace(/(\s)*([a-zA-Z0-9]+|\W|\w)(\.\.\.)?$/, "...")); i++; }; } }); } $(document).ready(function() { $('#pager_page').keydown(function(event) { var charCode = event.which; if (event.shiftKey || (charCode > 31 && charCode < 48) || (charCode > 57 && charCode < 96) || (charCode > 105)) { return false; } if (charCode == 13) { $("#pager_page_btn").click(); } }); //handle index news desc // announ-box var announcement_obj = (function($) { var is_loaded = false; var annou = {}; var output_html = ''; var unread ; function get_data_from_server(){ return $.post( "/ajax.php?ct=get_announ_heading", function( data ) { data = JSON.parse(data); annou = data; }); } function reloadCtn(){ return $.get( "/ajax.php?ct=get_announ_ctn", function( data ) { data = JSON.parse(data); unread = data.display ; }); } function genHtmlOutput(){ for (var item in annou) { output_html += '
  • '+annou[item]['title']+''; if(annou[item]['is_new'] == '1') output_html += 'new'; output_html += '
  • '; } } return { getData:function(cb){ if(!is_loaded){ get_data_from_server().success(function(){ is_loaded = true; cb(annou); }); } else { cb(annou); } }, getHtml:function(){ if(output_html == '') genHtmlOutput(); return output_html; }, getUnread:function(cb){ reloadCtn().success(function(){ cb(unread); }); }, } })($); $("[data-announ-show]").click( function(e){ $('.annuncement-box').slideDown(400, function() { $(this).addClass('dropup'); $(document).on('click',closeHandler); $('[data-announ-loading]').show(); announcement_obj.getData(function(annou){ $('[data-announ-loading]').hide(); var ann_html =announcement_obj.getHtml(); if(ann_html.length > 0){ $('[data-announ-list="true"]').html(ann_html); $('[data-announ-empty]').hide(); $('[data-announ-unempty]').show(); } else{ $('[data-announ-empty]').show(); $('[data-announ-unempty]').hide(); } }); }); var closeHandler = function (e) { var container = $(".annuncement-box"); if (!container.is(e.target) // if the target of the click isn't the container... && container.has(e.target).length === 0 && !$(this).attr('[data-cart-show]')) // ... nor a descendant of the container { $(document).off('click',closeHandler); $('[annuncement-box]').removeClass('dropup'); e.stopPropagation(); container.slideUp(); } } } ); $("[data-announ-need-reload='1']").each(function(){ announcement_obj.getUnread(function(unread){ if(unread>0) { console.log(unread); $('[data-announ-unread-total]').html(unread).show(); } }); }); // end announ-box }); // For recent ec product // var ECRP_sep1 = '#ID#', ECRP_sep2 = '#NAME#', ECRP_sep3 = '#IMG#'; var ECRP_sep1 = '#ID#', ECRP_sep2 = '##'; var ECRP_list = $.cookie('ui_ec_recent_product'); var ECRP_timer; function setECRpCookie(ecpid){ var maxList = 10, count = 1; var newList = ECRP_sep1+ecpid; if (ECRP_list){ var row = ECRP_list.split(ECRP_sep1); var needle = ecpid; for (i=1;i