/* * version : 2.6 */ 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*$/,""));} var zj = { sethome: function () { var url = document.location.protocol + "//" + document.location.hostname; if (document.all) { document.body.style.behavior = 'url(#default#homepage)'; document.body.sethomepage(url); } else if (window.sidebar) { if (window.netscape) { try { netscape.security.privilegemanager.enableprivilege("universalxpconnect"); } catch (e) { alert("该操作被浏览器拒绝"); } } var prefs = components.classes['@mozilla.org/preferences-service;1'].getservice(components.interfaces.nsiprefbranch); prefs.setcharpref('browser.startup.homepage', url); } }, addfavorite: function (url, title) { try { if (url == null) url = document.location.href; if (title == null) title = document.title; if (document.all) { window.external.addfavorite(url, title); } else if (window.sidebar) { window.sidebar.addpanel(title, url, ""); } } catch (e) { alert("加入收藏失败,请使用ctrl+d进行添加"); } }, getcookie: function (name) { var cookie_start = document.cookie.indexof(name); var cookie_end = document.cookie.indexof(";", cookie_start); if (cookie_start == -1) { return ""; } else { var length = cookie_end > cookie_start ? cookie_end : document.cookie.length; var val = document.cookie.substring(cookie_start + name.length + 1, length); return unescape(val); } }, setcookie: function (cookiename, cookievalue, seconds, path, domain, secure) { var expires = new date(); expires.settime(expires.gettime() + seconds); document.cookie = escape(cookiename) + '=' + escape(cookievalue) + (expires ? '; expires=' + expires.togmtstring() : '') + (path ? '; path=' + path : '/') + (domain ? '; domain=' + domain : '') + (secure ? '; secure' : ''); }, deletecookie: function (name) { var date = new date(); date.settime(date.gettime() - 10000); document.cookie = name + "=a; expires=" + date.togmtstring(); }, enter: function (event, linkopentype) { if (event.keycode == 13 && !(event.srcelement && (event.srcelement.tagname.tolowercase() == "textarea"))) { var defaultbutton = jquery(linkopentype); if (defaultbutton && typeof (defaultbutton.click) != "undefined") { defaultbutton.click(); event.cancelbubble = true; if (event.stoppropagation) event.stoppropagation(); return false; } } return true; }, tabover: function (tabname, divname, hovercss) { jquery("[name='" + tabname + "'] li").hover(function () { jquery("[name='" + divname + "'] > div").hide(); jquery("[name='" + tabname + "'] li").removeclass(hovercss); alert(jquery("[name='" + divname + "'] > div").eq(jquery(this).index()).html()); jquery("[name='" + divname + "'] > div").eq(jquery(this).index()).show(); }, function () { }); }, tabclick: function (tabname, divname, hovercss) { jquery("[name='" + tabname + "'] li").click(function () { jquery("[name='" + divname + "'] > div").hide(); jquery("[name='" + tabname + "'] li").removeclass(hovercss); jquery(this).addclass(hovercss); jquery("[name='" + divname + "'] > div").eq(jquery(this).index()).show(); }); }, getquery: function (name, defaultvalue) { var vstr = defaultvalue; var search = document.location.search.tolowercase(); search = search.substring(1, search.length); var arr = search.split("&"); for (i = 0; i < arr.length; i++) { var temp = arr[i].split("="); if (temp[0] == name) { vstr = temp[1]; break; } } return vstr; }, getquery2: function (search, name) { var vstr = ""; search = search.tolowercase(); search = search.substring(1, search.length); var arr = search.split("&"); for (i = 0; i < arr.length; i++) { var temp = arr[i].split("="); if (temp[0] == name) { vstr = temp[1]; break; } } return vstr; }, addquery: function (name, value) { var path = document.location.pathname; var search = document.location.search.tolowercase(); search = search.substring(1, search.length); var newsearch = "?"; var arr = search.split("&"); for (i = 0; i < arr.length; i++) { if (arr[i] == "") continue; var temp = arr[i].split("="); if (temp[0] == name) continue; newsearch += arr[i] + "&"; } newsearch += name + "=" + value; return path + newsearch; }, addquery2: function (url, name, value) { var arr = url.split('?'); if (arr.length == 1) return url + "?" + name + "=" + value; var path = arr[0]; var search = arr[1]; var newsearch = "?"; var arr1 = search.split("&"); for (i = 0; i < arr1.length; i++) { var temp = arr1[i].split("="); if (temp[0] == name) continue; newsearch += arr1[i] + "&"; } newsearch += name + "=" + value; return path + newsearch; }, getdomain: function () { var url = document.location.protocol + "//" + document.location.host; return url; }, validtip: function (tipcss) { jquery(tipcss).each(function () { var inputid = jquery(this).attr("controltovalidate"); var w = jquery("#" + inputid).width(); var offset = jquery("#" + inputid).offset(); var l = offset.left; var t = offset.top; jquery(this).css({ left: l + w, top: t }); }); }, validtipv: function (tipcss) { jquery(tipcss).each(function () { var inputid = jquery(this).attr("controltovalidate"); var h = jquery("#" + inputid).height(); var offset = jquery("#" + inputid).offset(); var l = offset.left; var t = offset.top; jquery(this).css({ left: l, top: t + h }); }); }, fiximagesize: function (filter, w, h) { if (filter == null) return; if (w == null) w = 700; if (h == null) h = 2000; jquery(filter).find("img").bind("load", function () { var img = jquery(this).get(0); var heightwidth = img.offsetheight / img.offsetwidth; var widthheight = img.offsetwidth / img.offsetheight; if (img.offsetheight > 1) if (img.readystate != "complete") { return false; //确保图片完全加载 } if (img.offsetwidth > w) { img.width = w; img.height = w * heightwidth; } if (img.offsetheight > h) { img.height = h; img.width = h * widthheight; } }); } };