﻿// JScript 文件

function Inherit(d, s, b)
{
    for(p in s)
    {
        if(b == true || d[p] == undefined || d[p] == null)
        {
            d[p] = s[p];
        }
    }
    return d;
}
Inherit(Array.prototype, {
    push: function(o) 
    {
	    this[this.length] = o;
	    return this.length;
    },
    dele: function(index)
    {
        if(this.length == 0 || this.length < index)
        {
            return null;
        }
        else
        {
            var o = this[index];
            for(var i = index; i < this.length - 1; i++)
            {
                this[i] = this[i + 1];
            }
            this.length = this.length - 1;
            return o;
        }
    },
    pop: function()
    {
        if(this.length == 0)
        {
            return null;
        }
        else
        {
            var o = this[this.length - 1];
            this.length = this.length - 1;
            return o;
        }
    },
    addRange: function(o)
    {
        if(o.length > 0)
        {
            for(var i = 0; i < o.length; i++)
            {
                this.push(o[i]);
            }
        }
    },
    clear: function()
    {
        this.length = 0;
    },
    shift: function()
    {
        if(this.length == 0)
        {
            return null;
        }
        else
        {
            var o = this[0];
            for(var i = 1; i < this.length; i++)
            {
                this[i - 1] = this[i];
            }
            this.length = this.length - 1;
            return o;
        }
    },
    indexOf: function(o)
    {
        for (var i = 0; i < this.length; i++)
        {
            if (this[i] === o)
            {
                return i;
            }
        }
        return -1;
    },
    contains: function(o)
    {
        if(this.indexOf(o) == -1)
        {
            return false;
        }
        else
        {
            return true;
        }
    },
    clone: function(a, b)
    {
        if(a == undefined || a == null)
        {
            a = 0;
        }
        if(b == undefined || b == null || b > this.length - a)
        {
            b = this.length;
        }
        else
        {
            b = a + b;
        }
        var o = new Array();
        for(var i = a; i < b; i++)
        {
            o[i - a] = this[i];
        }
        return o;
    },
    remove: function(o)
    {
        var p = this.indexOf(o);
        if(p == -1)
        {
            return;
        }
        for(var i = p; i < this.length - 1; i++)
        {
            this[i] = this[i + 1];
        }
        this.length = this.length - 1;
    }
},false);
Inherit(String.prototype, {
    trimLeft: function() 
    {
	    return this.replace(/^\s*/,"");
    },
    trimRight: function() 
    {
	    return this.replace(/\s*$/,"");
    },
    trim: function()
    {
        return this.trimRight().trimLeft();
    },
    startsWith: function(s) 
    {
	    if(this.length == 0 || this.length < s.length)
	    {
	        return false;
	    }
	    else
	    {
	        if(this.substr(0, s.length) == s)
	        {
	            return true;
	        }
	        else
	        {
	            return false;
	        }
	    }
    },
    endsWith: function(s) 
    {
	    if(this.length == 0 || this.length < s.length)
	    {
	        return false;
	    }
	    else
	    {
	        if(this.substr(this.length - s.length) == s)
	        {
	            return true;
	        }
	        else
	        {
	            return false;
	        }
	    }
    },
    split: function(c)
    {
	    var a = new Array();
	    if(this.length == 0)
	    {
	        return a;
	    }
	    var p = 0;
	    for(var i=0; i<this.length; i++) 
	    {
		    if(this.charAt(i) == c) 
		    {
			    a.push(this.substring(p, i));
			    p = ++i;
		    }
	    }
	    a.push(s.substr(p));
	    return a;
    }
},false);
Inherit(Date.prototype,{
    toLongString: function()
    {
        return this.getFullYear() + "-" + (this.getMonth() < 9 ? ("0" + (this.getMonth() + 1)) : (this.getMonth() + 1)) + "-" + (this.getDate() < 10 ? ("0" + this.getDate()) : this.getDate()) + " " + (this.getHours() < 10 ? ("0" + this.getHours()) : this.getHours()) + ":" + (this.getMinutes() < 10 ? ("0" + this.getMinutes()) : this.getMinutes()) + ":" + (this.getSeconds() < 10 ? ("0" + this.getSeconds()) : this.getSeconds());
    },
    toShortString: function()
    {
        return this.getFullYear() + "-" + (this.getMonth() < 9 ? ("0" + (this.getMonth() + 1)) : (this.getMonth() + 1)) + "-" + (this.getDate() < 10 ? ("0" + this.getDate()) : this.getDate());
    },
    addYears: function(y)
    {
        this.setFullYear(this.getFullYear() + y);
        return this;
    },
    addMonths: function(m)
    {
        this.setMonth(this.getMonth() + m);
        return this;
    },
    addDays: function(d)
    {
        this.setDate(this.getDate() + d);
        return this;
    },
    addHours: function(h)
    {
        this.setHours(this.getHours() + h);
        return this;
    },
    addMinutes: function(m)
    {
        this.setMinutes(this.getMinutes() + m);
        return this;
    },
    addSeconds: function(s)
    {
        this.setSeconds(this.getSeconds() + s);
        return this;
    }
},false);
Date.parseString = function(s)
{
    var a = s.split(" ");
    var b = a[0].split("-");
    if(a.length == 2)
    {
        c = a[1].split(":");
        return new Date(Number(b[0]),Number(b[1]) - 1,Number(b[2]),Number(c[0]),Number(c[1]),Number(c[2]));
    }
    else
    {
        return new Date(Number(b[0]),Number(b[1]) - 1,Number(b[2]));
    }
};
Inherit(Function.prototype,{
    getArgs: function()
    {
        var a = new Array();
        for(var i = 0; i < this.arguments.length; i++)
        {
            a.push(this.arguments[i]);
        }
        return a;
    },
    apply: function(o, a) 
    {
        if(o == undefined || o == null)
        {
            o = new object();
        }
        if(a == undefined || a == null)
        {
            a = new Array();
        }
        o["__a__"] = this;
        var p = new Array();
        for(var i = 0; i < a.length; i++)
        {
            p[i] = "a[" + i.toString() + "]";
        }
        var r = eval("o.__a__(" + p.join(",") + ")");
        delete o["__a__"];
        return r;
    },
    bind: function(o)
    {
        var __method__ = this;
        return function()
        {
            return __method__.apply(o,arguments);
        };
    }
},false);
if(typeof(addEvent) == "undefined")
{
	addEvent = function(o, n, f, c) 
	{
		if(o != undefined && o != null)
		{
		    if(o.attachEvent) 
		    {
			    o.attachEvent("on" + n, f);
		    }
		    else if(o.addEventListener) 
		    {
			    o.addEventListener(n, f, c);
		    } 
		    else 
		    {
			    try
			    { 
			        o["on" + n] = f; 
			    }
			    catch(e)
			    {
			    }
		    }
		}
	};
};
if(typeof removeEvent == "undefined")
{
	removeEvent = function(o, n, f, c) 
	{
		if(o != undefined && o != null)
		{
		    if (o.detachEvent) 
		    {
			    o.detachEvent("on" + n, f);
		    }
		    else if(o.removeEventListener) 
		    {
			    o.removeEventListener(n, f, c);
		    } 
		    else
		    {
			    try
			    { 
			        o["on" + n] = function()
			        {
			        }; 
			    }
			    catch(e)
			    {
			    }
		    }
		}
	};
};
function __client()
{
    var client = window.navigator.userAgent.toLowerCase();
    this.isIE = client.indexOf("msie") != -1;
    this.isFF = client.indexOf("firefox") != -1;
    this.isOP = client.indexOf("opera") != -1;
    this.isNS = client.indexOf("netscape") != -1;
}
var $Client = new __client();
function $()
{
    switch (arguments.length)
    {
        case 0:
            throw "No argument received.";
        case 1:
            if (typeof(arguments[0]) == "string")
            {
                return document.getElementById(arguments[0]);
            }
            else
            {
                throw "Data type of arguments[0]{" + arguments[0].toString() + "} is not string.";
            }
        default:
            var e = new Array();
            for (var i = 0; i < arguments.length; i++)
            {
                if (typeof(arguments[i]) == "string")
                {
                    e.push(document.getElementById(arguments[i]));
                }
                else
                {
                    throw "Data type of arguments[" + i.toString() + "]{" + e[i].toString() + "} is not string.";
                }
            }
            return e;
    }
}
function $V()
{
   switch (arguments.length)
    {
        case 0:
            throw "No argument received.";
        case 1:
            if (typeof(arguments[0]) == "string")
            {
                var o = document.getElementById(arguments[0]);
                if(o.type == "text")
                {
                    return o.value;
                }
                else if(o.type == "checkbox")
                {
                    return o.checked;
                }
                else
                {
                    return o.value;                    
                }
            }
            else
            {
                throw "Data type of arguments[0]{" + arguments[0].toString() + "} is not string.";
            }
        default:
            var e = new Array();
            for (var i = 0; i < e.length; i++)
            {
                if (typeof(arguments[i]) == "string")
                {
                    e.push($V(arguments[i]));
                }
                else
                {
                    throw "Data type of arguments[" + i.toString() + "]{" + arguments[i].toString() + "} is not string.";
                }
            }
            return e;
    }
}
function $Event()
{
    this.__event = arguments[0];
    if($Client.isFF == true)
    {
        this.srcElement = this.__event.target;
        this.fromElement = this.__event.relatedTarget;
        this.clientX = this.__event.clientX;
        this.clientY = this.__event.clientY;
        this.offsetX = this.__event.layerX;
        this.offsetY = this.__event.layerY;
        this.keyCode = this.__event.keyCode;
        this.type = this.__event.type;
        this.altKey = this.__event.altKey;
        this.ctrlKey = this.__event.ctrlKey;
        this.shiftKey = this.__event.shiftKey;
        this.cancelBubble = this.__event.stopPropagation;
        this.returnValue = this.__event.preventDefault;
        switch(this.__event.button)
        {
            case 0:
                this.button = 1;
                break;
            case 1:
                this.button = 4;
                break;
            default:
                this.button = this.__event.button;
                break;
        }
    }
    else
    {
        this.srcElement = this.__event.srcElement;
        this.fromElement = this.__event.fromElement;
        this.clientX = this.__event.clientX;
        this.clientY = this.__event.clientY;
        this.offsetX = this.__event.offsetX;
        this.offsetY = this.__event.offsetY;
        this.keyCode = this.__event.keyCode;
        this.type = this.__event.type;
        this.altKey = this.__event.altKey;
        this.ctrlKey = this.__event.ctrlKey;
        this.shiftKey = this.__event.shiftKey;
        this.cancelBubble = function(_arg)
        {
            this.__event.cancelBubble = _arg;
        };
        this.returnValue = function(_arg)
        {
            this.__event.returnValue = _arg;
        };
        this.button = this.__event.button;
    }
}
function __args(p,l)
{
    var a = new Array();
    for(var i = 0; i < l; i++)
    {
        if(p[i] == undefined || p[i] == null)
        {
            a.push(null);
        }
        else
        {
            a.push(p[i]);
        }
    }
    return a;
}
function __date(o)
{
    if(o == null || o == undefined)
    {
        return null;
    }
    else
    {
        var y = o.getUTCFullYear();
        var m = o.getUTCMonth();
        var d = o.getUTCDate();
        var h = o.getUTCHours();
        var ms = o.getUTCMinutes();
        var s = o.getUTCSeconds();
        var mss = o.getUTCMilliseconds()
        return "(" + Date.UTC(y,m,d,h,ms,s,mss) + ")";
    }
}
function __xml()
{
    if(arguments.length == 0)
    {
        if($Client.isFF == true)
        {
            return document.implementation.createDocument("","",null);
        }
        else
        {
            var o = ["new ActiveXObject(\"MSXML2.DOMDocument.3.0\")","new ActiveXObject(\"Msxml2.DOMDocument\")"];
            for(var i = 0; i < o.length; i++)
            {
                try
                {
                    return eval(o[i]);
                }
                catch(e)
                {
                }
            }            
        }
        throw "Can't Create ActiveXObject For XML Element.";
    }
    else
    {
        var xml = new __xml();
        xml.async = false;
        xml.loadXML(arguments[0]);
        while(xml.readyState != 4)
        {
        }
        return xml;
    }
}
function __xmlHttp()
{
    var o = new Array("new ActiveXObject(\"Microsoft.XMLHTTP\")","new ActiveXObject(\"Msxml2.XMLHTTP.4.0\")","new ActiveXObject(\"MSXML2.XMLHTTP\")","new ActiveXObject(\"MSXML3.XMLHTTP\")","new XMLHttpRequest()");
    for(var i = 0; i < o.length; i++)
    {
        try
        {
            return eval(o[i]);
        }
        catch(e)
        {
        }
    }
    throw "XMLHTTP Object can't create.";
}
function toJSON(o) 
{
	if(o == undefined || o == null)
	{
		return "null";
    }
	switch(o.constructor.toString().split(" ")[1]) 
	{
		case "String()":
			var v = [];
			for(var i = 0; i < o.length; i++) 
			{
				var c = o.charAt(i);
				if(c >= " ") 
				{
					if(c == "\\" || c == '"') 
					{
					    v.push("\\");
					}
					v.push(c);
				} 
				else 
				{
					switch(c) 
					{
						case "\n": 
						    v.push("\\n"); 
						    break;
						case "\r": 
						    v.push("\\r"); 
						    break;
						case "\b": 
						    v.push("\\b"); 
						    break;
						case "\f": 
						    v.push("\\f"); 
						    break;
						case "\t": 
						    v.push("\\t"); 
						    break;
						default:
							v.push("\\u00");
							v.push(c.charCodeAt().toString(16));
					}
				}
			}
			return '"' + v.join('') + '"';
		case "Array()":
			var v = [];
			for(var i=0; i<o.length; i++)
			{
				v.push(toJSON(o[i])) ;
		    }
			return "[" + v.join(",") + "]";
		case "Number()":
		    if(isFinite(o))
		    {
		        return o.toString();
		    }
		    else
		    {
		        return toJSON(null);
		    }
		case "Boolean()":
			return o.toString();
		case "Date()":
		    return __date(o);
		default:
			if(typeof o == "object") 
			{
				var v=[];
				for(attr in o) 
				{
					if(typeof o[attr] != "function")
					{
						v.push('"' + attr + '":' + toJSON(o[attr]));
					}
				}
				if(v.length>0)
				{
					return "{" + v.join(",") + "}";
				}
				return "{}";		
			}
			return o.toString();
	}
}
function doZoom(size)
{
    document.getElementById('TextDiv').style.fontSize = size + 'px';
}


