function trim(str)
{
	while (str.charAt(0) == " ")
		str = str.substr(1,str.length -1);

	while (str.charAt(str.length-1) == " ")
		str = str.substr(0,str.length-1);
		
	return str;
} 

function isTexto(value)
{
	if (trim(value) == "")
		return false;
		
	return true;
	
}

function isNumero(value)
{
	
	if ((trim(value) == "")||(isNaN(value)))
		return false;
	else
		return true;
}

function isData(value)
{
	if (trim(value) == "")	return false;
	return true;
}

function isEmail(value)
{
	var reEmail = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	return reEmail.test(value)
}

function isData(value)
{
	var vData = /^((0?[1-9]|[12]\d)\/(0?[1-9]|1[0-2])|30\/(0?[13-9]|1[0-2])|31\/(0?[13578]|1[02]))\/(19|20)?\d{2}$/;
	return vData.test(value);
}

function isHora(value)
{
	//Valida a hora no formato HH:MM:SS
	var vHora = /^(((0|1)[0-9])|(2[0-4]))\:([0-5][0-9])\:([0-5][0-9])$/;
	return vHora.test(value);
}

function isCep(value)
{
	var reCep = /^(\d{5}\-\d{3})$/;	
	return reCep.test(value);
}

function isCepFull(value)
{
	var reCep = /^(\d{8})$/;	
	return reCep.test(value);
}

function isDecimal(value)
{
	var reDecimal = /^[+-]?((\d+|\d{1,3}(\.\d{3})+)(\,\d*)?|\,\d+)$/;	
	return reDecimal.test(value);
}

function comparaData(dDataInicial, dDataFinal)
{
	var dataIni = new Date(dDataInicial.substring(6,10),
											   dDataInicial.substring(3,5)-1,
											   dDataInicial.substring(0,2));
											   
	var dataFim = new Date(dDataFinal.substring(6,10),
											   dDataFinal.substring(3,5)-1,
											   dDataFinal.substring(0,2));											   
	
	if (dataIni == dataFim)
		return 0;
	else if (dataIni < dataFim)
		return -1;
	else if (dataIni > dataFim)
		return 1;
												   
	
}

function validaFormConvenio() {

   if ( document.theform.empresa.value == "" ) {
      alert("Atenção, preencha o campo 'Empresa'.");
	  document.theform.empresa.focus();
	  return false;
   }

   if ( document.theform.atividade.value == "" ) {
      alert("Atenção, preencha o campo 'Ramo de ativ.'.");
	  document.theform.atividade.focus();
	  return false;
   }

   if ( document.theform.Sim.checked == false && document.theform.Não.checked == false ) {
      alert("Atenção, selecione o campo 'Há filiais'.");
	  document.theform.Sim.focus();
	  return false;
   }

   if ( document.theform.endereco.value == "" ) {
      alert("Atenção, preencha o campo 'Endereço'.");
	  document.theform.endereco.focus();
	  return false;
   }

   if ( document.theform.funcionarios.value == "" ) {
      alert("Atenção, preencha o campo 'Funcionários'.");
	  document.theform.funcionarios.focus();
	  return false;
   }

   if ( document.theform.contato.value == "" ) {
      alert("Atenção, preencha o campo 'Contato'.");
	  document.theform.contato.focus();
	  return false;
   }

   if ( document.theform.cargo.value == "" ) {
      alert("Atenção, preencha o campo 'Cargo'.");
	  document.theform.cargo.focus();
	  return false;
   }

   if ( document.theform.site.value == "" ) {
      alert("Atenção, preencha o campo 'Site'.");
	  document.theform.site.focus();
	  return false;
   }

   if ( document.theform.email.value == "" ) {
      alert("Atenção, preencha o campo 'E-mail'.");
	  document.theform.email.focus();
	  return false;
   }else{
	  if ( document.theform.email.value.indexOf("@") == -1 || document.theform.email.value.indexOf(".") == -1 ) {
		 alert("Atenção, preencha corretamente o campo 'E-mail'.");
		 document.theform.email.focus();
		 return false;
	  }   
   }

   if ( document.theform.ddd.value == "" ) {
      alert("Atenção, preencha o campo 'DDD'.");
	  document.theform.ddd.focus();
	  return false;
   }

   if ( document.theform.telefone.value == "" ) {
      alert("Atenção, preencha o campo 'Telefone'.");
	  document.theform.telefone.focus();
	  return false;
   }

   if ( document.theform.comentarios.value == "" ) {
      alert("Atenção, preencha o campo 'Comentários'.");
	  document.theform.comentarios.focus();
	  return false;
   }

}

