if(!String.prototype.trim)
{
	String.prototype.trim = function()
	{
		var temp = this.replace(/^\s+|\s+$/, '');    //possibly spaces at front and back
		return temp.replace(/^\s+|\s+$/, '');
	};
}

if(!String.prototype.startsWith)
{
	String.prototype.startsWith = function(s)
	{
		return (this.indexOf(s) == 0);
	};
}

if(!String.prototype.endsWith)
{
	String.prototype.endsWith = function(s)
	{
		return (this.lastIndexOf(s) == (this.length - s.length));
	};
}

if(!String.prototype.isValidEmailAddress)
{
	String.prototype.isValidEmailAddress = function()
	{
		return (MLX_ValidEmailRegExp.test(this.trim()));
	};
}
	
if(!String.prototype.format)
{
	String.prototype.format = function(type)
	{
		var ret = "";
		var decimalPlaces = type.length == 2 ? parseInt(type.substr(1,1)) : 0;
		var intValue;
		
		try
		{
			if(type.toUpperCase().startsWith("C") || type.toUpperCase().startsWith("N"))
			{
				dblValue = parseFloat(this.replace(/\$|\,/g,''));				
				blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
				intValue = Math.floor(dblValue);
				strCents = (Math.floor(Math.floor(((dblValue - intValue) * Math.pow(10,decimalPlaces))+.0000000001))/Math.pow(10,decimalPlaces)).toString();
				
				if(strCents == "0")
					strCents = ".";
				else
					strCents = strCents.substr(1,strCents.length-1);
				
				while(strCents.length - 1 < decimalPlaces)
					strCents += "0";
				
				dblValue = intValue.toString();
				for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
					dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+ dblValue.substring(dblValue.length-(4*i+3));
				ret = (((blnSign)?'':'-') + (type.toUpperCase().startsWith("C") ? '$' : '') + dblValue + (decimalPlaces > 0 ? strCents : ''));
			}
			else if(type.toUpperCase().startsWith("P"))
			{
				var flt = (this.indexOf("%") != -1 ? (parseFloat(this.replace(/%/g,'')) / 100.0) : (parseFloat(this.replace(/%/g,''))));
				intValue = Math.floor(flt * 100.0 + 0.0000000001);
				flt = flt * 100.0 + 0.0000000001;
				var decimals = (Math.floor(Math.floor(((flt - intValue) * Math.pow(10,decimalPlaces))+.0000000001))/Math.pow(10,decimalPlaces)).toString();
				
				if(decimals == "0")
					decimals = ".";
				else
					decimals = decimals.substr(1,decimals.length-1);
				
				while(decimals.length - 1 < decimalPlaces)
					decimals += "0";

				ret = intValue.toString() + (decimalPlaces > 0 ? decimals : '') + '%';
			}
		}
		catch(err)
		{
		}
		
		return ret.length > 0 ? ret : this;
	};
}

if(!String.prototype.HTMLDecode)
{
	String.prototype.HTMLDecode = function()
	{
		var re = new RegExp("&amp;", "g");
		var s = this.replace(re, "&");
		re = new RegExp("&gt;", "g");
		s = s.replace(re, ">");		
		return s;
	};
}

if(!String.prototype.XmlEncode)
{
	String.prototype.XmlEncode = function()
	{
		var re = new RegExp("&", "g");
		var s = this.replace(re, "&amp;");
		re = new RegExp("<", "g");
		s = s.replace(re, "&lt;");		
		return s;
	};
}

if(!String.prototype.XmlDecode)
{
	String.prototype.XmlDecode = function()
	{
		var re = new RegExp("&amp;", "g");
		var s = this.replace(re, "&");
		re = new RegExp("&lt;", "g");
		s = s.replace(re, "<");		
		return s;
	};
}

if(!String.prototype.stripHtml)
{
    String.prototype.stripHtml = function()
	{
	    var re = new RegExp(/<.*?>/g);
        var s = this.replace(re, "");
        return s;
    }
}
if(!String.prototype.stripWhitespace)
{
    String.prototype.stripWhitespace = function()
	{
	    var re = new RegExp(/\s/g);
        var s = this.replace(re, "");
        return s;
    }
}

if(!String.prototype.stripWrappingTags)
{
    String.prototype.stripWrappingTags = function(tag)
	{
		var s = this.trim()
	    var re = new RegExp("\^<" + tag + ">([\\s\\S]*)(?=<\/" + tag + ">$)", "i");
        found = re.exec(s);
		if (found && found.length > 1)
		    return found[1];
		else
            return s;
    }
}