/****************************************************************************************
* 											*
*		Copyright (C) 2009 François Grondin. All Rights Reserved		*
*											*
* -------------------------------------------------------------------------------------	*
*											*
* The code in this website is the property of François Grondin. Copyright and other 	*
* intellectual property laws protect these materials. Reproduction or retransmission of *
* the materials, in whole or in part, in any manner, without the prior consent of the 	*
* copyright holder, is a violation of copyright law.					*
*											*
* The author is not responsible for any damages whatsoever, including any type of loss	*
* of information, interruption of business, personal injury and/or any damage or 	*
* consequential damage without any limitation incurred before, during or after the use	*
* of this code.										*
*											*
****************************************************************************************/

function encodeString(expression)
{

	var encodedString;
	var code;

	encodedString = "";

	for (var index = 0; index < expression.length; index++)
	{

		code = expression.charCodeAt(index);

		if (code == 0)
		{
			encodedString += "000";
		}
		else if (code < 10)
		{
			encodedString += "00" + code;
		}
		else if (code < 100)
		{
			encodedString += "0" + code;
		}
		else
		{
			encodedString += code;
		}
	}

	return encodedString;

}

function decodeString(expression)
{

	var decodedString;

	decodedString = "";

	for (var index = 0; index < expression.length; index+=3)
	{

		decodedString += String.fromCharCode(parseInt(expression.substr(index,3),10));

	}

	return decodedString;

}

function encodeURL(decimal, hexadecimal)
{

	var decimalPar;
	var hexPar;

	hexPar = "hexadecimal";
	decimalPar = "decimal";

	if (decimal != "")
	{

		return (decimalPar + "=" + encodeString(decimal));

	}

	if (hexadecimal != "")
	{

		return (hexPar + "=" + hexadecimal);

	}

}


function decodeURLDecimal(urlString)
{

	var decimalPar;
	var decimal

	var arrayString = new Array();
	var arrayParameter = new Array();

	var decodedDecimal;

	decimalPar = "decimal";
	decimal = "";
	decodedDecimal = "";

	if (urlString.indexOf("?") != -1)
	{
		urlString = urlString.substring(urlString.indexOf("?")+1);
	}
	else
	{
		urlString = "";
	}
	
	arrayString = urlString.split("&");

	for (var index = 0; index < arrayString.length; index++)
	{
		arrayParameter = arrayString[index].split("=");
			
		if (arrayParameter[0] == decimalPar)
		{
			decimal = arrayParameter[1];
		}

	}

	decodedDecimal = decodeString(decimal);

	return (decodedDecimal);

}

function decodeURLHexadecimal(urlString)
{

	var hexaPar;
	var hexa;

	var arrayString = new Array();
	var arrayParameter = new Array();

	var decodedHex;

	hexaPar = "hexadecimal";
	hexa = "";

	if (urlString.indexOf("?") != -1)
	{
		urlString = urlString.substring(urlString.indexOf("?")+1);
	}
	else
	{
		urlString = "";
	}
	
	arrayString = urlString.split("&");

	for (var index = 0; index < arrayString.length; index++)
	{
		arrayParameter = arrayString[index].split("=");
			
		if (arrayParameter[0] == hexaPar)
		{
			hexa = arrayParameter[1];
		}

	}

	decodedHex = hexa;

	return (decodedHex);

}