﻿String.prototype.ltrim = function String$ltrim() { var re = /\s*((\S+\s*)*)/; return this.replace(re, "$1"); }
String.prototype.rtrim = function String$rtrim() { var re = /((\s*\S+)*)\s*/; return this.replace(re, "$1"); }
String.prototype.trim = function String$trim() { return this.ltrim(this.rtrim()); }

String.prototype.htmlEncode = function String$htmlEncode()
{
	return this.trim().replace(/&/g, "&amp;")
		.replace(/</g, "&lt;")
		.replace(/>/g, "&gt;")
		.replace(/\"/g, "&quot;")
		.replace(/'/g, "&apos;")
		.replace(/\r\n/g, "<br />")
		.replace(/\r/g, "<br />")
		.replace(/\n/g, "<br />");
}

String.prototype.htmlDecode = function String$htmlDecode()
{
	return this.trim().replace(/&amp;/g, "&")
		.replace(/&lt;/g, "<")
		.replace(/&gt;/g, ">")
		.replace(/&quot;/g, "\"")
		.replace(/&apos;/g, "'")
		.replace(/<br \/>/g, "\n");
}

$.ajaxSetup(
	{
		type: "POST",
		contentType: "application/json; charset=utf-8",
		dataType: "json",
		data: "{}",
		dataFilter: function(data)
		{
			var m = null;

			if (typeof (JSON) != "undefined" && "function" == typeof (JSON.parse))
				msg = JSON.parse(data);
			else
				msg = eval("(" + data + ")");

			if (msg.hasOwnProperty("d"))
				return msg.d;

			return msg;
		},
		beforeSend: function(xhr)
		{
			xhr.setRequestHeader("X-MicrosoftAjax", "Delta=true");
		}
	});

function openFullWindow(url)
{
	window.open(url, "_blank", "location=1,status=1,resizable=1,menubar=1,scrollbars=1,toolbar=1");
}
