/*
	string_additions.js

	Created by murat on 2007-10-26.
	Copyright (c) 2007 murat n konar. All rights reserved.
*/

// ------------------------------------------------------------------------------------------------------------
//	String.UnEncodeHTML
// ------------------------------------------------------------------------------------------------------------
String.prototype.unEncodeHTML = function()
{
	var htmlString = this
	var unencodedString = new String("");
	var open = false;
	var charCode = 0;
	
	for (var index = 0; index < htmlString.length; index++) 
	{
		var c = htmlString.charAt(index);
	
		if (!open && c=="&" && htmlString.charAt(index+1) == "#")
		{
			open = true
			charCode = ""
			continue
		}
		else if (open && c==";")
		{
			open = false
			unencodedString += String.fromCharCode(Number(charCode))
			continue
		}
		
		if (open)
		{
			switch (c)
			{
				case "x":
					charCode += "0x"
					break;
				
				case "#":
					// skip
					break;
					
				default:
					charCode += c
			}
		}
		else
		{
			unencodedString += c
		}
	}
		
	return unencodedString;
}

// ------------------------------------------------------------------------------------------------------------
//	String.stringPaddedWithLeadingZeroes
// ------------------------------------------------------------------------------------------------------------
String.prototype.stringPaddedWithLeadingZeroes = function(targetLength)
{
	var paddedString = this
	while (paddedString.length < targetLength)
	{
		paddedString = '0' + paddedString
	}
	
	return paddedString
}


// ------------------------------------------------------------------------------------------------------------
//	String.stringWithNonBreakingSpaces
// ------------------------------------------------------------------------------------------------------------
String.prototype.stringWithNonBreakingSpaces = function()
{
	return this.replace(' ', String.fromCharCode(Number(160)))
}
