www.gusucode.com > 中网景企业网站源码时尚版 2009.73码程序 > common/chkuser02.js
// {{{ error handling Function.prototype.getDecl = function() { var match=/function\s*([^\(]*)\(([^\)]+)\)/.exec(String(this)); if (match) { return {name:match[1], args:match[2].split(/[, ]+/g)}; } return {name:'',args:[]}; } Function.prototype.getBody = function() { var m = String(this).split(/\{/); delete m[0]; return m.join('{'); } String.prototype.compatToLine = function() { return this.replace(/\s{2,}/g, '').replace(/[\r\n]+/g, '/'); } String.prototype.cut = function(len) { return (this.length > len) ? this.substr(0, len) + "..." : String(this); } String.prototype.dump = function() { return "'" + this.replace(/\\/g, '\\\\') .replace(/\n/g, "\\n") .replace(/\r/g, "\\r") .replace(/\t/g, "\\t") .replace(/'/g, "\\'") + "'"; } Error.prototype.getBacktrace = function(func) { try { var x = ''; var stack = this.stack; if (stack) { x = stack + "\n"; } else { if (!func) return ""; var decl = func.getDecl(); x += "- " + decl.name +"("; for (var a = 0, c = func.arguments.length; a < c; a ++) { if (a > 0) x += ", "; x += (decl.args[a]||'') + '='; var lm = func.arguments[a]; switch (typeof(lm)) { case 'function': x += 'F'; lm = lm.getBody(); case 'string': x += lm.cut(40).dump(); break; case 'undefined': x += 'N'; break; default: x += String(lm); } } x += ")\n"; if (decl.name.indexOf('anony') != -1 || !decl.name) { x += " " + func.getBody().compatToLine().cut(40) + "\n"; } if (func.caller) { x += this.getBacktrace(func.caller); } } return x; } catch(wa) { return "[Cannot get stack trace]\n"; } } Error.prototype.send = function() { return this.sendEx(document.URL, 'Unknown'); } Error.prototype.sendEx = function(url, line, col) { try { var ag = navigator.userAgent; if (line == 6 && ag.match(/Maxthon|MyIE2/i)) { return false; // sux } } catch(e) {} var charset = (self.is && is.gecko ? is.charset : null) || 'utf-8'; var ref = "referrer"; try{ref = document[ref];} catch(e){ref = "";} self.errcnt = (self.errcnt||0) + 1; if (self.errcnt > 5) { return {}.undefined; } var err = this.description||this.message; if (err.indexOf("RPC") != -1) { alert('错误: ' + err + "\n1. 本站安全, 但是您的浏览器出故障" + "\n2. 您可能中冲击波或其变种了" + "\n3. 建议您打开网络防火墙, 杀毒, 重启," + " 并给 Windows 升级打补丁"); return true; } try { var img = new Image(); err += "\n" + this.getBacktrace(this.sendEx.caller); var ps = { err: err, url: url, line: line, col: col, ref: ref, request: document.URL }; if (self.SS) { ps.jses = SS.jses(); ps.incompletes = SS.incompletes(); } try{ ps.docsize = document.fileSize; }catch(e) {} var src = "/misc/senderror.php?charset=" + charset; for (var i in ps) { if (ps[i]) { src += ';' + i + '=' + (self.encodeURIComponent||String)(ps[i]); } } img.src = src; } catch(e) { var img = new Image(); document.title = "Cannot handle error"; img.src = "/misc/senderror.php?charset=" + charset + ';err=e5+' + (e.description||e.message) + ';request=' + document.URL; } return true; } function assert(v) { if (!v) { throw Error("assertion failed"); } } var _test = 0; try { if (!self.location.host.toString().match(/-(:\d+)?$/)) { throw('!'); } _test = 1; } catch(e) { if (!self.onerror && self.location && self.location.href.indexOf(';debug') == -1) { window.onerror = function(err, url, line) { var e = window.event; return Error(err).sendEx(url, line, e ? e.errorCharacter : window.undefined); } } } // }}} // {{{ utf8 String.prototype.toUtf8 = function() { var out, i, len, c; var S = String; var fc = 'fromCharCode'; out = ""; len = this.length; for (i = 0; i < len; i++) { c = this.charCodeAt(i); if ((c >= 0x0001) && (c <= 0x007F)) { out += this.charAt(i); } else if (c > 0x07FF) { out += S[fc](0xE0 | ((c >> 12) & 0x0F)); out += S[fc](0x80 | ((c >> 6) & 0x3F)); out += S[fc](0x80 | ((c >> 0) & 0x3F)); } else { out += S[fc](0xC0 | ((c >> 6) & 0x1F)); out += S[fc](0x80 | ((c >> 0) & 0x3F)); } } return out; } String.prototype.fromUtf8 = function() { var out, i, len, c; var char2, char3; var cca = 'chatCodeAt'; out = ""; len = this.length; i = 0; while (i < len) { c = this[cca](i++); switch(c >> 4) { case 12: case 13: char2 = this[cca](i++); out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F)); break; case 14: char2 = this[cca](i++); char3 = this[cca](i++); out += String.fromCharCode(((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | ((char3 & 0x3F) << 0)); break; default: out += this.charAt(i-1); break; } } return out; } // }}} // {{{ BC with ie5.0 if (!self.encodeURIComponent) { self.encodeURIComponent = function(str) { return escape(String(str).toUtf8()); } self.decodeURIComponent = function(str) { return String(unescape(str)).fromUtf8(); } } // }}} // {{{ ext to String String.prototype.ltrim = function () { return this.replace(/^\s+/, "" ); } String.prototype.rtrim = function () { return this.replace(/\s+$/, "" ); } String.prototype.trim = function () { return this.replace(/(^\s+|\s+$)/, "" ); } String.prototype.htmlencode = function () { return this .replace(/&/g, "&") .replace(/^[ ]/, ' ') .replace(/[\r\n][ ]/g, '\n ') .replace(/"/g, """) .replace(/</g, "<") .replace(/>/g, ">"); } String.prototype.htmlencode2 = function () { return this .replace(/ /g, " ") .replace(/\t/g, ' ') .replace(/(\r\n|\n|\r)/g, "<BR>") .replace(/space;/g, ' ') } String.prototype.sreplace = function(re, callback) { if (is.ie && is.v == 5.5) { re = new RegExp(re, "g"); return this.replace(re, callback); } var str = this.toString(); if (!str) return ''; var loops = 1000; var m = ""; var nstr = ''; re = new RegExp(re, ""); while((--loops) > 0 && (m = str.match(re)) && (nstr != str)) { nstr = str; str = str.replace(m[0], callback(m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8], m[9])); if (!str) break; } return str||''; } // }}} function urlencode(obj, sep) { // {{{ if (typeof obj == 'string') { return encodeURIComponent(obj); } sep = sep || '&'; var r = []; var i = 0; for (k in obj) { r[i++] = encodeURIComponent(k) + '=' + encodeURIComponent(obj[k]); } return r.join(sep); } // }}} // {{{ SSObject var SSObj = function() { this.loaded = false; this.handlerId = 0; } var SSp = SSObj.prototype; SSp.jses = function(done) { if (typeof(done) == 'undefined') { done = true; } var ret = []; for (var name in scripts) { name = name.replace('://', '').replace(/:\d+/, ''); name = name.replace(/[^\/]+[a-z-]\/(.*)\.js/i, '$1').replace(/\//g,'.'); if (done == (typeof(scriptscomplete[name]) != 'undefined')) { ret[ret.length] = name; } } return ret.join(', '); } SSp.incompletes = function() { return this.jses(false); } SSp.include = function(src) { src = src.split("."); if (src[src.length-1] == 'js') src.length -= 1; if (src[0] != 'skysoft' || src[2] && src[1] != 'common') { throw Error('invalidate include'); } this.includex(src.join("."), false) } SSp.loadGroup = function(group) { if (!self.scripturl) self.scripturl = (self.rooturl||'')+'/scripts'; document.write('<script language="Javascript1.2"' + ' src="'+self.scripturl+'/loadjs.php?filegroup='+group+'">' + '<\/script>'); } SSp.includex = function(filename, trans) { if (!self.scripturl) self.scripturl = (self.rooturl||'')+'/scripts'; if (!filename) return {}.undefined; filename = filename.replace(/\./g , "/" ).replace("common/","" ).replace("skysoft/","") if (typeof trans == 'undefined' || trans) document.write('<script language="Javascript1.2"' + ' src="'+self.scripturl+'/loadjs.php?' + 'files='+filename+'.js&trans=1&c='+(is.charset||'')+'">' + '<\/script>'); else document.write('<script language="Javascript1.2"' + 'src="'+self.scripturl+'/loadjs.php?files='+filename+'.js">' + '<\/script>'); return {}.undefined; } SSp.addLoadFunction = function(f) { return this.listen(window, 'load', f); } SSp.addUnLoadFunction = function(f) { return this.listen(window, 'unload', f); } SSp.addResizeFunction = function(f) { return this.listen(window, 'resize', f); } // fix IE memory leak? SSp.cleanListen = function() { for (var i in this.listens) { this.listens[i][0].detachEvent('on' + this.listens[i][1]); } } // {{{ listen: listen object event // target name [thisobj] handler SSp.listen = function(target, name, v1, v2) { assert(typeof target != 'string'); if (v2) { var thisobj = v1; var handler = v2; } else { var thisobj = target; var handler = v1; } var cb = this.makeEventHandler(target, thisobj, handler); if (target.addEventListener) { target.addEventListener(name, cb, false); return cb; } else if (target.attachEvent) { if (!this.listens) { this.listens = []; var _SS = this; this.listen(window, 'unload', function(){_SS.cleanListen()}); } this.listens[this.listens.length] = [target, name]; target.attachEvent('on' + name, cb); return cb; } else { var key = 'on' + name; var oldhandler = target[key]; if (oldhandler) { if (typeof oldhandler == 'string') { oldhandler = this.makeEventHandler(target, target, oldhandler); } target[key] = function(e) { oldhandler(event); cb(event); } } else { target[key] = cb; } return cb; } } // }}} // {{{ makeEventHandler: return a optimized event handler SSp.makeEventHandler = function(target, thisobj, handler) { var hid = '__SS_handler__' + (this.handlerId ++); if (is.ie) { if (handler instanceof Function && handler.constructor.call instanceof Function) { var cb = function(event) { return handler.call(thisobj, event||window.event, target); } } else { if (typeof handler == 'string') { handler = function(event) { eval(handler); } } thisobj[hid] = handler; var cb = function(event) { return thisobj[hid](event||window.event, target); } } } else { var cb = function(event) { if (!event) { return {}.undefined; } if(handler instanceof Function) { if (handler.call instanceof Function) { ret = handler.call(thisobj, event, target); } else { thisobj[hid] = handler; ret = thisobj[hid](event, target); } } else if (handler) { ret = eval(handler); } else { return {}.undefined; } if (ret === false) { event.returnValue = ret; if (event.preventDefault) { event.preventDefault(); } } if (event.cancelBubble && event.stopPropagation) { event.stopPropagation(); } return ret; } } cb.handlerId = hid; return cb; } // }}} // dreamwaver's findObject SSp.obj = SSp.findObject = function(n, d) { var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p); } if(!(x=d[n])&&d.all) x=d.all[n]; if(!x && d.getElementById) x=d.getElementById(n); for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=this.findObject(n,d.layers[i].document); return x; } // newest plugin version SSp.InsertFlash = function(src, w, h, trans, vars) { this.insertFlash(src, w, h, trans, true, vars); } // common plugin version SSp.insertFlash_id = 0; SSp.insertFlash = function(src, w, h, trans, newest, vars) { w=w||550; h=h||400; if (vars instanceof Object) { vars = urlencode(vars); } if (vars) { vars = vars.htmlencode(); } else { vars = false; } var codebase = (self.resurl||self.rooturl||"http://res.oursky.net") + "/flash/plugin/swflash.cab#version="+ (newest?"6,0,40,0":"5,0,0,0") ; var html = '\ <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"\ codebase="'+codebase+'"\ width="'+w+'" height="'+h+'"> \ <param name="movie" value="'+src.htmlencode()+'">\ <param name="AllowScriptAccess" value="sameDomain">\ ' + (vars ? '<param name="FlashVars" value="'+vars+'" />' : '') + ' \ ' + (trans ? '<param name="wmode" value="transparent">':'') + ' \ <param name="quality" value="high"> \ <embed src="'+src.htmlencode()+'" \ ' + (vars ? 'FlashVars="'+vars+'"' : '') + ' \ ' + (trans?'wmode="transparent"' : '')+' \ quality="high" \ AllowScriptAccess="sameDomain" \ pluginspage="http://www.macromedia.com/' + 'shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" \ type="application/x-shockwave-flash" \ width="'+w+'" height="'+h+'"> \ </embed> \ </object> \ '; if (SS.cookies.read('noflash') == 1) { var id = 'SSinsertFlash' + (this.insertFlash_id ++); document.write('<a href="javascript:" onclick="this.outerHTML=this.realhtml"' + ' style="display: block; width: ' + w + 'px; height: ' + h + 'px; line-height: ' + h + 'px" id="' + id + '">[click to see flash]</a>'); var o = document.getElementById(id); o.realhtml = html; } else { document.write(html); } } SSp.getBody = function(doc) { doc = doc||document; return !is.cssCompatMode ? doc.documentElement : doc.body; } // create object var SS, SkySoft; SS = SkySoft = new SSObj(); // install handler if (self.DynAPI||self.dynapi) { if (!self.dynapi) { dynapi = self.DynAPI; } } // }}} // {{{ cookie functions SkySoft.cookies = { save : function(name, value, days, path, domain, raw) { if (typeof name == 'object') { value = name.value; days = name.days; path = name.path; name = name.name; domain = name.domain; raw = name.raw; } var cookie; if (raw) { cookie = name + "=" + value; } else { cookie = encodeURIComponent(name) + "=" + encodeURIComponent(value); } if (days) { var date=new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); cookie += "; expires="+date.toGMTString(); } if (typeof path == 'undefined') { cookie += '; path=/'; } else if (path != '.') { cookie += '; path=' + path; } if (domain) { cookie += '; domain=' + domain; } document.cookie = cookie; }, read : function(name) { var nameEQ = encodeURIComponent(name) + "="; var nameLN = nameEQ.length; var ca = document.cookie.split(/[; ]+/); for (var i in ca) { if (ca[i].substring(0, nameLN) == nameEQ) { return decodeURIComponent(ca[i].substring(nameLN)); } } return {}.undefined; }, del : function(name) { this.save(name,"",-1); } }; SkySoft.cookies.write = SkySoft.cookies.save; if (self.DynAPI) { self.DynAPI.cookies = SkySoft.cookies; } // }}} // {{{ browser detection /* code from dynapi3, Powered by oursky.net */ function Browser() { var b = navigator.appName; var v = this.version = navigator.appVersion; var ua = navigator.userAgent.toLowerCase(); this.v = parseInt(v); this.safari = ua.indexOf("safari") != -1; // always check for safari & opera this.opera = ua.indexOf("opera") != -1; // before ns or ie this.ns = !this.opera && !this.safari && (b=="Netscape"); this.ie = !this.opera && (b=="Microsoft Internet Explorer"); this.gecko = ua.indexOf('gecko') != -1; if (this.ns) { this.ns4 = (this.v==4); this.ns6 = (this.v>=5); this.b = "Netscape"; } else if (this.ie) { this.v=parseFloat(v.substr(v.indexOf("MSIE")+4)); if (this.v > 8) {} else if (this.v >= 7) {this.ie7 = true;} else if (this.v >= 6) {this.ie6 = true;} else if (this.v >= 5) {this.ie5 = true;} else if (this.v >= 4) {this.ie4 = true;} this.b = "MSIE"; } else if (this.opera) { this.v=ua.substr(ua.indexOf("opera")+6,1) * 1; // set opera version if (this.v >= 7) {this.opera7 = true;} else if (this.v >= 6) {this.opera6 = true;} this.b = "Opera"; } else if (this.safari) { this.ns6 = (this.v>=5); // ns6 compatible correct? this.b = "Safari"; } this.dom = (document.createElement && document.appendChild && document.getElementsByTagName)? true : false; this.def = (this.ie||this.dom); this.win32 = ua.indexOf("win")>-1; if (this.win32) { this.win = true; if (ua.indexOf("nt")>-1) { this.nt = true; if (ua.indexOf("nt 5")>-1) { this.nt5 = true; if (ua.indexOf("nt 5.1")>-1) { this.nt51 = true } } } } else if (ua.indexOf("mac")>-1) { this.mac = true; } else if (ua.indexOf("x11")>-1) { this.x = true; } this.filter = this.ie && this.v>=6; this.other = (!this.win32 && !this.mac); this.detectCharset(); var minver = navigator.appMinorVersion||''; if (minver.indexOf('SP1')) this.sp1 = true; this.hand = this.ie ? 'hand' : 'pointer'; this.blankpage = this.opera ? (self.siteurl||'') + '/blank.html' : 'about:blank'; this.cssCompatMode = !document.compatMode|| document.compatMode=='BackCompat'; this.supported = (this.def||this.ns4||this.ns6||this.opera); if (!this.supported) { this.setStatus('无法识别的浏览器. 本站脚本可能不支持该浏览器.'); } if (!window.navigate) { window.navigate = function(url) { window.location.href = phpurl(url); } } } Browser.prototype.detectCharset = function () { var _this = this; if (!self.document) { setTimeout(function(){_this.detectCharset()}, 0); return } this.en = this.english = self.english; this.charset = (document.charset||document.characterSet||"").toLowerCase(); var c = this.charset; this.cht = (c=="big5"||c=="big5-hkscs"||c=="euc-tw"); // gb2312 hz-gb-2312 x-gbk this.chs = (c.indexOf("gb")>=0?true:false); } Browser.prototype.setStatus = function(str) { if (this.ie7) { if (!this.docTitle) { this.docTitle = document.title; } document.title = this.docTitle + ' | ' + str; } else { window.status = str; } } var is = SkySoft.browser = new Browser(); var ie = is.ie; var ns = is.ns; // }}} SS.listen(window, 'load', function() { SS.loaded = true; var incompletes = SS.incompletes(); if (incompletes) { if (SS.browser) { SS.browser.setStatus('尚未载入脚本: ' + incompletes); } else { window.status ='尚未载入脚本: ' + incompletes; } } init_button_overout(true); init_button_overout(false); var forms = document.forms; var forms_l = forms.length; for (var i = 0; i < forms_l; i ++) { var elements = forms[i].elements; var elements_j = elements.length; var found = false; for (var j = 0; j < elements_j; j ++) { if (!found && elements[j].type == 'submit') { forms[i].defaultSubmitElement = elements[j]; found = true; if (is.ie) { break; } } if (!is.ie) { form_init_focus_event(forms[i], elements[j], true); form_init_focus_event(forms[i], elements[j], false); } } if (is.ie) { form_init_focus_event(forms[i], null, true); form_init_focus_event(forms[i], null, false); } } var ae = document.activeElement; if (ae && ae.nodeName == '#text') { ae = ae.parentNode; } if (ae && ae.nodeName != 'TEXTAREA' && ae.form && ae.form.defaultSubmitElement) { ae.form.defaultSubmitElement.className += ' btnactive'; ae.form.activeButton = ae.form.defaultSubmitElement; } }); // {{{ over effect function init_button_overout(over) { SS.listen(document, over ? 'mouseover' : 'mouseout', function(e) { e = e||window.event; var o = e.srcElement||e.target; if (!o) { return; // in case when the page is unloading? } if (o.nodeName == '#text') { o = o.parentNode; } if (over && o.disabled) { return; } var css, reg; switch (o.nodeName) { case 'INPUT': switch (o.type) { case 'submit': case 'reset': case 'image': case 'button': css = ' btnover'; reg = / ?\bbtnover\b/g; break; case 'text': css = ' inpover'; reg = / ?\binpover\b/g; break; default: return; } break; case 'IMG': css = ' imgover'; reg = / ?\bimgover\b/g; break; case 'LABEL': css = ' lblover'; reg = / ?\blblover\b/g; break; default: return; } if (over) { o.className += css; } else { o.className = o.className.replace(reg, ''); } }); } // }}} // {{{ focus effect function form_init_focus_event(form, o, isin) { SS.listen(o||form, o ? (isin ? 'focus' : 'blur') : (isin ? 'focusin' : 'focusout'), function(e) { e = e||window.event; var o = e.srcElement||e.target; if (o.nodeName == '#text') { o = o.parentNode; } var updatefocus = function() { form.timerFocus = 0; var btn = null; if (isin) { btn = form.defaultSubmitElement; switch (o.nodeName) { case 'INPUT': switch (o.type) { case 'submit': case 'reset': case 'image': case 'button': btn = o; } break; case 'TEXTAREA': case 'IFRAME': case 'A': btn = null; break; } } var ab = form.activeButton; if (ab != btn) { if (ab) { ab.className = ab.className.replace(/ ?\bbtnactive\b/g, ''); } if (btn) { btn.className += ' btnactive'; } } form.activeButton = btn; } if (form.timerFocus) { window.clearTimeout(form.timerFocus); } if (isin) { updatefocus(); } else { form.timerFocus = window.setTimeout(updatefocus, 1); } }); } if (!self.scriptscomplete) scriptscomplete = {}; if (!self.scripts) scripts = {}; scriptscomplete['skysoft'] = true;