/*
 *
 * Wijmo Library 3.20173.126
 * http://wijmo.com/
 *
 * Copyright(c) GrapeCity, Inc.  All rights reserved.
 * 
 * Licensed under the Wijmo Commercial License. Also available under the GNU GPL Version 3 license.
 * licensing@wijmo.com
 * http://wijmo.com/widgets/license/
 *
 */
var wijmo;
(function (wijmo) {
    (function (input) {
        /** @ignore */
        var CharInfo = (function () {
            function CharInfo() {
            }
            CharInfo.Getbyte64 = function (s, i) {
                var idx = CharInfo.ALPHA.indexOf(s.charAt(i));
                if (idx == -1) {
                    throw "Cannot decode base64";
                }
                return idx;
            };
            CharInfo.Decode = function (s) {
                if (window.atob !== undefined) {
                    return window.atob(s);
                }

                // convert to string
                s = "" + s;
                var getbyte64 = CharInfo.Getbyte64;
                var pads, i, b10;
                var imax = s.length;
                if (imax == 0) {
                    return s;
                }

                if (imax % 4 != 0) {
                    throw "Cannot decode base64";
                }

                pads = 0;
                if (s.charAt(imax - 1) == CharInfo.PADCHAR) {
                    pads = 1;
                    if (s.charAt(imax - 2) == CharInfo.PADCHAR) {
                        pads = 2;
                    }

                    // either way, we want to ignore this last block
                    imax -= 4;
                }

                var x = [];
                for (i = 0; i < imax; i += 4) {
                    b10 = (getbyte64(s, i) << 18) | (getbyte64(s, i + 1) << 12) | (getbyte64(s, i + 2) << 6) | getbyte64(s, i + 3);
                    x.push(String.fromCharCode(b10 >> 16, (b10 >> 8) & 0xff, b10 & 0xff));
                }

                switch (pads) {
                    case 1:
                        b10 = (getbyte64(s, i) << 18) | (getbyte64(s, i + 1) << 12) | (getbyte64(s, i + 2) << 6);
                        x.push(String.fromCharCode(b10 >> 16, (b10 >> 8) & 0xff));
                        break;
                    case 2:
                        b10 = (getbyte64(s, i) << 18) | (getbyte64(s, i + 1) << 12);
                        x.push(String.fromCharCode(b10 >> 16));
                        break;
                }
                return x.join('');
            };

            CharInfo.prototype.getbyte = function (s, i) {
                var x = s.charCodeAt(i);
                if (x > 255) {
                    throw "INVALID_CHARACTER_ERR: DOM Exception 5";
                }
                return x;
            };

            CharInfo.DecodeCharInfo = function () {
                var str = CharInfo.Decode(CharInfo._base64CharInfo);
                var numArr = [];
                var i = 0;
                for (i = 0; i < str.length; i += 2) {
                    var num = (str.charCodeAt(i + 1) * 256) + str.charCodeAt(i);
                    numArr.push(num);
                }
                var tempResult = [];
                for (i = 0; i < numArr.length; i++) {
                    if (numArr[i] != 0xfffe) {
                        tempResult.push(numArr[i]);
                    } else {
                        var number = numArr[i + 1];
                        for (var j = 1; j < number; j++) {
                            tempResult.push(numArr[i - 1]);
                        }
                        i++;
                    }
                }
                for (i = 0; i < tempResult.length; i += 2) {
                    var val = (tempResult[i + 1] * 65536) + tempResult[i];
                    CharInfo._charInfo.push(val);
                }
            };

            CharInfo.GetByte = function (index) {
                if (CharInfo._charInfo.length === 0) {
                    CharInfo.DecodeCharInfo();
                }
                var i = Math.floor(index / 4);
                var j = index % 4;
                var value = CharInfo._charInfo[i];
                switch (j) {
                    case 0:
                        return value & 0xff;
                    case 1:
                        return (value >> 8) & 0xff;
                    case 2:
                        return (value >> 16) & 0xff;
                    case 3:
                        return (value >> 24) & 0xff;
                }
            };

            CharInfo.GetShortValue = function (index) {
                var i = CharInfo.GetByte(index);
                var j = CharInfo.GetByte(index + 1);
                return j * 256 + i;
            };

            CharInfo.GetIntValue = function (index) {
                var a = CharInfo.GetByte(index);
                var b = CharInfo.GetByte(index + 1);
                var c = CharInfo.GetByte(index + 2);
                var d = CharInfo.GetByte(index + 3);
                return d * 65535 * 256 + c * 65535 + b * 256 + a;
            };
            CharInfo.PADCHAR = "=";
            CharInfo.ALPHA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';

            CharInfo._charInfo = [];

            CharInfo._base64CharInfo = " ";
            return CharInfo;
        })();
        input.CharInfo = CharInfo;

        /** @ignore */
        var CharUnicodeInfo = (function () {
            function CharUnicodeInfo() {
            }
            CharUnicodeInfo.InitTable = function () {
                CharUnicodeInfo.globalizationResourceBytePtr = 0;
                CharUnicodeInfo.headerPtr = CharUnicodeInfo.globalizationResourceBytePtr;
                CharUnicodeInfo.s_pCategoryLevel1Index = CharInfo.GetIntValue(CharUnicodeInfo.globalizationResourceBytePtr + 40);
                CharUnicodeInfo.s_pCategoriesValue = CharInfo.GetIntValue(CharUnicodeInfo.globalizationResourceBytePtr + 0x2c);
                CharUnicodeInfo.s_pNumericLevel1Index = CharInfo.GetIntValue(CharUnicodeInfo.globalizationResourceBytePtr + 0x30);
                CharUnicodeInfo.s_pNumericValues = CharInfo.GetIntValue(CharUnicodeInfo.globalizationResourceBytePtr + 0x38);
                CharUnicodeInfo.s_pDigitValues = CharInfo.GetIntValue(CharUnicodeInfo.globalizationResourceBytePtr + 0x34);
            };

            CharUnicodeInfo.InternalConvertToUtf32 = function (s, index, charLength) {
                charLength.length = 1;
                if (index < (s.length - 1)) {
                    var num = s.charCodeAt(index) - 0xd800;
                    if ((num >= 0) && (num <= 0x3ff)) {
                        var num2 = s.charCodeAt(index + 1) - 0xdc00;
                        if ((num2 >= 0) && (num2 <= 0x3ff)) {
                            charLength.length++;
                            return (((num * 0x400) + num2) + 0x10000);
                        }
                    }
                }
                return s.charCodeAt(index);
            };

            CharUnicodeInfo.InternalGeteCategoryValue = function (ch, offset) {
                if (offset === undefined || offset === null) {
                    offset = 0;
                }
                var num = CharInfo.GetShortValue(CharUnicodeInfo.s_pCategoryLevel1Index + 2 * (ch >> 8));
                num = CharInfo.GetShortValue(CharUnicodeInfo.s_pCategoryLevel1Index + 2 * (num + ((ch >> 4) & 15)));
                var numPtr = CharUnicodeInfo.s_pCategoryLevel1Index + 2 * num;
                var num2 = CharInfo.GetByte(numPtr + (ch & 15));
                return CharInfo.GetByte(CharUnicodeInfo.s_pCategoriesValue + (num2 * 2) + offset);
            };

            CharUnicodeInfo.InternalGetUnicodeCategory = function (str, index, charLength) {
                var utf32 = CharUnicodeInfo.InternalConvertToUtf32(str, index, charLength);

                return CharUnicodeInfo.InternalGeteCategoryValue(utf32, 0);
            };

            CharUnicodeInfo.IsCombiningCategory = function (uc) {
                if ((uc !== 5 /* NonSpacingMark */) && (uc !== 6 /* SpacingCombiningMark */)) {
                    return (uc === 7 /* EnclosingMark */);
                }
                return true;
            };
            return CharUnicodeInfo;
        })();
        input.CharUnicodeInfo = CharUnicodeInfo;

        CharUnicodeInfo.InitTable();

        /** @ignore */
        (function (UnicodeCategory) {
            UnicodeCategory[UnicodeCategory["ClosePunctuation"] = 0x15] = "ClosePunctuation";
            UnicodeCategory[UnicodeCategory["ConnectorPunctuation"] = 0x12] = "ConnectorPunctuation";
            UnicodeCategory[UnicodeCategory["Control"] = 14] = "Control";
            UnicodeCategory[UnicodeCategory["CurrencySymbol"] = 0x1a] = "CurrencySymbol";
            UnicodeCategory[UnicodeCategory["DashPunctuation"] = 0x13] = "DashPunctuation";
            UnicodeCategory[UnicodeCategory["DecimalDigitNumber"] = 8] = "DecimalDigitNumber";
            UnicodeCategory[UnicodeCategory["EnclosingMark"] = 7] = "EnclosingMark";
            UnicodeCategory[UnicodeCategory["FinalQuotePunctuation"] = 0x17] = "FinalQuotePunctuation";
            UnicodeCategory[UnicodeCategory["Format"] = 15] = "Format";
            UnicodeCategory[UnicodeCategory["InitialQuotePunctuation"] = 0x16] = "InitialQuotePunctuation";
            UnicodeCategory[UnicodeCategory["LetterNumber"] = 9] = "LetterNumber";
            UnicodeCategory[UnicodeCategory["LineSeparator"] = 12] = "LineSeparator";
            UnicodeCategory[UnicodeCategory["LowercaseLetter"] = 1] = "LowercaseLetter";
            UnicodeCategory[UnicodeCategory["MathSymbol"] = 0x19] = "MathSymbol";
            UnicodeCategory[UnicodeCategory["ModifierLetter"] = 3] = "ModifierLetter";
            UnicodeCategory[UnicodeCategory["ModifierSymbol"] = 0x1b] = "ModifierSymbol";
            UnicodeCategory[UnicodeCategory["NonSpacingMark"] = 5] = "NonSpacingMark";
            UnicodeCategory[UnicodeCategory["OpenPunctuation"] = 20] = "OpenPunctuation";
            UnicodeCategory[UnicodeCategory["OtherLetter"] = 4] = "OtherLetter";
            UnicodeCategory[UnicodeCategory["OtherNotAssigned"] = 0x1d] = "OtherNotAssigned";
            UnicodeCategory[UnicodeCategory["OtherNumber"] = 10] = "OtherNumber";
            UnicodeCategory[UnicodeCategory["OtherPunctuation"] = 0x18] = "OtherPunctuation";
            UnicodeCategory[UnicodeCategory["OtherSymbol"] = 0x1c] = "OtherSymbol";
            UnicodeCategory[UnicodeCategory["ParagraphSeparator"] = 13] = "ParagraphSeparator";
            UnicodeCategory[UnicodeCategory["PrivateUse"] = 0x11] = "PrivateUse";
            UnicodeCategory[UnicodeCategory["SpaceSeparator"] = 11] = "SpaceSeparator";
            UnicodeCategory[UnicodeCategory["SpacingCombiningMark"] = 6] = "SpacingCombiningMark";
            UnicodeCategory[UnicodeCategory["Surrogate"] = 0x10] = "Surrogate";
            UnicodeCategory[UnicodeCategory["TitlecaseLetter"] = 2] = "TitlecaseLetter";
            UnicodeCategory[UnicodeCategory["UppercaseLetter"] = 0] = "UppercaseLetter";
        })(input.UnicodeCategory || (input.UnicodeCategory = {}));
        var UnicodeCategory = input.UnicodeCategory;

        /** @ignore */
        var StringInfo = (function () {
            function StringInfo() {
            }
            StringInfo.GetNextTextElement = function (str, index, ref) {
                var num2;
                if (str == null) {
                    throw "ArgumentNullException";
                }
                var length = str.length;
                if ((index < 0) || (index >= length)) {
                    if (index != length) {
                        throw "ArgumentOutOfRangeException";
                    }
                    return "";
                }
                var charLengh = {};
                var ucCurrent = CharUnicodeInfo.InternalGetUnicodeCategory(str, index, charLengh);
                num2 = charLengh.length;
                var elementLen = StringInfo.GetCurrentTextElementLen(str, index, length, ucCurrent, num2, ref);
                ref.length = elementLen;
                return str.substr(index, elementLen);
            };
            StringInfo.GetCurrentTextElementLen = function (str, index, len, ucCurrent, currentCharCount, ref) {
                var num;
                if ((index + currentCharCount) === len) {
                    return currentCharCount;
                }
                var charLength = {};
                var uc = CharUnicodeInfo.InternalGetUnicodeCategory(str, index + currentCharCount, charLength);
                num = charLength.length;
                if (((!CharUnicodeInfo.IsCombiningCategory(uc) || CharUnicodeInfo.IsCombiningCategory(ucCurrent)) || ((ucCurrent === 15 /* Format */) || (ucCurrent === 14 /* Control */))) || ((ucCurrent === 29 /* OtherNotAssigned */) || (ucCurrent === 16 /* Surrogate */))) {
                    var num3 = currentCharCount;
                    ref.ucCurrent = uc;
                    ref.currentCharCount = num;
                    return num3;
                }
                var num2 = index;
                index += currentCharCount + num;
                while (index < len) {
                    var charLength = {};
                    uc = CharUnicodeInfo.InternalGetUnicodeCategory(str, index, charLength);
                    num = charLength.length;
                    if (!CharUnicodeInfo.IsCombiningCategory(uc)) {
                        ref.ucCurrent = uc;
                        ref.currentCharCount = num;
                        break;
                    }
                    index += num;
                }
                return (index - num2);
            };

            StringInfo.GetTextElement = function (str) {
                var result = [];
                var index = 0;
                while (index < str.length) {
                    var ref = {};
                    var element = StringInfo.GetNextTextElement(str, index, ref);
                    result.push(element);
                    index += ref.length;
                }
                return result;
            };
            return StringInfo;
        })();
        input.StringInfo = StringInfo;

        /** @ignore */
        var StringCache = (function () {
            function StringCache() {
            }
            StringCache.AddElementCache = function (str, element) {
                if (StringCache.TextElementCacheCount > 500) {
                    StringCache.TextElementCache = {};
                    StringCache.TextElementCacheCount = 0;
                }

                StringCache.TextElementCache[str] = element;
                StringCache.TextElementCacheCount++;
            };
            StringCache.TextElementCache = {};
            StringCache.TextElementCacheCount = 0;
            return StringCache;
        })();
        input.StringCache = StringCache;

        /** @ignore */
        String.prototype.GetStandardPosition = function (position, start) {
            this.CreateSurrogateArray();
            var newValue = position;
            if (StringCache.TextElementArray !== null && position > 0) {
                var maxIndex = Math.min(position, StringCache.TextElementArray.length);
                var totalElementSize = 0;
                for (var i = 0; i < maxIndex; i++) {
                    totalElementSize += StringCache.TextElementArray[i].length;
                }
                newValue = totalElementSize;
            }
            return newValue;
        };

        /** @ignore */
        String.prototype.CreateSurrogateArray = function () {
            if (StringCache.TextElementArray === undefined || StringCache._InnerValue.toString() != this.toString()) {
                StringCache._InnerValue = this;

                //save position of surrogate pair
                var elementCol = StringCache.TextElementCache[this];
                if (elementCol === undefined) {
                    elementCol = StringInfo.GetTextElement(this);

                    // Improve performance.
                    StringCache.AddElementCache(this, elementCol);
                }
                if (elementCol.length === this.length) {
                    StringCache.TextElementArray = null;
                } else {
                    StringCache.TextElementArray = elementCol;
                    StringCache.MultiCharExit = false;
                    for (var i = 0; i < elementCol.length; i++) {
                        if (elementCol[i].length > 2) {
                            StringCache.MultiCharExit = true;
                            break;
                        }
                    }
                }
            }
        };

        /** @ignore */
        String.prototype.GetLength = function () {
            this.CreateSurrogateArray();
            var newLength = this.length;
            if (StringCache.TextElementArray !== null) {
                newLength = StringCache.TextElementArray.length;
            }

            return newLength;
        };

        /** @ignore */
        String.prototype.Substring = function (start, end) {
            this.CreateSurrogateArray();

            if (start >= end) {
                return "";
            }
            var newValue = this.substring(start, end);
            if (StringCache.TextElementArray !== null) {
                start = Math.max(0, start);
                end = Math.min(StringCache.TextElementArray.length, end);
                var result = [];
                for (var i = start; i < end; i++) {
                    result.push(StringCache.TextElementArray[i]);
                }
                newValue = result.join("");
            }

            return newValue;
        };

        /** @ignore */
        String.prototype.IndexOf = function (findtext, startindex) {
            this.CreateSurrogateArray();

            var newValue = this.indexOf(findtext, startindex);
            if (StringCache.TextElementArray !== null && newValue > 0) {
                var totalLength = 0;
                for (var i = 0; i < StringCache.TextElementArray.length; i++) {
                    totalLength += StringCache.TextElementArray[i].length;
                    if (totalLength == newValue) {
                        newValue = i + 1;
                        break;
                    }
                }
            }

            if (StringCache.TextElementArray !== null && newValue >= 0) {
                if (this.Substring(newValue, newValue + findtext.GetLength()).length != findtext.length) {
                    newValue = -1;
                }
            }
            return newValue;
        };

        /** @ignore */
        String.prototype.LastIndexOf = function (text) {
            this.CreateSurrogateArray();
            var newValue = this.lastIndexOf(text);
            if (StringCache.TextElementArray !== null && newValue > 0) {
                var totalLength = 0;
                for (var i = 0; i < StringCache.TextElementArray.length; i++) {
                    totalLength += StringCache.TextElementArray[i];
                    if (totalLength == newValue) {
                        newValue = i + 1;
                        break;
                    }
                }
            }

            if (StringCache.TextElementArray !== null && newValue >= 0) {
                if (this.Substring(newValue, newValue + text.GetLength()).length != text.length) {
                    newValue = -1;
                }
            }
            return newValue;
        };

        /** @ignore */
        String.prototype.CharAt = function (position) {
            this.CreateSurrogateArray();
            var newValue = this.charAt(position);
            if (StringCache.TextElementArray !== null) {
                if (position >= 0 && position < StringCache.TextElementArray.length) {
                    newValue = StringCache.TextElementArray[position];
                } else {
                    newValue = "";
                }
            }

            return newValue;
        };

        /** @ignore */
        String.prototype.startWith = function (str) {
            if (str == null || str == "" || this.length == 0 || str.length > this.length)
                return false;
            if (this.substr(0, str.length) == str)
                return true;
            else
                return false;
        };

        /** @ignore */
        String.prototype.IsNulOrEmpty = function (str) {
            return str == null || str == "";
        };
    })(wijmo.input || (wijmo.input = {}));
    var input = wijmo.input;
})(wijmo || (wijmo = {}));

;
