function XMLUtils() {
	this.root = null;
}

XMLUtils.prototype.escstr = function(str) {
	if (this.root == null) {
		var x = this.loadstr("<xml></xml>");
		this.root = x.createTextNode("");
	}
	this.root.nodeValue = str;
	if (typeof XMLSerializer != "undefined")
		return (new XMLSerializer( )).serializeToString(this.root);
	return this.root.xml;
}

XMLUtils.prototype.createclfBHNode = function(id, categ) {
	var xml = this.loadstr("<xml></xml>");
	var clfBH = xml.createElement("clfBH");
	clfBH.setAttribute("id", id);
	clfBH.setAttribute("category", categ);
	if (typeof XMLSerializer != "undefined")
		return (new XMLSerializer( )).serializeToString(clfBH);
	return clfBH.xml;
}

XMLUtils.prototype.loadstr = function(str) {
	if (typeof DOMParser != "undefined") {
		// Mozilla, Firefox, and related browsers
		return (new DOMParser( )).parseFromString(str, "application/xml");
	} else if (typeof ActiveXObject != "undefined") {
		// Internet Explorer
		var root = new ActiveXObject("MSXML2.DOMDocument");
		root.preserveWhiteSpace = true;
		root.loadXML(str);
		return root;
	} else {
		// ???
		throw new Error("CLFERROR: Unsupportable browser");
	}
}

function CSSUtils(cssname) {
	this._css = null;
	cssname = cssname.toLowerCase();
	for (var i=0; i < document.styleSheets.length && this._css == null; i++)
		if (document.styleSheets[i].href.toLowerCase().indexOf(cssname) > -1)
			this._css = document.styleSheets[i];
	if (this._css == null) return null;
	this._rules = this._css.cssRules ? this._css.cssRules : this._css.rules;
}

CSSUtils.prototype.setStyle = function(selector, styleName, styleValue) {
	selector = selector.toLowerCase();
	for (var i = 0; i < this._rules.length; i++) {
		if (this._rules[i].selectorText.toLowerCase() == selector) {
			this._rules[i].style[styleName] = styleValue;
			break;
		}
	}
}

CSSUtils.prototype.disableSelector = function(selector) {
	var from = '.' + selector;
	var to = '.DISABLE' + selector + 'DISABLE';
	this.changeSelector(from, to);
}

CSSUtils.prototype.enableSelector = function(selector) {
	var from = '.DISABLE' + selector + 'DISABLE';
	var to = '.' + selector;
	this.changeSelector(from, to);
}

CSSUtils.prototype.changeSelector = function(from, to) {
	if (this._css.cssText != null) { // IE
		this._css.cssText = this._css.cssText.replace(from, to);
	} else { // FF
		from = from.toLowerCase();
		for (var i = 0; i < this._rules.length; i++) {
			if (this._rules[i].selectorText.toLowerCase() == from)
				this._rules[i].selectorText = to;
				break;
		}	
	}
}




