
//Combo dinâmico para estado/cidade
function Dados(valor) {
      //verifica se o browser tem suporte a ajax
	  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;
            }
         }
      }
	  //se tiver suporte ajax
	  if(ajax) {
	     //deixa apenas o elemento 1 no option, os outros são excluídos
		 document.forms[0].listCidades.options.length = 1;
	     
		 idOpcao  = document.getElementById("opcoes");
		 
	     ajax.open("GET", "../config/cidade.asp", true);
		 ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		 
		 ajax.onreadystatechange = function() {
            //enquanto estiver processando...emite a msg de carregando
			if(ajax.readyState == 1) {
			   idOpcao.innerHTML = "carregando...";   
	        }
			//após ser processado - chama função processXML que vai varrer os dados
            if(ajax.readyState == 4 ) {
			   if(ajax.responseXML) {
			      processXML(ajax.responseXML);
			   }
			   else {
			       //caso não seja um arquivo XML emite a mensagem abaixo
				   idOpcao.innerHTML = "--";
			   }
            }
         }
		 //passa o código do estado escolhido
	     var params = "estado="+valor;
         ajax.send(params);
      }
   }
   
   function processXML(obj){
      //pega a tag cidade
      var dataArray   = obj.getElementsByTagName("cidade");
      
	  //total de elementos contidos na tag cidade
	  if(dataArray.length > 0) {
	     //percorre o arquivo XML paara extrair os dados
         for(var i = 0 ; i < dataArray.length ; i++) {
            var item = dataArray[i];
			//contéudo dos campos no arquivo XML
			var codigo    =  item.getElementsByTagName("codigo")[0].firstChild.nodeValue;
			var descricao =  item.getElementsByTagName("descricao")[0].firstChild.nodeValue;
			
	        idOpcao.innerHTML = "--";
			
			//cria um novo option dinamicamente  
			var novo = document.createElement("option");
			    //atribui um ID a esse elemento
			    novo.setAttribute("id", "opcoes");
				//atribui um valor
			    novo.value = codigo;
				//atribui um texto
			    novo.text  = descricao;
				//finalmente adiciona o novo elemento
				document.forms[0].listCidades.options.add(novo);
		 }
	  }
	  else {
	    //caso o XML volte vazio, printa a mensagem abaixo
		idOpcao.innerHTML = "--";
	  }	  
   }



//-------------------------------------------**--------------------------------------


function txtBoxFormat(objForm, strField, sMask, evtKeyPress) {
var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

if(document.all) { // Internet Explorer
    nTecla = evtKeyPress.keyCode;
} else if(document.layers) { // Nestcape
    nTecla = evtKeyPress.which;
} else {
    nTecla = evtKeyPress.which;
    if (nTecla == 8) {
        return true;
    }
}

sValue = objForm[strField].value;
// Limpa todos os caracteres de formatação que
// já estiverem no campo.
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( " ", "" );
sValue = sValue.toString().replace( " ", "" );
fldLen = sValue.length;
mskLen = sMask.length;

i = 0;
nCount = 0;
sCod = "";
mskLen = fldLen;

while (i <= mskLen) {
bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ":") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

if (bolMask) {
    sCod += sMask.charAt(i);
    mskLen++;
} else {
    sCod += sValue.charAt(nCount);
    nCount++;
}
i++;
}

objForm[strField].value = sCod;
if (nTecla != 8) { // backspace
    if (sMask.charAt(i-1) == "9") { // apenas números...
    return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
else { // qualquer caracter...
    return true;
}
} else {
    return true;
}
}

//Fim da Função Máscaras Gerais

/***
* AUTO TAB - ao prencher o campo, automaticamente manda o foco para o próximo!
***/
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 da Função AutoTab


//----------------------------------------------xx------------------------------------------------


//Validação de CEP
function valida_cep( CEP ) {
	if ( CEP.length != 9 ) return true;
	if ( CEP.indexOf("-" )!= 5 ) return true;
	for ( var i = 0; i < CEP.length ; i++ ) {
		if ( CEP.substring(i, i+1) >= '0' && CEP.substring(i, i+1) <= '9'  ) {		
			if ( i == 5 ) return true;
		}
		else { 
			if ( i != 5 )  return true;
		}
	}
	return false;
}


//----------------------------------------------xx------------------------------------------------


//Validação de CNPJ
function validaCNPJ() {
                CNPJ = document.validacao.CNPJID.value;
                erro = new String;
                if (CNPJ.length < 18) erro += "É necessario preencher corretamente o número do CNPJ! \n\n";
                if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){
                if (erro.length == 0) erro += "É necessário preencher corretamente o número do CNPJ! \n\n";
                }
                //substituir os caracteres que não são números
              if(document.layers && parseInt(navigator.appVersion) == 4){
                      x = CNPJ.substring(0,2);
                      x += CNPJ. substring (3,6);
                      x += CNPJ. substring (7,10);
                      x += CNPJ. substring (11,15);
                      x += CNPJ. substring (16,18);
                      CNPJ = x;
              } else {
                      CNPJ = CNPJ. replace (".","");
                      CNPJ = CNPJ. replace (".","");
                      CNPJ = CNPJ. replace ("-","");
                      CNPJ = CNPJ. replace ("/","");
               }
              var nonNumbers = /\D/;
              if (nonNumbers.test(CNPJ)) erro += "A verificação de CNPJ suporta apenas números! \n\n";
               var a = [];
               var b = new Number;
               var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
              for (i=0; i<12; i++){
                      a[i] = CNPJ.charAt(i);
                       b += a[i] * c[i+1];
 }
              if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
              b = 0;
              for (y=0; y<13; y++) {
                      b += (a[y] * c[y]);
              }
              if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
              if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){
                      erro +="Dígito verificador com problema!";
              }
              if (erro.length > 0){
                      alert(erro);
                      return false;
              } else {
                      alert("CNPJ valido!");
               }
              return true;

}

//----------------------------------------------xx------------------------------------------------


//Validação de e-mail
function valida_mail(valor) {
	prim = valor.indexOf("@")
	if(prim < 2) return false;
	if(valor.indexOf("@",prim + 1) != -1) return false
	if(valor.indexOf(".") < 1) return false;
	if(valor.indexOf("zipmeil.com") > 0) return false;
	if(valor.indexOf("hotmeil.com") > 0) return false;
	if(valor.indexOf(".@") > 0) return false;
	if(valor.indexOf("@.") > 0) return false;
	if(valor.indexOf(".com.br.") > 0) return false;
	if(valor.indexOf("/") > 0) return false;
	if(valor.indexOf("[") > 0) return false;
	if(valor.indexOf("]") > 0) return false;
	if(valor.indexOf("(") > 0) return false;
	if(valor.indexOf(")") > 0) return false;
	if(valor.indexOf("..") > 0) return false;
	if(valor.indexOf(",") > 0) return false;
	return true;

}


//----------------------------------------------xx------------------------------------------------


	function ValidaFormulario1() {

	
	if (document.frmAjax.nome.value==""){ 
		alert("Por favor, digite seu NOME.");
		document.frmAjax.nome.focus();
		return false;
	}
	
	
	if (document.frmAjax.sexo.value==""){ 
		alert("Por favor, escolha o SEXO.");
		document.frmAjax.sexo.focus();
		return false;
	}
	
	
	if (document.frmAjax.idade.value==""){ 
		alert("Por favor, digite sua IDADE.");
		document.frmAjax.idade.focus();
		return false;
	}
	
	
	if (document.frmAjax.endereco.value==""){ 
		alert("Por favor, digite o ENDEREÇO.");
		document.frmAjax.endereco.focus();
		return false;
	}
	
	
	if (document.frmAjax.bairro.value==""){ 
		alert("Por favor, digite o BAIRRO.");
		document.frmAjax.bairro.focus();
		return false;
	}
	
	
	if (document.frmAjax.listEstados.value==""){ 
		alert("Por favor, escolha o ESTADO.");
		document.frmAjax.listEstados.focus();
		return false;
	}
	
	
	if (document.frmAjax.listCidades.value==""){ 
		alert("Por favor, escolha a CIDADE.");
		document.frmAjax.listCidades.focus();
		return false;
	}	
	
	
	if (document.frmAjax.ddd1.value==""){ 
		alert("Por favor, digite o DDD.");
		document.frmAjax.ddd1.focus();
		return false;
	}
	
	
	if (document.frmAjax.telefone.value==""){ 
		alert("Por favor, digite o TELEFONE.");
		document.frmAjax.telefone.focus();
		return false;
	}


	if (document.frmAjax.email.value==""){ 
		alert("Por favor, digite seu E-MAIL.");
		document.frmAjax.email.focus();
		return false;
	}
	
	
	if (!valida_mail(document.frmAjax.email.value=="")){ 
		alert("Por favor, digite seu E-MAIL corretamente.");
		document.frmAjax.email.focus();
		return false;
	}

	if (document.frmAjax.vaga.value==""){ 
		alert("Por favor, escolha uma VAGA.");
		document.frmAjax.vaga.focus();
		return false;
	}
	
	
	
}

//-----------------------------------------**---------------------------------------


	function ValidaFormulario2() {

	
	if (document.form1.nome.value==""){ 
		alert("Por favor, digite seu NOME.");
		document.form1.nome.focus();
		return false;
	}
	
	if (document.form1.email.value==""){ 
		alert("Por favor, digite seu E-MAIL.");
		document.form1.email.focus();
		return false;
	}
	
	if (document.form1.setor.value==""){ 
		alert("Por favor, escolha o SETOR.");
		document.form1.setor.focus();
		return false;
	}	
	
	if (document.form1.mensagem.value==""){ 
		alert("Por favor, digite a MENSAGEM.");
		document.form1.mensagem.focus();
		return false;
	}
	
	
	
}

//-----------------------------------------**---------------------------------------

