﻿Date.chineseYear='年';Date.chineseMonth='月';Date.chineseDay='日';Date.chineseWeeks=['日','一','二','三','四','五','六'];Date.chineseLongWeeks=['星期日','星期一','星期二','星期三','星期四','星期五','星期六'];
Date.isLeapyear=function(year){year=typeof(year)=='string'?parseInt(year):year;return year%400==0||year%4==0&&year%100!=0;}
Date.getDays=function(year,month){year=typeof(year)=='string'?parseInt(year):year;month=typeof(month)=='string'?parseInt(month):month;return(month>7)?(month%2==0?31:30):(month%2==0?(month==2?(Date.isLeapyear(year)?29:28):30):31);}
Date.check=function(val){if(!val){return false;}return val instanceof Date || typeof(val)=='string'&&val.isDate();}
Date.parseDate=function parseDate(val){if(!val){return null;}if(val instanceof Date){return val;}var reg=new RegExp('[\-\.'+Date.chineseYear+Date.chineseMonth+Date.chineseDay+']','g');var result=new Date(arguments[0].replace(reg,'/'));return isNaN(result)?null:result;}
Date.prototype.isLeapyear=function(){return Date.isLeapyear(this.getFullYear());}
Date.prototype.getDays=function(){return Date.getDays(this.getFullYear(),this.getMonth()+1);}
Date.prototype.add=function(part,n){if(typeof(part)=='string'&&typeof(n)=='number'){var year=this.getFullYear();var mon=this.getMonth();var day=this.getDate();var hour=this.getHours();var min=this.getMinutes();var sec=this.getSeconds();var ms=this.getMilliseconds();if(part.toLowerCase()=='ms'){ms+=n;}else{switch(part){case 'Y':case 'y':year+=n;break;case 'M':mon+=n;break;case 'D':case 'd':day+=n;break;case 'H':case 'h':hour+=n;break;case 'm':min+=n;break;case 'S':case 's':sec+=n;break;default:throw 'unknown date part.';}}return new Date(year,mon,day,hour,min,sec,ms);}};
Number.chineseNumber=['零','一','二','三','四','五','六','七','八','九','十','百','千','万','亿'];
Number.chineseUpperNumber=['零','壹','贰','叁','肆','伍','陆','柒','捌','玖','拾','佰','仟','万','亿'];
String.repeat=function(str,count){var result='';for(var i=0;i<count;i++){result+=str;}return result;}
String.prototype.repeat=function(count){var result='';for(var i=0;i<count;i++){result+=this;}return result;}
String.prototype.isNumber=function(){return /^(\+|-)?\d*(\.?\d+)?$/.test(this);};
String.prototype.isHexNumber=function(){return /^[a-f\d]+$/i.test(this);}
String.prototype.isInteger=function(){return /^(\+|-)?\d+$/.test(this);};
String.prototype.isDate=function(){if(/^([0-9]{1,4})\.([0-9]{1,2})\.([0-9]{1,2})(([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}))?$/.exec(this.replace(new RegExp('[\-\.'+Date.chineseYear+Date.chineseMonth+Date.chineseDay+']','g'),'/'))){var day=RegExp.$3;var days=Date.getDays(RegExp.$1,RegExp.$2);if(RegExp.$4==''){return day<=days;}else{return day<=days&&parseInt(RegExp.$5)<24&&parseInt(RegExp.$6)<60&&parseInt(RegExp.$7)<60;}}else return false;};
String.prototype.isEmail=function(){return /^(\w+([-+.]\w)+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/i.test(this);};
String.prototype.isColor=function(){return /(^#[0-9a-f]{3}$)|(^#[0-9a-f]{6}$)/i.test(this);}
String.prototype.regEscape=function(){return this.replace(/([\^\$\(\)\[\]\{\}\*\+\.\?\\\/\|])/g,'\\$1');};
String.prototype.trim=function(){if(arguments.length==0){return this.replace(/(^\s*)|(\s*$)/g,'');}else{if(typeof(arguments[0])=='string'){return this.replace(new RegExp('(^'+arguments[0].regularEscape()+ '*)|('+arguments[0].regularEscape+'*$)' ,'g'),'');}else{return this;}}};
String.prototype.trimStart=function(){if(arguments.length==0){return this.replace(/(^\s*)/g,'');}else{if(typeof(arguments[0])=='string'){return this.replace(new RegExp('(^'+arguments[0].RegEscape()+'*)' ,'g'),'');}else{return this;}}};
String.prototype.trimEnd=function(){if(arguments.length==0){return this.replace(/(\s*$)/g,'');}else{if(typeof(arguments[0])=='string'){return this.replace(new RegExp('('+arguments[0].RegEscape()+'*$)' ,'g'),'');}else{return this;}}};
String.prototype.startWith=function(str){return new RegExp('^'+str.regEscape()).test(this);}
String.prototype.endWith=function(str){return new RegExp(str.regEscape+'$').test(this);}
String.prototype.format = function(){var args=arguments;return this.replace(/\{(\d+)\}/g,function(m,i){return args[i];});};
String.prototype.repeat=function(times){var result='';for(var i=0;i<times;i++){result+=this;}return result;}
Array.each=function(arr,fn){if(arr instanceof Array){for(var i=0;i<arr.length;i++){__exec(fn,arr[i]);}}}
window.$=function(id,doc){if(id){return doc?doc.getElementById(id):document.getElementById(id);}}
window.$$=function(tag,id,doc){if(tag&&tag!=''){var result=doc?doc.createElement(tag):document.createElement(tag);if(id&&id!=''){result.setAttribute('id',id);}return result;}}
window.$$t=function(text,doc){return doc?(text?doc.createTextNode(text.toString()):doc.createTextNode()):(text?document.createTextNode(text.toString()):document.createTextNode());}
window.$p=function(element){var result={};result.x=0;result.y=0;result.width=0;result.height=0;if(element.offsetParent){result.x=element.offsetLeft;result.y=element.offsetTop;var parent=element.offsetParent;while(parent){result.x+=parent.offsetLeft;result.y+=parent.offsetTop;var parentTagName=parent.tagName.toLowerCase();if(parentTagName!='table' &&parentTagName!='body'&&parentTagName!='html'&&parentTagName!='div'&&parent.clientTop&&parent.clientLeft){result.x+=parent.clientLeft;result.y+=parent.clientTop;}parent=parent.offsetParent;}}else if(element.left&&element.top){result.x=element.left;result.y=element.top;}else{if(element.x){result.x=element.x;}if(element.y){result.y=element.y;}}if(element.offsetWidth&&element.offsetHeight){result.width=element.offsetWidth;result.height=element.offsetHeight;}else if(element.style&&element.style.pixelWidth&&element.style.pixelHeight){result.width=element.style.pixelWidth;result.height=element.style.pixelHeight;}return result;}
window.$b=document.compatMode=='CSS1Compat'?document.documentElement:document.body;
window.$q=new function(){queryString=window.location.search.substring(1);if(queryString.length>0){var parts=queryString.split('&');for(var s in parts){var pair=parts[s].split('=');this[pair[0]]=pair[1];}}}();
window.exec=function(){if(arguments[0]){var args=new Array();for(var i=1;i<arguments.length;i++){args.push(arguments[i]);}if(typeof(arguments[0])=='function'){if(args.length>0){return arguments[0].apply(arguments[0],args);}else{return arguments[0].apply(arguments[0],[]);}}else if(typeof(arguments[0])=='string'){return eval(arguments[0]);}}};
window.handler=function(){};window.handler.isHandler=function(fn){return typeof(fn)=='function'&&fn.prototype&&fn.prototype.constructor==handler;};
window.handler.create=function()
{
    var result=function()
    {
        var params=new Array();
        for(var i=0;i<arguments.length;i++)
        {
            params.push(arguments[i]);
        }
        for(var m in result.prototype)
        {
            var fn=result.prototype[m];
            if(typeof(fn)=='function')
            {
                return fn.apply(fn,params);
            }
            else
            {
                return eval(fn);
            }
        }
    };
    result.prototype=new handler();
    result.attach=function(fn,id)
    {
        switch(typeof(fn))
        {
            case 'function':
                result.prototype[typeof(id)=='string'&&id!=''?id:identity().toString()]=fn;
                break;
            case 'string':
                result.prototype[typeof(id)=='string'&&id!=''?id:fn]=fn;
                break;
        }
    };
    result.detach=function(id)
    {
        switch(typeof(id))
        {
            case 'function':
                for(var m in result.prototype)
                {
                    if(id==result.prototype[m])
                    {
                        delete result.prototype[m];
                        break;
                    }
                }
                break;
            case 'string':
                if(typeof(id)=='string'&&id!='')
                {
                    delete result.prototype[id];
                }
                break;
        }
    };
    result.exists=function(id)
    {
        switch(typeof(id))
        {
            case 'function':
                for(var m in result.prototype)
                {
                    if(id==result.prototype[m])
                    {
                        return true;
                    }
                }
                return false;
            case 'string':
                return id in result.prototype;
        }
    };
    result.clear=function()
    {
        for(var m in result.prototype)
        {
            delete result.prototype[m];
        }
    };
    result.isEmpty=function()
    {
        for(var m in result.prototype)
        {
            return false;
        }
        return true;
    };
    return result;
};
window.identity=function(){return (window.identity.seed++);};
window.identity.seed=0;