function right(str,index)
//Função que retorna o lado direito de uma string, com index caracteres a contar do fim.
{
	return str.substr(str.length-index);
};

function JSTrim(pValue)
// Função que executa um trim na string pValue e retorna a nova string.
{
	Left = 0;
	while(pValue.charAt(Left) == " ")
	{
		Left++;
	};
	Right = 0;
	while(pValue.charAt(pValue.length-1-Right) == " ")
	{
		Right++;
	}
	return pValue.substr(Left,(pValue.length-Right-Left));
};

function trimObj(oObj)
{
	Aux = JSTrim(oObj.value);	
	oObj.value = Aux;
}


function validateDate(sValue)
{
	DateTab = "/";
	
	aAuxDate = sValue.split(DateTab);
	if(aAuxDate.length != 3)
	//Sair ...
	{
		return false;
	}
	
	var MyDay, MyMonth, MyYear;

	MyDay = aAuxDate[0];
	MyMonth = aAuxDate[1];
	MyYear = aAuxDate[2];
	
	var AuxDate = new Date(MyYear,MyMonth-1,MyDay);
	if(parseInt(AuxDate.getDate()) == parseInt(MyDay) && (parseInt(AuxDate.getMonth())+1) == parseInt(MyMonth) && parseInt(AuxDate.getFullYear()) == parseInt(MyYear))
		return true;
	else
		return false;
}



function validateEmail(sValue)
{
	var EmailReg = new RegExp();
	EmailReg.compile("([a-z]|[0-9])+(.([a-z]|[0-9])+)*@([a-z]|[0-9])+(.([a-z]|[0-9])+)*","ig");
	if(testregExp(EmailReg, sValue))
		return true;
	else
		return false;
}

function testRequiredAndPopup(sObject, sFieldName)
{
	if(sObject.value == "")
	{
		sObject.focus();
		alert(sFieldName + " é um campo obrigatório!");
		return false;
	}
	
	return true;
}

function testDateAndPopup(sObject, sFieldName)
{
	if(!validateDate(sObject.value))
	{
		sObject.focus();
		alert(sFieldName + " tem uma data inválida!");
		return false;
	}
	
	return true;
}

function testEmailAndPopup(sObject, sFieldName)
{
	if(!validateEmail(sObject.value))
	{
		sObject.focus();
		alert(sFieldName + " está preenchido com um email inválido!");
		return false;	
	}
	return true;
}

function testregExp(oRegObj, sRegString)
{
	oAux = sRegString.match(oRegObj);
	if(oAux == null)
		return false;
	if(oAux.length != 1)
	{
		return false;
	}
	else
	{
		if(oAux[0] != sRegString)
			return false;
		else
			return true;
	};
};

