String.prototype.trim = function(){return (this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, ""))}
String.prototype.startsWith = function(str){return (this.match("^"+str)==str)}
String.prototype.endsWith = function(str){return (this.match(str+"$")==str)}


// Given a span element name and a length
// change the number of chars so it fits within length and append ...
function resizeText(spanElementName, length)
{

	var spanElm = document.getElementById(spanElementName);

	if (spanElm && spanElm.textContent)
	{	
		// set width to auto so we can calculate based on offsetWidth
		spanElm.style.width = 'auto';
		if (spanElm.offsetWidth >= length)
		{
			//temp var to hold the string we will create
			var origStr = spanElm.textContent;

			// perform a rough calc on the number of chars required.
			// Over estimate by 20%, and then reduce			
			var widthPerChar = origStr.length / spanElm.offsetWidth;
			var estimatedChars = length * widthPerChar;
			estimatedChars = Math.ceil(estimatedChars * 1.2);						
			
			if (estimatedChars <  origStr.length)
				origStr = origStr.substring(0, estimatedChars);
			
			var index = 0;
			spanElm.textContent = origStr;				
					
			while (spanElm.offsetWidth >= length && spanElm.textContent.length > 5)
			{					
				spanElm.textContent = spanElm.textContent.substring(0, spanElm.textContent.length -1);
			}
			// apend ...
			spanElm.textContent += '...';
			
			spanElm.style.width = (length+6) + 'px';
						
		}									
	}
	
} 	

function escapeHtml(text)
{
	text = text.replace("<", "&lt;").replace(">", "&gt;");
	text = text.replace("<", "&lt;").replace(">", "&gt;");
	text = text.replace("eval\\((.*)\\)", "");
	text = text.replace("[\\\"\\\'][\\s]*((?i)javascript):(.*)[\\\"\\\']", "\"\"");
	text = text.replace("((?i)script)", "");
	
	return text;
}

function isHtml(text)
{
	if(text.indexOf("<") > -1 || text.indexOf("&lt") > -1 || text.indexOf(">") > -1 || text.indexOf("&gt") > -1)
		return true;
	else
		return false;
}


// Perform ecnodeURI component and replace any '
function escapeString(str)
{
	var searchTxt = str;
	if (str != null && str.length > 0) {
		searchTxt = encodeURIComponent(searchTxt);
		escapeApos = escape("'");
		searchTxt = searchTxt.replace("'", escapeApos);
	}
	
	
	return searchTxt

}

// Unencode any \' and perform decodeURI component
function unescapeString(str)
{
	var searchTxt = str;
	if (str != null && str.length > 0) {
		searchTxt = decodeURIComponent(searchTxt);
		escapeApos = escape("'");
		searchTxt = searchTxt.replace(escapeApos, "'");		
	}	
	else 
	{
		searchTxt = '';
	}
	return searchTxt
}

function getRequestParameter(name)
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function hide(id)
{
	document.getElementById(id).style.display = 'none';
}
function show(id)
{
	document.getElementById(id).style.display = '';
}
function getElement(id)
{
	return document.getElementById(id);
}
function toggleDisplay(id)
{
	if(getElement(id).style.display == 'none')
		getElement(id).style.display = '';
	else
		getElement(id).style.display = 'none';
}

function getBrowser() {
	return navigator.userAgent;
}