    function SetState_Nacionalidade()
    {  
    
      if (document.frmDocumento.cbNacionalidade.value > 0)
      {      
         document.frmDocumento.txtNacionalidade_Outra.disabled = true;
         document.frmDocumento.txtNacionalidade_Outra.style.backgroundColor = 'rgb(210, 210, 210)';
         document.frmDocumento.txtNacionalidade_Outra.value = "";         
      }
      else
      {
         document.frmDocumento.txtNacionalidade_Outra.disabled = false;
         document.frmDocumento.txtNacionalidade_Outra.style.backgroundColor = 'rgb(255, 255, 255)';
      }
    }
    
    function SetState_ArquivoBI()
    {  
      if (document.frmDocumento.cbArquivoBI.value > 0)
      {      
         document.frmDocumento.txtArquivoBI_Outro.disabled = true;
         document.frmDocumento.txtArquivoBI_Outro.style.backgroundColor = 'rgb(210, 210, 210)';
         document.frmDocumento.txtArquivoBI_Outro.value = "";
      }
      else
      {
         document.frmDocumento.txtArquivoBI_Outro.disabled = false;
         document.frmDocumento.txtArquivoBI_Outro.style.backgroundColor = 'rgb(255, 255, 255)';
      }
    }
    
    function SetState_GrauAcademico()
    {  
      if (document.frmDocumento.cmbGrau_Academico.value == 0)
      {
         document.frmDocumento.txtAnoConclusao.disabled = true;
         document.frmDocumento.txtAnoConclusao.style.backgroundColor = 'rgb(210, 210, 210)';
         document.frmDocumento.txtAnoConclusao.value = "";         
         document.frmDocumento.cmbNotaFinal.disabled = true;
         document.frmDocumento.cmbNotaFinal.style.backgroundColor = 'rgb(210, 210, 210)';
         document.frmDocumento.cmbNotaFinal.value=0;         
         document.frmDocumento.txtAnoFrequencia.disabled = true;
         document.frmDocumento.txtAnoFrequencia.style.backgroundColor = 'rgb(210, 210, 210)';
         document.frmDocumento.txtAnoFrequencia.value = "";         
         document.frmDocumento.txtAnosCurso.disabled = true;
         document.frmDocumento.txtAnosCurso.style.backgroundColor = 'rgb(210, 210, 210)';
         document.frmDocumento.txtAnosCurso.value = "";
      }
      else
      {
         if (document.frmDocumento.cmbGrau_Academico.value == 4)
         {      
            document.frmDocumento.txtAnoConclusao.disabled = true;
            document.frmDocumento.txtAnoConclusao.style.backgroundColor = 'rgb(210, 210, 210)';
            document.frmDocumento.txtAnoConclusao.value = ""            
            document.frmDocumento.cmbNotaFinal.disabled = true;
            document.frmDocumento.cmbNotaFinal.style.backgroundColor = 'rgb(210, 210, 210)';
            document.frmDocumento.cmbNotaFinal.value = 0;            
            document.frmDocumento.txtAnoFrequencia.disabled = false;
            document.frmDocumento.txtAnoFrequencia.style.backgroundColor = 'rgb(255, 255, 255)';
            document.frmDocumento.txtAnosCurso.disabled = false;
            document.frmDocumento.txtAnosCurso.style.backgroundColor = 'rgb(255, 255, 255)';
         }
         else
         {
            document.frmDocumento.txtAnoConclusao.disabled = false;
            document.frmDocumento.txtAnoConclusao.style.backgroundColor = 'rgb(255, 255, 255)';
            document.frmDocumento.cmbNotaFinal.disabled = false;
            document.frmDocumento.cmbNotaFinal.style.backgroundColor = 'rgb(255, 255, 255)';
            document.frmDocumento.txtAnoFrequencia.disabled = true;
            document.frmDocumento.txtAnoFrequencia.style.backgroundColor = 'rgb(210, 210, 210)';
            document.frmDocumento.txtAnoFrequencia.value = "";
            document.frmDocumento.txtAnosCurso.disabled = true;
            document.frmDocumento.txtAnosCurso.style.backgroundColor = 'rgb(210, 210, 210)';
            document.frmDocumento.txtAnosCurso.value = "";
         }
      }
    }

    function SetState_cbQP2_1()
    {  
      if (document.frmDocumento.cbQP2_1.value > 0)
      {      
         document.frmDocumento.txtQP2_1_Outro.disabled = true;
         document.frmDocumento.txtQP2_1_Outro.style.backgroundColor = 'rgb(210, 210, 210)';
         document.frmDocumento.txtQP2_1_Outro.value = "";         
      }
      else
      {
         document.frmDocumento.txtQP2_1_Outro.disabled = false;
         document.frmDocumento.txtQP2_1_Outro.style.backgroundColor = 'rgb(255, 255, 255)';
      }
    }
    
    function SetState_chQP3_1()
    {
       if(document.frmDocumento.chQP3_1.checked == true)
       { 
         document.frmDocumento.txtQP3_1_Ano1.disabled   = false;
         document.frmDocumento.txtQP3_1_Ano2.disabled   = false;
         document.frmDocumento.txtQP3_1_Curso1.disabled = false;
         document.frmDocumento.txtQP3_1_Curso2.disabled = false;
         if (document.frmDocumento.txtQP3_1_Ano1.style)
         {
            document.frmDocumento.txtQP3_1_Ano1.style.backgroundColor   = 'rgb(255, 255, 255)';
            document.frmDocumento.txtQP3_1_Ano2.style.backgroundColor   = 'rgb(255, 255, 255)';
            document.frmDocumento.txtQP3_1_Curso1.style.backgroundColor = 'rgb(255, 255, 255)';
            document.frmDocumento.txtQP3_1_Curso2.style.backgroundColor = 'rgb(255, 255, 255)';
         }
       }
       else
       { 
         document.frmDocumento.txtQP3_1_Ano1.disabled   = true;
         document.frmDocumento.txtQP3_1_Ano2.disabled   = true;
         document.frmDocumento.txtQP3_1_Curso1.disabled = true;
         document.frmDocumento.txtQP3_1_Curso2.disabled = true;
         if (document.frmDocumento.txtQP3_1_Ano1.style)
         {
            document.frmDocumento.txtQP3_1_Ano1.style.backgroundColor   = 'rgb(210, 210, 210)';
            document.frmDocumento.txtQP3_1_Ano2.style.backgroundColor   = 'rgb(210, 210, 210)';
            document.frmDocumento.txtQP3_1_Curso1.style.backgroundColor = 'rgb(210, 210, 210)';
            document.frmDocumento.txtQP3_1_Curso2.style.backgroundColor = 'rgb(210, 210, 210)';
         }
       }
    }
        
    function SetState_cbQP4_12()
    {  
      if (document.frmDocumento.cbQP4_12.value == 0)
      {      
         document.frmDocumento.txtQP4_12_Outro.disabled = true;
         document.frmDocumento.txtQP4_12_Outro.style.backgroundColor = 'rgb(210, 210, 210)';
         document.frmDocumento.txtQP4_12_Outro.value = "";
      }
      else
      {
         document.frmDocumento.txtQP4_12_Outro.disabled = false;
         document.frmDocumento.txtQP4_12_Outro.style.backgroundColor = 'rgb(255, 255, 255)';
      }
    }
    
    function SetState_chQP5_10()
    {  
      if (document.frmDocumento.chQP5_10.checked == false)
      {      
         document.frmDocumento.txtQP5_10_Qual.disabled = true;
         document.frmDocumento.txtQP5_10_Qual.style.backgroundColor = 'rgb(210, 210, 210)';
         document.frmDocumento.txtQP5_10_Qual.value = "";         
      }
      else
      {
         document.frmDocumento.txtQP5_10_Qual.disabled = false;
         document.frmDocumento.txtQP5_10_Qual.style.backgroundColor = 'rgb(255, 255, 255)';
      }
    }

  function Verificar()
  {

    with (document.frmDocumento)
    {          
      if (cmbCurso.selectedIndex <= 0)
      {
        CaixaMSG("Tem de Seleccionar um Curso ! \n\n Erro ao Validar Campos ...", cmbCurso);
        return false;
      }
      
      if ((isEmpty(txtNome.value)) || (trim(txtNome.value) == ""))
      {
        CaixaMSG("Tem de Preencher o Seu Nome ! \n\n Erro ao Validar Campos ...", txtNome);
        return false;
      }   
      
      if ((isEmpty(txtDataNascimento.value)) || (! isDate(txtDataNascimento.value)))
      {
        CaixaMSG("Tem de Preencher a data ! \n\n Erro ao Validar Campos ...", txtDataNascimento);
        return false;
      }      
      
      if (dateCompare(txtDataNascimento.value, "01/01/1990") > 0)
      {
        CaixaMSG("Nasceu há muito pouco tempo ! \n\n Erro ao Validar Campos ...", txtDataNascimento);
        return false;
      }      
     
      if ((optSexo[0].checked == false) && (optSexo[1].checked == false))
      {
        CaixaMSG("Tem de Indicar o Sexo ! \n\n Erro ao Validar Campos ...", optSexo[0]);
        return false;
      }
      
      if ((isEmpty(txtMorada1.value)) || (trim(txtMorada1.value) == ""))
      {
        CaixaMSG("Tem de Preencher a Sua Morada ! \n\n Erro ao Validar Campos ...", txtMorada1);
        return false;
      }
      
      if ((isEmpty(txtCodPostal.value)) || (trim(txtCodPostal.value).length < 4))
      {
        CaixaMSG("Tem de Preencher o seu Código Postal ! \n\n Erro ao Validar Campos ...", txtCodPostal);
        return false;
      }
      
      if ((isEmpty(txtLocalidade.value)) || (trim(txtLocalidade.value) == ""))
      {
        CaixaMSG("Tem de Preencher a Localidade do Código Postal ! \n\n Erro ao Validar Campos ...", txtLocalidade);
        return false;
      }
			debugger          								 
      if ((cbNacionalidade.selectedIndex < 0) || ((!txtNacionalidade_Outra.disabled) && (isEmpty(txtNacionalidade_Outra.value))) )
      {
        CaixaMSG("Tem de Preencher a Nacionalidade ! \n\n Erro ao Validar Campos ...", cbNacionalidade);
        return false;
      }
       
      if (!  isPositiveNumber(txtNumeroBI.value))
      {
        CaixaMSG("Tem de Preencher o Bilhete de Identidade ! \n\n Erro ao Validar Campos ...", txtNumeroBI);
        return false;
      }
      
      if ((trim(txtDataBI.value) == "" ) || (!  isDate(txtDataBI.value )))
      {
        CaixaMSG("Tem de Preencher a Data de Identificação ! \n\n Erro ao Validar Campos ...", txtDataBI);
        return false;
      }
      
      var today = new Date();
      if (dateCompare(txtDataBI.value, AddZero(today.getDate()) + "/" + AddZero(today.getMonth()+1) + "/" + today.getFullYear()) > 0)
      {
        CaixaMSG("Data de Identificação superior ao Dia ! \n\n Erro ao Validar Campos ...", txtDataBI);
        return false;
      }
  
      if ((cbArquivoBI.selectedIndex < 0) || ((!txtArquivoBI_Outro.disabled) && (isEmpty(txtArquivoBI_Outro.value))))
      {
        CaixaMSG("Tem de Preencher o Arquivo de Identificacao ! \n\n Erro ao Validar Campos ...", cbArquivoBI);
        return false;
      }
      
      if (trim(txtNaturalidade.value) == "")
      {
        CaixaMSG("Tem de Preencher a sua Naturalidade ! \n\n Erro ao Validar Campos ...", txtNaturalidade);
        return false;
      }
      
      if (trim(txtFiliacaoPai.value) == "")
      {
        CaixaMSG("Tem de Preencher a Filiação (Pai) ! \n\n Erro ao Validar Campos ...", txtFiliacaoPai);
        return false;
      }
      
      if (trim(txtFiliacaoMae.value) == "")
      {
        CaixaMSG("Tem de Preencher a Filiação (Mãe) ! \n\n Erro ao Validar Campos ...", txtFiliacaoMae);
        return false;
      }
      
      if (cmbEstadoCivil.selectedIndex <= 0)
      {
        CaixaMSG("Tem de Seleccionar um Estado Civil ! \n\n Erro ao Validar Campos ...", cmbEstadoCivil);
        return false;
      }
      
      if (!  isPositiveNumber(txtTelefone.value))
      {
        CaixaMSG("Tem de preencher o Telefone Correctamente ! \n\n Erro ao Validar Campos ...", txtTelefone);
        return false;
      }
      
      if ((!isEmpty(txtTelemovel.value)) && (! isPositiveNumber(txtTelemovel.value)))
      {
        CaixaMSG("Tem de Preencher o Telemóvel Correctamente ! \n\n Erro ao Validar Campos ...", txtTelemovel);
        return false;
      }
      
      if ((!isEmpty(txtFax.value)) && (! isPositiveNumber(txtFax.value)))
      {
        CaixaMSG("Tem de Preencher o Fax Correctamente ! \n\n Erro ao Validar Campos ...", txtFax);
        return false;
      }
      
      if ((!isEmpty(txtContribuinte.value)) &&  (!  isNumeroContribuinte(txtContribuinte.value)))
      {
        CaixaMSG("Tem de Preencher o Contribuinte Correctamente ! \n\n Erro ao Validar Campos ...", txtContribuinte);
        return false;
      }
      
      if ((!isEmpty(txtEmail.value)) && (!isEmailValido(txtEmail.value)))
      {
        CaixaMSG("Correio Electrónico inválido ! \n\n Erro ao Validar Campos ...", txtEmail);
        return false;     
      }
      
      if (cmbGrau_Academico.selectedIndex <= 0)
      {
        CaixaMSG("Tem de Seleccionar um Grau Académico ! \n\n Erro ao Validar Campos ...", cmbGrau_Academico);
        return false;
      }
      
      if (trim(txtNomeEscola.value) == "")
      {
        CaixaMSG("Tem de Preencher o Nome da Escola  ! \n\n Erro ao Validar Campos ...", txtNomeEscola);
        return false;
      }
      
      if (trim(txtCursoEscola.value) == "")
      {
        CaixaMSG("Tem de preencher o Curso Que Frequentou  ! \n\n Erro ao Validar Campos ...", txtCursoEscola);
        return false;
      }
      
      if (cmbGrau_Academico.value == 4)
      {
        if ((txtAnoFrequencia.value).length > 4) 
        {
          CaixaMSG("Tem de Preencher o Ano da Frequência Correctamente ! \n\n Erro ao Validar Campos ...", txtAnoFrequencia);
          return false;
        }
        if (!  isPositiveNumber(txtAnoFrequencia.value))
        {
          CaixaMSG("Tem de Preencher o Ano da Frequência Correctamente ! \n\n Erro ao Validar Campos ...", txtAnoFrequencia);
          return false;
        }
        if ((txtAnosCurso.value).length > 2)
        {
          CaixaMSG("Tem de Preencher os Anos de Curso Correctamente ! \n\n Erro ao Validar Campos ...", txtAnosCurso);
          return false;
        }
        if (!  isPositiveNumber(txtAnosCurso.value))
        {
          CaixaMSG("Tem de Preencher os Anos de Curso Correctamente ! \n\n Erro ao Validar Campos ...", txtAnosCurso);
          return false;
        }
      }
      else
      {
        if ((txtAnoConclusao.value).length != 4)
        {
          CaixaMSG("Tem de Preencher o Ano da Conclusão (4 Digitos) Correctamente ! \n\n Erro ao Validar Campos ...", txtAnoConclusao);
          return false;
        }
        if (!  isPositiveNumber(txtAnoConclusao.value))
        {
          CaixaMSG("Tem de Preencher o Ano da Conclusão Correctamente ! \n\n Erro ao Validar Campos ...", txtAnoConclusao);
          return false;
        }
        if (cmbNotaFinal.selectedIndex <= 0)
        {
          CaixaMSG("Tem de Seleccionar a Nota Final ! \n\n Erro ao Validar Campos ...", cmbNotaFinal);
          return false;
        }
      }
      
      if ((!isEmpty(txtTelefoneEmprego.value)) && (!isPositiveNumber(txtTelefoneEmprego.value)))
      {
        CaixaMSG("Tem de Preencher o Telefone do Emprego Correctamente ! \n\n Erro ao Validar Campos ...", txtTelefoneEmprego);
        return false;
      }
      
      if ((!isEmpty(txtFaxEmprego.value)) && (!isPositiveNumber(txtFaxEmprego.value)))
      {
        CaixaMSG("Tem de Preencher o Fax do Emprego Correctamente ! \n\n Erro ao Validar Campos ...", txtFaxEmprego);
        return false;
      }
      
      if ((!isEmpty(txtContribuinteEmpresa.value)) && (!isPositiveNumber(txtContribuinteEmpresa.value)))
      {
        CaixaMSG("Tem de Preencher o Numero de Contribuinte da Empresa Correctamente ! \n\n Erro ao Validar Campos ...", txtContribuinteEmpresa);
        return false;
      }
      
      if (!isEmpty(txtQP3_1_Ano1.value) && (!isPositiveNumber(txtQP3_1_Ano1.value)))
      {
        CaixaMSG("Tem de Preencher o Ano do Curso Correctamente ! \n\n Erro ao Validar Campos ...", txtQP3_1_Ano1);
        return false;
      }
      
      if (!isEmpty(txtQP3_1_Ano2.value) & (!isPositiveNumber(txtQP3_1_Ano2.value)))
      {
        CaixaMSG("Tem de Preencher o Ano do Curso Correctamente ! \n\n Erro ao Validar Campos ...", txtQP3_1_Ano2);
        return false;
      }
         
    }

    return true;
  }
  
    function VerificarMail()
  {
    with (document.frmDocumento)
    {    
      if (isEmpty(txtNome.value) || (trim(txtNome.value).length == 0))
      {
        CaixaMSG("Tem de preencher o seu Nome ! \n\n Erro ao Validar Campos ...", txtNome);
        return false;
      }
      
      if (isEmpty(txtEmail.value) || (trim(txtEmail.value).length == 0))
      {
        CaixaMSG("Tem de preencher o seu Correio Electrónico ! \n\n Erro ao Validar Campos ...", txtEmail);
        return false;
      }

      if (!isEmailValido(txtEmail.value))
      {
        CaixaMSG("Correio Electrónico inválido ! \n\n Erro ao Validar Campos ...", txtEmail);
        return false;
      }

      if (cmbTipo_Mail.selectedIndex <= 0)
      {
        CaixaMSG("Tem de seleccionar um Tipo de Mailing ! \n\n Erro ao Validar Campos ...", cmbTipo_Mail);
        return false;
      }
    }
    return true; 
  }  
  
  function MarcarTodas(Sender, CodigoTipoTopico)
  {
    for (i = 0; i< 98; i++) // 98 e 99 são os elementos com outros
    {
      var ck = eval("document.frmDocumento.ck_" + CodigoTipoTopico + "_" + i)
      if (ck == null)
        continue;
      else
        ck.checked = Sender.checked;
    }
    return ;
  }
