/*  GENERIC DOM-RELATED FUNCTIONS  */

// creates and returns a generic element
// designed for simple elements like div or p
// at a minimum, it must be passed an object with a property 'node_type'
var SSDOMCreateElement = function( obj ){
	if( obj.node_type ){
		mn = document.createElement( obj.node_type );

		// loop all properties of obj and add them as attributes
		for( var pr in obj ){
			// handle special ones
			// text node
			if( pr=='text_node' ){
				tn = SSDOMCreateTextNode( obj.text_node );
				mn.appendChild( tn );
			}
			// default, with extra little bit for class
			else{
				mn.setAttribute( pr,obj[pr] );
				if( pr=='className' ){
					mn.setAttribute( 'class',obj[pr] );
					mn.className = obj[pr];
				}
			}
		}
		return mn;
	}
	else{
		return null;
	}
};

// creates and returns a text node
var SSDOMCreateTextNode = function( str ){
	tn = null;
	if( str ){
		tn = document.createTextNode( str );
	}
	return tn;
};



/*  GENERIC FUNCTION TO EMPTY A NODE  */
var SSEmptyNode = function( the_node ){
	while( the_node.hasChildNodes() ){
		the_node.removeChild(the_node.firstChild);
	}
	return true;
};
/*  END GENERIC FUNCTION TO EMPTY A NODE  */



/*  GENERIC FUNCTION TO WALK XML DOM NODE AND TURN IT INTO XHTML  */
/*
	this is to work around Safari's "DOM Exception 4" complaint when I try to pass valid XHTML from XML directly into the XHTML DOM it directly into the tree
	ASSUMES THE NODE EQUATES TO VALID XHTML...DON'T PASS ARBITRARY XML TO THIS FUNCTION
*/
var SSXMLElementToXHTMLElement = function( obj ){
	var max = 0;
	// handle an element
	if( obj.nodeType==1 ){
		// create an element of that type
		var this_el = document.createElement( obj.nodeName );

		// loop all of its attributes
		for (var i = 0, max=obj.attributes.length; i < max; i++) {
			if( obj.attributes[i].name=='class' ){
				this_el.className = obj.attributes[i].value;
			}
			else{
				this_el.setAttribute(obj.attributes[i].name,obj.attributes[i].value);
			}
			//alert(  obj.attributes[i].name + ' - ' + obj.attributes[i].value );
		}
		// now loop the children of this element
		for( i = 0; i < obj.childNodes.length; i++ ){
			this_el.appendChild( SSXMLElementToXHTMLElement( obj.childNodes[i] ) );
		}
		return( this_el );
	}
	// handle a text node
	else if( obj.nodeType==3 ){
		// create a text node
		the_txt = document.createTextNode( obj.nodeValue );
		return( the_txt );
	}
	// handle a comment
	
};

/*  END GENERIC FUNCTION TO WALK XML SELECT AND TURN IT INTO XHTML  */


