// Funções para validar formularios
function ValidateFormContato(theForm)
{var vldrec = RadioUtil.getCheckedValue(theForm.tipo);
// Pessoa juridica
// Razao Social
if (vldrec == "Juridica") 
	{
	  if(theForm.razao)
 	  {
	    if (theForm.razao.value == "")
	    {
		  alert("Preencha o campo \"Razão Social\".");
		  theForm.razao.focus();
		  return false;
	    }
	    if (theForm.razao.value.length < 8)
	    {
	  	  alert("O campo \"Razão Social\" não está preenchido corretamente!");
		  theForm.razao.focus();
		  return false;
	    }
	  }

	  // CNPJ
	  if(theForm.cnpj)
	  {	
	    if (theForm.cnpj.value == "")
	    {
		  alert("Preencha o campo \"CNPJ\".");
		  theForm.cnpj.focus();
		  return false;
	    }
	  }
	
	  // I.E.
	  if(theForm.ie)
	   {	
	     if (theForm.ie.value == "")
	     {
		   alert("Preencha o campo \"Inscrição Estadual\".");
		   theForm.ie.focus();
		   return false;
	     }
	     if (theForm.ie.value.length < 6)
	       {
		     alert("O campo \"Inscrição Estadual\" não está preenchido corretamente!");
		     theForm.ie.focus();
		     return false;
	       }
	   }
	}

// Pessoa Fisica
    // Nome Pessoa Fisica

    if (vldrec == "Fisica") 
	 {	
	   if(theForm.nomefis)
	    {	
	     if (theForm.nomefis.value == "")
	      {
		   alert("Preencha o campo \"Nome\".");
		   theForm.nomefis.focus();
		   return false;
	    }
	   if (theForm.nomefis.value.length < 3)
	     {
		   alert("O campo \"Nome\" não está preenchido corretamente!");
		   theForm.nomefis.focus();
		   return false;
	     }
	 }

	  // CPF (No obrigatorio)
//	  if(theForm.cpf)
//	   {	
//	     if (theForm.cpf.value == "")
//	       {
//	       alert("Preencha o campo \"CPF\".");
//		    theForm.cpf.focus();
//		    return false;
//	       }
//	   }

	  // R.G. (No Obrigatorio)
//	  if(theForm.rg)
//	   {	
//	     if (theForm.rg.value == "")
//	      {
//		   alert("Preencha o campo \"RG\".");
//		   theForm.rg.focus();
//		   return false;
//	      }
//	     if (theForm.rg.value.length < 6)
//	      {
//		    alert("O campo \"RG\" não está preenchido corretamente!");
//		    theForm.rg.focus();
//		    return false;
//	      }
//	   }
    }	
	// endereço
	if(theForm.endereco)
	{
	  if (theForm.endereco.value == "")
	  {
		alert("Preencha o campo \"Endereço\".");
		theForm.endereco.focus();
		return false;
	  }
	  if (theForm.endereco.value.length < 3)
	  {
		alert("O campo \"endereço\" não está preenchido corretamente!");
		theForm.endereco.focus();
		return false;
	  }
	}
	// numero
	if(theForm.numero)
	{
	  if (theForm.numero.value == "")
	  {
		alert("Preencha o campo \"Numero\".");
		theForm.numero.focus();
		return false;
	  }
	}
	// Bairro
	if(theForm.bairro)
	{
      if (theForm.bairro.value == "")
	  {
		alert("Preencha o campo \"Bairro\".");
		theForm.bairro.focus();
		return false;
	  }
	}
	// Cidade
	if(theForm.cidade)
	{
	  if (theForm.cidade.value == "")
	   { 
		alert("Preencha o campo \"Cidade\".");
		theForm.cidade.focus();
		return false;
	  }
	  if (theForm.cidade.value.length < 3)
	  {
		alert("O campo \"Cidade\" não está preenchido corretamente!");
		theForm.cidade.focus();
		return false;
	  }
	}
	
	// Estado
	if(theForm.UF)
	{
	  if (theForm.UF.value == "0")
	   {
		alert("Selecione o \"Estado\".");
		theForm.UF.focus();
		return false;
	   }
	}
	
    // CEP
	if(theForm.CEP)
	{
	  if (theForm.CEP.value == "")
 	  {
		alert("Preencha o campo \"CEP\".");
		theForm.CEP.focus();
		return false;
	  }

      if (theForm.CEP.value.length < 9)
	   {
		alert("O campo \"CEP\" não está preenchido corretamente!");
		theForm.CEP.focus();
		return false;
	   }
	}
	
	// DDD
	if(theForm.DDD)
	{
	  if (theForm.DDD.value == "")
	   {
		alert("Preencha o campo \"DDD\".");
		theForm.DDD.focus();
		return false;
	   }
	   if ((theForm.DDD.value.length < 2) || (theForm.DDD.value < 11) || ((theForm.DDD.value)%10 == 0))
	   {
		alert("O campo \"DDD\" não está preenchido corretamente!");
		theForm.DDD.focus();
		return false;
       }
	}

	// Fone
	if (theForm.fone)
	{	
	   if (theForm.fone.value == "")
	   {
		alert("Preencha o campo \"Telefone\".");
		theForm.fone.focus();
		return false;
	   }
		if (theForm.fone.value.length < 9)
	      {
		   alert("O campo \"Telefone\" não está preenchido corretamente!");
		   theForm.fone.focus();
		   return false;
          }
	}

	// Nome do contato
	if (vldrec == "Juridica") 
	{
	  if (theForm.nome)
	  {
	     if (theForm.nome.value == "")
  	     {
		  alert("Preencha o campo \"Nome Contato\".");
		  theForm.nome.focus();
		  return false;
	    }
	  }
	}
	// E-mail
	if (theForm.email)
	{
	   if (theForm.email.value == "")
	   {
		alert("Preencha o campo \"E-mail Contato\".");
		theForm.email.focus();
		return false;
	   } 
	   //e-mail  valido
	   if (checkEmail(theForm.email.value) == false)
	   { alert("E-mail inválido!");
	  	 theForm.email.focus();
		 return false;
	   }
	}
 return true;
}

// Formulario de inscrição
function ValidateFormInscr(theForm)
{
    // Cursos
    if (theForm.nrocurso)
	{
      if(theForm.nrocurso.value == "0")
  	   {
		 alert("Selecione o \"Curso\" que deseja participar.");
		 return false;
	    }
	}
    // Nome do participante
	if (theForm.nomepart)
	{
	   if (theForm.nomepart.value == "")
  	   {
		 alert("Preencha o campo \"Nome\".");
		 theForm.nomepart.focus();
		 return false;
	   }
	}

	// Cracha do participante
	if (theForm.crachapart)
	{
	   if (theForm.crachapart.value == "")
  	   {
		 alert("Preencha o campo \"Nome para crachá\".");
		 theForm.crachapart.focus();
		 return false;
	   }
	}
	
	// Cargo do participante
	if (theForm.cargopart)
	{
	   if (theForm.cargopart.value == "")
  	   {
		 alert("Preencha o campo \"Cargo\".");
		 theForm.cargopart.focus();
		 return false;
	   }
	}	
	
	// E-mail
	if (theForm.emailpart)
	{
	   if (theForm.emailpart.value == "")
	   {
		alert("Preencha o campo \"E-mail\".");
		theForm.emailpart.focus();
		return false;
	   } 
	   //e-mail  valido
	   if (checkEmail(theForm.emailpart.value) == false)
	   { alert("E-mail inválido!");
	  	 theForm.emailpart.focus();
		 return false;
	   }
	}
	
	// DDD
	if(theForm.DDDpart)
	{
	  if (theForm.DDDpart.value == "")
	   {
		alert("Preencha o campo \"DDD\".");
		theForm.DDDpart.focus();
		return false;
	   }
	   if (theForm.DDDpart.value.length < 2)
	   {
		alert("O campo \"DDD\" não está preenchido corretamente!");
		theForm.DDDpart.focus();
		return false;
       }
	}

	// Celular Tel contato
	if(theForm.celpart)
	{	
	  if (theForm.celpart.value == "")
	   {
		alert("Preencha o campo \"Celular\".");
		theForm.celpart.focus();
		return false;
	   }
		if (theForm.celpart.value.length < 9)
	   {
		alert("O campo \"Celular\" não está preenchido corretamente!");
		theForm.celpart.focus();
		return false;
       }
	}
	// Revista do Participante
	if (theForm.revpart)
	{var divrevista = document.getElementById("temrevista");
	 if(divrevista.style.display == "block")
	  {
	    if (theForm.revpart.value == "0")
  	       {
		     alert("Selecione a \"Revista\" que deseja receber.");
		     return false;
	       }
	  }
	}
	// Como Soube dos Cursos
	if (theForm.divulgacao.value == 0)
	   {
		alert("Por favor, informe como ficou sabendo do evento.");
		theForm.divulgacao.focus();
		return false;
       } 
	   else
	     {
	      if ( theForm.divulgacao.value == "outros" )
	       { if (theForm.divulgtext.value == "")
	          {
		       alert("Por favor, especifique como ficou sabendo do evento.");
		       theForm.divulgtext.focus();
		       return false;
		      }
		   }
	     }
return true;
}

function ValidateFormCompany(theForm)
{
	  if(theForm.razao)
 	  {
	    if (theForm.razao.value == "")
	    {
		  alert("Preencha o campo \"Razão Social\".");
		  theForm.razao.focus();
		  return false;
	    }
	    if (theForm.razao.value.length < 8)
	    {
	  	  alert("O campo \"Razo Social\" não está preenchido corretamente!");
		  theForm.razao.focus();
		  return false;
	    }
	  }

	  // CNPJ
	  if(theForm.cnpj)
	  {	
	    if (theForm.cnpj.value == "")
	    {
		  alert("Preencha o campo \"CNPJ\".");
		  theForm.cnpj.focus();
		  return false;
	    }
	  }
	
	  // I.E.
	  if(theForm.ie)
	   {	
	     if (theForm.ie.value == "")
	     {
		   alert("Preencha o campo \"Inscrição Estadual\".");
		   theForm.ie.focus();
		   return false;
	     }
	     if (theForm.ie.value.length < 6)
	       {
		     alert("O campo \"Inscrição Estadual\" não está preenchido corretamente!");
		     theForm.ie.focus();
		     return false;
	       }
	   }
	// endereço
	if(theForm.endereco)
	{
	  if (theForm.endereco.value == "")
	  {
		alert("Preencha o campo \"Endereço\".");
		theForm.endereco.focus();
		return false;
	  }
	  if (theForm.endereco.value.length < 3)
	  {
		alert("O campo \"endereço\" não está preenchido corretamente!");
		theForm.endereco.focus();
		return false;
	  }
	}
	// Bairro
	if(theForm.bairro)
	{
      if (theForm.bairro.value == "")
	  {
		alert("Preencha o campo \"Bairro\".");
		theForm.bairro.focus();
		return false;
	  }
	}
	// Cidade
	if(theForm.cidade)
	{
	  if (theForm.cidade.value == "")
	   { 
		alert("Preencha o campo \"Cidade\".");
		theForm.cidade.focus();
		return false;
	  }
	  if (theForm.cidade.value.length < 3)
	  {
		alert("O campo \"Cidade\" não está preenchido corretamente!");
		theForm.cidade.focus();
		return false;
	  }
	}
	
	// Estado
	if(theForm.UF)
	{
	  if (theForm.UF.value == "0")
	   {
		alert("Selecione o \"Estado\".");
		theForm.UF.focus();
		return false;
	   }
	}
	
    // CEP
	if(theForm.CEP)
	{
	  if (theForm.CEP.value == "")
 	  {
		alert("Preencha o campo \"CEP\".");
		theForm.CEP.focus();
		return false;
	  }

      if (theForm.CEP.value.length < 9)
	   {
		alert("O campo \"CEP\" não está preenchido corretamente!");
		theForm.CEP.focus();
		return false;
	   }
	}
	
	// DDD
	if(theForm.DDD)
	{
	  if (theForm.DDD.value == "")
	   {
		alert("Preencha o campo \"DDD\".");
		theForm.DDD.focus();
		return false;
	   }
	   if (theForm.DDD.value.length < 2)
	   {
		alert("O campo \"DDD\" não está preenchido corretamente!");
		theForm.DDD.focus();
		return false;
       }
	}

	// Fone
	if (theForm.telefone)
	{	
	   if (theForm.telefone.value == "")
	   {
		alert("Preencha o campo \"Telefone\".");
		theForm.telefone.focus();
		return false;
	   }
		if (theForm.telefone.value.length < 9)
	      {
		   alert("O campo \"Telefone\" não está preenchido corretamente!");
		   theForm.telefone.focus();
		   return false;
          }
	}

    // Nome do contato
	if (theForm.nome)
	  {
	     if (theForm.nome.value == "")
  	     {
		  alert("Preencha o campo \"Nome Contato\".");
		  theForm.nome.focus();
		  return false;
 	     }
	  	 if (theForm.nome.value.length < 9)
	      {
		   alert("O campo \"Nome Contato\" não está preenchido corretamente!");
		   theForm.nome.focus();
		   return false;
          }
	  }
	// Departamento do contato
	if (theForm.depto)
	  {
	     if (theForm.depto.value == "")
  	     {
		  alert("Preencha o campo \"Departamento\".");
		  theForm.depto.focus();
		  return false;
	    }
	  	if (theForm.depto.value.length < 5)
	      {
		   alert("O campo \"Departamento\" não está preenchido corretamente!");
		   theForm.depto.focus();
		   return false;
          }		
	  }
	
	// E-mail
	if (theForm.email)
	{
	   if (theForm.email.value == "")
	   {
		alert("Preencha o campo \"E-mail Contato\".");
		theForm.email.focus();
		return false;
	   } 
	   //e-mail  valido
	   if (checkEmail(theForm.email.value) == false)
	   { alert("E-mail inválido!");
	  	 theForm.email.focus();
		 return false;
	   }
	}

   // Proposta
	if (theForm.proposta)
	{
	   if (theForm.proposta.value == "")
	   {
		alert("Preencha o campo \"Proposta\".");
		theForm.proposta.focus();
		return false;
	   } 
	   // 
  	   if (theForm.proposta.value.length < 1)
	      {
		   alert("O campo \"Proposta\" não está preenchido corretamente!");
		   theForm.proposta.focus();
		   return false;
          }
	}

return true;
}

function ValidateFormFale(theForm)
{
	  if(theForm.empresa)
 	  {
	    if (theForm.empresa.value == "")
	    {
		  alert("Preencha o campo \"Empresa/Instituição\".");
		  theForm.empresa.focus();
		  return false;
	    }
	    if (theForm.empresa.value.length < 8)
	    {
	  	  alert("O campo \"Empresa/Instituição\" não está preenchido corretamente!");
		  theForm.empresa.focus();
		  return false;
	    }
	  }

    // Nome do contato
	if (theForm.nome)
	  {
	     if (theForm.nome.value == "")
  	     {
		  alert("Preencha o campo \"Nome Contato\".");
		  theForm.nome.focus();
		  return false;
 	     }
	  	 if (theForm.nome.value.length < 9)
	      {
		   alert("O campo \"Nome Contato\" não está preenchido corretamente!");
		   theForm.nome.focus();
		   return false;
          }
	  }

// E-mail
	if (theForm.email)
	{
	   if (theForm.email.value == "")
	   {
		alert("Preencha o campo \"E-mail\".");
		theForm.email.focus();
		return false;
	   } 
	   //e-mail  valido
	   if (checkEmail(theForm.email.value) == false)
	   { alert("E-mail inválido!");
	  	 theForm.email.focus();
		 return false;
	   }
	}

// assunto
	if (theForm.assunto)
	{
	   if (theForm.assunto.value == "")
	   {
		alert("Preencha o campo \"Assunto\".");
		theForm.assunto.focus();
		return false;
	   } 
	   // 
  	   if (theForm.assunto.value.length < 1)
	      {
		   alert("O campo \"Assunto\" não está preenchido corretamente!");
		   theForm.assunto.focus();
		   return false;
          }
	}

// Informaes
	if (theForm.info)
	{
	   if (theForm.info.value == "")
	   {
		alert("Preencha o campo \"Comentários\".");
		theForm.info.focus();
		return false;
	   } 
	   // 
  	   if (theForm.info.value.length < 1)
	      {
		   alert("O campo \"Comentários\" não está preenchido corretamente!");
		   theForm.info.focus();
		   return false;
          }
	}

return true;
}

function ValidateFormCadastro(theForm)
{
 if (theForm.usrnome.value == "")
      {alert("Preencha o campo \"Nome\".");
	   theForm.usrnome.focus();
	   return false;
	  }
	 if (theForm.usrnome.value.length < 3)
	  {alert("O campo \"Nome\" não está preenchido corretamente!");
	   theForm.usrnome.focus();
	   return false;
	  }
	  
if (theForm.usremail)
	{
	   if (theForm.usremail.value == "")
	   {
		alert("Preencha o campo \"E-mail\".");
		theForm.usremail.focus();
		return false;
	   } 
	   //e-mail  valido
	   if (checkEmail(theForm.usremail.value) == false)
	   { alert("E-mail inválido!");
	  	 theForm.usremail.focus();
		 return false;
	   }
	}	  

if (theForm.usrpwd.value == "")
      {alert("Preencha o campo \"Senha\".");
	   theForm.usrpwd.focus();
	   return false;
	  }
	 if (theForm.usrpwd.value.length < 6)
	  {alert("O campo \"Senha\" Deve conter no mínino 6 e máximo 16 caracteres");
	   theForm.usrpwd.focus();
	   return false;
	  }

if (theForm.usrpwdc.value == "")
      {alert("É necessario \"Confirmar a senha\"!");
	   theForm.usrpwdc.focus();
	   return false;
	  }
	 if (theForm.usrpwdc.value != theForm.usrpwd.value)
	  {alert("Sua \"senha\" não confere, tente novamente!");
	   theForm.usrpwdc.value="";
	   theForm.usrpwd.value = "";
	   theForm.usrpwd.focus();
	   return false;
	  }
return true;
}

function ValidateFormDVD(theForm)
{
	  if(theForm.empresa)
 	  {
	    if (theForm.empresa.value == "")
	    {
		  alert("Preencha o campo \"Empresa/Instituição\".");
		  theForm.empresa.focus();
		  return false;
	    }
	    if (theForm.empresa.value.length < 8)
	    {
	  	  alert("O campo \"Empresa/Instituição\" não está preenchido corretamente!");
		  theForm.empresa.focus();
		  return false;
	    }
	  }

    // Nome do contato
	if (theForm.nome)
	  {
	     if (theForm.nome.value == "")
  	     {
		  alert("Preencha o campo \"Nome Contato\".");
		  theForm.nome.focus();
		  return false;
 	     }
	  	 if (theForm.nome.value.length < 9)
	      {
		   alert("O campo \"Nome Contato\" não está preenchido corretamente!");
		   theForm.nome.focus();
		   return false;
          }
	  }
	  
	// endereço
	if(theForm.endereco)
	{
	  if (theForm.endereco.value == "")
	  {
		alert("Preencha o campo \"Endereço\".");
		theForm.endereco.focus();
		return false;
	  }
	  if (theForm.endereco.value.length < 3)
	  {
		alert("O campo \"endereço\" não está preenchido corretamente!");
		theForm.endereco.focus();
		return false;
	  }
	}
	// Bairro
	if(theForm.bairro)
	{
      if (theForm.bairro.value == "")
	  {
		alert("Preencha o campo \"Bairro\".");
		theForm.bairro.focus();
		return false;
	  }
	}
	// Cidade
	if(theForm.cidade)
	{
	  if (theForm.cidade.value == "")
	   { 
		alert("Preencha o campo \"Cidade\".");
		theForm.cidade.focus();
		return false;
	  }
	  if (theForm.cidade.value.length < 3)
	  {
		alert("O campo \"Cidade\" não está preenchido corretamente!");
		theForm.cidade.focus();
		return false;
	  }
	}
	
	// Estado
	if(theForm.UF)
	{
	  if (theForm.UF.value == "0")
	   {
		alert("Selecione o \"Estado\".");
		theForm.UF.focus();
		return false;
	   }
	}
	
    // CEP
	if(theForm.CEP)
	{
	  if (theForm.CEP.value == "")
 	  {
		alert("Preencha o campo \"CEP\".");
		theForm.CEP.focus();
		return false;
	  }

      if (theForm.CEP.value.length < 9)
	   {
		alert("O campo \"CEP\" não está preenchido corretamente!");
		theForm.CEP.focus();
		return false;
	   }
	}
	
	// DDD
	if(theForm.DDD)
	{
	  if (theForm.DDD.value == "")
	   {
		alert("Preencha o campo \"DDD\".");
		theForm.DDD.focus();
		return false;
	   }
	   if (theForm.DDD.value.length < 2)
	   {
		alert("O campo \"DDD\" não está preenchido corretamente!");
		theForm.DDD.focus();
		return false;
       }
	}

	// Fone
	if (theForm.telefone)
	{	
	   if (theForm.telefone.value == "")
	   {
		alert("Preencha o campo \"Telefone\".");
		theForm.telefone.focus();
		return false;
	   }
		if (theForm.telefone.value.length < 9)
	      {
		   alert("O campo \"Telefone\" não está preenchido corretamente!");
		   theForm.telefone.focus();
		   return false;
          }
	}

// E-mail
	if (theForm.email)
	{
	   if (theForm.email.value == "")
	   {
		alert("Preencha o campo \"E-mail\".");
		theForm.email.focus();
		return false;
	   } 
	   //e-mail  valido
	   if (checkEmail(theForm.email.value) == false)
	   { alert("E-mail inválido!");
	  	 theForm.email.focus();
		 return false;
	   }
	}

// assunto
	if (theForm.assunto)
	{
	   if (theForm.assunto.value == "")
	   {
		alert("Preencha o campo \"Assunto\".");
		theForm.assunto.focus();
		return false;
	   } 
	   // 
  	   if (theForm.assunto.value.length < 1)
	      {
		   alert("O campo \"Assunto\" não está preenchido corretamente!");
		   theForm.assunto.focus();
		   return false;
          }
	}

// Informaes
	if (theForm.info)
	{
	   if (theForm.info.value == "")
	   {
		alert("Preencha o campo \"Informações\".");
		theForm.info.focus();
		return false;
	   } 
	   // 
  	   if (theForm.info.value.length < 10)
	      {
		   alert("O campo \"Informações\" não está preenchido corretamente!");
		   theForm.info.focus();
		   return false;
          }
	}

return true;
}
/**
* Reference: Sandeep V. Tamhankar (stamhankar@hotmail.com),
* http://javascript.internet.com
*/
function checkEmail(emailStr)
{
 if (emailStr.length == 0) {return true;}
 var emailPat=/^(.+)@(.+)$/;
 var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
 var validChars="\[^\\s" + specialChars + "\]";
 var quotedUser="(\"[^\"]*\")";
 var ipDomainPat=/^(\d{1,3})[.](\d{1,3})[.](\d{1,3})[.](\d{1,3})$/;
 var atom=validChars + '+';
 var word="(" + atom + "|" + quotedUser + ")";
 var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
 var domainPat=new RegExp("^" + atom + "(\\." + atom + ")*$");
 var matchArray=emailStr.match(emailPat);
 if (matchArray == null) { return false; }
 var user=matchArray[1];
 var domain=matchArray[2];
 if (user.match(userPat) == null) { return false; }
 var IPArray = domain.match(ipDomainPat);
 if (IPArray != null)
  {for (var i = 1; i <= 4; i++)
     {
 	  if (IPArray[i] > 255) { return false; }
     }
     return true;
  }
 var domainArray=domain.match(domainPat);
 if (domainArray == null) { return false; }
 var atomPat=new RegExp(atom,"g");
 var domArr=domain.match(atomPat);
 var len=domArr.length;
 if ((domArr[domArr.length-1].length < 2) || (domArr[domArr.length-1].length > 3)){return false;}
 if (len < 2) { return false; }
 return true;
}

/** validao de documentos */

function Valida_CPF(theForm)
{
var CPF = theForm.cpf.value; 
var POSICAO, I, SOMA, DV, DV_INFORMADO;
var DIGITO = new Array(10);
CPF = CPF.replace(/\-|\/|\./g,'');
DV_INFORMADO = CPF.substr(9, 2); 

if (CPF == "") {return true;}

for (I=0; I<=8; I++) {
 DIGITO[I] = CPF.substr( I, 1);
}

POSICAO = 10;
SOMA = 0;
 for (I=0; I<=8; I++) {
 SOMA = SOMA + DIGITO[I] * POSICAO;
 POSICAO = POSICAO - 1;
 }
DIGITO[9] = SOMA % 11;
 if (DIGITO[9] < 2) {
 DIGITO[9] = 0;
}
 else{
 DIGITO[9] = 11 - DIGITO[9];
}

POSICAO = 11;
SOMA = 0;
 for (I=0; I<=9; I++) {
 SOMA = SOMA + DIGITO[I] * POSICAO;
 POSICAO = POSICAO - 1;
 }
DIGITO[10] = SOMA % 11;
 if (DIGITO[10] < 2) {
 DIGITO[10] = 0;
 }
 else {
 DIGITO[10] = 11 - DIGITO[10];
 }

DV = DIGITO[9] * 10 + DIGITO[10];
 if (DV != DV_INFORMADO) {
 alert('CPF inválido');
 theForm.cpf.focus();
 return false;
 }

 for (I=0; I<=9; I++) {

	if (DIGITO[I] == DIGITO[9] && DIGITO[I] == DIGITO[8] && DIGITO[I] == DIGITO[7] && DIGITO[I] == DIGITO[6] && DIGITO[I] == DIGITO[5] && DIGITO[I] == DIGITO[4] && DIGITO[I] == DIGITO[3] && DIGITO[I] == DIGITO[2] && DIGITO[I] == DIGITO[1] && DIGITO[I] == DIGITO[0]) {
	  alert('CPF inválido');
      theForm.cpf.focus();
      return false;
    }
 }
return true;
}

function Valida_CNPJ(theForm)
{
var CNPJ = theForm.cnpj.value; 
var POSICAO, I, SOMA1,SOMA2, DV, DV_INFORMADO;
var DIGITO = new Array(13);
CNPJ = CNPJ.replace(/\-|\/|\./g,'');
DV_INFORMADO = CNPJ.substr(12, 2); 

if (CNPJ == "") {return true;}
//if (CNPJ == 00000000000000) {return false;}
for (I=0; I<=11; I++) {
 DIGITO[I] = CNPJ.substr( I, 1);
}

POSICAO = 5;
SOMA1 = 0;
 for (I=0; I<=3; I++) {
 SOMA1 = SOMA1 + DIGITO[I] * POSICAO;
 POSICAO = POSICAO - 1;
 }
POSICAO = 9;
SOMA2 = 0;
 for (I=4; I<=11; I++) {
 SOMA2 = SOMA2 + DIGITO[I] * POSICAO;
 POSICAO = POSICAO - 1;
 }

SOMA2 = SOMA1 + SOMA2;

DIGITO[12] = SOMA2 % 11;
 if (DIGITO[12] < 2) {
 DIGITO[12] = 0;
}
 else{
 DIGITO[12] = 11 - DIGITO[12];
}

POSICAO = 6;
SOMA1 = 0;
 for (I=0; I<=4; I++) {
 SOMA1 = SOMA1 + DIGITO[I] * POSICAO;
 POSICAO = POSICAO - 1;
 }
 
 POSICAO = 9;
 SOMA2 = 0;
 for (I=5; I<=12; I++) {
 SOMA2 = SOMA2 + DIGITO[I] * POSICAO;
 POSICAO = POSICAO - 1;
 }
 
SOMA2 = SOMA1 + SOMA2;

DIGITO[13] = SOMA2 % 11;
 if (DIGITO[13] < 2) {
 DIGITO[13] = 0;
 }
 else {
 DIGITO[13] = 11 - DIGITO[13];
 }

DV = DIGITO[12] * 10 + DIGITO[13];
 if (DV != DV_INFORMADO) {
 alert('CNPJ inválido');
 theForm.cnpj.focus();
 return false;
 }
 else
 { return true; }
// return true;
}