function get_docXHtml() {
	var doc = activeElement.DOM.body;
	var toReturn = innerXHTML(doc, new RegExp("contenteditable"));
	return toReturn;
}

function innerXHTMLAttributes(el, ignore) {
	var str = '';
	for (var i = 0; i < el.attributes.length; i++) {
		var attr = el.attributes[i];
		if (attr.nodeValue && typeof(attr.nodeValue) == "string") {
			if (!ignore || attr.nodeName.toLowerCase().search(ignore) == -1) {
				if (str.length) str += ' ';
				str += attr.nodeName.toLowerCase(); //lower
				str += '="' + (attr.nodeValue).replace(/[\"]/g, "&quot;") + '"'; //put between quotes, escape quote
			}
		}
	}
	return str;
}

function innerXHTML(el, ignore) {
	var str = '';
	var r2;
	var r = activeElement.DOM.body.createTextRange(); //create range 
	r.moveToElementText(el); //contain the element in the range 
	for (var i = 0; i < el.children.length; i++) { //for all the children 
		r2 = activeElement.DOM.body.createTextRange();

		// set the end of our range to the start of this child node.
		// so that r.text contains all the text up to this element.
		r2.moveToElementText(el.children[i]);
		r.setEndPoint("EndToStart", r2);
		str += r.text.replace(/[&]/g, "&amp;").replace(/[<]/g, "&lt;").replace(/[>]/g, "&gt;").replace(/["]/g, "&quot;");
		// emit the child node
		str += outerXHTML(el.children[i], ignore);
		// now, reset the text range for the main element and then move
		// the start point of our range to the end of the element just
		// output in preparation for the next chunk of text (or last chunk
		// if this was the last child node)
		r.moveToElementText(el);
		r.setEndPoint("StartToEnd", r2);
	}
	return str + r.text.replace(/[&]/g, "&amp;").replace(/[<]/g, "&lt;").replace(/[>]/g, "&gt;").replace(/["]/g, "&quot;");
}

function outerXHTML(el, ignore) {
	var attrs = innerXHTMLAttributes(el, ignore);
	var inner = innerXHTML(el, ignore);
	return '<' + el.nodeName.toLowerCase() + (attrs.length ? ' ' + attrs : '') + (inner.length ? '>' + inner + '</' + el.nodeName.toLowerCase() + '>':' />');
	//						lowercase the elementname  if there are attributes add them     if there are children add them and close
	//																							otherwise space                 otherwise close like <br/>
}

function util_Transform(html) {
	//var html = doc.innerHTML;
	//if (html) html = replaceCharacters(html);
	if (html) html = util_replaceAbsoluteUrls(html);
	if (html) html = util_remEmptyTags(html)
	//if (html) html = util_replaceTags([["strong","B"],["em","I"]],html);
	return html;
}

function util_remEmptyTags() {
	var html = activeElement.DOM.body.innerHTML;
	var re = /<[^(>|\/|td|tr)]+>[ |	]*<\/[^>]+>/gi;
	while(re.test(html)) {
		html = html.replace(re,"");
		while(re.test(html)) {
			html = html.replace(re,"");
		}
	}
	return html;
}

function util_replaceAbsoluteUrls(html) {
	//var html = activeElement.DOM.body.innerHTML;	
	var docLoc = document.location.toString();
	docLoc = docLoc.substring(0,docLoc.lastIndexOf("/")+1);
	docLoc = docLoc.replace(/\//gi,"\\\/");
	var re = eval("/"+docLoc+"/gi");
	return html.replace(re, "");
}
// set= [["strong", "b"], ["em", "i"]]
function util_replaceTags(set, html) {
	var re;
	for(var i = 0; i < set.length; i++) {
		re = eval("/(<[\/]{0,1})"+set[i][0]+">/gi");
		html=html.replace(re,"$1"+set[i][1]+">");
	}
	return html;
}

function util_ccParser(html) {
//	html = html.replace(/@/gi,"_AT_");
//	html = html.replace(/#/gi,"_DZ_");
//
	var htmltag = /(&lt;[\w\/]+[ ]*[\w\=\"\'\.\/\;\: \)\(-]*&gt;)/gi;
//	html = html.replace(htmltag,"<span class=ccp_tag>$1</span>");
	html = html.replace(htmltag,"<span style='color:#0000CC'>$1</span>");
//

	return html;
}function sg(a,a2,a3) {
	var r='';
	while (a.indexOf(a2)!=-1) {
		var v1=a.indexOf(a2);
		r+=a.substring(0,v1)+a3;
		a=a.substring(v1+a2.length);
	}
	return r+a;
}

function toSafeString(a) {
//	a = sg(a,'\\','\\\\'); // Backslash backslashes.
//	a = sg(a,'\n','\\n');  // Backslash newlines (Unix, Windows, DOS).
//	a = sg(a,'\r','\\r');  // Backslash newlines (Macintosh).
//	a = sg(a,'\t','\\t');  // Backslash tabs.
//	a = sg(a,'"','\\"');   // Backslash double quotes.
	a = sg(a,'\'','\\\'');
	//return '"' + a + '"';  // Return quoted string.
	return a; //Return nonquoted String
}
