/**
 * Get browser information
 */
var UserData = new function() {
	function construct() {
		var 	browser 	= navigator.appName,
			version		= parseFloat(navigator.appVersion),
			userAgent	= navigator.userAgent,
			codeName	= navigator.appCodeName,
			isIE		= (browser == 'Microsoft Internet Explorer'),
			isSafari 	= (browser == 'Safari'),
			isFirefox	= (browser == 'Firefox'),
			isOpera		= (browser == 'Opera');
	}
	return new construct();
}

/** 
 * Some addtional methods to String class 
 */
/** Remove all spaceses from beging of string */
if ('undefined' == typeof String.prototype.ltrim) {
	String.prototype.ltrim = function() {
		return this.replace(/^\s+/, '');
	}
}
/** Remove all spaceses from end of string */
if ('undefined' == typeof String.prototype.rtrim) {
	String.prototype.rtrim = function() {
		return this.replace(/\s+$/, '');
	}
}
/** Remove all spaces ftom begining and end of the string */
if ('undefined' == typeof String.prototype.trim) {
	String.prototype.trim = function() {
		return this.replace(/^\s+/, '').replace(/\s+$/, '');
	}
}

/** 
 * Additional functions for working with numbers
 */
/** Check for NaN and returns 0 */
Number.prototype.NaN0 = function() {
	return (this == 'NaN')? 0: this; 
}

/** 
 * Additional functions for working with arrays
 */
/** Check array for elements */
Array.prototype.inArray = function (value) {
	for (var i = 0; i < this.length; i++) 
		if (this[i] === value) 
			return true;
	return false;
};
/** Remove item from array */
Array.prototype.removeFromArray = function(arr, element) { // removes only one item!
	for (itemIndex in arr) 
		if (arr[itemIndex] == element) {
			arr.splice(itemIndex, 1);
			return arr;
		}
	return arr;
}


/** Short form of getElementById method */
function $(id) {
	return document.getElementById(id);
}
/** Returns array of elements, which class name contains specified class name */
function getElementsByClass(searchClass, node, tag) {
	var classElements = Array();
	if (node == null)
		node = document;
	if (tag == null)
		tag = "*";
	var els = node.getElementsByTagName(tag);
	var pattern = " " + searchClass + " ";
	for (var i = 0, j = 0; i < els.length; i++) {
		var elementsClass = " " + els[i].className + " ";
		if (elementsClass.indexOf(pattern) != -1) 
			classElements[j++] = els[i];
	}
	return classElements;
}
