﻿
//
var Comm = {
    IsIE: navigator.appVersion.indexOf("MSIE") != -1 ? true : false,
    $: function(id) { return document.getElementById(id); },
    AddEvent: function(obj, eventType, func) { if (obj.attachEvent) { obj.attachEvent("on" + eventType, func); } else { obj.addEventListener(eventType, func, false) } },
    DelEvent: function(obj, eventType, func) { if (obj.detachEvent) { obj.detachEvent("on" + eventType, func) } else { obj.removeEventListener(eventType, func, false) } },
    LTrim: function(a) { var b = new String(" \t\n\r"); var s = new String(a); if (b.indexOf(s.charAt(0)) != -1) { var j = 0; i = s.length; while (j < i && b.indexOf(s.charAt(j)) != -1) { j++; } s = s.substring(j, i); } return s; },
    RTrim: function(a) { var b = new String(" \t\n\r"); var s = new String(a); if (b.indexOf(s.charAt(s.length - 1)) != -1) { var i = s.length - 1; while (i >= 0 && b.indexOf(s.charAt(i)) != -1) { i--; } s = s.substring(0, i + 1) } return s; },
    Trim: function(a) { return Comm.RTrim(Comm.LTrim(a)); },
    IsEmpty: function(a, b) { if (Comm.Trim(a.value) == "") { alert(b); if (a.disabled == false && a.readOnly == false) { a.focus() } return false; } else { return true; } },
    IsEmptys: function(a) { if (Comm.Trim(a.value) == "") { if (a.disabled == false && a.readOnly == false) { a.focus(); } return false; } else { return true; } },
    EmptyAlert: function(a) { if (Comm.Trim($(a).value) == "") { alert($(a).title + '不能为空'); if ($(a).disabled == false && $(a).readOnly == false) { $(a).focus() } return false; } else { return true; } },
    IsEmptym: function(a, b, c) { if (Comm.Trim(a.value) == "") { var d = $(c); if (d != null) { d.innerHTML = b; } if (a.disabled == false && a.readOnly == false) { a.focus(); } return false; } else { return true; } },
    GetEPos: function(a) { return Comm.GetEPosObj($(a)); },
    GetEPosObj: function(e) { var b = navigator.userAgent.toLowerCase(); var c = (b.indexOf('opera') != -1); var d = (b.indexOf('msie') != -1 && !c); if (e.parentNode === null || e.style.display == 'none') { return false } var f = null; var g = []; var h; if (e.getBoundingClientRect) { h = e.getBoundingClientRect(); var i = Math.max(document.documentElement.scrollTop, document.body.scrollTop); var j = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft); return { x: h.left + j, y: h.top + i} } else if (document.getBoxObjectFor) { h = document.getBoxObjectFor(e); var k = (e.style.borderLeftWidth) ? parseInt(e.style.borderLeftWidth) : 0; var l = (e.style.borderTopWidth) ? parseInt(e.style.borderTopWidth) : 0; g = [h.x - k, h.y - l] } else { g = [e.offsetLeft, e.offsetTop]; f = e.offsetParent; if (f != e) { while (f) { g[0] += f.offsetLeft; g[1] += f.offsetTop; f = f.offsetParent } } if (b.indexOf('opera') != -1 || (b.indexOf('safari') != -1 && e.style.position == 'absolute')) { g[0] -= document.body.offsetLeft; g[1] -= document.body.offsetTop } } if (e.parentNode) { f = e.parentNode } else { f = null } while (f && f.tagName != 'BODY' && f.tagName != 'HTML') { g[0] -= f.scrollLeft; g[1] -= f.scrollTop; if (f.parentNode) { f = f.parentNode } else { f = null } } return { x: g[0], y: g[1] }; },
    IsNoSelect: function(a, b, c) { if (a.value == c) { alert(b); if (a.disabled == false) { a.focus(); } return false; } else { return true; } },
    CkMobile: function(a) { if (a.length == 11) { var b = /^1[3456789]{1}[0-9]{1}[0-9]{8}$/; if (!b.test(a)) { return false; } else { return true; } } else { return false } },
    ReadCookie: function(l) { var i = "", I = l + "="; if (document.cookie.length > 0) { offset = document.cookie.indexOf(I); if (offset != -1) { offset += I.length; end = document.cookie.indexOf(";", offset); if (end == -1) end = document.cookie.length; i = unescape(document.cookie.substring(offset, end)) } else { i = null; } return i; } else { return null; } },
    WriteCookie: function(O, o, l, I) { var i = "", c = ""; if (l != null) { i = new Date((new Date).getTime() + l * 3600000); i = "; expires=" + i.toGMTString() }; if (I != null) { c = ";domain=" + I }; document.cookie = O + "=" + escape(o) + i + c + ';path=/;'; },
    DeleteCookie: function(O) { Comm.WriteCookie(O, '', null, null); },
    IsInArray: function(a, b) { var e = false; a.each(function(c) { if (c == b) { e = true; return; } }); return e; },
    ArrayRemove: function(a, b) { var d = new Array(); a.each(function(c) { if (c != b) { d.push(c); } }); return d; },
    ArrayRemoveAt: function(a, b) { var d = new Array(); for (var i = 0; i < a.length; i++) { if (i != b) { d.push(a[i]) } } return d; },
    Floatto2bits: function(flt) { if (parseFloat(flt) == flt) { return Math.round(flt * 100) / 100; } else { return 0; } },
    SetValue: function(a, b) { for (var i = 0; i < a.options.length; i++) { if (a.options[i].value == b) { a.options[i].selected = true; break; } } },
    CheckNumber: function(b) { var c = true; if (b == "") { c = false; return c; } var d = new String(b); for (i = 0; i < d.length; i++) { var a = d.substr(i, 1); if (!(a == "0" || a == "1" || a == "2" || a == "3" || a == "4" || a == "5" || a == "6" || a == "7" || a == "8" || a == "9")) { c = false; break; } } return c; },
    SpecChar: function(b) { var re = new RegExp(/[^\u4E00-\u9FA50-9a-zA-Z_]/g); var a = b.match(re); if (a != null && a != "") { return false; } else { return true; } },
    SpecCharNE: function(b) { var re = new RegExp(/[^0-9a-zA-Z_]/g); var a = b.match(re); if (a != null && a != "") { return false; } else { return true; } },
    SpecCharCNE: function(b) { var re = new RegExp(/[^\u4E00-\u9FA5a-zA-Z-\s]/g); var a = b.match(re); if (a != null && a != "") { return false; } else { return true; } },
    TimeMach: function(a, b) { var Y = a.getFullYear(); var M = a.getMonth() + 1; var D = a.getDate(); var h = a.getHours(); var m = a.getMinutes(); var s = a.getSeconds(); switch (b) { case '-': return Y + "-" + M + "-" + D; case '/': return Y + "/" + M + "/" + D; case '.': return Y + "." + M + "." + D; case 'Y': return Y + "年"; case 'M': return Y + "年" + M + "月"; case 'D': return Y + "年" + M + "月" + D + "日"; case 'h': return Y + "年" + M + "月" + D + "日 " + h + "时"; case 'm': return Y + "年" + M + "月" + D + "日 " + h + "时" + m + "分"; case 's': return Y + "年" + M + "月" + D + "日 " + h + "时" + m + "分" + s + "秒"; case 'mm': return Y + "-" + M + "-" + D + " " + h + ":" + m + ""; case 'ss': return Y + "-" + M + "-" + D + " " + h + ":" + m + ":" + s; default: return Y + "-" + M + "-" + D; } },
    GetkeyCode: function(e) { this.NS4 = (document.layers) ? true : false; this.IE4 = (document.all) ? true : false; this.code = 0; if (this.NS4) { this.code = e.which; } else { this.code = e.keyCode; } return this.code; },
    QString: function(a, b) { var c = new RegExp("(^|\\?|&)" + b + "=([^&]*)(\\s|&|$)", "i"); if (c.test(a)) { return unescape(RegExp.$2.replace(/\+/g, ' ')); } else { return ''; } },
    QStringDf: function(a, b, d) { var c = new RegExp("(^|\\?|&)" + b + "=([^&]*)(\\s|&|$)", "i"); if (c.test(a)) { return unescape(RegExp.$2.replace(/\+/g, ' ')); } else { return d; } },
    PName: function() { var sSeparator = "/"; if (location.protocol.indexOf("file ") > -1) { sSeparator = "\\" } var url = document.URL; var ar = url.split(sSeparator); var FileName = ar[ar.length - 1]; var PageName = FileName.replace(/^(.*)\..*/, "$1"); FileName = FileName.replace(/\?.*$/, ""); return [PageName, FileName]; },
    PNameU: function(url) { var sSeparator = "/"; if (url.indexOf("file ") > -1) { sSeparator = "\\" } var ar = url.split(sSeparator); var FileName = ar[ar.length - 1]; var PageName = FileName.replace(/^(.*)\..*/, "$1"); FileName = FileName.replace(/\?.*$/, ""); return [PageName, FileName]; },
    Onload: function(a) { Comm.AddEvent(window, "load", a); },
    UnOnload: function(a) { Comm.AddEvent(window, "unload", a); },
    NodeValue: function(a, b) { if (a && typeof (a.attributes[b]) != "undefined") { return a.attributes[b].nodeValue; } else { return null; } },
    SetData: function(a) { if (typeof (a) != 'undefined') { for (var name in a) { if (Comm.$(name) != null) { switch (Comm.$(name).tagName.toLocaleLowerCase()) { case 'input': Comm.$(name).value = a[name]; break; case 'textarea': Comm.$(name).value = a[name]; break; case 'select': Comm.SetValue(Comm.$(name), a[name]); break; default: break; } } } } },
    IsVisible: function(a) { while (a && a.tagName != 'BODY') { if (!$(a).visible()) return false; a = a.parentNode; } return true; },
    GetparentNode: function(a, tagName) { while (a && a.tagName != 'BODY') { if (a.tagName.toString().toLocaleUpperCase() == tagName.toString().toLocaleUpperCase()) return a; a = a.parentNode; } return null; }
};

