/// <reference path="intellisense/intellisense.js" />

/******************************************************************************
**      Desc: The Utilities class. Contains the commonly used methods.
**		Auth: Aleksey Fomichenko
**		Date: 09/14/2007
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:		Description:
**		-----------	-----------	-----------------------------------------------
**		09/14/2007	Aleksey F.	File created.
**		09/18/2007	Samir P.	Implemented the getRandomNumber method.
**		09/19/2007	Aleksey F.	Additional methods imported from Common.js file.
**		09/21/2007	Aleksey F.	More methods imported from RegExpVal.js file.
**		10/01/2007	Aleksey F.	formatAddress method implementation.
**		12/18/2007	Aleksey F.	generateUrl method.
*******************************************************************************/



/******************************************************************************
	Namespace Registration
******************************************************************************/

Type.registerNamespace("Fidelity.Scripts");

/******************************************************************************
	Fidelity.Scripts.Utilities static class
******************************************************************************/

var $util = Fidelity.Scripts.Utilities = function () 
{
	/// <summary>Fidelity.Scripts.Utilities static class. Contains the commonly used methods.</summary>
	
	// this is a static class, so an exception will be thrown if attempt to 
	// instantiate this class is made with the 'new' operator.
	throw Error.notImplemented(); 
};

Fidelity.Scripts.Utilities.prototype = 
{
	getRandomNumber : function (low, high)
	{
		/// <summary>Returns a random number between the low and high boundaries.</summary>
		/// <param name="low" type="Number" optional="false" mayBeNull="false">The lowest possible number.</param>
		/// <param name="high" type="Number" optional="false" mayBeNull="false">The highest possible number.</param>
		/// <returns type="Number" mayBeNull="false"></returns>
		
		return Math.floor((Math.random()*(high-low+1))+low);
	},
	
	appendElementIds : function (target, elements, prefix, postfix)
	{
		/// <summary>Appends element ids to the target collection.</summary>
		/// <param name="target" type="Object" optional="false" mayBeNull="false">The target object to append element ids to.</param>
		/// <param name="elements" type="Array" optional="false" mayBeNull="false">The array of elements to append.</param>
		/// <param name="prefix" type="String" optional="true" mayBeNull="true">The prefix to add to the element id.</param>
		/// <param name="postfix" type="String" optional="true" mayBeNull="true">The postfix to add to the element id.</param>
		
		for (var i = 0; i < elements.length; i++)
		{
			target[elements[i]] = "{0}{1}{2}".format(prefix ? prefix : String.empty, elements[i], postfix ? postfix : String.empty);
		}
	},
		
	preloadImages : function (imagesArray)
	{
		/// <summary>Preloads images from the specified array of images paths.</summary>
		/// <param name="imagesArray" type="Array" optional="false" mayBeNull="false">The array of image paths to preload.</param>

		var d = document;
		if (d.images) 
		{ 
			if(!d.PreloadedImages) d.PreloadedImages = new Array();
			for (var i = 0; i < imagesArray.length; i++)
			{
				d.PreloadedImages.push(new Image());
				d.PreloadedImages[d.PreloadedImages.length-1].src = imagesArray[i];
			}
		}
	},

	swapImage : function (imageElementId, newSrc) 
	{
		/// <summary>Swaps the current image's src attribute value.</summary>
		/// <param name="imageElementId" type="String" optional="false" mayBeNull="false">The id of the image element.</param>
		/// <param name="newSrc" type="String" optional="false" mayBeNull="false">The new value for the src attribute.</param>
		
		var img = $get(imageElementId);
		if (img)
		{
			if (!img.oldSrc) img.oldSrc = img.src;				
			img.src = newSrc;
			this.swapImageLastElement = img;
		}
	},
	
	swapImageRestore : function (imageElementId) 
	{
		/// <summary>Restores the previously swapped image src.</summary>
		/// <param name="imageElementId" type="String" optional="true" mayBeNull="true">Optional. The id of the image element to restore a previously swapped src attribute value. If not supplied, the last swapped image is restored.</param>
		
		var img;
		if (imageElementId && (img = $get(imageElementId)) && img.oldSrc)
		{
			img.src = img.oldSrc;
			return;
		}
		
		if (this.swapImageLastElement)
			this.swapImageLastElement.src = this.swapImageLastElement.oldSrc;
	},
	

	imageGroup : function (event, grpName)
	{
		/// <summary>Todo: Samir...</summary>
		/// <param name="event" type="String" optional="false" mayBeNull="false">Todo: Samir...</param>

		var i, img, nbArr;
		var args = arguments;
		
		if (event == "init" && args.length > 2) 
		{
			if ((img = $get(args[2])) !== null && !img.MM_init) 
			{
				img.MM_init = true; 
				img.MM_up = args[3]; 
				img.MM_dn = img.src;
				
				if (!(nbArr = document[grpName])) 
					nbArr = document[grpName] = new Array();
					
				nbArr[nbArr.length] = img;
				for (i=4; i < args.length-1; i+=2)
				{
					if ((img = $get(args[i])) !== null) 
					{
						if (!img.MM_up) 
							img.MM_up = img.src;
						img.src = img.MM_dn = args[i+1];
						nbArr[nbArr.length] = img;
					}
				}
			}
		} 
		else if (event == "over") 
		{
			document.MM_nbOver = nbArr = new Array();
			for (i=1; i < args.length-1; i+=3)
			{
				if ((img = $get(args[i])) !== null) 
				{
					if (!img.MM_up) 
						img.MM_up = img.src;
					img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
					nbArr[nbArr.length] = img;
				}
			}
		} 
		else if (event == "out" ) 
		{
			for (i=0; i < document.MM_nbOver.length; i++) 
			{
				img = document.MM_nbOver[i]; 
				img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; 
			}
		} 
		else if (event == "down") 
		{
			nbArr = document[grpName];
			if (nbArr)
			{
				for (i=0; i < nbArr.length; i++) 
				{ 
					img=nbArr[i]; 
					img.src = img.MM_up; 
					img.MM_dn = 0; 
				}
			}	
			document[grpName] = nbArr = new Array();
			for (i=2; i < args.length-1; i+=2)
			{
				if ((img = $get(args[i])) !== null) 
				{
					if (!img.MM_up) 
						img.MM_up = img.src;
					img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
					nbArr[nbArr.length] = img;
				}
			}
		}
	},
	
	htmlEncode : function (str)
	{
		/// <summary>Html-encodes the specified string.</summary>
		/// <param name="str" type="String" optional="false" mayBeNull="false">The string to html-encode.</param>
		/// <returns type="String" mayBeNull="false"></returns>

		return str.replace(/&/gi, "&amp;").replace(/</gi, "&lt;").replace(/>/gi, "&gt;");
	},

	htmlDecode : function (str)
	{
		/// <summary>Decodes the html-encoded string.</summary>
		/// <param name="str" type="String" optional="false" mayBeNull="false">The string to decode.</param>
		/// <returns type="String" mayBeNull="false"></returns>
		
		return str.replace(/&gt;/gi, ">").replace(/&lt;/gi, "<").replace(/&amp;/gi, "&");
	},

	formatUSPhone : function (value)
	{
		/// <summary>Formats the value as a US phone number.</summary>
		/// <param name="value" type="String" optional="false" mayBeNull="false">The string to format.</param>
		/// <returns type="String" mayBeNull="false"></returns>
		
		value = Number.extractDigits(value);
		
		if (value.charAt(0) == "1")
			value = value.substring(1);

		//var expr = /(^\d{3})(\d{3})(\d{4}$)/; // - same as below
		var expr = new RegExp("(^\\d{3})(\\d{3})(\\d{4}$)");

		if (expr.test(value))
			return value.replace(expr, "($1) $2-$3");
		else
			return value;
	},
	
	isState : function (value)
	{
		/// <summary>Evaluates the specified string to determine whether it is a valid US state.</summary>
		/// <param name="value" type="String" optional="false" mayBeNull="false">The string to evaluate.</param>
		/// <returns type="Boolean" mayBeNull="false"></returns>

		var reg = new RegExp(String.format("^({0})$", $const.states), "i"); // The "i" ignores case.
		return value.match(reg) !== null;
	},

	isStateAbbreviation : function (value)
	{
		/// <summary>Evaluates the specified string to determine whether it is an abbreviation of a valid US state.</summary>
		/// <param name="value" type="String" optional="false" mayBeNull="false">The string to evaluate.</param>
		/// <returns type="Boolean" mayBeNull="false"></returns>

		var reg = new RegExp(String.format("^({0})$", $const.stateAbbreviations), "i"); // The "i" ignores case.
		return value.match(reg) !== null;
	},

	getStateAbbreviation : function (value)
	{
		/// <summary>Converts the full US state to its abbreviation.</summary>
		/// <param name="value" type="String" optional="false" mayBeNull="false">The full US state name to convert.</param>
		/// <returns type="String" mayBeNull="false"></returns>
		
		if (this.isState(value))
		{
			var states = $const.states.split("|");
			for (var i = 0; i < states.length; i++)
			{
				if (states[i].toLowerCase() === value.toLowerCase())
					return $const.stateAbbreviations.split("|")[i];
			}
		}
		return value.toUpperCase();
	},

	removeCurrency : function (value)
	{
		/// <summary>Removes currency formatting from source string.</summary>
		/// <param name="value" type="String" optional="false" mayBeNull="false">Source string from which currency formatting will be removed.</param>
		/// <returns type="String" mayBeNull="false">Source string with commas removed.</returns>

		var objRegExp = /\(/;
		var strMinus = String.empty;

		//check if negative
		if (objRegExp.test(value))
			strMinus = '-';

		objRegExp = /\)|\(|[,]/g;
		value = value.replace(objRegExp,'');
		if (value.indexOf('$') >= 0)
			value = value.substring(1, value.length);
		
		return strMinus + value;
	},

	addCurrency : function (value)
	{
		/// <summary>Formats a number as currency. Assumes number passed is a valid numeric value in the rounded to 2 decimal places. If not, returns original value.</summary>
		/// <param name="value" type="String" optional="false" mayBeNull="false">Source string to be formatted.</param>
		/// <returns type="String" mayBeNull="false"></returns>
		
		var objRegExp = new RegExp("-?[0-9]+(\\.[0-9]{2})?");
		var s = value.toString();

		if (objRegExp.test(s)) 
		{
			objRegExp.compile('^-');
			s = Fidelity.Scripts.Utilities.addCommas(s);
			if (objRegExp.test(s))
				s = '($' + s.replace(objRegExp,'') + ')';
			else
				s = '$' + s;
		}
		return s;
	},
	
	removeCommas : function (value)
	{
		/// <summary>Removes commas from source string.</summary>
		/// <param name="value" type="String" optional="false" mayBeNull="false">Source string from which commas will be removed.</param>
		/// <returns type="String" mayBeNull="false"></returns>
		
		var objRegExp = /,/g; //search for commas globally
		return value.replace(objRegExp, String.empty);
	},
	
	addCommas : function (value)
	{
		/// <summary>Inserts commas into numeric string. Used with integers or numbers with 2 or less decimal places.</summary>
		/// <param name="value" type="String" optional="false" mayBeNull="false">Source string to add commas to.</param>
		/// <returns type="String" mayBeNull="false">String modified with comma grouping if source was all numeric, otherwise source is returned.</returns>
	
		var objRegExp  = /(-?[0-9]+)([0-9]{3})/;
		var s = value.toString();
		while (objRegExp.test(s)) 
		{
			//replace original string with first group match, a comma, then second group match
			s = s.replace(objRegExp, '$1,$2');
		}
		return s;
	},
	
	removeWhiteSpace : function (value)
	{
		/// <summary>Removes whitespace character from the source string.</summary>
		/// <param name="value" type="String" optional="false" mayBeNull="false">Source string to remove the whitespace character from.</param>
		/// <returns type="String" mayBeNull="false"></returns>
		
		return value.replace(/\s/g, '');
	},
	
	addEllipses : function (value, maxLength, ellipseToUse)
	{
		/// <summary></summary>
		/// <param name="value" type="String" optional="false" mayBeNull="false"></param>
		/// <param name="maxLength" type="String" optional="false" mayBeNull="false"></param>
		/// <param name="ellipseToUse" type="String" optional="false" mayBeNull="false"></param>
		/// <returns type="String" mayBeNull="false"></returns>
		
		if (!value) return String.empty;
		
		value = value.trim();
		return (value.length > maxLength) ? 
			value.substring(0, maxLength - ellipseToUse.length).trim() + ellipseToUse : 
			value;
	},
	
	getEvent : function (evt)
	{
		/// <summary>Gets the current event.</summary>
		/// <returns type="event" mayBeNull="true"></returns>

		return (evt ? evt : window.event);
	},
	
	getEventKey : function (evt)
	{
		/// <summary>Gets the keyboard key code associated with the event</summary>
		/// <returns type="Number" mayBeNull="false"></returns>

		evt = this.getEvent(evt);
		if (evt)
			return (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
	},

	freezeEvent : function (evt)
	{
		/// <summary>Freezes the event from bubbling and doing any default actions.</summary>

		if (evt.preventDefault) evt.preventDefault();
		evt.returnValue = false;
		evt.cancelBubble = true;
		if (evt.stopPropagation) evt.stopPropagation();
		return false;
	},

	getEventElement : function (evt)
	{
		/// <summary>Gets the element associated with the event.</summary>

		evt = this.getEvent(evt);
		return (evt.srcElement ? evt.srcElement: (evt.target ? evt.target : evt.currentTarget));
	},
		
	cancelEnterKey : function (evt, codeToExecute)
	{
		/// <summary>Cancels the default behaviour of the 'ENTER' key press and (if provided) executes the custom code.</summary>
		/// <param name="evt" type="Object" optional="false" mayBeNull="false">The event associated with the key press.</param>
		/// <param name="codeToExecute" type="String" optional="true" mayBeNull="true">Optional code to execute if the enter key was pressed.</param>

		var key = Fidelity.Scripts.Utilities.getEventKey(evt);
		if (key == Sys.UI.Key.enter)
		{
			Fidelity.Scripts.Utilities.freezeEvent(evt);
			if (codeToExecute) { window.setTimeout(codeToExecute, 100); }
			return false;
		}
		return true;
	},
	
	formatNumericTextbox : function (source, evt)
	{
		/// <summary>Formats a numeric value in a textbox.</summary>
		/// <param name="source" type="DOMElement" optional="false" mayBeNull="false">The textbox whose value to format.</param>

		source.value = Fidelity.Scripts.Utilities.addCommas(Fidelity.Scripts.Utilities.removeCommas(source.value));
	},
	
	setCookie : function (name, value, expires, path, domain, secure) 
	{
		/// <summary>Sets the client browser cookie.</summary>
		/// <param name="name" type="String" optional="false" mayBeNull="false">The name of the cookie to set.</param>
		/// <param name="value" type="String" optional="false" mayBeNull="false">The value of the cookie to set.</param>
		/// <param name="expires" type="Date" optional="true" mayBeNull="false">The expiration date of the cookie (defaults to end of current session).</param>
		/// <param name="path" type="String" optional="true" mayBeNull="false">The path for which the cookie is valid (defaults to path of calling document).</param>
		/// <param name="domain" type="String" optional="true" mayBeNull="false">The domain for which the cookie is valid (defaults to domain of calling document).</param>
		/// <param name="secure" type="Boolean" optional="true" mayBeNull="false">Indicates wheter the cookie transmission requires a secure transmission.</param>

		var curCookie = name + "=" + escape(value) +
			((expires)	? "; expires=" + expires.toGMTString() : "") +
			((path)		? "; path=" + path : "") +
			((domain)	? "; domain=" + domain : "") +
			((secure)	? "; secure" : "");
		document.cookie = curCookie;
	},
	
	openNewWindow : function (url, name, width, height, top, left, displayStatusBar, displayScrollbars, allowResizing, displayMenubar, displayToolbar, replace) 
	{
		/// <summary>Opens a new window and loads the document specified by a given URL.</summary>
		/// <param name="url" type="String" optional="false" mayBeNull="false">Required. A String that specifies the URL to render in the new window.</param>
		/// <param name="name" type="String" optional="true" mayBeNull="true">Optional. A String that specifies the name of the window.</param>
		/// <param name="width" type="Number" optional="true" mayBeNull="true">Optional. Sets the width of the window in pixels. The minimum value is 250, and specifies the minimum width of the browser content area.</param>
		/// <param name="height" type="Number" optional="true" mayBeNull="true">Optional. Sets the height of the window in pixels. The minimum value is 150, and specifies the minimum height of the browser content area.</param>
		/// <param name="top" type="Number" optional="true" mayBeNull="true">Optional. Specifies the top position, in pixels. This value is relative to the upper-left corner of the screen. The value must be greater than or equal to zero.</param>
		/// <param name="left" type="Number" optional="true" mayBeNull="true">Optional. Specifies the left position, in pixels. This value is relative to the upper-left corner of the screen. The value must be greater than or equal to zero.</param>
		/// <param name="displayStatusBar" type="Boolean" optional="true" mayBeNull="true">Optional. Specifies whether to add a Status Bar at the bottom of the window.</param>
		/// <param name="displayScrollbars" type="Boolean" optional="true" mayBeNull="true">Optional. Specifies whether to display horizontal and vertical scroll bars.</param>
		/// <param name="allowResizing" type="Boolean" optional="true" mayBeNull="true">Optional. Specifies whether to display resize handles at the corners of the window.</param>
		/// <param name="displayMenubar" type="Boolean" optional="true" mayBeNull="true">Optional. Specifies whether to display the menu bar.</param>
		/// <param name="displayToolbar" type="Boolean" optional="true" mayBeNull="true">Optional. Specifies whether to display the browser toolbar.</param>
		/// <param name="replace" type="Boolean" optional="true" mayBeNull="true">Optional. When the url is loaded into the same window, this Boolean parameter specifies whether the url creates a new entry or replaces the current entry in the window's history list.</param>
		
		var features = "{0}{1}{2}{3}{4}{5}{6}".format(
			Number.isNumber(width)			? "width={0},".format(width) : String.empty,
			Number.isNumber(height)			? "height={0},".format(height) : String.empty,
			Number.isNumber(top)			? "top={0},".format(top) : String.empty,
			Number.isNumber(left)			? "left={0},".format(left) : String.empty,
			displayStatusBar === true		? "status=yes," : "status=no,",
			displayScrollbars === true		? "scrollbars=yes," : "scrollbars=no,",
			allowResizing === true			? "resizable=yes," : "resizable=no,",
			displayMenubar === true			? "menubar=yes," : "menubar=no,",
			displayToolbar === true			? "toolbar=yes," : "toolbar=no,");
		
		if (features.length > 0) features = features.substring(0, features.length-1);
		
		trace("New window features: {0}".format(features));
		
		newWin = window.open(url, name, features, replace);
		if (newWin) newWin.focus();
	},
		
	getCurrentTime : function ()
	{
		/// <summary>Gets the current time in milliseconds.</summary>
		/// <returns type="Number" mayBeNull="false"></returns>

		return new Date().getTime();
	},

	getElapsedTime : function (startTime)
	{
		/// <summary>Gets the number of milliseconds from the start time to the current time.</summary>
		/// <param name="startTime" type="Number" optional="false" mayBeNull="false">The start time in milliseconds.</param>
		/// <returns type="Number" mayBeNull="false"></returns>

		return this.getCurrentTime() - (startTime * 1);
	},
	
	extractZip5 : function (fullZip)
	{
		/// <summary>Returns the first 5 digits from a full ZIP, i.e. [91709]-2948</summary>
		/// <param name="fullZip" type="String" optional="false" mayBeNull="false">The ZIP code to extract from.</param>
		/// <returns type="String" mayBeNull="false"></returns>

		if (!fullZip) return String.empty;
		if (fullZip.length < 6) return fullZip;
		return fullZip.substring(0,5);
	},

	extractZip4 : function (fullZip)
	{
		/// <summary>Returns the last 4 digits from a full ZIP, i.e. 91709-[2948]</summary>
		/// <param name="fullZip" type="String" optional="false" mayBeNull="false">The ZIP code to extract from.</param>
		/// <returns type="String" mayBeNull="false"></returns>

		if (!fullZip || fullZip.indexOf("-") < 0) return String.empty;
		return fullZip.split("-")[1];
	},

	formatZeroValue : function (value, zeroReplacement, nonZeroFormatMethod, nonZeroPrefix, nonZeroPostfix)
	{
		/// <summary>Formats a specified value. If the value is '0' it is replaced with the 'zeroReplacement' argument. If the value is not a '0', then it is optionally formatted as well as prefixed and postfixed.</summary>
		/// <param name="value" type="String" optional="false" mayBeNull="true">The value to evaluate and format.</param>
		/// <param name="zeroReplacement" type="String" optional="true" mayBeNull="true">The string to return if the value is a '0'.</param>
		/// <param name="nonZeroFormatMethod" type="String" optional="true" mayBeNull="true">The format method name to apply to the value if it is not a '0'.</param>
		/// <param name="nonZeroPrefix" type="String" optional="false" mayBeNull="false">The string to prefix the value with if it is not a '0'.</param>
		/// <param name="nonZeroPostfix" type="String" optional="false" mayBeNull="false">The string to append to the value if it not a '0'.</param>
		/// <returns type="String" mayBeNull="false"></returns>

		if (!value || parseInt(value, null) === 0 || String.isNullOrEmpty(value))
			return (zeroReplacement ? zeroReplacement : String.empty);
		
		if (nonZeroFormatMethod && !String.isNullOrEmpty(nonZeroFormatMethod))
			value = eval("{0}({1});".format(nonZeroFormatMethod, value));
			
		if (nonZeroPrefix)
			value = nonZeroPrefix + value;
		
		if (nonZeroPostfix)
			value = value + nonZeroPostfix;
		
		return value;
	},
	
	formatAddress : function (streetAddress, city, state, zip)
	{
		/// <summary>Formats components of the address.</summary>
		/// <returns type="String" mayBeNull="false"></returns>
		
		return String.format("{0}{1}{2}",
			streetAddress,
			String.isNullOrEmpty(streetAddress) ? String.empty : ", ",
			$util.formatCityStateZip(city, state, zip)).trim();
	},
	
	formatCityStateZip : function (city, state, zip)
	{
		/// <summary>Formats the city, state and zip components of the address.</summary>
		/// <returns type="String" mayBeNull="false"></returns>
		
		return String.format("{0}{1}{2}{3}{4}",
			city,
			String.isNullOrEmpty(city) ? String.empty : ", ",
			state,
			String.isNullOrEmpty(state) ? String.empty : " ",
			zip).trim();
	},
	
	countWords : function (value) 
	{
		/// <summary>Returns the number of words in a specified string.</summary>
		/// <param name="value" type="String"></param>
		/// <returns type="Number" mayBeNull="false"></returns>
		
		var fullStr = value + " ";
		var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
		var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
		var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
		var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
		var splitString = cleanedStr.split(" ");
		var word_count = splitString.length - 1;
		
		if (fullStr.length <2) {
			word_count = 0;
		}
		
		return word_count;
	},
	
	getQueryStringParameter : function (keyValuePair, treatAsFirstParameter)
	{
		/// <summary>Generates the key/value pair for the QueryString, including the & or the ? marks.</summary>
		/// <param name="keyValuePair" type="Fidelity.Scripts.KeyValuePair">The Fidelity.Scripts.KeyValuePair instance to get the key and a value from.</param>
		/// <param name="treatAsFirstParameter" type="Boolean" optional="true" mayBeNull="true">If set to true, the '?' mark will be used instead of the '&' mark.</param>
		
		if (String.isNullOrEmpty(keyValuePair.value))
			return String.empty;
			
		return "{0}{1}={2}".format(treatAsFirstParameter ? "?" : "&", keyValuePair.key, escape(keyValuePair.value));
	},
	
	generateUrl : function (baseUrl, keyValuePairs)
	{
		/// <summary>Generates the URL from the base url and the collections of keys and values.</summary>
		/// <param name="baseUrl" type="String">The url to append the params to.</param>
		/// <param name="keyValuePairs" type="Array">The collection of Fidelity.Scripts.KeyValuePair objects.</param>
					
		var firstParamFound = false;
		
		for (var i = 0; i < keyValuePairs.length; i++)
		{
			var param = $util.getQueryStringParameter(keyValuePairs[i], !firstParamFound);
			
			if (!firstParamFound && !String.isNullOrEmpty(param))
				firstParamFound = true;
				
			baseUrl += param;
		}
		
		return baseUrl;
	},
	
	addOptionToDropDownList : function (ddl, text, value)
	{
		/// <summary>Adds a new option to the 'select' html control.</summary>
		
		var o = document.createElement("OPTION");
		ddl.options.add(o);
		if (!text) { text = value; }
		if (!value) { value = text; }
		o.innerText = text;
		o.value = value;
	}
};

// register static class
Fidelity.Scripts.Utilities.registerStaticClass("Fidelity.Scripts.Utilities");


// Notify ScriptManager that this is the end of the script.
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
