﻿/*huang.qc 2009-09-15 extend methods、jquery and jquery.fn*/
//extend method
Object.extendFn = function(target, sourceArray) { for (var property in sourceArray) { try { switch (property.toString()) { case "fromElement": case "toElement": case "x": case "y": case "offsetX": case "offsetY": case "srcElement": case "returnValue": continue; default: target[property] = sourceArray[property]; break; } } catch (exx) { } } return target; }
//extend String
Object.extendFn(String.prototype, {
    trim: function() { return $.trim(this); },
    ltrim: function() { return this.replace(/(^\s*)/g, ""); },
    rtrim: function() { return this.replace(/(\s*$)/g, ""); },
    clearHTML: function() { return this.replace(/<[^>]*>/g, ""); },
    lower: function() { return this.toLowerCase(); },
    upper: function() { return this.toUpperCase(); },
    isChn: function() { return (/^([\u4e00-\u9fa5\uf900-\ufa2d])*$/.test(this)); },
    hasChn: function() { return (/[\u4e00-\u9fa5\uf900-\ufa2d]/.test(this)); },
    len: function() { return this.replace(/([^\x00-\xff])/g, "**").length; },
    sub: function(len, start, end) {
        if (len == null) return this;
        if (start == null) start = 0;
        if (end == null || (end + 1) > this.length) end = this.length;
        var a = 0, i = 0, temp = "";
        for (i = start; i < end; i++) { a += this.charCodeAt(i) > 255 ? 2 : 1; if (a > len) return temp; temp += this.charAt(i); }
        return temp;
    },
    dbc2sbc: function() {
        var result = '', code = '';
        for (var i = 0; i < this.length; i++) {
            code = this.charCodeAt(i);
            if (code >= 65281 && code <= 65373)
                result += String.fromCharCode(this.charCodeAt(i) - 65248);
            else if (code == 12288)
                result += String.fromCharCode(this.charCodeAt(i) - 12288 + 32);
            else
                result += this.charAt(i);
        }
        return result;
    },
    format: function() { var args = arguments; return this.replace(/\{(\d+)\}/g, function(m, i) { return args[i]; }); },
    appendFormat: function() { if (arguments.length == 0) return this; var fstr = arguments[0]; var arr = $.array(arguments); var args = arr.findAll(function(index, item) { return index != 0; }); fstr = fstr.replace(/\{(\d+)\}/g, function(m, i) { return args[i]; }); return this + fstr; },
    startWith: function(str) { if (str == null || str == "" || this.length == 0 || str.length > this.length) return false; return (this.substr(0, str.length) == str); },
    endWith: function(str) { if (str == null || str == "" || this.length == 0 || str.length > this.length) return false; return (this.substring(this.length - str.length) == str); },
    isNOrE: function() { return (this == null) || (this.length == 0) },
    isN: function() { if (this == null) return false; return (/^(\-|\+)?(\d+)*$/.test(this)); },
    isNN: function() { if (this == null) return false; return (/^(((\+)?[1-9]+(\d*))|(([1-9])+(\d*)))$/.test(this)); },
    is_NN: function() { if (this == null) return false; return (/^(\-){1}(\d+)*$/.test(this)); },
    isUserName: function() { if (this == null) return false; return (/^[A-Za-z_]{1}[A-Za-z0-9_]{5,17}$/.test(this)); },
    isEmail: function() { if (this == null) return false; var reg = /^([a-zA-Z0-9_-])+(\.*)([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/; return reg.test(this); },
    isMobile: function() { if (this == null) return false; return (/^1[0-9]{10}$/.test(this)); },
    isTel: function() { if (this == null) return false; return (/^(\d{3,4})-(\d{7,8})/.test(this)); },
    isIDCard: function() { return (/^(\d{18}|\d{15}|\d{14}[A-Za-z]{1})$/.test(this)); },
    toInt: function() { try { return parseInt(this); } catch (e) { return 0; } },
    toDate: function() {
        var DateStr = this; if (!DateStr.isDateTime() && !DateStr.isDate()) return null;
        var converted = Date.parse(DateStr); var myDate = new Date(converted);
        if (isNaN(myDate)) {
            if (DateStr.isDate()) { /*2008-01-01*/var arys = DateStr.split('-'); myDate = new Date(arys[0], --arys[1], arys[2]); }
            else { /*2008-01-01 00:00:00*/var partArray = DateStr.split(" "); var darray = partArray[0].split("-"); var tarray = partArray[1].split(":"); myDate = new Date(darray[0], --darray[1], darray[2], tarray[0], tarray[1], tarray[2]); }
        }
        return myDate;
    },
    getArray: function(spliter) { var a = []; if (spliter == null || spliter == "") for (var i = 0; i < this.length; i++) a.insert(this.charAt(i), i); else a = this.split(spliter); return a; },
    isDateTime: function() { return (/^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\s(((0?[0-9])|([1][0-9])|([2][0-4]))\:([0-5]?[0-9])((\s)|(\:([0-5]?[0-9])))))?$/.test(this)); },
    isDate: function() { return (/^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))$/.test(this)); },
    isTime: function() { return (/^(\s(((0?[0-9])|([1][0-9])|([2][0-4]))\:([0-5]?[0-9])((\s)|(\:([0-5]?[0-9])))))?$/.test(this)); },
    times: function(n) { var result = ''; for (var i = 0; i < n; i++) result += this; return result; },
    padl: function(c, len) { if (this.length >= len) return this; var n = len - this.length; return c.toString().times(n) + this; },
    padr: function(c, len) { if (this.length >= len) return this; var n = len - this.length; return this + c.toString().times(n); },
    camelize: function() { var parts = this.getArray('-'), len = parts.length; if (len == 1) return parts[0]; var camelized = this.charAt(0) == '-' ? parts[0].charAt(0).upper() + parts[0].substring(1) : parts[0]; for (var i = 1; i < len; i++) camelized += parts[i].charAt(0).upper() + parts[i].substring(1); return camelized; },
    capitalize: function() { return this.charAt(0).upper() + this.substring(1).lower(); }
})
//extend Date
Object.extendFn(Date.prototype, {
    date: function(f) { if (f == null) f = "yyyy-MM-dd"; return this.format(f); },
    time: function(f) { if (f == null) f = "yyyy-MM-dd"; return this.format(f); },
    isLeapYear: function() { return (0 == this.getYear() % 4 && ((this.getYear() % 100 != 0) || (this.getYear() % 400 == 0))); },
    format: function(formatStr) {//date format,eg：(new Date()).format("yyyy-MM-dd HH:mm:ss")
        var str = formatStr;
        var Week = ['日', '一', '二', '三', '四', '五', '六'];
        str = str.replace(/yyyy|YYYY/, this.getFullYear());
        str = str.replace(/yy|YY/, (this.getYear() % 100) > 9 ? (this.getYear() % 100).toString() : '0' + (this.getYear() % 100));

        str = str.replace(/MM/, (this.getMonth() + 1) > 9 ? (this.getMonth() + 1).toString() : '0' + (this.getMonth() + 1));
        str = str.replace(/M/g, (this.getMonth() + 1));

        str = str.replace(/w|W/g, Week[this.getDay()]);

        str = str.replace(/dd|DD/, this.getDate() > 9 ? this.getDate().toString() : '0' + this.getDate());
        str = str.replace(/d|D/g, this.getDate());

        str = str.replace(/hh|HH/, this.getHours() > 9 ? this.getHours().toString() : '0' + this.getHours());
        str = str.replace(/h|H/g, this.getHours());
        str = str.replace(/mm/, this.getMinutes() > 9 ? this.getMinutes().toString() : '0' + this.getMinutes());
        str = str.replace(/m/g, this.getMinutes());

        str = str.replace(/ss|SS/, this.getSeconds() > 9 ? this.getSeconds().toString() : '0' + this.getSeconds());
        str = str.replace(/s|S/g, this.getSeconds());

        return str;
    },
    daysDiff: function(targetDate) {
        var thisDate = this.format("yyyy-MM-dd");
        var thisMonth = thisDate.substring(5, thisDate.lastIndexOf('-'));
        var thisDay = thisDate.substring(thisDate.length, thisDate.lastIndexOf('-') + 1);
        var thisYear = thisDate.substring(0, thisDate.indexOf('-'));

        if (typeof targetDate != 'string')
            targetDate = targetDate.format("yyyy-MM-dd");

        var targetMonth = targetDate.substring(5, targetDate.lastIndexOf('-'));
        var targetDay = targetDate.substring(targetDate.length, targetDate.lastIndexOf('-') + 1);
        var targetYear = targetDate.substring(0, targetDate.indexOf('-'));

        var cha = ((Date.parse(thisMonth + '/' + thisDay + '/' + thisYear) - Date.parse(targetMonth + '/' + targetDay + '/' + targetYear)) / 86400000);
        return Math.abs(cha);
    },
    dateDiff: function(datePart, dtEnd) {
        var dtStart = this;
        if (typeof dtEnd == 'string') dtEnd = dtEnd.toDate();

        switch (datePart.lower()) {
            case 's':
            case 'second': return parseInt((dtEnd - dtStart) / 1000);
            case 'n':
            case 'minute': return parseInt((dtEnd - dtStart) / 60000);
            case 'h':
            case "hour": return parseInt((dtEnd - dtStart) / 3600000);
            case 'd':
            case 'day': return parseInt((dtEnd - dtStart) / 86400000);
            case 'w':
            case 'week': return parseInt((dtEnd - dtStart) / (86400000 * 7));
            case 'm':
            case 'month': return (dtEnd.getMonth() + 1) + ((dtEnd.getFullYear() - dtStart.getFullYear()) * 12) - (dtStart.getMonth() + 1);
            case 'y':
            case 'year': return dtEnd.getFullYear() - dtStart.getFullYear();
        }
    },
    dateAdd: function(datePart, Number) {
        var dtTmp = this;
        var date;
        switch (datePart) {
            case 's':
            case 'second': date = new Date(Date.parse(dtTmp) + (1000 * Number)); break;
            case 'm':
            case 'mi':
            case 'minute': date = new Date(Date.parse(dtTmp) + (60000 * Number)); break;
            case 'h':
            case 'H': date = new Date(Date.parse(dtTmp) + (3600000 * Number)); break;
            case 'd':
            case 'day': date = new Date(Date.parse(dtTmp) + (86400000 * Number)); break;
            case 'w':
            case 'week': date = new Date(Date.parse(dtTmp) + ((86400000 * 7) * Number)); break;
            case 'M':
            case 'mon':
            case 'month': date = new Date(dtTmp.getFullYear(), (dtTmp.getMonth()) + Number, dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds()); break;
            case 'y':
            case 'year': date = new Date((dtTmp.getFullYear() + Number), dtTmp.getMonth(), dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp.getSeconds()); break;
        }
        return date.format("yyyy-MM-dd HH:mm:ss");
    },
    dayOfWeek: function() { return this.getDay() + 1; },
    dayOfWeekCn: function() { return ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"][this.getDay() + 1]; },
    dayOfWeekEn: function() { return ["SUNDAY", "MONDAY", "TURESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY"][this.getDay() + 1]; }
});

jQuery.kong = function(index, value) { return value; }
var enumFn = {
    each: function(func, args) { jQuery.each(this, func, args); },
    allFit: function(func) { var result = true; this.each(function(index, value) { result = result && !!(func || jQuery.kong)(index, value); }); return result; },
    anyFit: function(func) { var result = false; this.each(function(index, value) { if (!result) { if ((func || jQuery.kong)(index, value)) result = true; } }); return result; },
    find: function(func, index) { var objs = this.findAll(func); if (index == null) index = 0; if (index > objs.length - 1) index = objs.length - 1; return objs.length == 0 ? null : objs[index]; },
    findAll: function(func) { var results = []; this.each(function(index, value) { results.push((func || jQuery.kong)(index, value)); }); return results; },
    first: function(func) { return this.find(func); },
    last: function(func) { var objs = this.findAll(func); return objs.length == 0 ? null : objs[objs.length - 1]; },
    max: function(func) { var result; this.each(function(index, value) { if (typeof value == 'object' && func == null) throw {}; value = (func || jQuery.kong)(index, value); if (result == undefined || value >= result) result = value; }); return result; },
    min: function(func) { var result; this.each(function(index, value) { value = (func || jQuery.kong)(index, value); if (result == undefined || value < result) result = value; }); return result; }
}

Object.extendFn(Array.prototype, enumFn);

Array.prototype.exist = function(item, att) { if (typeof item == 'string') item = item.lower(); for (var i = 0; i < this.length; i++) { if (typeof item == 'string' && this[i].lower() == item) return true; else if (att != null) { var a1 = eval("this[i]." + att), a2 = eval("item." + att); if (a1.lower() == a2.lower()) return true; } else if (this[i] == item) return true; } return false; }
Array.prototype.add = function() { if (arguments == null || arguments.length == 0) return; for (var i = 0; i < arguments.length; i++) { this[this.length] = arguments[i]; } }
Array.prototype.remove = function() { if (arguments == null || arguments.length == 0) return; var items = []; for (var i = 0; i < arguments.length; i++) { items[items.length] = arguments[i]; } var arr = []; for (var i = 0; i < this.length; i++) { var exist = items.exist(this[i]); if (!exist) arr.add(this[i]); } return arr; }
Array.prototype.fillterItems = function(key, value, key2, value2) { value = value.lower(); var _list = []; this.each(function(index, item) { if (key2 == null) { var v1 = item.getAttribute(key).lower(); if (v1 == value) _list.add(item); } else { var v1 = item.getAttribute(key).lower(), v2 = item.getAttribute(key2).lower(); if ((v1 == value && v2 == value2) || (v1 == value2 && v2 == value)) _list.add(item); } }); return _list; }
Array.prototype.toAttArray = function(att) { var _list = []; this.each(function(index, item) { var v = item.getAttribute(att); _list.add(v); }); return _list; }
Array.prototype.distinct = function() { var _list = []; this.each(function(index, item) { if (!_list.exist(item)) _list.add(item); }); return _list; }


var jqueryExt = {
    ie: navigator.userAgent.lower().indexOf('msie') > -1,
    ie6: navigator.userAgent.lower().indexOf('msie 7') > -1 ? false : navigator.userAgent.lower().indexOf('msie 6') > -1,
    ie7: navigator.userAgent.lower().indexOf('msie 7') > -1,
    ie8: navigator.userAgent.lower().indexOf('msie 8') > -1,
    maxthon: navigator.userAgent.lower().indexOf('maxthon') > -1,
    firefox: navigator.userAgent.lower().indexOf('firefox') > -1,
    google: navigator.userAgent.lower().indexOf('chrome') > -1,
    opera: !!window.opera,
    webKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
    gecko: navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1,
    avail: function() {
        var winWidth = 0, winHeight = 0;
        if (window.innerWidth) { winWidth = window.innerWidth; winHeight = window.innerHeight; }
        else ((document.body) && (document.body.clientWidth))
        { winWidth = document.body.clientWidth; winHeight = document.body.clientHeight; }

        if (document.documentElement && document.documentElement.clientWidth) { winWidth = document.documentElement.clientWidth; winHeight = document.documentElement.clientHeight; }

        return { width: winWidth, height: winHeight };
    },
    docAvail: function() { return { width: document.body.scrollWidth, height: document.body.scrollHeight }; },
    center: function(obj) { var avail = jqueryExt.avail(); var loc = {}; if (typeof obj == 'undefined' || obj == null) { loc.left = avail.width / 2; loc.top = avail.height / 2; } else if (typeof obj == 'object') { loc.left = (avail.width - el.offsetWidth) / 2; loc.top = (avail.height - el.offsetHeight) / 2; } else if (typeof obj == 'string') { obj = fn.idObj(obj); if (obj == null) { loc.left = avail.width / 2; loc.top = avail.height / 2; } else { loc.left = (avail.width - el.offsetWidth) / 2; loc.top = (avail.height - el.offsetHeight) / 2; } } return loc; },
    htmlObj: function(html) { return $(html); },
    maxIndex: function() { var els = $.tagObj("*"), max = 0, z; els.each(function(idx, el) { if (el.style && el.style.zIndex) { z = el.css("zIndex"); if (z != null) { if (typeof z == "string") z = z.toInt(); if (z > max) max = z; } } }); return max; },
    array: function(input) { if (!input) return []; if (input.toArray) return input.toArray(); else { var results = []; for (var i = 0, length = input.length; i < length; i++) results.push(input[i]); return results; } },
    idObj: function(id) { if (typeof id == 'string') return $("#" + id); return $(id); },
    tagObj: function(tag, target) { if (tag == null || tag == "") tag = "*"; if (target == null) return $(tag); if (typeof target == 'string') return $("#{0} {1}".format(target, tag)); if (!target.find) target = $(target); return target.find(tag); },
    attObj: function(att, v, target) {
        if (att == null || att == "")
            return $([]);
        if (target == null) return $("*[@{0}='{1}']".format(att, v));
        if (typeof target == 'string') return $("#{0} > *[@{1}='{2}']".format(target, att, v));
        if (!target.find) target = $(target);
        return target.find("*[@{0}='{1}']".format(att, v));
    },
    nameObj: function(name, target) { return jqueryExt.attObj("name", name, target); },
    classObj: function(c, target) {
        if (c == null || c == "")
            return $([]);
        if (target == null) return $(".{0}".format(c));
        if (typeof target == 'string') return $("#{0} .{1}".format(target, c));
        if (!target.find) target = $(target);
        return target.find(".{0}".format(c));
    },
    url: document.location,
    host: document.location.hostname,
    port: document.location.port,
    path: document.location.pathname,
    root: document.location.protocol + "//" + document.location.hostname + (document.location.port == "80" ? "" : ":" + document.location.port) + "/",
    qstr: document.location.search,
    page: function() {
        var index = this.path.lastIndexOf("/");
        if (index < 0)
            return this.path;
        return this.path.substr(index + 1);
    },
    ext: function() {
        var p = this.page();
        if (p == "")
            return "";
        var index = p.lastIndexOf(".");
        if (index < 0)
            return "";
        return p.substr(index + 1);
    },
    pageNoQ: function() { var u = this.url.toString(); for (var i = 0; i < u.length; i++) { if (u.charAt(i) == '?') return u.substr(0, i); } return u; },
    q: function(key, v) { if (v == null) { key = key.lower(); var queryStr = this.qstr; if (queryStr.length > 0) queryStr = queryStr.substr(1); var kvs = queryStr.split("&"); var itemArray; for (var i = 0; i < kvs.length; i++) { itemArray = kvs[i].split("="); if (itemArray[0].lower() == key && itemArray.length == 2) return itemArray[1]; return ""; } return ""; } else { key = key.lower(); var queryStr = this.qstr; if (queryStr.length > 0) queryStr = queryStr.substr(1); var kvs = queryStr.split("&"), itemArray, newQ = "?", find = false; kvs.each(function(idx, kv) { newQ += idx == 0 ? "" : "&"; itemArray = kv.split("="); if (itemArray[0].lower() == key) { find = true; newQ += "{0}={1}".format(key, v); } else newQ += kv; }); if (!find) newQ += "{0}{1}={2}".format(newQ == "?" ? "" : "&", key, v); return this.pageNoQ() + newQ; } },
    req: function(url, succFn, errFn, preFn, completeFn, getXml) { return $.ajax({ type: "GET", url: url, dataType: (getXml ? "xml" : "html"), beforeSend: preFn, complete: completeFn, success: succFn, error: function(rsp, textStatus, errorThrown) { if (typeof textStatus == 'string' && errFn) errFn(rsp, textStatus, errorThrown); } }); },
    post: function(url, data, succFn, errFn, preFn, completeFn, getXml) { return $.ajax({ type: "POST", url: url, data: data, dataType: (getXml ? "xml" : "html"), beforeSend: preFn, complete: completeFn, success: succFn, error: function(rsp, textStatus, errorThrown) { if (typeof textStatus == 'string' && errFn) errFn(rsp, textStatus, errorThrown) } }); },
    update: function(target, url, succFn, errFn, preFn, completeFn) { return jqueryExt.req(url, function(rsp) { $(target).html(rsp); if (succFn) succFn(rsp); }, function(rsp, textStatus, errorThrown) { if (typeof textStatus == 'string' && errFn) errFn(rsp, textStatus, errorThrown); }, preFn, completeFn, false); },
    parseXslt: function(__xmlDoc, _xsltDoc) {//huang.qc 2009-11-12 add
        var text;
        if (typeof (window.ActiveXObject) != 'undefined') {
            try {
                text = __xmlDoc.documentElement.transformNode(_xsltDoc.documentElement);
            }
            catch (e) {
                text = "";
                alert(e.name + ": " + e.message);
            }
        }
        else if (document.implementation && document.implementation.createDocument) {
            try {
                var xsltProcessor = new XSLTProcessor();
                xsltProcessor.importStylesheet(_xsltDoc);
                var result = xsltProcessor.transformToDocument(__xmlDoc);
                //alert(result);
                var xmls = new XMLSerializer();
                var r1 = /(\<)(\s+)([a-zA-Z]{1,})(\>)/g;
                var r2 = /(\<)(\/)([a-zA-Z]{1,})(\s+)(\>)/g
                text = xmls.serializeToString(result).replace(r1, '<$3>').replace(r2, '</$3>');
            }
            catch (e) {
                text = "";
                alert(e.name + ": " + e.message);
            }
        }
        return text;
    }
}


jQuery.extend(jqueryExt);


var jqueryFnExt = {
    tagObj: function(tag) { return $.tagObj(tag, this); },
    attObj: function(att, v) { return $.attObj(att, v, this); },
    nameObj: function(name) { return $.nameObj(name, this); },
    classObj: function(c) { return $.classObj(c, this); },
    wh: function() {
        var obj = this[0];
        var display = obj.style ? obj.style.display : "none";
        if (display != 'none' && display != null)
            return { width: obj.offsetWidth, height: obj.offsetHeight };

        var els = obj.style;
        var originalVisibility = els.visibility;
        var originalPosition = els.position;
        var originalDisplay = els.display;
        els.visibility = 'hidden';
        els.position = 'absolute';
        els.display = 'block';
        var originalWidth = obj.clientWidth;
        var originalHeight = obj.clientHeight;
        els.display = originalDisplay;
        els.position = originalPosition;
        els.visibility = originalVisibility;
        return { width: originalWidth, height: originalHeight };
    },
    offsetPos: function() { var iPos_x = 0, iPos_y = 0, el = this[0]; while (el != null) { iPos_x += el["offsetLeft"]; iPos_y += el["offsetTop"]; el = el.offsetParent; } return { left: iPos_x, top: iPos_y }; },
    setOpacity: function(value) { var obj = this[0]; obj.style.filter = "alpha(opacity={0})".format(parseFloat(value) * 100); obj.style.opacity = (value == 1 || value === "") ? "" : (value < 0.00001) ? 0 : value; return this; },
    trans: function(opacity) { return this.setOpacity(opacity); },
    bottom: function() { return this[0].offsetPos().top + this[0].offsetHeight; },
    right: function() { return this[0].offsetPos().left + this[0].offsetWidth; },
    isHide: function() { return this.css("display").lower() == "none" || this.css("visibility").lower() == "hidden"; },
    first: function(tag) { return $(this).find("{0}:first-child".format(tag == null || tag == "" ? "*" : tag)); },
    last: function(tag) { return $(this).find("{0}:last-child".format(tag == null || tag == "" ? "*" : tag)); },
    cssTxt: function(_cssTxt, append) { var obj = this[0]; if (_cssTxt != null) { if (append == null || !append) obj.style.cssText = _cssTxt; else obj.style.cssText = obj.style.cssText.toString() + ";" + _cssTxt; return this; } if (!obj.style) return ""; return obj.style.cssText; }
}
jQuery.fn.extend(jqueryFnExt);

if ($.firefox) {
    HTMLElement.prototype.__defineGetter__("outerHTML", function() {
        var a = this.attributes, str = "<" + this.tagName, i = 0; for (; i < a.length; i++)
            if (a[i].specified)
            str += " " + a[i].name + '="' + a[i].value + '"';
        if (!this.canHaveChildren)
            return str + " />";
        return str + ">" + this.innerHTML + "</" + this.tagName + ">";
    });
    HTMLElement.prototype.__defineSetter__("outerHTML", function(s) {
        var r = this.ownerDocument.createRange();
        r.setStartBefore(this);
        var df = r.createContextualFragment(s);
        this.parentNode.replaceChild(df, this);
        return s;
    });
    HTMLElement.prototype.__defineGetter__("canHaveChildren", function() {
        return !/^(area|base|basefont|col|frame|hr|img|br|input|isindex|link|meta|param)$/.test(this.tagName.toLowerCase());
    });

    XMLDocument.prototype.selectSingleNode = Element.prototype.selectSingleNode = function(xpath) {
        var x = this.selectNodes(xpath)
        if (!x || x.length < 1)
            return null;
        return x[0];
    }
    XMLDocument.prototype.selectNodes = Element.prototype.selectNodes = function(xpath) {
        var xpe = new XPathEvaluator();
        var nsResolver = xpe.createNSResolver(this.ownerDocument == null ? this.documentElement : this.ownerDocument.documentElement);
        var result = xpe.evaluate(xpath, this, nsResolver, 0, null);
        var found = [];
        var res;
        while (res = result.iterateNext())
            found.push(res);
        return found;
    }
}

$.close = function() {
    var ua = navigator.userAgent
    var ie = navigator.appName == "Microsoft Internet Explorer" ? true : false;

    if (ie) {
        var IEversion = parseFloat(ua.substring(ua.indexOf("MSIE ") + 5, ua.indexOf(";", ua.indexOf("MSIE "))))
        if (IEversion < 5.5) {
            var str = '<object id=noTipClose classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">'
            str += '<param name="Command" value="Close"></object>';
            document.body.insertAdjacentHTML("beforeEnd", str);
            document.all.noTipClose.Click();
        }
        else {
            window.opener = null;
            window.open('', '_self', ''); //for IE7
            window.close();
        }
    }
    else {
        window.close()
    }
}

