// JavaScript Document
var contador, contador2, verificador;

function habilita() {
document.getElementById("nome").style.cssText = "z-index:1;";
document.getElementById("magaiver").style.cssText = "z-index:-1;";

}
function desabilita() {
document.getElementById("nome").style.cssText = "z-index:1;";
document.getElementById("magaiver").style.cssText = "z-index:2;";

}


	

contador = 0;
contador2 = 5;
contador3 = 10;
function inclui(campo) {
	if(campo == "n1") {
	document.getElementById("historico").style.display = '';
	newDiv = document.createElement("div");
	newDiv.setAttribute("id",contador);
	newDiv.innerHTML = "<table width='740' border='0' cellspacing='0' cellpadding='0'>"+
          "<tr>"+
"<td width='740' colspan=6 align='left'>-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------</td></tr>"+
            "<td width='60' align='left'>Empresa:</td>"+
"            <td width='186' align='left'><input name='empresa["+contador+"]' type='text' class='formulario' id='empresa[0]' size='27'></td>"+
"            <td width='52' align='left'>Cidade: </td>"+
"            <td width='170' align='left'><input name='cidade["+contador+"]' type='text' class='formulario' id='cidade[0]' size='25'></td>"+
"            <td width='42' align='left'>Cargo:</td>"+
"            <td width='230' align='left'><input name='cargo["+contador+"]' type='text' class='formulario' id='cargo[0]' size='41'></td>"+
"          </tr>"+
      "<tr>"+
        "<td colspan=\"6\" class=\"style1\"><table width=\"740\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"+
          "<tr>"+
            "<td colspan=\"2\" align=\"left\"><img src=\"images/space.gif\" height=\"6\"></td>"+
          "</tr>"+
          "<tr>"+
            "<td width=\"245\" align=\"left\">Descri&ccedil;&atilde;o das atividades desempenhadas:</td>"+
            "<td width=\"495\" align=\"left\"><input name=\"atividade[-1]\" type=\"text\" class=\"formulario\" id=\"atividade[-1]\" size=\"90\"></td>"+
            "</tr>"+
        "</table></td>"+
      "</tr>"+
"<tr><td colspan=6 width=740>"+
"<table width='740' border='0' cellspacing='0' cellpadding='0'>"+
"          <tr>"+
"            <td colspan=\"6\" align=\"left\"><img src=\"images/space.gif\" height=\"6\"></td>"+
"          </tr>"+
" <tr><td width='97' align='left'>Data da entrada :</td>"+
" <td width='150' align='left'><input name='entrada_dia["+contador+"]' type='text' class='formulario' size='1' onKeyUp='return autoTab(this, 2, event), somente_numero(this);'>"+
" / "+
"  <input name='entrada_mes["+contador+"]' type='text' class='formulario' size='1' onKeyUp='return autoTab(this, 2, event), somente_numero(this);'>"+
" / "+
"<input name='entrada_ano["+contador+"]' type='text' class='formulario' size='2' onKeyUp='return autoTab(this, 4, event), somente_numero(this);'></td>"+
            "<td width='75' align='left'>Data sa&iacute;da:</td>"+
            "<td width='147' align='left'><input name='saida_dia["+contador+"]' type='text' class='formulario' size='1' onKeyUp='return autoTab(this, 2, event), somente_numero(this);'>"+
" / "+
  "<input name='saida_mes["+contador+"]' type='text' class='formulario' size='1' onKeyUp='return autoTab(this, 2, event), somente_numero(this);'>"+
  " / "+
"<input name='saida_ano["+contador+"]' type='text' class='formulario' size='2' onKeyUp='return autoTab(this, 4, event), somente_numero(this);'></td>"+
"            <td width='94' align='left'>Motivo da sa&iacute;da: </td>"+
            "<td width='177' align='left'><input name='motivo_saida["+contador+"]' type='text' class='formulario' id='motivo_saida["+contador+"]' size='30'></td>"+		
"          </tr>"+
"</table></td></tr>"+
"        </table>";
	document.getElementById("primeiro").innerHTML = '<input type="button" value="Remover campos" class="formulario" onClick="retira(1)"><br>';
	contador = contador+1;
	document.getElementById("historico").insertBefore(newDiv);
	} else if(campo == "n2") {
	document.getElementById("cursos").style.display = '';
	newDiv = document.createElement("div");
	newDiv.setAttribute("id",contador2);
	newDiv.innerHTML = "<table width='740' border='0' cellspacing='0' cellpadding='0'>"+
		  "<tr>"+
          "  <td align='left' width=12 height=29>"+contador2+".</td>"+
		  "<td width=380><input name='curso["+contador2+"] type='text' class='formulario' size='62'></td>"+
		  "<td align='left' width=12>"+(contador2+1)+".</td>"+
"            <td width=100><input name='curso["+(contador2+1)+"]' type='text' class='formulario' size='62'></td>"+
"          </tr>"+
"        </table>";

	document.getElementById("segundo").innerHTML = '<input type="button" value="Remover campos" class="formulario" onClick="retira(2)"><br>';
	document.getElementById("cursos").insertBefore(newDiv);
	contador2 = contador2+2;
	} else if(campo == "n3") {
	document.getElementById("cursos_idioma").style.display = '';
	newDiv = document.createElement("div");
	newDiv.setAttribute("id",contador3);
	newDiv.innerHTML = "<table align=\"center\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">"+
          "<tbody>"+
            "<tr>"+
              "<td colspan=\"6\" align=\"left\"><img src=\"images/space.gif\" height=\"6\"></td>"+
            "</tr>"+
            "<tr>"+
              "<td width=\"7%\" class=\"style4\">Idioma:</td>"+
              "<td width=\"16%\"><input type=\"text\" class=\"formulario\" id=\"["+contador3+"]\" name=\"["+contador3+"]\" size=\"15\"></td>"+
              "<td width=\"13%\" class=\"style4\">Compreens&atilde;o:</td>"+
              "<td width=\"17%\"><select name=\"leitura3\" size=\"1\" class=\"formulario\" id=\"select\">"+
                  "<option selected=\"selected\"></option>"+
                  "<option value=\"B&aacute;sico\">B&aacute;sico</option>"+
                  "<option value=\"Intermedi&aacute;rio\">Intermedi&aacute;rio</option>"+
                  "<option value=\"Avan&ccedil;ado\">Avan&ccedil;ado</option>"+
                  "<option value=\"Fluente\">Fluente</option>"+
                "</select>              </td>"+
              "<td width=\"5%\" class=\"style4\">Fala:</td>"+
              "<td width=\"17%\"><select name=\"fala3\" size=\"1\" class=\"formulario\" id=\"fala3\">"+
                  "<option selected=\"selected\"></option>"+
                  "<option value=\"B&aacute;sico\">B&aacute;sico</option>"+
                  "<option value=\"Intermedi&aacute;rio\">Intermedi&aacute;rio</option>"+
                  "<option value=\"Avan&ccedil;ado\">Avan&ccedil;ado</option>"+
                  "<option value=\"Fluente\">Fluente</option>"+
                "</select>              </td>"+
              "<td width=\"7%\" class=\"style4\">Escrita:</td>"+
              "<td width=\"17%\"><select name=\"escrita3\" size=\"1\" class=\"formulario\" id=\"select3\">"+
                  "<option selected=\"selected\"></option>"+
                  "<option value=\"B&aacute;sico\">B&aacute;sico</option>"+
                  "<option value=\"Intermedi&aacute;rio\">Intermedi&aacute;rio</option>"+
                  "<option value=\"Avan&ccedil;ado\">Avan&ccedil;ado</option>"+
                  "<option value=\"Fluente\">Fluente</option>"+
                "</select>              </td>"+
            "</tr>"+
         " </tbody>"+
        "</table>";

	document.getElementById("terceiro").innerHTML = '<input type="button" value="Remover campos" class="formulario" onClick="retira(3)"><br>';
	document.getElementById("cursos_idioma").insertBefore(newDiv);
	contador3 = contador3+2;		
	}
		
}
function retira(campo2) {
	if(campo2 == 1) {
		contador = contador-1;
		if(contador < 1) {
			document.getElementById("primeiro").innerHTML = '';
		} 
		var d = document.getElementById("historico");
		var velho = document.getElementById(contador);
		d.removeChild(velho);
	} else if(campo2 == 2) {
		contador2 = contador2-2;
		if(contador2 <= 5) {
			document.getElementById("segundo").innerHTML = '';
		} 
		var d = document.getElementById("cursos");
		var velho = document.getElementById(contador2);
		d.removeChild(velho);	
	} else if(campo2 == 3) {
		contador3 = contador3-2;
		if(contador3 <= 10) {
			document.getElementById("terceiro").innerHTML = '';
		} 
		var d = document.getElementById("cursos_idioma");
		var velho = document.getElementById(contador3);
		d.removeChild(velho);			
	}
}
verificador = '1';
function fecha_campos() {
	if(verificador == '2') {
	document.frmAjax.empresa0.disabled = false;
	document.frmAjax.empresa0.style.background = "FFFFFF";
	document.frmAjax.cargo0.disabled = false;
	document.frmAjax.cargo0.style.background = "FFFFFF";
	document.frmAjax.cidade0.disabled = false;
	document.frmAjax.cidade0.style.background = "FFFFFF";
	document.frmAjax.entrada_dia0.disabled = false;
	document.frmAjax.entrada_dia0.style.background = "FFFFFF";	
	document.frmAjax.entrada_mes0.disabled = false;
	document.frmAjax.entrada_mes0.style.background = "FFFFFF";	
	document.frmAjax.entrada_ano0.disabled = false;	
	document.frmAjax.entrada_ano0.style.background = "FFFFFF";	
	document.frmAjax.saida_ano0.disabled = false;	
	document.frmAjax.saida_ano0.style.background = "FFFFFF";	
	document.frmAjax.saida_mes0.disabled = false;	
	document.frmAjax.saida_mes0.style.background = "FFFFFF";	
	document.frmAjax.saida_dia0.disabled = false;	
	document.frmAjax.saida_dia0.style.background = "FFFFFF";	
	document.frmAjax.motivo_saida0.disabled = false;
	document.frmAjax.motivo_saida0.style.background = "FFFFFF";	
	document.frmAjax.incluir.disabled = false;	
		for(contador; contador>0; contador-1) {
			retira(1);
		}
	verificador = '1';
	} else {
	document.frmAjax.empresa0.disabled = true;
	document.frmAjax.empresa0.style.background = "D5D5D5";
	document.frmAjax.cargo0.disabled = true;
	document.frmAjax.cargo0.style.background = "D5D5D5";
	document.frmAjax.cidade0.disabled = true;
	document.frmAjax.cidade0.style.background = "D5D5D5";
	document.frmAjax.entrada_dia0.disabled = true;
	document.frmAjax.entrada_dia0.style.background = "D5D5D5";	
	document.frmAjax.entrada_mes0.disabled = true;
	document.frmAjax.entrada_mes0.style.background = "D5D5D5";	
	document.frmAjax.entrada_ano0.disabled = true;	
	document.frmAjax.entrada_ano0.style.background = "D5D5D5";	
	document.frmAjax.saida_ano0.disabled = true;	
	document.frmAjax.saida_ano0.style.background = "D5D5D5";	
	document.frmAjax.saida_mes0.disabled = true;	
	document.frmAjax.saida_mes0.style.background = "D5D5D5";	
	document.frmAjax.saida_dia0.disabled = true;	
	document.frmAjax.saida_dia0.style.background = "D5D5D5";	
	document.frmAjax.motivo_saida0.disabled = true;
	document.frmAjax.motivo_saida0.style.background = "D5D5D5";	
	document.frmAjax.incluir.disabled = true;	
	document.getElementById("primeiro").innerHTML = '';
	document.getElementById("historico").style.display = 'none';
	verificador = '2';
	document.getElementById("reg_cart").innerHTML = '<input name=nao_possui_reg_carteira type=checkbox id=nao_possui_reg_carteira onClick=fecha_campos(); checked> N&atilde;o possuo registro em minha carteira profissional!';
	}
}
function somente_numero(campo){
	var digits="0123456789"
	var campo_temp
	for (var i=0;i<campo.value.length;i++){
	  campo_temp=campo.value.substring(i,i+1)
	  if (digits.indexOf(campo_temp)==-1){
		    campo.value = campo.value.substring(0,i);
		    break;
	   }
	}
}
function submete () {
   if (checaCPF(document.frmAjax.cpf.value)) {
     document.getElementById("cpf2").style.display = 'none';
   }
	else {
	     document.getElementById("cpf2").style.display = '';
   }
 }

 function checaCPF (CPF) {
	 CPF = CPF.replace("-","");
     CPF = CPF.replace(".","");
	 CPF = CPF.replace(".","");
	 CPF = CPF.replace(".","");

	if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
		CPF == "22222222222" ||	CPF == "33333333333" || CPF == "44444444444" ||
		CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
		CPF == "88888888888" || CPF == "99999999999")
		return false;
	soma = 0;
	for (i=0; i < 9; i ++)
		soma += parseInt(CPF.charAt(i)) * (10 - i);
	resto = 11 - (soma % 11);
	if (resto == 10 || resto == 11)
		resto = 0;
	if (resto != parseInt(CPF.charAt(9)))
		return false;
	soma = 0;
	for (i = 0; i < 10; i ++)
		soma += parseInt(CPF.charAt(i)) * (11 - i);
	resto = 11 - (soma % 11);
	if (resto == 10 || resto == 11)
		resto = 0;
	if (resto != parseInt(CPF.charAt(10)))
		return false;
       //document.getElementById("cpf").innerHTML = '<font color=#FF0000>CPF Incorreto</font>';
	return true;
 }
<!-- Inicio auto tab
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode; 
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
input.form[(getIndex(input)+1) % input.form.length].focus();
}
function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
found = true;
else
index++;
return found;
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}
return true;
}
//  Fim auto tab -->
function Dados(valor) {
	  try {
         ajax = new ActiveXObject("Microsoft.XMLHTTP");
      } 
      catch(e) {
         try {
            ajax = new ActiveXObject("Msxml2.XMLHTTP");
         }
	     catch(ex) {
            try {
               ajax = new XMLHttpRequest();
            }
	        catch(exc) {
               alert("Esse browser não tem recursos para uso do Ajax");
               ajax = null;
            }
         }
      }
	  if(ajax) {
		 document.forms[0].listCidades.options.length = 1;
		 idOpcao  = document.getElementById("opcoes");
	     ajax.open("POST", "cidades.php", true);
		 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		 ajax.onreadystatechange = function() {
			if(ajax.readyState == 1) {
			   idOpcao.innerHTML = "Aguarde...!";
	        }
            if(ajax.readyState == 4 ) {
			   if(ajax.responseXML) {
			      processXML(ajax.responseXML);
			   }
			   else {
				   idOpcao.innerHTML = "Selecione o Estado";
			   }
            }
         }
	     var params = "estado="+valor;
         ajax.send(params);
      }
   }
   function processXML(obj){
      var dataArray   = obj.getElementsByTagName("cidade");
	  if(dataArray.length > 0) {
         for(var i = 0 ; i < dataArray.length ; i++) {
            var item = dataArray[i];
			var codigo    =  item.getElementsByTagName("codigo")[0].firstChild.nodeValue;
			var descricao =  item.getElementsByTagName("descricao")[0].firstChild.nodeValue;
	        idOpcao.innerHTML = "Selecione uma opção";
			var novo = document.createElement("option");
			    novo.setAttribute("id", "opcoes");
			    novo.value = codigo;
			    novo.text  = descricao;
				document.forms[0].listCidades.options.add(novo);
		 }
	  }
	  else {
		idOpcao.innerHTML = "Selecione o Estado";
	  }	  
   }

