// dom v2.5

//	Object evt
//		Works with DOM event
//	
//	METHODS
//	
//	Event evt.fix(event e)
//		Fixes event compatibility, returns compatible Event object
//	
//	Boolean evt.add(HtmlElement obj, String evType, Function fn[, Boolean useCapture])
//		Attaches event listener to element "obj".
//	
//	Boolean evt.remove(HtmlElement obj, String evType, Function fn[, Boolean useCapture])
//		Removes event listener from object.
//		Parameter "fn" is the same function that has been added by evt.add. If the function to remove
//		is not the same, it will not be removed, even if the two functions had identical syntax.
//	
//	HtmlElement evt.getTarget(Event e[, String tagName])
//		Finds event target that has given tagName. If tagName is not specified, returns normal target
//	
//	Boolean evt.stop(Event e)
//		Stops event propagation and cancels default event handling

var evt = {
	
	fix: function(e) {
		if (typeof e == "undefined") e = window.event;
		if (typeof e.target == "undefined") e.target = e.srcElement;
		if (typeof e.layerX == "undefined") e.layerX = e.offsetX;
		if (typeof e.layerY == "undefined") e.layerY = e.offsetY;
		if (!e.preventDefault) {
			e.preventDefault = function() {
				e.returnValue = false;
			} // thanx to KKL2401 for preventDefault hack
		}
		return e;
	},

	add: function(obj, evType, fn, useCapture) {
		if (window.opera && (obj == window)) obj = document; // Opera hack
		if (obj.addEventListener) { // standard way
			obj.addEventListener(evType, fn, useCapture);
			return true;
		} else if (obj.attachEvent){ // MSIE
			return obj.attachEvent("on" + evType, fn);
		}
		return false;
	},

	remove: function(obj, evType, fn, useCapture) {
		if (window.opera && (obj == window)) obj = document; // Opera hack
		if (obj.removeEventListener) {
			obj.removeEventListener(evType, fn, useCapture);
			return true;
		} else if (obj.detachEvent) {
			return obj.detachEvent("on"+evType, fn);
		}
		return false;
	},

	getTarget: function(e, tagName) {
		var obj; // HtmlElement
		e = evt.fix(e);
		obj = e.target;
		if (typeof tagName == "string") { // search for parent with tagName
			while (obj.tagName.toLowerCase() != tagName) {
				if (obj.tagName && (obj.tagName.toLowerCase() == "html"))
					return null; // not found
				obj = obj.parentNode;
			}
		}
		return obj;
	},

	stop: function(e) {
		if (typeof e == "undefined")
			e = window.event;
		if (!e.preventDefault) { // MSIE
			e.cancelBubble = true;
			e.returnValue = false;
		} else { // Standard
			e.preventDefault();
			e.stopPropagation();
		}
		return true;
	}
};



//	Object cls
//		Class manipulations
//	
//	
//	METHODS
//	
//	Array cls.get(HtmlElement obj)
//		Returns aall classes of the element "obj" as Array of Strings
//	
//	Boolean cls.has(HtmlElement obj, String cl)
//		Returns true if element "obj" contains the class "cl"
//	
//	Boolean cls.add(HtmlElement obj, String cl)
//		Adds class "cl" to element "obj" if it is not present
//	
//	Boolean cls.remove(HtmlElement obj, String cl)
//		Removes class "cl" from element "obj"
//	
//	Boolean cls.replace(HtmlElement obj, String oldCl, String newCl)
//		Replaces class "oldCl" by class "newCl". If there is no "oldCl" adds "newCl".

var cls = {
	get: function(obj) {
		var cl; // String
		if (obj && obj.tagName) {
			cl = obj.className.replace(/\s+/g, " ");
			return cl.split(" ");
		}
		return null;
	},

	has : function(obj, cl) {
		var i; // Int
		if ((typeof cl == "string") && (actCl = cls.get(obj)))
			for (i = 0; i < actCl.length; i++)
				if (actCl[i] == cl)	return true;
		return false;
	},

	add : function(obj, cl) {
		var actCl = cls.get(obj);
		if ((typeof cl != "undefined") && (actCl != null)) {
			if (!cls.has(obj, cl)) 
				obj.className += (actCl.length > 0) ? " " + cl : cl;
			return true;
		}
		return false;
	},

	remove: function(obj, cl) {
		var i; // Int iterator
		var actCl = cls.get(obj); // String
		var tempCl = ""; // String
		if ((typeof cl == "string") && (actCl != null)) {
			for (i = 0; i < actCl.length; i++) {
				if (actCl[i] != cl) {
					if (tempCl != "") {tempCl += " ";}
					tempCl += actCl[i];
				}
				obj.className = tempCl;
			}
			return true;
		}
		return false;
	},

	replace: function(obj, oldCl, newCl) {
		var i; // Int iterator
		var actCl = cls.get(obj); // String
		var tempCl = ""; // String
		if ((typeof oldCl == "string") && (typeof newCl == "string") && (actCl != null)) {
			if (cls.has(obj, newCl)) {
				cls.remove(obj, oldCl);
			} else if (cls.has(obj, oldCl)) {
				for (i = 0; i < actCl.length; i++) {
					if (tempCl != "") {tempCl += " ";}
					tempCl += (actCl[i] == oldCl) ? newCl : actCl[i];
				}
				obj.className = tempCl;
			} else {
				cls.add(obj, newCl);
			}
			return true;
		}
		return false;
	}
};



//	Object cook
//		Cookie manager
//	
//	
//	METHODS
//	
//	Boolean cook.set(String name, String value[, Int days])
//		Sets cookie
//	
//	String cook.get(String name)
//		Returns cookie content text
//	
//	Boolean cook.remove(String name)
//		Removes cookie

var cook = {

	set: function(name, value, days) {
		var date; // Date
		var expires; // String
		if (typeof days != "undefined") {
			date = new Date();
			date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
			expires = "; expires=" + date.toGMTString();
		} else expires = "";
		document.cookie = name + "=" + value + expires + "; path=/";
		return true;
	},

	get: function(name) {
		var i; // Int iterator
		var nameEQ = name + "="; // String
		var c; // String
		var ca = document.cookie.split(';'); // Array of Strings
		for (i = 0; i < ca.length; i++) {
			c = ca[i];
			while (c.charAt(0) == ' ')
				c = c.substring(1, c.length);
			if (c.indexOf(nameEQ) == 0)
				return c.substring(nameEQ.length, c.length);
		}
		return null;
	},

	remove: function(name) {
		saveCookie(name, "", -1);
	}
};



//	Object elm
//		Elements manipulation object
//	
//	
//	METHODS
//	
//	HtmlElement elm.get(HtmlElement|String elmIdentity)
//		Returns element defined by elmIdentity. If elmIdentity is HtmlElement, returns it.
//		If elmIdentity is string, tries to find element with id equal to elmIdentity and returns that element.
//		Otherwise it returns null
//	
//	HtmlCollection elm.getByTag(String tagName[, HtmlElement srcElm])
//		Collects all child elements of srcElm with given tagName
//	
//	String elm.getValue(HtmlElement srcElm)
//		Reads element value. Can read inputs and selects

var elm = {

	get: function(elmIdentity) {
		if (typeof elmIdentity == "undefined") return null;
		if (typeof elmIdentity == "string")
			return document.getElementById(elmIdentity);
		else return elmIdentity;
	},

	getByTag: function(tagName, srcElm) {
		srcElm = (srcElm) ? srcElm : document;
		if (srcElm.all && (tagName == "*"))	// MSIE hack
			return(srcElm.all);
		if (srcElm.getElementsByTagName)	// standard way
			return srcElm.getElementsByTagName(tagName.toUpperCase());
		return false;
	},

	getValue: function(srcElm) {
		if (srcElm.value) return srcElm.value; // element is standard INPUT
		if (srcElm.selectedIndex && srcElm.options) // element is SELECT
			return srcElm.options[srcElm.selectedIndex].value;
		return srcElm.innerHTML;
	},

	getAttribute: function(srcElm, attrName) {
		if ((attrName == "class") && (typeof srcElm.getAttribute("class") == "undefined"))
			return srcElm.getAttribute("className");
		if ((attrName == "for") && (srcElm.getAttribute("for") == null))
			return srcElm.getAttribute("htmlFor");
		return srcElm.getAttribute(attrName);
	}
};

