/trunk/src/MyShop.UI.Web.MainSite/Scripts/MicrosoftAjax.debug.js

# · JavaScript · 6850 lines · 6072 code · 113 blank · 665 comment · 1453 complexity · 24cdbf995d405f5d448c89744ce431d7 MD5 · raw file

Large files are truncated click here to view the full file

  1. // Name: MicrosoftAjax.debug.js
  2. // Assembly: System.Web.Extensions
  3. // Version: 3.5.0.0
  4. // FileVersion: 3.5.30729.1
  5. //-----------------------------------------------------------------------
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------
  8. // MicrosoftAjax.js
  9. // Microsoft AJAX Framework.
  10. Function.__typeName = 'Function';
  11. Function.__class = true;
  12. Function.createCallback = function Function$createCallback(method, context) {
  13. /// <summary locid="M:J#Function.createCallback" />
  14. /// <param name="method" type="Function"></param>
  15. /// <param name="context" mayBeNull="true"></param>
  16. /// <returns type="Function"></returns>
  17. var e = Function._validateParams(arguments, [
  18. {name: "method", type: Function},
  19. {name: "context", mayBeNull: true}
  20. ]);
  21. if (e) throw e;
  22. return function() {
  23. var l = arguments.length;
  24. if (l > 0) {
  25. var args = [];
  26. for (var i = 0; i < l; i++) {
  27. args[i] = arguments[i];
  28. }
  29. args[l] = context;
  30. return method.apply(this, args);
  31. }
  32. return method.call(this, context);
  33. }
  34. }
  35. Function.createDelegate = function Function$createDelegate(instance, method) {
  36. /// <summary locid="M:J#Function.createDelegate" />
  37. /// <param name="instance" mayBeNull="true"></param>
  38. /// <param name="method" type="Function"></param>
  39. /// <returns type="Function"></returns>
  40. var e = Function._validateParams(arguments, [
  41. {name: "instance", mayBeNull: true},
  42. {name: "method", type: Function}
  43. ]);
  44. if (e) throw e;
  45. return function() {
  46. return method.apply(instance, arguments);
  47. }
  48. }
  49. Function.emptyFunction = Function.emptyMethod = function Function$emptyMethod() {
  50. /// <summary locid="M:J#Function.emptyMethod" />
  51. if (arguments.length !== 0) throw Error.parameterCount();
  52. }
  53. Function._validateParams = function Function$_validateParams(params, expectedParams) {
  54. var e;
  55. e = Function._validateParameterCount(params, expectedParams);
  56. if (e) {
  57. e.popStackFrame();
  58. return e;
  59. }
  60. for (var i=0; i < params.length; i++) {
  61. var expectedParam = expectedParams[Math.min(i, expectedParams.length - 1)];
  62. var paramName = expectedParam.name;
  63. if (expectedParam.parameterArray) {
  64. paramName += "[" + (i - expectedParams.length + 1) + "]";
  65. }
  66. e = Function._validateParameter(params[i], expectedParam, paramName);
  67. if (e) {
  68. e.popStackFrame();
  69. return e;
  70. }
  71. }
  72. return null;
  73. }
  74. Function._validateParameterCount = function Function$_validateParameterCount(params, expectedParams) {
  75. var maxParams = expectedParams.length;
  76. var minParams = 0;
  77. for (var i=0; i < expectedParams.length; i++) {
  78. if (expectedParams[i].parameterArray) {
  79. maxParams = Number.MAX_VALUE;
  80. }
  81. else if (!expectedParams[i].optional) {
  82. minParams++;
  83. }
  84. }
  85. if (params.length < minParams || params.length > maxParams) {
  86. var e = Error.parameterCount();
  87. e.popStackFrame();
  88. return e;
  89. }
  90. return null;
  91. }
  92. Function._validateParameter = function Function$_validateParameter(param, expectedParam, paramName) {
  93. var e;
  94. var expectedType = expectedParam.type;
  95. var expectedInteger = !!expectedParam.integer;
  96. var expectedDomElement = !!expectedParam.domElement;
  97. var mayBeNull = !!expectedParam.mayBeNull;
  98. e = Function._validateParameterType(param, expectedType, expectedInteger, expectedDomElement, mayBeNull, paramName);
  99. if (e) {
  100. e.popStackFrame();
  101. return e;
  102. }
  103. var expectedElementType = expectedParam.elementType;
  104. var elementMayBeNull = !!expectedParam.elementMayBeNull;
  105. if (expectedType === Array && typeof(param) !== "undefined" && param !== null &&
  106. (expectedElementType || !elementMayBeNull)) {
  107. var expectedElementInteger = !!expectedParam.elementInteger;
  108. var expectedElementDomElement = !!expectedParam.elementDomElement;
  109. for (var i=0; i < param.length; i++) {
  110. var elem = param[i];
  111. e = Function._validateParameterType(elem, expectedElementType,
  112. expectedElementInteger, expectedElementDomElement, elementMayBeNull,
  113. paramName + "[" + i + "]");
  114. if (e) {
  115. e.popStackFrame();
  116. return e;
  117. }
  118. }
  119. }
  120. return null;
  121. }
  122. Function._validateParameterType = function Function$_validateParameterType(param, expectedType, expectedInteger, expectedDomElement, mayBeNull, paramName) {
  123. var e;
  124. if (typeof(param) === "undefined") {
  125. if (mayBeNull) {
  126. return null;
  127. }
  128. else {
  129. e = Error.argumentUndefined(paramName);
  130. e.popStackFrame();
  131. return e;
  132. }
  133. }
  134. if (param === null) {
  135. if (mayBeNull) {
  136. return null;
  137. }
  138. else {
  139. e = Error.argumentNull(paramName);
  140. e.popStackFrame();
  141. return e;
  142. }
  143. }
  144. if (expectedType && expectedType.__enum) {
  145. if (typeof(param) !== 'number') {
  146. e = Error.argumentType(paramName, Object.getType(param), expectedType);
  147. e.popStackFrame();
  148. return e;
  149. }
  150. if ((param % 1) === 0) {
  151. var values = expectedType.prototype;
  152. if (!expectedType.__flags || (param === 0)) {
  153. for (var i in values) {
  154. if (values[i] === param) return null;
  155. }
  156. }
  157. else {
  158. var v = param;
  159. for (var i in values) {
  160. var vali = values[i];
  161. if (vali === 0) continue;
  162. if ((vali & param) === vali) {
  163. v -= vali;
  164. }
  165. if (v === 0) return null;
  166. }
  167. }
  168. }
  169. e = Error.argumentOutOfRange(paramName, param, String.format(Sys.Res.enumInvalidValue, param, expectedType.getName()));
  170. e.popStackFrame();
  171. return e;
  172. }
  173. if (expectedDomElement) {
  174. var val;
  175. if (typeof(param.nodeType) !== 'number') {
  176. var doc = param.ownerDocument || param.document || param;
  177. if (doc != param) {
  178. var w = doc.defaultView || doc.parentWindow;
  179. val = (w != param) && !(w.document && param.document && (w.document === param.document));
  180. }
  181. else {
  182. val = (typeof(doc.body) === 'undefined');
  183. }
  184. }
  185. else {
  186. val = (param.nodeType === 3);
  187. }
  188. if (val) {
  189. e = Error.argument(paramName, Sys.Res.argumentDomElement);
  190. e.popStackFrame();
  191. return e;
  192. }
  193. }
  194. if (expectedType && !expectedType.isInstanceOfType(param)) {
  195. e = Error.argumentType(paramName, Object.getType(param), expectedType);
  196. e.popStackFrame();
  197. return e;
  198. }
  199. if (expectedType === Number && expectedInteger) {
  200. if ((param % 1) !== 0) {
  201. e = Error.argumentOutOfRange(paramName, param, Sys.Res.argumentInteger);
  202. e.popStackFrame();
  203. return e;
  204. }
  205. }
  206. return null;
  207. }
  208. Error.__typeName = 'Error';
  209. Error.__class = true;
  210. Error.create = function Error$create(message, errorInfo) {
  211. /// <summary locid="M:J#Error.create" />
  212. /// <param name="message" type="String" optional="true" mayBeNull="true"></param>
  213. /// <param name="errorInfo" optional="true" mayBeNull="true"></param>
  214. /// <returns type="Error"></returns>
  215. var e = Function._validateParams(arguments, [
  216. {name: "message", type: String, mayBeNull: true, optional: true},
  217. {name: "errorInfo", mayBeNull: true, optional: true}
  218. ]);
  219. if (e) throw e;
  220. var e = new Error(message);
  221. e.message = message;
  222. if (errorInfo) {
  223. for (var v in errorInfo) {
  224. e[v] = errorInfo[v];
  225. }
  226. }
  227. e.popStackFrame();
  228. return e;
  229. }
  230. Error.argument = function Error$argument(paramName, message) {
  231. /// <summary locid="M:J#Error.argument" />
  232. /// <param name="paramName" type="String" optional="true" mayBeNull="true"></param>
  233. /// <param name="message" type="String" optional="true" mayBeNull="true"></param>
  234. /// <returns></returns>
  235. var e = Function._validateParams(arguments, [
  236. {name: "paramName", type: String, mayBeNull: true, optional: true},
  237. {name: "message", type: String, mayBeNull: true, optional: true}
  238. ]);
  239. if (e) throw e;
  240. var displayMessage = "Sys.ArgumentException: " + (message ? message : Sys.Res.argument);
  241. if (paramName) {
  242. displayMessage += "\n" + String.format(Sys.Res.paramName, paramName);
  243. }
  244. var e = Error.create(displayMessage, { name: "Sys.ArgumentException", paramName: paramName });
  245. e.popStackFrame();
  246. return e;
  247. }
  248. Error.argumentNull = function Error$argumentNull(paramName, message) {
  249. /// <summary locid="M:J#Error.argumentNull" />
  250. /// <param name="paramName" type="String" optional="true" mayBeNull="true"></param>
  251. /// <param name="message" type="String" optional="true" mayBeNull="true"></param>
  252. /// <returns></returns>
  253. var e = Function._validateParams(arguments, [
  254. {name: "paramName", type: String, mayBeNull: true, optional: true},
  255. {name: "message", type: String, mayBeNull: true, optional: true}
  256. ]);
  257. if (e) throw e;
  258. var displayMessage = "Sys.ArgumentNullException: " + (message ? message : Sys.Res.argumentNull);
  259. if (paramName) {
  260. displayMessage += "\n" + String.format(Sys.Res.paramName, paramName);
  261. }
  262. var e = Error.create(displayMessage, { name: "Sys.ArgumentNullException", paramName: paramName });
  263. e.popStackFrame();
  264. return e;
  265. }
  266. Error.argumentOutOfRange = function Error$argumentOutOfRange(paramName, actualValue, message) {
  267. /// <summary locid="M:J#Error.argumentOutOfRange" />
  268. /// <param name="paramName" type="String" optional="true" mayBeNull="true"></param>
  269. /// <param name="actualValue" optional="true" mayBeNull="true"></param>
  270. /// <param name="message" type="String" optional="true" mayBeNull="true"></param>
  271. /// <returns></returns>
  272. var e = Function._validateParams(arguments, [
  273. {name: "paramName", type: String, mayBeNull: true, optional: true},
  274. {name: "actualValue", mayBeNull: true, optional: true},
  275. {name: "message", type: String, mayBeNull: true, optional: true}
  276. ]);
  277. if (e) throw e;
  278. var displayMessage = "Sys.ArgumentOutOfRangeException: " + (message ? message : Sys.Res.argumentOutOfRange);
  279. if (paramName) {
  280. displayMessage += "\n" + String.format(Sys.Res.paramName, paramName);
  281. }
  282. if (typeof(actualValue) !== "undefined" && actualValue !== null) {
  283. displayMessage += "\n" + String.format(Sys.Res.actualValue, actualValue);
  284. }
  285. var e = Error.create(displayMessage, {
  286. name: "Sys.ArgumentOutOfRangeException",
  287. paramName: paramName,
  288. actualValue: actualValue
  289. });
  290. e.popStackFrame();
  291. return e;
  292. }
  293. Error.argumentType = function Error$argumentType(paramName, actualType, expectedType, message) {
  294. /// <summary locid="M:J#Error.argumentType" />
  295. /// <param name="paramName" type="String" optional="true" mayBeNull="true"></param>
  296. /// <param name="actualType" type="Type" optional="true" mayBeNull="true"></param>
  297. /// <param name="expectedType" type="Type" optional="true" mayBeNull="true"></param>
  298. /// <param name="message" type="String" optional="true" mayBeNull="true"></param>
  299. /// <returns></returns>
  300. var e = Function._validateParams(arguments, [
  301. {name: "paramName", type: String, mayBeNull: true, optional: true},
  302. {name: "actualType", type: Type, mayBeNull: true, optional: true},
  303. {name: "expectedType", type: Type, mayBeNull: true, optional: true},
  304. {name: "message", type: String, mayBeNull: true, optional: true}
  305. ]);
  306. if (e) throw e;
  307. var displayMessage = "Sys.ArgumentTypeException: ";
  308. if (message) {
  309. displayMessage += message;
  310. }
  311. else if (actualType && expectedType) {
  312. displayMessage +=
  313. String.format(Sys.Res.argumentTypeWithTypes, actualType.getName(), expectedType.getName());
  314. }
  315. else {
  316. displayMessage += Sys.Res.argumentType;
  317. }
  318. if (paramName) {
  319. displayMessage += "\n" + String.format(Sys.Res.paramName, paramName);
  320. }
  321. var e = Error.create(displayMessage, {
  322. name: "Sys.ArgumentTypeException",
  323. paramName: paramName,
  324. actualType: actualType,
  325. expectedType: expectedType
  326. });
  327. e.popStackFrame();
  328. return e;
  329. }
  330. Error.argumentUndefined = function Error$argumentUndefined(paramName, message) {
  331. /// <summary locid="M:J#Error.argumentUndefined" />
  332. /// <param name="paramName" type="String" optional="true" mayBeNull="true"></param>
  333. /// <param name="message" type="String" optional="true" mayBeNull="true"></param>
  334. /// <returns></returns>
  335. var e = Function._validateParams(arguments, [
  336. {name: "paramName", type: String, mayBeNull: true, optional: true},
  337. {name: "message", type: String, mayBeNull: true, optional: true}
  338. ]);
  339. if (e) throw e;
  340. var displayMessage = "Sys.ArgumentUndefinedException: " + (message ? message : Sys.Res.argumentUndefined);
  341. if (paramName) {
  342. displayMessage += "\n" + String.format(Sys.Res.paramName, paramName);
  343. }
  344. var e = Error.create(displayMessage, { name: "Sys.ArgumentUndefinedException", paramName: paramName });
  345. e.popStackFrame();
  346. return e;
  347. }
  348. Error.format = function Error$format(message) {
  349. /// <summary locid="M:J#Error.format" />
  350. /// <param name="message" type="String" optional="true" mayBeNull="true"></param>
  351. /// <returns></returns>
  352. var e = Function._validateParams(arguments, [
  353. {name: "message", type: String, mayBeNull: true, optional: true}
  354. ]);
  355. if (e) throw e;
  356. var displayMessage = "Sys.FormatException: " + (message ? message : Sys.Res.format);
  357. var e = Error.create(displayMessage, {name: 'Sys.FormatException'});
  358. e.popStackFrame();
  359. return e;
  360. }
  361. Error.invalidOperation = function Error$invalidOperation(message) {
  362. /// <summary locid="M:J#Error.invalidOperation" />
  363. /// <param name="message" type="String" optional="true" mayBeNull="true"></param>
  364. /// <returns></returns>
  365. var e = Function._validateParams(arguments, [
  366. {name: "message", type: String, mayBeNull: true, optional: true}
  367. ]);
  368. if (e) throw e;
  369. var displayMessage = "Sys.InvalidOperationException: " + (message ? message : Sys.Res.invalidOperation);
  370. var e = Error.create(displayMessage, {name: 'Sys.InvalidOperationException'});
  371. e.popStackFrame();
  372. return e;
  373. }
  374. Error.notImplemented = function Error$notImplemented(message) {
  375. /// <summary locid="M:J#Error.notImplemented" />
  376. /// <param name="message" type="String" optional="true" mayBeNull="true"></param>
  377. /// <returns></returns>
  378. var e = Function._validateParams(arguments, [
  379. {name: "message", type: String, mayBeNull: true, optional: true}
  380. ]);
  381. if (e) throw e;
  382. var displayMessage = "Sys.NotImplementedException: " + (message ? message : Sys.Res.notImplemented);
  383. var e = Error.create(displayMessage, {name: 'Sys.NotImplementedException'});
  384. e.popStackFrame();
  385. return e;
  386. }
  387. Error.parameterCount = function Error$parameterCount(message) {
  388. /// <summary locid="M:J#Error.parameterCount" />
  389. /// <param name="message" type="String" optional="true" mayBeNull="true"></param>
  390. /// <returns></returns>
  391. var e = Function._validateParams(arguments, [
  392. {name: "message", type: String, mayBeNull: true, optional: true}
  393. ]);
  394. if (e) throw e;
  395. var displayMessage = "Sys.ParameterCountException: " + (message ? message : Sys.Res.parameterCount);
  396. var e = Error.create(displayMessage, {name: 'Sys.ParameterCountException'});
  397. e.popStackFrame();
  398. return e;
  399. }
  400. Error.prototype.popStackFrame = function Error$popStackFrame() {
  401. /// <summary locid="M:J#checkParam" />
  402. if (arguments.length !== 0) throw Error.parameterCount();
  403. if (typeof(this.stack) === "undefined" || this.stack === null ||
  404. typeof(this.fileName) === "undefined" || this.fileName === null ||
  405. typeof(this.lineNumber) === "undefined" || this.lineNumber === null) {
  406. return;
  407. }
  408. var stackFrames = this.stack.split("\n");
  409. var currentFrame = stackFrames[0];
  410. var pattern = this.fileName + ":" + this.lineNumber;
  411. while(typeof(currentFrame) !== "undefined" &&
  412. currentFrame !== null &&
  413. currentFrame.indexOf(pattern) === -1) {
  414. stackFrames.shift();
  415. currentFrame = stackFrames[0];
  416. }
  417. var nextFrame = stackFrames[1];
  418. if (typeof(nextFrame) === "undefined" || nextFrame === null) {
  419. return;
  420. }
  421. var nextFrameParts = nextFrame.match(/@(.*):(\d+)$/);
  422. if (typeof(nextFrameParts) === "undefined" || nextFrameParts === null) {
  423. return;
  424. }
  425. this.fileName = nextFrameParts[1];
  426. this.lineNumber = parseInt(nextFrameParts[2]);
  427. stackFrames.shift();
  428. this.stack = stackFrames.join("\n");
  429. }
  430. Object.__typeName = 'Object';
  431. Object.__class = true;
  432. Object.getType = function Object$getType(instance) {
  433. /// <summary locid="M:J#Object.getType" />
  434. /// <param name="instance"></param>
  435. /// <returns type="Type"></returns>
  436. var e = Function._validateParams(arguments, [
  437. {name: "instance"}
  438. ]);
  439. if (e) throw e;
  440. var ctor = instance.constructor;
  441. if (!ctor || (typeof(ctor) !== "function") || !ctor.__typeName || (ctor.__typeName === 'Object')) {
  442. return Object;
  443. }
  444. return ctor;
  445. }
  446. Object.getTypeName = function Object$getTypeName(instance) {
  447. /// <summary locid="M:J#Object.getTypeName" />
  448. /// <param name="instance"></param>
  449. /// <returns type="String"></returns>
  450. var e = Function._validateParams(arguments, [
  451. {name: "instance"}
  452. ]);
  453. if (e) throw e;
  454. return Object.getType(instance).getName();
  455. }
  456. String.__typeName = 'String';
  457. String.__class = true;
  458. String.prototype.endsWith = function String$endsWith(suffix) {
  459. /// <summary locid="M:J#String.endsWith" />
  460. /// <param name="suffix" type="String"></param>
  461. /// <returns type="Boolean"></returns>
  462. var e = Function._validateParams(arguments, [
  463. {name: "suffix", type: String}
  464. ]);
  465. if (e) throw e;
  466. return (this.substr(this.length - suffix.length) === suffix);
  467. }
  468. String.prototype.startsWith = function String$startsWith(prefix) {
  469. /// <summary locid="M:J#String.startsWith" />
  470. /// <param name="prefix" type="String"></param>
  471. /// <returns type="Boolean"></returns>
  472. var e = Function._validateParams(arguments, [
  473. {name: "prefix", type: String}
  474. ]);
  475. if (e) throw e;
  476. return (this.substr(0, prefix.length) === prefix);
  477. }
  478. String.prototype.trim = function String$trim() {
  479. /// <summary locid="M:J#String.trim" />
  480. /// <returns type="String"></returns>
  481. if (arguments.length !== 0) throw Error.parameterCount();
  482. return this.replace(/^\s+|\s+$/g, '');
  483. }
  484. String.prototype.trimEnd = function String$trimEnd() {
  485. /// <summary locid="M:J#String.trimEnd" />
  486. /// <returns type="String"></returns>
  487. if (arguments.length !== 0) throw Error.parameterCount();
  488. return this.replace(/\s+$/, '');
  489. }
  490. String.prototype.trimStart = function String$trimStart() {
  491. /// <summary locid="M:J#String.trimStart" />
  492. /// <returns type="String"></returns>
  493. if (arguments.length !== 0) throw Error.parameterCount();
  494. return this.replace(/^\s+/, '');
  495. }
  496. String.format = function String$format(format, args) {
  497. /// <summary locid="M:J#String.format" />
  498. /// <param name="format" type="String"></param>
  499. /// <param name="args" parameterArray="true" mayBeNull="true"></param>
  500. /// <returns type="String"></returns>
  501. var e = Function._validateParams(arguments, [
  502. {name: "format", type: String},
  503. {name: "args", mayBeNull: true, parameterArray: true}
  504. ]);
  505. if (e) throw e;
  506. return String._toFormattedString(false, arguments);
  507. }
  508. String.localeFormat = function String$localeFormat(format, args) {
  509. /// <summary locid="M:J#String.localeFormat" />
  510. /// <param name="format" type="String"></param>
  511. /// <param name="args" parameterArray="true" mayBeNull="true"></param>
  512. /// <returns type="String"></returns>
  513. var e = Function._validateParams(arguments, [
  514. {name: "format", type: String},
  515. {name: "args", mayBeNull: true, parameterArray: true}
  516. ]);
  517. if (e) throw e;
  518. return String._toFormattedString(true, arguments);
  519. }
  520. String._toFormattedString = function String$_toFormattedString(useLocale, args) {
  521. var result = '';
  522. var format = args[0];
  523. for (var i=0;;) {
  524. var open = format.indexOf('{', i);
  525. var close = format.indexOf('}', i);
  526. if ((open < 0) && (close < 0)) {
  527. result += format.slice(i);
  528. break;
  529. }
  530. if ((close > 0) && ((close < open) || (open < 0))) {
  531. if (format.charAt(close + 1) !== '}') {
  532. throw Error.argument('format', Sys.Res.stringFormatBraceMismatch);
  533. }
  534. result += format.slice(i, close + 1);
  535. i = close + 2;
  536. continue;
  537. }
  538. result += format.slice(i, open);
  539. i = open + 1;
  540. if (format.charAt(i) === '{') {
  541. result += '{';
  542. i++;
  543. continue;
  544. }
  545. if (close < 0) throw Error.argument('format', Sys.Res.stringFormatBraceMismatch);
  546. var brace = format.substring(i, close);
  547. var colonIndex = brace.indexOf(':');
  548. var argNumber = parseInt((colonIndex < 0)? brace : brace.substring(0, colonIndex), 10) + 1;
  549. if (isNaN(argNumber)) throw Error.argument('format', Sys.Res.stringFormatInvalid);
  550. var argFormat = (colonIndex < 0)? '' : brace.substring(colonIndex + 1);
  551. var arg = args[argNumber];
  552. if (typeof(arg) === "undefined" || arg === null) {
  553. arg = '';
  554. }
  555. if (arg.toFormattedString) {
  556. result += arg.toFormattedString(argFormat);
  557. }
  558. else if (useLocale && arg.localeFormat) {
  559. result += arg.localeFormat(argFormat);
  560. }
  561. else if (arg.format) {
  562. result += arg.format(argFormat);
  563. }
  564. else
  565. result += arg.toString();
  566. i = close + 1;
  567. }
  568. return result;
  569. }
  570. Boolean.__typeName = 'Boolean';
  571. Boolean.__class = true;
  572. Boolean.parse = function Boolean$parse(value) {
  573. /// <summary locid="M:J#Boolean.parse" />
  574. /// <param name="value" type="String"></param>
  575. /// <returns type="Boolean"></returns>
  576. var e = Function._validateParams(arguments, [
  577. {name: "value", type: String}
  578. ]);
  579. if (e) throw e;
  580. var v = value.trim().toLowerCase();
  581. if (v === 'false') return false;
  582. if (v === 'true') return true;
  583. throw Error.argumentOutOfRange('value', value, Sys.Res.boolTrueOrFalse);
  584. }
  585. Date.__typeName = 'Date';
  586. Date.__class = true;
  587. Date._appendPreOrPostMatch = function Date$_appendPreOrPostMatch(preMatch, strBuilder) {
  588. var quoteCount = 0;
  589. var escaped = false;
  590. for (var i = 0, il = preMatch.length; i < il; i++) {
  591. var c = preMatch.charAt(i);
  592. switch (c) {
  593. case '\'':
  594. if (escaped) strBuilder.append("'");
  595. else quoteCount++;
  596. escaped = false;
  597. break;
  598. case '\\':
  599. if (escaped) strBuilder.append("\\");
  600. escaped = !escaped;
  601. break;
  602. default:
  603. strBuilder.append(c);
  604. escaped = false;
  605. break;
  606. }
  607. }
  608. return quoteCount;
  609. }
  610. Date._expandFormat = function Date$_expandFormat(dtf, format) {
  611. if (!format) {
  612. format = "F";
  613. }
  614. if (format.length === 1) {
  615. switch (format) {
  616. case "d":
  617. return dtf.ShortDatePattern;
  618. case "D":
  619. return dtf.LongDatePattern;
  620. case "t":
  621. return dtf.ShortTimePattern;
  622. case "T":
  623. return dtf.LongTimePattern;
  624. case "F":
  625. return dtf.FullDateTimePattern;
  626. case "M": case "m":
  627. return dtf.MonthDayPattern;
  628. case "s":
  629. return dtf.SortableDateTimePattern;
  630. case "Y": case "y":
  631. return dtf.YearMonthPattern;
  632. default:
  633. throw Error.format(Sys.Res.formatInvalidString);
  634. }
  635. }
  636. return format;
  637. }
  638. Date._expandYear = function Date$_expandYear(dtf, year) {
  639. if (year < 100) {
  640. var curr = new Date().getFullYear();
  641. year += curr - (curr % 100);
  642. if (year > dtf.Calendar.TwoDigitYearMax) {
  643. return year - 100;
  644. }
  645. }
  646. return year;
  647. }
  648. Date._getParseRegExp = function Date$_getParseRegExp(dtf, format) {
  649. if (!dtf._parseRegExp) {
  650. dtf._parseRegExp = {};
  651. }
  652. else if (dtf._parseRegExp[format]) {
  653. return dtf._parseRegExp[format];
  654. }
  655. var expFormat = Date._expandFormat(dtf, format);
  656. expFormat = expFormat.replace(/([\^\$\.\*\+\?\|\[\]\(\)\{\}])/g, "\\\\$1");
  657. var regexp = new Sys.StringBuilder("^");
  658. var groups = [];
  659. var index = 0;
  660. var quoteCount = 0;
  661. var tokenRegExp = Date._getTokenRegExp();
  662. var match;
  663. while ((match = tokenRegExp.exec(expFormat)) !== null) {
  664. var preMatch = expFormat.slice(index, match.index);
  665. index = tokenRegExp.lastIndex;
  666. quoteCount += Date._appendPreOrPostMatch(preMatch, regexp);
  667. if ((quoteCount%2) === 1) {
  668. regexp.append(match[0]);
  669. continue;
  670. }
  671. switch (match[0]) {
  672. case 'dddd': case 'ddd':
  673. case 'MMMM': case 'MMM':
  674. regexp.append("(\\D+)");
  675. break;
  676. case 'tt': case 't':
  677. regexp.append("(\\D*)");
  678. break;
  679. case 'yyyy':
  680. regexp.append("(\\d{4})");
  681. break;
  682. case 'fff':
  683. regexp.append("(\\d{3})");
  684. break;
  685. case 'ff':
  686. regexp.append("(\\d{2})");
  687. break;
  688. case 'f':
  689. regexp.append("(\\d)");
  690. break;
  691. case 'dd': case 'd':
  692. case 'MM': case 'M':
  693. case 'yy': case 'y':
  694. case 'HH': case 'H':
  695. case 'hh': case 'h':
  696. case 'mm': case 'm':
  697. case 'ss': case 's':
  698. regexp.append("(\\d\\d?)");
  699. break;
  700. case 'zzz':
  701. regexp.append("([+-]?\\d\\d?:\\d{2})");
  702. break;
  703. case 'zz': case 'z':
  704. regexp.append("([+-]?\\d\\d?)");
  705. break;
  706. }
  707. Array.add(groups, match[0]);
  708. }
  709. Date._appendPreOrPostMatch(expFormat.slice(index), regexp);
  710. regexp.append("$");
  711. var regexpStr = regexp.toString().replace(/\s+/g, "\\s+");
  712. var parseRegExp = {'regExp': regexpStr, 'groups': groups};
  713. dtf._parseRegExp[format] = parseRegExp;
  714. return parseRegExp;
  715. }
  716. Date._getTokenRegExp = function Date$_getTokenRegExp() {
  717. return /dddd|ddd|dd|d|MMMM|MMM|MM|M|yyyy|yy|y|hh|h|HH|H|mm|m|ss|s|tt|t|fff|ff|f|zzz|zz|z/g;
  718. }
  719. Date.parseLocale = function Date$parseLocale(value, formats) {
  720. /// <summary locid="M:J#Date.parseLocale" />
  721. /// <param name="value" type="String"></param>
  722. /// <param name="formats" parameterArray="true" optional="true" mayBeNull="true"></param>
  723. /// <returns type="Date"></returns>
  724. var e = Function._validateParams(arguments, [
  725. {name: "value", type: String},
  726. {name: "formats", mayBeNull: true, optional: true, parameterArray: true}
  727. ]);
  728. if (e) throw e;
  729. return Date._parse(value, Sys.CultureInfo.CurrentCulture, arguments);
  730. }
  731. Date.parseInvariant = function Date$parseInvariant(value, formats) {
  732. /// <summary locid="M:J#Date.parseInvariant" />
  733. /// <param name="value" type="String"></param>
  734. /// <param name="formats" parameterArray="true" optional="true" mayBeNull="true"></param>
  735. /// <returns type="Date"></returns>
  736. var e = Function._validateParams(arguments, [
  737. {name: "value", type: String},
  738. {name: "formats", mayBeNull: true, optional: true, parameterArray: true}
  739. ]);
  740. if (e) throw e;
  741. return Date._parse(value, Sys.CultureInfo.InvariantCulture, arguments);
  742. }
  743. Date._parse = function Date$_parse(value, cultureInfo, args) {
  744. var custom = false;
  745. for (var i = 1, il = args.length; i < il; i++) {
  746. var format = args[i];
  747. if (format) {
  748. custom = true;
  749. var date = Date._parseExact(value, format, cultureInfo);
  750. if (date) return date;
  751. }
  752. }
  753. if (! custom) {
  754. var formats = cultureInfo._getDateTimeFormats();
  755. for (var i = 0, il = formats.length; i < il; i++) {
  756. var date = Date._parseExact(value, formats[i], cultureInfo);
  757. if (date) return date;
  758. }
  759. }
  760. return null;
  761. }
  762. Date._parseExact = function Date$_parseExact(value, format, cultureInfo) {
  763. value = value.trim();
  764. var dtf = cultureInfo.dateTimeFormat;
  765. var parseInfo = Date._getParseRegExp(dtf, format);
  766. var match = new RegExp(parseInfo.regExp).exec(value);
  767. if (match === null) return null;
  768. var groups = parseInfo.groups;
  769. var year = null, month = null, date = null, weekDay = null;
  770. var hour = 0, min = 0, sec = 0, msec = 0, tzMinOffset = null;
  771. var pmHour = false;
  772. for (var j = 0, jl = groups.length; j < jl; j++) {
  773. var matchGroup = match[j+1];
  774. if (matchGroup) {
  775. switch (groups[j]) {
  776. case 'dd': case 'd':
  777. date = parseInt(matchGroup, 10);
  778. if ((date < 1) || (date > 31)) return null;
  779. break;
  780. case 'MMMM':
  781. month = cultureInfo._getMonthIndex(matchGroup);
  782. if ((month < 0) || (month > 11)) return null;
  783. break;
  784. case 'MMM':
  785. month = cultureInfo._getAbbrMonthIndex(matchGroup);
  786. if ((month < 0) || (month > 11)) return null;
  787. break;
  788. case 'M': case 'MM':
  789. var month = parseInt(matchGroup, 10) - 1;
  790. if ((month < 0) || (month > 11)) return null;
  791. break;
  792. case 'y': case 'yy':
  793. year = Date._expandYear(dtf,parseInt(matchGroup, 10));
  794. if ((year < 0) || (year > 9999)) return null;
  795. break;
  796. case 'yyyy':
  797. year = parseInt(matchGroup, 10);
  798. if ((year < 0) || (year > 9999)) return null;
  799. break;
  800. case 'h': case 'hh':
  801. hour = parseInt(matchGroup, 10);
  802. if (hour === 12) hour = 0;
  803. if ((hour < 0) || (hour > 11)) return null;
  804. break;
  805. case 'H': case 'HH':
  806. hour = parseInt(matchGroup, 10);
  807. if ((hour < 0) || (hour > 23)) return null;
  808. break;
  809. case 'm': case 'mm':
  810. min = parseInt(matchGroup, 10);
  811. if ((min < 0) || (min > 59)) return null;
  812. break;
  813. case 's': case 'ss':
  814. sec = parseInt(matchGroup, 10);
  815. if ((sec < 0) || (sec > 59)) return null;
  816. break;
  817. case 'tt': case 't':
  818. var upperToken = matchGroup.toUpperCase();
  819. pmHour = (upperToken === dtf.PMDesignator.toUpperCase());
  820. if (!pmHour && (upperToken !== dtf.AMDesignator.toUpperCase())) return null;
  821. break;
  822. case 'f':
  823. msec = parseInt(matchGroup, 10) * 100;
  824. if ((msec < 0) || (msec > 999)) return null;
  825. break;
  826. case 'ff':
  827. msec = parseInt(matchGroup, 10) * 10;
  828. if ((msec < 0) || (msec > 999)) return null;
  829. break;
  830. case 'fff':
  831. msec = parseInt(matchGroup, 10);
  832. if ((msec < 0) || (msec > 999)) return null;
  833. break;
  834. case 'dddd':
  835. weekDay = cultureInfo._getDayIndex(matchGroup);
  836. if ((weekDay < 0) || (weekDay > 6)) return null;
  837. break;
  838. case 'ddd':
  839. weekDay = cultureInfo._getAbbrDayIndex(matchGroup);
  840. if ((weekDay < 0) || (weekDay > 6)) return null;
  841. break;
  842. case 'zzz':
  843. var offsets = matchGroup.split(/:/);
  844. if (offsets.length !== 2) return null;
  845. var hourOffset = parseInt(offsets[0], 10);
  846. if ((hourOffset < -12) || (hourOffset > 13)) return null;
  847. var minOffset = parseInt(offsets[1], 10);
  848. if ((minOffset < 0) || (minOffset > 59)) return null;
  849. tzMinOffset = (hourOffset * 60) + (matchGroup.startsWith('-')? -minOffset : minOffset);
  850. break;
  851. case 'z': case 'zz':
  852. var hourOffset = parseInt(matchGroup, 10);
  853. if ((hourOffset < -12) || (hourOffset > 13)) return null;
  854. tzMinOffset = hourOffset * 60;
  855. break;
  856. }
  857. }
  858. }
  859. var result = new Date();
  860. if (year === null) {
  861. year = result.getFullYear();
  862. }
  863. if (month === null) {
  864. month = result.getMonth();
  865. }
  866. if (date === null) {
  867. date = result.getDate();
  868. }
  869. result.setFullYear(year, month, date);
  870. if (result.getDate() !== date) return null;
  871. if ((weekDay !== null) && (result.getDay() !== weekDay)) {
  872. return null;
  873. }
  874. if (pmHour && (hour < 12)) {
  875. hour += 12;
  876. }
  877. result.setHours(hour, min, sec, msec);
  878. if (tzMinOffset !== null) {
  879. var adjustedMin = result.getMinutes() - (tzMinOffset + result.getTimezoneOffset());
  880. result.setHours(result.getHours() + parseInt(adjustedMin/60, 10), adjustedMin%60);
  881. }
  882. return result;
  883. }
  884. Date.prototype.format = function Date$format(format) {
  885. /// <summary locid="M:J#Date.format" />
  886. /// <param name="format" type="String"></param>
  887. /// <returns type="String"></returns>
  888. var e = Function._validateParams(arguments, [
  889. {name: "format", type: String}
  890. ]);
  891. if (e) throw e;
  892. return this._toFormattedString(format, Sys.CultureInfo.InvariantCulture);
  893. }
  894. Date.prototype.localeFormat = function Date$localeFormat(format) {
  895. /// <summary locid="M:J#Date.localeFormat" />
  896. /// <param name="format" type="String"></param>
  897. /// <returns type="String"></returns>
  898. var e = Function._validateParams(arguments, [
  899. {name: "format", type: String}
  900. ]);
  901. if (e) throw e;
  902. return this._toFormattedString(format, Sys.CultureInfo.CurrentCulture);
  903. }
  904. Date.prototype._toFormattedString = function Date$_toFormattedString(format, cultureInfo) {
  905. if (!format || (format.length === 0) || (format === 'i')) {
  906. if (cultureInfo && (cultureInfo.name.length > 0)) {
  907. return this.toLocaleString();
  908. }
  909. else {
  910. return this.toString();
  911. }
  912. }
  913. var dtf = cultureInfo.dateTimeFormat;
  914. format = Date._expandFormat(dtf, format);
  915. var ret = new Sys.StringBuilder();
  916. var hour;
  917. function addLeadingZero(num) {
  918. if (num < 10) {
  919. return '0' + num;
  920. }
  921. return num.toString();
  922. }
  923. function addLeadingZeros(num) {
  924. if (num < 10) {
  925. return '00' + num;
  926. }
  927. if (num < 100) {
  928. return '0' + num;
  929. }
  930. return num.toString();
  931. }
  932. var quoteCount = 0;
  933. var tokenRegExp = Date._getTokenRegExp();
  934. for (;;) {
  935. var index = tokenRegExp.lastIndex;
  936. var ar = tokenRegExp.exec(format);
  937. var preMatch = format.slice(index, ar ? ar.index : format.length);
  938. quoteCount += Date._appendPreOrPostMatch(preMatch, ret);
  939. if (!ar) break;
  940. if ((quoteCount%2) === 1) {
  941. ret.append(ar[0]);
  942. continue;
  943. }
  944. switch (ar[0]) {
  945. case "dddd":
  946. ret.append(dtf.DayNames[this.getDay()]);
  947. break;
  948. case "ddd":
  949. ret.append(dtf.AbbreviatedDayNames[this.getDay()]);
  950. break;
  951. case "dd":
  952. ret.append(addLeadingZero(this.getDate()));
  953. break;
  954. case "d":
  955. ret.append(this.getDate());
  956. break;
  957. case "MMMM":
  958. ret.append(dtf.MonthNames[this.getMonth()]);
  959. break;
  960. case "MMM":
  961. ret.append(dtf.AbbreviatedMonthNames[this.getMonth()]);
  962. break;
  963. case "MM":
  964. ret.append(addLeadingZero(this.getMonth() + 1));
  965. break;
  966. case "M":
  967. ret.append(this.getMonth() + 1);
  968. break;
  969. case "yyyy":
  970. ret.append(this.getFullYear());
  971. break;
  972. case "yy":
  973. ret.append(addLeadingZero(this.getFullYear() % 100));
  974. break;
  975. case "y":
  976. ret.append(this.getFullYear() % 100);
  977. break;
  978. case "hh":
  979. hour = this.getHours() % 12;
  980. if (hour === 0) hour = 12;
  981. ret.append(addLeadingZero(hour));
  982. break;
  983. case "h":
  984. hour = this.getHours() % 12;
  985. if (hour === 0) hour = 12;
  986. ret.append(hour);
  987. break;
  988. case "HH":
  989. ret.append(addLeadingZero(this.getHours()));
  990. break;
  991. case "H":
  992. ret.append(this.getHours());
  993. break;
  994. case "mm":
  995. ret.append(addLeadingZero(this.getMinutes()));
  996. break;
  997. case "m":
  998. ret.append(this.getMinutes());
  999. break;
  1000. case "ss":
  1001. ret.append(addLeadingZero(this.getSeconds()));
  1002. break;
  1003. case "s":
  1004. ret.append(this.getSeconds());
  1005. break;
  1006. case "tt":
  1007. ret.append((this.getHours() < 12) ? dtf.AMDesignator : dtf.PMDesignator);
  1008. break;
  1009. case "t":
  1010. ret.append(((this.getHours() < 12) ? dtf.AMDesignator : dtf.PMDesignator).charAt(0));
  1011. break;
  1012. case "f":
  1013. ret.append(addLeadingZeros(this.getMilliseconds()).charAt(0));
  1014. break;
  1015. case "ff":
  1016. ret.append(addLeadingZeros(this.getMilliseconds()).substr(0, 2));
  1017. break;
  1018. case "fff":
  1019. ret.append(addLeadingZeros(this.getMilliseconds()));
  1020. break;
  1021. case "z":
  1022. hour = this.getTimezoneOffset() / 60;
  1023. ret.append(((hour <= 0) ? '+' : '-') + Math.floor(Math.abs(hour)));
  1024. break;
  1025. case "zz":
  1026. hour = this.getTimezoneOffset() / 60;
  1027. ret.append(((hour <= 0) ? '+' : '-') + addLeadingZero(Math.floor(Math.abs(hour))));
  1028. break;
  1029. case "zzz":
  1030. hour = this.getTimezoneOffset() / 60;
  1031. ret.append(((hour <= 0) ? '+' : '-') + addLeadingZero(Math.floor(Math.abs(hour))) +
  1032. dtf.TimeSeparator + addLeadingZero(Math.abs(this.getTimezoneOffset() % 60)));
  1033. break;
  1034. }
  1035. }
  1036. return ret.toString();
  1037. }
  1038. Number.__typeName = 'Number';
  1039. Number.__class = true;
  1040. Number.parseLocale = function Number$parseLocale(value) {
  1041. /// <summary locid="M:J#Number.parseLocale" />
  1042. /// <param name="value" type="String"></param>
  1043. /// <returns type="Number"></returns>
  1044. var e = Function._validateParams(arguments, [
  1045. {name: "value", type: String}
  1046. ]);
  1047. if (e) throw e;
  1048. return Number._parse(value, Sys.CultureInfo.CurrentCulture);
  1049. }
  1050. Number.parseInvariant = function Number$parseInvariant(value) {
  1051. /// <summary locid="M:J#Number.parseInvariant" />
  1052. /// <param name="value" type="String"></param>
  1053. /// <returns type="Number"></returns>
  1054. var e = Function._validateParams(arguments, [
  1055. {name: "value", type: String}
  1056. ]);
  1057. if (e) throw e;
  1058. return Number._parse(value, Sys.CultureInfo.InvariantCulture);
  1059. }
  1060. Number._parse = function Number$_parse(value, cultureInfo) {
  1061. value = value.trim();
  1062. if (value.match(/^[+-]?infinity$/i)) {
  1063. return parseFloat(value);
  1064. }
  1065. if (value.match(/^0x[a-f0-9]+$/i)) {
  1066. return parseInt(value);
  1067. }
  1068. var numFormat = cultureInfo.numberFormat;
  1069. var signInfo = Number._parseNumberNegativePattern(value, numFormat, numFormat.NumberNegativePattern);
  1070. var sign = signInfo[0];
  1071. var num = signInfo[1];
  1072. if ((sign === '') && (numFormat.NumberNegativePattern !== 1)) {
  1073. signInfo = Number._parseNumberNegativePattern(value, numFormat, 1);
  1074. sign = signInfo[0];
  1075. num = signInfo[1];
  1076. }
  1077. if (sign === '') sign = '+';
  1078. var exponent;
  1079. var intAndFraction;
  1080. var exponentPos = num.indexOf('e');
  1081. if (exponentPos < 0) exponentPos = num.indexOf('E');
  1082. if (exponentPos < 0) {
  1083. intAndFraction = num;
  1084. exponent = null;
  1085. }
  1086. else {
  1087. intAndFraction = num.substr(0, exponentPos);
  1088. exponent = num.substr(exponentPos + 1);
  1089. }
  1090. var integer;
  1091. var fraction;
  1092. var decimalPos = intAndFraction.indexOf(numFormat.NumberDecimalSeparator);
  1093. if (decimalPos < 0) {
  1094. integer = intAndFraction;
  1095. fraction = null;
  1096. }
  1097. else {
  1098. integer = intAndFraction.substr(0, decimalPos);
  1099. fraction = intAndFraction.substr(decimalPos + numFormat.NumberDecimalSeparator.length);
  1100. }
  1101. integer = integer.split(numFormat.NumberGroupSeparator).join('');
  1102. var altNumGroupSeparator = numFormat.NumberGroupSeparator.replace(/\u00A0/g, " ");
  1103. if (numFormat.NumberGroupSeparator !== altNumGroupSeparator) {
  1104. integer = integer.split(altNumGroupSeparator).join('');
  1105. }
  1106. var p = sign + integer;
  1107. if (fraction !== null) {
  1108. p += '.' + fraction;
  1109. }
  1110. if (exponent !== null) {
  1111. var expSignInfo = Number._parseNumberNegativePattern(exponent, numFormat, 1);
  1112. if (expSignInfo[0] === '') {
  1113. expSignInfo[0] = '+';
  1114. }
  1115. p += 'e' + expSignInfo[0] + expSignInfo[1];
  1116. }
  1117. if (p.match(/^[+-]?\d*\.?\d*(e[+-]?\d+)?$/)) {
  1118. return parseFloat(p);
  1119. }
  1120. return Number.NaN;
  1121. }
  1122. Number._parseNumberNegativePattern = function Number$_parseNumberNegativePattern(value, numFormat, numberNegativePattern) {
  1123. var neg = numFormat.NegativeSign;
  1124. var pos = numFormat.PositiveSign;
  1125. switch (numberNegativePattern) {
  1126. case 4:
  1127. neg = ' ' + neg;
  1128. pos = ' ' + pos;
  1129. case 3:
  1130. if (value.endsWith(neg)) {
  1131. return ['-', value.substr(0, value.length - neg.length)];
  1132. }
  1133. else if (value.endsWith(pos)) {
  1134. return ['+', value.substr(0, value.length - pos.length)];
  1135. }
  1136. break;
  1137. case 2:
  1138. neg += ' ';
  1139. pos += ' ';
  1140. case 1:
  1141. if (value.startsWith(neg)) {
  1142. return ['-', value.substr(neg.length)];
  1143. }
  1144. else if (value.startsWith(pos)) {
  1145. return ['+', value.substr(pos.length)];
  1146. }
  1147. break;
  1148. case 0:
  1149. if (value.startsWith('(') && value.endsWith(')')) {
  1150. return ['-', value.substr(1, value.length - 2)];
  1151. }
  1152. break;
  1153. }
  1154. return ['', value];
  1155. }
  1156. Number.prototype.format = function Number$format(format) {
  1157. /// <summary locid="M:J#Number.format" />
  1158. /// <param name="format" type="String"></param>
  1159. /// <returns type="String"></returns>
  1160. var e = Function._validateParams(arguments, [
  1161. {name: "format", type: String}
  1162. ]);
  1163. if (e) throw e;
  1164. return this._toFormattedString(format, Sys.CultureInfo.InvariantCulture);
  1165. }
  1166. Number.prototype.localeFormat = function Number$localeFormat(format) {
  1167. /// <summary locid="M:J#Number.localeFormat" />
  1168. /// <param name="format" type="String"></param>
  1169. /// <returns type="String"></returns>
  1170. var e = Function._validateParams(arguments, [
  1171. {name: "format", type: String}
  1172. ]);
  1173. if (e) throw e;
  1174. return this._toFormattedString(format, Sys.CultureInfo.CurrentCulture);
  1175. }
  1176. Number.prototype._toFormattedString = function Number$_toFormattedString(format, cultureInfo) {
  1177. if (!format || (format.length === 0) || (format === 'i')) {
  1178. if (cultureInfo && (cultureInfo.name.length > 0)) {
  1179. return this.toLocaleString();
  1180. }
  1181. else {
  1182. return this.toString();
  1183. }
  1184. }
  1185. var _percentPositivePattern = ["n %", "n%", "%n" ];
  1186. var _percentNegativePattern = ["-n %", "-n%", "-%n"];
  1187. var _numberNegativePattern = ["(n)","-n","- n","n-","n -"];
  1188. var _currencyPositivePattern = ["$n","n$","$ n","n $"];
  1189. var _currencyNegativePattern = ["($n)","-$n","$-n","$n-","(n$)","-n$","n-$","n$-","-n $","-$ n","n $-","$ n-","$ -n","n- $","($ n)","(n $)"];
  1190. function zeroPad(str, count, left) {
  1191. for (var l=str.length; l < count; l++) {
  1192. str = (left ? ('0' + str) : (str + '0'));
  1193. }
  1194. return str;
  1195. }
  1196. function expandNumber(number, precision, groupSizes, sep, decimalChar) {
  1197. var curSize = groupSizes[0];
  1198. var curGroupIndex = 1;
  1199. var factor = Math.pow(10, precision);
  1200. var rounded = (Math.round(number * factor) / factor);
  1201. if (!isFinite(rounded)) {
  1202. rounded = number;
  1203. }
  1204. number = rounded;
  1205. var numberString = number.toString();
  1206. var right = "";
  1207. var exponent;
  1208. var split = numberString.split(/e/i);
  1209. numberString = split[0];
  1210. exponent = (split.length > 1 ? parseInt(split[1]) : 0);
  1211. split = numberString.split('.');
  1212. numberString = split[0];
  1213. right = split.length > 1 ? split[1] : "";
  1214. var l;
  1215. if (exponent > 0) {
  1216. right = zeroPad(right, exponent, false);
  1217. numberString += right.slice(0, exponent);
  1218. right = right.substr(exponent);
  1219. }
  1220. else if (exponent < 0) {
  1221. exponent = -exponent;
  1222. numberString = zeroPad(numberString, exponent+1, true);
  1223. right = numberString.slice(-exponent, numberString.length) + right;
  1224. numberString = numberString.slice(0, -exponent);
  1225. }
  1226. if (precision > 0) {
  1227. if (right.length > precision) {
  1228. right = right.slice(0, precision);
  1229. }
  1230. else {
  1231. right = zeroPad(right, precision, false);
  1232. }
  1233. right = decimalChar + right;
  1234. }
  1235. else {
  1236. right = "";
  1237. }
  1238. var stringIndex = numberString.length-1;
  1239. var ret = "";
  1240. while (stringIndex >= 0) {
  1241. if (curSize === 0 || curSize > stringIndex) {
  1242. if (ret.length > 0)
  1243. return numberString.slice(0, stringIndex + 1) + sep + ret + right;
  1244. else
  1245. return numberString.slice(0, stringIndex + 1) + right;
  1246. }
  1247. if (ret.length > 0)
  1248. ret = numberString.slice(stringIndex - curSize + 1, stringIndex+1) + sep + ret;
  1249. else
  1250. ret = numberString.slice(stringIndex - curSize + 1, stringIndex+1);
  1251. stringIndex -= curSize;
  1252. if (curGroupIndex < groupSizes.length) {
  1253. curSize = groupSizes[curGroupIndex];
  1254. curGroupIndex++;
  1255. }
  1256. }
  1257. return numberString.slice(0, stringIndex + 1) + sep + ret + right;
  1258. }
  1259. var nf = cultureInfo.numberFormat;
  1260. var number = Math.abs(this);
  1261. if (!format)
  1262. format = "D";
  1263. var precision = -1;
  1264. if (format.length > 1) precision = parseInt(format.slice(1), 10);
  1265. var pattern;
  1266. switch (format.charAt(0)) {
  1267. case "d":
  1268. case "D":
  1269. pattern = 'n';
  1270. if (precision !== -1) {
  1271. number = zeroPad(""+number, precision, true);
  1272. }
  1273. if (this < 0) number = -number;
  1274. break;
  1275. case "c":
  1276. case "C":