Utilities = {

	Import : function(){
		
		for(var x in this.BaseFunctions){
			var c = this.BaseFunctions[x];
			if(!window[c] && this[c]){
				window[c] = this[c];
				}
			}
	
		for(var i = 0; i < arguments.length; i++){
			
			var c = arguments[i];
			if(!window[c] && this[c]){
				window[c] = this[c];
				}
			}		
		},
	
	BaseFunctions : [
		'AddClass',
		'AddEvent',
		'AddOption',
		'EmptyElement',
		'GetPosition',
		'GetCookie',
		'GetValue',
		'RemoveClass',
		'RemoveEvent',
		'Screen',
		'Scroll',
		'SetCookie',
		'SetValue'		
		],
	
	AddClass : function(el, className){
		
		if(typeof(el) == 'string'){
			el = document.getElementById(el);
			}
		
		if(el.className == ''){
			el.className = className;
			}
		else{
			el.className += ' ' + className;
			}
		},

	AddEvent : function(obj, evt, func){
	
		if(typeof(obj) == 'string'){
			obj = document.getElementById(obj);
			}
	
		if(func && obj){
			if(obj.addEventListener){
				obj.addEventListener(evt, func, false);
				}
			else if(obj.attachEvent){
				obj.attachEvent('on' + evt, func);
				}
			else{
				eval('obj.on' + evt + ' = func;');
				}
			}
		},
	
	AddOption : function(select, value, text){
	
		var option = document.createElement('option');
		option.value = value;
		option.text = text;
		
		try{
			select.add(option);
			}
		catch(err){
			select.add(option, null);
			}
		
		return option
		},
	
	EmptyElement : function(element){
		
		if(typeof(element) == 'string'){
			element = document.getElementById(element);
			}
		
		if(element){
			for(i = element.childNodes.length; i > 0; i --){
				element.removeChild(element.childNodes[i - 1]);
				}
			}			
		},
	
	GetPosition : function(obj){

		if(typeof(obj) == 'string'){
			obj = document.getElementById(obj);
			}
	
		var pos = {
			X : null,
			Y : null
			}
		
		if(obj){
			pos.X = obj.offsetLeft;
			pos.Y = obj.offsetTop;
			
			while(obj = obj.offsetParent){
				pos.X += obj.offsetLeft || 0;
				pos.Y += obj.offsetTop || 0;
				}
			}
		
		return pos;
		},
	
	GetCookie : function(name){
	
		if(document.cookie.length > 0){
			startPos = document.cookie.indexOf(name + "=");
			if(startPos != -1){ 
				startPos = startPos + name.length + 1; 
				endPos = document.cookie.indexOf(";", startPos);
	 			if(endPos == -1){
	 				endPos = document.cookie.length;
	 				}
				return unescape(document.cookie.substring(startPos, endPos));
				} 
			}
		
		return false;
		},
	
	GetValue : function(obj){
		
		if(typeof(obj) == 'string'){
			obj = document.getElementById(obj);
			}
		
		return obj.value;
		},
	
	RemoveClass : function(el, className){
		
		if(typeof(el) == 'string'){
			el = document.getElementById(el);
			}
		
		if(el.className == className){
			el.className = '';
			}
		else if(el.className.match(new RegExp(className + "( )?"))){
			el.className = el.className.replace(new RegExp(className + "( )?"), '');
			}
		else if(el.className.match(new RegExp("( )?" + className))){
			el.className = el.className.replace(new RegExp("( )?" + className), '');
			}
		},

	RemoveEvent : function(obj, evt, func){
	
		if(typeof(obj) == 'string'){
			obj = document.getElementById(obj);
			}
	
		if(obj.removeEventListener){
			obj.removeEventListener(evt, func, false);
			}
		else if(obj.detachEvent){
			obj.detachEvent('on' + evt, func);
			}
		else{
			eval('obj.on' + evt + ' = function(){}');
			}
		},
	
	Screen : function(){
		
		var Screen = {
			Width : 0,
			Height : 0
			};

		if(typeof(window.innerWidth) == 'number'){
			//Non-IE
			Screen.Width = window.innerWidth;
			Screen.Height = window.innerHeight;
			}
		else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
			//IE 6+ in 'standards compliant mode'
			Screen.Width = document.documentElement.clientWidth;
			Screen.Height = document.documentElement.clientHeight;
			}
		else if(document.body && (document.body.clientWidth || document.body.clientHeight)){
			//IE 4 compatible
			Screen.Width = document.body.clientWidth;
			Screen.Height = document.body.clientHeight;
			}
		
		return Screen;
		},
	
	Scroll : function(){
	
		var Scroll = {
			Left : 0,
			Top : 0
			};
		
		if(typeof(window.pageYOffset) == 'number'){
			//Netscape compliant
			Scroll.Left = window.pageXOffset;
			Scroll.Top = window.pageYOffset;
			}
		else if(document.body && (document.body.scrollLeft || document.body.scrollTop)){
			//DOM compliant
			Scroll.Left = document.body.scrollLeft;
			Scroll.Top = document.body.scrollTop;
			}
		else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)){
			//IE6 standards compliant mode
			Scroll.Left = document.documentElement.scrollLeft;
			Scroll.Top = document.documentElement.scrollTop;
			}
		
			return Scroll;
		},
	
	SetCookie : function(name, value, expirationInDays){
	
		var today = new Date();
		var expire = new Date();
		if(expirationInDays == null || expirationInDays == 0){
			expirationInDays = 1;
			}
		expire.setTime(today.getTime() + 3600000 * 24 * expirationInDays);
		document.cookie = name + "=" + escape(value) + ";expires=" + expire.toGMTString();
		},
	
	SetValue : function(obj, value){
		
		if(typeof(obj) == 'string'){
			obj = document.getElementById(obj);
			}
		
		obj.value = value;
		},
		
	Constants : {
		
		}
	}
