var s = navigator.userAgent.toLowerCase();
String.prototype.Trim = function (trimChar)
{
	if (typeof (trimChar) != 'undefined' && trimChar != '')
	{
		var regexString = '/(^' + trimChar + '|' + trimChar + '+$)/g';
		return this.replace(regexString, '');
	}
	else
	{
		return this.replace(/(^\s+|\s+$)/g, '');
	}
}
String.prototype.Contains = function (value)
{
	return (this.indexOf(value) > -1);
};
if (typeof (Ms) == "undefined")
	Ms = { };

if (typeof (Ms.BrowserInfo) == "undefined")
{
	Ms.BrowserInfo = {
		IsIE: /*@cc_on!@*/false,
		IsLessThanIE6: /*@cc_on!@*/false && (parseInt(s.match(/msie (\d+)/)[1], 10) < 6),
		IsLessThanIE8: /*@cc_on!@*/false && (parseInt(s.match(/msie (\d+)/)[1], 10) < 8),
		IsIE6: /*@cc_on!@*/false && (parseInt(s.match(/msie (\d+)/)[1], 10) >= 6),
		IsIE7: /*@cc_on!@*/false && (parseInt(s.match(/msie (\d+)/)[1], 10) >= 7),
		IsIE8: /*@cc_on!@*/false && (parseInt(s.match(/msie (\d+)/)[1], 10) >= 8),
		IsGecko: s.Contains('gecko/'),
		IsSafari: s.Contains(' applewebkit/'),
		IsOpera: !!window.opera,
		IsMac: s.Contains('macintosh'),
		IsFirefox: s.Contains("firefox/"),
		IsAIR: s.Contains(' adobeair/'),
		IsChrome: s.Contains(' chrome/'),
		UserAgent: s
	};

	(function (browserInfo)
	{
		browserInfo.IsGecko = (navigator.product == 'Gecko') && !browserInfo.IsSafari && !browserInfo.IsOpera;
		browserInfo.IsGeckoLike = (browserInfo.IsGecko || browserInfo.IsSafari || browserInfo.IsOpera);


		if (browserInfo.IsGecko)
		{
			var geckoMatch = s.match(/rv:(\d+\.\d+)/);
			var geckoVersion = geckoMatch && parseFloat(geckoMatch[1]);

			// Actually "10" refers to Gecko versions before Firefox 1.5, when
			// Gecko 1.8 (build 20051111) has been released.

			// Some browser (like Mozilla 1.7.13) may have a Gecko build greater
			// than 20051111, so we must also check for the revision number not to
			// be 1.7 (we are assuming that rv < 1.7 will not have build > 20051111).

			if (geckoVersion)
			{
				browserInfo.IsGecko10 = (geckoVersion < 1.8);
				browserInfo.IsGecko19 = (geckoVersion > 1.8);
			}
		}
	})(Ms.BrowserInfo);
	Ms.BrowserInfo.IsStrictMode = function (document)
	{
		return ('CSS1Compat' == (document.compatMode || (this.IsSafari ? 'CSS1Compat' : null)));
	}
}
if (typeof (Ms.Tools) == "undefined")
	Ms.Tools = { WindowLoaded: false };
Ms.Tools.IsArray = function (obj)
{
	if (obj == null)
		return false;
	return (obj instanceof Array);
}
Ms.Tools.SetObjectOpacity = function (obj, value)
{
	obj.style['opacity'] = value / 100;
	obj.style['-moz-opacity'] = value / 100;
	if (obj.filters && obj.filters.alpha)
		obj.filters.alpha["opacity"] = value; // = "alpha(opacity=" + value + ")";
}
Ms.Tools.GetWindowScrollSize = function (win)
{
	if (!win)
		win = window;
	var x = 0, y = 0;
	if (typeof (win.scrollMaxX) == 'number')
	{
		y = win.innerHeight + win.scrollMaxY;
		x = win.innerWidth + win.scrollMaxX;
	}
	else if (win.document.body && (win.document.body.scrollHeight || win.document.body.scrollWidth))
	{
		y = win.document.body.scrollHeight;
		x = win.document.body.scrollWidth;
	}
	else if (win.document.documentElement && (win.document.documentElement.scrollHeight || win.document.documentElement.scrollWidth))
	{
		y = win.document.documentElement.scrollHeight;
		x = win.document.documentElement.scrollWidth;
	}
	return { Height: y, Width: x };
}
Ms.Tools.GetWindowScroll = function (win)
{
	if (!win)
		win = window;
	var x = 0, y = 0;
	if (typeof (win.pageYOffset) == 'number')
	{
		y = win.pageYOffset;
		x = win.pageXOffset;
	}
	else if (win.document.body && (win.document.body.scrollLeft || win.document.body.scrollTop))
	{
		y = win.document.body.scrollTop;
		x = win.document.body.scrollLeft;
	}
	else if (win.document.documentElement && (win.document.documentElement.scrollLeft || win.document.documentElement.scrollTop))
	{
		y = win.document.documentElement.scrollTop;
		x = win.document.documentElement.scrollLeft;
	}
	return [x, y];
};
Ms.Tools.GetWindowScrollX = function (win)
{
	return this.GetWindowScroll(win)[0];
};
Ms.Tools.GetWindowScrollY = function (win)
{
	return this.GetWindowScroll(win)[1];
};
Ms.Tools.GetViewPaneSize = function (win)
{
	if (Ms.BrowserInfo.IsIE)
	{
		var oSizeSource;

		var oDoc = win.document.documentElement;
		if (oDoc && oDoc.clientWidth)				// IE6 Strict Mode
		{
			oSizeSource = oDoc;
			if (win.document.body.clientWidth && win.document.body.clientWidth > oDoc.clientWidth)
				oSizeSource = win.document.body;
		}
		else
			oSizeSource = win.document.body; 	// Other IEs

		var returnValue = {};

		if (oSizeSource)
		{
			returnValue = { Width: oSizeSource.clientWidth, Height: oSizeSource.clientHeight };
			/*
			if (win.document.body.scrollWidth > oSizeSource.clientWidth)
			returnValue.Width = win.document.body.scrollWidth;
			
			if (win.document.body.scrollHeight > oSizeSource.clientHeight && win.document.body.scrollHeight < this.GetWindowHeight(window))
			returnValue.Height = win.document.body.scrollHeight;
			*/
		}
		else
			returnValue = { Width: 0, Height: 0 };
		return returnValue;
	}
	else
	{
		return { Width: win.innerWidth, Height: win.innerHeight };
	}
}
Ms.Tools.GetWindowDimensions = function (win)
{
	if (!win)
		win = window;
	var w = 0, h = 0;
	if (typeof (win.innerWidth) == 'number')
	{
		w = win.innerWidth;
		h = win.innerHeight;
	}
	else if (win.document.documentElement && (win.document.documentElement.clientWidth || win.document.documentElement.clientHeight))
	{
		w = win.document.documentElement.clientWidth;
		h = win.document.documentElement.clientHeight;
	}
	else if (win.document.body && (win.document.body.clientWidth || win.document.body.clientHeight))
	{
		w = win.document.body.clientWidth;
		h = win.document.body.clientHeight;
	}
	return [w, h];
};
Ms.Tools.GetWindowWidth = function (win)
{
	return this.GetWindowDimensions(win)[0];
};
Ms.Tools.GetWindowHeight = function (win)
{
	return this.GetWindowDimensions(win)[1];
};
Ms.Tools.GetTopWindow = function (startWindow)
{
	if (!startWindow)
		startWindow = window;
	var topWindow = startWindow.parent, lastTopWindow = topWindow;

	while (topWindow.parent && topWindow.parent != topWindow)
	{
		try
		{
			if (topWindow.parent.document.domain != document.domain)
				break;
			if (topWindow.parent.document.getElementsByTagName('frameset').length > 0)
			{
				topWindow = topWindow.parent;
				continue;
			}
		}
		catch (e)
		{
			break;
		}
		topWindow = topWindow.parent;
		lastTopWindow = topWindow;
	}
	if (lastTopWindow != topWindow)
		topWindow = lastTopWindow;

	return topWindow;
}
Ms.Tools.GetObjectPosition = function (o)
{
	var t = l = 0;
	if (!o.offsetParent)
		return [l, t];
	t = o.offsetTop;
	l = o.offsetLeft;
	while ((o = o.offsetParent))
	{
		t += o.offsetTop;
		l += o.offsetLeft;
	};
	return [l, t];
}
Ms.Tools.GetObjectPositionX = function (o)
{
	return this.GetObjectPosition(o)[0];
};
Ms.Tools.GetObjectPositionY = function (o)
{
	return this.GetObjectPosition(o)[1];
};
Ms.Tools.GetObjectBoundaries = function (obj)
{
	var bcrect, od, odb, odde, dimensions = { "left": 0, "top": 0, "right": 0, "bottom": 0, "width": 0, "height": 0 };

	if (obj)
	{
		od = obj.ownerDocument;
		odb = od.body;
		odde = od.documentElement;
		bcrect = obj.getBoundingClientRect();
		dimensions.left = bcrect.left;
		dimensions.top = bcrect.top;
		dimensions.right = bcrect.right;
		dimensions.bottom = bcrect.bottom;

		if (bcrect.width)
		{
			dimensions.width = bcrect.width;
			dimensions.height = bcrect.height;
		}
		else
		{
			dimensions.width = dimensions.right - dimensions.left;
			dimensions.height = dimensions.bottom - dimensions.top;
		}

		if (odb.scrollTop)
		{
			dimensions.top += odb.scrollTop;
			dimensions.left += odb.scrollLeft;
		}
		else if (odde && odde.scrollTop)
		{
			dimensions.top += odde.scrollTop;
			dimensions.left += odde.scrollLeft;
		}
	}
	return dimensions;
};
Ms.Tools.RegisterScript = function (url)
{
	var obj = document.createElement("SCRIPT");
	obj.setAttribute("type", "text/javascript");

	obj.setAttribute("src", url);
	var head = document.getElementsByTagName("HEAD");
	if (head != null && head.length > 0)
		head = head[0];
	else
		head = document.body;

	head.appendChild(obj);
}
Ms.Tools.RegisterCss = function ()
{
	var obj = document.createElement("LINK");
	obj.setAttribute("type", "text/css");
	obj.setAttribute("rel", "stylesheet");

	obj.setAttribute("href", url);
	var head = document.getElementsByTagName("HEAD");
	if (head != null && head.length > 0)
		head = head[0];
	else
		head = document.body;

	head.appendChild(obj);
}
Ms.Tools.RunFunction = function (func, thisObject, paramsArray, timerWindow)
{
	if (func)
		this.SetTimeout(func, 0, thisObject, paramsArray, timerWindow);
}
Ms.Tools.SetTimeout = function (func, milliseconds, thisObject, paramsArray, timerWindow)
{
	//this is to allow the setTimeout to work as an event-handler - even-handlers pass the event-object as the first parameter
	if (typeof (func) != "function")
	{
		func = arguments[1];

		try
		{
			milliseconds = arguments[2];
			thisObject = arguments[3];
			paramsArray = arguments[4];
			timerWindow = arguments[5];
		}
		catch (e) { }
	}
	return (timerWindow || window).setTimeout(function ()
	{
		if (paramsArray)
			func.apply(thisObject, [].concat(paramsArray));
		else
			func.apply(thisObject);
	}, milliseconds);
};
Ms.Tools.SetInterval = function (func, milliseconds, thisObject, paramsArray, timerWindow)
{
	return (timerWindow || window).setInterval(function ()
	{
		if (paramsArray)
			func.apply(thisObject, [].concat(paramsArray));
		else
			func.apply(thisObject);
	}, milliseconds);
};
Ms.Tools.getChildElementById = function (s_id, node)
{
	var ret;
	var nl = node.childNodes.length;
	if (nl == 0)
		return null;
	for (var i = 0; i < nl; i++)
	{
		if (i == 0)
			node = node.firstChild;
		else
			node = node.nextSibling;
		if (node == null)
			return null;
		if (node.nodeType == 3 || node.nodeType == 8)
			continue;
		if (node.id.toLowerCase() == s_id.toLowerCase())
		{
			return node;
		}
		else if (node.childNodes.length > 0)
		{
			ret = this.getChildElementById(s_id, node);
		}
		if (ret)
			return ret;
	};
	return null;
};
Ms.Tools.IsChildOf = function (childNode, parentNode)
{
	if (!childNode)
		return false;
	if (childNode == parentNode)
		return true;
	while ((childNode = childNode.parentNode) != null)
	{
		if (childNode == parentNode)
			return true;
		else if (childNode.nodeName == "BODY")
			return false;
	}
	return false;
}
Ms.Tools.DisableSelection = function (element)
{
	if (Ms.BrowserInfo.IsIE)
	{
		element.unselectable = 'on';

		var e, i = 0;
		while ((e = element.all[i++]))
		{
			switch (e.tagName)
			{
				case 'IFRAME':
				case 'TEXTAREA':
				case 'INPUT':
				case 'SELECT':
					/* Ignore the above tags */
					break;
				default:
					e.unselectable = 'on';
			}
		}
	}
	else
	{
		if (Ms.BrowserInfo.IsGecko)
			element.style.MozUserSelect = 'none';
		else
			element.style.userSelect = 'none';
	}
}
Ms.Tools.EnableSelection = function (element)
{
	if (Ms.BrowserInfo.IsIE)
	{
		element.unselectable = 'off';

		var e, i = 0;
		while ((e = element.all[i++]))
		{
			switch (e.tagName)
			{
				case 'IFRAME':
				case 'TEXTAREA':
				case 'INPUT':
				case 'SELECT':
					/* Ignore the above tags */
					break;
				default:
					e.unselectable = 'off';
			}
		}
	}
	else
	{
		if (Ms.BrowserInfo.IsGecko)
			element.style.MozUserSelect = 'text';
		else
			element.style.userSelect = 'text';
	}
}
Ms.Tools.AddEventListener = function(sourceObject, eventName, listener, paramsArray, targetObject )
{
	if (Ms.BrowserInfo.IsIE)
	{
		var o = new Object();
		o.Source = targetObject || sourceObject;
		if (typeof(sourceObject) == "string")
			sourceObject = document.getElementById(sourceObject);
		o.Params = paramsArray || [];
		/*Memory leak if we have DOM objects here.*/
		if (eventName == "load" && sourceObject == window)
		{
			o.Listener = function(ev)
			{
				Ms.Tools.WindowLoaded = true;
				return listener.apply(o.Source, [ev].concat(o.Params));
			};
		}
		else
		{
			o.Listener = function(ev)
			{
				return listener.apply(o.Source, [ev].concat(o.Params));
			};
		}
		sourceObject.attachEvent('on' + eventName, o.Listener);
		sourceObject = null;
		paramsArray = null;
	}
	else
	{
		if (eventName == "load" && sourceObject == window)
		{
			sourceObject.addEventListener(eventName, function(e)
			{
				Ms.Tools.WindowLoaded = true;
				listener.apply(targetObject || sourceObject, [e].concat(paramsArray || []));
			}, false);
		}
		else
		{
			sourceObject.addEventListener(eventName, function(e)
			{
				listener.apply(targetObject || sourceObject, [e].concat(paramsArray || []));
			}, false);
		}
	};
}
Ms.Tools.FixPngs = function ()
{
	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion[1]);
	var img, imgName, imgSrc, imgWidth, imgHeight, i, imgCount;
	if ((version >= 5.5 && version < 7) && (document.body.filters))
	{
		for (i = 0, imgCount = document.images.length; i < imgCount; i++)
		{
			img = document.images[i];
			imgName = img.src.toUpperCase();
			if (imgName.substring(imgName.length - 3, imgName.length) == "PNG")
			{
				imgSrc = img.src;
				imgWidth = img.getAttribute("width");
				imgHeight = img.getAttribute("height");

				if (imgWidth == null || imgWidth == "" || imgWidth == "0")
					imgWidth = img.clientWidth;
				if (imgHeight == null || imgHeight == "" || imgHeight == "0")
					imgHeight = img.clientHeight;
				/* make sure the width / height attributes are set */
				if (imgWidth != "100%" && imgWidth != "0")
					img.setAttribute("width", imgWidth);
				if (imgHeight != "100%" && imgHeight != "0")
					img.setAttribute("height", imgHeight);
				img.src = '/images/spacer.gif';
				img.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + imgSrc + "',sizingMethod='scale')";
			}
		}
	}
}

Ms.Tools.Print = function (win)
{
	if (!win)
		win = window;

	win.print();
}
Ms.Tools.ToggleVisibility = function (objOrName)
{
	if (typeof (objOrName) == "string")
		objOrName = document.getElementById(objOrName);

	if (objOrName)
	{
		if (objOrName.style.display == "none")
			objOrName.style.display = "block";
		else
			objOrName.style.display = "none";
	}
}
Ms.Tools.IsDate = function (value, delimiter)
{
	if (typeof (delimiter) == "undefined" || delimiter == null || delimiter == "")
		delimiter = "./-";
	var re = new RegExp("^\\s*?([0]?[1-9]|[1][0-2])[" + delimiter + "]([0]?[1-9]|[1|2][0-9]|[3][0|1])[" + delimiter + "]([0-9]{4}|[0-9]{2})\\s*?$", "gi");
	return re.test(value);
}


Ms.Request = {HttpHost: document.location.host, Hash: document.location.hash.substring(1) };
(function ()
{
	var qstring = document.location, qstringItems = {};
	qstring = qstring.search.substr(1);
	
	a_qstring = qstring.split('&');

		var name = '', value = '';
		for (var i = 0; i < a_qstring.length; i++)
		{
			value = a_qstring[i].split('=');
			if (value.length > 0)
			{
				name = value.splice(0, 1)[0];
				value = value.join('=');
			}
			else
				continue;
			if (name == "")
				continue;
			qstringItems[name.toLowerCase()] = value;
		}
	
	Ms.Request.qstring = qstring;
	Ms.Request.QueryStringItems = qstringItems;
})();

Ms.Request.QueryString = function (name)
{
	if (typeof (name) == "undefined" || name == null)
		return ('?') + this.qstring;
	if (this.QueryStringItems[name.toLowerCase()])
		return this.QueryStringItems[name.toLowerCase()];
	return '';
}
Ms.Request.HashString = function (key)
{
	if (typeof (key) == "undefined" || key == null)
		return this.Hash;
	if (typeof (this.HashStringItems) == 'undefined')
	{
		var hash = this.Hash.split("&"), name, value;

		this.HashStringItems = {};

		for (var i = 0; i < hash.length; i++)
		{
			value = hash[i].split('=');
			if (value.length > 0)
			{
				name = value.splice(0, 1)[0];
				value = value.join('=');
			}
			else
				continue;
			if (name == "")
				continue;
			qstringItems[name.toLowerCase()] = value;
		}
	}
	return this.HashStringItems[key] || "";
}
Ms.Request.Exclude = function (items)
{
	var skip = false, returnValue = '', item;
	if (!Ms.Tools.IsArray(items))
		items = items.split(',');
	for (var i = 0; i < this.QueryStringItems.length; i++)
	{
		item = items[i];
		skip = false;
		if (!item || !this.QueryStringItems[item])
			break;
		for (var x = 0; x < items.length; x++)
		{
			if (item == items[x].toLowerCase())
			{
				skip = true;
				break;
			}
		};
		if (!skip)
			returnValue += '&' + item + '=' + this.QueryStringItems[item];
	};
	returnValue = '?' + returnValue.substring(1);
	return returnValue;
}
Ms.Request.Append = function (items, vals)
{
	var s = this.Exclude(items);
	if (s == "?")
		s = "";
	var amp = '&', eq = '=';
	
	if (items.indexOf(',') != -1)
	{
		items = items.split(',');
		vals = vals.split(',');
		for (var i = 0; i < items.length; i++)
			s += amp + items[i] + eq + vals[i];
	}
	else
		s += amp + items + eq + vals;
	
	s = '?' + s.substring(1);
	return s;
}
Ms.Request.ScriptName = function ()
{
	return document.location.pathname;
}
Ms.Request.Https = (function ()
{
	return document.location.protocol == "https:";
})();
Ms.Request.ServerName = (function ()
{
	return (this.Https ? "https://" : "http://") + document.location.hostname || document.location.host;
})();

Ms.Tools.CookiesEnabled = function ()
{

}

Ms.Tools.FormatDate = function (date, format)
{
	if (typeof (format) == "undefined" || format == null)
		format = "MM/dd/yyyy";

	var returnValue = format;

	returnValue = returnValue.replace(/ddd(d?)/gi, "{0}");

	returnValue = returnValue.replace(/d(d?)/gi, "{1}");


	returnValue = returnValue.replace(/yyy(y?)/gi, "{2}");

	var strYear = date.getFullYear().toString();

	returnValue = returnValue.replace(/y(y?)/gi, "{3}");

	returnValue = returnValue.replace(/MMMM/g, "{5}");

	returnValue = returnValue.replace(/MMM/g, "{4}");
	
	returnValue = returnValue.replace(/MM/g, "{6}");

	var obj = this;

	var months = ["", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]

	var weekdayNames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];


	returnValue = returnValue.replace(/\{([0-9])\}/g, function (match, submatch)
	{
		switch (submatch)
		{
			case "0":
				return weekdayNames[date.getDay()];
			case "1":
				return date.getDate();
			case "2":
				return date.getFullYear();
			case "3":
				return strYear.substr(strYear.length - 2);
			case "4":
				return months[date.getMonth() + 1].substring(0, 3);
			case "5":
				return months[date.getMonth()+1];
			case "6":
				return date.getMonth();
		}
	});

	return returnValue;
}
