//Returns the keypressed
function key(pEvent)
{
	if(window.event)
		return pEvent.keyCode;
	else 
		return pEvent.which;
}

//Returns the element with the given ID
function $(pID)
{
	return document.getElementById(pID);
}

//Returns the elements with the given class
function $C(pClass)
{
	var elem = new Array();
	var i = 0;
	for (e in document.all)
	{
		if(document.all[e].className == pClass)
		{
			elem[i] = document.all[e];
			i++;
		}
	}
	return elem;
}

//Returns the elements with the given tag name
function $T(pTag)
{
	return document.getElementsByTagName(pTag);
}

//Eliminates spaces from the beggining and end of the string
String.prototype.trim = function()
{
	this.replace(/\s*\b/,"")
}

//Returns the number inside the string
String.prototype.numValue = function()
{
	return Number(this.replace(/\D/g,""));
}

//Checks the key pressed
function keyPressed(pEvent)
{
	if(window.event)
		return pEvent.keyCode;
	else 
		return pEvent.which;
}

//Check if the given value is in the given array
function inArray(pValue, pArray)
{
	for (i=0;i<pArray.length;i++)
		if(pValue == pArray[i]) return true;
	return false;
}

//Filters key pressed according to the ASCII code
function filterInterval(pKey, pMin, pMax)
{
	if (pKey.keyCode < pMin) return false;
	if (pKey.keyCode > pMax) return false;
}

//Formats the string as money
function toMoney(pValue)
{
	var arrValue = pValue.split(".");
	if(pValue == "")
		return "0.00";
	if((arrValue.length>2)||(arrValue.length<1))
		return pValue;
	if(arrValue.length == 1)
		return pValue + ".00";
	if(arrValue[1].length >= 2)
		return pValue;
	if(arrValue[1].length == 1)
		return pValue + "0";
	if(arrValue[1].length == 0)
		return pValue + "00";
}

//Checks if the key pressed is tab, enter or esc
function isActionKey(pChar)
{
	switch(pChar)
	{
		case 0:
		case 8:
		case 13:return true;
		default: return false;
	}
}

//Checks if the character is a valid brazilian portuguese character
function isValidSpecialChar(pChar)
{
	switch(pChar)
	{	
		case 32:
		case 192:
		case 193:
		case 195:
		case 199:
		case 201:
		case 202:
		case 205:
		case 211:
		case 212:
		case 213:
		case 218:
		case 224:
		case 225:
		case 227:
		case 231:
		case 233:
		case 234:
		case 237:
		case 243:
		case 244:
		case 245:
		case 250:return true;
		default: return false;
	}
}
