function.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. String.prototype.trim = function () {
  2. var str = this,
  3. str = str.replace(/^\s+/, '');
  4. for (var i = str.length - 1; i >= 0; i--) {
  5. if (/\S/.test(str.charAt(i))) {
  6. str = str.substring(0, i + 1);
  7. break;
  8. }
  9. }
  10. return str;
  11. }
  12. Array.prototype.Contain = function(item){
  13. var array = this;
  14. for(var i=array.length-1;i>=0;i--){
  15. if(array[i]==item)
  16. return true;
  17. }
  18. return false;
  19. }
  20. var _browser = (function (a) {
  21. var r = /(webkit)[ \/]([\w.]+)/,
  22. s = /(opera)(?:.*version)?[ \/]([\w.]+)/,
  23. t = /(msie) ([\w.]+)/,
  24. u = /(mozilla)(?:.*? rv:([\w.]+))?/;
  25. var b = r.exec(a) || s.exec(a) || t.exec(a) || a.indexOf("compatible") < 0 && u.exec(a) || [];
  26. return {
  27. name: b[1] || "",
  28. version: b[2] || "0"
  29. };
  30. })(window.navigator.userAgent.toLowerCase());
  31. /*取cookies*/
  32. var getCookie = function (c_name) {
  33. if (document.cookie.length > 0) {
  34. c_start = document.cookie.indexOf(c_name + "=");
  35. if (c_start != -1) {
  36. c_start = c_start + c_name.length + 1;
  37. c_end = document.cookie.indexOf(";", c_start);
  38. if (c_end == -1) c_end = document.cookie.length;
  39. return decodeURIComponent(document.cookie.substring(c_start, c_end));
  40. }
  41. }
  42. return "";
  43. }
  44. var showadvert = function(url,objId){
  45. var xmlhttp;
  46. if (window.XMLHttpRequest)
  47. { xmlhttp = new XMLHttpRequest(); }
  48. else
  49. { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  50. xmlhttp.onreadystatechange = function () {
  51. if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
  52. var _txt = xmlhttp.responseText;
  53. _txt = _txt.replace("document.write(\"","");
  54. _txt = _txt.replace("\")","");
  55. _txt = _txt.split("\\").join("");
  56. if(objId)
  57. document.getElementById(objId).innerHTML = _txt;
  58. }
  59. }
  60. xmlhttp.open("GET", url, true);
  61. xmlhttp.send();
  62. }
  63. var showSelectBox=function(){
  64. $(document).click(function(event){
  65. var _box = $(".mSelectBox");
  66. var _select=_box.children(".mSelect");
  67. var _list = _box.children(".mSelectList");
  68. if(_browser.name == "msie") {
  69. if(event.srcElement.className=="mSelect"){
  70. if(_list.css("display")=="block"){
  71. _list.css("display","none");
  72. }else{_list.css("display","block");}
  73. }
  74. else{_list.css("display","none");}
  75. }else {
  76. if($(event.target).attr("class")=="mSelect"){
  77. if(_list.css("display")=="block"){
  78. _list.css("display","none");}
  79. else{_list.css("display","block");}
  80. }
  81. else{_list.css("display","none");}
  82. }
  83. });
  84. }
  85. var showNavSelect=function(){
  86. var tab=$("#chooserTab");
  87. var box = $("#chooserBox");
  88. tab.hover(
  89. function(){box.slideDown("fast");},
  90. function(){box.slideUp("fast");}
  91. );
  92. }
  93. var scrollTrend = function(){
  94. if (_browser.name == "msie" && parseInt(_browser.version) == 6) {
  95. return true;
  96. }
  97. var position = "fixed";
  98. var b = $("#chartBody");
  99. var p={t:b.offset().top,h:b.height()};
  100. $("div.scrollBanner").each(function () {
  101. var $this = $(this);
  102. var st = $(window).scrollTop();
  103. if (st >= p.t&& st<p.t+p.h) {
  104. $this.css({ position: position,display:"block"});
  105. }else{$this.hide();}
  106. });
  107. }
  108. //设为首页
  109. var sethomepage = function (url) {
  110. if (document.all) {
  111. document.body.style.behavior = 'url(#default#homepage)';
  112. document.body.setHomePage(window.location.href);
  113. } else if (window.sidebar) {
  114. if (window.netscape) {
  115. try {
  116. netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  117. } catch (e) {
  118. alert("该操作被浏览器拒绝,如果想启用该功能,请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true");
  119. }
  120. }
  121. var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
  122. prefs.setCharPref('browser.startup.homepage', window.location.href);
  123. } else {
  124. alert('您的浏览器不支持自动设置首页, 请使用浏览器菜单手动设置!');
  125. }
  126. }
  127. //加入收藏
  128. var addfav = function () {
  129. if (document.all) {
  130. try {
  131. window.external.addFavorite(window.location.href, document.title);
  132. } catch (e) {
  133. alert("加入收藏失败,请使用Ctrl+D进行添加");
  134. }
  135. } else if (window.sidebar) {
  136. window.sidebar.addPanel(document.title, window.location.href, "");
  137. } else {
  138. alert("加入收藏失败,请使用Ctrl+D进行添加");
  139. }
  140. }
  141. //图片缩放 参数(图片,允许的宽度,允许的高度)
  142. function DrawImage(ImgD, iwidth, iheight) {
  143. var image = new Image();
  144. image.src = ImgD.src;
  145. if (image.width > 0 && image.height > 0) {
  146. if (image.width / image.height >= iwidth / iheight) {
  147. if (image.width > iwidth) {
  148. ImgD.width = iwidth;
  149. ImgD.height = (image.height * iwidth) / image.width;
  150. } else {
  151. ImgD.width = image.width;
  152. ImgD.height = image.height;
  153. }
  154. }
  155. else {
  156. if (image.height > iheight) {
  157. ImgD.height = iheight;
  158. ImgD.width = (image.width * iheight) / image.height;
  159. } else {
  160. ImgD.width = image.width;
  161. ImgD.height = image.height;
  162. }
  163. }
  164. }
  165. }