var uk; // Required in GLOBAL scope - does not overwrite any existing objects!
if(!uk){ uk = {}; } else if(typeof uk != "object"){ throw new Error("uk already exists and is not an object"); }
if(!uk.co){ uk.co = {}; } else if(typeof uk.co != "object"){ throw new Error("uk.co already exists and is not an object"); }
if(!uk.co.pntestbed){ uk.co.pntestbed = {}; } else if(typeof uk.co.pntestbed != "object"){ throw new Error("uk.co.pntestbed already exists and is not an object"); }
if(uk.co.pntestbed.XHTML){ throw new Error("uk.co.pntestbed.XHTML already exists"); }
//---------------------------------------------------------------------
/*
	*	--------------------------
	* 	Constructor
	*	--------------------------
*/
uk.co.pntestbed.XHTML = function(){}
//---------------------------------------------------------------------
/*
	*	--------------------------
	* 	Static properties and methods
	*	--------------------------
*/
//---------------------------------------------------------------------
uk.co.pntestbed.XHTML.createNode = function(sTagName, oArgs){
/*
	*	Required arguments
	* 	sTagName		- div, p, a - any xhtml tag
	*	Optional arguments
	* 	oArgs.oAtts 	- tag attributes (id, class etc)
	* 	oArgs.vChildren	- either array of child nodes or single node
*/
	if(document.createElementNS){
		var node = document.createElementNS('http://www.w3.org/1999/xhtml', sTagName);
	} else  {
		var node = document.createElement(sTagName);
	}
	node.appendText = function(sText){ this.appendChild(document.createTextNode(sText)); }
	if(typeof oArgs == 'string'){
		node.appendChild(document.createTextNode(oArgs));
	} else if(typeof oArgs != 'undefined'){
		if(typeof oArgs.oAtts != 'undefined'){
			for(var att in oArgs.oAtts){
				node.setAttribute(att, oArgs.oAtts[att]);
			}		
		}
		if(typeof oArgs.vChildren != 'undefined'){
			if(oArgs.vChildren instanceof Array){
				for(var i = 0; i < oArgs.vChildren.length; i++){
					node.appendChild(oArgs.vChildren[i]);
				}
			} else {
				node.appendChild(oArgs.vChildren);
			}
		}
	}	
	return node;
}
//---------------------------------------------------------------------
uk.co.pntestbed.XHTML.documentFragment = function(vChildren){
	var docFrag = document.createDocumentFragment();
	if(typeof vChildren != 'undefined'){
		if(vChildren instanceof Array){
			for(var i = 0; i < vChildren.length; i++){
				docFrag.appendChild(vChildren[i]);
			}
		} else {
			docFrag.appendChild(vChildren);
		}
	}
	return docFrag;
}
//---------------------------------------------------------------------
uk.co.pntestbed.XHTML.removeAllChildren = function(oNode){
	while(oNode.childNodes[0]){
		oNode.removeChild(oNode.childNodes[0])
	}
}
//---------------------------------------------------------------------
uk.co.pntestbed.XHTML.replaceNode = function(vNode, vChildren){
	if(typeof vNode == 'string'){
		var xhtmlOld = document.getElementById(vNode);
		var xhtmlNew = uk.co.pntestbed.XHTML.createNode(xhtmlOld.tagName.toLowerCase(),	{ oAtts: { id: vNode },	vChildren: vChildren });
	} else {
		var xhtmlOld = vNode;	
		var xhtmlNew = uk.co.pntestbed.XHTML.createNode(xhtmlOld.tagName.toLowerCase(),	{ oAtts: { },	vChildren: vChildren });
	}
	xhtmlOld.parentNode.replaceChild(xhtmlNew, xhtmlOld);
}
//---------------------------------------------------------------------
uk.co.pntestbed.XHTML.getAttribute = function(sId, sAttName){ 	return 	(document.getElementById(sId))[sAttName]; }
//--
uk.co.pntestbed.XHTML.setAttribute = function(sId, sAttName, sAttVal){	(document.getElementById(sId))[sAttName] = sAttVal; }
//---------------------------------------------------------------------
uk.co.pntestbed.XHTML.getValue = function(sId){ 	return 	(document.getElementById(sId)).value; }
//--
uk.co.pntestbed.XHTML.setValue = function(sId, sValue){		(document.getElementById(sId)).value = sValue; }
//---------------------------------------------------------------------
uk.co.pntestbed.XHTML.getInnerHTML = function(sId){ return 	(document.getElementById(sId)).innerHTML; }
//--
uk.co.pntestbed.XHTML.setInnerHTML  = function(sId, sHTML){	(document.getElementById(sId)).innerHTML = sHTML; }
//---------------------------------------------------------------------
//---------------------------------------------------------------------


