﻿if (typeof (Swao) == 'undefined')
    Swao = new Object();

Swao.register = function (namespace) {
    ///	<summary>
    ///	命名空间注册
    ///	</summary>
    ///	<param name="namespace" type="String">命名空间</param>

    var nsArray = namespace.split('.');
    var sEval = "";
    var sNS = "";
    for (var i = 0; i < nsArray.length; i++) {
        if (i != 0) sNS += ".";
        sNS += nsArray[i];
        // 依次创建构造命名空间对象
        sEval += "if (typeof(" + sNS + ") == 'undefined') " + sNS + " = new Object();"
    }
    if (sEval != "") eval(sEval);
};

﻿

if (typeof (Swao) == 'undefined')
    Swao = new Object();
if (typeof (Swao.Const) == 'undefined')
    Swao.Const = new Object();
//Swao.register('Swao.Const');

Swao.Const = {

};

Swao.Const.SearchAllString = 'All';
Swao.Const.SearchMaxNumber = 10000;
﻿
Swao.buildTime = function () {
    return "2011/04/20 11:58:46";
}
Swao.codeTime = function () {
    return "2011/04/19 10:49:21";
}
Swao.version = function () {
    return "1.0.0.5927";
}
Swao.copyRight = function () {
    return "http://www.swao.cn";
}
﻿
if (typeof (Swao.base) == 'undefined')
    Swao.base = new Object();
if (typeof (Swao.base.ClientRecord) == 'undefined')
    Swao.base.ClientRecord = new Object();
//Swao.register('Swao.base.ClientRecord');

Swao.base.ClientRecord = function (category) {
    ///	<summary>
    ///	客户端记录列表管理工具，数据是JSON格式存放在本地cookie。对象必须支持函数[bool equals(obj)]
    ///	</summary>
    ///	<param name="category" type="string">记录类别</param>

    var validDays = 3;
    var maxLength = 10;
    var CRMCategory = 'CRM_' + category;

    this.add = function (obj) {
        ///	<summary>
        ///	添加对象，如果存在则删除重复的
        ///	</summary>
        ///	<param name="obj" type="object">需添加的对象</param>

        var data = Swao.utils.Cookie.get(CRMCategory);
        var clientRecordMap = Array();
        if (Swao.utils.String.isNullOrEmpty(data)) {
            // 直接新加一条记录
            clientRecordMap.push(obj);
        }
        else {
            clientRecordMap = JSON.parse(data);
            var removeResult = innerRemove(clientRecordMap, obj);
            if (removeResult[0])
                clientRecordMap = removeResult[1];

            // 保证不超过最大条数，超过删除最早的
            while (clientRecordMap.length >= maxLength)
                clientRecordMap = clientRecordMap.remove(0);
            // 保证不超过最大条数，超过删除最早的

            clientRecordMap.push(obj);
        }
        Swao.utils.Cookie.set(CRMCategory, JSON.stringify(clientRecordMap), validDays);
    };

    this.update = function (obj) {
        ///	<summary>
        ///	更新匹配的对象，如不存在则不更新
        ///	</summary>
        ///	<param name="obj" type="object">需更新的对象</param>
        ///	<returns type="boolean">更新发生</returns>

        var data = Swao.utils.Cookie.get(CRMCategory);
        var clientRecordMap = JSON.parse(data);

        var matchIndex = innerMatch(clientRecordMap, obj);

        // 如有匹配则更新
        if (matchIndex >= 0) {
            clientRecordMap[matchIndex] = obj;
            Swao.utils.Cookie.set(CRMCategory, JSON.stringify(clientRecordMap), validDays);
            return true;
        }
        else
            return false;
    };

    this.remove = function (obj) {
        ///	<summary>
        ///	删除匹配的对象
        ///	</summary>
        ///	<param name="obj" type="object">需删除的对象</param>
        ///	<returns type="boolean">删除发生</returns>

        var data = Swao.utils.Cookie.get(CRMCategory);
        var clientRecordMap = JSON.parse(data);
        var removeResult = innerRemove(clientRecordMap);
        if (removeResult[0]) {
            // 删除发生了才更新
            Swao.utils.Cookie.set(CRMCategory, JSON.stringify(removeResult[1]), validDays);
            return true;
        }
        else
            return false;
    };

    this.readList = function () {
        ///	<summary>
        ///	获取所有的对象列表，按照添加时间从旧到新排序
        ///	</summary>
        ///	<returns type="Array">对象数组</returns>

        var data = Swao.utils.Cookie.get(CRMCategory)
        var clientRecordMap = JSON.parse(data);
        return clientRecordMap;
    };

    this.clear = function () {
        Swao.utils.Cookie.remove(CRMCategory);
    };

    var innerRemove = function (clientRecordMap, obj) {
        ///	<summary>
        ///	删除匹配的对象
        ///	</summary>
        ///	<param name="clientRecordMap" type="Array">需要检索的数组</param>
        ///	<param name="obj" type="object">需删除的对象</param>
        ///	<returns type="boolean">删除发生</returns>
        ///	<returns type="Array">删除发生才返回数组</returns>

        // 匹配检查
        var matchIndex = innerMatch(clientRecordMap, obj);

        // 如有匹配则删除
        if (matchIndex >= 0) {
            return [true, clientRecordMap.remove(matchIndex)];
        }
        else
            return [false];
    };

    var innerMatch = function (clientRecordMap, obj) {
        ///	<summary>
        ///	匹配对象
        ///	</summary>
        ///	<param name="clientRecordMap" type="Array">需要检索的数组</param>
        ///	<param name="obj" type="object">需删除的对象</param>
        ///	<returns type="int">匹配的索引，>=0表示有匹配</returns>

        // 匹配检查
        var matchIndex = -1;
        for (i = 0; i < clientRecordMap.length; i++) {
            if (obj.equals(clientRecordMap[i])) {
                matchIndex = i;
                break;
            }
        }
        return matchIndex;
    };
};

﻿
if (typeof (Swao.base) == 'undefined')
    Swao.base = new Object();
if (typeof (Swao.base.Dictionary) == 'undefined')
    Swao.base.Dictionary = new Object();
//Swao.register('Swao.base.Dictionary');

Swao.base.Dictionary = function () {
    ///	<summary>
    ///	<key, value>映射
    ///	</summary>

    this.data = new Array(); //定义数组属性      

    this.put = function (_key, _value) {
        ///	<summary>
        ///	新增，如果有则更新
        ///	</summary>
        ///	<param name="_key" type="object"></param>
        ///	<param name="_value" type="object"></param>

        var i;
        for (i = 0; i < this.data.length; i++) {
            if (this.data[i].key == _key) {
                this.data[i].value = _value;
                break;
            }
        }
        if (this.data.length == i) {
            this.data.push({ key: _key, value: _value })
        }
    }

    this.get = function (_key) {
        ///	<summary>
        ///	返回指定键所映射的值
        ///	</summary>
        ///	<param name="_key" type="object"></param>
        ///	<returns type="object">值，没找到无返回</returns>

        for (var i = 0; i < this.data.length; i++) {
            if (this.data[i].key == _key) {
                return this.data[i].value;
            }
        }
    }

    this.remove = function (_key) {
        ///	<summary>
        ///	删除指定键的映射
        ///	</summary>
        ///	<param name="_key" type="object"></param>

        for (var i = 0; i < this.data.length; i++) {
            if (this.data[i].key == _key) {
                this.data.splice(i, 1);
            }
        }
    }

    this.putList = function (dic) {
        ///	<summary>
        ///	新增列表，如果有则更新
        ///	</summary>
        ///	<param name="dic" type="Dictionary"></param>

        var i;
        for (i = 0; i < dic.data.length; i++) {
            this.put(dic.data[i].key, dic.data[i].value);
        }
    }

    this.contain = function (_key) {
        ///	<summary>
        ///	是否包含指定键
        ///	</summary>
        ///	<param name="_key" type="object"></param>
        ///	<returns type="boolean">包含返回true</returns>

        return (this.get(_key) != null);
    }

    this.size = function () {
        ///	<summary>
        ///	获取数量
        ///	</summary>
        ///	<returns type="int">数量</returns>

        return this.data.length;
    }

    this.isEmpty = function () {
        ///	<summary>
        ///	空映射判断
        ///	</summary>
        ///	<returns type="boolean">空则返回true</returns>

        return this.data.length == 0;
    }

    this.clear = function () {
        ///	<summary>
        ///	删除所有映射
        ///	</summary>

        this.data.splice(0, this.data.length);
    }

    this.keySet = function () {
        ///	<summary>
        ///	返回所有的key列表
        ///	</summary>
        ///	<returns type="Array">key列表</returns>

        var keySet = new Array();
        for (var i = 0; i < this.data.length; i++) {
            keySet.push(this.data[i].key);
        }
        return keySet;
    }

    this.values = function () {
        ///	<summary>
        ///	返回所有的value列表
        ///	</summary>
        ///	<returns type="Array">value列表</returns>

        var values = new Array();
        for (var i = 0; i < this.data.length; i++) {
            values.push(this.data[i].value);
        }
        return values;
    }

    this.toJsonString = function () {
        ///	<summary>
        ///	返回映射的json格式字符串[数组]
        ///	</summary>
        ///	<returns type="String">json格式字符串</returns>
        var sb = '{';
        for (var i = 0; i < this.data.length; i++) {
            if (i == this.data.length - 1) {
                sb += Swao.utils.String.format('"{0}":"{1}"', this.data[i].key, this.data[i].value);
            }
            else {
                sb += Swao.utils.String.format('"{0}":"{1}",', this.data[i].key, this.data[i].value);
            }
        }
        sb += '}';
        return sb;
    }

    this.clone = function () {
        ///	<summary>
        ///	返回this的克隆
        ///	</summary>
        ///	<returns type="Dictionary"></returns>

        var F = function () { }
        F.prototype = this;
        return new F();
    }
};

﻿
if (typeof (Swao.base) == 'undefined')
    Swao.base = new Object();
if (typeof (Swao.base.Guid) == 'undefined')
    Swao.base.Guid = new Object();

Swao.base.Guid = function (g) {
    ///	<summary>
    ///	表示全局唯一标识符 (GUID)。
    ///	a)“N”： xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    ///	b)“D”  由连字符分隔的 32 位数字 xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
    ///	c)“B”  括在大括号中、由连字符分隔的 32 位数字：{... ...}
    ///	d)“P”  括在圆括号中、由连字符分隔的 32 位数字：(... ...)
    ///	</summary>
    ///	<param name="g" type="String">GUID字符串格式编码（N\D\B\P）</param>

    var arr = new Array(); //存放32位数值的数组
    if (typeof (g) == "string") { //如果构造函数的参数为字符串
        initByString(arr, g);
    }
    else {
        initByOther(arr);
    }

    this.equals = function (o) {
        ///	<summary>
        ///	返回一个值，该值指示 Guid 的两个实例是否表示同一个值。
        ///	</summary>
        ///	<param name="o" type="Guid">用于比较的字符串Guid</param>
        ///	<returns type="boolean">等于</returns>

        if (o && o.isGuid) {
            return this.toString() == o.toString();
        }
        else {
            return false;
        }
    }

    this.isGuid = function () {
        ///	<summary>
        ///	Guid对象的标记
        ///	</summary>
        ///	<returns type="boolean">是GUID</returns>

        return (arr.length == 32);
    }

    this.toString = function (format) {
        ///	<summary>
        ///	返回 Guid 类的此实例值的 String 表示形式。
        ///	</summary>
        ///	<param name="format" type="String">GUID字符串格式编码（N\D\B\P）</param>
        ///	<returns type="String">GUID字符串</returns>

        if (typeof (format) == "string") {
            if (format == "N" || format == "D" || format == "B" || format == "P") {
                return toStringWithFormat(arr, format);
            }
            else {
                return toStringWithFormat(arr, "D");
            }
        }
        else {
            return toStringWithFormat(arr, "D");
        }
    }

    function initByString(arr, g) {
        ///	<summary>
        ///	由字符串加载
        ///	</summary>
        ///	<param name="arr" type="？">？</param>
        ///	<param name="g" type="？">？</param>

        g = g.replace(/\{|\(|\)|\}|-/g, "");
        g = g.toLowerCase();
        if (g.length != 32 || g.search(/[^0-9,a-f]/i) != -1) {
            initByOther(arr);
        }
        else {
            for (var i = 0; i < g.length; i++) {
                arr.push(g[i]);
            }
        }
    }

    function initByOther(arr) {
        ///	<summary>
        ///	由其他类型加载
        ///	</summary>
        ///	<param name="arr" type="？">？</param>

        var i = 32;
        while (i--) {
            arr.push("0");
        }
    }

    function toStringWithFormat(arr, format) {
        ///	<summary>
        ///	根据所提供的格式说明符，返回此 Guid 实例值的 String 表示形式。
        ///	</summary>
        ///	<param name="arr" type="？">？</param>
        ///	<param name="format" type="String">GUID字符串格式编码（N\D\B\P）</param>
        ///	<returns type="String">GUID字符串</returns>

        switch (format) {
            case "N":
                return arr.toString().replace(/,/g, "");
            case "D":
                var str = arr.slice(0, 8) + "-" + arr.slice(8, 12) + "-" + arr.slice(12, 16) + "-" + arr.slice(16, 20) + "-" + arr.slice(20, 32);
                str = str.replace(/,/g, "");
                return str;
            case "B":
                var str = toStringWithFormat(arr, "D");
                str = "{" + str + "}";
                return str;
            case "P":
                var str = toStringWithFormat(arr, "D");
                str = "(" + str + ")";
                return str;
            default:
                return new Guid();
        }
    }
}

///	<summary>
///	Guid 类的默认实例，其值保证均为零。
///	</summary>
Swao.base.Guid.Empty = new Swao.base.Guid();

Swao.base.Guid.create = function (format) {
    ///	<summary>
    ///	初始化 Guid 类的一个新实例。
    ///	</summary>
    ///	<param name="format" type="String">GUID字符串格式编码（N\D\B\P）</param>
    ///	<returns type="String">GUID字符串</returns>

    var g = "";
    var i = 32;
    while (i--) {
        g += Math.floor(Math.random() * 16.0).toString(16);
    }
    var guid = new Swao.base.Guid(g);
    if (typeof (format) == 'undefined') {
        return guid.toString("D")
    }
    else { return guid.toString(format) }
};
﻿/*
    http://www.JSON.org/json2.js
    2010-03-20

    Public Domain.

    NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.

    See http://www.JSON.org/js.html


    This code should be minified before deployment.
    See http://javascript.crockford.com/jsmin.html

    USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
    NOT CONTROL.


    This file creates a global JSON object containing two methods: stringify
    and parse.

        JSON.stringify(value, replacer, space)
            value       any JavaScript value, usually an object or array.

            replacer    an optional parameter that determines how object
                        values are stringified for objects. It can be a
                        function or an array of strings.

            space       an optional parameter that specifies the indentation
                        of nested structures. If it is omitted, the text will
                        be packed without extra whitespace. If it is a number,
                        it will specify the number of spaces to indent at each
                        level. If it is a string (such as '\t' or '&nbsp;'),
                        it contains the characters used to indent at each level.

            This method produces a JSON text from a JavaScript value.

            When an object value is found, if the object contains a toJSON
            method, its toJSON method will be called and the result will be
            stringified. A toJSON method does not serialize: it returns the
            value represented by the name/value pair that should be serialized,
            or undefined if nothing should be serialized. The toJSON method
            will be passed the key associated with the value, and this will be
            bound to the value

            For example, this would serialize Dates as ISO strings.

                Date.prototype.toJSON = function (key) {
                    function f(n) {
                        // Format integers to have at least two digits.
                        return n < 10 ? '0' + n : n;
                    }

                    return this.getUTCFullYear()   + '-' +
                         f(this.getUTCMonth() + 1) + '-' +
                         f(this.getUTCDate())      + 'T' +
                         f(this.getUTCHours())     + ':' +
                         f(this.getUTCMinutes())   + ':' +
                         f(this.getUTCSeconds())   + 'Z';
                };

            You can provide an optional replacer method. It will be passed the
            key and value of each member, with this bound to the containing
            object. The value that is returned from your method will be
            serialized. If your method returns undefined, then the member will
            be excluded from the serialization.

            If the replacer parameter is an array of strings, then it will be
            used to select the members to be serialized. It filters the results
            such that only members with keys listed in the replacer array are
            stringified.

            Values that do not have JSON representations, such as undefined or
            functions, will not be serialized. Such values in objects will be
            dropped; in arrays they will be replaced with null. You can use
            a replacer function to replace those with JSON values.
            JSON.stringify(undefined) returns undefined.

            The optional space parameter produces a stringification of the
            value that is filled with line breaks and indentation to make it
            easier to read.

            If the space parameter is a non-empty string, then that string will
            be used for indentation. If the space parameter is a number, then
            the indentation will be that many spaces.

            Example:

            text = JSON.stringify(['e', {pluribus: 'unum'}]);
            // text is '["e",{"pluribus":"unum"}]'


            text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
            // text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'

            text = JSON.stringify([new Date()], function (key, value) {
                return this[key] instanceof Date ?
                    'Date(' + this[key] + ')' : value;
            });
            // text is '["Date(---current time---)"]'


        JSON.parse(text, reviver)
            This method parses a JSON text to produce an object or array.
            It can throw a SyntaxError exception.

            The optional reviver parameter is a function that can filter and
            transform the results. It receives each of the keys and values,
            and its return value is used instead of the original value.
            If it returns what it received, then the structure is not modified.
            If it returns undefined then the member is deleted.

            Example:

            // Parse the text. Values that look like ISO date strings will
            // be converted to Date objects.

            myData = JSON.parse(text, function (key, value) {
                var a;
                if (typeof value === 'string') {
                    a =
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
                    if (a) {
                        return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
                            +a[5], +a[6]));
                    }
                }
                return value;
            });

            myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
                var d;
                if (typeof value === 'string' &&
                        value.slice(0, 5) === 'Date(' &&
                        value.slice(-1) === ')') {
                    d = new Date(value.slice(5, -1));
                    if (d) {
                        return d;
                    }
                }
                return value;
            });


    This is a reference implementation. You are free to copy, modify, or
    redistribute.
*/

/*jslint evil: true, strict: false */

/*members "", "\b", "\t", "\n", "\f", "\r", "\"", JSON, "\\", apply,
    call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
    getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
    lastIndex, length, parse, prototype, push, replace, slice, stringify,
    test, toJSON, toString, valueOf
*/


// Create a JSON object only if one does not already exist. We create the
// methods in a closure to avoid creating global variables.

if (!this.JSON) {
    this.JSON = {};
}

(function () {

    function f(n) {
        // Format integers to have at least two digits.
        return n < 10 ? '0' + n : n;
    }

    if (typeof Date.prototype.toJSON !== 'function') {

        Date.prototype.toJSON = function (key) {

            return isFinite(this.valueOf()) ?
                   this.getUTCFullYear()   + '-' +
                 f(this.getUTCMonth() + 1) + '-' +
                 f(this.getUTCDate())      + 'T' +
                 f(this.getUTCHours())     + ':' +
                 f(this.getUTCMinutes())   + ':' +
                 f(this.getUTCSeconds())   + 'Z' : null;
        };

        String.prototype.toJSON =
        Number.prototype.toJSON =
        Boolean.prototype.toJSON = function (key) {
            return this.valueOf();
        };
    }

    var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
        escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
        gap,
        indent,
        meta = {    // table of character substitutions
            '\b': '\\b',
            '\t': '\\t',
            '\n': '\\n',
            '\f': '\\f',
            '\r': '\\r',
            '"' : '\\"',
            '\\': '\\\\'
        },
        rep;


    function quote(string) {

// If the string contains no control characters, no quote characters, and no
// backslash characters, then we can safely slap some quotes around it.
// Otherwise we must also replace the offending characters with safe escape
// sequences.

        escapable.lastIndex = 0;
        return escapable.test(string) ?
            '"' + string.replace(escapable, function (a) {
                var c = meta[a];
                return typeof c === 'string' ? c :
                    '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
            }) + '"' :
            '"' + string + '"';
    }


    function str(key, holder) {

// Produce a string from holder[key].

        var i,          // The loop counter.
            k,          // The member key.
            v,          // The member value.
            length,
            mind = gap,
            partial,
            value = holder[key];

// If the value has a toJSON method, call it to obtain a replacement value.

        if (value && typeof value === 'object' &&
                typeof value.toJSON === 'function') {
            value = value.toJSON(key);
        }

// If we were called with a replacer function, then call the replacer to
// obtain a replacement value.

        if (typeof rep === 'function') {
            value = rep.call(holder, key, value);
        }

// What happens next depends on the value's type.

        switch (typeof value) {
        case 'string':
            return quote(value);

        case 'number':

// JSON numbers must be finite. Encode non-finite numbers as null.

            return isFinite(value) ? String(value) : 'null';

        case 'boolean':
        case 'null':

// If the value is a boolean or null, convert it to a string. Note:
// typeof null does not produce 'null'. The case is included here in
// the remote chance that this gets fixed someday.

            return String(value);

// If the type is 'object', we might be dealing with an object or an array or
// null.

        case 'object':

// Due to a specification blunder in ECMAScript, typeof null is 'object',
// so watch out for that case.

            if (!value) {
                return 'null';
            }

// Make an array to hold the partial results of stringifying this object value.

            gap += indent;
            partial = [];

// Is the value an array?

            if (Object.prototype.toString.apply(value) === '[object Array]') {

// The value is an array. Stringify every element. Use null as a placeholder
// for non-JSON values.

                length = value.length;
                for (i = 0; i < length; i += 1) {
                    partial[i] = str(i, value) || 'null';
                }

// Join all of the elements together, separated with commas, and wrap them in
// brackets.

                v = partial.length === 0 ? '[]' :
                    gap ? '[\n' + gap +
                            partial.join(',\n' + gap) + '\n' +
                                mind + ']' :
                          '[' + partial.join(',') + ']';
                gap = mind;
                return v;
            }

// If the replacer is an array, use it to select the members to be stringified.

            if (rep && typeof rep === 'object') {
                length = rep.length;
                for (i = 0; i < length; i += 1) {
                    k = rep[i];
                    if (typeof k === 'string') {
                        v = str(k, value);
                        if (v) {
                            partial.push(quote(k) + (gap ? ': ' : ':') + v);
                        }
                    }
                }
            } else {

// Otherwise, iterate through all of the keys in the object.

                for (k in value) {
                    if (Object.hasOwnProperty.call(value, k)) {
                        v = str(k, value);
                        if (v) {
                            partial.push(quote(k) + (gap ? ': ' : ':') + v);
                        }
                    }
                }
            }

// Join all of the member texts together, separated with commas,
// and wrap them in braces.

            v = partial.length === 0 ? '{}' :
                gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' +
                        mind + '}' : '{' + partial.join(',') + '}';
            gap = mind;
            return v;
        }
    }

// If the JSON object does not yet have a stringify method, give it one.

    if (typeof JSON.stringify !== 'function') {
        JSON.stringify = function (value, replacer, space) {

// The stringify method takes a value and an optional replacer, and an optional
// space parameter, and returns a JSON text. The replacer can be a function
// that can replace values, or an array of strings that will select the keys.
// A default replacer method can be provided. Use of the space parameter can
// produce text that is more easily readable.

            var i;
            gap = '';
            indent = '';

// If the space parameter is a number, make an indent string containing that
// many spaces.

            if (typeof space === 'number') {
                for (i = 0; i < space; i += 1) {
                    indent += ' ';
                }

// If the space parameter is a string, it will be used as the indent string.

            } else if (typeof space === 'string') {
                indent = space;
            }

// If there is a replacer, it must be a function or an array.
// Otherwise, throw an error.

            rep = replacer;
            if (replacer && typeof replacer !== 'function' &&
                    (typeof replacer !== 'object' ||
                     typeof replacer.length !== 'number')) {
                throw new Error('JSON.stringify');
            }

// Make a fake root object containing our value under the key of ''.
// Return the result of stringifying the value.

            return str('', {'': value});
        };
    }


// If the JSON object does not yet have a parse method, give it one.

    if (typeof JSON.parse !== 'function') {
        JSON.parse = function (text, reviver) {

// The parse method takes a text and an optional reviver function, and returns
// a JavaScript value if the text is a valid JSON text.

            var j;

            function walk(holder, key) {

// The walk method is used to recursively walk the resulting structure so
// that modifications can be made.

                var k, v, value = holder[key];
                if (value && typeof value === 'object') {
                    for (k in value) {
                        if (Object.hasOwnProperty.call(value, k)) {
                            v = walk(value, k);
                            if (v !== undefined) {
                                value[k] = v;
                            } else {
                                delete value[k];
                            }
                        }
                    }
                }
                return reviver.call(holder, key, value);
            }


// Parsing happens in four stages. In the first stage, we replace certain
// Unicode characters with escape sequences. JavaScript handles many characters
// incorrectly, either silently deleting them, or treating them as line endings.

            text = String(text);
            cx.lastIndex = 0;
            if (cx.test(text)) {
                text = text.replace(cx, function (a) {
                    return '\\u' +
                        ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
                });
            }

// In the second stage, we run the text against regular expressions that look
// for non-JSON patterns. We are especially concerned with '()' and 'new'
// because they can cause invocation, and '=' because it can cause mutation.
// But just to be safe, we want to reject all unexpected forms.

// We split the second stage into 4 regexp operations in order to work around
// crippling inefficiencies in IE's and Safari's regexp engines. First we
// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
// replace all simple value tokens with ']' characters. Third, we delete all
// open brackets that follow a colon or comma or that begin the text. Finally,
// we look to see that the remaining characters are only whitespace or ']' or
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.

            if (/^[\],:{}\s]*$/.
test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').
replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').
replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {

// In the third stage we use the eval function to compile the text into a
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
// in JavaScript: it can begin a block or an object literal. We wrap the text
// in parens to eliminate the ambiguity.

                j = eval('(' + text + ')');

// In the optional fourth stage, we recursively walk the new structure, passing
// each name/value pair to a reviver function for possible transformation.

                return typeof reviver === 'function' ?
                    walk({'': j}, '') : j;
            }

// If the text is not JSON parseable, then a SyntaxError is thrown.

            throw new SyntaxError('JSON.parse');
        };
    }
}());
﻿
if (typeof (Swao.utils) == 'undefined')
    Swao.utils = new Object();
if (typeof (Swao.utils.AjaxREST) == 'undefined')
    Swao.utils.AjaxREST = new Object();
//Swao.register('Swao.utils.AjaxREST');

Swao.utils.AjaxREST = {
    ajax_json_get: function (ajaxurl, jsonObj, timeoutMS, async, successFn, errorFn, beforeSendFn) {
        ///	<summary>
        ///	get方法获取数据
        ///	</summary>
        ///	<param name="ajaxurl" type="String">提交地址</param>
        ///	<param name="jsonObj" type="obj">json obj</param>
        ///	<param name="timeoutMS" type="int">有效时间</param>
        ///	<param name="async" type="bool">true－>异步,false->同步</param>
        ///	<param name="successFn" type="fn">成功后返回的方法</param>
        ///	<param name="errorFn" type="fn">错误后返回的方法</param>
        ///	<param name="beforeSendFn" type="fn">等待的时候返回的方法</param>

        $.ajax({
            url: ajaxurl,
            type: 'GET',
            data: ((jsonObj != null) ? JSON.stringify(jsonObj) : null),
            dataType: 'json',
            contentType: "application/json; charset=utf-8",
            timeout: timeoutMS,
            async: async,
            beforeSend: function () {
                if (beforeSendFn) beforeSendFn();
            },
            error: function () {
                if (errorFn) errorFn();
            },
            success: function (data) {
                if (successFn) successFn(data);
            }
        });

    },

    ajax_json_post: function (ajaxurl, jsonText, timeoutMS, async, successFn, errorFn, beforeSendFn) {
        ///	<summary>
        ///	post方法提交数据
        ///	</summary>
        ///	<param name="ajaxurl" type="String">提交地址</param>
        ///	<param name="jsonText" type="string">json string</param>
        ///	<param name="timeoutMS" type="int">有效时间</param>
        ///	<param name="async" type="bool">true－>异步,false->同步</param>
        ///	<param name="successFn" type="fn">成功后返回的方法</param>
        ///	<param name="errorFn" type="fn">错误后返回的方法</param>
        ///	<param name="beforeSendFn" type="fn">等待的时候返回的方法</param>

        $.ajax({
            url: ajaxurl,
            type: 'POST',
            data: jsonText,
            dataType: 'json',
            contentType: "application/json; charset=utf-8",
            timeout: timeoutMS,
            async: async,
            beforeSend: function () {
                if (beforeSendFn) beforeSendFn();
            },
            error: function () {
                if (errorFn) errorFn();
            },
            success: function (data) {
                if (successFn) successFn(data);
            }
        });
    },

    ajax_json_put: function (ajaxurl, jsonText, timeoutMS, async, successFn, errorFn, beforeSendFn) {
        ///	<summary>
        ///	put方法修改数据
        ///	</summary>
        ///	<param name="ajaxurl" type="String">提交地址</param>
        ///	<param name="jsonText" type="string">json string</param>
        ///	<param name="timeoutMS" type="int">有效时间</param>
        ///	<param name="async" type="bool">true－>异步,false->同步</param>
        ///	<param name="successFn" type="fn">成功后返回的方法</param>
        ///	<param name="errorFn" type="fn">错误后返回的方法</param>
        ///	<param name="beforeSendFn" type="fn">等待的时候返回的方法</param>

        $.ajax({
            url: ajaxurl,
            type: 'PUT',
            data: jsonText,
            dataType: 'json',
            contentType: "application/json; charset=utf-8",
            timeout: timeoutMS,
            async: async,
            beforeSend: function () {
                if (beforeSendFn) beforeSendFn();
            },
            error: function () {
                if (errorFn) errorFn();
            },
            success: function (data) {
                if (successFn) successFn(data);
            }
        });
    },

    ajax_json_delete: function (ajaxurl, jsonText, timeoutMS, async, successFn, errorFn, beforeSendFn) {
        ///	<summary>
        ///	delete方法删除数据
        ///	</summary>
        ///	<param name="ajaxurl" type="String">提交地址</param>
        ///	<param name="jsonText" type="string">json string</param>
        ///	<param name="timeoutMS" type="int">有效时间</param>
        ///	<param name="async" type="bool">true－>异步,false->同步</param>
        ///	<param name="successFn" type="fn">成功后返回的方法</param>
        ///	<param name="errorFn" type="fn">错误后返回的方法</param>
        ///	<param name="beforeSendFn" type="fn">等待的时候返回的方法</param>

        $.ajax({
            url: ajaxurl,
            type: 'DELETE',
            data: jsonText,
            dataType: 'json',
            contentType: "application/json; charset=utf-8",
            timeout: timeoutMS,
            async: async,
            beforeSend: function () {
                if (beforeSendFn) beforeSendFn();
            },
            error: function () {
                if (errorFn) errorFn();
            },
            success: function (data) {
                if (successFn) successFn(data);
            }
        });
    },

    ajax_jsonp_get: function (ajaxurl, jsonObj, successFn) {
        ///	<summary>
        ///	跨域get方法获取数据
        ///	</summary>
        ///	<param name="ajaxurl" type="String">提交地址</param>
        ///	<param name="jsonObj" type="obj">json obj</param>
        ///	<param name="successFn" type="fn">成功后返回的方法</param>

        $.getJSON(ajaxurl + '?jsoncallback=?', ((jsonObj != null) ? JSON.stringify(jsonObj) : null), function (data) {
            if (successFn) successFn(data);
        });
    }

};

Swao.utils.AjaxREST.version = "2.0";

﻿
if (typeof (Swao.utils) == 'undefined')
    Swao.utils = new Object();
if (typeof (Swao.utils.Array) == 'undefined')
    Swao.utils.Array = new Object();
//Swao.register('Swao.utils.Array');

Swao.utils.Array = {
    ///	<summary>
    ///	需要JQuery支持
    ///	</summary>

    inArray: function (elem, array) {
        if (array.indexOf) {
            return array.indexOf(elem);
        }

        for (var i = 0, length = array.length; i < length; i++) {
            if (array[i] === elem) {
                return i;
            }
        }

        return -1;
    },

    toArray: function (array) {
        return array.toArray();
    },

    arrayIds: function (array) {
        return array.map(function () { return this.id; }).get().join(",");
    }
};

Array.prototype.remove = function (index) {
    ///	<summary>
    ///	等于函数，ClientRecord使用
    ///	</summary>
    ///	<param name="index" type="int">第几项，从0开始算起</param>
    ///	<returns type="boolean"></returns>

    if (index < 0)
        return this;
    else
        return this.slice(0, index).concat(this.slice(index + 1, this.length));
};

﻿
if (typeof (Swao.utils) == 'undefined')
    Swao.utils = new Object();
if (typeof (Swao.utils.Browser) == 'undefined')
    Swao.utils.Browser = new Object();
//Swao.register('Swao.utils.Browser');

Swao.utils.Browser = {
    getBrowserHeight: function () {
        ///	<summary>
        ///	获取浏览器可视区域的高度
        ///	</summary>

        if ($.browser.msie) {
            return document.compatMode == "CSS1Compat" ? document.documentElement.scrollHeight :
                  document.body.scrollHeight;
        } else {
            return document.body.scrollHeight;
        }
    },

    pageHeight: function () {
        ///	<summary>
        ///	获取浏览器页面的整体高度
        ///	</summary>

        if ($.browser.msie) {
            return document.compatMode == "CSS1Compat" ? document.documentElement.clientHeight :
        document.body.clientHeight;
        } else {
            return self.innerHeight;
        }
    },

    pageWidth: function () {
        ///	<summary>
        ///	获取浏览器页面的宽度
        ///	</summary>

        if ($.browser.msie) {
            return document.compatMode == "CSS1Compat" ? document.documentElement.clientWidth :
        document.body.clientWidth;
        } else {
            return self.innerWidth;
        }
    },

    browserType: function () {
        ///	<summary>
        ///	获取浏览器的类型
        ///	</summary>
        ///	<returns type="string">浏览器</returns>

        if (navigator.userAgent.indexOf("MSIE") > 0) {
            return "MSIE";
        }
        if (isFirefox = navigator.userAgent.indexOf("Firefox") > 0) {
            return "Firefox";
        }
        if (isSafari = navigator.userAgent.indexOf("Safari") > 0) {
            return "Safari";
        }
        if (isCamino = navigator.userAgent.indexOf("Camino") > 0) {
            return "Camino";
        }
        if (isMozilla = navigator.userAgent.indexOf("Gecko/") > 0) {
            return "Gecko";
        }
    }
};

﻿
if (typeof (Swao.utils) == 'undefined')
    Swao.utils = new Object();
if (typeof (Swao.utils.Cookie) == 'undefined')
    Swao.utils.Cookie = new Object();
//Swao.register('Swao.utils.Cookie');

Swao.utils.Cookie = {
    set: function (name, value, days) {
        if (days) days = days * 1000 * 60 * 60 * 24;
        var c = name + '=' + encodeURIComponent(value);
        if (days) c += ';expires=' + new Date(new Date().getTime() + days).toGMTString();
        document.cookie = c;
    },

    setDomain: function (domain, name, value, days) {
        if (days) days = days * 1000 * 60 * 60 * 24;
        var c = name + '=' + encodeURIComponent(value);
        if (days) c += ';expires=' + new Date(new Date().getTime() + days).toGMTString();
        c += ';domain=' + domain;
        document.cookie = c;
    },

    get: function (name) {
        var start = document.cookie.indexOf(name + "=");
        if (start == -1) return null;
        start += name.length + 1;
        var end = document.cookie.indexOf(';', start);
        if (end == -1) end = document.cookie.length;
        return decodeURIComponent(document.cookie.substring(start, end));
    },

    remove: function (name) {
        document.cookie = name + '=;expires=Thu, 01-Jan-70 00:00:01 GMT;';
    }
};

﻿
if (typeof (Swao.utils) == 'undefined')
    Swao.utils = new Object();
if (typeof (Swao.utils.DataUtility) == 'undefined')
    Swao.utils.DataUtility = new Object();
//Swao.register('Swao.utils.DataUtility');

Swao.utils.DataUtility = {
    search: function (keyword, joList, searchField) {
        ///	<summary>
        ///	关键字和json列表数据包的特定字段经行模糊匹配
        ///	</summary>
        ///	<param name="keyword" type="String">关键字</param>
        ///	<param name="joList" type="obj">json list</param>
        ///	<param name="searchField" type="string[]">需要匹配的字段</param>
        ///	<returns type="obj">返回所有模糊或者完全匹配的json数据包</returns>

        if (keyword.length == 0) {
            return joList;
        }
        var aList = [];
        for (var i = 0; i < joList.length; i++) {
            if (this.isMatch(keyword, joList[i], searchField))
                aList.push(joList[i]);
        }
        if (aList.length > 0) {
            return aList;
        } else {
            return [];
        }
    },


    isMatch: function (keyword, jo, searchField) {
        ///	<summary>
        ///	关键字和json单个数据包的特定字段经行模糊匹配
        ///	</summary>
        ///	<param name="keyword" type="String">关键字</param>
        ///	<param name="jo" type="obj">json</param>
        ///	<param name="searchField" type="string[]">需要匹配的字段</param>
        ///	<returns type="bool">true/false</returns>

        if (keyword.length == 0) {
            return false;
        }

        var keyword = keyword.toLowerCase().split("");
        var lastIndex = -1;
        for (var i = 0; i < searchField.length; i++) {

            var aInfo = eval('jo.' + searchField[i]);
            var flg = true;
            for (var m = 0; m < keyword.length; m++) {
                var newIndex = aInfo.indexOf(keyword[m]);
                if (newIndex > lastIndex) {
                    aInfo = Swao.utils.String.replaceChar(aInfo, newIndex, "-");
                    lastIndex = newIndex;
                } else {
                    flg = false;
                }
            }

            if (flg == true) {
                return true;
            }
        }
        return false;
    }
};﻿
if (typeof (Swao.utils) == 'undefined')
    Swao.utils = new Object();
if (typeof (Swao.utils.DateTime) == 'undefined')
    Swao.utils.DateTime = new Object();
//Swao.register('Swao.utils.DateTime');

Swao.utils.DateTime = {
    isLeapYear: function (dt) {
        ///	<summary>
        ///	闰年判断
        ///	</summary>
        ///	<param name="dt" type="Date"></param>
        ///	<returns type="boolean">true:闰年,False:非闰年</returns>

        if (!dt) return null;

        return (0 == dt.getYear() % 4 && ((dt.getYear() % 100 != 0) || (dt.getYear() % 400 == 0)));
    },

    convertStandardDate2LocalTime: function (dts) {
        ///	<summary>
        ///	标准格式日期字符串("yyyyMMdd")转换成时间对象
        ///	</summary>
        ///	<param name="dts" type="string">日期字符串</param>
        ///	<returns type="Date"></returns>

        if (!dts || typeof dts !== "string" || dts.length != 8) return null;

        return convertStandardDateTime2LocalTime(dts + "000000", false);
    },

    convertStandardDateTime2LocalTime: function (dts, isUtc) {
        ///	<summary>
        ///	标准格式时间字符串("yyyyMMddHHmmss")转换成时间对象
        ///	</summary>
        ///	<param name="dts" type="string">时间字符串</param>
        /// <param name="isUtc" type="boolean">dts是否是UTC时间</param>
        ///	<returns type="Date"></returns>

        if (!dts || typeof dts !== "string" || dts.length != 14) return null;

        var dt = new Date();
        if (isUtc) dt.setTime(Date.UTC(dts.substr(0, 4), dts.substr(4, 2) - 1, dts.substr(6, 2), dts.substr(8, 2), dts.substr(10, 2), dts.substr(12, 2)));
        else {
            dt.setFullYear(dts.substr(0, 4));
            dt.setMonth(dts.substr(4, 2) - 1);
            dt.setDate(dts.substr(6, 2));
            dt.setHours(dts.substr(8, 2));
            dt.setMinutes(dts.substr(10, 2));
            dt.setSeconds(dts.substr(12, 2));
        }
        return dt;
    },

    getShortTimeString2: function (time, isUtc) {
        return Swao.utils.DateTime.getShortTimeString(Swao.utils.DateTime.convertStandardDateTime2LocalTime(time, isUtc));
    },

    getShortTimeString: function (time) {
        ///	<summary>
        ///	
        ///	</summary>
        ///	<param name="time" type="Date">时间</param>
        ///	<returns type="String">昨天 14:21    10天前 14:21</returns>

        var now = new Date();
        var ms = (now).getTime() - time.getTime();
        if (ms <= 0) return '';

        var difference = Date.UTC(now.getYear(), now.getMonth(), now.getDate(), 0, 0, 0) - Date.UTC(time.getYear(), time.getMonth(), time.getDate(), 0, 0, 0);

        days = difference / 86400000;
        if (days == 0) timeTip = "今天";
        else if (days == 1) timeTip = "昨天";
        else if (days == 2) timeTip = "前天";
        else timeTip = days + "天前";

        timeTip += " " + Swao.utils.DateTime.PadTime(time.getHours()) + ":" + Swao.utils.DateTime.PadTime(time.getMinutes());

        return timeTip;
    },

    getTimeString: function (time) {
        ///	<summary>
        ///	
        ///	</summary>
        ///	<param name="time" type="Date">时间</param>
        ///	<returns type="String">昨天 14:21:21    10天前 14:21:31</returns>

        var str = Swao.utils.DateTime.getShortTimeString(time);
        if (time == '') return '';
        else return (str + Swao.utils.DateTime.PadTime(time.getSeconds()));
    },

    getAgeString: function (time) {
        ///	<summary>
        ///	岁数
        ///	</summary>
        ///	<param name="time" type="Date">时间</param>
        ///	<returns type="String">1岁11月</returns>

        var now = new Date();
        var ms = now.getTime() - time.getTime();
        if (ms <= 0) return '';

        year = now.getFullYear() - time.getFullYear();
        month = now.getMonth() - time.getMonth();
        if (month < 0) {
            year = year - 1;
            month = month + 12;
        }

        if (year > 0) {
            ageTip = year + "岁";
        }
        if (month > 0) {
            ageTip = month + "月";
        }

        return ageTip;
    },

    getFullTimeSpanString: function (endTime, beginTime) {
        ///	<summary>
        ///	获取差额时间的提示字符串
        ///	</summary>
        ///	<param name="endTime" type="Date">结束时间</param>
        ///	<param name="beginTime" type="Date">开始时间</param>
        ///	<returns type="String">(endTime-beginTime)的差额时间</returns>

        if (!endTime || !beginTime) return null;

        var ms = endTime.getTime() - beginTime.getTime();
        if (ms <= 0) return '';

        hours = ms / 3600000;
        if (hours > 0) {
            timeTip = Math.floor(hours) + "小时";
            ms = ms % (1000 * 60 * 60);
            if (timeTip > 0) {
                return timeTip + "小时前"
            };
        }
        minutes = ms / 60000;
        if (minutes > 0) {
            timeTip += Math.floor(minutes) + "分";
            ms = ms % (1000 * 60);
        }
        seconds = ms / 1000;
        if (seconds > 0) {
            timeTip += Math.floor(seconds) + "秒";
        }
        timeTip += "前";
        return timeTip;
    },

    getTimeSpanString: function (endTime, beginTime) {
        ///	<summary>
        ///	获取差额时间大概的提示字符串
        ///	</summary>
        ///	<param name="endTime" type="Date">结束时间</param>
        ///	<param name="beginTime" type="Date">开始时间</param>
        ///	<returns type="String">(endTime-beginTime)的差额时间</returns>

        if (!endTime || !beginTime) return null;

        var ms = endTime.getTime() - beginTime.getTime();
        if (ms <= 0) return '';

        hours = ms / 3600000;
        if (hours > 0) {
            timeTip = Math.floor(hours);
            ms = ms % (1000 * 60 * 60);
            if (timeTip > 0) {
                return timeTip + "小时前"
            };
        }
        minutes = ms / 60000;
        if (minutes > 0) {
            timeTip += Math.floor(minutes);
            ms = ms % (1000 * 60);
            if (timeTip > 0) {
                return timeTip + "分钟前"
            };
        }
        seconds = ms / 1000;
        if (seconds > 0) {
            timeTip += Math.floor(seconds);
            return timeTip + "秒前";
        }
    },

    PadTime: function (i) {
        ///	<summary>
        ///	内部函数，补足两位
        ///	</summary>
        ///	<param name="i" type="String">时间整数</param>
        ///	<returns type="String"></returns>
        if (i < 10) {
            i = "0" + i
        }
        return i
    },

    getDaysInMonth: function (year, month) {
        ///	<summary>
        ///	某年某月有多少天
        ///	</summary>
        ///	<param name="year" type="int">年</param>
        ///	<param name="month" type="int">月</param>
        ///	<returns type="int">天数</returns>

        month = parseInt(month, 10) + 1;
        var temp = new Date(year + "/" + month + "/0");
        return temp.getDate();
    }
};


﻿
if (typeof (Swao.utils) == 'undefined')
    Swao.utils = new Object();
if (typeof (Swao.utils.Diagnostics) == 'undefined')
    Swao.utils.Diagnostics = new Object();
//Swao.register('Swao.utils.Diagnostics');

Swao.utils.Diagnostics = {
};

﻿
if (typeof (Swao.utils) == 'undefined')
    Swao.utils = new Object();
if (typeof (Swao.utils.DivMove) == 'undefined')
    Swao.utils.DivMove = new Object();
//Swao.register('Swao.utils.DivMove');

Swao.utils.DivMove = {
    movePopDiv: function (divName, moveDiv) {
        ///	<summary>
        ///	层的移动
        ///	</summary>
        ///	<param name="divName" type="String">需要移动的层</param>
        ///	<param name="moveDiv" type="int">按住哪个地方拖动</param>

        $("#" + divName + "").Drags({ // move window
            zIndex: 200,
            handle: '#' + moveDiv + '',
            callback: {
                onMove: function (e) {
                    //$('#droptracer').html('Div Position:(Left:' + e.pageX + ' ,Top:' + e.pageY + ')');
                },
                onDrop: function () {
                    //$('#droptracer').html('Div has been dopped');
                }
            }
        });
    },

    centerPopup: function (divName) {
        ///	<summary>
        ///	层居中
        ///	</summary>
        ///	<param name="divName" type="String">需要居中的层</param>

        //获取系统变量 
        var windowWidth = Swao.utils.Browser.pageWidth();
        var popupWidth = $("#" + divName + "").width();
        //居中设置     
        $("#" + divName + "").css({ "position": "absolute", "left": windowWidth / 2 - popupWidth / 2 });
        //高度订位
        var menuYloc = $("#" + divName + "").offset().top;
        var offsetTop = menuYloc + $(window).scrollTop() + "px";
        $("#" + divName + "").animate({ top: offsetTop }, { duration: 0, queue: false });
    },

    controlDlideDownOrUp: function (areaId, controlId, speed, controlContent_Down, controlContent_Up) {
        ///	<summary>
        ///	上下展开和隐藏动画效果
        ///	</summary>
        ///	<param name="areaId" type="String">展开收起控件的id</param>
        ///	<param name="controlId" type="String">控制的展开收起控件的id</param>
        ///	<param name="speed" type="String">速度</param>
        ///	<param name="controlContent_Down" type="String">控件展开的时候控制控件所显示的内容</param>
        ///	<param name="controlContent_Up" type="String">控件隐藏的时候控制控件所显示的内容</param>

        if ($("#" + areaId).css("display") == "none") {
            $("#" + areaId).slideDown(speed, function () {
                $("#" + controlId).html(controlContent_Down);
            });
        }
        else {
            $("#" + areaId).slideUp(speed, function () {
                $("#" + controlId).html(controlContent_Up);
            });
        }
    },

    layoutFn: function (from, to, LeftStr, TopStr) {
        var left, top;
        var OffsetStr = from.offset();
        left = OffsetStr.left;
        top = OffsetStr.top;

        to.css({
            left: left + LeftStr + "px",
            top: top + TopStr + "px"
        });
    }
};
﻿
if (typeof (Swao.utils) == 'undefined')
    Swao.utils = new Object();
if (typeof (Swao.utils.Random) == 'undefined')
    Swao.utils.Random = new Object();
//Swao.register('Swao.utils.Encoding');

Swao.utils.Encoding = {
    utf8Encode: function (string) {
        string = string.replace(/\r\n/g, "\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if ((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    }
};
﻿
if (typeof (Swao.utils) == 'undefined')
    Swao.utils = new Object();
if (typeof (Swao.utils.Random) == 'undefined')
    Swao.utils.Random = new Object();
//Swao.register('Swao.utils.Event');

Swao.utils.Event = {
    dispatchEvent: function (element, eventName, handler) {
        ///	<summary>
        ///	dispatch event
        ///	</summary>
        ///	<param name="element" type="object">对象</param>
        ///	<param name="eventName" type="String">事件名称，比如mousedown</param>
        ///	<param name="handler" type="function">处理函数</param>

        if (element.attachEvent) {
            element.attachEvent('on' + eventName, function (e) {
                handler.call(element, e);
            });
        } else if (element.addEventListener) {
            element.addEventListener(eventName, handler, false);
        } else {
            element['on' + eventName] = function (e) {
                handler.call(element, e);
            };
        }
    },

    getTarget: function (e) {
        ///	<summary>
        ///	resolve target of event
        ///	</summary>
        ///	<param name="e" type="event">事件</param>
        ///	<returns type="object">事件对象</returns>

        var node = e.target || e.srcElement;
        try {
            if (node && node.nodeType === 3) {
                return node.parentNode;
            }
        } catch (ex) { }
        return node;
    }
};
﻿
if (typeof (Swao.utils) == 'undefined')
    Swao.utils = new Object();
if (typeof (Swao.utils.FormatCheck) == 'undefined')
    Swao.utils.FormatCheck = new Object();
//Swao.register('Swao.utils.FormatCheck');

Swao.utils.FormatCheck = {

    isDate: function (str) {
        ///	<summary>
        ///	判断时期格式
        ///	</summary>
        ///	<param name="str" type="String">输入字符串（如：2010-01-01)</param>
        ///	<returns type="bool">是/否</returns>

        var the1st = str.indexOf('-');
        var the2nd = str.lastIndexOf('-');

        if (the1st == the2nd) {
            return (false);
        }
        else {
            var y = str.substring(0, the1st);
            var m = str.substring(the1st + 1, the2nd);
            var d = str.substring(the2nd + 1, str.length);
            var maxDays = 31;

            if (isNum(m) == false || isNum(d) == false || isNum(y) == false) {
                return (false);
            }
            else if (y.length < 4) {
                return (false);
            }
            else if ((m < 1) || (m > 12)) {
                return (false);
            }
            else if (m == 4 || m == 6 || m == 9 || m == 11) {
                maxDays = 30;
            }
            else if (m == 2) {
                if (y % 4 > 0) {
                    maxDays = 28;
                }
                else if (y % 100 == 0 && y % 400 > 0) {
                    maxDays = 28;
                }
                else {
                    maxDays = 29;
                }
            }
            if ((d < 1) || (d > maxDays)) {
                return (false);
            }
            else {
                return (true);
            }
        }
    },

    isInt: function (str, type) {
        ///	<summary>
        ///	判断是否为整数
        ///	</summary>
        ///	<param name="str" type="String">输入字符串</param>
        ///	<param name="str" type="String">类型（0+＝非负整数，+＝正整数，-0＝非正整数，-＝负整数，空＝整数值）</param>
        ///	<returns type="bool">是/否</returns>

        if (type == "0+") {
            return /^\\d+$/.test(str);
        } else if (type == "+") {
            return /^\\d*[1-9]\\d*$/.test(str);
        } else if (type == "-0") {
            return /^((-\\d+)|(0+))$/.test(str);
        } else if (type == "-") {
            return /^-\\d*[1-9]\\d*$/.test(str);
        } else {
            return /^-?\\d+$/.test(str);
        }
    },

    isFloat: function (str, type) {
        ///	<summary>
        ///	判断是否为浮点数字
        ///	</summary>
        ///	<param name="str" type="String">输入字符串</param>
        ///	<param name="str" type="String">类型（0+＝非负浮点数，+＝正浮点数，-0＝非正浮点数，-＝负浮点数，空＝浮点数值）</param>
        ///	<returns type="bool">是/否</returns>

        if (type == "0+") {
            return /^\\d+(\.\\d+)?$/.test(str);
        } else if (type == "+") {
            return /^((\\d+\\.\\d*[1-9]\\d*)|(\\d*[1-9]\\d*\\.\\d+)|(\\d*[1-9]\\d*))$/.test(str);
        } else if (type == "-0") {
            return /^((-\\d+(\.\\d+)?)|(0+(\\.0+)?))$/.test(str);
        } else if (type == "-") {
            return /^(-((\\d+\\.\\d*[1-9]\\d*)|(\\d*[1-9]\\d*\\.\\d+)|(\\d*[1-9]\\d*)))$/.test(str);
        } else {
            return /^(-?\\d+)(\\.\\d+)?$/.test(str);
        }
    },

    isUrl: function (str) {
        ///	<summary>
        ///	判断是否网址
        ///	</summary>
        ///	<param name="str" type="String">输入字符串</param>
        ///	<returns type="bool">是/否</returns>

        var pattern = /^(http:\/\/)?[a-zA-Z0-9-]+(\.[a-zA-z0-9-]+)+\/?$/gi;
        return pattern.test(str);
    },

    isMobile: function (str) {
        ///	<summary>
        ///	判断是手机
        ///	</summary>
        ///	<param name="str" type="String">输入字符串</param>
        ///	<returns type="bool">是/否</returns>

        var pattern = /^1[358]\d{9}$/;
        return pattern.test(str);
    },

    isPhone: function (str) {
        ///	<summary>
        ///	判断是电话
        ///	</summary>
        ///	<param name="str" type="String">输入字符串</param>
        ///	<returns type="bool">是/否</returns>

        var pattern = /^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){7,8})+$/;
        return pattern.test(str);
    },

    isZip: function (str) {
        ///	<summary>
        ///	判断是邮编
        ///	</summary>
        ///	<param name="str" type="String">输入字符串</param>
        ///	<returns type="bool">是/否</returns>

        var pattern = /^[a-zA-Z0-9 ]{3,12}$/;
        return pattern.test(str);
    },

    isMail: function (str) {
        ///	<summary>
        ///	判断是邮箱
        ///	</summary>
        ///	<param name="str" type="String">输入字符串</param>
        ///	<returns type="bool">是/否</returns>

        var pattern = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
        return pattern.test(str);
    },

    isQQ: function (str) {
        ///	<summary>
        ///	判断是QQ
        ///	</summary>
        ///	<param name="str" type="String">输入字符串</param>
        ///	<returns type="bool">是/否</returns>

        var pattern = /^[1-9]\d{5,8}$/;
        return pattern.test(str);
    },

    isChinese: function (str) {
        ///	<summary>
        ///	判断是中文
        ///	</summary>
        ///	<param name="str" type="String">输入字符串</param>
        ///	<returns type="bool">是/否</returns>

        if (str == null || typeof (str) == 'undefined' || str == '')
            return false;
        var pattern = /^([\u4E00-\u9FA5]|[\uFE30-\uFFA0])*$/gi;
        return pattern.test(str);
    },

    isNoChinese: function (str) {
        ///	<summary>
        ///	判断字符串中没有中文
        ///	</summary>
        ///	<param name="str" type="String">输入字符串</param>
        ///	<returns type="bool">是/否</returns>

        if (str == null || typeof (str) == 'undefined' || str == '')
            return false;
        var pattern = /[^A-Za-z0-9_]/g;
        if (pattern.test(str)) {
            return false;
        }
        else {
            return true;
        }
    },

    isAtn: function (str, n) {
        ///	<summary>
        ///	判断是否为固定的位数
        ///	</summary>
        ///	<param name="str" type="String">输入字符串</param>
        ///	<param name="n" type="int">数量</param>
        ///	<returns type="bool">是/否</returns>

        if (str.length != n) {
            return (false);
        }
        else {
            return (true);
        }
    },

    getStrLength: function (str) {
        ///	<summary>
        ///	获取字符串长度(中文2个字符)
        ///	</summary>
        ///	<param name="str" type="String">输入字符串</param>
        ///	<returns type="int">字符串长度(中文2个字符)</returns>

        var chineseRegex = /[^\x00-\xff]/g;
        var strLength = str.replace(chineseRegex, "**").length;
        return strLength;
    },

    isBetween: function (str, n, m) {
        ///	<summary>
        ///	判断是否为之间的位数
        ///	</summary>
        ///	<param name="str" type="String">输入字符串</param>
        ///	<param name="n" type="int">数量</param>
        ///	<param name="m" type="int">数量</param>
        ///	<returns type="bool">是/否</returns>

        var length =  this.getStrLength(str);
        if (length > m || length < n) {
            return (false);
        }
        else {
            return (true);
        }
    },

    isSame: function (str1, str2) {
        ///	<summary>
        ///	判断两个字符串是否一致
        ///	</summary>
        ///	<param name="str1" type="String">输入字符串</param>
        ///	<param name="str2" type="String">输入字符串</param>
        ///	<returns type="bool">是/否</returns>

        if (str1 == str2) {
            return (true);
        } else {
            return (false);
        }
    },

    isNoIllegalString: function (str) {
        ///	<summary>
        ///	不包含特殊字符
        ///	</summary>
        ///	<param name="str" type="String">输入字符串</param>
        ///	<returns type="bool">是/否</returns>

        var chars = "|+)(*&^%$#@~\\}{></";
        var c;
        var returnFlg = true;
        for (var i = 0; i < chars.length; ++i) {
            c = (chars.substring(i, i + 1));
            if (str.indexOf(c) != -1) {
                returnFlg = false;
                break;
            }
        }
        return returnFlg;
    },

    checkNickname: function (str) {
        ///	<summary>
        ///	用户名检查
        ///	</summary>
        ///	<param name="str" type="String">输入字符串</param>
        ///	<returns type="bool">是/否</returns>

        var returnFlg = false;

        if (this.isNoIllegalString(str) && this.isBetween(str, 2, 14)) {
            returnFlg = true;
        }
        return returnFlg;
    }
};
﻿
if (typeof (Swao.utils) == 'undefined')
    Swao.utils = new Object();
if (typeof (Swao.utils.Random) == 'undefined')
    Swao.utils.Random = new Object();
//Swao.register('Swao.utils.Math');

Swao.utils.Math = {
    addUnsigned: function (lX, lY) {
        var lX4, lY4, lX8, lY8, lResult;
        lX8 = (lX & 0x80000000);
        lY8 = (lY & 0x80000000);
        lX4 = (lX & 0x40000000);
        lY4 = (lY & 0x40000000);
        lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF);
        if (lX4 & lY4) {
            return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
        }
        if (lX4 | lY4) {
            if (lResult & 0x40000000) {
                return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
            } else {
                return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
            }
        } else {
            return (lResult ^ lX8 ^ lY8);
        }
    },

    accAdd: function (arg1, arg2) {
        ///	<summary>
        ///	加法运算（支持浮点）
        ///	</summary>
        ///	<param name="arg1" type="float">参数1</param>
        ///	<param name="arg2" type="float">参数2</param>
        ///	<returns type="int">结果</returns>

        var r1, r2, m;
        try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 }
        try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 }
        m = Math.pow(10, Math.max(r1, r2))
        return (arg1 * m + arg2 * m) / m
    },

    Subtr: function (arg1, arg2) {
        ///	<summary>
        ///	减法运算（支持浮点）
        ///	</summary>
        ///	<param name="arg1" type="float">参数1</param>
        ///	<param name="arg2" type="float">参数2</param>
        ///	<returns type="int">结果</returns>

        var r1, r2, m, n;
        try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 }
        try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 }
        m = Math.pow(10, Math.max(r1, r2));
        //last modify by deeka
        //动态控制精度长度
        n = (r1 >= r2) ? r1 : r2;
        return ((arg1 * m - arg2 * m) / m).toFixed(n);
    },

    accDiv: function (arg1, arg2) {
        ///	<summary>
        ///	除法运算（支持浮点）
        ///	</summary>
        ///	<param name="arg1" type="float">参数1</param>
        ///	<param name="arg2" type="float">参数2</param>
        ///	<returns type="int">结果</returns>

        var t1 = 0, t2 = 0, r1, r2;
        try { t1 = arg1.toString().split(".")[1].length } catch (e) { }
        try { t2 = arg2.toString().split(".")[1].length } catch (e) { }
        with (Math) {
            r1 = Number(arg1.toString().replace(".", ""))
            r2 = Number(arg2.toString().replace(".", ""))
            return (r1 / r2) * pow(10, t2 - t1);
        }
    },

    accMul: function (arg1, arg2) {
        ///	<summary>
        ///	乘法运算（支持浮点）
        ///	</summary>
        ///	<param name="arg1" type="float">参数1</param>
        ///	<param name="arg2" type="float">参数2</param>
        ///	<returns type="int">结果</returns>

        var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
        try { m += s1.split(".")[1].length } catch (e) { }
        try { m += s2.split(".")[1].length } catch (e) { }
        return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
    }
};

﻿
if (typeof (Swao.utils) == 'undefined')
    Swao.utils = new Object();
if (typeof (Swao.utils.Page) == 'undefined')
    Swao.utils.Page = new Object();
//Swao.utils.register('Swao.utils.Page');

Swao.utils.Page = {
}

//通过object类为每个对象添加变量mapBuffer
Swao.utils.Page.mapBuffer = new Swao.base.Dictionary();

Swao.utils.Page.addMapBuffer = function (guid, obj) {
    ///	<summary>
    ///	添加映射缓存
    ///	</summary>
    ///	<param name="guid" type="string">guid</param>
    ///	<param name="obj" type="object">对象</param>

    Swao.utils.Page.mapBuffer.put(guid, obj);
};

//
Swao.utils.Page.getMapBuffer = function (guid) {
    ///	<summary>
    ///	获取映射缓存
    ///	</summary>
    ///	<param name="guid" type="string">guid</param>
    ///	<returns type="object"></returns>

    return Swao.utils.Page.mapBuffer.get(guid);
};

Swao.utils.Page.deleteMapBuffer = function (guid) {
    ///	<summary>
    ///	删除映射缓存
    ///	</summary>
    ///	<param name="guid" type="string">guid</param>

    return Swao.utils.Page.mapBuffer.remove(guid);
};

// #region 映射类别
Swao.utils.Page.guid_data = function (guid) {
    ///	<summary>
    ///	数据缓存的GUID
    ///	</summary>
    ///	<param name="guid" type="string">guid</param>
    ///	<returns type="string"></returns>

    return "d_" + guid;
};

Swao.utils.Page.guid_Search = function (guid) {
    ///	<summary>
    ///	搜索缓存的GUID
    ///	</summary>
    ///	<param name="guid" type="string">guid</param>
    ///	<returns type="string"></returns>

    return "s_" + guid;
};
// #endregion

// #region 项目特定的映射类别
Swao.utils.Page.guid_data_RepeaterItem = function (guid) {
    return Swao.utils.Page.guid_data("RepeaterItem_" + guid);
};
// #endregion
﻿
if (typeof (Swao.utils) == 'undefined')
    Swao.utils = new Object();
if (typeof (Swao.utils.Random) == 'undefined')
    Swao.utils.Random = new Object();
//Swao.register('Swao.utils.Random');

Swao.utils.Random = {
};
﻿
if (typeof (Swao.utils) == 'undefined')
    Swao.utils = new Object();
if (typeof (Swao.utils.Repost) == 'undefined')
    Swao.utils.Repost = new Object();
//Swao.register('Swao.utils.Repost');

Swao.utils.Repost = {
    repostTokaixin001: function () {
        ///	<summary>
        ///	发布给开心网
        ///	</summary>

        d = document;
        t = d.selection ? (d.selection.type != 'None' ? d.selection.createRange().text : '') : (d.getSelection ? d.getSelection() : '');
        kaixin = window.open(Swao.utils.String.format('http://www.kaixin001.com/~repaste/repaste.php?&rurl={0}&rtitle={1}&rcontent={2}', escape(d.location.href), escape(d.title), escape(t)), 'kaixin');
        kaixin.focus();
    },

    repostToRenren: function () {
        ///	<summary>
        ///	发布给人人网
        ///	</summary>

    },

    shareToRenren: function () {
        ///	<summary>
        ///	共享给人人网
        ///	</summary>

        renren = window.open(Swao.utils.String.format('http://share.renren.com/share/buttonshare.do?link={0}&title={1}', escape(document.location.href), escape(document.title)), 'renren');
        renren.focus();
    },

    shareToDouban: function () {
        ///	<summary>
        ///	共享给豆瓣
        ///	</summary>

        douban = window.open(Swao.utils.String.format('http://www.douban.com/recommend/?url={0}&title={1}', escape(document.location.href), escape(document.title)), 'douban');
        douban.focus();
    }
};
﻿
if (typeof (Swao.utils) == 'undefined')
    Swao.utils = new Object();
if (typeof (Swao.utils.Security) == 'undefined')
    Swao.utils.Security = new Object();
//Swao.register('Swao.utils.Security');

Swao.utils.Security = {
    md5: function (string) {
        ///	<summary>
        ///	MD5加密，中文采用UTF8编码
        ///	</summary>
        ///	<param name="data" type="String"></param>
        ///	<returns type="String">MD5加密字符串</returns>
        if (!string) return null;

        string = '' + string; // convert param to String, by janlay
        function RotateLeft(lValue, iShiftBits) {
            return (lValue << iShiftBits) | (lValue >>> (32 - iShiftBits));
        }

        function F(x, y, z) { return (x & y) | ((~x) & z); }
        function G(x, y, z) { return (x & z) | (y & (~z)); }
        function H(x, y, z) { return (x ^ y ^ z); }
        function I(x, y, z) { return (y ^ (x | (~z))); }

        function FF(a, b, c, d, x, s, ac) {
            a = Swao.utils.Math.addUnsigned(a, Swao.utils.Math.addUnsigned(Swao.utils.Math.addUnsigned(F(b, c, d), x), ac));
            return Swao.utils.Math.addUnsigned(RotateLeft(a, s), b);
        }

        function GG(a, b, c, d, x, s, ac) {
            a = Swao.utils.Math.addUnsigned(a, Swao.utils.Math.addUnsigned(Swao.utils.Math.addUnsigned(G(b, c, d), x), ac));
            return Swao.utils.Math.addUnsigned(RotateLeft(a, s), b);
        }

        function HH(a, b, c, d, x, s, ac) {
            a = Swao.utils.Math.addUnsigned(a, Swao.utils.Math.addUnsigned(Swao.utils.Math.addUnsigned(H(b, c, d), x), ac));
            return Swao.utils.Math.addUnsigned(RotateLeft(a, s), b);
        }

        function II(a, b, c, d, x, s, ac) {
            a = Swao.utils.Math.addUnsigned(a, Swao.utils.Math.addUnsigned(Swao.utils.Math.addUnsigned(I(b, c, d), x), ac));
            return Swao.utils.Math.addUnsigned(RotateLeft(a, s), b);
        }

        function ConvertToWordArray(string) {
            var lWordCount;
            var lMessageLength = string.length;
            var lNumberOfWords_temp1 = lMessageLength + 8;
            var lNumberOfWords_temp2 = (lNumberOfWords_temp1 - (lNumberOfWords_temp1 % 64)) / 64;
            var lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16;
            var lWordArray = Array(lNumberOfWords - 1);
            var lBytePosition = 0;
            var lByteCount = 0;
            while (lByteCount < lMessageLength) {
                lWordCount = (lByteCount - (lByteCount % 4)) / 4;
                lBytePosition = (lByteCount % 4) * 8;
                lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount) << lBytePosition));
                lByteCount++;
            }
            lWordCount = (lByteCount - (lByteCount % 4)) / 4;
            lBytePosition = (lByteCount % 4) * 8;
            lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80 << lBytePosition);
            lWordArray[lNumberOfWords - 2] = lMessageLength << 3;
            lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29;
            return lWordArray;
        }

        function WordToHex(lValue) {
            var WordToHexValue = "", WordToHexValue_temp = "", lByte, lCount;
            for (lCount = 0; lCount <= 3; lCount++) {
                lByte = (lValue >>> (lCount * 8)) & 255;
                WordToHexValue_temp = "0" + lByte.toString(16);
                WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length - 2, 2);
            }
            return WordToHexValue;
        }

        var x = Array();
        var k, AA, BB, CC, DD, a, b, c, d;
        var S11 = 7, S12 = 12, S13 = 17, S14 = 22;
        var S21 = 5, S22 = 9, S23 = 14, S24 = 20;
        var S31 = 4, S32 = 11, S33 = 16, S34 = 23;
        var S41 = 6, S42 = 10, S43 = 15, S44 = 21;

        string = Swao.utils.Encoding.utf8Encode(string);

        x = ConvertToWordArray(string);

        a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476;

        for (k = 0; k < x.length; k += 16) {
            AA = a; BB = b; CC = c; DD = d;
            a = FF(a, b, c, d, x[k + 0], S11, 0xD76AA478);
            d = FF(d, a, b, c, x[k + 1], S12, 0xE8C7B756);
            c = FF(c, d, a, b, x[k + 2], S13, 0x242070DB);
            b = FF(b, c, d, a, x[k + 3], S14, 0xC1BDCEEE);
            a = FF(a, b, c, d, x[k + 4], S11, 0xF57C0FAF);
            d = FF(d, a, b, c, x[k + 5], S12, 0x4787C62A);
            c = FF(c, d, a, b, x[k + 6], S13, 0xA8304613);
            b = FF(b, c, d, a, x[k + 7], S14, 0xFD469501);
            a = FF(a, b, c, d, x[k + 8], S11, 0x698098D8);
            d = FF(d, a, b, c, x[k + 9], S12, 0x8B44F7AF);
            c = FF(c, d, a, b, x[k + 10], S13, 0xFFFF5BB1);
            b = FF(b, c, d, a, x[k + 11], S14, 0x895CD7BE);
            a = FF(a, b, c, d, x[k + 12], S11, 0x6B901122);
            d = FF(d, a, b, c, x[k + 13], S12, 0xFD987193);
            c = FF(c, d, a, b, x[k + 14], S13, 0xA679438E);
            b = FF(b, c, d, a, x[k + 15], S14, 0x49B40821);
            a = GG(a, b, c, d, x[k + 1], S21, 0xF61E2562);
            d = GG(d, a, b, c, x[k + 6], S22, 0xC040B340);
            c = GG(c, d, a, b, x[k + 11], S23, 0x265E5A51);
            b = GG(b, c, d, a, x[k + 0], S24, 0xE9B6C7AA);
            a = GG(a, b, c, d, x[k + 5], S21, 0xD62F105D);
            d = GG(d, a, b, c, x[k + 10], S22, 0x2441453);
            c = GG(c, d, a, b, x[k + 15], S23, 0xD8A1E681);
            b = GG(b, c, d, a, x[k + 4], S24, 0xE7D3FBC8);
            a = GG(a, b, c, d, x[k + 9], S21, 0x21E1CDE6);
            d = GG(d, a, b, c, x[k + 14], S22, 0xC33707D6);
            c = GG(c, d, a, b, x[k + 3], S23, 0xF4D50D87);
            b = GG(b, c, d, a, x[k + 8], S24, 0x455A14ED);
            a = GG(a, b, c, d, x[k + 13], S21, 0xA9E3E905);
            d = GG(d, a, b, c, x[k + 2], S22, 0xFCEFA3F8);
            c = GG(c, d, a, b, x[k + 7], S23, 0x676F02D9);
            b = GG(b, c, d, a, x[k + 12], S24, 0x8D2A4C8A);
            a = HH(a, b, c, d, x[k + 5], S31, 0xFFFA3942);
            d = HH(d, a, b, c, x[k + 8], S32, 0x8771F681);
            c = HH(c, d, a, b, x[k + 11], S33, 0x6D9D6122);
            b = HH(b, c, d, a, x[k + 14], S34, 0xFDE5380C);
            a = HH(a, b, c, d, x[k + 1], S31, 0xA4BEEA44);
            d = HH(d, a, b, c, x[k + 4], S32, 0x4BDECFA9);
            c = HH(c, d, a, b, x[k + 7], S33, 0xF6BB4B60);
            b = HH(b, c, d, a, x[k + 10], S34, 0xBEBFBC70);
            a = HH(a, b, c, d, x[k + 13], S31, 0x289B7EC6);
            d = HH(d, a, b, c, x[k + 0], S32, 0xEAA127FA);
            c = HH(c, d, a, b, x[k + 3], S33, 0xD4EF3085);
            b = HH(b, c, d, a, x[k + 6], S34, 0x4881D05);
            a = HH(a, b, c, d, x[k + 9], S31, 0xD9D4D039);
            d = HH(d, a, b, c, x[k + 12], S32, 0xE6DB99E5);
            c = HH(c, d, a, b, x[k + 15], S33, 0x1FA27CF8);
            b = HH(b, c, d, a, x[k + 2], S34, 0xC4AC5665);
            a = II(a, b, c, d, x[k + 0], S41, 0xF4292244);
            d = II(d, a, b, c, x[k + 7], S42, 0x432AFF97);
            c = II(c, d, a, b, x[k + 14], S43, 0xAB9423A7);
            b = II(b, c, d, a, x[k + 5], S44, 0xFC93A039);
            a = II(a, b, c, d, x[k + 12], S41, 0x655B59C3);
            d = II(d, a, b, c, x[k + 3], S42, 0x8F0CCC92);
            c = II(c, d, a, b, x[k + 10], S43, 0xFFEFF47D);
            b = II(b, c, d, a, x[k + 1], S44, 0x85845DD1);
            a = II(a, b, c, d, x[k + 8], S41, 0x6FA87E4F);
            d = II(d, a, b, c, x[k + 15], S42, 0xFE2CE6E0);
            c = II(c, d, a, b, x[k + 6], S43, 0xA3014314);
            b = II(b, c, d, a, x[k + 13], S44, 0x4E0811A1);
            a = II(a, b, c, d, x[k + 4], S41, 0xF7537E82);
            d = II(d, a, b, c, x[k + 11], S42, 0xBD3AF235);
            c = II(c, d, a, b, x[k + 2], S43, 0x2AD7D2BB);
            b = II(b, c, d, a, x[k + 9], S44, 0xEB86D391);
            a = Swao.utils.Math.addUnsigned(a, AA);
            b = Swao.utils.Math.addUnsigned(b, BB);
            c = Swao.utils.Math.addUnsigned(c, CC);
            d = Swao.utils.Math.addUnsigned(d, DD);
        }

        var temp = WordToHex(a) + WordToHex(b) + WordToHex(c) + WordToHex(d);

        return temp.toLowerCase();
    }
};
﻿
if (typeof (Swao.utils) == 'undefined')
    Swao.utils = new Object();
if (typeof (Swao.utils.String) == 'undefined')
    Swao.utils.String = new Object();
//Swao.register('Swao.utils.String');

Swao.utils.String = {
    truncateString: function (str, number) {
        ///	<summary>
        ///	截断字符串
        ///	</summary>
        ///	<param name="str" type="String">输入字符串</param>
        ///	<param name="number" type="int">最大允许返回的ASCII长度</param>
        ///	<returns type="String">截断的字符串，ASCII长度不超过number</returns>

        if (Swao.utils.String.getStrLength(str) <= number)
            return str;
        else {
            var retStr = "";
            var currentCount = 0;
            for (loop = 0; loop < str.length; loop++) {
                ch = str.charAt(loop);
                currentCount += Swao.utils.String.getStrLength(ch);
                if (currentCount > number)
                    break;
                else retStr += ch;
            }
            return retStr;
        }
    },

    isASCII: function (str) {
        ///	<summary>
        ///	检查输入字符是否是ASCII码
        ///	</summary>
        ///	<param name="str" type="String">输入字符</param>
        ///	<returns type="boolean">true:ASCII,False:非ASCII</returns>

        var chineseRegex = /[^\x00-\xff]/g;
        return !(str.replace(chineseRegex, "**") == "**");
    },

    getStrLength: function (str) {
        ///	<summary>
        ///	获取字符串长度(中文2个字符)
        ///	</summary>
        ///	<param name="str" type="String">输入字符串</param>
        ///	<returns type="int">字符串长度(中文2个字符)</returns>

        var chineseRegex = /[^\x00-\xff]/g;
        var strLength = str.replace(chineseRegex, "**").length;
        return strLength;
    },

    format: function () {
        ///	<summary>
        ///	字符串格式化。第一个参数是格式，第二个参数是格式化的第一个参数，第三个参数是格式化的第二个参数...
        /// var fmt = "Hello {0}!";Swao.utils.String.format(fmt, "Andrew");
        ///	</summary>
        ///	<param name="str" type="String">输入字符串</param>
        ///	<returns type="int">字符串长度(中文2个字符)</returns>

        if (arguments.length == 0)
            return null;

        var str = arguments[0];
        for (var i = 1; i < arguments.length; i++) {
            var re = new RegExp('\\{' + (i - 1) + '\\}', 'gm');
            str = str.replace(re, arguments[i]);
        }
        return str;
    },

    isNull: function (str) {
        ///	<summary>
        ///	判断字符串是否为空
        ///	</summary>
        ///	<param name="str" type="String">输入字符串</param>
        ///	<returns type="boolean"></returns>

        return (str == null || typeof (str) == 'undefined');
    },

    isEmpty: function (str) {
        ///	<summary>
        ///	判断字符串是否为空
        ///	</summary>
        ///	<param name="str" type="String">输入字符串</param>
        ///	<returns type="boolean"></returns>

        return (str == '');
    },

    isNullOrEmpty: function (str) {
        ///	<summary>
        ///	判断字符串是否为空
        ///	</summary>
        ///	<param name="str" type="String">输入字符串</param>
        ///	<returns type="boolean"></returns>

        return (str == null || typeof (str) == 'undefined' || str == '');
    },

    replaceChar: function (astring, aindex, Char) {
        ///	<summary>
        ///	字符串匹配
        ///	</summary>

        return astring.substr(0, aindex) + Char + astring.substr(aindex + 1, astring.length - 1);
    }
};

