/* 
==============================
Dom Functions
==============================
This Javascript cucumber was pickled by:
>> Robin Wallar at See Design
>> www.seedesign.ca | robin [at] seedesign.ca
------------------------------
Written with massive mits on while scraping ice of the screen
of my icicle that serves as a monitor. 
------------------------------

------------------------------
Feel free to use this to educate
yourself on the wonders of javascript.
If you plan on copying something directly please contact us. 
------------------------------
*/

/*get dom value of an id of and elemtn and return it
gebi = get element by id
*/
function gebi(id)
{
	return document.getElementById(id);

}

/*this will return the text and children of an element*/
function get_text(obj)
{
	// return the data of obj if its a text node
	if (obj.nodeType == 3)
	{
		return obj.nodeValue;
	}
	
	var txt = new Array(),i=0;
   
   // loop over the children of obj and recursively pass them back to this function
	while(obj.childNodes[i])
	{
		txt[txt.length] = get_text(obj.childNodes[i]);
		i++;
	}
    
	// return the array as a string
    return txt.join("");
}

/*this will clear an element*/
function clear(id)
{
	obj  = gebi(id);

	// perform a shallow clone on obj
	nObj = obj.cloneNode(false);
	// insert the cloned object into the DOM before the original one
	obj.parentNode.insertBefore(nObj,obj);
	// remove the original object
	obj.parentNode.removeChild(obj);
}

/*this will copy all the childrem from one elements to another*/
function clone(from, to)
{
	//Clone the origional el
	new_content = gebi(from).cloneNode(true);
	
	// clear the contents of the destination element.
	clear(to);
	
	// append the cloned element to the destination element
	gebi(to).appendChild(new_content);
}
