// JavaScript Document
	function getElementBoxCoordsById(elementID)
	{
		var element = document.getElementById(elementID);
		if (element != null)
		{
			return getElementBoxCoords(element);
		}
	}

	
	function BoxCoords(x1,y1,x2,y2) {
		this.x1 = x1 || 0;
		this.y1 = y1 || 0;
		this.x2 = x2 || 0;
		this.y2 = y2 || 0;
	}
	
	function XYCoords(x,y) { 
		this.x = x || 0;
		this.y = y || 0;	
	}
	
	function Dimensions(w,h) { 
		this.width = w || 0;
		this.height = h || 0;
	}


	function JavaScriptSystem()
	{
		this.isAlien=function(a) {
			return this.isObject(a) && typeof a.constructor != "function";
		}
		
		this.isArray=function(a) {
			return this.isObject(a) && a.constructor == Array;
		}
		
		this.isBoolean=function(a) {
			return typeof a == "boolean";
		}
		
		this.getElement=function(Name){
			return document.all?document.all(Name):document.getElementById(Name);	
		}
		
		this.isEmpty=function(o) {
			var i, v;
			if (this.isObject(o))
			{
				for (i in o) 
				{
					v = o[i];
					if (this.isUndefined(v) && this.isFunction(v))
					{
						return false;
					}
				}
			}
			return true;
		}
		
		this.isFunction=function(a) {
			return typeof a == "function";
		}
		
		this.isNull=function(a) {
			return typeof a == "object" && !a;
		}
		
		this.isNumber=function(a) {
			return typeof a == "number";
		}
		
		this.isObject=function(a) {
			return (a && typeof a == "object") || this.isFunction(a);
		}
		
		this.isString=function(a) {
			return typeof a == "string";
		}
		
		this.isTag=function(a) {
			return (a.nodeType && a.nodeType == 1);
		}
		
		this.isUndefined=function(a) {
			return typeof a == "undefined";
		} 
		
		this.getElementById=function(s){
			return document.getElementById(s);
		}
		
		this.removeElementFromDOM=function(id) {
			var element = this.getElementById(id);
			return element.parentNode.removeChild(element);
		}
		
		this.resolveElementId=function(elem)
		{
			if(elem)
			{
				var id = elem.getAttribute("id");
				if(!id) 
				{			
					var name = elem.nodeName.toLowerCase();
					id = this.randomId(name);
					elem.setAttribute('id', id);
				}
				return id;
			}
			return null;
		}
		
		this.randomId=function(name)
		{
			var num = Math.floor(Math.random()*1000);
			name = (name) ? name : "rand";
			var id = (name+num);
			while(this.getElementById(id))
			{
				id = name+(num++);
			}
			return id;
		}
		
		this.getFirstTag=function(parent,tagname)
		{
			if(!parent) return null;
			var nodes = parent.childNodes;
			for(var i=0,len=nodes.length;i<len;i++)
			{
				var node = nodes[i];
				if(node && node.nodeType == 1)
				{
					if(!tagname)
						return node;
					else if(node.nodeName == tagname)
						return node;
					else
						continue;	
				}
			}
			return null;
		}

		this.getChildTags=function(parent, tagname)
		{
			if(!parent) return null;
			var output = new Array();
			var nodes = parent.childNodes;
			for(var i=0,len=nodes.length;i<len;i++)
			{
				var node = nodes[i];
				if(node && node.nodeType == 1)
				{
					if(!tagname)
						output.push(node);
					else if(node.nodeName == tagname)
						output.push(node);
					else
						continue;
				}
			}
			return output;
		}
		
		this.attrExp=function(s)
		{
			return new RegExp("(^| )"+s+"( |$)"); 
		}

		this.getAttrValue=function(node, attr)
		{
			if(node[attr] != null) return node[attr];
			if(node.getAttribute(attr) != null) return node.getAttribute(attr);
			return "";
		}
		

		this.getWindowDimensions=function() {
			var width = (window.innerWidth) ? window.innerWidth : document.body.clientWidth;
			var height = (window.innerHeight) ? window.innerHeight : document.body.clientHeight;
			return new Dimensions(width,height);
		}
		
		
		this.getContentDimensions=function() {
			var width = Math.max(document.body.offsetWidth,document.body.scrollWidth);
			var height = Math.max(document.body.offsetHeight,document.body.scrollHeight);
			return new Dimensions(width,height);
		}
		
		this.getScrollPosition=function() {
			var scrollPosition = new XYCoords();
			if (window.scrollX && window.scrollY)
			{
				scrollPosition.x = window.scrollX;
				scrollPosition.y = window.scrollY;
			}
			else
			{
				var docBody = document.body;
				var parent_scrollLeft = (docBody.parentNode.scrollLeft) ? docBody.parentNode.scrollLeft : 0;
				var parent_scrollTop = (docBody.parentNode.scrollTop) ? docBody.parentNode.scrollTop : 0;
				scrollPosition.x = Math.max(docBody.scrollLeft,parent_scrollLeft);
				scrollPosition.y = Math.max(docBody.scrollTop,parent_scrollTop);
			}
			return scrollPosition;
		}


	}
	
	function getEventCoords (e) {
		var coords = new XYCoords();
		if (e.pageX && e.pageY) {
			coords.x = e.pageX;
			coords.y = e.pageY;
		}
		else if (e.clientX && e.clientY)
		{
			coords.x = e.clientX + document.body.scrollLeft;
			coords.y = e.clientY + document.body.scrollTop;
		}
		return coords;
	}
	
	function getElementBoxCoords(domElement)
	{
		this.element = domElement;
		this.calculated_offset;
		this.calcOffsetFrom = function (element,from,reset)
		{
			if (reset != false) this.calculated_offset = 0;
			if (element != null)
			{
				switch (from)
				{
					case 'top': 
					this.calculated_offset += element.offsetTop;
					break;
					case 'left': 
					this.calculated_offset += element.offsetLeft;
					break;
				}
				if ((element.offsetParent == document.body) || (element.offsetParent.tagName == ('HTML'||'BODY')))
				{				
					return this.calculated_offset;
				}
				else
				{
					return this.calcOffsetFrom(element.offsetParent,from,false);
				}
			}
		}
		this.w = this.element.offsetWidth;
		this.h = this.element.offsetHeight;
		var coords = new BoxCoords();
		coords.x1 = this.calcOffsetFrom(this.element,'left',true);
		coords.y1 = this.calcOffsetFrom(this.element,'top',true);
		coords.x2 = coords.x1 + this.w;
		coords.y2 = coords.y1 + this.h;
		return coords;
	}	
	
	var System=new JavaScriptSystem();
