function trim(objeto,trinca)
{
var semIni=true;
var semFim=true;
var retorno = objeto.value;
if (objeto.value.length > 0 )
  {
  while ((semIni) || (semFim))
    {
    if (retorno.charAt(0)==' ')
      {
      retorno= retorno.substring(1,retorno.length);
      }
    else
      {
      semIni=false;
      }
    if (retorno.charAt(retorno.length-1)== ' ')
      {
      retorno= retorno.substring(0,retorno.length-1);
      }
    else
      {
      semFim=false;
      }	
    }
  }
if (trinca)
{
  objeto.value=retorno;
}  
return(retorno);
}

function valida_cep(cepIni,cepFim)
 {
 if (trim(cepIni,false)=='')
 {
		alert('O Prenchimento do campo CEP é obrigatório.');
		cepIni.select();
        return (false);
 }
if (!eNumero(cepIni.value))
	{
 	alert( 'Por favor, digite somente números.');
	cepIni.select();
    return (false);
	}
if (cepIni.value.length!=5)
	{
	alert('O Prefixo do Cep deve conter 5 caracteres.');
	cepIni.focus();
	return(false); 
	}	
if (trim(cepFim,false)=='')
 {
		alert('O Prenchimento do campo CEP é obrigatório.');
		cepFim.select();
        return (false);
 }
if (!eNumero(cepFim.value))
	{
 	alert( 'Por favor, digite somente números.');
	cepFim.select();
    return (false);
	}
if (cepFim.value.length!=3)
	{
	alert('O Sulfixo do Cep deve conter 3 caracteres.');
	cepFim.focus();
	return(false); 
	}
return(true);		  
}	
function eNumero(valor)
{
var contador=0;
var total=valor.length;
var bNumero=true;
if (contador!=-1)
	{
	while ((contador<total) && (bNumero))
		{
		if (isNaN(valor.charAt(contador)))
			{
			bNumero=false;
			return(false);  
			}
		contador=contador+1;
		}
	}
	return(true);
}

