/* ---------------------------------- js 基础类 小男(sman) 2006-07-11 最后修改 小男(sman) 2007-01-31 -----------------------------------*/ var BASE_PATH = "http://www.chinachugui.com/System/Js/"; var IE = document.all; /*得到对象或对象数组(document.getElementById)*/ function $() { var elements = new Array(); for (var i = 0; i < arguments.length; i++) { var element = arguments[i]; if (typeof element == 'string') element = document.getElementById(element); elements.push(element); } if (arguments.length == 1) return elements[0]; return elements; } document.$ = $ //document.write function $W(str){ document.write(str); } //得到同名(ID)对象数组 function $N(objName){ return document.getElementsByName(objName); } //对象绝对位置 function $Px(e){ var x=e.offsetLeft; while(e=e.offsetParent){ x+=e.offsetLeft; } return x; } function $Py(e){ var y=e.offsetTop; while(e=e.offsetParent){ y+=e.offsetTop; } return y } //显示隐藏对象 //返回是否显示 function $SH(objName){ var obj = $(objName); if (obj){ if (obj.style.display=="none"){ obj.style.display = "block" }else{ obj.style.display = "none" } }else{ return false; } } //设置对象属性 function setAttribute(element,sAttrName,sValue){ var obj = $(element); if (obj){ eval("obj."+sAttrName+"=sValue"); } } //包含本文件夹中的JS文件 function Import(strFileName){ $W(''); } function gc() {   if (IE)   {     CollectGarbage();     setTimeout("CollectGarbage();", 5000);   } } //setTimeout 传函数 var _st = window.setTimeout; window.setTimeout = function(fRef, mDelay) { if(typeof fRef == 'function'){ var argu = Array.prototype.slice.call(arguments,2); var f = (function(){ fRef.apply(null, argu); }); return _st(f, mDelay); } return _st(fRef,mDelay); } /*------String------*/ //去首尾空格 String.prototype.trim = function(){ if(!this) return ""; return this.replace(/(^[\s  \t\r\n]+)|([\s  \t\r\n]+$)/gm, ""); } //字符串长度(中文2) String.prototype.Length = function(){ if(!this)return ""; return this.length + this.replace(/[\u0000-\u00ff]+/g,"").length } String.prototype.delHTML = function(){ return this.replace(/<\/?[^>]+>/gi, ''); } String.prototype.Right = function (N){ if(!N)return this return this.substr(this.length - N, N) } //转义HTML String.prototype.escapeHTML = function() { var div = document.createElement('div'); var text = document.createTextNode(this); div.appendChild(text); return div.innerHTML; } //escapeHTML的反转 String.prototype.unescapeHTML = function() { var div = document.createElement('div'); div.innerHTML = this.delHTML(); return div.childNodes[0] ? div.childNodes[0].nodeValue : ''; } String.prototype.toArray = function() { return this.split(''); } String.prototype.getSafeRegEx = function(){ var strout = this; strout = strout.replace(/\\/g,"\\\\"); strout = strout.replace(/\|/g,"\\|"); strout = strout.replace(/\./g,"\\."); strout = strout.replace(/\^/g,"\\^"); strout = strout.replace(/\$/g,"\\$"); strout = strout.replace(/\[/g,"\\["); strout = strout.replace(/\]/g,"\\]"); strout = strout.replace(/\(/g,"\\("); strout = strout.replace(/\)/g,"\\)"); strout = strout.replace(/\{/g,"\\{"); strout = strout.replace(/\}/g,"\\}"); strout = strout.replace(/\+/g,"\\+"); strout = strout.replace(/\?/g,"\\?"); strout = strout.replace(/\,/g,"\\,"); strout = strout.replace(/\=/g,"\\="); strout = strout.replace(/\!/g,"\\!"); strout = strout.replace(/\-/g,"\\-"); return strout; } /*------数组------*/ function ArrIndexOf(a,v) { for (var i = 0; i < a.length; i++) if (a[i] == v) return i; return -1; } /*---cookies操作-------*/ function getCookie(key){ var arg = key + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen){ var j = i + alen; if (document.cookie.substring(i,j) == arg) return getCookieVal(j); i = document.cookie.indexOf(" ",i) + 1; if (i == 0) break; } return null; } function setCookie(key,value){ var expdate = new Date(); var argv = setCookie.arguments; var argc = setCookie.arguments.length; var expires = (argc > 2) ? argv[2] : null; var path = (argc > 3) ? argv[3] : null; var domain = (argc > 4) ? argv[4] : null; var secure = (argc > 5) ? argv[5] : false; if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 )); document.cookie = key + "=" + escape(value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString())) +((path == null) ? "; path=/" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain)) +((secure == true) ? "; secure" : ""); } function getCookieVal(offset){ var endstr = document.cookie.indexOf (";", offset); if (endstr == -1) endstr = document.cookie.length; return unescape(document.cookie.substring(offset,endstr)); } function delCookie(name){ var exp = new Date(); exp.setTime (exp.getTime() - 1); var cval = getCookie(name); document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString(); } /*-event-*/ function getKeyCode(evt){ if (evt){ return evt.keyCode; }else{ return event.keyCode; } } /*--select--*/ function getSelectText(o){ if (!o) return ''; if (o.value=='') return ''; if (o.options.selectedIndex ==-1) return ''; var value = o.options[o.options.selectedIndex]; if (!value) return ''; if (value.text=='undefined') return '' return value.text; } function SetNewsImgSite(img) { var width; var height; var MaxSite; MaxSite = 650; width=img.width; height=img.height; //alert(width) //if (height>width) //{ if (width>MaxSite) { img.width=MaxSite; img.style.height="auto"; return false; } //} //else //{ //if (height>MaxSite) //{ // img.height=MaxSite; // img.style.width="auto"; // return false; //} //} }