
/*////////////////////////////////////////////////////////*/
/*####################### CLS.PAGE #######################*/
/*////////////////////////////////////////////////////////*/

	var Page=new function()
	{
		/*////////////////////////////////////*/
		/*//////// PRIVATE.VARIABLES /////////*/
		/*////////////////////////////////////*/

		var Self=this;

		/*////////////////////////////////////*/
		/*///////// PUBLIC.VARIABLES /////////*/
		/*////////////////////////////////////*/

		this.isLoaded=false;

		/*##############################################*/
		/*############## PRIVATE.CONTRUCT ##############*/
		/*##############################################*/

		/*////////////////////////////////////*/
		/*////////// THIS.CONSTRUCT //////////*/
		/*////////////////////////////////////*/

		this.construct=function(Args)
		{
			this.event.addListener(window,'load',window.onload);
			this.event.addListener(window,'load',function(){ Self.isLoaded=true; });
		};

		/*##############################################*/
		/*############## PUBLIC.FUNCTIONS ##############*/
		/*##############################################*/

		/*////////////////////////////////////*/
		/*////////// THIS.URLREQUEST /////////*/
		/*////////////////////////////////////*/

		this.urlRequest=function(Url,Method,Data,Handler)
		{
			var Request=typeof(XMLHttpRequest)!='undefined'?new XMLHttpRequest():(typeof(window.createRequest)!='undefined'?window.createRequest():false);

			if(!Request)
			{
				try{ Request=new ActiveXObject('Msxml2.XMLHTTP'); } catch(e){ try{ Request=new ActiveXObject('Microsoft.XMLHTTP'); } catch(e){ Request=false; } }
			}

			Request.open(Method,Url,true,false,false);
			Request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			Request.onreadystatechange=function(){ try{ Request.readyState==4?(Request.status==200?Handler(Request.responseText):Handler(false)):null; } catch(e){ Handler(false); } };
			Request.send(Data);
		};

		/*##############################################*/
		/*############### PUBLIC.OBJECTS ###############*/
		/*##############################################*/

		/*////////////////////////////////////*/
		/*//////////// THIS.MOUSE ////////////*/
		/*////////////////////////////////////*/

		this.mouse=
		{
			getX:function(Event)
			{
				return (typeof(Event.pageX)!='undefined'?Event.pageX:Event.x+document.body.parentNode.scrollLeft);
			},

			getY:function(Event)
			{
				return (typeof(Event.pageY)!='undefined'?Event.pageY:Event.y+document.body.parentNode.scrollTop);
			}
		};

		/*////////////////////////////////////*/
		/*/////////// THIS.BROWSER ///////////*/
		/*////////////////////////////////////*/

		this.browser=
		{
			isSafari	:navigator.userAgent.toLowerCase().search('safari')!=-1,
			isIE		:navigator.userAgent.toLowerCase().search('msie 7')!=-1,
			isFirefox	:navigator.userAgent.toLowerCase().search('firefox')!=-1,
			isNetscape	:navigator.userAgent.toLowerCase().search('netscape')!=-1
		};

		/*////////////////////////////////////*/
		/*/////////// THIS.ENCODING //////////*/
		/*////////////////////////////////////*/

		this.encoding=
		{
			toUtf8:function(Input)
			{
				Input=typeof(Input)=='undefined'?'':Input.toString().replace(/\r\n/g,'\n');

				var Output="";

				for(var a=0;a<Input.length;a++)
				{
					var Code=Input.charCodeAt(a);

					if(Code<128){ Output+=String.fromCharCode(Code); }
					else if(Code>127 && Code<2048){ Output+=String.fromCharCode((Code >> 6) | 192);Output+=String.fromCharCode((Code & 63) | 128); }
					else{ Output+=String.fromCharCode((Code >> 12) | 224);Output+=String.fromCharCode(((Code >> 6) & 63) | 128);Output+=String.fromCharCode((Code & 63) | 128); }
				}

				return Output;
			}
		};

		/*////////////////////////////////////*/
		/*///////////// THIS.DOM /////////////*/
		/*////////////////////////////////////*/

		this.dom=
		{
			createNode:function(Node,Attributes)
			{
				var Output=null;

				if(typeof(Node)=='string')
				{
					Output=document.createElement(Node);

					this.setAttributes(Output,Attributes);
				}

				return Output;
			},

			setAttributes:function(Node,Attributes)
			{
				Node=typeof(Node)=='string'?document.getElementById(Node):Node;

				if(Node && typeof(Attributes)=='object')
				{
					for(var a in Attributes)
					{
						Node[a]=Attributes[a];
					}
				}
			},
			
			getOffsetX:function(Node,Element)
			{
				Output	=0;
				Element	=Element?Element:document;

				if(Node && Node!=Element)
				{
					if(Self.browser.isIE)
					{
						Output=(Node.offsetLeft?Node.offsetLeft:0)+(Node.parentNode?this.getOffsetX(Node.parentNode,Element):0);
					}
					else
					{
						Output=(Node.offsetLeft?Node.offsetLeft:0)-(Element.offsetLeft?Element.offsetLeft:0);
					}
				}
				
				return Output;
			},
			
			getOffsetY:function(Node,Element)
			{
				Output	=0;
				Element	=Element?Element:document;

				if(Node && Node!=Element)
				{
					if(Self.browser.isIE)
					{
						Output=(Node.offsetTop?Node.offsetTop:0)+(Node.parentNode?this.getOffsetY(Node.parentNode,Element):0);
					}
					else
					{
						Output=(Node.offsetTop?Node.offsetTop:0)-(Element.offsetTop?Element.offsetTop:0);
					}
				}
				
				return Output;
			}
		};

		/*////////////////////////////////////*/
		/*//////////// THIS.EVENT ////////////*/
		/*////////////////////////////////////*/

		this.event=
		{
			addListener:function(Node,Type,Handler)
			{
				Node=typeof(Node)=='string'?document.getElementById(Node):Node;

				var Id=null;

				if(Node && typeof(Handler)=='function')
				{
					Type=Type.toLowerCase();

					Node.eventHandler=typeof(Node.eventHandler)=='object'?Node.eventHandler:{count:1,types:{}};

					var Id=Node.eventHandler.count;

					Node.eventHandler.types[Type]		=typeof(Node.eventHandler.types[Type])=='object'?Node.eventHandler.types[Type]:{};
					Node.eventHandler.types[Type][Id]	=Handler;

					Node['on'+Type]=function(e)
					{
						var Output=true;

						for(var a in Node.eventHandler.types[Type])
						{
							if(typeof(Node.eventHandler.types[Type][a])=='function')
							{
								Output=Node.eventHandler.types[Type][a](e?e:event);
							}
						}

						return Output;
					}

					Node.eventHandler.count++;
				}

				return Id;
			},
			
			addListeners:function(Node,Object)
			{
				if(typeof(Object)=='object')
				{
					for(var a in Object)
					{
						this.addListener(Node,a,Object[a]);
					}
				}			
			},

			removeListener:function(Node,Id)
			{
				if(Id && Node)
				{
					if(typeof(Node.eventHandler)=='object')
					{
						for(var a in Node.eventHandler.types)
						{
							if(typeof(Node.eventHandler.types[a][Id])=='function')
							{
								Node.eventHandler.types[a][Id]=null;
								delete Node.eventHandler.types[a][Id];
							}
						}
					}
				}
			}
		};

		/*////////////////////////////////////*/
		/*///////// THIS.CONTEXTMENU /////////*/
		/*////////////////////////////////////*/

		this.contextMenu=
		{
			add:function(Menu,Button,AutoHide)
			{
				if(Self.isLoaded)
				{
					Menu	=typeof(Menu)=='string'		?document.getElementById(Menu)	:Menu;
					Button	=typeof(Button)=='string'	?document.getElementById(Button):Button;
					AutoHide=typeof(AutoHide)=='boolean'?AutoHide						:true;

					if(Menu && Button)
					{
						Menu.style.position='absolute';Menu.style.top='0px';Menu.style.left='0px';Menu.style.visibility='hidden';

						Menu.isUp=0;

						if(typeof(Menu.events)!='object')
						{
							Menu.events	=
							[
								Self.event.addListener(Menu						,'mousedown'	,function(e){ Menu.isUp=1; }),
								Self.event.addListener(Menu						,'mouseout'		,function(e){ Menu.isUp=0; }),
								Self.event.addListener(Menu						,'mouseup'		,function(e){ Menu.isUp=0;(AutoHide?Self.contextMenu.hide(Menu):null); }),
								Self.event.addListener(document.body.parentNode	,'mousedown'	,function(e){ (Menu.isUp?null:Self.contextMenu.hide(Menu)); })
							];
						}

						Menu.events.push(Self.event.addListener(Button,'contextmenu',function(e){ Self.contextMenu.show(Menu,Self.mouse.getX(e),Self.mouse.getY(e));e.cancelBubble=true;return false; }));
					}
				}
				else
				{
					Self.event.addListener(window,'load',function(){ Self.contextMenu.add(Menu,Button,AutoHide); });
				}
			},

			remove:function(Menu)
			{
				Menu=typeof(Menu)=='string'?document.getElementById(Menu):Menu;

				if(Menu)
				{
					if(Menu.events)
					{
						for(var a in Menu.events)
						{
							Self.event.removeListener(Menu.events[a]);
						}
					}
				}
			},

			show:function(Menu,X,Y)
			{
				this.hide(Menu);

				Menu=typeof(Menu)=='string'?document.getElementById(Menu):Menu;

				if(Menu)
				{
					X=typeof(X)=='undefined'?0:X;
					Y=typeof(Y)=='undefined'?0:Y;

					var MaxHeight	=document.body.parentNode.clientHeight;
					var MaxWidth	=document.body.parentNode.clientWidth;

					Menu.style.left		=(X+Menu.clientWidth<MaxWidth	?X:X-Menu.clientWidth)+'px';
					Menu.style.top		=(Y+Menu.clientHeight<MaxHeight	?Y:Y-Menu.clientHeight)+'px';

					Menu.style.position	='absolute';Menu.style.zIndex='95';Menu.style.visibility='visible';
				}
			},

			hide:function(Menu)
			{
				Menu=typeof(Menu)=='string'?document.getElementById(Menu):Menu;

				if(Menu)
				{
					Menu.style.visibility='hidden';
				}
			},

			enable:function(Menu,Enable)
			{
				Menu=typeof(Menu)=='string'?document.getElementById(Menu):Menu;

				if(Menu)
				{
					Menu.style.display=Enable?'':'none';
				}
			},

			enableItem:function(Menu,Item,Enable)
			{
				Menu=typeof(Menu)=='string'?document.getElementById(Menu):Menu;
				Item=typeof(Item)=='string'?document.getElementById(Item):Item;

				if(Menu && Item)
				{
					Item.style.display=Enable?'':'none';
				}
			}
		};

		/*##############################################*/
		/*################ PRIVATE.HELP ################*/
		/*##############################################*/

		/*////////////////////////////////////*/
		/*////////// THIS.CONSTRUCT //////////*/
		/*////////////////////////////////////*/

		this.construct(arguments);
	};