//
// domhelpers.js
// Shamelessly copied and pasted from http://slayeroffice.com/articles/innerHTML_alternatives/
//

//
// dce
// Create an element node.
//
function dce(p_Element) {
	return document.createElement(p_Element);
}

//
// dct
// Create a text node.
//
function dct(p_String) {
	return document.createTextNode(p_String);
}

//
// ac
// Append child to parent node.
//
function ac(p_Parent,p_Node) {
	p_Parent.appendChild(p_Node);
}

//
// act
// Append text note to parent, created from the text.
//
function act(p_Parent,p_String)
{
	ac(p_Parent,dct(p_String));
}

//
// acet
// Append an element node with child text node to a parent node.
//
function acet ( p_Parent , p_Element , p_String )
{
	var e = dce(p_Element);
	var t = dct(p_String);
	ac(e,t);
	ac(p_Parent,e);
	return e;
}

//
// sa
// Set attribute on element.
//
function sa(p_Element,p_Attribute,p_String) {
	p_Element.setAttribute(p_Attribute,p_String);
}

//
// ge
// Get element by ID.
//
function ge(p_ID) {
	return document.getElementById(p_ID);
}

//
// dcea
// Create anchor tag.
//
function dcea ( p_Href , p_Text )
{
   var a = dce('a');
   sa(a,'href',p_Href);
   act(a,p_Text);
   return a;
}

// 
// so_getText
// Returns a string of all text found in obj.
//
function so_getText(p_Node) {
	if(p_Node.textContent) return p_Node.textContent;
	if (p_Node.nodeType == 3) return p_Node.data;
	var innerText = new Array(), i=0;
	while(p_Node.childNodes[i]) {
		innerText[innerText.length] = so_getText(p_Node.childNodes[i]);
		i++;
	}
    return innerText.join('');
}

//
// so_applyStyleString
// Applies a string of styles to an object.
//
function so_applyStyleString(p_Node,p_Style) {
	if(document.all && !window.opera) {
		p_Node.style.setAttribute('cssText',p_Style);
	} else {
		p_Node.setAttribute('style',p_Style);
	}
}

//
// so_clearInnerHTML
// A DOM based approach to clearing the contents of an object without setting its innerHTML property.
//
function so_clearInnerHTML(p_Node) {
	while(p_Node.firstChild) p_Node.removeChild(p_Node.firstChild);
}

//
// AddListItem
// Add a list item to a list.
// Creates the list if not created already.
// Returns the created list.
//
function AddListItem ( p_List , p_String , p_Element )
{
	if ( !p_List )
		p_List = dce('ul');
	var item = dce('li');
	if ( p_Element )
		acet(item,p_Element,p_String);
	else
		ac(item,dct(p_String));
	ac(p_List,item);
	return p_List;
}
