/***********************************************************************************
* Browser Object                                                                   *
* © 2011 Robot Scott LLC                                                           *
***********************************************************************************/
var Browser =
{
    /***********************************************************************************
	* Global Variables                                                                 *
	***********************************************************************************/
	Initialized : false,
    UserAgent   : false,
    IsSupported : false,
    IsIE        : false,
    Name        : false,
    Version     : false,
	Domain      : false,
    SubDomain   : false,
    Protocol    : (document.location.protocol) ? document.location.protocol : window.location.protocol,
	/**********************************************************************************/


	/***********************************************************************************
	* Initialization                                                                   *
	***********************************************************************************/
	Initialize : function ()
	{
		this.UserAgent = navigator.userAgent.toLowerCase();

		/***********************************************************************************
		* Detect Microsoft Internet Explorer                                               *
		***********************************************************************************/
		if ((navigator.appName.toLowerCase() == 'microsoft internet explorer') && (this.UserAgent.indexOf("maxthon") == -1))
		{
			this.IsIE        = true;
			this.Name        = navigator.appName;
			this.Version     = this.SupportedBrowsers['MSIE'].GetVersion();
		}
		/**********************************************************************************/


		/***********************************************************************************
		* Detect Netscape (Firefox, Safari, and Chrome)                                    *
		***********************************************************************************/
		else if (navigator.appName.toLowerCase() == 'netscape')
		{
			if ((this.UserAgent.indexOf("firefox") != -1) && (this.UserAgent.indexOf("navigator") == -1) && (this.UserAgent.indexOf("opera") == -1))
			{
				this.Name = "Firefox";
			}
			else if ((this.UserAgent.indexOf("safari") != -1) && (this.UserAgent.indexOf("chrome") == -1))
			{
				this.Name = "Safari";
			}
			else if (this.UserAgent.indexOf("chrome") != -1)
			{
				this.Name = "Chrome";
			}
			else
			{
				this.Name = 'Unsupported Netscape Browser'
			}

			if (typeof this.SupportedBrowsers[this.Name] !== 'undefined')
			{
				this.Version = this.SupportedBrowsers[this.Name].GetVersion();
			}
		}
		/**********************************************************************************/


		/***********************************************************************************
		* Detect Opera                                                                     *
		***********************************************************************************/
		else if (navigator.appName.toLowerCase() == 'opera')
		{
			this.Name        = navigator.appName;
			this.Version     = this.SupportedBrowsers[this.Name].GetVersion();
		}
		/**********************************************************************************/


		/***********************************************************************************
		* Unsupported Browsers                                                             *
		***********************************************************************************/
		else
		{
			this.Name    = 'Unsupported Browser';
			this.Version = '';
		}
		/**********************************************************************************/


		/***********************************************************************************
		* Check Version Support                                                            *
		***********************************************************************************/
		if (this.Name.indexOf('Unsupported') == -1)
		{
			this.IsSupported = this.SupportedBrowsers.IsVersionSupported();
		}
		/**********************************************************************************/

		this.Initialized = true;
	},
	/**********************************************************************************/


	/***********************************************************************************
	* ParseSubDomain: Checks for a subdomain and populates it                          *
	***********************************************************************************/
	ParseSubDomain : function ()
	{
		if (document.domain)
		{
			this.SubDomain = document.domain;
			this.Domain    = document.domain;

			if (document.domain.indexOf('.') != -1)
			{
				var domain_values = document.domain.split('.');

				if (domain_values.length > 2)
				{
					domain_values.shift();
				}

				this.Domain = domain_values.join('.');
			}
		}
	},
	/**********************************************************************************/


	/***********************************************************************************
	* toString: returns the name and version of the browser (if supported)             *
	***********************************************************************************/
	toString : function ()
	{
		return this.Name + ' ' + this.Version;
	},
	/**********************************************************************************/


	/***********************************************************************************
	* Show: Displays browser information inside the element specified                  *
	***********************************************************************************/
	Show : function (id)
	{
		document.getElementById(id).innerHTML = this.toString();
	},
	/**********************************************************************************/


	/***********************************************************************************
	* Event Registration Model                                                         *
	***********************************************************************************/
	Events :
	{
		Events : {},

		/***********************************************************************************
		* Add Event Handler                                                                *
		***********************************************************************************/
		AddEventHandler : function (el, evt, func)
		{
			el = (typeof el == 'string') ? document.getElementById(el) : el;

			if ((el != null) && (typeof func == 'function'))
			{
				var event   = (Browser.IsIE) ? 'on' + evt.toLowerCase() : evt.toLowerCase();
				var handler = (Browser.IsIE) ? function () { func.call(el); } : func;

				if (typeof this.Events[el] === 'undefined')
				{
					this.Events[el] = {};
				}

				if (typeof this.Events[el][event] === 'undefined')
				{
					this.Events[el][event] = [];
				}

				this.Events[el][event].push(handler);

				if (Browser.IsIE)
				{
					var result = el.attachEvent(event, handler);
				}
				else
				{
					el.addEventListener(event, handler, false);
				}
			}
		},
		/**********************************************************************************/


		/***********************************************************************************
		* Remove Event Handler                                                             *
		***********************************************************************************/
		RemoveEventHandler : function (el, evt, func)
		{
			el = (typeof el == 'string') ? document.getElementById(el) : el;

			if ((el != null) && (typeof func == 'function'))
			{
				var event   = (Browser.IsIE) ? 'on' + evt.toLowerCase() : evt.toLowerCase();
				var handler = (Browser.IsIE) ? function () { func.call(el); } : func;

				if ((this.Events[el]) && (this.Events[el][event]))
				{
					for (var i = 0; i < this.Events[el][event].length; i++)
					{
						if (this.Events[el][e][i].toString() == handler)
						{
							this.Events[el][e].splice(i, 1);

							if (Browser.IsIE)
							{
								el.detachEvent(event, handler);
							}
							else
							{
								el.removeEventListener(event, handler, false);
							}
						}
					}
				}
			}
		}
		/**********************************************************************************/
	},
	/**********************************************************************************/


	/***********************************************************************************
	* Page                                                                             *
	***********************************************************************************/
	Page :
	{
		/***********************************************************************************
		* Width                                                                            *
		***********************************************************************************/
		Width : function ()
		{
			var width = null;

			if (window.innerWidth != null)
			{
				width = window.innerWidth;
			}
			else
			{
				if ((document.documentElement) && (document.documentElement.clientWidth))
				{
					width = document.documentElement.clientWidth;
				}
				else
				{
					if (document.body != null)
					{
						width = document.body.clientWidth;
					}
				}
			}

			return width;
		},
		/**********************************************************************************/


		/***********************************************************************************
		* Height                                                                           *
		***********************************************************************************/
		Height : function ()
		{
			var height = null;

			if (window.innerHeight != null)
			{
				height = window.innerHeight;
			}
			else
			{
				if ((document.documentElement) && (document.documentElement.clientHeight))
				{
					height = document.documentElement.clientHeight;
				}
				else
				{
					if (document.body != null)
					{
						height = document.body.clientHeight;
					}
				}
			}

			return height;
		}
		/**********************************************************************************/
	},
	/**********************************************************************************/


	/***********************************************************************************
	* Position                                                                         *
	***********************************************************************************/
	Position :
	{
		/***********************************************************************************
		* Top                                                                              *
		***********************************************************************************/
		Top : function ()
		{
			pos_top = 0;

			if (typeof window.pageYOffset != 'undefined')
			{
				pos_top = window.pageYOffset;
			}
			else
			{
				if ((document.documentElement) && (document.documentElement.scrollTop))
				{
					pos_top = document.documentElement.scrollTop;
				}
				else
				{
					if (document.body.scrollTop)
					{
						pos_top = document.body.scrollTop;
					}
				}
			}

			return pos_top;
		},
		/**********************************************************************************/


		/***********************************************************************************
		* Left                                                                             *
		***********************************************************************************/
		Left : function ()
		{
			var pos_left = 0;

			if (typeof window.pageXOffset != 'undefined')
			{
				pos_left = window.pageXOffset;
			}
			else
			{
				if ((document.documentElement) && (document.documentElement.scrollLeft))
				{
					pos_left = document.documentElement.scrollLeft;
				}
				else
				{
					if (document.body.scrollLeft)
					{
						pos_left = document.body.scrollLeft
					}
				}
			}

			return pos_left;
		},
		/**********************************************************************************/


		/***********************************************************************************
		* Right                                                                            *
		***********************************************************************************/
		Right : function ()
		{
			return this.Position.Left() + this.Page.Width();
		},
		/**********************************************************************************/


		/***********************************************************************************
		* Bottom                                                                           *
		***********************************************************************************/
		Bottom : function ()
		{
			return this.Position.Top() + this.Page.Height();
		}
		/**********************************************************************************/
	},
	/**********************************************************************************/


	/***********************************************************************************
	* Element                                                                          *
	***********************************************************************************/
	Element :
	{
		/***********************************************************************************
		* Width                                                                            *
		***********************************************************************************/
		Width : function (el)
		{
			var e = (typeof el == 'string') ? document.getElementById(el) : el;
			var w = false;

			if (typeof e != 'undefined')
			{
				w = e.offsetWidth;
			}

			return w;
		},
		/**********************************************************************************/


		/***********************************************************************************
		* Width                                                                            *
		***********************************************************************************/
		Height : function (el)
		{
			var e = (typeof el == 'string') ? document.getElementById(el) : el;
			var h = false;

			if (typeof e !== 'undefined')
			{
				h = e.offsetHeight;
			}

			return h;
		},
		/**********************************************************************************/


		/***********************************************************************************
		* HasClassName                                                                     *
		***********************************************************************************/
		HasClassName : function (el, cname)
		{
			var e = (typeof el == 'string') ? document.getElementById(el) : el;
			var c = (typeof cname == 'string') ? cname : false;

			var result = false;

			if ((e) && (c))
			{
				if (e.className)
				{
					var arrList = e.className.split(' ');

					for (var i = 0; i < arrList.length; i++)
					{
						if (arrList[i].toUpperCase() == c.toUpperCase())
						{
							result = true;
							break;
						}
					}
				}
			}
			else
			{
				alert("Browser.Element.HasClassName: Object reference is undefined (" + c + ")");
			}

			return result;
		},
		/**********************************************************************************/


		/***********************************************************************************
		* AddClassName                                                                     *
		***********************************************************************************/
		AddClassName : function (el, cname, exists)
		{
			var e = (typeof el == 'string') ? document.getElementById(el) : el;
			var c = (typeof cname == 'string') ? cname : false;
			var x = (exists) ? true : false;

			if ((e) && (c))
			{
				if (e.className)
				{
					var arrList = e.className.split(' ');

					if (x)
					{
						for (var i = 0; i < arrList.length; i++)
						{
							if (arrList[i].toUpperCase() == c.toUpperCase())
							{
								arrList.splice(i, 1);
								i--;
							}
						}
					}

					arrList[arrList.length] = c;
					e.className = arrList.join(' ');
				}
				else
				{
					e.className = c;
				}
			}
			else
			{
				alert("Browser.Element.AddClassName: Object reference is undefined (" + c + ")");
			}
		},
		/**********************************************************************************/


		/***********************************************************************************
		* RemoveClassName                                                                  *
		***********************************************************************************/
		RemoveClassName : function (el, cname)
		{
			var e = (typeof el == 'string') ? document.getElementById(el) : el;
			var c = (typeof cname == 'string') ? cname : false;

			if ((e) && (c))
			{
				if (e.className)
				{
					var arrList = e.className.split(' ');

					for (var i = 0; i < arrList.length; i++)
					{
						if (arrList[i].toUpperCase() == c.toUpperCase())
						{
							arrList.splice(i, 1);
							i--;
						}
					}

					e.className = arrList.join(' ');
				}
			}
			else
			{
				alert("Browser.Element.RemoveClassName: Object reference is undefined (" + c + ")");
			}
		}
		/**********************************************************************************/
	},
	/**********************************************************************************/


	/***********************************************************************************
	* Cookies: Built-In Cookie Management                                              *
	***********************************************************************************/
	Cookies :
	{
		/* Internal Variables *************************************************************/
		Enabled : false,
		Parsed  : false,
		Keys    : false,
		Jar     : false,
		/**********************************************************************************/


		/***********************************************************************************
		* Enabled: returns boolean value indicating cookies are enabled in the browser     *
		***********************************************************************************/
		CheckEnabled : function ()
		{
			var result = false;
			var key    = '__RelativityCookieTest__';
			var val    = new Date().toGMTString();

			this.Set(key, val);

			result = (this.Remove(key) == val);

			this.Enabled = result;
			return result;
		},
		/**********************************************************************************/


		/***********************************************************************************
		* Parse: Parses the cookie string and populates the cookie jar                     *
		***********************************************************************************/
		Parse : function ()
		{
			var cookies = document.cookie.split("; ");

			this.Jar = {};

			for (var i = 0; i < cookies.length; i++)
			{
				var data = cookies[i].split('=');
				this.Jar[data[0]] = data[1];
			}

			this.Parsed = true;
		},
		/**********************************************************************************/


		/***********************************************************************************
		* Set: Sets a cookie (same for new cookie or updating a cookie)                    *
		***********************************************************************************/
		Set : function (key, val, options)
		{
			if (!this.Parsed) { this.Parse(); }

			var ratios  = { seconds: 1000, minutes:(1000 * 60), hours:(1000 * 60 * 60), days:(1000 * 60 * 60 * 24) };
			var config  = [];

			if (typeof options !== 'undefined')
			{
				if (typeof options['Expires'] !== 'undefined')
				{
					var ex_params = options['Expires'].split(' ');

					if ((/^\d+$/.test(ex_params[0])) && (typeof ratios[ex_params[1].toLowerCase()] !== 'undefined'))
					{
						config.push('expires=' + new Date(new Date().getTime() + (ex_params[0] * ratios[ex_params[1].toLowerCase()])).toGMTString());
					}
					else if (ex_params[0] == '-1')
					{
						config.push('expires=' + Browser.Epoch);
					}
				}

				if (typeof options['Domain'] !== 'undefined')
				{
					if (Browser.Domain.indexOf(options['Domain']) != -1)
					{
						config.push('domain=' + options['Domain']);
					}
				}

				if (typeof options['Path'] !== 'undefined')
				{
					config.push('path=' + options['Path']);
				}

				if (typeof options['Secure'] !== 'undefined')
				{
					if (options['Secure'] == true)
					{
						config.push('secure');
					}
				}
			}

			var tcookie = key + '=' + val + ';';

			if (config.length > 0)
			{
				var remainder = config.join('; ');
				tcookie = tcookie + ' ' + remainder;
			}

			document.cookie = tcookie;
			this.Jar[key] = val;
		},
		/**********************************************************************************/


		/***********************************************************************************
		* Get: Returns the value of the cookie for the given key, if it exists             *
		***********************************************************************************/
		Get : function (key)
		{
			if (!this.Parsed) { this.Parse(); }

			var result = false;

			if (typeof this.Jar[key] !== 'undefined')
			{
				result = this.Jar[key];
			}

			return result;
		},
		/**********************************************************************************/


		/***********************************************************************************
		* Remove: Removes the cookie for the given key                                     *
		***********************************************************************************/
		Remove : function (key)
		{
			if (!this.Parsed) { this.Parse(); }

			var result = false;

			if (typeof this.Jar[key] !== 'undefined')
			{
				result = this.Jar[key];
				this.Set(key, "", { Expires:'-1' })
			}

			return result;
		},
		/**********************************************************************************/


		/***********************************************************************************
		* GetKeys: Returns an array of all the cookie names                                *
		***********************************************************************************/
		GetKeys : function ()
		{
			this.Parse();

			this.Keys = [];

			for (var key in this.Jar)
			{
				this.Keys.push(key);
			}

			return this.Keys;
		}
		/**********************************************************************************/
	},
	/**********************************************************************************/


	/***********************************************************************************
	* Query String                                                                     *
	***********************************************************************************/
	QueryString :
	{
		Parsed : false,
		Data : {},

		/***********************************************************************************
		* Parse                                                                            *
		***********************************************************************************/
		Parse : function ()
		{
			var parts = window.location.search.substring(1).split("&");

			for (var i = 0; i < parts.length; i++)
			{
				var pair = parts[i].split("=");
				this.Data[pair[0]] = pair[1];
			}

			Parsed = true;
		},
		/**********************************************************************************/


		/***********************************************************************************
		* Get                                                                              *
		***********************************************************************************/
		Get : function (key)
		{
			if (!this.Parsed) { this.Parse(); }

			var val = false;

			if (this.Data[key])
			{
				val = this.Data[key];
			}

			return val;
		}
		/**********************************************************************************/
	},
	/**********************************************************************************/


	/***********************************************************************************
	* Supported Browsers and Versions                                                  *
	***********************************************************************************/
	SupportedBrowsers :
	{
		/***********************************************************************************
		* MSIE                                                                             *
		***********************************************************************************/
		MSIE :
		{
			MinSupportedVersion : '8',
			MaxSupportedVersion : '8',

			GetVersion : function ()
			{
				var result = false;

				/***********************************************************************************
				* Code taken from MSDN article: Detecting Internet Explorer More Effectively       *
				* URL: http://msdn.microsoft.com/en-us/library/ms537509.aspx                       *
				***********************************************************************************/
				var ua = navigator.userAgent;
				var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
				if (re.exec(ua) != null)
				{
					//rv = parseFloat( RegExp.$1 );
					result = parseFloat( RegExp.$1 );
				}
				/**********************************************************************************/

				return result;
			}
		},
		/**********************************************************************************/


		/***********************************************************************************
		* Firefox                                                                          *
		***********************************************************************************/
		Firefox :
		{
			MinSupportedVersion : '3.6',
			MaxSupportedVersion : '4.0',

			GetVersion : function ()
			{
				var result = false;
				var regex  = /firefox\/([\.\d]+)/;

				if (regex.exec(navigator.userAgent.toLowerCase()) != null)
				{
					var version = regex.exec(navigator.userAgent.toLowerCase());
					result = version[1];
				}

				return result;
			}
		},
		/**********************************************************************************/


		/***********************************************************************************
		* Opera                                                                            *
		***********************************************************************************/
		Opera :
		{
			MinSupportedVersion : '10',
			//MaxSupportedVersion : '',

			GetVersion : function ()
			{
				var result = false;
				var regex  = /version\/([\.\d]+)/;

				if (regex.exec(navigator.userAgent.toLowerCase()) != null)
				{
					var version = regex.exec(navigator.userAgent.toLowerCase());
					result = version[1];
				}

				return result;
			}
		},
		/**********************************************************************************/


		/***********************************************************************************
		*                                                                                  *
		***********************************************************************************/
		Safari :
		{
			MinSupportedVersion : '4',
			//MaxSupportedVersion : '4.0',

			GetVersion : function ()
			{
				var result = false;
				var regex  = /version\/([\.\d]+)/;

				if (regex.exec(navigator.userAgent.toLowerCase()) != null)
				{
					var version = regex.exec(navigator.userAgent.toLowerCase());
					result = version[1];
				}

				return result;
			}
		},
		/**********************************************************************************/


		/***********************************************************************************
		* Chrome                                                                           *
		***********************************************************************************/
		Chrome :
		{
			MinSupportedVersion : '8',
			//MaxSupportedVersion : '4.0',

			GetVersion : function ()
			{
				var result = false;
				var regex  = /chrome\/([\.\d]+)/;

				if (regex.exec(navigator.userAgent.toLowerCase()) != null)
				{
					var version = regex.exec(navigator.userAgent.toLowerCase());
					result = version[1];
				}

				return result;
			}
		},
		/**********************************************************************************/


		/***********************************************************************************
		* Komodo                                                                           *
		***********************************************************************************/
		Komodo :
		{
			MinSupportedVersion : '4',
			//MaxSupportedVersion : '4.0',

			GetVersion : function ()
			{
				var result = false;
				var regex  = /komodo\/([\.\d]+)/;

				if (regex.exec(navigator.userAgent.toLowerCase()) != null)
				{
					var version = regex.exec(navigator.userAgent.toLowerCase());
					result = version[1];
				}

				return result;
			}
		},
		/**********************************************************************************/


		/***********************************************************************************
		* Is Version Supported                                                             *
		***********************************************************************************/
		IsVersionSupported : function ()
		{
			var result  = false;
			var browser = (Browser.Name == 'Microsoft Internet Explorer') ? 'MSIE' : Browser.Name;
			var minver  = Browser.SupportedBrowsers[browser].MinSupportedVersion;
			var maxver  = (typeof Browser.SupportedBrowsers[browser].MaxSupportedVersion !== 'undefined') ? Browser.SupportedBrowsers[browser].MaxSupportedVersion : false;

			if (parseFloat(Browser.Version) >= minver)
			{
				if (maxver)
				{
					if ((maxver >= minver) && (maxver >= parseFloat(Browser.Version)))
					{
						result = true;
					}
				}
				else
				{
					result = true;
				}
			}

			return result;
		}
		/**********************************************************************************/
    },
    /**********************************************************************************/

	SessionTimersEnabled : false
}
/**********************************************************************************/

Browser.Initialize();

