﻿// VARS //

var host = (isLocalHost ? document.location.host + "/blacktie.org": document.location.host);
var prot = (("https:" == document.location.protocol) ? "https://" : "http://");
var isLocalHost = (document.location.hostname.toLowerCase() == 'localhost');

// PROTOTYPES //

String.prototype.trim = function() {
	return this.replace( /^\s+|\s+$/g , "");
};

String.prototype.ltrim = function() {
	return this.replace( /^\s+/ , "");
};

String.prototype.rtrim = function() {
	return this.replace( /\s+$/ , "");
};

Array.prototype.contains = function (element) {
	for (var x = 0; x < this.length; x++)
		if (this[x] === element)
			return true;
	return false;
};

if (!Array.prototype.indexOf) {
	// This method allows indexOf to work in IE
	Array.prototype.indexOf = function(obj, start) {
		for (var i = (start || 0), j = this.length; i < j; i++) {
			if (this[i] === obj) {
				return i;
			}
		}
		return -1;
	};
}

if (!Array.prototype.forEach) {
	Array.prototype.forEach = function (callback, thisArg) {
		var T = null, k;
		if (this == null) {
			throw new TypeError(" this is null or not defined");
		}
		var O = Object(this);
		var len = O.length >>> 0;
		if ({}.toString.call(callback) != "[object Function]") {
			throw new TypeError(callback + " is not a function");
		}
		if (thisArg) {
			T = thisArg;
		}
		k = 0;
		while (k < len) {
			var kValue;
			if (k in O) {
				kValue = O[k];
				callback.call(T, kValue, k, O);
			}
			k++;
		}
	};
}

location.querystring = (function () {
	var urlParams = {};
	var e,
        q = window.location.search.substring(1),
        r = /([^&=]+)=([^&]+)/g;

	while (e = r.exec(q))
		urlParams[decodeURIComponent(e[1])] = decodeURIComponent(e[2]);

	return urlParams;
})();

// COMMON FUNCTIONS //

function refreshPage() {
	window.location.reload();
	return false;
}

function cloneLastRow(tableId) {
	var $tableBody = $('#' + tableId + ' tbody');
	var $lastRow = $tableBody.children().last();
	var $trClone = $lastRow.clone();

	var index = $tableBody.children().length;
	$trClone.find('*').andSelf().filter('[id]').each(function () {
		this.id = this.id.replace('_' + index, '_' + (index + 1));
	});

	$tableBody.append($trClone);

	$trClone.find($('input:text')).val('');
	$trClone.find($('select')).selectedIndex = 0;
	
	return (index + 1);
}

function moveHtmlElement(elementId, direction) {
	var element = getById(elementId);
	var sibling;

	if (direction == 0) // Moved up / left
	{
		sibling = element.previousSibling;
	}
	else if (direction == 1) // Moved Down / right
	{
		sibling = element.nextSibling;
	}

	if (sibling == null || sibling == element) {
		return;
	}

	if (direction == 0) {
		element.parentNode.insertBefore(element, sibling);
	}
	else {
		element.parentNode.insertBefore(sibling, element);
	}
}

function insertBefore(newElementId, targetElementId) {
	var newElement = getById(newElementId);
	var targetElement = getById(targetElementId);
	var parent = targetElement.parentNode;

	if (parent.firstchild == targetElement) {
		parent.insertBefore(newElement, targetElement.nextSibling);
	}
	else {
		parent.appendChild(newElement);
	}
}

function insertAfter(newElementId, targetElementId) {
	var newElement = getById(newElementId);
	var targetElement = getById(targetElementId);
	var parent = targetElement.parentNode;

	if (parent.lastchild == targetElement) {
		parent.appendChild(newElement);
	}
	else {
		parent.insertBefore(newElement, targetElement.nextSibling);
	}
}

function cancelEventBubbling(ev) {
	if (ev != null && typeof (ev.stopPropagation) != 'undefined') {
		ev.stopPropagation();
	}
	else if (typeof (event) != 'undefined') {
		event.cancelBubble = true;
	}
}

function getElementText(elementId, removeWhitespace) {
	var element = getById(elementId);
	var text = null;

	if (element) {
		if (element.value != null) {
			text = element.value;
		}
		else if (element.innerText != null) {
			text = element.innerText;
		}
		else if (element.textContent != null) {
			text = element.textContent;
		}

		if (typeof (removeWhitespace) != 'undefined' && removeWhitespace == true) {
			text = text.trim();
		}
	}
	return text;
}

function getSelectedIndex(elementId) {
	var element = getById(elementId);
	if (!element || !element.options || element.options.length == 0) return null;
	return element.options.selectedIndex;
}

function getSelectedValue(elementId) {
	var element = getById(elementId);
	if (!element || !element.options || element.options.length == 0) return null;
	return element.options[element.options.selectedIndex].value;
}

function getSelectedText(elementId) {
	var element = getById(elementId);
	if (!element || !element.options || element.options.length == 0) return null;
	return element.options[element.options.selectedIndex].text.trim();
}

function setSelectedValue(elementId, value) {
	var element = getById(elementId);
	if (element && element.options) {
		for (var i = 0; i < element.options.length; i++) {
			if (value == element.options[i].value) {
				element.selectedIndex = i;
				return;
			}
		}
		element.selectedIndex = 0;
	}
}

function setElementText(elementId, text) {
	var element = getById(elementId);
	if (element) {
		if (element.value != null) {
			element.value = text;
		}
		else if (element.innerText != null) {
			element.innerText = text;
		}
		else {
			element.textContent = text;
		}
	}
}

function setElementTitle(elementId, text) {
	var element = getById(elementId);
	if (element) {
		element.title = text;
	}
}

function setElementInnerHTML(elementId, textHTML) {
	var element = getById(elementId);
	if (element) {
		if (element.innerHTML != null) {
			element.innerHTML = textHTML;
		}
	}
}

function setOpacity(elementName) {
	var speed = Math.round(250 / 100); //speed for each frame

	var timer = 0;

	for (var i = 0; i <= 100; i++) {
		setTimeout("changeOpacity(" + i + ",'" + elementName + "')", (timer * speed));
		timer++;
	}
}

function changeOpacity(opacity, elementName) {
	var element = window.$get(elementName);

	if (element != null) {
		var elementStyle = element.style;
		elementStyle.opacity = (opacity / 100);
		elementStyle.MozOpacity = (opacity / 100);
		elementStyle.KhtmlOpacity = (opacity / 100);
	}
}

function deleteAllRows(parentElement) {
	var tableBody;

	if (parentElement.tagName == 'TBODY') {
		tableBody = parentElement;
	}
	else if (parentElement.tagName == 'TABLE') {
		tableBody = parentElement.tBodies[0];
	}

	if (tableBody != null) {
		var rowCount = tableBody.rows.length;
		var index = 1;

		while (index <= rowCount) {
			tableBody.removeChild(tableBody.rows[0]);
			index++;
		}
	}
}

function openDialog(url, windowName, name, width, height, canScroll, canResize, leftPos, topPos) {
	var win;
	var scrollValue = (canScroll) ? 'yes' : 'no';
	var resizableValue = (canResize) ? 'yes' : 'no';
	var left = (leftPos == undefined) ? (screen.width / 2) - width / 2 : leftPos;
	var top = (topPos == undefined) ? (screen.height / 2) - height / 2 : topPos;

	win = window.open(url, windowName, 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=' + scrollValue + ',resizable=' + resizableValue + ',copyhistory=no,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',screenX=' + left + ',screenY=' + top);

	if (win != null) {
		win.name = name;

		if (window.focus) {
			win.focus();
		}
	}
}

function formatDateTime(dateTime) {
	return dateTime.format('MM/dd/yyyy HH:mm:ss');
}

function formatDate(dateTime) {
	return dateTime.format('MM/dd/yyyy');
}

function dateDiffInDays(fromDate, toDate) {
	var one_day = 1000 * 60 * 60 * 24;
	return Math.ceil((fromDate.getTime() - toDate.getTime()) / (one_day));
}

function addStyle(element, styleName, value) {
	element.style.setProperty(styleName, value);
}

function removeStyle(element, styleName) {
	element.style.removeProperty(styleName);
}

function hideContent(element) {
	if (element != null) {
		addStyle(element, 'display', 'none');
	}
}

function showContent(element) {
	if (element != null) {
		removeStyle(element, 'display');
	}
}

function hideContentItems(contentItems) {
	Array.forEach(
		contentItems,
		function(contentItem) {
			hideContent(window.$get(contentItem));
		}
	);
}

function showContentItems(contentItems) {
	Array.forEach(
		contentItems,
		function(contentItem) {
			showContent(window.$get(contentItem));
		}
	);
}

function formatCurrency(nStr) {
	return String.localeFormat("{0:c}", parseFloat(nStr));
}

function initializeDropDown(element, text, value, isDefaultSelected, isSelected) {
	element.options.length = 0;
	addDropDownOption(element, text, value, isDefaultSelected, isSelected);
}

function addDropDownOption(element, text, value, isDefaultSelected, isSelected) {
	var optSelect = new Option(text, value, isDefaultSelected, isSelected);
	element.options[element.options.length] = optSelect;
}

function leftPad(c, n, len) {
	return (new Array(len - String(n).length + 1)).join(c).concat(n);
}

function maskNumber(number) {
	var t = number;
	var l = number.length;
	var last4 = t.substring(l - 4);
	return leftPad("x", last4, l);
}

function getEnumKeyFromValue(targetEnum, value) {
	for (key in targetEnum) {
		if (targetEnum[key] == value) {
			return  key;
		}
	}
	return null;
}

var HtmlInputHelper = new function () {

	//
	// Handles the onkeydown event on an input element
	// and returns whether or not the entry is a number.
	//
	this.isNumericEntryValid = function (evt) {
		var valid = false;

		if (evt) {
			var keyCode = evt.keyCode > 0 ? evt.keyCode : evt.charCode;

			if (evt.shiftKey == false) {
				valid = (keyCode >= 48 && keyCode <= 57); // between 0 and 9
				valid = valid || (keyCode >= 96 && keyCode <= 105); // between 0 and 9 on numeric keypad
			}

			// check for special keys
			valid = valid || keyCode == 8; // BKSP
			valid = valid || keyCode == 9; // TAB
			valid = valid || keyCode == 13; // CR
			valid = valid || keyCode == 35; // END
			valid = valid || keyCode == 36; // HOME
			valid = valid || keyCode == 37; // LFT
			valid = valid || keyCode == 39; // RTG
			valid = valid || keyCode == 46; // DEL
		}

		return valid;
	};

	//
	// Attaches behavior to an input element that only allows
	// numbers to be entered.
	//
	this.attachNumericEntryBehavior = function (item) {
		$(item).keydown(function (e) {
			return HtmlInputHelper.isNumericEntryValid(e);
		});
	};
};

//
// Table
//
var HtmlTableHelper = new function () {

	//
	// Applies a CSS class to all visible even rows in the specified table. If no
	// CSS class is specified, then the default even row class will be applied.
	//
	this.alternateRowColors = function (element, evenRowCssClass) {
		var parent = $(element);
		$("tr", parent).removeClass();
		$("tr:even", parent).toggleClass(evenRowCssClass || 'alt-row', true);
	};

	//
	// Removes all rows from the specified table
	//
	this.removeAllRows = function(element) {
		$("tr", $(element)).remove();
	};

	this.scrollToBottom = function (element) {
		var containingDiv = $(element).closest(".scrollableDiv");

		if (containingDiv != null) {
			$(containingDiv).scrollTop($(containingDiv).attr("scrollHeight") - $(containingDiv).height());
		}
	};
};

function roundTo(value, precision, hideDecimalForInteger) {

	value = value.toFixed(precision);
	if (hideDecimalForInteger) {

		var valueAsInteger = Math.round(value);
		if (valueAsInteger == value) {
			value = valueAsInteger;
		}
	}
	return value;
}

function limitMaxLength(element, maxLength) {

	if (element.value.length >= maxLength) {
		element.value = element.value.substring(0, maxLength);
	}

}

function isMaxLength(obj) {
	var mlength = obj.getAttribute ? parseInt(obj.getAttribute("maxlength")) : "";
	if (obj.getAttribute && obj.value.length > mlength)
		obj.value = obj.value.substring(0, mlength);
}

function isNullOrEmpty(value) {
	return (value == null || value == '' ? true : false);
}

function isNumeric(val) {
	return (isNaN(parseFloat(val))) ? false : true;
}

function isDate(dateStr) {
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
	var matchArray = dateStr.match(datePat);
	if (matchArray == null) {
		return false;
	}

	var month = matchArray[1];
	var day = matchArray[3];
	var year = matchArray[5];

	if (month < 1 || month > 12) {
		return false;
	}

	if (day < 1 || day > 31) {
		return false;
	}

	if ((month == 4 || month == 6 || month == 9 || month == 11) && day == 31) {
		return false;
	}

	if (month == 2) {
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day == 29 && !isleap)) {
			return false;
		}
	}
	return true;
}

function isNullOrWhitespace(input) {

	if (input == null) return true;

	return input.replace(/\s/g, '').length < 1;
}

function replaceAll(text, replaceValue, withValue) {
	if (text == null || replaceValue == withValue) return text;
	while (text.indexOf(replaceValue) > -1) {
		text = text.replace(new RegExp(replaceValue, 'g'), withValue);
	}
	return text;
}

function htmlEscape(str) {
	return String(str)
            .replace(/&/g, '&amp;')
            .replace(/"/g, '&quot;')
            .replace(/'/g, '&#39;')
            .replace(/</g, '&lt;')
            .replace(/>/g, '&gt;');
}

function isInternetExplorer() {
	var m = navigator.userAgent.match(/MSIE\s\d+/);
	return m != null;
}

function getFirefoxVersion() {
	var m = navigator.userAgent.match(/Firefox\/(\d+(?:\.\d+)?)/i);
	return m ? m[1] : 0;
}

function isWindowMaximized() {
	return window.innerHeight == screen.availHeight || window.innerWidth == screen.availWidth;
}

function resizeWindow(width, height) {
	try {
		window.resizeTo(width, height);
	} catch (e) {

	}
}

function isChildWindow() {
	return (window.opener == null) ? false : true;
}

function getRandomNumber(from, to) {
	return Math.floor(Math.random() * (to - from + 1) + from);
}

function launchNewWindow(url) {
	var w = window.open(url);
	w.focus();
	return false;
}

function ellipseText(text, maxLength) {
	if (text == null || text == '') {
		return '';
	}
	if (text.length > maxLength) {
		text = text.substring(0, maxLength) + '...';
	}
	return text;
}

function addEvent(elm, evType, fn, useCapture) {
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	}
	else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	}
	else {
		elm['on' + evType] = fn;
		return null;
	}
}

function addPageLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function () {
			oldonload();
			func();
		};
	}
}

function objectToJson(obj) {
	return JSON.stringify(obj);
}

function jsonToObject(data) {
	if (data.d != null) {
		return eval("(" + data.d + ')');
	}
	else {
		return eval("(" + data + ')');
	}
}

function jsonToQueryString(json) {
	return jQuery.param(json);
}

function getQueryStringValue(key) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i = 0; i < vars.length; i++) {
		var pair = vars[i].split("=");
		if (pair[0] == key) {
			return unescape(pair[1]);
		}
	}
	return null;
}

function launchWindow(url) {
	var w = window.open(url);
	w.focus();
	return false;
}

function CallPageMethod(methodName, onSuccess, onFail) {

	var args = '';
	var l = arguments.length;
	if (l > 3) {
		for (var i = 3; i < l - 1; i += 2) {
			if (args.length != 0) args += ',';
			args += '"' + arguments[i] + '":"' + arguments[i + 1] + '"';
		}
	}

	$.ajax({
		type: "POST",
		url: prot + host + "/Utility/WebMethods.aspx/" + methodName,
		data: "{" + args + "}",
		contentType: "application/json; charset=utf-8",
		dataType: "json",
		cache: false,
		success: onSuccess,
		fail: onFail
	});
}

function onScriptError() {
	alert("Sorry, there has been an error");
}

function stripHtml(value) {
	value = value.replace(/&(lt|gt);/g, function (strMatch, p1) { return (p1 == "lt") ? "<" : ">"; });
	value = value.replace(/<\/?[^>]+(>|$)/g, "");
	return value;
}

function getById(id) {
	return document.getElementById(id);
}

function getByClass(className) {
	return document.getElementById(className);
}

function jSelect(id) {
	return $('#' + id);
}

function disable(elementId) {
	$('#' + elementId).attr("disabled", "disabled");
}

function enable(elementId) {
	$('#' + elementId).removeAttr("disabled");
}

function isDisabled(elementId) {
	var element = document.getElementById(elementId);
	return element.getAttribute('disabled') != null;
}

function isRequired(elementId) {
	var element = document.getElementById(elementId);
	return (element.getAttribute('required') != null);
}

function isInValid(elementId) {
	var element = document.getElementById(elementId);
	if (element.getAttribute('disabled') != null) return false;
	if (element.getAttribute('required') != null && isNullOrEmpty(element.value)) return true;
	return (element.getAttribute('invalid') != null);
}

function properCase(s) {
	return s.toLowerCase().replace(/^(.)|\s(.)/g,
          function ($1) { return $1.toUpperCase(); });
}

function parseChars(str, alpha, numeric, symbols, spaces) {
	if (alpha == true && numeric == false && symbols == false) {
		//a
		return spaces ? str.replace(/[^A-Za-z ]/g, '') : str.replace(/[^A-Za-z]/g, '');
	}
	else if (alpha == false && numeric == true && symbols == false) {
		//n
		return spaces ? str.replace(/[^\d ]/g, '') : str.replace(/[^\d]/g, '');
	}
	else if (alpha == false && numeric == false && symbols == true) {
		//s
		return spaces ? str.replace(/[A-Za-z\d]/g, '') : str.replace(/[A-Za-z\d ]/g, '');
	}
	else if (alpha == true && numeric == true && symbols == false) {
		//an
		return spaces ? str.replace(/[^A-Za-z\d ]/g, '') : str.replace(/[^A-Za-z\d]/g, '');
	}
	else if (alpha == true && numeric == false && symbols == true) {
		//as
		return spaces ? str.replace(/[\d]/g, '') : str.replace(/[\d ]/g, '');
	}
	else if (alpha == false && numeric == true && symbols == true) {
		//ns
		return spaces ? str.replace(/[A-Za-z]/g, '') : str.replace(/[A-Za-z ]/g, '');
	}
	else {
		return null;
	}
}

function showInvoice(mylink) {
	if (!window.focus) return true;
	var href;
	if (typeof (mylink) == 'string')
		href = mylink;
	else
		href = mylink.href;
	window.open(href, Math.floor(Math.random() * 11), 'width=676,resizable=yes,modal=yes,scroll=yes,status=no');
	return false;
}

function parseName() {

}

function dateDiff(date1, date2, interval) {
    var second = 1000, minute = second * 60, hour = minute * 60, day = hour * 24, week = day * 7;
    date1 = new Date(date1);
    date2 = new Date(date2);
    var timediff = date2 - date1;
    if (isNaN(timediff)) return NaN;
    switch (interval) {
    case "years":
        return date2.getFullYear() - date1.getFullYear();
    case "months":
        return (
            (date2.getFullYear() * 12 + date2.getMonth())
                -
                (date1.getFullYear() * 12 + date1.getMonth())
        );
    case "weeks":
        return Math.floor(timediff / week);
    case "days":
        return Math.floor(timediff / day);
    case "hours":
        return Math.floor(timediff / hour);
    case "minutes":
        return Math.floor(timediff / minute);
    case "seconds":
        return Math.floor(timediff / second);
    default:
        return undefined;
    }
}

// ENUMS //

var keyPress = {
	BACKSPACE: 8,
	TAB: 9,
	ENTER: 13,
	SHIFT: 16,
	CTRL: 17,
	ALT: 18,
	PAUSE: 19,
	CAPS_LOCK: 20,
	ESCAPE: 27,
	PAGE_UP: 33,
	PAGE_DOWN: 34,
	END: 35,
	HOME: 36,
	LEFT_ARROW: 37,
	UP_ARROW: 38,
	RIGHT_ARROW: 39,
	DOWN_ARROW: 40,
	INSERT: 45,
	DELETE: 46,
	KEY_0: 48,
	KEY_1: 49,
	KEY_2: 50,
	KEY_3: 51,
	KEY_4: 52,
	KEY_5: 53,
	KEY_6: 54,
	KEY_7: 55,
	KEY_8: 56,
	KEY_9: 57,
	KEY_A: 65,
	KEY_B: 66,
	KEY_C: 67,
	KEY_D: 68,
	KEY_E: 69,
	KEY_F: 70,
	KEY_G: 71,
	KEY_H: 72,
	KEY_I: 73,
	KEY_J: 74,
	KEY_K: 75,
	KEY_L: 76,
	KEY_M: 77,
	KEY_N: 78,
	KEY_O: 79,
	KEY_P: 80,
	KEY_Q: 81,
	KEY_R: 82,
	KEY_S: 83,
	KEY_T: 84,
	KEY_U: 85,
	KEY_V: 86,
	KEY_W: 87,
	KEY_X: 88,
	KEY_Y: 89,
	KEY_Z: 90,
	LEFT_META: 91,
	RIGHT_META: 92,
	SELECT: 93,
	NUMPAD_0: 96,
	NUMPAD_1: 97,
	NUMPAD_2: 98,
	NUMPAD_3: 99,
	NUMPAD_4: 100,
	NUMPAD_5: 101,
	NUMPAD_6: 102,
	NUMPAD_7: 103,
	NUMPAD_8: 104,
	NUMPAD_9: 105,
	MULTIPLY: 106,
	ADD: 107,
	SUBTRACT: 109,
	DECIMAL: 110,
	DIVIDE: 111,
	F1: 112,
	F2: 113,
	F3: 114,
	F4: 115,
	F5: 116,
	F6: 117,
	F7: 118,
	F8: 119,
	F9: 120,
	F10: 121,
	F11: 122,
	F12: 123,
	NUM_LOCK: 144,
	SCROLL_LOCK: 145,
	SEMICOLON: 186,
	EQUALS: 187,
	COMMA: 188,
	DASH: 189,
	PERIOD: 190,
	FORWARD_SLASH: 191,
	GRAVE_ACCENT: 192,
	OPEN_BRACKET: 219,
	BACK_SLASH: 220,
	CLOSE_BRACKET: 221,
	SINGLE_QUOTE: 222
};

// THIRD PARTY //

// JSON UTILITY -- https://github.com/douglascrockford/JSON-js
var JSON; if (!JSON) { JSON = {} } (function () { function str(a, b) { var c, d, e, f, g = gap, h, i = b[a]; if (i && typeof i === "object" && typeof i.toJSON === "function") { i = i.toJSON(a) } if (typeof rep === "function") { i = rep.call(b, a, i) } switch (typeof i) { case "string": return quote(i); case "number": return isFinite(i) ? String(i) : "null"; case "boolean": case "null": return String(i); case "object": if (!i) { return "null" } gap += indent; h = []; if (Object.prototype.toString.apply(i) === "[object Array]") { f = i.length; for (c = 0; c < f; c += 1) { h[c] = str(c, i) || "null" } e = h.length === 0 ? "[]" : gap ? "[\n" + gap + h.join(",\n" + gap) + "\n" + g + "]" : "[" + h.join(",") + "]"; gap = g; return e } if (rep && typeof rep === "object") { f = rep.length; for (c = 0; c < f; c += 1) { if (typeof rep[c] === "string") { d = rep[c]; e = str(d, i); if (e) { h.push(quote(d) + (gap ? ": " : ":") + e) } } } } else { for (d in i) { if (Object.prototype.hasOwnProperty.call(i, d)) { e = str(d, i); if (e) { h.push(quote(d) + (gap ? ": " : ":") + e) } } } } e = h.length === 0 ? "{}" : gap ? "{\n" + gap + h.join(",\n" + gap) + "\n" + g + "}" : "{" + h.join(",") + "}"; gap = g; return e } } function quote(a) { escapable.lastIndex = 0; return escapable.test(a) ? '"' + a.replace(escapable, function (a) { var b = meta[a]; return typeof b === "string" ? b : "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4) }) + '"' : '"' + a + '"' } function f(a) { return a < 10 ? "0" + a : a } "use strict"; if (typeof Date.prototype.toJSON !== "function") { Date.prototype.toJSON = function (a) { return isFinite(this.valueOf()) ? this.getUTCFullYear() + "-" + f(this.getUTCMonth() + 1) + "-" + f(this.getUTCDate()) + "T" + f(this.getUTCHours()) + ":" + f(this.getUTCMinutes()) + ":" + f(this.getUTCSeconds()) + "Z" : null }; String.prototype.toJSON = Number.prototype.toJSON = Boolean.prototype.toJSON = function (a) { return this.valueOf() } } var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, gap, indent, meta = { "\b": "\\b", "\t": "\\t", "\n": "\\n", "\f": "\\f", "\r": "\\r", '"': '\\"', "\\": "\\\\" }, rep; if (typeof JSON.stringify !== "function") { JSON.stringify = function (a, b, c) { var d; gap = ""; indent = ""; if (typeof c === "number") { for (d = 0; d < c; d += 1) { indent += " " } } else if (typeof c === "string") { indent = c } rep = b; if (b && typeof b !== "function" && (typeof b !== "object" || typeof b.length !== "number")) { throw new Error("JSON.stringify") } return str("", { "": a }) } } if (typeof JSON.parse !== "function") { JSON.parse = function (text, reviver) { function walk(a, b) { var c, d, e = a[b]; if (e && typeof e === "object") { for (c in e) { if (Object.prototype.hasOwnProperty.call(e, c)) { d = walk(e, c); if (d !== undefined) { e[c] = d } else { delete e[c] } } } } return reviver.call(a, b, e) } var j; text = String(text); cx.lastIndex = 0; if (cx.test(text)) { text = text.replace(cx, function (a) { return "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4) }) } if (/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, "]").replace(/(?:^|:|,)(?:\s*\[)+/g, ""))) { j = eval("(" + text + ")"); return typeof reviver === "function" ? walk({ "": j }, "") : j } throw new SyntaxError("JSON.parse") } } })()
