<script language="JavaScript">
function focusField(obj)
{
obj.focus();
}

function refresh(step) {
// Processa:
// 0 = Limpa campos
// 1 = Inscrio
// 2 = Confirmao
// 3 = Correo
// 4 = Finalizao
// 5 = Gera Boleto

if ((step == 0) || (step == 1) || (step == 3))
   {
   formInscricao.action = "inscricao.asp?concurso=<%=Id_Concurso%>" ;
   }
if (step == 2)
   {
   formInscricao.action = "confirmacao.asp";
   }
if (step == 4)
   {
   formInscricao.action = "finalizacao.asp";
   }
   
formInscricao.step.value = step;
formInscricao.submit();

}

//################################################
//Implementaes efetuadas por Eliel em 09/09/2002
//Confirm if like you clear fields
//################################################

function fun_clear_fields() {

 //open_windows();
 if (confirm ("Deseja realmente limpar os campos?")) {
  refresh(0);
 } 

}

function open_windows() {
 Jan1 = open("","JanSecund","scrollbars=no,top=400,left=280,resizable=1,width=250,height=100");
 Jan1.document.open();
 Jan1.document.write("<HEAD><TITLE>Aviso...</TITLE></HEAD><body text=black bgcolor=''><center><P>Deseja limpar os campos agora?.</p><center><FORM id=form1 name=form1><input type='button' value='Sim' onclick='window.close()' id='button'1 name='button'1></FORM></center>")
 Jan1.document.close()
}

//################################################
//Implementaes efetuadas por Eliel em 29/08/2002
//Valida se uma data esta correta e ano bissexto
//################################################
// Ex.: valid_data("17", "08", "1966")
//################################################

function valid_day(dd,mm,yy) {

 //verify if day is not null
 if (dd == "") {
  message(5);
  formInscricao.cmbDataNascDia.focus(); 
 } else
  valid_date(dd,mm,yy);
  
}

function valid_date(dd,mm,yy) {

 seq = 0;
 //verify day, mother and year is not null
 if ((mm > 0) & (yy > 0) & (dd > 0)) {
  //verifica a validade do ms digitado
  if (mm < 13) { 
   //verifica a validade do ano digitado
   if (yy > 1879) { 
    //verifica se o ms  fevereiro ou no
    if (mm == 2) {
     //verifica se o ano  bissexto ou no
     if (bissexto(yy) == 0) {
      ab = 29;
     } else {
      ab = 28;
     }
    } else {
    
     //Atribui 30 ou 31 para verificao do dia
     if ((mm == 4) | (mm == 6) | (mm == 9) | (mm == 11))  { 
      ab = 30;
     } else {
      ab = 31; 
     }
   
    } 
   } else {
    message(2); 
    seq = 1;
   }
  } else { 
   message(1); 
   seq = 1;
  }
  
  //Verifica sequencia de validao 
  if (seq == 0) {
    //verifica a validade do dia digitado
    if (dd <= ab) {
     //Verificao final concluda
     //alert(ab+"-"+dd+"/"+mm+"/"+yy);
    } else {
     formInscricao.cmbDataNascDia.value = "";
     formInscricao.cmbDataNascDia.focus(); 
     message(0);
    }
  }
 }

}

function bissexto(bi) {

 // resto = bi mod4;
 resto = (bi % 4);
 if (resto == 0) {
  // resto = 0 O ano  bissexto
  //message(3);
  return 0;
 } else {
  // resto <> 0 O ano NO  bissexto
  //message(4);
  return 1;
 }

}

//#################################################
// Implementaes efetuadas por Eliel em 17/09/2002
// Permite digitar somente numrico
//#################################################

function cpf_numeric(num) {

 var field = formInscricao.txtCPF;
 for(i=0; i < 11; i++) {
  if (num >= 0) {
   //alert("");
  } else {
   tam=num.length;
   field.value=num.substring(0, (tam-1));
   num=num.substring(0, (tam-1));
  }
 } 
}


//#################################################
// Implementaes efetuadas por Eliel em 30/08/2002
// Verifica se um CPF est correto
//#################################################

function verify_cpf(num) {

 var field = formInscricao.txtCPF;
 if (num == "") { 
  message(8);
  field.focus();
 } else {
  if (num.length < 10) {
   message(6);
   field.focus();
  } else {
   if (valid_cpf(num)!=0) {
    message(7);
    field.focus();
    field.select();
   } 
  }
 }

}

function valid_cpf(num) {

 n1=num.substring(0, 1);
 n2=num.substring(1, 2);
 n3=num.substring(2, 3);
 n4=num.substring(3, 4);
 n5=num.substring(4, 5);
 n6=num.substring(5, 6);
 n7=num.substring(6, 7);
 n8=num.substring(7, 8);
 n9=num.substring(8, 9);
 d1=(n9*2)+(n8*3)+(n7*4)+(n6*5)+(n5*6)+(n4*7)+(n3*8)+(n2*9)+(n1*10);
 d1=(11-(d1 % 11));
 if (d1>=10) 
  d1=0;
 d2=(d1*2)+(n9*3)+(n8*4)+(n7*5)+(n6*6)+(n5*7)+(n4*8)+(n3*9)+(n2*10)+(n1*11);
 d2=(11-(d2 % 11));
 if (d2>=10) 
  d2=0;
 calculado=d1+d2;
 g1=digitado=num.substring(9,10);
 g2=digitado=num.substring(10,11);
 digitado=(g1*1)+(g2*1);
 if (calculado==digitado) {
  return 0;
 } else {
  return 1;
 }

}

//#################################################
// Implementaes efetuadas por Eliel em 29/08/2002
// Verifica se um e-mail esta correto(digitao)
//#################################################

function valid_email() {

  //lowercase()
  var field = formInscricao.txtEmail;
  var str = field.value;
  if (window.RegExp) {
    var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
    var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
    var reg1 = new RegExp(reg1str);
    var reg2 = new RegExp(reg2str);
    if (!reg1.test(str) && reg2.test(str)) {
      //e-mail 'OK'
      formInscricao.enviar.focus();
      return true;
    } else {
      //if field.value is not null - dever ser preenchido corretamente
      if (field.value != "") {
        message(10);
        field.focus();
        field.select();
        return false;
      } else {
        //e-mail 'OK' - com alerta sobre e-mail em branco (incorreto)
        //message(9);
        formInscricao.enviar.focus();
        return true;
      }
    }
  } else {
    if(str.indexOf("@") >= 0)
      return true;
    message(10);  
    return false;
  }
  
}

//#################################################
// Implementaes efetuadas por Eliel em 03/09/2002
// Valida diversas mensagens do sistema
//#################################################

function message(op) {

 if (op == 0) {
  window.alert("O DIA est incorreto! Digite novamente.") 
 }
 if (op == 1) {
  window.alert("O MS est incorreto! Digite novamente.") 
 }
 if (op == 2) {
  window.alert("O ANO est incorreto! Digite novamente.") 
 }
 if (op == 3) {
  window.alert("Este ano  bissexto!") 
 }
 if (op == 4) {
  window.alert("Este ano NO  bissexto!") 
 }
 if (op == 5) {
  window.alert("Digite um DIA vlido!") 
 }
 if (op == 6) {
  window.alert("Digite um nmero vlido para seu CPF!") 
 }
 if (op == 7) {
  window.alert("Nmero de CPF INVLIDO... Confira o nmero digitado!") 
 }
 if (op == 8) {
  window.alert("Por favor digite o CPF.") 
 }
 if (op == 9) {
  window.alert("Por favor digite um e-mail!") 
 }
 if (op == 10) {
  window.alert("Seu e-mail est INCORRETO... Corrija e tente novamente!!!") 
 }
 if (op == 11) {
  window.alert("Por favor, selecione o Estado do Orgo Expedidor da Carteira de Identidade.") 
 }
 if (op == 100) {
  window.alert("PRIMEIRA opo de mensagem para teste...") 
 }
 if (op == 101) {
  window.alert("SEGUNDA opo de mensagem para teste...") 
 }

}

//#################################################
// Implementaes efetuadas por Eliel em 05/09/2002
// Valida a existncia de campos nulos
//#################################################

function valid_form() {

  var i=0;
  var rv=1;
  var st="";

  for(i=1; i<document.forms[0].elements.length; i++) {
    //exceptions fields 
    //txtDescricaoProvaEspecial, txtDDD, txtTelefone, txtEmail
    //index:8,26,27,28
    //or index:7,25,26,27
    //if ((i!=8) & (i!=26) & (i!=27) & (i!=28)) {
    if ((i!=7) & (i!=25) & (i!=26) & (i!=27)) {
      if (!document.forms[0].elements[i].value) 
        rv=0;
    } else {
      //if (i==8) {
      if (i==7) {
        //verify if the test is especial
        //if true: field is not null
        //if (formInscricao.elements[7].checked==false) {
        if (formInscricao.elements[6].checked==false) {
          if (!document.forms[0].elements[i].value) rv=0;
        }  
      }
    }
    //alert(formInscricao.elements[i].name + ": " + formInscricao.elements[i].value + " index:" + i);
  }

  if(rv==0) {
   
    for(i=0; i < document.forms[0].elements.length; i++) {
     if (document.forms[0].elements[i].value == "") {
      //exceptions fields 
      //txtDescricaoProvaEspecial, txtDDD, txtTelefone, txtEmail
      //index:8,26,27,28
      //or index:7,25,26,27
      //if ((i!=8) & (i!=26) & (i!=27) & (i!=28)) {
      if ((i!=7) & (i!=25) & (i!=26) & (i!=27)) {
       campo = document.forms[0].elements[i].name;
       
       if (campo=="txtNome") campo="Nome";
       if (campo=="txtFilhos") campo="Filhos";
       if (campo=="txtIdentidade") campo="Identidade";
       if (campo=="txtOrgaoIdent") campo="Orgado Identidade";
       if (campo=="txtCEP") campo="CEP";
       if (campo=="txtCPF") campo="CPF";
       if (campo=="txtRua") campo="Rua";
       if (campo=="txtCompl") campo="Complemento";
       if (campo=="txtBairro") campo="Bairro";
       if (campo=="txtCidade") campo="Cidade";
       if (campo=="cmbCargo") campo="Cargo";
       if (campo=="cmbVaga") campo="Vaga";
       if (campo=="cmbProva") campo="Prova";
       if (campo=="cmbDataNascDia") campo="Dia do Nascimento";
       if (campo=="cmbDataNascMes") campo="Ms do Nascimento";
       if (campo=="cmbDataNascAno") campo="Ano do Nascimento";
       if (campo=="cmbEstadoIdent") campo="Estado do Orgo Emissor da Identidade";
       if (campo=="cmbEstado") campo="Estado do Endereco";

       //add fields text
       if (document.forms[0].elements[i].type=="text") st = st + campo + ": " + document.forms[0].elements[i].value + "\n\n"; 
       //add fields combobox
       if(document.forms[0].elements[i].type=="select-one") st = st + campo + ": " + document.forms[0].elements[i].value + "\n\n"; 
      }
     }
    }
    alert(' necessrio o preenchimento deste(s) campo(s) obrigatrio(s).' + "\n" + "\n" + st); 
    
  } else {
    
    //for(i=0; i<document.forms[0].elements.length; i++) {
     //if(document.forms[0].elements[i].type=="text") st=st + document.forms[0].elements[i].name + ": " + document.forms[0].elements[i].value + "\n\n"; 
     //if(document.forms[0].elements[i].type=="combo") st=st + document.forms[0].elements[i].name + ": " + document.forms[0].elements[i].value + "\n\n"; 
    //}
    //if(confirm(st + "\nEsta(s) informaes esto corretas?")) document.forms[0].submit();
    
    //data completed
    refresh(2);
    
  }
  
}

//#################################################
// Implementaes efetuadas por Eliel em 30/08/2002
// Habilita/Desabilita campo descricao da prova
// especial para edio
//#################################################

function ena_des_field(vlr) {

 if (vlr == 0){ 
  formInscricao.txtDescricaoProvaEspecial.disabled = false;
  formInscricao.txtDescricaoProvaEspecial.disabled = false; 
  formInscricao.txtDescricaoProvaEspecial.focus();
 }

 if (vlr == 1){ 
  formInscricao.txtDescricaoProvaEspecial.disabled = true;
  formInscricao.txtDescricaoProvaEspecial.disabled = true; 
  formInscricao.txtDescricaoProvaEspecial.value = ""; 
  formInscricao.txtNome.focus();

 }
 
}

//#################################################
// Implementaes efetuadas por Eliel em 06/09/2002
// desabled or enabled fields to the find 'cep'
//#################################################

function control_field(vlr) {

  //desabled or enabled fields to the find 'cep'
  if (vlr==0) {
    formInscricao.txtRua.value="Buscando endereo, aguarde...";
    formInscricao.txtRua.disabled = true;
    formInscricao.txtBairro.value="Buscando bairro, aguarde...";
    formInscricao.txtBairro.disabled = true;
    formInscricao.txtCidade.value="Buscando cidade, aguarde...";
    formInscricao.txtCidade.disabled = true;
    //return object active (focus in the txtCompl)
    formInscricao.status==formInscricao.status+2;
    formInscricao.txtCompl.focus();
  } 
  
}

//#################################################
// Implementaes efetuadas por Eliel em 09/09/2002
// modify string lowercase to uppercase
// fld(field name), str(string value), and  
// st(status to 0-lowercase and 1-uppercase)
//#################################################

function fun_upper_lower_case(fld,str,st) {

  var field = fld;
  if (st==0) {
   field.value=str.toLowerCase();
  } else {
   field.value=str.toUpperCase();
  }

}

//#################################################
// Implementaes efetuadas por Eliel em 10/09/2002
// modify string to number
// fld(field name), str(string value), and  
// st(status to 0-optional and 1-optional)
//#################################################

function fun_numeric(fld,str,st) {
 
  var field = fld;
  n1=str.substring(0, 1);
  n2=str.substring(1, 2);
  if ((n1>=0)&(n1<=9)){
    if (!parseInt(n2)) {
      if (parseInt(n2)!=0)
        field.value=n1+"";
    }
  }  
  if (!parseInt(n1)) {
    if (parseInt(n1)!=0)
      field.value="";
  }
  if (field.value == "")
    field.value = 0;

}

</script>
