//=============================================================================
// MSXML 
//=============================================================================

var msxmlClassNamePrefix = null;
function getMSXMLClassNamePrefix() {	
	if (msxmlClassNamePrefix) {
		return msxmlClassNamePrefix;
	}
	var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
	for (var i = 0; i < prefixes.length; i++) {
		try {
			var o1 = new ActiveXObject(prefixes[i] + ".XMLHTTP");
			var o2 = new ActiveXObject(prefixes[i] + ".XMLDOM");
			msxmlClassNamePrefix = prefixes[i];
			return msxmlClassNamePrefix;
		}
		catch(ex) {
		}
	}
	throw new Error("MSXML is not installed.");
}

function createMSXMLDOMDocument() {
	return new ActiveXObject(getMSXMLClassNamePrefix() + ".XMLDOM");
}


//------------------------------------------------------------------------------
/** 
 * ResourceStorage
 *
 * @constructor
 * @param source The XML Document to use for the resource storage. If this parameter 
 *               is null then an internal document will be created.
 */

ResourceManager = new ResourceStorage(document.all.ResourcesData);

function ResourceStorage(source) {

  // XML Document
	var _storageDocument = source ;
	
	if (source == null) {
		_storageDocument = createMSXMLDOMDocument()							 ;
		var _rootElement = _storageDocument.createElement("ResourceStorage") ;
		_storageDocument.appendChild(_rootElement)                           ;
	} // if (source == null) ...
	
	/**
	* Gets the string with the specified Id.
	*
	* @param pCode The Id of the requested string.
	* @param pDefaultValue The default string value for this code.
	* @returns A requested string, or the default value if doesn't exist in the resource storage.
	*/
	this.getString = function(pCode) {
	  
	  var _stringElement = _storageDocument.selectSingleNode("ResourceStorage/Strings/String[@id=\"" + pCode + "\"]") ;
	  var _resultValue   = "";
	  if (_stringElement != null) {
	    _resultValue = _stringElement.getAttribute("value");
	  } // if (_stringElement != null) ...
	  if ((this.getString.arguments.length > 1) && (_resultValue != "")) {
		for (var i=1; i < this.getString.arguments.length; i++) {
			var _int = i-1;
			_resultValue = _resultValue.replace("{" + _int + "}", this.getString.arguments[i]);
		} // for (var i=1; i <= getString.arguments.length; i++) ...
	  } // if ((getString.arguments.length > 1) && (_resultValue != "")) ...
	  return _resultValue;
	  
	}; // getString ...
	
	/**
	* Get the control specified by the Id stored in the resource storage.
	*
	* @param pCode The Id for getting the id value for the control. Hard to understand, eh?
	* @returns The DHTML control for an specified id in the page.
	*/
	this.getControl = function(pCode) {
	  var _stringElement = _storageDocument.selectSingleNode("ResourceStorage/Strings/String[@id=\"" + pCode + "\"]") ;
	  var _resultValue   = null;
	  if (_stringElement != null) {
	    _resultValue = document.getElementById(_stringElement.getAttribute("value"));
	  } // if (_stringElement != null) ...
	  return _resultValue;
	}; // getControl ...
	
	
	/**
	* Get the object specified by the Id stored in the resource storage.
	*
	* @param pCode The Id for getting the id value for the object. Hard to understand again, eh?
	* @returns The javascript object for an specified id in the page.
	*/
	this.getObject = function(pCode) {
	  var _stringElement = _storageDocument.selectSingleNode("ResourceStorage/Strings/String[@id=\"" + pCode + "\"]") ;
	  var _resultValue   = null;
	  if (_stringElement != null) {
	    _resultValue = eval(_stringElement.getAttribute("value"));
	  } // if (_stringElement != null) ...
	  return _resultValue;
	}; // getObject ...
	
}


