common.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. [DESTOON B2B System] Copyright (c) 2008-2018 www.destoon.com
  3. This is NOT a freeware, use is subject to license.txt
  4. */
  5. var UA = navigator.userAgent.toLowerCase();
  6. var isIE = (document.all && window.ActiveXObject && !window.opera) ? true : false;
  7. var isGecko = UA.indexOf('webkit') != -1;
  8. var DMURL = document.location.protocol+'//'+location.hostname+(location.port ? ':'+location.port : '')+'/';
  9. if(DTPath.indexOf(DMURL) != -1) DMURL = DTPath;
  10. var AJPath = DMURL+'ajax.php';
  11. var UPPath = DMURL+'upload.php';
  12. if(isIE) try {document.execCommand("BackgroundImageCache", false, true);} catch(e) {}
  13. function Dd(i) {return document.getElementById(i);}
  14. function Ds(i) {Dd(i).style.display = '';}
  15. function Dh(i) {Dd(i).style.display = 'none';}
  16. function Dsh(i) {Dd(i).style.display = Dd(i).style.display == 'none' ? '' : 'none';}
  17. function Df(i) {Dd(i).focus();}
  18. var tID=0;
  19. function Tab(ID) {
  20. var tTab = Dd('Tab'+tID); var tTabs = Dd('Tabs'+tID); var Tab = Dd('Tab'+ID); var Tabs = Dd('Tabs'+ID);
  21. if(ID!=tID) {tTab.className='tab'; Tab.className='tab_on'; tTabs.style.display='none'; Tabs.style.display=''; tID = ID; try{Dd('tab').value=ID;}catch(e){}}
  22. }
  23. function checkall(f, t) {
  24. var t = t ? t : 1;
  25. for(var i = 0; i < f.elements.length; i++) {
  26. var e = f.elements[i];
  27. if(e.type != 'checkbox' || e.name == 'msg' || e.name == 'eml' || e.name == 'sms' || e.name == 'wec') continue;
  28. if(t == 1) e.checked = e.checked ? false : true;
  29. if(t == 2) e.checked = true;
  30. if(t == 3) e.checked = false;
  31. }
  32. }
  33. function Dmsg(str, i, s, t) {
  34. var t = t ? t : 5000; var s = s ? 1 : 0; var h = i == 'content' ? 450 : 50;
  35. try{
  36. if(typeof Dbrowser != 'undefined') {alert(str);return;}
  37. if(s || i == 'content'){$("html, body").animate({scrollTop:$('#d'+i).offset().top-h}, 100);}
  38. Dd('d'+i).innerHTML = '<img src="'+DTPath+'file/image/check-ko.png" width="16" height="16" align="absmiddle"/> '+str;
  39. Dd(i).focus();
  40. }catch(e){}
  41. window.setTimeout(function(){Dd('d'+i).innerHTML = '';}, t);
  42. }
  43. function Inner(i,s) {try {Dd(i).innerHTML = s;}catch(e){}}
  44. function Go(u) {window.location = u;}
  45. function confirmURI(m,f) {if(confirm(m)) Go(f);}
  46. function showmsg(m, t) {
  47. var t = t ? t : 5000; var s = m.indexOf(L['str_delete']) != -1 ? 'delete' : 'ok';
  48. try{Dd('msgbox').style.display = '';Dd('msgbox').innerHTML = m+sound(s);window.setTimeout('closemsg();', t);}catch(e){}
  49. }
  50. function closemsg() {try{Dd('msgbox').innerHTML = '';Dd('msgbox').style.display = 'none';}catch(e){}}
  51. function sound(f) {return '<div style="float:left;"><embed src="'+DTPath+'file/flash/'+f+'.swf" quality="high" type="application/x-shockwave-flash" height="0" width="0" hidden="true"/></div>';}
  52. function Eh(t) {
  53. var t = t ? t : 'select';
  54. if(isIE) {
  55. var arVersion = navigator.appVersion.split("MSIE"); var IEversion = parseFloat(arVersion[1]);
  56. if(IEversion >= 7 || IEversion < 5) return;
  57. $(t).css('visibility', 'hidden');
  58. }
  59. }
  60. function Es(t) {
  61. var t = t ? t : 'select';
  62. if(isIE) {
  63. var arVersion = navigator.appVersion.split("MSIE"); var IEversion = parseFloat(arVersion[1]);
  64. if(IEversion >= 7 || IEversion < 5) return;
  65. $(t).css('visibility', 'visible');
  66. }
  67. }
  68. function FCKLen(i) {return EditorAPI(i, 'len');}
  69. function FCKXHTML(i) {return EditorAPI(i, 'get');}
  70. function Tb(o) {
  71. if(o.className == 'on') return;
  72. var t = o.id.split('-h-'); var p = t[0]; var k = t[1];
  73. $('#'+p+'-h').children().each(function() {
  74. var i = $(this).attr('id').replace(p+'-h-', '');
  75. if(i == k) {
  76. $('#'+p+'-h-'+i).attr('class', 'on');
  77. $('#'+p+'-b-'+i).fadeIn(100);
  78. } else {
  79. $('#'+p+'-h-'+i).attr('class', '');
  80. $('#'+p+'-b-'+i).hide();
  81. }
  82. });
  83. }
  84. function ext(v) {return v.substring(v.lastIndexOf('.')+1, v.length).toLowerCase();}
  85. function GoMobile(url) {
  86. if((UA.indexOf('phone') != -1 || UA.indexOf('mobile') != -1 || UA.indexOf('android') != -1 || UA.indexOf('ipod') != -1) && get_cookie('mobile') != 'pc' && UA.indexOf('ipad') == -1) {
  87. Go(url);
  88. }
  89. }
  90. function PushNew() {
  91. $('#destoon_push').remove();
  92. s = document.createElement("script");
  93. s.type = "text/javascript";
  94. s.id = "destoon_push";
  95. s.src = DTPath+"api/push.js.php?refresh="+Math.random()+".js";
  96. document.body.appendChild(s);
  97. }
  98. function Dnotification(id, url, icon, title, content) {
  99. if(window.webkitNotifications) {
  100. if(webkitNotifications.checkPermission()==1) {
  101. window.onclick = function() {
  102. window.webkitNotifications.requestPermission(function() {
  103. if(webkitNotifications.checkPermission()==0) {
  104. var N = window.webkitNotifications.createNotification(icon, title, content);
  105. N.replaceId = id;N.onclick = function() {window.focus();window.top.location = url;N.cancel();};N.show();
  106. }
  107. });
  108. };
  109. } else if(webkitNotifications.checkPermission()==0) {
  110. var N = window.webkitNotifications.createNotification(icon, title, content);
  111. N.replaceId = id;N.onclick = function() {window.focus();window.top.location = url;N.cancel();};N.show();
  112. }
  113. }
  114. }
  115. function set_cookie(n, v, d) {
  116. var e = '';
  117. var f = d ? d : 365;
  118. e = new Date((new Date()).getTime() + f * 86400000);
  119. e = "; expires=" + e.toGMTString();
  120. document.cookie = CKPrex + n + "=" + v + ((CKPath == "") ? "" : ("; path=" + CKPath)) + ((CKDomain =="") ? "" : ("; domain=" + CKDomain)) + e;
  121. }
  122. function get_cookie(n) {
  123. var v = ''; var s = CKPrex + n + "=";
  124. if(document.cookie.length > 0) {
  125. o = document.cookie.indexOf(s);
  126. if(o != -1) {
  127. o += s.length;
  128. end = document.cookie.indexOf(";", o);
  129. if(end == -1) end = document.cookie.length;
  130. v = unescape(document.cookie.substring(o, end));
  131. }
  132. }
  133. return v;
  134. }
  135. function del_cookie(n) {var e = new Date((new Date()).getTime() - 1 ); e = "; expires=" + e.toGMTString(); document.cookie = CKPrex + n + "=" + escape("") +";path=/"+ e;}
  136. function set_local(n, v) {window.localStorage ? localStorage.setItem(CKPrex + n, v) : set_cookie(n, v);}
  137. function get_local(n) {return window.localStorage ? localStorage.getItem(CKPrex + n) : get_cookie(n);}
  138. function del_local(n) {window.localStorage ? localStorage.removeItem(CKPrex + n) : del_cookie(n);}
  139. function substr_count(str, exp) {if(str == '') return 0;var s = str.split(exp);return s.length-1;}
  140. function checked_count(id) {return $('#'+id+' :checked').length;}
  141. function lang(s, a) {for(var i = 0; i < a.length; i++) {s = s.replace('{V'+i+'}', a[i]);} return s;}
  142. function get_cart() {var cart = parseInt(get_cookie('cart'));return cart > 0 ? cart : 0;}
  143. function cutstr(str, mark1, mark2) {
  144. var p1 = str.indexOf(mark1);
  145. if(p1 == -1) return '';
  146. str = str.substr(p1 + mark1.length);
  147. var p2 = str.indexOf(mark2);
  148. if(p2 == -1) return str;
  149. return str.substr(0, p2);
  150. }
  151. document.onkeydown = function(e) {
  152. var k = typeof e == 'undefined' ? event.keyCode : e.keyCode;
  153. if(k == 37) {
  154. try{if(Dd('destoon_previous').value && typeof document.activeElement.name == 'undefined')Go(Dd('destoon_previous').value);}catch(e){}
  155. } else if(k == 39) {
  156. try{if(Dd('destoon_next').value && typeof document.activeElement.name == 'undefined')Go(Dd('destoon_next').value);}catch(e){}
  157. } else if(k == 38 || k == 40 || k == 13) {
  158. try{if(Dd('search_tips').style.display != 'none' || Dd('search_tips').innerHTML != ''){SCTip(k);return false;}}catch(e){}
  159. }
  160. }
  161. $(function(){
  162. $(window).bind("scroll.back2top", function() {
  163. var st = $(document).scrollTop(), winh = $(window).height();
  164. (st > 0) ? $('.back2top').show() : $('.back2top').hide();
  165. if(!window.XMLHttpRequest) { $('.back2top').css("top", st + winh - 166);}//IE6
  166. });
  167. $('.back2top').click(function() {
  168. $('html, body').animate({scrollTop:0}, 200);
  169. });
  170. var vip = $('.vipGo');
  171. var vip_shadow = $('.vip-shadow');
  172. var vip_close = $('#close_vip');
  173. vip.mouseover(function(){
  174. $(this).css('animation-play-state','paused');
  175. vip_shadow.css('animation-play-state','paused');
  176. }).mouseout(function(){
  177. $(this).css('animation-play-state','running');
  178. vip_shadow.css('animation-play-state','running');
  179. });
  180. vip_close.click(function () {
  181. vip.remove();
  182. vip_shadow.remove();
  183. });
  184. function send_url() {
  185. var search_value = $('#destoon_kw').val();
  186. if(search_value.length < 2 || search_value === '请输入关键词') return;
  187. location.href = '/company/search.php?kw='+encodeURI(search_value);
  188. }
  189. function news_url() {
  190. var search_value = $('.sort-value').val();
  191. if(search_value.length <= 0) return;
  192. location.href = '/news/search.php?kw='+encodeURI(search_value);
  193. }
  194. $('.head_search').find('input:submit').click(function() {
  195. send_url();
  196. });
  197. $('#destoon_kw').keydown(function(event) {
  198. if(event.keyCode != 13) return;
  199. send_url();
  200. });
  201. $('.sort-v').find('input:submit').click(function() {
  202. news_url();
  203. });
  204. });