/**
* Valida o CEP passado
* CEP válido, retorna true.
* CEP inválido, retorna false.
* CEP não preenchido, retorna o valor booleano passado como parâmetro para indicar se o campo é de preenchimento obrigatório.
*/
// Função para retirar os espaços em branco do início e do fim da string.
function myTrim( strTexto )
{
    // Substitúi os espaços vazios no inicio e no fim da string por vazio.
    return strTexto.replace(/^\s+|\s+$/g, '');
}

// Função para validação de CEP.
function isCEP( strCEP, blnVazio )
{
    // Caso o CEP não esteja nesse formato ele é inválido!
    var objER = /^[0-9]{2}\.[0-9]{3}-[0-9]{3}$/;

    strCEP = myTrim(strCEP)
    if(strCEP.length > 0)
    {
        if(objER.test(strCEP))
            return true;
        else
            return false;
    }
    else
        return blnVazio;
}
/**
* Checa se o valor é vazio ou zero
*/
function isEmpty( valor )
{
	if ( valor=='' || valor==0 )
		return true;
	else
		return false;
}
/**
* Checa se o valor é negativo
*/
function isNegative( valor )
{
	if (valor < 0)
		return true;
	else
		return false;
}
// Checa o email
function isEmail( valor )
{
    var objER = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

    if(valor.length > 0)
    {
        if(objER.test(valor))
            return true;
        else
            return false;
    }
    else
        return false;
}
// checa se é nro de telefone
function isNumTel( event )
{
	var Tecla = event.which;
	if(Tecla == null) Tecla = event.keyCode;
	//se nao for número nem parentesis ou espaço
	if( ( Tecla != 8 && Tecla != 13 && Tecla != 27 && Tecla != 37 && Tecla != 39 && Tecla != 46 &&  Tecla != 109 ) && ( ( Tecla < 48 || Tecla > 59 ) && ( Tecla < 96 || Tecla > 105 ) ) )
	{
		event.returnValue = false;
		alert( "Só devem ser digitados números !" );
		return false;
	}
	event.returnValue = true;
	return true;
}
// Checa se a tecla digitada é um nro
function isNum( event )
{
	var Tecla = event.which;
	if(Tecla == null) Tecla = event.keyCode;
	//se nao for número
	if( ( Tecla != 8 && Tecla != 13 && Tecla != 27 && Tecla != 37 && Tecla != 39 && Tecla != 46 &&  Tecla != 109 ) && ( ( Tecla < 48 || Tecla > 57 ) && ( Tecla > 96 || Tecla < 105 ) ) )
	{
		event.returnValue = false;
		alert( "Só devem ser digitados números !" );
		return false;
	}
	event.returnValue = true;
	return true;
}
