var General =
{
	OpacitySpeed: 25,
	OpacityUnit: 20,

	DOMInsertHTML: function(Element, HTML, Clear)
	{
		function Load(Data)
		{
			if(typeof(DOMParser)!="undefined")
				return((new DOMParser()).parseFromString(Data, "application/xml"));

			var ActiveXObjectDefinition = ["MSXML2.DOMDocument.6.0", "MSXML2.DOMDocument.4.0", "MSXML2.DOMDocument", "MSXML.DOMDocument", "Microsoft.XMLDOM"];
			for(var Loop=0;Loop<ActiveXObjectDefinition.length;Loop++)
			{
				try
				{
					var DOM = new ActiveXObject(ActiveXObjectDefinition[Loop]);
					DOM.loadXML(Data);
					return(DOM);
				}
				catch(e)
				{
				}
			}

			return null;
		}

		function Remove(Element)
		{
			while(Element.lastChild)
			{
//				General.PurgeFunction(Element.lastChild);
				if ( (Browser.Browser=="Explorer") && (Browser.Version<8) && (Element.lastChild.outerHTML) )
					Element.lastChild.outerHTML = "";
				else
					Element.removeChild(Element.lastChild);
			}
		}

		function Event(Event)
		{
			return(function() { eval(Event); } );
		}

		function Insert(Element, DOM, Level)
		{
			if(typeof(Level)=="undefined")
				Level = 1;

			if (Level>1)
			{
				if(DOM.nodeType==1)
				{
					var NewElement = ((Browser.Browser=="Explorer") && (Browser.Version<8) && (DOM.attributes.getNamedItem("name")) )?document.createElement('<'+DOM.nodeName+' name="'+DOM.attributes.getNamedItem("name").nodeValue+'" />'):document.createElement(DOM.nodeName);

					for(var LoopAttribute=0;LoopAttribute<DOM.attributes.length;LoopAttribute++)
					{
						var AttributeName = DOM.attributes[LoopAttribute].name;
						var AttributeValue = DOM.attributes[LoopAttribute].value;

						if (AttributeName.substr(0,2)=="on")
						{
							NewElement[AttributeName] = Event.call(NewElement, AttributeValue);
						}
						else
						{
							switch(AttributeName)
							{
								case "checked":
									( (Browser.Browser=="Explorer") && (Browser.Version<8) )?NewElement.setAttribute('defaultChecked', AttributeValue):NewElement.setAttribute('checked', AttributeValue);
									break;

								case "class":
									( (Browser.Browser=="Explorer") && (Browser.Version<8) )?NewElement.setAttribute('className', AttributeValue):NewElement.setAttribute('class', AttributeValue);
									break;

								case "style":
									( (Browser.Browser=="Explorer") && (Browser.Version<8) )?NewElement.style.setAttribute('cssText', AttributeValue):NewElement.setAttribute('style', AttributeValue);
									break;

								case "className":
									( (Browser.Browser=="Mozilla") || (Browser.Browser=="Safari") )?NewElement.setAttribute('class', AttributeValue):NewElement.setAttribute('className', AttributeValue);
									break;

								case "for":
									NewElement.setAttribute('htmlFor', AttributeValue);
									break;

								case "cellpadding":
									NewElement.setAttribute('cellPadding', AttributeValue);
									break;

								case "cellspacing":
									NewElement.setAttribute('cellSpacing', AttributeValue);
									break;

								case "acceptcharset":
									NewElement.setAttribute('acceptCharset', AttributeValue);
									break;

								case "allowtransparency":
									NewElement.setAttribute('allowTransparency', AttributeValue);
									break;

								case "frameborder":
									NewElement.setAttribute('frameBorder', AttributeValue);
									break;

								case "readonly":
									NewElement.setAttribute('readOnly', AttributeValue);
									break;

								case "maxlength":
									NewElement.setAttribute('maxLength', AttributeValue);
									break;

								case "marginwidth":
									NewElement.setAttribute('marginWidth', AttributeValue);
									break;

								case "marginheight":
									NewElement.setAttribute('marginHeight', AttributeValue);
									break;

								case "noresize":
									NewElement.setAttribute('noResize', AttributeValue);
									break;

								case "noshade":
									NewElement.setAttribute('noShade', AttributeValue);
									break;

								case "defaultselected":
									NewElement.setAttribute('defaultSelected', AttributeValue);
									break;

								case "defaultvalue":
									NewElement.setAttribute('defaultValue', AttributeValue);
									break;

								case "accesskey":
									NewElement.setAttribute('accessKey', AttributeValue);
									break;

								case "hspace":
									NewElement.setAttribute('hSpace', AttributeValue);
									break;

								case "vspace":
									NewElement.setAttribute('vSpace', AttributeValue);
									break;

								case "bgcolor":
									NewElement.setAttribute('bgColor', AttributeValue);
									break;

								case "longdesc":
									NewElement.setAttribute('longDesc', AttributeValue);
									break;

								case "colspan":
									NewElement.setAttribute('colSpan', AttributeValue);
									break;

								case "rowspan":
									NewElement.setAttribute('rowSpan', AttributeValue);
									break;

								case "valign":
									NewElement.setAttribute('vAlign', AttributeValue);
									break;

								case "tabindex":
									NewElement.setAttribute('tabIndex', AttributeValue);
									break;

								default:
									NewElement.setAttribute(AttributeName, AttributeValue);
							}
						}
					}

					Element = Element.appendChild(NewElement);
				}

				if(DOM.nodeType==3)
				{
					var Text = (DOM.nodeValue?DOM.nodeValue:"");

					switch(Element.nodeName)
					{
						case "SCRIPT":
							Element.text = Text;
							break;

						default:
							Element.appendChild(document.createTextNode(Text));
					}
				}
			}

			for(var LoopNode=0;LoopNode<DOM.childNodes.length;LoopNode++)
				Insert(Element, DOM.childNodes[LoopNode], Level+1);

		}

		if(typeof(HTML)=="undefined")
			HTML = "";

		var HTMLXML = null;
		HTMLXML = HTML.replace(new RegExp("&", "gi"), "&amp;");
		HTMLXML = HTMLXML.replace(new RegExp("&amp;nbsp;", "gi"), "&#160;");

		var DOMXML = Load("<root>"+HTMLXML+"</root>");

		if((Element)&&(DOMXML))
		{
			if(Clear!=false)
				Remove(Element);

			Insert(Element, DOMXML.documentElement);
		}

		delete DOMXML;
	},

	PurgeFunction: function(Element)
	{
		if (Element.attributes)
		{
			for (var Loop=0; Loop<Element.attributes.length; Loop++)
			{
				if (typeof(Element[Element.attributes[Loop].name])=="function")
					Element[Element.attributes[Loop].name] = null;
			}
		}

		if (Element.childNodes)
		{
			for (var Loop=0; Loop<Element.childNodes.length; Loop++)
			{
				General.PurgeFunction(Element.childNodes[Loop]);
			}
		}
	},

	GetElementPositionX: function(Element)
	{
		var x = Element.offsetLeft;
		var Parent = Element.offsetParent;
		while(Parent)
		{
			x += Parent.offsetLeft;
			Parent = Parent.offsetParent;
		}
		return x;
	},

	GetElementPositionY: function(Element)
	{
		var y = Element.offsetTop;
		var Parent = Element.offsetParent;
		while(Parent)
		{
			y += Parent.offsetTop;
			Parent = Parent.offsetParent;
		}
		return y;
	},

	GetBrowserInnerWidth: function()
	{
		if (document.all)
			return(document.documentElement.clientWidth);
		else
			return(window.innerWidth);
	},

	GetBrowserInnerHeight: function()
	{
		if (document.all)
			return(document.documentElement.clientHeight);
		else
			return(window.innerHeight);
	},

	GetBrowserScrollPositionX: function()
	{
		if (document.all)
			return(document.documentElement.scrollLeft);
		else
			return(window.pageXOffset);
	},

	GetBrowserScrollPositionY: function()
	{
		if (document.all)
			return(document.documentElement.scrollTop);
		else
			return(window.pageYOffset);
	},

	EventHandlerAdd: function(Object, Event, Handler)
	{
		if (Object.attachEvent)
			Object.attachEvent("on"+Event, Handler);
		else if (Object.addEventListener)
			Object.addEventListener(Event, Handler, false);
	},

	EventHandlerRemove: function(Object, Event, Handler)
	{
		if (Object.detachEvent)
			Object.detachEvent("on"+Event, Handler);
		else if (Object.removeEventListener)
			Object.removeEventListener(Event, Handler, false);
	},

	PreviousSibling: function(Object)
	{
		NodeName = Object.nodeName;
		Object = Object.previousSibling;

		while((Object)&&(Object.nodeName!=NodeName))
			Object = Object.previousSibling;

		return(Object);
	},

	NextSibling: function(Object)
	{
		NodeName = Object.nodeName;
		Object = Object.nextSibling;

		while((Object)&&(Object.nodeName!=NodeName))
			Object = Object.nextSibling;

		return(Object);
	},

	OpacitySet: function(Object, Opacity)
	{
		if (typeof(Object)=="string")
			Object = document.getElementById(Object);

		Object.setAttribute("OpacityOpacity", Opacity);
		Object.setAttribute("OpacityTimer", null);
		Object.style.opacity = Object.getAttribute("OpacityOpacity")/100;
		Object.style.filter = "alpha(opacity="+Object.getAttribute("OpacityOpacity")+")";
	},

	OpacityChange: function(Object, Opacity, CallBack)
	{
		if (typeof(Object)=="string")
			Object = document.getElementById(Object);

		if (typeof(CallBack)=="function")
			Object["OpacityCallBack"] = CallBack;
		else if (CallBack!=null)
			Object["OpacityCallBack"] = null;

		if (Object.getAttribute("OpacityOpacity")==null)
			General.OpacitySet(Object, 100);

		if (Object.OpacityTimer)
			clearTimeout(Object.getAttribute("OpacityTimer"));

		if (Object.getAttribute("OpacityOpacity")<Opacity)
		{
			if (Object.getAttribute("OpacityOpacity")+General.OpacityUnit > Opacity)
				Object.setAttribute("OpacityOpacity", Opacity);
			else
				Object.setAttribute("OpacityOpacity", Object.getAttribute("OpacityOpacity")+General.OpacityUnit);
			Object.style.opacity = Object.getAttribute("OpacityOpacity")/100;
			Object.style.filter = "alpha(opacity="+Object.getAttribute("OpacityOpacity")+")";
			Object.setAttribute("OpacityTimer", setTimeout(General.OpacityChange.bind(Object, [Object, Opacity, null]), General.OpacitySpeed));
		}
		else if (Object.getAttribute("OpacityOpacity")>Opacity)
		{
			if (Object.getAttribute("OpacityOpacity")-General.OpacityUnit < Opacity)
				Object.setAttribute("OpacityOpacity", Opacity);
			else
				Object.setAttribute("OpacityOpacity", Object.getAttribute("OpacityOpacity")-General.OpacityUnit);
			Object.style.opacity = Object.getAttribute("OpacityOpacity")/100;
			Object.style.filter = "alpha(opacity="+Object.getAttribute("OpacityOpacity")+")";
			Object.setAttribute("OpacityTimer", setTimeout(General.OpacityChange.bind(Object, [Object, Opacity, null]), General.OpacitySpeed));
		}
		else
		{
			if (Object["OpacityCallBack"])
				Object["OpacityCallBack"].apply();
		}
	}

}

//General.EventHandlerAdd(window, "unload", General.PurgeFunction.bind(this, [window.document]) );
