if ((top.UtilsInit == "undefined") || (top.UtilsInit != true))
{

	/**
	 *
	 * Client Utilities
	 *
	 */

	function Utils()
	{
	}

	Utils.prototype.prefixUrlParams = function(
		pUrl,
		pPrefix,
		pSuffix )
	{
		var index = pUrl.indexOf("?");

		if ( index < 0 )
			return pUrl;

		var retUrl = pUrl.substring(0,index+1);

		if ( index + 1 > pUrl.length)
			return retUrl;
		else
			pUrl = pUrl.substring(index+1);	


		while(pUrl.length > 0){				

			index = pUrl.indexOf("&amp;");

			if ( index < 0 )
				break;

			retUrl += pPrefix;
			retUrl += pUrl.substring(0,index+5);
			pUrl = pUrl.substring(index+5);		
		}

		retUrl += pPrefix;
		retUrl += pUrl;
		retUrl += pSuffix;

		return retUrl;
	}

	/**
	* The method is depricated.
	*/

	Utils.getFullURL = function(baseUrl, url) 
	{
		return url;
	}

	/**
	* Escape a string in HTML format.
	* Replace ' and " with &quot;
	* @arguement pStr The source string.
	* @returns The escaped string 
	*/

	Utils.escapeStringInHTML = function(pStr) 
	{
		var strArray = pStr.split("'");
		var str = "";
		for (var i=0; i<strArray.length - 1; i++) {
			str += 	strArray[i] + "&quot;";
		}

		if (strArray.length >= 1) {
			str += 	strArray[strArray.length - 1];
		}

		strArray = str.split('"');
		str ="";
		for (var i=0; i<strArray.length - 1; i++) {
			str += 	strArray[i] + "&quot;";
		}

		if (strArray.length >= 1) {
			str += 	strArray[strArray.length - 1];
		}


		return str;
	}

	/**
	* Test if the window is a dialog.
	*
	* @arguement pWindow The window to be tested.
	* @returns True if the winodw is a dialog; false otherwise
	*/

	Utils.isDialog = function(pWindow) 
	{
		var res = false;
		if (pWindow.dialogArguments != null) {
			res = true;
		}
		return res;
	}

	/**
	 * The class provide XML parse utility function.
	 */

	function XMLUtils()
	{

	}

	// retrieve the value of the first occurrence of the specified element

	XMLUtils.getElementFirstValue = function (xmlStr, elementName) 
	{
		var value = null;
		var startTag = "<" + elementName + ">";
		var endTag = "</" + elementName + ">";

		var index1 = xmlStr.indexOf(startTag);
		var index2 = xmlStr.indexOf(endTag);

		if ((index1 >= 0) && (index2 >= 0) && (index1 < index2)) {
			value = xmlStr.substring(index1 + elementName.length + 2, index2);
		}

		return value;	
	}

	XMLUtils.getElementXmlStr = function (elementName, elementValue)
	{
		var startTag = "<" + elementName + ">";
		var endTag = "</" + elementName + ">";
		return startTag + elementValue + endTag;
	}


	XMLUtils.getElementXmlStrWithAttr = function (elementName, elementValue, attributeName, attributeValue)
	{
		var startTag = "<" + elementName + " " + attributeName + "=" + "\"" + attributeValue + "\"" + ">";
		var endTag = "</" + elementName + ">";
		return startTag + elementValue + endTag;
	}

	/**
	 * Context object describes the runtime information for a component.
	 * The information includes dataDoc, instanceKey, and baseUrl.
	 */

	function Context(pDataDoc, pInstanceKey, pBaseUrl) 
	{
		this.dataDoc = pDataDoc;
		this.baseUrl = pBaseUrl;
		this.instanceKey = pInstanceKey;
	}

	/**
	 * A mutable String object. It wraps a value of the primitive string type in an object.
	 */

	function StringObject(p) 
	{
		this.str = p;
	}

	StringObject.prototype.append = function (p) 
	{
		this.str += p;
	}

	StringObject.prototype.set = function (p) 
	{
		this.str = p;
	}

	StringObject.prototype.get = function () 
	{
		return this.str;
	}

	StringObject.prototype.isEmpty = function () 
	{
		if ((this.str == null) || (this.str == "")) {
			return true;
		} else {
			return false;
		}
	}

	StringObject.prototype.toString = function () 
	{
		return this.str;
	}


	/**
	 * The class implements functions to build id for different components.
	 */

	function IdBuilder() {
	}

	IdBuilder.buildMenuItemId = function (id) 
	{
		if (id != null) {
			return "wsys_mnuitem_" + id;
		}
	}


	/**
	 * Number Formatting Functions.
	 */
	function Formatter() {
	}
	
	Formatter.unFormat = function(value){
		var retVal;
		if(value.indexOf('$')==0){
			retVal = value.substring(1,value.length);
		} else{
			retVal = value;
		}
		return Formatter.removeAllCommas(retVal);
	}
	
	Formatter.toNumber = function(value){
		return parseFloat(Formatter.unFormat(value));
	}

	Formatter.currencyFormat = function(value){
		if ( value != null ) {
			var tempValue = Formatter.unFormat(value.toString());
			tempValue = (tempValue.replace( /(\d+)(\d{3})/, '$1'+','+'$2')).replace( /(\d+)(\d{3})/, '$1'+','+'$2');
			return '$' + (Formatter.toFixed(tempValue)).toString();
		}
	}

 	Formatter.removeAllCommas = function(value){
 		var loc = value.lastIndexOf(',');
 		if(loc > -1) {
 			return this.removeAllCommas(value.substring(0, loc) + value.substring(loc+1, value.length));
 		}
 		return value;
 	}

 	Formatter.toFixed = function(value){
 		var loc = value.toString().lastIndexOf('.');
 		var tmpValue = '';
 		if(loc >-1){
 			if (loc > value.length - 3) {
 				value += '0';
 			}
 			else if(loc < value.length - 3) {
 				tmpValue = value.substr(0, loc);
 				tmpValue += value.substr(loc + 1, 2);
 				value = tmpValue;
 			}
 		}
 		else {
 			value += '.00';
 		}
 		return value;
 	}
 	
	//////////////////////////////////////

	top.UtilsInit = true;
}
