├── README.md ├── broadcast.md ├── dex.md ├── dividends.md ├── issuance.md ├── js ├── biginteger.js ├── bitcore │ ├── .bower.json │ ├── LICENSE │ ├── README.md │ ├── bitcore.js │ ├── bitcore.min.js │ ├── bower.json │ └── package.json ├── hex2dec-cs.js ├── jquery.min.js ├── mnemonic.js └── xcp-js │ ├── convert-type.js │ ├── decode.js │ ├── pushtx.js │ ├── rc4.js │ └── transactions.js └── test ├── asset_send.html ├── broadcast_send.html ├── extract_asset_send.html ├── extract_broadcast.html ├── extract_issuance.html ├── index.html └── issue_asset.html /README.md: -------------------------------------------------------------------------------- 1 | # XCP Tools JS 2 | 3 | Javascript library for encoding and decoding Counterparty (http://counterparty.io) data in Bitcoin transactions. 4 | 5 | Includes the following transaction types: 6 | - Asset Send (OP_CHECKMULTISIG and OP_RETURN) 7 | - Broadcast (OP_CHECKMULTISIG) 8 | - Asset Issuance (OP_CHECKMULTISIG) 9 | 10 | XCP Tools JS utilizes jQuery (http://jquery.org), Bitcore (http://bitcore.io) and Mnemonic.js (http://github.com/ggozad/mnemonic.js) libraries as well as APIs from Insight (http://insight.bitpay.com), Blockchain.info (http://blockchain.info) and Counterpartychain (https://counterpartychain.io). 11 | 12 | Currently under development, use at your own risk! 13 | 14 | Helpful? Donate to 1LrM4bojLAKfuoFMXkDtVPMGydX1rkaMqH 15 | -------------------------------------------------------------------------------- /broadcast.md: -------------------------------------------------------------------------------- 1 | Broadcast Transaction Example 2 | ----------------------------- 3 | 4 | http://www.blockscan.com/feedinfo?q=11627824 5 | 6 | 2a434e5452505254590000001e552161c8403e000000000000000000000d584350454c454354494f4e203100000000000000000000000000000000000000 7 | 8 | 2a <-- Message Length + 29 = 13 + 29 = 42 (hex to dec) 9 | 10 | 434e545250525459 <-- CNTRPRTY prefix (hex to bin) 11 | 12 | 0000001e <-- ID = 30 (hex to dec) 13 | 14 | 552161c8 <-- Timestamp = 1428251080 (hex to dec) 15 | 16 | 403e000000000000 <-- Value = 30 (hex to floating pt) 17 | 18 | 00000000 <-- Fee Fraction Data = 0 (hex to dec) 19 | 20 | 0d <-- Message Length = 13 (hex to dec) 21 | 22 | 584350454c454354494f4e203100000000000000000000000000000000000000 <-- Broadcast Message = XCPELECTION 1 (hex to bin) 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /dex.md: -------------------------------------------------------------------------------- 1 | https://chain.so/tx/BTC/3c5bd0fa2c977211287b1b8473878d1498a1f951c57431c6a50d42e91b35e52a 2 | 3 | ```` 4 | 5 | 434e545250525459 = CNTRPRTY prefix (hex to text) 6 | 0000000a = Transaction ID = 10 (hex to dec) 7 | 00098b174a7d3945 = Asset to Sell = 2686206940625221 = TATIANACOIN (hex to dec) 8 | 00000022ecb25c00 = Amount to Sell = 150000000000 (hex to dec) 9 | 0000000000000001 = Asset to Buy = 1 = XCP (hex to dec) 10 | 0000000035a4e900 = Amount to Buy = 900000000 (hex to dec) 11 | 03e8 = Expiration = 1000 blocks (hex to dec) 12 | 0000000000000000 = Fee Required = 0 satoshis (hex to dec) 13 | ```` 14 | 15 | 16 | https://chain.so/api/v2/tx/BTC/f25b72c68f8f277ff5a92cec02ad70521a4e2219fc5342e48176bd539e0e6151 17 | 18 | ```` 19 | 20 | 434e545250525459 = CNTRPRTY prefix (hex to text) 21 | 0000000a = Transaction ID = 10 (hex to dec) 22 | 0000000000000001 = Asset to Sell = 1 = XCP (hex to dec) 23 | 000000000e5c9d61 = Amount to Sell = 240950625 (hex to dec) 24 | 00000000d806c1d5 = Asset to Buy = 3624321493 = LTBCOIN (hex to dec) 25 | 0000046203873a20 = Amount to Buy = 4819012500000 (hex to dec) 26 | 03e8 = Expiration = 1000 blocks (hex to dec) 27 | 0000000000000000 = Fee Required = 0 satoshis (hex to dec) 28 | ```` 29 | 30 | 31 | https://chain.so/tx/BTC/da6b47b20f1cb410d80cd0a4e2cec95c43315155139721801ab57efc7630e810 32 | 33 | ```` 34 | 35 | 434e545250525459 = CNTRPRTY prefix (hex to text) 36 | 0000000a = Transaction ID = 10 (hex to dec) 37 | 00000000001c125a = Asset to Sell = 1839706 = EARLY (hex to dec) 38 | 0000000000000001 = Amount to Sell = 1 (hex to dec) 39 | 00000021ce5ce3ba = Asset to Buy = 145196114874 = SCAMMIES (hex to dec) 40 | 000000b512884100 = Amount to Buy = 777700000000 (hex to dec) 41 | 03e8 = Expiration = 1000 blocks (hex to dec) 42 | 0000000000000000 = Fee Required = 0 satoshis (hex to dec) 43 | ```` 44 | 45 | 46 | https://chain.so/tx/BTC/ac489447245fff131cdd0e4246c307997c1a25509fd69a8a3623d7dbd82ca838 47 | 48 | ```` 49 | 50 | 434e545250525459 = CNTRPRTY prefix (hex to text) 51 | 00000046 = Transaction ID = 10 (hex to dec) 52 | 3c0381a7cc44af01da2aee188f8896729bfcaa7fe255f68671912fd528c59f1d = Cancel Order with this Transaction ID 53 | 54 | ```` 55 | 56 | https://chain.so/tx/BTC/34e2bb5b3312630d11404880cec4b8e7bfc895124153ca5db94dd2fb3ffdf946 57 | 58 | ```` 59 | 60 | BTC Pay for Buy OAZT/Sell BTC order (Txid 36c485), Block 350068, Sent by 15ztnk 61 | 62 | Outputs / Receivers 63 | 0 17FKi2nNYtq6VGjayArSNJ9MPQqZJC3j9U 0.01350000 = Send BTC buy amount to BTC Buyer 64 | 65 | Outputs / Multisig Data (2) 66 | 434e545250525459 67 | 0000000b 68 | 36c4857c11ac5c6620bf51f763c9858c0cc7f090b731ad8fb2aa7253bf4a65ee 69 | 18b355d2e87d14c8a33b12c3e576c8e450 (434e545250525459) 13beedf70b1c7253c70dffa640aebb 70 | 0000000000000000000000000000000000000000000000000000000000000000000000000000 71 | 72 | 73 | 434e545250525459 = CNTRPRTY prefix (hex to text) 74 | 0000000b = Transaction ID = 11 (hex to dec) 75 | 36c4857c11ac5c6620bf51f763c9858c0cc7f090b731ad8fb2aa7253bf4a65ee = Tx ID of Order (Buy OAZT/Sell BTC, Block 350063, XCP TX #11620755, Sent by 15ztnk) 76 | 77 | 434e545250525459 = CNTRPRTY prefix (hex to text) 78 | 0000000a = Transaction ID = 10 (hex to dec) 79 | 0000000000000000 = Asset to Sell = BTC 80 | 000000000016e360 = Amount to Sell = 1500000 satoshis 81 | 000000000003c3cd = Asset to Buy = 246733 = OAZT 82 | 000000003b9aca00 = Amount to Buy = 1000000000 83 | 03e8 = Expiration = 1000 blocks (hex to dec) 84 | 0000000000000000 = Fee Required = 0 satoshis (hex to dec) 85 | 00000000000000 86 | 87 | 434e545250525459 = CNTRPRTY prefix (hex to text) 88 | 18b355d2e87d14c8a33b12c3e576c8e45013beedf70b1c7253c70dffa640aebb = Tx ID of BTC Buy Order (Buy BTC/Sell OAZT, Block 350063, XCP TX #11620756, Sent by 17FKi2) 89 | 90 | 434e545250525459 = CNTRPRTY prefix (hex to text) 91 | 0000000a = Transaction ID = 10 (hex to dec) 92 | 000000000003c3cd = Asset to Sell = 246733 = OAZT 93 | 000000003b9aca00 = Amount to Sell = 1000000000 94 | 0000000000000000 = Asset to Buy = BTC 95 | 000000000016e360 = Amount to Buy = 1500000 satoshis 96 | 03e8 = Expiration = 1000 blocks (hex to dec) 97 | 0000000000000000 = Fee Required = 0 satoshis (hex to dec) 98 | 00000000000000 99 | 100 | 0000000000000000000000000000000000000000000000000000000000000000000000000000 101 | ```` 102 | 103 | 104 | -------------------------------------------------------------------------------- /dividends.md: -------------------------------------------------------------------------------- 1 | 2 | https://chain.so/tx/BTC/f2c0ef65173cbf34ae67d8e43aecdd96f97ac941731cf08ccd75c1804d06a07d 3 | 4 | ```` 5 | 6 | 434e545250525459 = CNTRPRTY (hex to text) 7 | 00000032 = Transaction ID = 50 (hex to dec) 8 | 0000000d09dc3000 = Amount per Share = 56000000000 (hex to dec) 9 | 00000009be0ab3a9 = Asset ID = 41843078057 = FFLTEAMB (hex to dec) 10 | 00000000d806c1d5 = Asset to Distribute = 3624321493 = LTBCOIN (hex to dec) 11 | 12 | ```` 13 | -------------------------------------------------------------------------------- /issuance.md: -------------------------------------------------------------------------------- 1 | Issuance Examples 2 | ----------------- 3 | 4 | 5 | https://counterpartychain.io/transaction/3e880e240dd48cce2f2bdb46527ce67757688959faa9ad372b6d5d0c11210cec 6 | 7 | -single multisig output- 8 | 9 | 27 = Encoded Data Length in Bytes (minus this index) = 39 (hex to dec) 10 | 434e545250525459 = CNTRPRTY (hex to text) 11 | 00000014 = Transaction ID = 20 (hex to dec) 12 | 00000002b790a1a0 = Asset ID = 11669643680 = BLUERING (hex to dec) 13 | 0000000000000001 = Quantity = 1 (hex to dec) 14 | 00000000000000000000 = Divisible: False (hex to dec) 15 | 00 = Description Length (hex to dec) 16 | 17 | 18 | 19 | https://counterpartychain.io/transaction/fd9bbc15b051f74541f5f53dfe560315fc14ad23bd152e8b2197b0b81be0b661 20 | 21 | -first multisig output- 22 | 23 | 3d = Encoded Data Length in Bytes (minus this index) = 61 (hex to dec) 24 | 434e545250525459 = CNTRPRTY (hex to text) 25 | 00000014 = Transaction ID = 20 (hex to dec) 26 | 97384fe311367090 = Asset ID = 10896547135087866000 (hex to dec) = A10896547135087866000 27 | 00000000000f423f = Quantity = 999999 (hex to dec) 28 | 00000000000000000000 = Divisible: False (hex to dec) 29 | 29 = Description Length = 41 (hex to dec) 30 | 74686973206973207468652062657374207465737420 = Description = this is the best test (hex to text) 31 | 32 | 33 | -second multisig output- 34 | 35 | 1b = 27 (hex to dec) 36 | 434e545250525459 = CNTRPRTY (hex to text) 37 | 61737365742074686174206861732065766572 = Description (cont.) = asset that has ever (hex to text) 38 | 39 | 40 | 41 | https://counterpartychain.io/transaction/4d6f504c6e0693cd79b2f252520b7e8cce0618a580a71fbb62b663a9c61ae1b9 42 | 43 | -single multisig output- 44 | 45 | 35 = Encoded Data Length in Bytes (minus this index) = 53 (hex to dec) 46 | 434e545250525459 = CNTRPRTY (hex to text) 47 | 00000014 = Transaction ID = 20 (hex to dec) 48 | faccf8d47f247a10 = Asset ID = 18072092996280810000 (hex to dec) = A18072092996280810000 49 | 000775f05a074000 = Quantity = 2100000000000000 (hex to dec) = 21000000.00000000 units/divisible 50 | 01000000000000000000 = Divisible: True (hex to dec) 51 | 0e = Description Length = 14 52 | 436f6d706f7374637265646974730000000000000000 = Description = Compostcredits 53 | -------------------------------------------------------------------------------- /js/biginteger.js: -------------------------------------------------------------------------------- 1 | /* 2 | JavaScript BigIntegerSM library version 0.9 3 | http://silentmatt.com/biginteger/ 4 | 5 | Copyright (c) 2009 Matthew Crumley 6 | Copyright (c) 2010,2011 by John Tobey 7 | Licensed under the MIT license. 8 | 9 | Support for arbitrary internal representation base was added by 10 | Vitaly Magerya. 11 | */ 12 | 13 | /* 14 | File: biginteger.js 15 | 16 | Exports: 17 | 18 | 19 | */ 20 | (function(exports) { 21 | "use strict"; 22 | /* 23 | Class: BigIntegerSM 24 | An arbitrarily-large integer. 25 | 26 | objects should be considered immutable. None of the "built-in" 27 | methods modify *this* or their arguments. All properties should be 28 | considered private. 29 | 30 | All the methods of instances can be called "statically". The 31 | static versions are convenient if you don't already have a 32 | object. 33 | 34 | As an example, these calls are equivalent. 35 | 36 | > BigIntegerSM(4).multiply(5); // returns BigIntegerSM(20); 37 | > BigIntegerSM.multiply(4, 5); // returns BigIntegerSM(20); 38 | 39 | > var a = 42; 40 | > var a = BigIntegerSM.toJSValue("0b101010"); // Not completely useless... 41 | */ 42 | 43 | var CONSTRUCT = {}; // Unique token to call "private" version of constructor 44 | 45 | /* 46 | Constructor: BigIntegerSM() 47 | Convert a value to a . 48 | 49 | Although is the constructor for objects, it is 50 | best not to call it as a constructor. If *n* is a object, it is 51 | simply returned as-is. Otherwise, is equivalent to 52 | without a radix argument. 53 | 54 | > var n0 = BigIntegerSM(); // Same as 55 | > var n1 = BigIntegerSM("123"); // Create a new with value 123 56 | > var n2 = BigIntegerSM(123); // Create a new with value 123 57 | > var n3 = BigIntegerSM(n2); // Return n2, unchanged 58 | 59 | The constructor form only takes an array and a sign. *n* must be an 60 | array of numbers in little-endian order, where each digit is between 0 61 | and BigIntegerSM.base. The second parameter sets the sign: -1 for 62 | negative, +1 for positive, or 0 for zero. The array is *not copied and 63 | may be modified*. If the array contains only zeros, the sign parameter 64 | is ignored and is forced to zero. 65 | 66 | > new BigIntegerSM([5], -1): create a new BigIntegerSM with value -5 67 | 68 | Parameters: 69 | 70 | n - Value to convert to a . 71 | 72 | Returns: 73 | 74 | A value. 75 | 76 | See Also: 77 | 78 | , 79 | */ 80 | function BigIntegerSM(n, s, token) { 81 | if (token !== CONSTRUCT) { 82 | if (n instanceof BigIntegerSM) { 83 | return n; 84 | } 85 | else if (typeof n === "undefined") { 86 | return ZERO; 87 | } 88 | return BigIntegerSM.parse(n); 89 | } 90 | 91 | n = n || []; // Provide the nullary constructor for subclasses. 92 | while (n.length && !n[n.length - 1]) { 93 | --n.length; 94 | } 95 | this._d = n; 96 | this._s = n.length ? (s || 1) : 0; 97 | } 98 | 99 | BigIntegerSM._construct = function(n, s) { 100 | return new BigIntegerSM(n, s, CONSTRUCT); 101 | }; 102 | 103 | // Base-10 speedup hacks in parse, toString, exp10 and log functions 104 | // require base to be a power of 10. 10^7 is the largest such power 105 | // that won't cause a precision loss when digits are multiplied. 106 | var BigIntegerSM_base = 10000000; 107 | var BigIntegerSM_base_log10 = 7; 108 | 109 | BigIntegerSM.base = BigIntegerSM_base; 110 | BigIntegerSM.base_log10 = BigIntegerSM_base_log10; 111 | 112 | var ZERO = new BigIntegerSM([], 0, CONSTRUCT); 113 | // Constant: ZERO 114 | // 0. 115 | BigIntegerSM.ZERO = ZERO; 116 | 117 | var ONE = new BigIntegerSM([1], 1, CONSTRUCT); 118 | // Constant: ONE 119 | // 1. 120 | BigIntegerSM.ONE = ONE; 121 | 122 | var M_ONE = new BigIntegerSM(ONE._d, -1, CONSTRUCT); 123 | // Constant: M_ONE 124 | // -1. 125 | BigIntegerSM.M_ONE = M_ONE; 126 | 127 | // Constant: _0 128 | // Shortcut for . 129 | BigIntegerSM._0 = ZERO; 130 | 131 | // Constant: _1 132 | // Shortcut for . 133 | BigIntegerSM._1 = ONE; 134 | 135 | /* 136 | Constant: small 137 | Array of from 0 to 36. 138 | 139 | These are used internally for parsing, but useful when you need a "small" 140 | . 141 | 142 | See Also: 143 | 144 | , , <_0>, <_1> 145 | */ 146 | BigIntegerSM.small = [ 147 | ZERO, 148 | ONE, 149 | /* Assuming BigIntegerSM_base > 36 */ 150 | new BigIntegerSM( [2], 1, CONSTRUCT), 151 | new BigIntegerSM( [3], 1, CONSTRUCT), 152 | new BigIntegerSM( [4], 1, CONSTRUCT), 153 | new BigIntegerSM( [5], 1, CONSTRUCT), 154 | new BigIntegerSM( [6], 1, CONSTRUCT), 155 | new BigIntegerSM( [7], 1, CONSTRUCT), 156 | new BigIntegerSM( [8], 1, CONSTRUCT), 157 | new BigIntegerSM( [9], 1, CONSTRUCT), 158 | new BigIntegerSM([10], 1, CONSTRUCT), 159 | new BigIntegerSM([11], 1, CONSTRUCT), 160 | new BigIntegerSM([12], 1, CONSTRUCT), 161 | new BigIntegerSM([13], 1, CONSTRUCT), 162 | new BigIntegerSM([14], 1, CONSTRUCT), 163 | new BigIntegerSM([15], 1, CONSTRUCT), 164 | new BigIntegerSM([16], 1, CONSTRUCT), 165 | new BigIntegerSM([17], 1, CONSTRUCT), 166 | new BigIntegerSM([18], 1, CONSTRUCT), 167 | new BigIntegerSM([19], 1, CONSTRUCT), 168 | new BigIntegerSM([20], 1, CONSTRUCT), 169 | new BigIntegerSM([21], 1, CONSTRUCT), 170 | new BigIntegerSM([22], 1, CONSTRUCT), 171 | new BigIntegerSM([23], 1, CONSTRUCT), 172 | new BigIntegerSM([24], 1, CONSTRUCT), 173 | new BigIntegerSM([25], 1, CONSTRUCT), 174 | new BigIntegerSM([26], 1, CONSTRUCT), 175 | new BigIntegerSM([27], 1, CONSTRUCT), 176 | new BigIntegerSM([28], 1, CONSTRUCT), 177 | new BigIntegerSM([29], 1, CONSTRUCT), 178 | new BigIntegerSM([30], 1, CONSTRUCT), 179 | new BigIntegerSM([31], 1, CONSTRUCT), 180 | new BigIntegerSM([32], 1, CONSTRUCT), 181 | new BigIntegerSM([33], 1, CONSTRUCT), 182 | new BigIntegerSM([34], 1, CONSTRUCT), 183 | new BigIntegerSM([35], 1, CONSTRUCT), 184 | new BigIntegerSM([36], 1, CONSTRUCT) 185 | ]; 186 | 187 | // Used for parsing/radix conversion 188 | BigIntegerSM.digits = "0123456789abcdefghijklmnopqrstuvwxyz".split(""); 189 | 190 | /* 191 | Method: toString 192 | Convert a to a string. 193 | 194 | When *base* is greater than 10, letters are upper case. 195 | 196 | Parameters: 197 | 198 | base - Optional base to represent the number in (default is base 10). 199 | Must be between 2 and 36 inclusive, or an Error will be thrown. 200 | 201 | Returns: 202 | 203 | The string representation of the . 204 | */ 205 | BigIntegerSM.prototype.toString = function(base) { 206 | base = +base || 10; 207 | if (base < 2 || base > 36) { 208 | throw new Error("illegal radix " + base + "."); 209 | } 210 | if (this._s === 0) { 211 | return "0"; 212 | } 213 | if (base === 10) { 214 | var str = this._s < 0 ? "-" : ""; 215 | str += this._d[this._d.length - 1].toString(); 216 | for (var i = this._d.length - 2; i >= 0; i--) { 217 | var group = this._d[i].toString(); 218 | while (group.length < BigIntegerSM_base_log10) group = '0' + group; 219 | str += group; 220 | } 221 | return str; 222 | } 223 | else { 224 | var numerals = BigIntegerSM.digits; 225 | base = BigIntegerSM.small[base]; 226 | var sign = this._s; 227 | 228 | var n = this.abs(); 229 | var digits = []; 230 | var digit; 231 | 232 | while (n._s !== 0) { 233 | var divmod = n.divRem(base); 234 | n = divmod[0]; 235 | digit = divmod[1]; 236 | // TODO: This could be changed to unshift instead of reversing at the end. 237 | // Benchmark both to compare speeds. 238 | digits.push(numerals[digit.valueOf()]); 239 | } 240 | return (sign < 0 ? "-" : "") + digits.reverse().join(""); 241 | } 242 | }; 243 | 244 | // Verify strings for parsing 245 | BigIntegerSM.radixRegex = [ 246 | /^$/, 247 | /^$/, 248 | /^[01]*$/, 249 | /^[012]*$/, 250 | /^[0-3]*$/, 251 | /^[0-4]*$/, 252 | /^[0-5]*$/, 253 | /^[0-6]*$/, 254 | /^[0-7]*$/, 255 | /^[0-8]*$/, 256 | /^[0-9]*$/, 257 | /^[0-9aA]*$/, 258 | /^[0-9abAB]*$/, 259 | /^[0-9abcABC]*$/, 260 | /^[0-9a-dA-D]*$/, 261 | /^[0-9a-eA-E]*$/, 262 | /^[0-9a-fA-F]*$/, 263 | /^[0-9a-gA-G]*$/, 264 | /^[0-9a-hA-H]*$/, 265 | /^[0-9a-iA-I]*$/, 266 | /^[0-9a-jA-J]*$/, 267 | /^[0-9a-kA-K]*$/, 268 | /^[0-9a-lA-L]*$/, 269 | /^[0-9a-mA-M]*$/, 270 | /^[0-9a-nA-N]*$/, 271 | /^[0-9a-oA-O]*$/, 272 | /^[0-9a-pA-P]*$/, 273 | /^[0-9a-qA-Q]*$/, 274 | /^[0-9a-rA-R]*$/, 275 | /^[0-9a-sA-S]*$/, 276 | /^[0-9a-tA-T]*$/, 277 | /^[0-9a-uA-U]*$/, 278 | /^[0-9a-vA-V]*$/, 279 | /^[0-9a-wA-W]*$/, 280 | /^[0-9a-xA-X]*$/, 281 | /^[0-9a-yA-Y]*$/, 282 | /^[0-9a-zA-Z]*$/ 283 | ]; 284 | 285 | /* 286 | Function: parse 287 | Parse a string into a . 288 | 289 | *base* is optional but, if provided, must be from 2 to 36 inclusive. If 290 | *base* is not provided, it will be guessed based on the leading characters 291 | of *s* as follows: 292 | 293 | - "0x" or "0X": *base* = 16 294 | - "0c" or "0C": *base* = 8 295 | - "0b" or "0B": *base* = 2 296 | - else: *base* = 10 297 | 298 | If no base is provided, or *base* is 10, the number can be in exponential 299 | form. For example, these are all valid: 300 | 301 | > BigIntegerSM.parse("1e9"); // Same as "1000000000" 302 | > BigIntegerSM.parse("1.234*10^3"); // Same as 1234 303 | > BigIntegerSM.parse("56789 * 10 ** -2"); // Same as 567 304 | 305 | If any characters fall outside the range defined by the radix, an exception 306 | will be thrown. 307 | 308 | Parameters: 309 | 310 | s - The string to parse. 311 | base - Optional radix (default is to guess based on *s*). 312 | 313 | Returns: 314 | 315 | a instance. 316 | */ 317 | BigIntegerSM.parse = function(s, base) { 318 | // Expands a number in exponential form to decimal form. 319 | // expandExponential("-13.441*10^5") === "1344100"; 320 | // expandExponential("1.12300e-1") === "0.112300"; 321 | // expandExponential(1000000000000000000000000000000) === "1000000000000000000000000000000"; 322 | function expandExponential(str) { 323 | str = str.replace(/\s*[*xX]\s*10\s*(\^|\*\*)\s*/, "e"); 324 | 325 | return str.replace(/^([+\-])?(\d+)\.?(\d*)[eE]([+\-]?\d+)$/, function(x, s, n, f, c) { 326 | c = +c; 327 | var l = c < 0; 328 | var i = n.length + c; 329 | x = (l ? n : f).length; 330 | c = ((c = Math.abs(c)) >= x ? c - x + l : 0); 331 | var z = (new Array(c + 1)).join("0"); 332 | var r = n + f; 333 | return (s || "") + (l ? r = z + r : r += z).substr(0, i += l ? z.length : 0) + (i < r.length ? "." + r.substr(i) : ""); 334 | }); 335 | } 336 | 337 | s = s.toString(); 338 | if (typeof base === "undefined" || +base === 10) { 339 | s = expandExponential(s); 340 | } 341 | 342 | var prefixRE; 343 | if (typeof base === "undefined") { 344 | prefixRE = '0[xcb]'; 345 | } 346 | else if (base == 16) { 347 | prefixRE = '0x'; 348 | } 349 | else if (base == 8) { 350 | prefixRE = '0c'; 351 | } 352 | else if (base == 2) { 353 | prefixRE = '0b'; 354 | } 355 | else { 356 | prefixRE = ''; 357 | } 358 | var parts = new RegExp('^([+\\-]?)(' + prefixRE + ')?([0-9a-z]*)(?:\\.\\d*)?$', 'i').exec(s); 359 | if (parts) { 360 | var sign = parts[1] || "+"; 361 | var baseSection = parts[2] || ""; 362 | var digits = parts[3] || ""; 363 | 364 | if (typeof base === "undefined") { 365 | // Guess base 366 | if (baseSection === "0x" || baseSection === "0X") { // Hex 367 | base = 16; 368 | } 369 | else if (baseSection === "0c" || baseSection === "0C") { // Octal 370 | base = 8; 371 | } 372 | else if (baseSection === "0b" || baseSection === "0B") { // Binary 373 | base = 2; 374 | } 375 | else { 376 | base = 10; 377 | } 378 | } 379 | else if (base < 2 || base > 36) { 380 | throw new Error("Illegal radix " + base + "."); 381 | } 382 | 383 | base = +base; 384 | 385 | // Check for digits outside the range 386 | if (!(BigIntegerSM.radixRegex[base].test(digits))) { 387 | throw new Error("Bad digit for radix " + base); 388 | } 389 | 390 | // Strip leading zeros, and convert to array 391 | digits = digits.replace(/^0+/, "").split(""); 392 | if (digits.length === 0) { 393 | return ZERO; 394 | } 395 | 396 | // Get the sign (we know it's not zero) 397 | sign = (sign === "-") ? -1 : 1; 398 | 399 | // Optimize 10 400 | if (base == 10) { 401 | var d = []; 402 | while (digits.length >= BigIntegerSM_base_log10) { 403 | d.push(parseInt(digits.splice(digits.length-BigIntegerSM.base_log10, BigIntegerSM.base_log10).join(''), 10)); 404 | } 405 | d.push(parseInt(digits.join(''), 10)); 406 | return new BigIntegerSM(d, sign, CONSTRUCT); 407 | } 408 | 409 | // Do the conversion 410 | var d = ZERO; 411 | base = BigIntegerSM.small[base]; 412 | var small = BigIntegerSM.small; 413 | for (var i = 0; i < digits.length; i++) { 414 | d = d.multiply(base).add(small[parseInt(digits[i], 36)]); 415 | } 416 | return new BigIntegerSM(d._d, sign, CONSTRUCT); 417 | } 418 | else { 419 | throw new Error("Invalid BigIntegerSM format: " + s); 420 | } 421 | }; 422 | 423 | /* 424 | Function: add 425 | Add two . 426 | 427 | Parameters: 428 | 429 | n - The number to add to *this*. Will be converted to a . 430 | 431 | Returns: 432 | 433 | The numbers added together. 434 | 435 | See Also: 436 | 437 | , , , 438 | */ 439 | BigIntegerSM.prototype.add = function(n) { 440 | if (this._s === 0) { 441 | return BigIntegerSM(n); 442 | } 443 | 444 | n = BigIntegerSM(n); 445 | if (n._s === 0) { 446 | return this; 447 | } 448 | if (this._s !== n._s) { 449 | n = n.negate(); 450 | return this.subtract(n); 451 | } 452 | 453 | var a = this._d; 454 | var b = n._d; 455 | var al = a.length; 456 | var bl = b.length; 457 | var sum = new Array(Math.max(al, bl) + 1); 458 | var size = Math.min(al, bl); 459 | var carry = 0; 460 | var digit; 461 | 462 | for (var i = 0; i < size; i++) { 463 | digit = a[i] + b[i] + carry; 464 | sum[i] = digit % BigIntegerSM_base; 465 | carry = (digit / BigIntegerSM_base) | 0; 466 | } 467 | if (bl > al) { 468 | a = b; 469 | al = bl; 470 | } 471 | for (i = size; carry && i < al; i++) { 472 | digit = a[i] + carry; 473 | sum[i] = digit % BigIntegerSM_base; 474 | carry = (digit / BigIntegerSM_base) | 0; 475 | } 476 | if (carry) { 477 | sum[i] = carry; 478 | } 479 | 480 | for ( ; i < al; i++) { 481 | sum[i] = a[i]; 482 | } 483 | 484 | return new BigIntegerSM(sum, this._s, CONSTRUCT); 485 | }; 486 | 487 | /* 488 | Function: negate 489 | Get the additive inverse of a . 490 | 491 | Returns: 492 | 493 | A with the same magnatude, but with the opposite sign. 494 | 495 | See Also: 496 | 497 | 498 | */ 499 | BigIntegerSM.prototype.negate = function() { 500 | return new BigIntegerSM(this._d, (-this._s) | 0, CONSTRUCT); 501 | }; 502 | 503 | /* 504 | Function: abs 505 | Get the absolute value of a . 506 | 507 | Returns: 508 | 509 | A with the same magnatude, but always positive (or zero). 510 | 511 | See Also: 512 | 513 | 514 | */ 515 | BigIntegerSM.prototype.abs = function() { 516 | return (this._s < 0) ? this.negate() : this; 517 | }; 518 | 519 | /* 520 | Function: subtract 521 | Subtract two . 522 | 523 | Parameters: 524 | 525 | n - The number to subtract from *this*. Will be converted to a . 526 | 527 | Returns: 528 | 529 | The *n* subtracted from *this*. 530 | 531 | See Also: 532 | 533 | , , , 534 | */ 535 | BigIntegerSM.prototype.subtract = function(n) { 536 | if (this._s === 0) { 537 | return BigIntegerSM(n).negate(); 538 | } 539 | 540 | n = BigIntegerSM(n); 541 | if (n._s === 0) { 542 | return this; 543 | } 544 | if (this._s !== n._s) { 545 | n = n.negate(); 546 | return this.add(n); 547 | } 548 | 549 | var m = this; 550 | // negative - negative => -|a| - -|b| => -|a| + |b| => |b| - |a| 551 | if (this._s < 0) { 552 | m = new BigIntegerSM(n._d, 1, CONSTRUCT); 553 | n = new BigIntegerSM(this._d, 1, CONSTRUCT); 554 | } 555 | 556 | // Both are positive => a - b 557 | var sign = m.compareAbs(n); 558 | if (sign === 0) { 559 | return ZERO; 560 | } 561 | else if (sign < 0) { 562 | // swap m and n 563 | var t = n; 564 | n = m; 565 | m = t; 566 | } 567 | 568 | // a > b 569 | var a = m._d; 570 | var b = n._d; 571 | var al = a.length; 572 | var bl = b.length; 573 | var diff = new Array(al); // al >= bl since a > b 574 | var borrow = 0; 575 | var i; 576 | var digit; 577 | 578 | for (i = 0; i < bl; i++) { 579 | digit = a[i] - borrow - b[i]; 580 | if (digit < 0) { 581 | digit += BigIntegerSM_base; 582 | borrow = 1; 583 | } 584 | else { 585 | borrow = 0; 586 | } 587 | diff[i] = digit; 588 | } 589 | for (i = bl; i < al; i++) { 590 | digit = a[i] - borrow; 591 | if (digit < 0) { 592 | digit += BigIntegerSM_base; 593 | } 594 | else { 595 | diff[i++] = digit; 596 | break; 597 | } 598 | diff[i] = digit; 599 | } 600 | for ( ; i < al; i++) { 601 | diff[i] = a[i]; 602 | } 603 | 604 | return new BigIntegerSM(diff, sign, CONSTRUCT); 605 | }; 606 | 607 | (function() { 608 | function addOne(n, sign) { 609 | var a = n._d; 610 | var sum = a.slice(); 611 | var carry = true; 612 | var i = 0; 613 | 614 | while (true) { 615 | var digit = (a[i] || 0) + 1; 616 | sum[i] = digit % BigIntegerSM_base; 617 | if (digit <= BigIntegerSM_base - 1) { 618 | break; 619 | } 620 | ++i; 621 | } 622 | 623 | return new BigIntegerSM(sum, sign, CONSTRUCT); 624 | } 625 | 626 | function subtractOne(n, sign) { 627 | var a = n._d; 628 | var sum = a.slice(); 629 | var borrow = true; 630 | var i = 0; 631 | 632 | while (true) { 633 | var digit = (a[i] || 0) - 1; 634 | if (digit < 0) { 635 | sum[i] = digit + BigIntegerSM_base; 636 | } 637 | else { 638 | sum[i] = digit; 639 | break; 640 | } 641 | ++i; 642 | } 643 | 644 | return new BigIntegerSM(sum, sign, CONSTRUCT); 645 | } 646 | 647 | /* 648 | Function: next 649 | Get the next (add one). 650 | 651 | Returns: 652 | 653 | *this* + 1. 654 | 655 | See Also: 656 | 657 | , 658 | */ 659 | BigIntegerSM.prototype.next = function() { 660 | switch (this._s) { 661 | case 0: 662 | return ONE; 663 | case -1: 664 | return subtractOne(this, -1); 665 | // case 1: 666 | default: 667 | return addOne(this, 1); 668 | } 669 | }; 670 | 671 | /* 672 | Function: prev 673 | Get the previous (subtract one). 674 | 675 | Returns: 676 | 677 | *this* - 1. 678 | 679 | See Also: 680 | 681 | , 682 | */ 683 | BigIntegerSM.prototype.prev = function() { 684 | switch (this._s) { 685 | case 0: 686 | return M_ONE; 687 | case -1: 688 | return addOne(this, -1); 689 | // case 1: 690 | default: 691 | return subtractOne(this, 1); 692 | } 693 | }; 694 | })(); 695 | 696 | /* 697 | Function: compareAbs 698 | Compare the absolute value of two . 699 | 700 | Calling is faster than calling twice, then . 701 | 702 | Parameters: 703 | 704 | n - The number to compare to *this*. Will be converted to a . 705 | 706 | Returns: 707 | 708 | -1, 0, or +1 if *|this|* is less than, equal to, or greater than *|n|*. 709 | 710 | See Also: 711 | 712 | , 713 | */ 714 | BigIntegerSM.prototype.compareAbs = function(n) { 715 | if (this === n) { 716 | return 0; 717 | } 718 | 719 | if (!(n instanceof BigIntegerSM)) { 720 | if (!isFinite(n)) { 721 | return(isNaN(n) ? n : -1); 722 | } 723 | n = BigIntegerSM(n); 724 | } 725 | 726 | if (this._s === 0) { 727 | return (n._s !== 0) ? -1 : 0; 728 | } 729 | if (n._s === 0) { 730 | return 1; 731 | } 732 | 733 | var l = this._d.length; 734 | var nl = n._d.length; 735 | if (l < nl) { 736 | return -1; 737 | } 738 | else if (l > nl) { 739 | return 1; 740 | } 741 | 742 | var a = this._d; 743 | var b = n._d; 744 | for (var i = l-1; i >= 0; i--) { 745 | if (a[i] !== b[i]) { 746 | return a[i] < b[i] ? -1 : 1; 747 | } 748 | } 749 | 750 | return 0; 751 | }; 752 | 753 | /* 754 | Function: compare 755 | Compare two . 756 | 757 | Parameters: 758 | 759 | n - The number to compare to *this*. Will be converted to a . 760 | 761 | Returns: 762 | 763 | -1, 0, or +1 if *this* is less than, equal to, or greater than *n*. 764 | 765 | See Also: 766 | 767 | , , , 768 | */ 769 | BigIntegerSM.prototype.compare = function(n) { 770 | if (this === n) { 771 | return 0; 772 | } 773 | 774 | n = BigIntegerSM(n); 775 | 776 | if (this._s === 0) { 777 | return -n._s; 778 | } 779 | 780 | if (this._s === n._s) { // both positive or both negative 781 | var cmp = this.compareAbs(n); 782 | return cmp * this._s; 783 | } 784 | else { 785 | return this._s; 786 | } 787 | }; 788 | 789 | /* 790 | Function: isUnit 791 | Return true iff *this* is either 1 or -1. 792 | 793 | Returns: 794 | 795 | true if *this* compares equal to or . 796 | 797 | See Also: 798 | 799 | , , , , , 800 | , 801 | */ 802 | BigIntegerSM.prototype.isUnit = function() { 803 | return this === ONE || 804 | this === M_ONE || 805 | (this._d.length === 1 && this._d[0] === 1); 806 | }; 807 | 808 | /* 809 | Function: multiply 810 | Multiply two . 811 | 812 | Parameters: 813 | 814 | n - The number to multiply *this* by. Will be converted to a 815 | . 816 | 817 | Returns: 818 | 819 | The numbers multiplied together. 820 | 821 | See Also: 822 | 823 | , , , 824 | */ 825 | BigIntegerSM.prototype.multiply = function(n) { 826 | // TODO: Consider adding Karatsuba multiplication for large numbers 827 | if (this._s === 0) { 828 | return ZERO; 829 | } 830 | 831 | n = BigIntegerSM(n); 832 | if (n._s === 0) { 833 | return ZERO; 834 | } 835 | if (this.isUnit()) { 836 | if (this._s < 0) { 837 | return n.negate(); 838 | } 839 | return n; 840 | } 841 | if (n.isUnit()) { 842 | if (n._s < 0) { 843 | return this.negate(); 844 | } 845 | return this; 846 | } 847 | if (this === n) { 848 | return this.square(); 849 | } 850 | 851 | var r = (this._d.length >= n._d.length); 852 | var a = (r ? this : n)._d; // a will be longer than b 853 | var b = (r ? n : this)._d; 854 | var al = a.length; 855 | var bl = b.length; 856 | 857 | var pl = al + bl; 858 | var partial = new Array(pl); 859 | var i; 860 | for (i = 0; i < pl; i++) { 861 | partial[i] = 0; 862 | } 863 | 864 | for (i = 0; i < bl; i++) { 865 | var carry = 0; 866 | var bi = b[i]; 867 | var jlimit = al + i; 868 | var digit; 869 | for (var j = i; j < jlimit; j++) { 870 | digit = partial[j] + bi * a[j - i] + carry; 871 | carry = (digit / BigIntegerSM_base) | 0; 872 | partial[j] = (digit % BigIntegerSM_base) | 0; 873 | } 874 | if (carry) { 875 | digit = partial[j] + carry; 876 | carry = (digit / BigIntegerSM_base) | 0; 877 | partial[j] = digit % BigIntegerSM_base; 878 | } 879 | } 880 | return new BigIntegerSM(partial, this._s * n._s, CONSTRUCT); 881 | }; 882 | 883 | // Multiply a BigIntegerSM by a single-digit native number 884 | // Assumes that this and n are >= 0 885 | // This is not really intended to be used outside the library itself 886 | BigIntegerSM.prototype.multiplySingleDigit = function(n) { 887 | if (n === 0 || this._s === 0) { 888 | return ZERO; 889 | } 890 | if (n === 1) { 891 | return this; 892 | } 893 | 894 | var digit; 895 | if (this._d.length === 1) { 896 | digit = this._d[0] * n; 897 | if (digit >= BigIntegerSM_base) { 898 | return new BigIntegerSM([(digit % BigIntegerSM_base)|0, 899 | (digit / BigIntegerSM_base)|0], 1, CONSTRUCT); 900 | } 901 | return new BigIntegerSM([digit], 1, CONSTRUCT); 902 | } 903 | 904 | if (n === 2) { 905 | return this.add(this); 906 | } 907 | if (this.isUnit()) { 908 | return new BigIntegerSM([n], 1, CONSTRUCT); 909 | } 910 | 911 | var a = this._d; 912 | var al = a.length; 913 | 914 | var pl = al + 1; 915 | var partial = new Array(pl); 916 | for (var i = 0; i < pl; i++) { 917 | partial[i] = 0; 918 | } 919 | 920 | var carry = 0; 921 | for (var j = 0; j < al; j++) { 922 | digit = n * a[j] + carry; 923 | carry = (digit / BigIntegerSM_base) | 0; 924 | partial[j] = (digit % BigIntegerSM_base) | 0; 925 | } 926 | if (carry) { 927 | partial[j] = carry; 928 | } 929 | 930 | return new BigIntegerSM(partial, 1, CONSTRUCT); 931 | }; 932 | 933 | /* 934 | Function: square 935 | Multiply a by itself. 936 | 937 | This is slightly faster than regular multiplication, since it removes the 938 | duplicated multiplcations. 939 | 940 | Returns: 941 | 942 | > this.multiply(this) 943 | 944 | See Also: 945 | 946 | */ 947 | BigIntegerSM.prototype.square = function() { 948 | // Normally, squaring a 10-digit number would take 100 multiplications. 949 | // Of these 10 are unique diagonals, of the remaining 90 (100-10), 45 are repeated. 950 | // This procedure saves (N*(N-1))/2 multiplications, (e.g., 45 of 100 multiplies). 951 | // Based on code by Gary Darby, Intellitech Systems Inc., www.DelphiForFun.org 952 | 953 | if (this._s === 0) { 954 | return ZERO; 955 | } 956 | if (this.isUnit()) { 957 | return ONE; 958 | } 959 | 960 | var digits = this._d; 961 | var length = digits.length; 962 | var imult1 = new Array(length + length + 1); 963 | var product, carry, k; 964 | var i; 965 | 966 | // Calculate diagonal 967 | for (i = 0; i < length; i++) { 968 | k = i * 2; 969 | product = digits[i] * digits[i]; 970 | carry = (product / BigIntegerSM_base) | 0; 971 | imult1[k] = product % BigIntegerSM_base; 972 | imult1[k + 1] = carry; 973 | } 974 | 975 | // Calculate repeating part 976 | for (i = 0; i < length; i++) { 977 | carry = 0; 978 | k = i * 2 + 1; 979 | for (var j = i + 1; j < length; j++, k++) { 980 | product = digits[j] * digits[i] * 2 + imult1[k] + carry; 981 | carry = (product / BigIntegerSM_base) | 0; 982 | imult1[k] = product % BigIntegerSM_base; 983 | } 984 | k = length + i; 985 | var digit = carry + imult1[k]; 986 | carry = (digit / BigIntegerSM_base) | 0; 987 | imult1[k] = digit % BigIntegerSM_base; 988 | imult1[k + 1] += carry; 989 | } 990 | 991 | return new BigIntegerSM(imult1, 1, CONSTRUCT); 992 | }; 993 | 994 | /* 995 | Function: quotient 996 | Divide two and truncate towards zero. 997 | 998 | throws an exception if *n* is zero. 999 | 1000 | Parameters: 1001 | 1002 | n - The number to divide *this* by. Will be converted to a . 1003 | 1004 | Returns: 1005 | 1006 | The *this* / *n*, truncated to an integer. 1007 | 1008 | See Also: 1009 | 1010 | , , , , 1011 | */ 1012 | BigIntegerSM.prototype.quotient = function(n) { 1013 | return this.divRem(n)[0]; 1014 | }; 1015 | 1016 | /* 1017 | Function: divide 1018 | Deprecated synonym for . 1019 | */ 1020 | BigIntegerSM.prototype.divide = BigIntegerSM.prototype.quotient; 1021 | 1022 | /* 1023 | Function: remainder 1024 | Calculate the remainder of two . 1025 | 1026 | throws an exception if *n* is zero. 1027 | 1028 | Parameters: 1029 | 1030 | n - The remainder after *this* is divided *this* by *n*. Will be 1031 | converted to a . 1032 | 1033 | Returns: 1034 | 1035 | *this* % *n*. 1036 | 1037 | See Also: 1038 | 1039 | , 1040 | */ 1041 | BigIntegerSM.prototype.remainder = function(n) { 1042 | return this.divRem(n)[1]; 1043 | }; 1044 | 1045 | /* 1046 | Function: divRem 1047 | Calculate the integer quotient and remainder of two . 1048 | 1049 | throws an exception if *n* is zero. 1050 | 1051 | Parameters: 1052 | 1053 | n - The number to divide *this* by. Will be converted to a . 1054 | 1055 | Returns: 1056 | 1057 | A two-element array containing the quotient and the remainder. 1058 | 1059 | > a.divRem(b) 1060 | 1061 | is exactly equivalent to 1062 | 1063 | > [a.quotient(b), a.remainder(b)] 1064 | 1065 | except it is faster, because they are calculated at the same time. 1066 | 1067 | See Also: 1068 | 1069 | , 1070 | */ 1071 | BigIntegerSM.prototype.divRem = function(n) { 1072 | n = BigIntegerSM(n); 1073 | if (n._s === 0) { 1074 | throw new Error("Divide by zero"); 1075 | } 1076 | if (this._s === 0) { 1077 | return [ZERO, ZERO]; 1078 | } 1079 | if (n._d.length === 1) { 1080 | return this.divRemSmall(n._s * n._d[0]); 1081 | } 1082 | 1083 | // Test for easy cases -- |n1| <= |n2| 1084 | switch (this.compareAbs(n)) { 1085 | case 0: // n1 == n2 1086 | return [this._s === n._s ? ONE : M_ONE, ZERO]; 1087 | case -1: // |n1| < |n2| 1088 | return [ZERO, this]; 1089 | } 1090 | 1091 | var sign = this._s * n._s; 1092 | var a = n.abs(); 1093 | var b_digits = this._d; 1094 | var b_index = b_digits.length; 1095 | var digits = n._d.length; 1096 | var quot = []; 1097 | var guess; 1098 | 1099 | var part = new BigIntegerSM([], 0, CONSTRUCT); 1100 | part._s = 1; 1101 | 1102 | while (b_index) { 1103 | part._d.unshift(b_digits[--b_index]); 1104 | 1105 | if (part.compareAbs(n) < 0) { 1106 | quot.push(0); 1107 | continue; 1108 | } 1109 | if (part._s === 0) { 1110 | guess = 0; 1111 | } 1112 | else { 1113 | var xlen = part._d.length, ylen = a._d.length; 1114 | var highx = part._d[xlen-1]*BigIntegerSM_base + part._d[xlen-2]; 1115 | var highy = a._d[ylen-1]*BigIntegerSM_base + a._d[ylen-2]; 1116 | if (part._d.length > a._d.length) { 1117 | // The length of part._d can either match a._d length, 1118 | // or exceed it by one. 1119 | highx = (highx+1)*BigIntegerSM_base; 1120 | } 1121 | guess = Math.ceil(highx/highy); 1122 | } 1123 | do { 1124 | var check = a.multiplySingleDigit(guess); 1125 | if (check.compareAbs(part) <= 0) { 1126 | break; 1127 | } 1128 | guess--; 1129 | } while (guess); 1130 | 1131 | quot.push(guess); 1132 | if (!guess) { 1133 | continue; 1134 | } 1135 | var diff = part.subtract(check); 1136 | part._d = diff._d.slice(); 1137 | if (part._d.length === 0) { 1138 | part._s = 0; 1139 | } 1140 | } 1141 | 1142 | return [new BigIntegerSM(quot.reverse(), sign, CONSTRUCT), 1143 | new BigIntegerSM(part._d, this._s, CONSTRUCT)]; 1144 | }; 1145 | 1146 | // Throws an exception if n is outside of (-BigIntegerSM.base, -1] or 1147 | // [1, BigIntegerSM.base). It's not necessary to call this, since the 1148 | // other division functions will call it if they are able to. 1149 | BigIntegerSM.prototype.divRemSmall = function(n) { 1150 | var r; 1151 | n = +n; 1152 | if (n === 0) { 1153 | throw new Error("Divide by zero"); 1154 | } 1155 | 1156 | var n_s = n < 0 ? -1 : 1; 1157 | var sign = this._s * n_s; 1158 | n = Math.abs(n); 1159 | 1160 | if (n < 1 || n >= BigIntegerSM_base) { 1161 | throw new Error("Argument out of range"); 1162 | } 1163 | 1164 | if (this._s === 0) { 1165 | return [ZERO, ZERO]; 1166 | } 1167 | 1168 | if (n === 1 || n === -1) { 1169 | return [(sign === 1) ? this.abs() : new BigIntegerSM(this._d, sign, CONSTRUCT), ZERO]; 1170 | } 1171 | 1172 | // 2 <= n < BigIntegerSM_base 1173 | 1174 | // divide a single digit by a single digit 1175 | if (this._d.length === 1) { 1176 | var q = new BigIntegerSM([(this._d[0] / n) | 0], 1, CONSTRUCT); 1177 | r = new BigIntegerSM([(this._d[0] % n) | 0], 1, CONSTRUCT); 1178 | if (sign < 0) { 1179 | q = q.negate(); 1180 | } 1181 | if (this._s < 0) { 1182 | r = r.negate(); 1183 | } 1184 | return [q, r]; 1185 | } 1186 | 1187 | var digits = this._d.slice(); 1188 | var quot = new Array(digits.length); 1189 | var part = 0; 1190 | var diff = 0; 1191 | var i = 0; 1192 | var guess; 1193 | 1194 | while (digits.length) { 1195 | part = part * BigIntegerSM_base + digits[digits.length - 1]; 1196 | if (part < n) { 1197 | quot[i++] = 0; 1198 | digits.pop(); 1199 | diff = BigIntegerSM_base * diff + part; 1200 | continue; 1201 | } 1202 | if (part === 0) { 1203 | guess = 0; 1204 | } 1205 | else { 1206 | guess = (part / n) | 0; 1207 | } 1208 | 1209 | var check = n * guess; 1210 | diff = part - check; 1211 | quot[i++] = guess; 1212 | if (!guess) { 1213 | digits.pop(); 1214 | continue; 1215 | } 1216 | 1217 | digits.pop(); 1218 | part = diff; 1219 | } 1220 | 1221 | r = new BigIntegerSM([diff], 1, CONSTRUCT); 1222 | if (this._s < 0) { 1223 | r = r.negate(); 1224 | } 1225 | return [new BigIntegerSM(quot.reverse(), sign, CONSTRUCT), r]; 1226 | }; 1227 | 1228 | /* 1229 | Function: isEven 1230 | Return true iff *this* is divisible by two. 1231 | 1232 | Note that is even. 1233 | 1234 | Returns: 1235 | 1236 | true if *this* is even, false otherwise. 1237 | 1238 | See Also: 1239 | 1240 | 1241 | */ 1242 | BigIntegerSM.prototype.isEven = function() { 1243 | var digits = this._d; 1244 | return this._s === 0 || digits.length === 0 || (digits[0] % 2) === 0; 1245 | }; 1246 | 1247 | /* 1248 | Function: isOdd 1249 | Return true iff *this* is not divisible by two. 1250 | 1251 | Returns: 1252 | 1253 | true if *this* is odd, false otherwise. 1254 | 1255 | See Also: 1256 | 1257 | 1258 | */ 1259 | BigIntegerSM.prototype.isOdd = function() { 1260 | return !this.isEven(); 1261 | }; 1262 | 1263 | /* 1264 | Function: sign 1265 | Get the sign of a . 1266 | 1267 | Returns: 1268 | 1269 | * -1 if *this* < 0 1270 | * 0 if *this* == 0 1271 | * +1 if *this* > 0 1272 | 1273 | See Also: 1274 | 1275 | , , , , 1276 | */ 1277 | BigIntegerSM.prototype.sign = function() { 1278 | return this._s; 1279 | }; 1280 | 1281 | /* 1282 | Function: isPositive 1283 | Return true iff *this* > 0. 1284 | 1285 | Returns: 1286 | 1287 | true if *this*.compare() == 1. 1288 | 1289 | See Also: 1290 | 1291 | , , , , , 1292 | */ 1293 | BigIntegerSM.prototype.isPositive = function() { 1294 | return this._s > 0; 1295 | }; 1296 | 1297 | /* 1298 | Function: isNegative 1299 | Return true iff *this* < 0. 1300 | 1301 | Returns: 1302 | 1303 | true if *this*.compare() == -1. 1304 | 1305 | See Also: 1306 | 1307 | , , , , , 1308 | */ 1309 | BigIntegerSM.prototype.isNegative = function() { 1310 | return this._s < 0; 1311 | }; 1312 | 1313 | /* 1314 | Function: isZero 1315 | Return true iff *this* == 0. 1316 | 1317 | Returns: 1318 | 1319 | true if *this*.compare() == 0. 1320 | 1321 | See Also: 1322 | 1323 | , , , , 1324 | */ 1325 | BigIntegerSM.prototype.isZero = function() { 1326 | return this._s === 0; 1327 | }; 1328 | 1329 | /* 1330 | Function: exp10 1331 | Multiply a by a power of 10. 1332 | 1333 | This is equivalent to, but faster than 1334 | 1335 | > if (n >= 0) { 1336 | > return this.multiply(BigIntegerSM("1e" + n)); 1337 | > } 1338 | > else { // n <= 0 1339 | > return this.quotient(BigIntegerSM("1e" + -n)); 1340 | > } 1341 | 1342 | Parameters: 1343 | 1344 | n - The power of 10 to multiply *this* by. *n* is converted to a 1345 | javascipt number and must be no greater than 1346 | (0x7FFFFFFF), or an exception will be thrown. 1347 | 1348 | Returns: 1349 | 1350 | *this* * (10 ** *n*), truncated to an integer if necessary. 1351 | 1352 | See Also: 1353 | 1354 | , 1355 | */ 1356 | BigIntegerSM.prototype.exp10 = function(n) { 1357 | n = +n; 1358 | if (n === 0) { 1359 | return this; 1360 | } 1361 | if (Math.abs(n) > Number(MAX_EXP)) { 1362 | throw new Error("exponent too large in BigIntegerSM.exp10"); 1363 | } 1364 | if (n > 0) { 1365 | var k = new BigIntegerSM(this._d.slice(), this._s, CONSTRUCT); 1366 | 1367 | for (; n >= BigIntegerSM_base_log10; n -= BigIntegerSM_base_log10) { 1368 | k._d.unshift(0); 1369 | } 1370 | if (n == 0) 1371 | return k; 1372 | k._s = 1; 1373 | k = k.multiplySingleDigit(Math.pow(10, n)); 1374 | return (this._s < 0 ? k.negate() : k); 1375 | } else if (-n >= this._d.length*BigIntegerSM_base_log10) { 1376 | return ZERO; 1377 | } else { 1378 | var k = new BigIntegerSM(this._d.slice(), this._s, CONSTRUCT); 1379 | 1380 | for (n = -n; n >= BigIntegerSM_base_log10; n -= BigIntegerSM_base_log10) { 1381 | k._d.shift(); 1382 | } 1383 | return (n == 0) ? k : k.divRemSmall(Math.pow(10, n))[0]; 1384 | } 1385 | }; 1386 | 1387 | /* 1388 | Function: pow 1389 | Raise a to a power. 1390 | 1391 | In this implementation, 0**0 is 1. 1392 | 1393 | Parameters: 1394 | 1395 | n - The exponent to raise *this* by. *n* must be no greater than 1396 | (0x7FFFFFFF), or an exception will be thrown. 1397 | 1398 | Returns: 1399 | 1400 | *this* raised to the *nth* power. 1401 | 1402 | See Also: 1403 | 1404 | 1405 | */ 1406 | BigIntegerSM.prototype.pow = function(n) { 1407 | if (this.isUnit()) { 1408 | if (this._s > 0) { 1409 | return this; 1410 | } 1411 | else { 1412 | return BigIntegerSM(n).isOdd() ? this : this.negate(); 1413 | } 1414 | } 1415 | 1416 | n = BigIntegerSM(n); 1417 | if (n._s === 0) { 1418 | return ONE; 1419 | } 1420 | else if (n._s < 0) { 1421 | if (this._s === 0) { 1422 | throw new Error("Divide by zero"); 1423 | } 1424 | else { 1425 | return ZERO; 1426 | } 1427 | } 1428 | if (this._s === 0) { 1429 | return ZERO; 1430 | } 1431 | if (n.isUnit()) { 1432 | return this; 1433 | } 1434 | 1435 | if (n.compareAbs(MAX_EXP) > 0) { 1436 | throw new Error("exponent too large in BigIntegerSM.pow"); 1437 | } 1438 | var x = this; 1439 | var aux = ONE; 1440 | var two = BigIntegerSM.small[2]; 1441 | 1442 | while (n.isPositive()) { 1443 | if (n.isOdd()) { 1444 | aux = aux.multiply(x); 1445 | if (n.isUnit()) { 1446 | return aux; 1447 | } 1448 | } 1449 | x = x.square(); 1450 | n = n.quotient(two); 1451 | } 1452 | 1453 | return aux; 1454 | }; 1455 | 1456 | /* 1457 | Function: modPow 1458 | Raise a to a power (mod m). 1459 | 1460 | Because it is reduced by a modulus, is not limited by 1461 | like . 1462 | 1463 | Parameters: 1464 | 1465 | exponent - The exponent to raise *this* by. Must be positive. 1466 | modulus - The modulus. 1467 | 1468 | Returns: 1469 | 1470 | *this* ^ *exponent* (mod *modulus*). 1471 | 1472 | See Also: 1473 | 1474 | , 1475 | */ 1476 | BigIntegerSM.prototype.modPow = function(exponent, modulus) { 1477 | var result = ONE; 1478 | var base = this; 1479 | 1480 | while (exponent.isPositive()) { 1481 | if (exponent.isOdd()) { 1482 | result = result.multiply(base).remainder(modulus); 1483 | } 1484 | 1485 | exponent = exponent.quotient(BigIntegerSM.small[2]); 1486 | if (exponent.isPositive()) { 1487 | base = base.square().remainder(modulus); 1488 | } 1489 | } 1490 | 1491 | return result; 1492 | }; 1493 | 1494 | /* 1495 | Function: log 1496 | Get the natural logarithm of a as a native JavaScript number. 1497 | 1498 | This is equivalent to 1499 | 1500 | > Math.log(this.toJSValue()) 1501 | 1502 | but handles values outside of the native number range. 1503 | 1504 | Returns: 1505 | 1506 | log( *this* ) 1507 | 1508 | See Also: 1509 | 1510 | 1511 | */ 1512 | BigIntegerSM.prototype.log = function() { 1513 | switch (this._s) { 1514 | case 0: return -Infinity; 1515 | case -1: return NaN; 1516 | default: // Fall through. 1517 | } 1518 | 1519 | var l = this._d.length; 1520 | 1521 | if (l*BigIntegerSM_base_log10 < 30) { 1522 | return Math.log(this.valueOf()); 1523 | } 1524 | 1525 | var N = Math.ceil(30/BigIntegerSM_base_log10); 1526 | var firstNdigits = this._d.slice(l - N); 1527 | return Math.log((new BigIntegerSM(firstNdigits, 1, CONSTRUCT)).valueOf()) + (l - N) * Math.log(BigIntegerSM_base); 1528 | }; 1529 | 1530 | /* 1531 | Function: valueOf 1532 | Convert a to a native JavaScript integer. 1533 | 1534 | This is called automatically by JavaScipt to convert a to a 1535 | native value. 1536 | 1537 | Returns: 1538 | 1539 | > parseInt(this.toString(), 10) 1540 | 1541 | See Also: 1542 | 1543 | , 1544 | */ 1545 | BigIntegerSM.prototype.valueOf = function() { 1546 | return parseInt(this.toString(), 10); 1547 | }; 1548 | 1549 | /* 1550 | Function: toJSValue 1551 | Convert a to a native JavaScript integer. 1552 | 1553 | This is the same as valueOf, but more explicitly named. 1554 | 1555 | Returns: 1556 | 1557 | > parseInt(this.toString(), 10) 1558 | 1559 | See Also: 1560 | 1561 | , 1562 | */ 1563 | BigIntegerSM.prototype.toJSValue = function() { 1564 | return parseInt(this.toString(), 10); 1565 | }; 1566 | 1567 | var MAX_EXP = BigIntegerSM(0x7FFFFFFF); 1568 | // Constant: MAX_EXP 1569 | // The largest exponent allowed in and (0x7FFFFFFF or 2147483647). 1570 | BigIntegerSM.MAX_EXP = MAX_EXP; 1571 | 1572 | (function() { 1573 | function makeUnary(fn) { 1574 | return function(a) { 1575 | return fn.call(BigIntegerSM(a)); 1576 | }; 1577 | } 1578 | 1579 | function makeBinary(fn) { 1580 | return function(a, b) { 1581 | return fn.call(BigIntegerSM(a), BigIntegerSM(b)); 1582 | }; 1583 | } 1584 | 1585 | function makeTrinary(fn) { 1586 | return function(a, b, c) { 1587 | return fn.call(BigIntegerSM(a), BigIntegerSM(b), BigIntegerSM(c)); 1588 | }; 1589 | } 1590 | 1591 | (function() { 1592 | var i, fn; 1593 | var unary = "toJSValue,isEven,isOdd,sign,isZero,isNegative,abs,isUnit,square,negate,isPositive,toString,next,prev,log".split(","); 1594 | var binary = "compare,remainder,divRem,subtract,add,quotient,divide,multiply,pow,compareAbs".split(","); 1595 | var trinary = ["modPow"]; 1596 | 1597 | for (i = 0; i < unary.length; i++) { 1598 | fn = unary[i]; 1599 | BigIntegerSM[fn] = makeUnary(BigIntegerSM.prototype[fn]); 1600 | } 1601 | 1602 | for (i = 0; i < binary.length; i++) { 1603 | fn = binary[i]; 1604 | BigIntegerSM[fn] = makeBinary(BigIntegerSM.prototype[fn]); 1605 | } 1606 | 1607 | for (i = 0; i < trinary.length; i++) { 1608 | fn = trinary[i]; 1609 | BigIntegerSM[fn] = makeTrinary(BigIntegerSM.prototype[fn]); 1610 | } 1611 | 1612 | BigIntegerSM.exp10 = function(x, n) { 1613 | return BigIntegerSM(x).exp10(n); 1614 | }; 1615 | })(); 1616 | })(); 1617 | 1618 | exports.BigIntegerSM = BigIntegerSM; 1619 | })(typeof exports !== 'undefined' ? exports : this); 1620 | -------------------------------------------------------------------------------- /js/bitcore/.bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bitcore", 3 | "main": "./bitcore.min.js", 4 | "version": "0.9.3", 5 | "homepage": "http://bitcore.io", 6 | "authors": [ 7 | "BitPay, Inc." 8 | ], 9 | "description": "A pure, powerful core for your bitcoin project.", 10 | "moduleType": [ 11 | "globals" 12 | ], 13 | "keywords": [ 14 | "bitcoin", 15 | "bitcore", 16 | "btc", 17 | "satoshi" 18 | ], 19 | "license": "MIT", 20 | "ignore": [ 21 | "**/.*", 22 | "CONTRIBUTING.md", 23 | "gulpfile.js", 24 | "lib", 25 | "index.js", 26 | "karma.conf.js", 27 | "npm-shrinkwrap.json", 28 | "test" 29 | ], 30 | "_release": "0.9.3", 31 | "_resolution": { 32 | "type": "version", 33 | "tag": "v0.9.3", 34 | "commit": "d92db9032298d1c90f5228cfa5a3fd66c473d1c2" 35 | }, 36 | "_source": "git://github.com/bitpay/bitcore.git", 37 | "_target": "~0.9.3", 38 | "_originalSource": "bitcore", 39 | "_direct": true 40 | } -------------------------------------------------------------------------------- /js/bitcore/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2015 BitPay, Inc. 2 | 3 | Parts of this software are based on fullnode 4 | Copyright (c) 2014 Ryan X. Charles 5 | Copyright (c) 2014 reddit, Inc. 6 | 7 | Parts of this software are based on BitcoinJS 8 | Copyright (c) 2011 Stefan Thomas 9 | 10 | Parts of this software are based on BitcoinJ 11 | Copyright (c) 2011 Google Inc. 12 | 13 | Permission is hereby granted, free of charge, to any person obtaining a copy 14 | of this software and associated documentation files (the "Software"), to deal 15 | in the Software without restriction, including without limitation the rights 16 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | copies of the Software, and to permit persons to whom the Software is 18 | furnished to do so, subject to the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be included in 21 | all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | THE SOFTWARE. 30 | -------------------------------------------------------------------------------- /js/bitcore/README.md: -------------------------------------------------------------------------------- 1 | Bitcore 2 | ======= 3 | 4 | [![NPM Package](https://img.shields.io/npm/v/bitcore.svg?style=flat-square)](https://www.npmjs.org/package/bitcore) 5 | [![Build Status](https://img.shields.io/travis/bitpay/bitcore.svg?branch=master&style=flat-square)](https://travis-ci.org/bitpay/bitcore) 6 | [![Coverage Status](https://img.shields.io/coveralls/bitpay/bitcore.svg?style=flat-square)](https://coveralls.io/r/bitpay/bitcore) 7 | 8 | [![Sauce Test Status](https://saucelabs.com/browser-matrix/maraoz.svg)](https://saucelabs.com/u/maraoz) 9 | 10 | A pure and powerful JavaScript Bitcoin library. 11 | 12 | ## Principles 13 | 14 | Bitcoin is a powerful new peer-to-peer platform for the next generation of financial technology. The decentralized nature of the Bitcoin network allows for highly resilient bitcoin infrastructure, and the developer community needs reliable, open-source tools to implement bitcoin apps and services. 15 | 16 | ## Get Started 17 | 18 | ``` 19 | npm install bitcore 20 | ``` 21 | 22 | Using it in Node.js: 23 | 24 | ```javascript 25 | var bitcore = require('bitcore'); 26 | 27 | assert(bitcore.Address.isValid('126vMmY1fyznpZiFTTnty3cm1Rw8wuheev')); 28 | var simpleTx = new bitcore.Transaction(); 29 | var simpleTx.from(unspent).to(address, amount); 30 | simpleTx.sign(privateKey); 31 | ``` 32 | 33 | ## Documentation 34 | 35 | The complete docs are hosted here: [bitcore documentation](http://bitcore.io/guide/). There's also a [bitcore API reference](http://bitcore.io/api/) available generated from the JSDocs of the project, where you'll find low-level details on each bitcore utility. 36 | 37 | [Read the Developer Guide](http://bitcore.io/guide/) 38 | 39 | [Read the API Reference](http://bitcore.io/api/) 40 | 41 | To get community assistance and ask for help with implementation questions, please use our [community forums](http://bitpaylabs.com/c/bitcore). 42 | 43 | ## Modules 44 | This module provides bitcoin's core features. Other features and protocol extensions are built into separate modules. Here is a list of official bitcore modules: 45 | 46 | Module | Version | Building | Coverage 47 | -------|---------|----------|--------- 48 | [bitcore-payment-protocol](http://github.com/bitpay/bitcore-payment-protocol) | [![NPM Package](https://img.shields.io/npm/v/bitcore-payment-protocol.svg?style=flat-square)](https://www.npmjs.org/package/bitcore-payment-protocol) | [![Build Status](https://img.shields.io/travis/bitpay/bitcore-payment-protocol.svg?branch=master&style=flat-square)](https://travis-ci.org/bitpay/bitcore-payment-protocol) | [![Coverage Status](https://img.shields.io/coveralls/bitpay/bitcore-payment-protocol.svg?style=flat-square)](https://coveralls.io/r/bitpay/bitcore-payment-protocol) 49 | [bitcore-p2p](http://github.com/bitpay/bitcore-p2p) | [![NPM Package](https://img.shields.io/npm/v/bitcore-p2p.svg?style=flat-square)](https://www.npmjs.org/package/bitcore-p2p) | [![Build Status](https://img.shields.io/travis/bitpay/bitcore-p2p.svg?branch=master&style=flat-square)](https://travis-ci.org/bitpay/bitcore-p2p) | [![Coverage Status](https://img.shields.io/coveralls/bitpay/bitcore-p2p.svg?style=flat-square)](https://coveralls.io/r/bitpay/bitcore-p2p?branch=master) 50 | [bitcore-mnemonic](http://github.com/bitpay/bitcore-mnemonic) | [![NPM Package](https://img.shields.io/npm/v/bitcore-mnemonic.svg?style=flat-square)](https://www.npmjs.org/package/bitcore-mnemonic) | [![Build Status](https://img.shields.io/travis/bitpay/bitcore-mnemonic.svg?branch=master&style=flat-square)](https://travis-ci.org/bitpay/bitcore-mnemonic) | [![Coverage Status](https://img.shields.io/coveralls/bitpay/bitcore-mnemonic.svg?style=flat-square)](https://coveralls.io/r/bitpay/bitcore-mnemonic) 51 | [bitcore-ecies](http://github.com/bitpay/bitcore-ecies) | [![NPM Package](https://img.shields.io/npm/v/bitcore-ecies.svg?style=flat-square)](https://www.npmjs.org/package/bitcore-ecies) | [![Build Status](https://img.shields.io/travis/bitpay/bitcore-ecies.svg?branch=master&style=flat-square)](https://travis-ci.org/bitpay/bitcore-ecies) | [![Coverage Status](https://img.shields.io/coveralls/bitpay/bitcore-ecies.svg?style=flat-square)](https://coveralls.io/r/bitpay/bitcore-ecies) 52 | [bitcore-channel](http://github.com/bitpay/bitcore-channel) | [![NPM Package](https://img.shields.io/npm/v/bitcore-channel.svg?style=flat-square)](https://www.npmjs.org/package/bitcore-channel) | [![Build Status](https://img.shields.io/travis/bitpay/bitcore-channel.svg?branch=master&style=flat-square)](https://travis-ci.org/bitpay/bitcore-channel) | [![Coverage Status](https://img.shields.io/coveralls/bitpay/bitcore-channel.svg?style=flat-square)](https://coveralls.io/r/bitpay/bitcore-channel) 53 | [bitcore-explorers](http://github.com/bitpay/bitcore-explorers) | [![NPM Package](https://img.shields.io/npm/v/bitcore-explorers.svg?style=flat-square)](https://www.npmjs.org/package/bitcore-explorers) | [![Build Status](https://img.shields.io/travis/bitpay/bitcore-explorers.svg?branch=master&style=flat-square)](https://travis-ci.org/bitpay/bitcore-explorers) | [![Coverage Status](https://img.shields.io/coveralls/bitpay/bitcore-explorers.svg?style=flat-square)](https://coveralls.io/r/bitpay/bitcore-explorers) 54 | 55 | ## Security 56 | 57 | We're using Bitcore in production, as are [many others](http://bitcore.io#projects), but please use common sense when doing anything related to finances! We take no responsibility for your implementation decisions. 58 | 59 | If you find a security issue, please email security@bitpay.com. 60 | 61 | ## Contributing 62 | 63 | Please send pull requests for bug fixes, code optimization, and ideas for improvement. For more information on how to contribute, please refer to our [CONTRIBUTING](https://github.com/bitpay/bitcore/blob/master/CONTRIBUTING.md) file. 64 | 65 | ## Building the Browser Bundle 66 | 67 | To build bitcore full bundle for the browser: 68 | 69 | ```sh 70 | gulp browser 71 | ``` 72 | 73 | This will generate files named `browser/bitcore.js` and `browser/bitcore.min.js`. 74 | 75 | ## Tests 76 | 77 | Run all the tests: 78 | 79 | ```sh 80 | gulp test 81 | ``` 82 | 83 | Run the NodeJS tests with mocha: 84 | 85 | ```sh 86 | gulp test:node 87 | ``` 88 | 89 | Run the browser tests with karma: 90 | 91 | ```sh 92 | gulp test:browser 93 | ``` 94 | 95 | Create a test coverage report (you can open `coverage/lcov-report/index.html` to visualize it): 96 | 97 | ```sh 98 | gulp coverage 99 | ``` 100 | 101 | ## License 102 | 103 | Code released under [the MIT license](https://github.com/bitpay/bitcore/blob/master/LICENSE). 104 | 105 | Copyright 2013-2015 BitPay, Inc. Bitcore is a trademark maintained by BitPay, Inc. 106 | -------------------------------------------------------------------------------- /js/bitcore/bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bitcore", 3 | "main": "./bitcore.min.js", 4 | "version": "0.9.3", 5 | "homepage": "http://bitcore.io", 6 | "authors": [ 7 | "BitPay, Inc." 8 | ], 9 | "description": "A pure, powerful core for your bitcoin project.", 10 | "moduleType": [ 11 | "globals" 12 | ], 13 | "keywords": [ 14 | "bitcoin", 15 | "bitcore", 16 | "btc", 17 | "satoshi" 18 | ], 19 | "license": "MIT", 20 | "ignore": [ 21 | "**/.*", 22 | "CONTRIBUTING.md", 23 | "gulpfile.js", 24 | "lib", 25 | "index.js", 26 | "karma.conf.js", 27 | "npm-shrinkwrap.json", 28 | "test" 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /js/bitcore/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bitcore", 3 | "version": "0.9.3", 4 | "description": "A pure and powerful JavaScript Bitcoin library.", 5 | "author": "BitPay ", 6 | "main": "index.js", 7 | "scripts": { 8 | "lint": "gulp lint", 9 | "test": "gulp test", 10 | "coverage": "gulp coverage", 11 | "build": "gulp" 12 | }, 13 | "contributors": [ 14 | { 15 | "name": "Daniel Cousens", 16 | "email": "bitcoin@dcousens.com" 17 | }, 18 | { 19 | "name": "Esteban Ordano", 20 | "email": "eordano@gmail.com" 21 | }, 22 | { 23 | "name": "Gordon Hall", 24 | "email": "gordon@bitpay.com" 25 | }, 26 | { 27 | "name": "Jeff Garzik", 28 | "email": "jgarzik@bitpay.com" 29 | }, 30 | { 31 | "name": "Kyle Drake", 32 | "email": "kyle@kyledrake.net" 33 | }, 34 | { 35 | "name": "Manuel Araoz", 36 | "email": "manuelaraoz@gmail.com" 37 | }, 38 | { 39 | "name": "Matias Alejo Garcia", 40 | "email": "ematiu@gmail.com" 41 | }, 42 | { 43 | "name": "Ryan X. Charles", 44 | "email": "ryanxcharles@gmail.com" 45 | }, 46 | { 47 | "name": "Stefan Thomas", 48 | "email": "moon@justmoon.net" 49 | }, 50 | { 51 | "name": "Stephen Pair", 52 | "email": "stephen@bitpay.com" 53 | }, 54 | { 55 | "name": "Wei Lu", 56 | "email": "luwei.here@gmail.com" 57 | } 58 | ], 59 | "keywords": [ 60 | "bitcoin", 61 | "bip32", 62 | "bip37", 63 | "bip70", 64 | "merge", 65 | "multisig" 66 | ], 67 | "repository": { 68 | "type": "git", 69 | "url": "https://github.com/bitpay/bitcore.git" 70 | }, 71 | "browser": { 72 | "request": "browser-request" 73 | }, 74 | "dependencies": { 75 | "bn.js": "=0.16.1", 76 | "bs58": "=2.0.0", 77 | "elliptic": "=0.16.0", 78 | "hash.js": "=0.3.2", 79 | "inherits": "=2.0.1", 80 | "lodash": "=2.4.1", 81 | "sha512": "=0.0.1" 82 | }, 83 | "devDependencies": { 84 | "bitcore-build": "git://github.com/bitpay/bitcore-build.git", 85 | "brfs": "^1.2.0", 86 | "chai": "^1.10.0", 87 | "gulp": "^3.8.10" 88 | }, 89 | "license": "MIT" 90 | } 91 | -------------------------------------------------------------------------------- /js/hex2dec-cs.js: -------------------------------------------------------------------------------- 1 | /** 2 | * A function for converting hex <-> dec w/o loss of precision. 3 | * 4 | * The problem is that parseInt("0x12345...") isn't precise enough to convert 5 | * 64-bit integers correctly. 6 | * 7 | * Internally, this uses arrays to encode decimal digits starting with the least 8 | * significant: 9 | * 8 = [8] 10 | * 16 = [6, 1] 11 | * 1024 = [4, 2, 0, 1] 12 | */ 13 | 14 | // Adds two arrays for the given base (10 or 16), returning the result. 15 | // This turns out to be the only "primitive" operation we need. 16 | function add(x, y, base) { 17 | var z = []; 18 | var n = Math.max(x.length, y.length); 19 | var carry = 0; 20 | var i = 0; 21 | while (i < n || carry) { 22 | var xi = i < x.length ? x[i] : 0; 23 | var yi = i < y.length ? y[i] : 0; 24 | var zi = carry + xi + yi; 25 | z.push(zi % base); 26 | carry = Math.floor(zi / base); 27 | i++; 28 | } 29 | return z; 30 | } 31 | 32 | // Returns a*x, where x is an array of decimal digits and a is an ordinary 33 | // JavaScript number. base is the number base of the array x. 34 | function multiplyByNumber(num, x, base) { 35 | if (num < 0) return null; 36 | if (num == 0) return []; 37 | 38 | var result = []; 39 | var power = x; 40 | while (true) { 41 | if (num & 1) { 42 | result = add(result, power, base); 43 | } 44 | num = num >> 1; 45 | if (num === 0) break; 46 | power = add(power, power, base); 47 | } 48 | 49 | return result; 50 | } 51 | 52 | function parseToDigitsArray(str, base) { 53 | var digits = str.split(''); 54 | var ary = []; 55 | for (var i = digits.length - 1; i >= 0; i--) { 56 | var n = parseInt(digits[i], base); 57 | if (isNaN(n)) return null; 58 | ary.push(n); 59 | } 60 | return ary; 61 | } 62 | 63 | function convertBase(str, fromBase, toBase) { 64 | var digits = parseToDigitsArray(str, fromBase); 65 | if (digits === null) return null; 66 | 67 | var outArray = []; 68 | var power = [1]; 69 | for (var i = 0; i < digits.length; i++) { 70 | // invariant: at this point, fromBase^i = power 71 | if (digits[i]) { 72 | outArray = add(outArray, multiplyByNumber(digits[i], power, toBase), toBase); 73 | } 74 | power = multiplyByNumber(fromBase, power, toBase); 75 | } 76 | 77 | var out = ''; 78 | for (var i = outArray.length - 1; i >= 0; i--) { 79 | out += outArray[i].toString(toBase); 80 | } 81 | return out; 82 | } 83 | 84 | function decToHex(decStr) { 85 | var hex = convertBase(decStr, 10, 16); 86 | return hex ? '0x' + hex : null; 87 | } 88 | 89 | function hexToDec(hexStr) { 90 | if (hexStr.substring(0, 2) === '0x') hexStr = hexStr.substring(2); 91 | hexStr = hexStr.toLowerCase(); 92 | return convertBase(hexStr, 16, 10); 93 | } -------------------------------------------------------------------------------- /js/jquery.min.js: -------------------------------------------------------------------------------- 1 | /*! jQuery v2.0.3 | (c) 2005, 2013 jQuery Foundation, Inc. | jquery.org/license 2 | */ 3 | (function(e,undefined){var t,n,r=typeof undefined,i=e.location,o=e.document,s=o.documentElement,a=e.jQuery,u=e.$,l={},c=[],p="2.0.3",f=c.concat,h=c.push,d=c.slice,g=c.indexOf,m=l.toString,y=l.hasOwnProperty,v=p.trim,x=function(e,n){return new x.fn.init(e,n,t)},b=/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,w=/\S+/g,T=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,C=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,k=/^-ms-/,N=/-([\da-z])/gi,E=function(e,t){return t.toUpperCase()},S=function(){o.removeEventListener("DOMContentLoaded",S,!1),e.removeEventListener("load",S,!1),x.ready()};x.fn=x.prototype={jquery:p,constructor:x,init:function(e,t,n){var r,i;if(!e)return this;if("string"==typeof e){if(r="<"===e.charAt(0)&&">"===e.charAt(e.length-1)&&e.length>=3?[null,e,null]:T.exec(e),!r||!r[1]&&t)return!t||t.jquery?(t||n).find(e):this.constructor(t).find(e);if(r[1]){if(t=t instanceof x?t[0]:t,x.merge(this,x.parseHTML(r[1],t&&t.nodeType?t.ownerDocument||t:o,!0)),C.test(r[1])&&x.isPlainObject(t))for(r in t)x.isFunction(this[r])?this[r](t[r]):this.attr(r,t[r]);return this}return i=o.getElementById(r[2]),i&&i.parentNode&&(this.length=1,this[0]=i),this.context=o,this.selector=e,this}return e.nodeType?(this.context=this[0]=e,this.length=1,this):x.isFunction(e)?n.ready(e):(e.selector!==undefined&&(this.selector=e.selector,this.context=e.context),x.makeArray(e,this))},selector:"",length:0,toArray:function(){return d.call(this)},get:function(e){return null==e?this.toArray():0>e?this[this.length+e]:this[e]},pushStack:function(e){var t=x.merge(this.constructor(),e);return t.prevObject=this,t.context=this.context,t},each:function(e,t){return x.each(this,e,t)},ready:function(e){return x.ready.promise().done(e),this},slice:function(){return this.pushStack(d.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(e){var t=this.length,n=+e+(0>e?t:0);return this.pushStack(n>=0&&t>n?[this[n]]:[])},map:function(e){return this.pushStack(x.map(this,function(t,n){return e.call(t,n,t)}))},end:function(){return this.prevObject||this.constructor(null)},push:h,sort:[].sort,splice:[].splice},x.fn.init.prototype=x.fn,x.extend=x.fn.extend=function(){var e,t,n,r,i,o,s=arguments[0]||{},a=1,u=arguments.length,l=!1;for("boolean"==typeof s&&(l=s,s=arguments[1]||{},a=2),"object"==typeof s||x.isFunction(s)||(s={}),u===a&&(s=this,--a);u>a;a++)if(null!=(e=arguments[a]))for(t in e)n=s[t],r=e[t],s!==r&&(l&&r&&(x.isPlainObject(r)||(i=x.isArray(r)))?(i?(i=!1,o=n&&x.isArray(n)?n:[]):o=n&&x.isPlainObject(n)?n:{},s[t]=x.extend(l,o,r)):r!==undefined&&(s[t]=r));return s},x.extend({expando:"jQuery"+(p+Math.random()).replace(/\D/g,""),noConflict:function(t){return e.$===x&&(e.$=u),t&&e.jQuery===x&&(e.jQuery=a),x},isReady:!1,readyWait:1,holdReady:function(e){e?x.readyWait++:x.ready(!0)},ready:function(e){(e===!0?--x.readyWait:x.isReady)||(x.isReady=!0,e!==!0&&--x.readyWait>0||(n.resolveWith(o,[x]),x.fn.trigger&&x(o).trigger("ready").off("ready")))},isFunction:function(e){return"function"===x.type(e)},isArray:Array.isArray,isWindow:function(e){return null!=e&&e===e.window},isNumeric:function(e){return!isNaN(parseFloat(e))&&isFinite(e)},type:function(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?l[m.call(e)]||"object":typeof e},isPlainObject:function(e){if("object"!==x.type(e)||e.nodeType||x.isWindow(e))return!1;try{if(e.constructor&&!y.call(e.constructor.prototype,"isPrototypeOf"))return!1}catch(t){return!1}return!0},isEmptyObject:function(e){var t;for(t in e)return!1;return!0},error:function(e){throw Error(e)},parseHTML:function(e,t,n){if(!e||"string"!=typeof e)return null;"boolean"==typeof t&&(n=t,t=!1),t=t||o;var r=C.exec(e),i=!n&&[];return r?[t.createElement(r[1])]:(r=x.buildFragment([e],t,i),i&&x(i).remove(),x.merge([],r.childNodes))},parseJSON:JSON.parse,parseXML:function(e){var t,n;if(!e||"string"!=typeof e)return null;try{n=new DOMParser,t=n.parseFromString(e,"text/xml")}catch(r){t=undefined}return(!t||t.getElementsByTagName("parsererror").length)&&x.error("Invalid XML: "+e),t},noop:function(){},globalEval:function(e){var t,n=eval;e=x.trim(e),e&&(1===e.indexOf("use strict")?(t=o.createElement("script"),t.text=e,o.head.appendChild(t).parentNode.removeChild(t)):n(e))},camelCase:function(e){return e.replace(k,"ms-").replace(N,E)},nodeName:function(e,t){return e.nodeName&&e.nodeName.toLowerCase()===t.toLowerCase()},each:function(e,t,n){var r,i=0,o=e.length,s=j(e);if(n){if(s){for(;o>i;i++)if(r=t.apply(e[i],n),r===!1)break}else for(i in e)if(r=t.apply(e[i],n),r===!1)break}else if(s){for(;o>i;i++)if(r=t.call(e[i],i,e[i]),r===!1)break}else for(i in e)if(r=t.call(e[i],i,e[i]),r===!1)break;return e},trim:function(e){return null==e?"":v.call(e)},makeArray:function(e,t){var n=t||[];return null!=e&&(j(Object(e))?x.merge(n,"string"==typeof e?[e]:e):h.call(n,e)),n},inArray:function(e,t,n){return null==t?-1:g.call(t,e,n)},merge:function(e,t){var n=t.length,r=e.length,i=0;if("number"==typeof n)for(;n>i;i++)e[r++]=t[i];else while(t[i]!==undefined)e[r++]=t[i++];return e.length=r,e},grep:function(e,t,n){var r,i=[],o=0,s=e.length;for(n=!!n;s>o;o++)r=!!t(e[o],o),n!==r&&i.push(e[o]);return i},map:function(e,t,n){var r,i=0,o=e.length,s=j(e),a=[];if(s)for(;o>i;i++)r=t(e[i],i,n),null!=r&&(a[a.length]=r);else for(i in e)r=t(e[i],i,n),null!=r&&(a[a.length]=r);return f.apply([],a)},guid:1,proxy:function(e,t){var n,r,i;return"string"==typeof t&&(n=e[t],t=e,e=n),x.isFunction(e)?(r=d.call(arguments,2),i=function(){return e.apply(t||this,r.concat(d.call(arguments)))},i.guid=e.guid=e.guid||x.guid++,i):undefined},access:function(e,t,n,r,i,o,s){var a=0,u=e.length,l=null==n;if("object"===x.type(n)){i=!0;for(a in n)x.access(e,t,a,n[a],!0,o,s)}else if(r!==undefined&&(i=!0,x.isFunction(r)||(s=!0),l&&(s?(t.call(e,r),t=null):(l=t,t=function(e,t,n){return l.call(x(e),n)})),t))for(;u>a;a++)t(e[a],n,s?r:r.call(e[a],a,t(e[a],n)));return i?e:l?t.call(e):u?t(e[0],n):o},now:Date.now,swap:function(e,t,n,r){var i,o,s={};for(o in t)s[o]=e.style[o],e.style[o]=t[o];i=n.apply(e,r||[]);for(o in t)e.style[o]=s[o];return i}}),x.ready.promise=function(t){return n||(n=x.Deferred(),"complete"===o.readyState?setTimeout(x.ready):(o.addEventListener("DOMContentLoaded",S,!1),e.addEventListener("load",S,!1))),n.promise(t)},x.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(e,t){l["[object "+t+"]"]=t.toLowerCase()});function j(e){var t=e.length,n=x.type(e);return x.isWindow(e)?!1:1===e.nodeType&&t?!0:"array"===n||"function"!==n&&(0===t||"number"==typeof t&&t>0&&t-1 in e)}t=x(o),function(e,undefined){var t,n,r,i,o,s,a,u,l,c,p,f,h,d,g,m,y,v="sizzle"+-new Date,b=e.document,w=0,T=0,C=st(),k=st(),N=st(),E=!1,S=function(e,t){return e===t?(E=!0,0):0},j=typeof undefined,D=1<<31,A={}.hasOwnProperty,L=[],q=L.pop,H=L.push,O=L.push,F=L.slice,P=L.indexOf||function(e){var t=0,n=this.length;for(;n>t;t++)if(this[t]===e)return t;return-1},R="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",M="[\\x20\\t\\r\\n\\f]",W="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",$=W.replace("w","w#"),B="\\["+M+"*("+W+")"+M+"*(?:([*^$|!~]?=)"+M+"*(?:(['\"])((?:\\\\.|[^\\\\])*?)\\3|("+$+")|)|)"+M+"*\\]",I=":("+W+")(?:\\(((['\"])((?:\\\\.|[^\\\\])*?)\\3|((?:\\\\.|[^\\\\()[\\]]|"+B.replace(3,8)+")*)|.*)\\)|)",z=RegExp("^"+M+"+|((?:^|[^\\\\])(?:\\\\.)*)"+M+"+$","g"),_=RegExp("^"+M+"*,"+M+"*"),X=RegExp("^"+M+"*([>+~]|"+M+")"+M+"*"),U=RegExp(M+"*[+~]"),Y=RegExp("="+M+"*([^\\]'\"]*)"+M+"*\\]","g"),V=RegExp(I),G=RegExp("^"+$+"$"),J={ID:RegExp("^#("+W+")"),CLASS:RegExp("^\\.("+W+")"),TAG:RegExp("^("+W.replace("w","w*")+")"),ATTR:RegExp("^"+B),PSEUDO:RegExp("^"+I),CHILD:RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+M+"*(even|odd|(([+-]|)(\\d*)n|)"+M+"*(?:([+-]|)"+M+"*(\\d+)|))"+M+"*\\)|)","i"),bool:RegExp("^(?:"+R+")$","i"),needsContext:RegExp("^"+M+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+M+"*((?:-\\d)?\\d*)"+M+"*\\)|)(?=[^-]|$)","i")},Q=/^[^{]+\{\s*\[native \w/,K=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,Z=/^(?:input|select|textarea|button)$/i,et=/^h\d$/i,tt=/'|\\/g,nt=RegExp("\\\\([\\da-f]{1,6}"+M+"?|("+M+")|.)","ig"),rt=function(e,t,n){var r="0x"+t-65536;return r!==r||n?t:0>r?String.fromCharCode(r+65536):String.fromCharCode(55296|r>>10,56320|1023&r)};try{O.apply(L=F.call(b.childNodes),b.childNodes),L[b.childNodes.length].nodeType}catch(it){O={apply:L.length?function(e,t){H.apply(e,F.call(t))}:function(e,t){var n=e.length,r=0;while(e[n++]=t[r++]);e.length=n-1}}}function ot(e,t,r,i){var o,s,a,u,l,f,g,m,x,w;if((t?t.ownerDocument||t:b)!==p&&c(t),t=t||p,r=r||[],!e||"string"!=typeof e)return r;if(1!==(u=t.nodeType)&&9!==u)return[];if(h&&!i){if(o=K.exec(e))if(a=o[1]){if(9===u){if(s=t.getElementById(a),!s||!s.parentNode)return r;if(s.id===a)return r.push(s),r}else if(t.ownerDocument&&(s=t.ownerDocument.getElementById(a))&&y(t,s)&&s.id===a)return r.push(s),r}else{if(o[2])return O.apply(r,t.getElementsByTagName(e)),r;if((a=o[3])&&n.getElementsByClassName&&t.getElementsByClassName)return O.apply(r,t.getElementsByClassName(a)),r}if(n.qsa&&(!d||!d.test(e))){if(m=g=v,x=t,w=9===u&&e,1===u&&"object"!==t.nodeName.toLowerCase()){f=gt(e),(g=t.getAttribute("id"))?m=g.replace(tt,"\\$&"):t.setAttribute("id",m),m="[id='"+m+"'] ",l=f.length;while(l--)f[l]=m+mt(f[l]);x=U.test(e)&&t.parentNode||t,w=f.join(",")}if(w)try{return O.apply(r,x.querySelectorAll(w)),r}catch(T){}finally{g||t.removeAttribute("id")}}}return kt(e.replace(z,"$1"),t,r,i)}function st(){var e=[];function t(n,r){return e.push(n+=" ")>i.cacheLength&&delete t[e.shift()],t[n]=r}return t}function at(e){return e[v]=!0,e}function ut(e){var t=p.createElement("div");try{return!!e(t)}catch(n){return!1}finally{t.parentNode&&t.parentNode.removeChild(t),t=null}}function lt(e,t){var n=e.split("|"),r=e.length;while(r--)i.attrHandle[n[r]]=t}function ct(e,t){var n=t&&e,r=n&&1===e.nodeType&&1===t.nodeType&&(~t.sourceIndex||D)-(~e.sourceIndex||D);if(r)return r;if(n)while(n=n.nextSibling)if(n===t)return-1;return e?1:-1}function pt(e){return function(t){var n=t.nodeName.toLowerCase();return"input"===n&&t.type===e}}function ft(e){return function(t){var n=t.nodeName.toLowerCase();return("input"===n||"button"===n)&&t.type===e}}function ht(e){return at(function(t){return t=+t,at(function(n,r){var i,o=e([],n.length,t),s=o.length;while(s--)n[i=o[s]]&&(n[i]=!(r[i]=n[i]))})})}s=ot.isXML=function(e){var t=e&&(e.ownerDocument||e).documentElement;return t?"HTML"!==t.nodeName:!1},n=ot.support={},c=ot.setDocument=function(e){var t=e?e.ownerDocument||e:b,r=t.defaultView;return t!==p&&9===t.nodeType&&t.documentElement?(p=t,f=t.documentElement,h=!s(t),r&&r.attachEvent&&r!==r.top&&r.attachEvent("onbeforeunload",function(){c()}),n.attributes=ut(function(e){return e.className="i",!e.getAttribute("className")}),n.getElementsByTagName=ut(function(e){return e.appendChild(t.createComment("")),!e.getElementsByTagName("*").length}),n.getElementsByClassName=ut(function(e){return e.innerHTML="
",e.firstChild.className="i",2===e.getElementsByClassName("i").length}),n.getById=ut(function(e){return f.appendChild(e).id=v,!t.getElementsByName||!t.getElementsByName(v).length}),n.getById?(i.find.ID=function(e,t){if(typeof t.getElementById!==j&&h){var n=t.getElementById(e);return n&&n.parentNode?[n]:[]}},i.filter.ID=function(e){var t=e.replace(nt,rt);return function(e){return e.getAttribute("id")===t}}):(delete i.find.ID,i.filter.ID=function(e){var t=e.replace(nt,rt);return function(e){var n=typeof e.getAttributeNode!==j&&e.getAttributeNode("id");return n&&n.value===t}}),i.find.TAG=n.getElementsByTagName?function(e,t){return typeof t.getElementsByTagName!==j?t.getElementsByTagName(e):undefined}:function(e,t){var n,r=[],i=0,o=t.getElementsByTagName(e);if("*"===e){while(n=o[i++])1===n.nodeType&&r.push(n);return r}return o},i.find.CLASS=n.getElementsByClassName&&function(e,t){return typeof t.getElementsByClassName!==j&&h?t.getElementsByClassName(e):undefined},g=[],d=[],(n.qsa=Q.test(t.querySelectorAll))&&(ut(function(e){e.innerHTML="",e.querySelectorAll("[selected]").length||d.push("\\["+M+"*(?:value|"+R+")"),e.querySelectorAll(":checked").length||d.push(":checked")}),ut(function(e){var n=t.createElement("input");n.setAttribute("type","hidden"),e.appendChild(n).setAttribute("t",""),e.querySelectorAll("[t^='']").length&&d.push("[*^$]="+M+"*(?:''|\"\")"),e.querySelectorAll(":enabled").length||d.push(":enabled",":disabled"),e.querySelectorAll("*,:x"),d.push(",.*:")})),(n.matchesSelector=Q.test(m=f.webkitMatchesSelector||f.mozMatchesSelector||f.oMatchesSelector||f.msMatchesSelector))&&ut(function(e){n.disconnectedMatch=m.call(e,"div"),m.call(e,"[s!='']:x"),g.push("!=",I)}),d=d.length&&RegExp(d.join("|")),g=g.length&&RegExp(g.join("|")),y=Q.test(f.contains)||f.compareDocumentPosition?function(e,t){var n=9===e.nodeType?e.documentElement:e,r=t&&t.parentNode;return e===r||!(!r||1!==r.nodeType||!(n.contains?n.contains(r):e.compareDocumentPosition&&16&e.compareDocumentPosition(r)))}:function(e,t){if(t)while(t=t.parentNode)if(t===e)return!0;return!1},S=f.compareDocumentPosition?function(e,r){if(e===r)return E=!0,0;var i=r.compareDocumentPosition&&e.compareDocumentPosition&&e.compareDocumentPosition(r);return i?1&i||!n.sortDetached&&r.compareDocumentPosition(e)===i?e===t||y(b,e)?-1:r===t||y(b,r)?1:l?P.call(l,e)-P.call(l,r):0:4&i?-1:1:e.compareDocumentPosition?-1:1}:function(e,n){var r,i=0,o=e.parentNode,s=n.parentNode,a=[e],u=[n];if(e===n)return E=!0,0;if(!o||!s)return e===t?-1:n===t?1:o?-1:s?1:l?P.call(l,e)-P.call(l,n):0;if(o===s)return ct(e,n);r=e;while(r=r.parentNode)a.unshift(r);r=n;while(r=r.parentNode)u.unshift(r);while(a[i]===u[i])i++;return i?ct(a[i],u[i]):a[i]===b?-1:u[i]===b?1:0},t):p},ot.matches=function(e,t){return ot(e,null,null,t)},ot.matchesSelector=function(e,t){if((e.ownerDocument||e)!==p&&c(e),t=t.replace(Y,"='$1']"),!(!n.matchesSelector||!h||g&&g.test(t)||d&&d.test(t)))try{var r=m.call(e,t);if(r||n.disconnectedMatch||e.document&&11!==e.document.nodeType)return r}catch(i){}return ot(t,p,null,[e]).length>0},ot.contains=function(e,t){return(e.ownerDocument||e)!==p&&c(e),y(e,t)},ot.attr=function(e,t){(e.ownerDocument||e)!==p&&c(e);var r=i.attrHandle[t.toLowerCase()],o=r&&A.call(i.attrHandle,t.toLowerCase())?r(e,t,!h):undefined;return o===undefined?n.attributes||!h?e.getAttribute(t):(o=e.getAttributeNode(t))&&o.specified?o.value:null:o},ot.error=function(e){throw Error("Syntax error, unrecognized expression: "+e)},ot.uniqueSort=function(e){var t,r=[],i=0,o=0;if(E=!n.detectDuplicates,l=!n.sortStable&&e.slice(0),e.sort(S),E){while(t=e[o++])t===e[o]&&(i=r.push(o));while(i--)e.splice(r[i],1)}return e},o=ot.getText=function(e){var t,n="",r=0,i=e.nodeType;if(i){if(1===i||9===i||11===i){if("string"==typeof e.textContent)return e.textContent;for(e=e.firstChild;e;e=e.nextSibling)n+=o(e)}else if(3===i||4===i)return e.nodeValue}else for(;t=e[r];r++)n+=o(t);return n},i=ot.selectors={cacheLength:50,createPseudo:at,match:J,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(e){return e[1]=e[1].replace(nt,rt),e[3]=(e[4]||e[5]||"").replace(nt,rt),"~="===e[2]&&(e[3]=" "+e[3]+" "),e.slice(0,4)},CHILD:function(e){return e[1]=e[1].toLowerCase(),"nth"===e[1].slice(0,3)?(e[3]||ot.error(e[0]),e[4]=+(e[4]?e[5]+(e[6]||1):2*("even"===e[3]||"odd"===e[3])),e[5]=+(e[7]+e[8]||"odd"===e[3])):e[3]&&ot.error(e[0]),e},PSEUDO:function(e){var t,n=!e[5]&&e[2];return J.CHILD.test(e[0])?null:(e[3]&&e[4]!==undefined?e[2]=e[4]:n&&V.test(n)&&(t=gt(n,!0))&&(t=n.indexOf(")",n.length-t)-n.length)&&(e[0]=e[0].slice(0,t),e[2]=n.slice(0,t)),e.slice(0,3))}},filter:{TAG:function(e){var t=e.replace(nt,rt).toLowerCase();return"*"===e?function(){return!0}:function(e){return e.nodeName&&e.nodeName.toLowerCase()===t}},CLASS:function(e){var t=C[e+" "];return t||(t=RegExp("(^|"+M+")"+e+"("+M+"|$)"))&&C(e,function(e){return t.test("string"==typeof e.className&&e.className||typeof e.getAttribute!==j&&e.getAttribute("class")||"")})},ATTR:function(e,t,n){return function(r){var i=ot.attr(r,e);return null==i?"!="===t:t?(i+="","="===t?i===n:"!="===t?i!==n:"^="===t?n&&0===i.indexOf(n):"*="===t?n&&i.indexOf(n)>-1:"$="===t?n&&i.slice(-n.length)===n:"~="===t?(" "+i+" ").indexOf(n)>-1:"|="===t?i===n||i.slice(0,n.length+1)===n+"-":!1):!0}},CHILD:function(e,t,n,r,i){var o="nth"!==e.slice(0,3),s="last"!==e.slice(-4),a="of-type"===t;return 1===r&&0===i?function(e){return!!e.parentNode}:function(t,n,u){var l,c,p,f,h,d,g=o!==s?"nextSibling":"previousSibling",m=t.parentNode,y=a&&t.nodeName.toLowerCase(),x=!u&&!a;if(m){if(o){while(g){p=t;while(p=p[g])if(a?p.nodeName.toLowerCase()===y:1===p.nodeType)return!1;d=g="only"===e&&!d&&"nextSibling"}return!0}if(d=[s?m.firstChild:m.lastChild],s&&x){c=m[v]||(m[v]={}),l=c[e]||[],h=l[0]===w&&l[1],f=l[0]===w&&l[2],p=h&&m.childNodes[h];while(p=++h&&p&&p[g]||(f=h=0)||d.pop())if(1===p.nodeType&&++f&&p===t){c[e]=[w,h,f];break}}else if(x&&(l=(t[v]||(t[v]={}))[e])&&l[0]===w)f=l[1];else while(p=++h&&p&&p[g]||(f=h=0)||d.pop())if((a?p.nodeName.toLowerCase()===y:1===p.nodeType)&&++f&&(x&&((p[v]||(p[v]={}))[e]=[w,f]),p===t))break;return f-=i,f===r||0===f%r&&f/r>=0}}},PSEUDO:function(e,t){var n,r=i.pseudos[e]||i.setFilters[e.toLowerCase()]||ot.error("unsupported pseudo: "+e);return r[v]?r(t):r.length>1?(n=[e,e,"",t],i.setFilters.hasOwnProperty(e.toLowerCase())?at(function(e,n){var i,o=r(e,t),s=o.length;while(s--)i=P.call(e,o[s]),e[i]=!(n[i]=o[s])}):function(e){return r(e,0,n)}):r}},pseudos:{not:at(function(e){var t=[],n=[],r=a(e.replace(z,"$1"));return r[v]?at(function(e,t,n,i){var o,s=r(e,null,i,[]),a=e.length;while(a--)(o=s[a])&&(e[a]=!(t[a]=o))}):function(e,i,o){return t[0]=e,r(t,null,o,n),!n.pop()}}),has:at(function(e){return function(t){return ot(e,t).length>0}}),contains:at(function(e){return function(t){return(t.textContent||t.innerText||o(t)).indexOf(e)>-1}}),lang:at(function(e){return G.test(e||"")||ot.error("unsupported lang: "+e),e=e.replace(nt,rt).toLowerCase(),function(t){var n;do if(n=h?t.lang:t.getAttribute("xml:lang")||t.getAttribute("lang"))return n=n.toLowerCase(),n===e||0===n.indexOf(e+"-");while((t=t.parentNode)&&1===t.nodeType);return!1}}),target:function(t){var n=e.location&&e.location.hash;return n&&n.slice(1)===t.id},root:function(e){return e===f},focus:function(e){return e===p.activeElement&&(!p.hasFocus||p.hasFocus())&&!!(e.type||e.href||~e.tabIndex)},enabled:function(e){return e.disabled===!1},disabled:function(e){return e.disabled===!0},checked:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&!!e.checked||"option"===t&&!!e.selected},selected:function(e){return e.parentNode&&e.parentNode.selectedIndex,e.selected===!0},empty:function(e){for(e=e.firstChild;e;e=e.nextSibling)if(e.nodeName>"@"||3===e.nodeType||4===e.nodeType)return!1;return!0},parent:function(e){return!i.pseudos.empty(e)},header:function(e){return et.test(e.nodeName)},input:function(e){return Z.test(e.nodeName)},button:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&"button"===e.type||"button"===t},text:function(e){var t;return"input"===e.nodeName.toLowerCase()&&"text"===e.type&&(null==(t=e.getAttribute("type"))||t.toLowerCase()===e.type)},first:ht(function(){return[0]}),last:ht(function(e,t){return[t-1]}),eq:ht(function(e,t,n){return[0>n?n+t:n]}),even:ht(function(e,t){var n=0;for(;t>n;n+=2)e.push(n);return e}),odd:ht(function(e,t){var n=1;for(;t>n;n+=2)e.push(n);return e}),lt:ht(function(e,t,n){var r=0>n?n+t:n;for(;--r>=0;)e.push(r);return e}),gt:ht(function(e,t,n){var r=0>n?n+t:n;for(;t>++r;)e.push(r);return e})}},i.pseudos.nth=i.pseudos.eq;for(t in{radio:!0,checkbox:!0,file:!0,password:!0,image:!0})i.pseudos[t]=pt(t);for(t in{submit:!0,reset:!0})i.pseudos[t]=ft(t);function dt(){}dt.prototype=i.filters=i.pseudos,i.setFilters=new dt;function gt(e,t){var n,r,o,s,a,u,l,c=k[e+" "];if(c)return t?0:c.slice(0);a=e,u=[],l=i.preFilter;while(a){(!n||(r=_.exec(a)))&&(r&&(a=a.slice(r[0].length)||a),u.push(o=[])),n=!1,(r=X.exec(a))&&(n=r.shift(),o.push({value:n,type:r[0].replace(z," ")}),a=a.slice(n.length));for(s in i.filter)!(r=J[s].exec(a))||l[s]&&!(r=l[s](r))||(n=r.shift(),o.push({value:n,type:s,matches:r}),a=a.slice(n.length));if(!n)break}return t?a.length:a?ot.error(e):k(e,u).slice(0)}function mt(e){var t=0,n=e.length,r="";for(;n>t;t++)r+=e[t].value;return r}function yt(e,t,n){var i=t.dir,o=n&&"parentNode"===i,s=T++;return t.first?function(t,n,r){while(t=t[i])if(1===t.nodeType||o)return e(t,n,r)}:function(t,n,a){var u,l,c,p=w+" "+s;if(a){while(t=t[i])if((1===t.nodeType||o)&&e(t,n,a))return!0}else while(t=t[i])if(1===t.nodeType||o)if(c=t[v]||(t[v]={}),(l=c[i])&&l[0]===p){if((u=l[1])===!0||u===r)return u===!0}else if(l=c[i]=[p],l[1]=e(t,n,a)||r,l[1]===!0)return!0}}function vt(e){return e.length>1?function(t,n,r){var i=e.length;while(i--)if(!e[i](t,n,r))return!1;return!0}:e[0]}function xt(e,t,n,r,i){var o,s=[],a=0,u=e.length,l=null!=t;for(;u>a;a++)(o=e[a])&&(!n||n(o,r,i))&&(s.push(o),l&&t.push(a));return s}function bt(e,t,n,r,i,o){return r&&!r[v]&&(r=bt(r)),i&&!i[v]&&(i=bt(i,o)),at(function(o,s,a,u){var l,c,p,f=[],h=[],d=s.length,g=o||Ct(t||"*",a.nodeType?[a]:a,[]),m=!e||!o&&t?g:xt(g,f,e,a,u),y=n?i||(o?e:d||r)?[]:s:m;if(n&&n(m,y,a,u),r){l=xt(y,h),r(l,[],a,u),c=l.length;while(c--)(p=l[c])&&(y[h[c]]=!(m[h[c]]=p))}if(o){if(i||e){if(i){l=[],c=y.length;while(c--)(p=y[c])&&l.push(m[c]=p);i(null,y=[],l,u)}c=y.length;while(c--)(p=y[c])&&(l=i?P.call(o,p):f[c])>-1&&(o[l]=!(s[l]=p))}}else y=xt(y===s?y.splice(d,y.length):y),i?i(null,s,y,u):O.apply(s,y)})}function wt(e){var t,n,r,o=e.length,s=i.relative[e[0].type],a=s||i.relative[" "],l=s?1:0,c=yt(function(e){return e===t},a,!0),p=yt(function(e){return P.call(t,e)>-1},a,!0),f=[function(e,n,r){return!s&&(r||n!==u)||((t=n).nodeType?c(e,n,r):p(e,n,r))}];for(;o>l;l++)if(n=i.relative[e[l].type])f=[yt(vt(f),n)];else{if(n=i.filter[e[l].type].apply(null,e[l].matches),n[v]){for(r=++l;o>r;r++)if(i.relative[e[r].type])break;return bt(l>1&&vt(f),l>1&&mt(e.slice(0,l-1).concat({value:" "===e[l-2].type?"*":""})).replace(z,"$1"),n,r>l&&wt(e.slice(l,r)),o>r&&wt(e=e.slice(r)),o>r&&mt(e))}f.push(n)}return vt(f)}function Tt(e,t){var n=0,o=t.length>0,s=e.length>0,a=function(a,l,c,f,h){var d,g,m,y=[],v=0,x="0",b=a&&[],T=null!=h,C=u,k=a||s&&i.find.TAG("*",h&&l.parentNode||l),N=w+=null==C?1:Math.random()||.1;for(T&&(u=l!==p&&l,r=n);null!=(d=k[x]);x++){if(s&&d){g=0;while(m=e[g++])if(m(d,l,c)){f.push(d);break}T&&(w=N,r=++n)}o&&((d=!m&&d)&&v--,a&&b.push(d))}if(v+=x,o&&x!==v){g=0;while(m=t[g++])m(b,y,l,c);if(a){if(v>0)while(x--)b[x]||y[x]||(y[x]=q.call(f));y=xt(y)}O.apply(f,y),T&&!a&&y.length>0&&v+t.length>1&&ot.uniqueSort(f)}return T&&(w=N,u=C),b};return o?at(a):a}a=ot.compile=function(e,t){var n,r=[],i=[],o=N[e+" "];if(!o){t||(t=gt(e)),n=t.length;while(n--)o=wt(t[n]),o[v]?r.push(o):i.push(o);o=N(e,Tt(i,r))}return o};function Ct(e,t,n){var r=0,i=t.length;for(;i>r;r++)ot(e,t[r],n);return n}function kt(e,t,r,o){var s,u,l,c,p,f=gt(e);if(!o&&1===f.length){if(u=f[0]=f[0].slice(0),u.length>2&&"ID"===(l=u[0]).type&&n.getById&&9===t.nodeType&&h&&i.relative[u[1].type]){if(t=(i.find.ID(l.matches[0].replace(nt,rt),t)||[])[0],!t)return r;e=e.slice(u.shift().value.length)}s=J.needsContext.test(e)?0:u.length;while(s--){if(l=u[s],i.relative[c=l.type])break;if((p=i.find[c])&&(o=p(l.matches[0].replace(nt,rt),U.test(u[0].type)&&t.parentNode||t))){if(u.splice(s,1),e=o.length&&mt(u),!e)return O.apply(r,o),r;break}}}return a(e,f)(o,t,!h,r,U.test(e)),r}n.sortStable=v.split("").sort(S).join("")===v,n.detectDuplicates=E,c(),n.sortDetached=ut(function(e){return 1&e.compareDocumentPosition(p.createElement("div"))}),ut(function(e){return e.innerHTML="","#"===e.firstChild.getAttribute("href")})||lt("type|href|height|width",function(e,t,n){return n?undefined:e.getAttribute(t,"type"===t.toLowerCase()?1:2)}),n.attributes&&ut(function(e){return e.innerHTML="",e.firstChild.setAttribute("value",""),""===e.firstChild.getAttribute("value")})||lt("value",function(e,t,n){return n||"input"!==e.nodeName.toLowerCase()?undefined:e.defaultValue}),ut(function(e){return null==e.getAttribute("disabled")})||lt(R,function(e,t,n){var r;return n?undefined:(r=e.getAttributeNode(t))&&r.specified?r.value:e[t]===!0?t.toLowerCase():null}),x.find=ot,x.expr=ot.selectors,x.expr[":"]=x.expr.pseudos,x.unique=ot.uniqueSort,x.text=ot.getText,x.isXMLDoc=ot.isXML,x.contains=ot.contains}(e);var D={};function A(e){var t=D[e]={};return x.each(e.match(w)||[],function(e,n){t[n]=!0}),t}x.Callbacks=function(e){e="string"==typeof e?D[e]||A(e):x.extend({},e);var t,n,r,i,o,s,a=[],u=!e.once&&[],l=function(p){for(t=e.memory&&p,n=!0,s=i||0,i=0,o=a.length,r=!0;a&&o>s;s++)if(a[s].apply(p[0],p[1])===!1&&e.stopOnFalse){t=!1;break}r=!1,a&&(u?u.length&&l(u.shift()):t?a=[]:c.disable())},c={add:function(){if(a){var n=a.length;(function s(t){x.each(t,function(t,n){var r=x.type(n);"function"===r?e.unique&&c.has(n)||a.push(n):n&&n.length&&"string"!==r&&s(n)})})(arguments),r?o=a.length:t&&(i=n,l(t))}return this},remove:function(){return a&&x.each(arguments,function(e,t){var n;while((n=x.inArray(t,a,n))>-1)a.splice(n,1),r&&(o>=n&&o--,s>=n&&s--)}),this},has:function(e){return e?x.inArray(e,a)>-1:!(!a||!a.length)},empty:function(){return a=[],o=0,this},disable:function(){return a=u=t=undefined,this},disabled:function(){return!a},lock:function(){return u=undefined,t||c.disable(),this},locked:function(){return!u},fireWith:function(e,t){return!a||n&&!u||(t=t||[],t=[e,t.slice?t.slice():t],r?u.push(t):l(t)),this},fire:function(){return c.fireWith(this,arguments),this},fired:function(){return!!n}};return c},x.extend({Deferred:function(e){var t=[["resolve","done",x.Callbacks("once memory"),"resolved"],["reject","fail",x.Callbacks("once memory"),"rejected"],["notify","progress",x.Callbacks("memory")]],n="pending",r={state:function(){return n},always:function(){return i.done(arguments).fail(arguments),this},then:function(){var e=arguments;return x.Deferred(function(n){x.each(t,function(t,o){var s=o[0],a=x.isFunction(e[t])&&e[t];i[o[1]](function(){var e=a&&a.apply(this,arguments);e&&x.isFunction(e.promise)?e.promise().done(n.resolve).fail(n.reject).progress(n.notify):n[s+"With"](this===r?n.promise():this,a?[e]:arguments)})}),e=null}).promise()},promise:function(e){return null!=e?x.extend(e,r):r}},i={};return r.pipe=r.then,x.each(t,function(e,o){var s=o[2],a=o[3];r[o[1]]=s.add,a&&s.add(function(){n=a},t[1^e][2].disable,t[2][2].lock),i[o[0]]=function(){return i[o[0]+"With"](this===i?r:this,arguments),this},i[o[0]+"With"]=s.fireWith}),r.promise(i),e&&e.call(i,i),i},when:function(e){var t=0,n=d.call(arguments),r=n.length,i=1!==r||e&&x.isFunction(e.promise)?r:0,o=1===i?e:x.Deferred(),s=function(e,t,n){return function(r){t[e]=this,n[e]=arguments.length>1?d.call(arguments):r,n===a?o.notifyWith(t,n):--i||o.resolveWith(t,n)}},a,u,l;if(r>1)for(a=Array(r),u=Array(r),l=Array(r);r>t;t++)n[t]&&x.isFunction(n[t].promise)?n[t].promise().done(s(t,l,n)).fail(o.reject).progress(s(t,u,a)):--i;return i||o.resolveWith(l,n),o.promise()}}),x.support=function(t){var n=o.createElement("input"),r=o.createDocumentFragment(),i=o.createElement("div"),s=o.createElement("select"),a=s.appendChild(o.createElement("option"));return n.type?(n.type="checkbox",t.checkOn=""!==n.value,t.optSelected=a.selected,t.reliableMarginRight=!0,t.boxSizingReliable=!0,t.pixelPosition=!1,n.checked=!0,t.noCloneChecked=n.cloneNode(!0).checked,s.disabled=!0,t.optDisabled=!a.disabled,n=o.createElement("input"),n.value="t",n.type="radio",t.radioValue="t"===n.value,n.setAttribute("checked","t"),n.setAttribute("name","t"),r.appendChild(n),t.checkClone=r.cloneNode(!0).cloneNode(!0).lastChild.checked,t.focusinBubbles="onfocusin"in e,i.style.backgroundClip="content-box",i.cloneNode(!0).style.backgroundClip="",t.clearCloneStyle="content-box"===i.style.backgroundClip,x(function(){var n,r,s="padding:0;margin:0;border:0;display:block;-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box",a=o.getElementsByTagName("body")[0];a&&(n=o.createElement("div"),n.style.cssText="border:0;width:0;height:0;position:absolute;top:0;left:-9999px;margin-top:1px",a.appendChild(n).appendChild(i),i.innerHTML="",i.style.cssText="-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;position:absolute;top:1%",x.swap(a,null!=a.style.zoom?{zoom:1}:{},function(){t.boxSizing=4===i.offsetWidth}),e.getComputedStyle&&(t.pixelPosition="1%"!==(e.getComputedStyle(i,null)||{}).top,t.boxSizingReliable="4px"===(e.getComputedStyle(i,null)||{width:"4px"}).width,r=i.appendChild(o.createElement("div")),r.style.cssText=i.style.cssText=s,r.style.marginRight=r.style.width="0",i.style.width="1px",t.reliableMarginRight=!parseFloat((e.getComputedStyle(r,null)||{}).marginRight)),a.removeChild(n))}),t):t}({});var L,q,H=/(?:\{[\s\S]*\}|\[[\s\S]*\])$/,O=/([A-Z])/g;function F(){Object.defineProperty(this.cache={},0,{get:function(){return{}}}),this.expando=x.expando+Math.random()}F.uid=1,F.accepts=function(e){return e.nodeType?1===e.nodeType||9===e.nodeType:!0},F.prototype={key:function(e){if(!F.accepts(e))return 0;var t={},n=e[this.expando];if(!n){n=F.uid++;try{t[this.expando]={value:n},Object.defineProperties(e,t)}catch(r){t[this.expando]=n,x.extend(e,t)}}return this.cache[n]||(this.cache[n]={}),n},set:function(e,t,n){var r,i=this.key(e),o=this.cache[i];if("string"==typeof t)o[t]=n;else if(x.isEmptyObject(o))x.extend(this.cache[i],t);else for(r in t)o[r]=t[r];return o},get:function(e,t){var n=this.cache[this.key(e)];return t===undefined?n:n[t]},access:function(e,t,n){var r;return t===undefined||t&&"string"==typeof t&&n===undefined?(r=this.get(e,t),r!==undefined?r:this.get(e,x.camelCase(t))):(this.set(e,t,n),n!==undefined?n:t)},remove:function(e,t){var n,r,i,o=this.key(e),s=this.cache[o];if(t===undefined)this.cache[o]={};else{x.isArray(t)?r=t.concat(t.map(x.camelCase)):(i=x.camelCase(t),t in s?r=[t,i]:(r=i,r=r in s?[r]:r.match(w)||[])),n=r.length;while(n--)delete s[r[n]]}},hasData:function(e){return!x.isEmptyObject(this.cache[e[this.expando]]||{})},discard:function(e){e[this.expando]&&delete this.cache[e[this.expando]]}},L=new F,q=new F,x.extend({acceptData:F.accepts,hasData:function(e){return L.hasData(e)||q.hasData(e)},data:function(e,t,n){return L.access(e,t,n)},removeData:function(e,t){L.remove(e,t)},_data:function(e,t,n){return q.access(e,t,n)},_removeData:function(e,t){q.remove(e,t)}}),x.fn.extend({data:function(e,t){var n,r,i=this[0],o=0,s=null;if(e===undefined){if(this.length&&(s=L.get(i),1===i.nodeType&&!q.get(i,"hasDataAttrs"))){for(n=i.attributes;n.length>o;o++)r=n[o].name,0===r.indexOf("data-")&&(r=x.camelCase(r.slice(5)),P(i,r,s[r]));q.set(i,"hasDataAttrs",!0)}return s}return"object"==typeof e?this.each(function(){L.set(this,e)}):x.access(this,function(t){var n,r=x.camelCase(e);if(i&&t===undefined){if(n=L.get(i,e),n!==undefined)return n;if(n=L.get(i,r),n!==undefined)return n;if(n=P(i,r,undefined),n!==undefined)return n}else this.each(function(){var n=L.get(this,r);L.set(this,r,t),-1!==e.indexOf("-")&&n!==undefined&&L.set(this,e,t)})},null,t,arguments.length>1,null,!0)},removeData:function(e){return this.each(function(){L.remove(this,e)})}});function P(e,t,n){var r;if(n===undefined&&1===e.nodeType)if(r="data-"+t.replace(O,"-$1").toLowerCase(),n=e.getAttribute(r),"string"==typeof n){try{n="true"===n?!0:"false"===n?!1:"null"===n?null:+n+""===n?+n:H.test(n)?JSON.parse(n):n}catch(i){}L.set(e,t,n)}else n=undefined;return n}x.extend({queue:function(e,t,n){var r;return e?(t=(t||"fx")+"queue",r=q.get(e,t),n&&(!r||x.isArray(n)?r=q.access(e,t,x.makeArray(n)):r.push(n)),r||[]):undefined},dequeue:function(e,t){t=t||"fx";var n=x.queue(e,t),r=n.length,i=n.shift(),o=x._queueHooks(e,t),s=function(){x.dequeue(e,t) 4 | };"inprogress"===i&&(i=n.shift(),r--),i&&("fx"===t&&n.unshift("inprogress"),delete o.stop,i.call(e,s,o)),!r&&o&&o.empty.fire()},_queueHooks:function(e,t){var n=t+"queueHooks";return q.get(e,n)||q.access(e,n,{empty:x.Callbacks("once memory").add(function(){q.remove(e,[t+"queue",n])})})}}),x.fn.extend({queue:function(e,t){var n=2;return"string"!=typeof e&&(t=e,e="fx",n--),n>arguments.length?x.queue(this[0],e):t===undefined?this:this.each(function(){var n=x.queue(this,e,t);x._queueHooks(this,e),"fx"===e&&"inprogress"!==n[0]&&x.dequeue(this,e)})},dequeue:function(e){return this.each(function(){x.dequeue(this,e)})},delay:function(e,t){return e=x.fx?x.fx.speeds[e]||e:e,t=t||"fx",this.queue(t,function(t,n){var r=setTimeout(t,e);n.stop=function(){clearTimeout(r)}})},clearQueue:function(e){return this.queue(e||"fx",[])},promise:function(e,t){var n,r=1,i=x.Deferred(),o=this,s=this.length,a=function(){--r||i.resolveWith(o,[o])};"string"!=typeof e&&(t=e,e=undefined),e=e||"fx";while(s--)n=q.get(o[s],e+"queueHooks"),n&&n.empty&&(r++,n.empty.add(a));return a(),i.promise(t)}});var R,M,W=/[\t\r\n\f]/g,$=/\r/g,B=/^(?:input|select|textarea|button)$/i;x.fn.extend({attr:function(e,t){return x.access(this,x.attr,e,t,arguments.length>1)},removeAttr:function(e){return this.each(function(){x.removeAttr(this,e)})},prop:function(e,t){return x.access(this,x.prop,e,t,arguments.length>1)},removeProp:function(e){return this.each(function(){delete this[x.propFix[e]||e]})},addClass:function(e){var t,n,r,i,o,s=0,a=this.length,u="string"==typeof e&&e;if(x.isFunction(e))return this.each(function(t){x(this).addClass(e.call(this,t,this.className))});if(u)for(t=(e||"").match(w)||[];a>s;s++)if(n=this[s],r=1===n.nodeType&&(n.className?(" "+n.className+" ").replace(W," "):" ")){o=0;while(i=t[o++])0>r.indexOf(" "+i+" ")&&(r+=i+" ");n.className=x.trim(r)}return this},removeClass:function(e){var t,n,r,i,o,s=0,a=this.length,u=0===arguments.length||"string"==typeof e&&e;if(x.isFunction(e))return this.each(function(t){x(this).removeClass(e.call(this,t,this.className))});if(u)for(t=(e||"").match(w)||[];a>s;s++)if(n=this[s],r=1===n.nodeType&&(n.className?(" "+n.className+" ").replace(W," "):"")){o=0;while(i=t[o++])while(r.indexOf(" "+i+" ")>=0)r=r.replace(" "+i+" "," ");n.className=e?x.trim(r):""}return this},toggleClass:function(e,t){var n=typeof e;return"boolean"==typeof t&&"string"===n?t?this.addClass(e):this.removeClass(e):x.isFunction(e)?this.each(function(n){x(this).toggleClass(e.call(this,n,this.className,t),t)}):this.each(function(){if("string"===n){var t,i=0,o=x(this),s=e.match(w)||[];while(t=s[i++])o.hasClass(t)?o.removeClass(t):o.addClass(t)}else(n===r||"boolean"===n)&&(this.className&&q.set(this,"__className__",this.className),this.className=this.className||e===!1?"":q.get(this,"__className__")||"")})},hasClass:function(e){var t=" "+e+" ",n=0,r=this.length;for(;r>n;n++)if(1===this[n].nodeType&&(" "+this[n].className+" ").replace(W," ").indexOf(t)>=0)return!0;return!1},val:function(e){var t,n,r,i=this[0];{if(arguments.length)return r=x.isFunction(e),this.each(function(n){var i;1===this.nodeType&&(i=r?e.call(this,n,x(this).val()):e,null==i?i="":"number"==typeof i?i+="":x.isArray(i)&&(i=x.map(i,function(e){return null==e?"":e+""})),t=x.valHooks[this.type]||x.valHooks[this.nodeName.toLowerCase()],t&&"set"in t&&t.set(this,i,"value")!==undefined||(this.value=i))});if(i)return t=x.valHooks[i.type]||x.valHooks[i.nodeName.toLowerCase()],t&&"get"in t&&(n=t.get(i,"value"))!==undefined?n:(n=i.value,"string"==typeof n?n.replace($,""):null==n?"":n)}}}),x.extend({valHooks:{option:{get:function(e){var t=e.attributes.value;return!t||t.specified?e.value:e.text}},select:{get:function(e){var t,n,r=e.options,i=e.selectedIndex,o="select-one"===e.type||0>i,s=o?null:[],a=o?i+1:r.length,u=0>i?a:o?i:0;for(;a>u;u++)if(n=r[u],!(!n.selected&&u!==i||(x.support.optDisabled?n.disabled:null!==n.getAttribute("disabled"))||n.parentNode.disabled&&x.nodeName(n.parentNode,"optgroup"))){if(t=x(n).val(),o)return t;s.push(t)}return s},set:function(e,t){var n,r,i=e.options,o=x.makeArray(t),s=i.length;while(s--)r=i[s],(r.selected=x.inArray(x(r).val(),o)>=0)&&(n=!0);return n||(e.selectedIndex=-1),o}}},attr:function(e,t,n){var i,o,s=e.nodeType;if(e&&3!==s&&8!==s&&2!==s)return typeof e.getAttribute===r?x.prop(e,t,n):(1===s&&x.isXMLDoc(e)||(t=t.toLowerCase(),i=x.attrHooks[t]||(x.expr.match.bool.test(t)?M:R)),n===undefined?i&&"get"in i&&null!==(o=i.get(e,t))?o:(o=x.find.attr(e,t),null==o?undefined:o):null!==n?i&&"set"in i&&(o=i.set(e,n,t))!==undefined?o:(e.setAttribute(t,n+""),n):(x.removeAttr(e,t),undefined))},removeAttr:function(e,t){var n,r,i=0,o=t&&t.match(w);if(o&&1===e.nodeType)while(n=o[i++])r=x.propFix[n]||n,x.expr.match.bool.test(n)&&(e[r]=!1),e.removeAttribute(n)},attrHooks:{type:{set:function(e,t){if(!x.support.radioValue&&"radio"===t&&x.nodeName(e,"input")){var n=e.value;return e.setAttribute("type",t),n&&(e.value=n),t}}}},propFix:{"for":"htmlFor","class":"className"},prop:function(e,t,n){var r,i,o,s=e.nodeType;if(e&&3!==s&&8!==s&&2!==s)return o=1!==s||!x.isXMLDoc(e),o&&(t=x.propFix[t]||t,i=x.propHooks[t]),n!==undefined?i&&"set"in i&&(r=i.set(e,n,t))!==undefined?r:e[t]=n:i&&"get"in i&&null!==(r=i.get(e,t))?r:e[t]},propHooks:{tabIndex:{get:function(e){return e.hasAttribute("tabindex")||B.test(e.nodeName)||e.href?e.tabIndex:-1}}}}),M={set:function(e,t,n){return t===!1?x.removeAttr(e,n):e.setAttribute(n,n),n}},x.each(x.expr.match.bool.source.match(/\w+/g),function(e,t){var n=x.expr.attrHandle[t]||x.find.attr;x.expr.attrHandle[t]=function(e,t,r){var i=x.expr.attrHandle[t],o=r?undefined:(x.expr.attrHandle[t]=undefined)!=n(e,t,r)?t.toLowerCase():null;return x.expr.attrHandle[t]=i,o}}),x.support.optSelected||(x.propHooks.selected={get:function(e){var t=e.parentNode;return t&&t.parentNode&&t.parentNode.selectedIndex,null}}),x.each(["tabIndex","readOnly","maxLength","cellSpacing","cellPadding","rowSpan","colSpan","useMap","frameBorder","contentEditable"],function(){x.propFix[this.toLowerCase()]=this}),x.each(["radio","checkbox"],function(){x.valHooks[this]={set:function(e,t){return x.isArray(t)?e.checked=x.inArray(x(e).val(),t)>=0:undefined}},x.support.checkOn||(x.valHooks[this].get=function(e){return null===e.getAttribute("value")?"on":e.value})});var I=/^key/,z=/^(?:mouse|contextmenu)|click/,_=/^(?:focusinfocus|focusoutblur)$/,X=/^([^.]*)(?:\.(.+)|)$/;function U(){return!0}function Y(){return!1}function V(){try{return o.activeElement}catch(e){}}x.event={global:{},add:function(e,t,n,i,o){var s,a,u,l,c,p,f,h,d,g,m,y=q.get(e);if(y){n.handler&&(s=n,n=s.handler,o=s.selector),n.guid||(n.guid=x.guid++),(l=y.events)||(l=y.events={}),(a=y.handle)||(a=y.handle=function(e){return typeof x===r||e&&x.event.triggered===e.type?undefined:x.event.dispatch.apply(a.elem,arguments)},a.elem=e),t=(t||"").match(w)||[""],c=t.length;while(c--)u=X.exec(t[c])||[],d=m=u[1],g=(u[2]||"").split(".").sort(),d&&(f=x.event.special[d]||{},d=(o?f.delegateType:f.bindType)||d,f=x.event.special[d]||{},p=x.extend({type:d,origType:m,data:i,handler:n,guid:n.guid,selector:o,needsContext:o&&x.expr.match.needsContext.test(o),namespace:g.join(".")},s),(h=l[d])||(h=l[d]=[],h.delegateCount=0,f.setup&&f.setup.call(e,i,g,a)!==!1||e.addEventListener&&e.addEventListener(d,a,!1)),f.add&&(f.add.call(e,p),p.handler.guid||(p.handler.guid=n.guid)),o?h.splice(h.delegateCount++,0,p):h.push(p),x.event.global[d]=!0);e=null}},remove:function(e,t,n,r,i){var o,s,a,u,l,c,p,f,h,d,g,m=q.hasData(e)&&q.get(e);if(m&&(u=m.events)){t=(t||"").match(w)||[""],l=t.length;while(l--)if(a=X.exec(t[l])||[],h=g=a[1],d=(a[2]||"").split(".").sort(),h){p=x.event.special[h]||{},h=(r?p.delegateType:p.bindType)||h,f=u[h]||[],a=a[2]&&RegExp("(^|\\.)"+d.join("\\.(?:.*\\.|)")+"(\\.|$)"),s=o=f.length;while(o--)c=f[o],!i&&g!==c.origType||n&&n.guid!==c.guid||a&&!a.test(c.namespace)||r&&r!==c.selector&&("**"!==r||!c.selector)||(f.splice(o,1),c.selector&&f.delegateCount--,p.remove&&p.remove.call(e,c));s&&!f.length&&(p.teardown&&p.teardown.call(e,d,m.handle)!==!1||x.removeEvent(e,h,m.handle),delete u[h])}else for(h in u)x.event.remove(e,h+t[l],n,r,!0);x.isEmptyObject(u)&&(delete m.handle,q.remove(e,"events"))}},trigger:function(t,n,r,i){var s,a,u,l,c,p,f,h=[r||o],d=y.call(t,"type")?t.type:t,g=y.call(t,"namespace")?t.namespace.split("."):[];if(a=u=r=r||o,3!==r.nodeType&&8!==r.nodeType&&!_.test(d+x.event.triggered)&&(d.indexOf(".")>=0&&(g=d.split("."),d=g.shift(),g.sort()),c=0>d.indexOf(":")&&"on"+d,t=t[x.expando]?t:new x.Event(d,"object"==typeof t&&t),t.isTrigger=i?2:3,t.namespace=g.join("."),t.namespace_re=t.namespace?RegExp("(^|\\.)"+g.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,t.result=undefined,t.target||(t.target=r),n=null==n?[t]:x.makeArray(n,[t]),f=x.event.special[d]||{},i||!f.trigger||f.trigger.apply(r,n)!==!1)){if(!i&&!f.noBubble&&!x.isWindow(r)){for(l=f.delegateType||d,_.test(l+d)||(a=a.parentNode);a;a=a.parentNode)h.push(a),u=a;u===(r.ownerDocument||o)&&h.push(u.defaultView||u.parentWindow||e)}s=0;while((a=h[s++])&&!t.isPropagationStopped())t.type=s>1?l:f.bindType||d,p=(q.get(a,"events")||{})[t.type]&&q.get(a,"handle"),p&&p.apply(a,n),p=c&&a[c],p&&x.acceptData(a)&&p.apply&&p.apply(a,n)===!1&&t.preventDefault();return t.type=d,i||t.isDefaultPrevented()||f._default&&f._default.apply(h.pop(),n)!==!1||!x.acceptData(r)||c&&x.isFunction(r[d])&&!x.isWindow(r)&&(u=r[c],u&&(r[c]=null),x.event.triggered=d,r[d](),x.event.triggered=undefined,u&&(r[c]=u)),t.result}},dispatch:function(e){e=x.event.fix(e);var t,n,r,i,o,s=[],a=d.call(arguments),u=(q.get(this,"events")||{})[e.type]||[],l=x.event.special[e.type]||{};if(a[0]=e,e.delegateTarget=this,!l.preDispatch||l.preDispatch.call(this,e)!==!1){s=x.event.handlers.call(this,e,u),t=0;while((i=s[t++])&&!e.isPropagationStopped()){e.currentTarget=i.elem,n=0;while((o=i.handlers[n++])&&!e.isImmediatePropagationStopped())(!e.namespace_re||e.namespace_re.test(o.namespace))&&(e.handleObj=o,e.data=o.data,r=((x.event.special[o.origType]||{}).handle||o.handler).apply(i.elem,a),r!==undefined&&(e.result=r)===!1&&(e.preventDefault(),e.stopPropagation()))}return l.postDispatch&&l.postDispatch.call(this,e),e.result}},handlers:function(e,t){var n,r,i,o,s=[],a=t.delegateCount,u=e.target;if(a&&u.nodeType&&(!e.button||"click"!==e.type))for(;u!==this;u=u.parentNode||this)if(u.disabled!==!0||"click"!==e.type){for(r=[],n=0;a>n;n++)o=t[n],i=o.selector+" ",r[i]===undefined&&(r[i]=o.needsContext?x(i,this).index(u)>=0:x.find(i,this,null,[u]).length),r[i]&&r.push(o);r.length&&s.push({elem:u,handlers:r})}return t.length>a&&s.push({elem:this,handlers:t.slice(a)}),s},props:"altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),fixHooks:{},keyHooks:{props:"char charCode key keyCode".split(" "),filter:function(e,t){return null==e.which&&(e.which=null!=t.charCode?t.charCode:t.keyCode),e}},mouseHooks:{props:"button buttons clientX clientY offsetX offsetY pageX pageY screenX screenY toElement".split(" "),filter:function(e,t){var n,r,i,s=t.button;return null==e.pageX&&null!=t.clientX&&(n=e.target.ownerDocument||o,r=n.documentElement,i=n.body,e.pageX=t.clientX+(r&&r.scrollLeft||i&&i.scrollLeft||0)-(r&&r.clientLeft||i&&i.clientLeft||0),e.pageY=t.clientY+(r&&r.scrollTop||i&&i.scrollTop||0)-(r&&r.clientTop||i&&i.clientTop||0)),e.which||s===undefined||(e.which=1&s?1:2&s?3:4&s?2:0),e}},fix:function(e){if(e[x.expando])return e;var t,n,r,i=e.type,s=e,a=this.fixHooks[i];a||(this.fixHooks[i]=a=z.test(i)?this.mouseHooks:I.test(i)?this.keyHooks:{}),r=a.props?this.props.concat(a.props):this.props,e=new x.Event(s),t=r.length;while(t--)n=r[t],e[n]=s[n];return e.target||(e.target=o),3===e.target.nodeType&&(e.target=e.target.parentNode),a.filter?a.filter(e,s):e},special:{load:{noBubble:!0},focus:{trigger:function(){return this!==V()&&this.focus?(this.focus(),!1):undefined},delegateType:"focusin"},blur:{trigger:function(){return this===V()&&this.blur?(this.blur(),!1):undefined},delegateType:"focusout"},click:{trigger:function(){return"checkbox"===this.type&&this.click&&x.nodeName(this,"input")?(this.click(),!1):undefined},_default:function(e){return x.nodeName(e.target,"a")}},beforeunload:{postDispatch:function(e){e.result!==undefined&&(e.originalEvent.returnValue=e.result)}}},simulate:function(e,t,n,r){var i=x.extend(new x.Event,n,{type:e,isSimulated:!0,originalEvent:{}});r?x.event.trigger(i,null,t):x.event.dispatch.call(t,i),i.isDefaultPrevented()&&n.preventDefault()}},x.removeEvent=function(e,t,n){e.removeEventListener&&e.removeEventListener(t,n,!1)},x.Event=function(e,t){return this instanceof x.Event?(e&&e.type?(this.originalEvent=e,this.type=e.type,this.isDefaultPrevented=e.defaultPrevented||e.getPreventDefault&&e.getPreventDefault()?U:Y):this.type=e,t&&x.extend(this,t),this.timeStamp=e&&e.timeStamp||x.now(),this[x.expando]=!0,undefined):new x.Event(e,t)},x.Event.prototype={isDefaultPrevented:Y,isPropagationStopped:Y,isImmediatePropagationStopped:Y,preventDefault:function(){var e=this.originalEvent;this.isDefaultPrevented=U,e&&e.preventDefault&&e.preventDefault()},stopPropagation:function(){var e=this.originalEvent;this.isPropagationStopped=U,e&&e.stopPropagation&&e.stopPropagation()},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=U,this.stopPropagation()}},x.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(e,t){x.event.special[e]={delegateType:t,bindType:t,handle:function(e){var n,r=this,i=e.relatedTarget,o=e.handleObj;return(!i||i!==r&&!x.contains(r,i))&&(e.type=o.origType,n=o.handler.apply(this,arguments),e.type=t),n}}}),x.support.focusinBubbles||x.each({focus:"focusin",blur:"focusout"},function(e,t){var n=0,r=function(e){x.event.simulate(t,e.target,x.event.fix(e),!0)};x.event.special[t]={setup:function(){0===n++&&o.addEventListener(e,r,!0)},teardown:function(){0===--n&&o.removeEventListener(e,r,!0)}}}),x.fn.extend({on:function(e,t,n,r,i){var o,s;if("object"==typeof e){"string"!=typeof t&&(n=n||t,t=undefined);for(s in e)this.on(s,t,n,e[s],i);return this}if(null==n&&null==r?(r=t,n=t=undefined):null==r&&("string"==typeof t?(r=n,n=undefined):(r=n,n=t,t=undefined)),r===!1)r=Y;else if(!r)return this;return 1===i&&(o=r,r=function(e){return x().off(e),o.apply(this,arguments)},r.guid=o.guid||(o.guid=x.guid++)),this.each(function(){x.event.add(this,e,r,n,t)})},one:function(e,t,n,r){return this.on(e,t,n,r,1)},off:function(e,t,n){var r,i;if(e&&e.preventDefault&&e.handleObj)return r=e.handleObj,x(e.delegateTarget).off(r.namespace?r.origType+"."+r.namespace:r.origType,r.selector,r.handler),this;if("object"==typeof e){for(i in e)this.off(i,t,e[i]);return this}return(t===!1||"function"==typeof t)&&(n=t,t=undefined),n===!1&&(n=Y),this.each(function(){x.event.remove(this,e,n,t)})},trigger:function(e,t){return this.each(function(){x.event.trigger(e,t,this)})},triggerHandler:function(e,t){var n=this[0];return n?x.event.trigger(e,t,n,!0):undefined}});var G=/^.[^:#\[\.,]*$/,J=/^(?:parents|prev(?:Until|All))/,Q=x.expr.match.needsContext,K={children:!0,contents:!0,next:!0,prev:!0};x.fn.extend({find:function(e){var t,n=[],r=this,i=r.length;if("string"!=typeof e)return this.pushStack(x(e).filter(function(){for(t=0;i>t;t++)if(x.contains(r[t],this))return!0}));for(t=0;i>t;t++)x.find(e,r[t],n);return n=this.pushStack(i>1?x.unique(n):n),n.selector=this.selector?this.selector+" "+e:e,n},has:function(e){var t=x(e,this),n=t.length;return this.filter(function(){var e=0;for(;n>e;e++)if(x.contains(this,t[e]))return!0})},not:function(e){return this.pushStack(et(this,e||[],!0))},filter:function(e){return this.pushStack(et(this,e||[],!1))},is:function(e){return!!et(this,"string"==typeof e&&Q.test(e)?x(e):e||[],!1).length},closest:function(e,t){var n,r=0,i=this.length,o=[],s=Q.test(e)||"string"!=typeof e?x(e,t||this.context):0;for(;i>r;r++)for(n=this[r];n&&n!==t;n=n.parentNode)if(11>n.nodeType&&(s?s.index(n)>-1:1===n.nodeType&&x.find.matchesSelector(n,e))){n=o.push(n);break}return this.pushStack(o.length>1?x.unique(o):o)},index:function(e){return e?"string"==typeof e?g.call(x(e),this[0]):g.call(this,e.jquery?e[0]:e):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(e,t){var n="string"==typeof e?x(e,t):x.makeArray(e&&e.nodeType?[e]:e),r=x.merge(this.get(),n);return this.pushStack(x.unique(r))},addBack:function(e){return this.add(null==e?this.prevObject:this.prevObject.filter(e))}});function Z(e,t){while((e=e[t])&&1!==e.nodeType);return e}x.each({parent:function(e){var t=e.parentNode;return t&&11!==t.nodeType?t:null},parents:function(e){return x.dir(e,"parentNode")},parentsUntil:function(e,t,n){return x.dir(e,"parentNode",n)},next:function(e){return Z(e,"nextSibling")},prev:function(e){return Z(e,"previousSibling")},nextAll:function(e){return x.dir(e,"nextSibling")},prevAll:function(e){return x.dir(e,"previousSibling")},nextUntil:function(e,t,n){return x.dir(e,"nextSibling",n)},prevUntil:function(e,t,n){return x.dir(e,"previousSibling",n)},siblings:function(e){return x.sibling((e.parentNode||{}).firstChild,e)},children:function(e){return x.sibling(e.firstChild)},contents:function(e){return e.contentDocument||x.merge([],e.childNodes)}},function(e,t){x.fn[e]=function(n,r){var i=x.map(this,t,n);return"Until"!==e.slice(-5)&&(r=n),r&&"string"==typeof r&&(i=x.filter(r,i)),this.length>1&&(K[e]||x.unique(i),J.test(e)&&i.reverse()),this.pushStack(i)}}),x.extend({filter:function(e,t,n){var r=t[0];return n&&(e=":not("+e+")"),1===t.length&&1===r.nodeType?x.find.matchesSelector(r,e)?[r]:[]:x.find.matches(e,x.grep(t,function(e){return 1===e.nodeType}))},dir:function(e,t,n){var r=[],i=n!==undefined;while((e=e[t])&&9!==e.nodeType)if(1===e.nodeType){if(i&&x(e).is(n))break;r.push(e)}return r},sibling:function(e,t){var n=[];for(;e;e=e.nextSibling)1===e.nodeType&&e!==t&&n.push(e);return n}});function et(e,t,n){if(x.isFunction(t))return x.grep(e,function(e,r){return!!t.call(e,r,e)!==n});if(t.nodeType)return x.grep(e,function(e){return e===t!==n});if("string"==typeof t){if(G.test(t))return x.filter(t,e,n);t=x.filter(t,e)}return x.grep(e,function(e){return g.call(t,e)>=0!==n})}var tt=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,nt=/<([\w:]+)/,rt=/<|&#?\w+;/,it=/<(?:script|style|link)/i,ot=/^(?:checkbox|radio)$/i,st=/checked\s*(?:[^=]|=\s*.checked.)/i,at=/^$|\/(?:java|ecma)script/i,ut=/^true\/(.*)/,lt=/^\s*\s*$/g,ct={option:[1,""],thead:[1,"","
"],col:[2,"","
"],tr:[2,"","
"],td:[3,"","
"],_default:[0,"",""]};ct.optgroup=ct.option,ct.tbody=ct.tfoot=ct.colgroup=ct.caption=ct.thead,ct.th=ct.td,x.fn.extend({text:function(e){return x.access(this,function(e){return e===undefined?x.text(this):this.empty().append((this[0]&&this[0].ownerDocument||o).createTextNode(e))},null,e,arguments.length)},append:function(){return this.domManip(arguments,function(e){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var t=pt(this,e);t.appendChild(e)}})},prepend:function(){return this.domManip(arguments,function(e){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var t=pt(this,e);t.insertBefore(e,t.firstChild)}})},before:function(){return this.domManip(arguments,function(e){this.parentNode&&this.parentNode.insertBefore(e,this)})},after:function(){return this.domManip(arguments,function(e){this.parentNode&&this.parentNode.insertBefore(e,this.nextSibling)})},remove:function(e,t){var n,r=e?x.filter(e,this):this,i=0;for(;null!=(n=r[i]);i++)t||1!==n.nodeType||x.cleanData(mt(n)),n.parentNode&&(t&&x.contains(n.ownerDocument,n)&&dt(mt(n,"script")),n.parentNode.removeChild(n));return this},empty:function(){var e,t=0;for(;null!=(e=this[t]);t++)1===e.nodeType&&(x.cleanData(mt(e,!1)),e.textContent="");return this},clone:function(e,t){return e=null==e?!1:e,t=null==t?e:t,this.map(function(){return x.clone(this,e,t)})},html:function(e){return x.access(this,function(e){var t=this[0]||{},n=0,r=this.length;if(e===undefined&&1===t.nodeType)return t.innerHTML;if("string"==typeof e&&!it.test(e)&&!ct[(nt.exec(e)||["",""])[1].toLowerCase()]){e=e.replace(tt,"<$1>");try{for(;r>n;n++)t=this[n]||{},1===t.nodeType&&(x.cleanData(mt(t,!1)),t.innerHTML=e);t=0}catch(i){}}t&&this.empty().append(e)},null,e,arguments.length)},replaceWith:function(){var e=x.map(this,function(e){return[e.nextSibling,e.parentNode]}),t=0;return this.domManip(arguments,function(n){var r=e[t++],i=e[t++];i&&(r&&r.parentNode!==i&&(r=this.nextSibling),x(this).remove(),i.insertBefore(n,r))},!0),t?this:this.remove()},detach:function(e){return this.remove(e,!0)},domManip:function(e,t,n){e=f.apply([],e);var r,i,o,s,a,u,l=0,c=this.length,p=this,h=c-1,d=e[0],g=x.isFunction(d);if(g||!(1>=c||"string"!=typeof d||x.support.checkClone)&&st.test(d))return this.each(function(r){var i=p.eq(r);g&&(e[0]=d.call(this,r,i.html())),i.domManip(e,t,n)});if(c&&(r=x.buildFragment(e,this[0].ownerDocument,!1,!n&&this),i=r.firstChild,1===r.childNodes.length&&(r=i),i)){for(o=x.map(mt(r,"script"),ft),s=o.length;c>l;l++)a=r,l!==h&&(a=x.clone(a,!0,!0),s&&x.merge(o,mt(a,"script"))),t.call(this[l],a,l);if(s)for(u=o[o.length-1].ownerDocument,x.map(o,ht),l=0;s>l;l++)a=o[l],at.test(a.type||"")&&!q.access(a,"globalEval")&&x.contains(u,a)&&(a.src?x._evalUrl(a.src):x.globalEval(a.textContent.replace(lt,"")))}return this}}),x.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(e,t){x.fn[e]=function(e){var n,r=[],i=x(e),o=i.length-1,s=0;for(;o>=s;s++)n=s===o?this:this.clone(!0),x(i[s])[t](n),h.apply(r,n.get());return this.pushStack(r)}}),x.extend({clone:function(e,t,n){var r,i,o,s,a=e.cloneNode(!0),u=x.contains(e.ownerDocument,e);if(!(x.support.noCloneChecked||1!==e.nodeType&&11!==e.nodeType||x.isXMLDoc(e)))for(s=mt(a),o=mt(e),r=0,i=o.length;i>r;r++)yt(o[r],s[r]);if(t)if(n)for(o=o||mt(e),s=s||mt(a),r=0,i=o.length;i>r;r++)gt(o[r],s[r]);else gt(e,a);return s=mt(a,"script"),s.length>0&&dt(s,!u&&mt(e,"script")),a},buildFragment:function(e,t,n,r){var i,o,s,a,u,l,c=0,p=e.length,f=t.createDocumentFragment(),h=[];for(;p>c;c++)if(i=e[c],i||0===i)if("object"===x.type(i))x.merge(h,i.nodeType?[i]:i);else if(rt.test(i)){o=o||f.appendChild(t.createElement("div")),s=(nt.exec(i)||["",""])[1].toLowerCase(),a=ct[s]||ct._default,o.innerHTML=a[1]+i.replace(tt,"<$1>")+a[2],l=a[0];while(l--)o=o.lastChild;x.merge(h,o.childNodes),o=f.firstChild,o.textContent=""}else h.push(t.createTextNode(i));f.textContent="",c=0;while(i=h[c++])if((!r||-1===x.inArray(i,r))&&(u=x.contains(i.ownerDocument,i),o=mt(f.appendChild(i),"script"),u&&dt(o),n)){l=0;while(i=o[l++])at.test(i.type||"")&&n.push(i)}return f},cleanData:function(e){var t,n,r,i,o,s,a=x.event.special,u=0;for(;(n=e[u])!==undefined;u++){if(F.accepts(n)&&(o=n[q.expando],o&&(t=q.cache[o]))){if(r=Object.keys(t.events||{}),r.length)for(s=0;(i=r[s])!==undefined;s++)a[i]?x.event.remove(n,i):x.removeEvent(n,i,t.handle);q.cache[o]&&delete q.cache[o]}delete L.cache[n[L.expando]]}},_evalUrl:function(e){return x.ajax({url:e,type:"GET",dataType:"script",async:!1,global:!1,"throws":!0})}});function pt(e,t){return x.nodeName(e,"table")&&x.nodeName(1===t.nodeType?t:t.firstChild,"tr")?e.getElementsByTagName("tbody")[0]||e.appendChild(e.ownerDocument.createElement("tbody")):e}function ft(e){return e.type=(null!==e.getAttribute("type"))+"/"+e.type,e}function ht(e){var t=ut.exec(e.type);return t?e.type=t[1]:e.removeAttribute("type"),e}function dt(e,t){var n=e.length,r=0;for(;n>r;r++)q.set(e[r],"globalEval",!t||q.get(t[r],"globalEval"))}function gt(e,t){var n,r,i,o,s,a,u,l;if(1===t.nodeType){if(q.hasData(e)&&(o=q.access(e),s=q.set(t,o),l=o.events)){delete s.handle,s.events={};for(i in l)for(n=0,r=l[i].length;r>n;n++)x.event.add(t,i,l[i][n])}L.hasData(e)&&(a=L.access(e),u=x.extend({},a),L.set(t,u))}}function mt(e,t){var n=e.getElementsByTagName?e.getElementsByTagName(t||"*"):e.querySelectorAll?e.querySelectorAll(t||"*"):[];return t===undefined||t&&x.nodeName(e,t)?x.merge([e],n):n}function yt(e,t){var n=t.nodeName.toLowerCase();"input"===n&&ot.test(e.type)?t.checked=e.checked:("input"===n||"textarea"===n)&&(t.defaultValue=e.defaultValue)}x.fn.extend({wrapAll:function(e){var t;return x.isFunction(e)?this.each(function(t){x(this).wrapAll(e.call(this,t))}):(this[0]&&(t=x(e,this[0].ownerDocument).eq(0).clone(!0),this[0].parentNode&&t.insertBefore(this[0]),t.map(function(){var e=this;while(e.firstElementChild)e=e.firstElementChild;return e}).append(this)),this)},wrapInner:function(e){return x.isFunction(e)?this.each(function(t){x(this).wrapInner(e.call(this,t))}):this.each(function(){var t=x(this),n=t.contents();n.length?n.wrapAll(e):t.append(e)})},wrap:function(e){var t=x.isFunction(e);return this.each(function(n){x(this).wrapAll(t?e.call(this,n):e)})},unwrap:function(){return this.parent().each(function(){x.nodeName(this,"body")||x(this).replaceWith(this.childNodes)}).end()}});var vt,xt,bt=/^(none|table(?!-c[ea]).+)/,wt=/^margin/,Tt=RegExp("^("+b+")(.*)$","i"),Ct=RegExp("^("+b+")(?!px)[a-z%]+$","i"),kt=RegExp("^([+-])=("+b+")","i"),Nt={BODY:"block"},Et={position:"absolute",visibility:"hidden",display:"block"},St={letterSpacing:0,fontWeight:400},jt=["Top","Right","Bottom","Left"],Dt=["Webkit","O","Moz","ms"];function At(e,t){if(t in e)return t;var n=t.charAt(0).toUpperCase()+t.slice(1),r=t,i=Dt.length;while(i--)if(t=Dt[i]+n,t in e)return t;return r}function Lt(e,t){return e=t||e,"none"===x.css(e,"display")||!x.contains(e.ownerDocument,e)}function qt(t){return e.getComputedStyle(t,null)}function Ht(e,t){var n,r,i,o=[],s=0,a=e.length;for(;a>s;s++)r=e[s],r.style&&(o[s]=q.get(r,"olddisplay"),n=r.style.display,t?(o[s]||"none"!==n||(r.style.display=""),""===r.style.display&&Lt(r)&&(o[s]=q.access(r,"olddisplay",Rt(r.nodeName)))):o[s]||(i=Lt(r),(n&&"none"!==n||!i)&&q.set(r,"olddisplay",i?n:x.css(r,"display"))));for(s=0;a>s;s++)r=e[s],r.style&&(t&&"none"!==r.style.display&&""!==r.style.display||(r.style.display=t?o[s]||"":"none"));return e}x.fn.extend({css:function(e,t){return x.access(this,function(e,t,n){var r,i,o={},s=0;if(x.isArray(t)){for(r=qt(e),i=t.length;i>s;s++)o[t[s]]=x.css(e,t[s],!1,r);return o}return n!==undefined?x.style(e,t,n):x.css(e,t)},e,t,arguments.length>1)},show:function(){return Ht(this,!0)},hide:function(){return Ht(this)},toggle:function(e){return"boolean"==typeof e?e?this.show():this.hide():this.each(function(){Lt(this)?x(this).show():x(this).hide()})}}),x.extend({cssHooks:{opacity:{get:function(e,t){if(t){var n=vt(e,"opacity");return""===n?"1":n}}}},cssNumber:{columnCount:!0,fillOpacity:!0,fontWeight:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":"cssFloat"},style:function(e,t,n,r){if(e&&3!==e.nodeType&&8!==e.nodeType&&e.style){var i,o,s,a=x.camelCase(t),u=e.style;return t=x.cssProps[a]||(x.cssProps[a]=At(u,a)),s=x.cssHooks[t]||x.cssHooks[a],n===undefined?s&&"get"in s&&(i=s.get(e,!1,r))!==undefined?i:u[t]:(o=typeof n,"string"===o&&(i=kt.exec(n))&&(n=(i[1]+1)*i[2]+parseFloat(x.css(e,t)),o="number"),null==n||"number"===o&&isNaN(n)||("number"!==o||x.cssNumber[a]||(n+="px"),x.support.clearCloneStyle||""!==n||0!==t.indexOf("background")||(u[t]="inherit"),s&&"set"in s&&(n=s.set(e,n,r))===undefined||(u[t]=n)),undefined)}},css:function(e,t,n,r){var i,o,s,a=x.camelCase(t);return t=x.cssProps[a]||(x.cssProps[a]=At(e.style,a)),s=x.cssHooks[t]||x.cssHooks[a],s&&"get"in s&&(i=s.get(e,!0,n)),i===undefined&&(i=vt(e,t,r)),"normal"===i&&t in St&&(i=St[t]),""===n||n?(o=parseFloat(i),n===!0||x.isNumeric(o)?o||0:i):i}}),vt=function(e,t,n){var r,i,o,s=n||qt(e),a=s?s.getPropertyValue(t)||s[t]:undefined,u=e.style;return s&&(""!==a||x.contains(e.ownerDocument,e)||(a=x.style(e,t)),Ct.test(a)&&wt.test(t)&&(r=u.width,i=u.minWidth,o=u.maxWidth,u.minWidth=u.maxWidth=u.width=a,a=s.width,u.width=r,u.minWidth=i,u.maxWidth=o)),a};function Ot(e,t,n){var r=Tt.exec(t);return r?Math.max(0,r[1]-(n||0))+(r[2]||"px"):t}function Ft(e,t,n,r,i){var o=n===(r?"border":"content")?4:"width"===t?1:0,s=0;for(;4>o;o+=2)"margin"===n&&(s+=x.css(e,n+jt[o],!0,i)),r?("content"===n&&(s-=x.css(e,"padding"+jt[o],!0,i)),"margin"!==n&&(s-=x.css(e,"border"+jt[o]+"Width",!0,i))):(s+=x.css(e,"padding"+jt[o],!0,i),"padding"!==n&&(s+=x.css(e,"border"+jt[o]+"Width",!0,i)));return s}function Pt(e,t,n){var r=!0,i="width"===t?e.offsetWidth:e.offsetHeight,o=qt(e),s=x.support.boxSizing&&"border-box"===x.css(e,"boxSizing",!1,o);if(0>=i||null==i){if(i=vt(e,t,o),(0>i||null==i)&&(i=e.style[t]),Ct.test(i))return i;r=s&&(x.support.boxSizingReliable||i===e.style[t]),i=parseFloat(i)||0}return i+Ft(e,t,n||(s?"border":"content"),r,o)+"px"}function Rt(e){var t=o,n=Nt[e];return n||(n=Mt(e,t),"none"!==n&&n||(xt=(xt||x("