if(!com){var com=new Object();}
if(typeof com.lbi=="undefined"){com.lbi=new Object();}
if(typeof com.lbi.utils=="undefined"){com.lbi.utils=new Object();}
if(typeof com.lbi.utils.DomUtils=="undefined"){com.lbi.utils.DomUtils=new Object();}

com.lbi.utils.DomUtils = function(){
}

com.lbi.utils.DomUtils.getInnerHTMLasXML = function (div_id) {
	var str = document.getElementById(div_id).innerHTML;
	var re,m;
	re = new RegExp("<[a-z]+\\s[^>]+>","gi");
	m = re.exec(str);
	if(m != null){
		while(m != null){
			str = str.substring(0,m.index)+com.lbi.utils.DomUtils.__addAttributeQuotes(m[0])+str.substring(m.index+m[0].length,str.length);
			m = re.exec(str);
		}
	}
	re = new RegExp("<(br|img[^>]+)>","gi");
	m = re.exec(str);
	if (m != null) {
		while(m != null){
			if(str.charAt(m.index+m[1].length) != "/"){
				str=str.substring(0,m.index+m[1].length+1)+" /"+str.substring(m.index+m[1].length+1,str.length);
			}else if(str.charAt(m.index+m[1].length-1) != " "){
				str=str.substring(0,m.index+m[1].length)+" "+str.substring(m.index+m[1].length,str.length);
			}
			m = re.exec(str);
		}
	}
	return str;
}
	
com.lbi.utils.DomUtils.__addAttributeQuotes = function(str){
	var re = new RegExp("=[a-z0-9]+","gi");
	m = re.exec(str);
	if(m != null){
		while(m != null){
			str = str.substring(0,m.index+1)+"\""+m[0].substring(1,m[0].length)+"\""+str.substring(m.index+m[0].length,str.length);
			m = re.exec(str);
		}
	}
	return str;
}
//TODO: provide full support for attributes
com.lbi.utils.DomUtils.innerHTML = function (src_obj)
{
	var InnerHTML = com.lbi.utils.DomUtils.innerHTML;
	var str_out='';
	
	var children=src_obj.childNodes;
	
	for (var i=children.length-1; i>=0; i--)
	{
		var c_node=children[i];
		
		if(c_node.nodeType==1) // element
		{
			var attr_str = "";
			attr_str += (c_node.getAttributeNode("id")) ? " id='" + c_node.getAttributeNode("id").nodeValue + "'" : "";
			attr_str += (c_node.getAttributeNode("href")) ? " href='" + c_node.getAttributeNode("href").nodeValue + "'" : "";
			attr_str += (c_node.getAttributeNode("class")) ? " class='" + c_node.getAttributeNode("class").nodeValue + "'" : "";
			str_out = 	'<' + c_node.tagName + attr_str + '>' +
						 InnerHTML(c_node) +  '</' + c_node.tagName + '>' + str_out;
		}else{ // 3 = text
			str_out = c_node.nodeValue + str_out;			
		}
	}
	return str_out;
}
