var XB = {
	// XB::newXHR
	// creates new XMLHttpRequest object
	newXHR: function() {
		var XHR = false;
		try {
			XHR = new XMLHttpRequest();
		}
		catch (e) {
			var XHRVersions = Array(
			"MSXML2.XMLHTTP.5.0",
			"MSXML2.XMLHTTP.4.0",
			"MSXML2.XMLHTTP.3.0",
			"MSXML2.XMLHTTP",
			"Microsoft.XMLHTTP");
			var len=XHRVersions.length ;
			for (i=0; i<len && !XHR; i++) {
				try {
					XHR = new ActiveXObject(XHRVersions[i]);
				}
				catch (e) {}
			}
		}
		return XHR;
	},

	// XB::getElementsByClass
	// @param string		class to look for
	// @param string		tag to consider
	// @param DOM Element	node to start search from
	getElementsByClass: function(className, tagName, rootNode) {
		if (tagName == null) {
			tagName = '*';
		}
		if (rootNode == null) {
			rootNode = document;
		}
		var matchedArray = [];
		var elementArray = rootNode.getElementsByTagName(tagName);
		var len = elementArray.length;
		for (var i = 0; i < len; i++) {
			if (elementArray[i].className.indexOf(className) != -1) {
				matchedArray.push(elementArray[i]);
			}
		}
		return matchedArray;
	},

	// XB::appendClassToElement
	// @param	string		class name
	// @param	DOM Element	node to apply changes to
	// @return	DOM Element	node itself
	appendClassToElement: function(className, node) {
		node.className += ' ' + className;
		return node;
	},
	
	// XB::removeClassFromElement
	// @param	string		class name
	// @param	DOM Element	node to apply changes to
	// @return	DOM Element	node itself
	removeClassFromElement: function(className, node) {
		var classes = node.className.split(' ');
		var l = classes.length;
		var indexes = [];
		for (var i=0; i<l; i++) {
			if (classes[i] == className) {
				classes.splice(i, 1);
				l--; i--;
			}
		}
		node.className = classes.join(' ');
		return node;
	},

	// XB::getCookie
	// @param	string		Cookie name
	// @return	string		Cookie value or false in case there is no cookie by given name
	getCookie: function(name) {
		var cookies = document.cookie.split('; ');
		var value=false;
		for (var i=0; i<cookies.length; i++) {
			var cookie = cookies[i].split('=');
			if (cookie[0] == name) {
				value = cookie[1];
				break;
			}
		}
		return value;
	},
	
	// XB::setCookie
	// @param	string		Cookie name
	// @param	string		Cookie value to set
	// @param	uint		Epire timeout in seconds
	// @param	string		path for which the cookie is going to be valid
	// @return	void
	setCookie: function(name, value, expire, path) {
//		alert('setCookie ' + name + ' ' + value);
		var cookie = [];
		var date = new Date();
		if (expire) {
			date.setTime(date.getTime() + expire*1000);
		}
		if (!path) {
			path = '/';
		}
		cookie.push(name + '=' + value);
		cookie.push('expires=' + date.toGMTString());
		cookie.push('path=' + path);
		document.cookie = cookie.join('; ');
	},
	
	// XB::loadCSS
	// @param	string		CSS file URL
	// @param	boolean		is disabled by default
	// @return	DOMelement	link put into the header
	loadCSS: function(url, disabled) {
		disabled = (disabled == null || disabled) ? true : false;
		var linkObj = document.createElement('link');
		linkObj.rel = 'stylesheet';
		linkObj.type = 'text/css';
		linkObj.href = url;
		document.getElementsByTagName('head')[0].appendChild(linkObj);
		linkObj.disabled = disabled;
		return linkObj;
	},
	
	// XB::loadJS
	// @param	string		JS file URL
	// @return	DOMelement	link put into the header
	loadJS: function(url) {
		var scriptObj = document.createElement('script');
		scriptObj.type = 'text/javascript';
		scriptObj.src = url;
		document.getElementsByTagName('head')[0].appendChild(scriptObj);
		return scriptObj;
	}
}


