/** 
 * @fileoverview Server-side Controls' client-side functionality base object for the JSPOOP library
 * @author James Palmer james@phoenixlondon.co.uk
 * @version 0.1 
 */

/**
 * Construct the Phoenix.Controls object.
 * @class Base class for server-side controls' client-side functionality in the Phoenix library.
 * @constructor
 * @requires Phoenix
 */
Phoenix.Controls = function()
{
};



/**
 * Registers the control's generic namespace identifier, so its presence will be discoverable by other controls/general javascript on any page it's included in.  If the control's root HTML element is specified by rootelementid, also grabs a reference to this element and sets the control's rootElement property to point to this element.
 * 
 * @see Phoenix.Widgets#registerThisWidget
 * @param {String} fullyqualifiednsid A string of the form "x.y.z", representing the control's name.
 * @param {String} rootelementid The HTML id of the root element the control is inhabiting.
 * @returns {object} Reference to the identifier if it exists, otherwise null.
 */
Phoenix.Controls.registerThisControl = function(fullyqualifiednsid, rootelementid)
{
	// Given the desired fully-qualified namespace identifier as a text string ("x.y.z"), register this control's namespace object (along with any necessary parent identifiers)
	registerNamespace(fullyqualifiednsid);
	
	// Now we need a reference to the control's newly-created namespace *object* ("z", in the example above)
	var nsParts = fullyqualifiednsid.split(".");
	var root = window;
	for(var i=0; i<nsParts.length; i++)
		root = root[nsParts[i]];
	
	// Now, given the passed-in HTML ID string we need a reference to the HTML element object it represents.
	var elementobj = document.getElementById(rootelementid);
	if(!elementobj)
		return(false);
	
	// Finally we assign this HTML object reference to the rootElement property of the control object (z.rootElement, in the above example)
	root.nsIdentifier = fullyqualifiednsid;
	root.rootElement = elementobj;
	
	return(true);
}
