// Fabiano Coelho
// 12.04.2009

// Mod em 12.04.2009
// versao. 1.1
function delreg(question,reg)
{
	if ( question=="" ){ question="Realmente deseja remover este registro?" }
	
	if (confirm(question))			
	{
		document.location = "?delreg="+reg;
	}
}

function TO(user,domain)
{
	locationstring = "mailto:" + user + "@" + domain;
	window.location = locationstring;
}

function validaCad()
{
	var msg = "ERRO!\nPor favor, preencha o campo ";
	
	if ( document.form1.nome.value == '' ) { alert(msg +'Nome'); return false; }
	if ( document.form1.doc.value == '' ) { alert(msg +'CPF ou CNPJ'); return false; }
	if ( document.form1.cep.value == '' ) { alert(msg +'CEP'); return false; }
	if ( document.form1.endereco.value == '' ) { alert(msg +'Endereço'); return false; }
	if ( document.form1.numero.value == '' ) { alert(msg +'Número'); return false; }
	if ( document.form1.bairro.value == '' ) { alert(msg +'Bairro'); return false; }
	if ( document.form1.cidade.value == '' ) { alert(msg +'Cidade'); return false; }
	if ( document.form1.email.value == '' ) { alert(msg +'E-mail'); return false; }
	if ( document.form1.pacesso.value == '' ) { alert(msg +'Senha'); return false; }
	
	else { return true; }	
}

var submitted = false;

function currValida(senha)
{		
	var msg = "ERRO!\nPor favor, preencha o campo ";
	var doc = document.form1;
	
	if ( document.form1.nome.value == '' ) { alert(msg +'Nome'); doc.nome.focus(); return false; }
	if ( document.form1.email.value == '' ) { alert(msg +'E-mail'); doc.email.focus(); return false; }
	if (senha==1) { if ( document.form1.pacesso.value == '' ) { alert(msg +'Senha de acesso'); doc.pacesso.focus(); return false; } }
	if ( document.form1.cargo.value == '' ) { alert('ERRO!\nPor favor, escolha uma opção de Cargo desejado.'); doc.cargo.focus(); return false; }
	if ( document.form1.nasc_local.value == '' ) { alert(msg +'Local de Nascimento'); doc.nasc_local.focus(); return false; }
	if ( document.form1.nasc_uf.value == '' ) { alert(msg +'Local de Nascimento (UF)'); doc.nasc_uf.focus(); return false; }
	
	if ( document.form1.end_rua.value == '' ) { alert(msg +'Logradouro'); doc.end_rua.focus(); return false; }
	if ( document.form1.end_num.value == '' ) { alert(msg +'Número de sua casa'); doc.end_num.focus(); return false; }
	if ( document.form1.end_bairro.value == '' ) { alert(msg +'Bairro'); doc.end_bairro.focus(); return false; }
	if ( document.form1.end_cidade.value == '' ) { alert(msg +'Cidade'); doc.end_cidade.focus(); return false; }
	if ( document.form1.end_uf.value == '' ) { alert(msg +'UF'); doc.end_uf.focus(); return false; }
	if ( document.form1.end_cep.value == '' ) { alert(msg +'Seu CEP'); doc.end_cep.focus(); return false; }
	if ( document.form1.fone_ddd.value == '' ) { alert(msg +'DDD de seu Telefone'); doc.fone_ddd.focus(); return false; }
	if ( document.form1.telefone.value == '' ) { alert(msg +'Telefone'); doc.telefone.focus(); return false; }
	
	if ( document.form1.pai.value == '' ) { alert(msg +'Nome de seu Pai'); doc.pai.focus(); return false; }
	if ( document.form1.mae.value == '' ) { alert(msg +'Nome de sua Mãe'); doc.mae.focus(); return false; }
	
	if ( document.form1.cpf.value == '' ) { alert(msg +'Seu CPF'); doc.cpf.focus(); return false; }
	if ( document.form1.rg.value == '' ) { alert(msg +'Seu RG'); doc.rg.focus(); return false; }
	if ( document.form1.rg_expedicao.value == '' ) { alert(msg +'Data de Expedição'); doc.rg_expedicao.focus(); return false; }
	
	if ( document.form1.parentes_empresa.value == '' ) { alert('Por favor, escolha uma opção'); doc.parentes_empresa.focus(); return false; }
	if ( document.form1.amigos_empresa.value == '' ) { alert('Por favor, escolha uma opção'); doc.amigos_empresa.focus(); return false; }
	
	if ( document.form1.parentes_empresa.value == 1 && document.form1.nome_parente.value == '' ) { alert(msg +'Nome do parente'); doc.nome_parente.focus(); return false; }
	if ( document.form1.amigos_empresa.value == 1 && document.form1.nome_amigo.value == '' ) { alert(msg +'Nome do conhecido'); doc.nome_amigo.focus(); return false; }	
	
	else { 	
	document.form1.enviar.disabled = true;
	document.form1.enviar.value = 'Processando dados ... aguarde!'; return true; }
}

function validaLogin()
{
	var msg = "ERRO!\nPor favor, preencha o campo ";
	var doc = document.form1;
	
	if ( document.form1.cpf.value == '' ) { alert(msg +'Seu CPF'); doc.cpf.focus(); return false; }
	if ( document.form1.senha.value == '' ) { alert(msg +'Senha'); doc.senha.focus(); return false; }
	
	else { return true; }
}

function validaDoc()
{
	var docvar = document.form1.doc.value;
	//xajax.$('docResult').innerHTML = '';
	xajax_validaDoc(docvar);
	return false;
}

function validaEmail()
{
	var email = document.form1.email.value;
	//xajax.$('docResult').innerHTML = '';
	xajax_checaEmail(email);
	return false;
}

function spass()
{
	if ( document.form2.sendpass.value == '' ) 
	{ 
		alert('ERRO!\nPor favor, informe seu e-mail');
		return false;
	}
	else { 
		xajax_sendpass(xajax.getFormValues("form2"));
		//return true; 
		}	
}

function valida()
{
	if ( document.form1.email.value == '' || document.form1.senha.value == '' ) 
	{ 
		alert('ERRO!\nPor favor, informe e-mail e senha');
		return false;
	}
		else { return true; }	
}	

function validaCEP()
{
	if ( document.form3.cep.value == '' || document.form3.cepdigitos.value == '' ) 
	{ 
		alert('ERRO!\nPor favor, informe seu CEP');
		return false;
	}
		else { return true; }	
}	

function validaCurriculo()
{
	
	if ( document.form3.nome.value == '' ) 
	{ 
		document.form3.nome.focus();
		alert('ERRO!\nPor favor, informe seu Nome');
		return false;
	}
	
	if ( document.form3.cpf2.value == '' ) 
	{ 
		alert('ERRO!\nPor favor, informe seu CPF');
		document.form3.cpf2.focus();
		return false;
	}
	
	if ( document.form3.cep.value == '' || document.form3.cepdigitos.value == '' ) 
	{ 
		alert('ERRO!\nPor favor, informe seu CEP');
		return false;
	}
	
	else { return true; }	
}

function JumpCEP(objeto, jumpto)
{
	var obj = eval(objeto);
	var jumpto = eval(jumpto);
	
	if(obj.value.length == 5)
	{
		jumpto.focus();
	}
}


function formataCNPJ(campo) {  
   var valor = "";  
   var teste = campo.value;  
   for (var i = 1;i<=teste.length;i++) {  
       if (!isNaN(teste.charAt(i-1))) {  
           valor += teste.charAt(i-1);  
           if (valor.length ==2 | valor.length == 6 ) {  
               valor += ".";  
           }  
            if (valor.length == 10) {  
                valor += "/";  
            }  
            if (valor.length == 15) {  
                valor += "-";  
            }  
        }  
    }  
    campo.value=valor;  
}

function VerificaCPF(campo) {
var CPF = campo.value; // Recebe o valor digitado no campo

// Aqui começa a checagem do CPF
var POSICAO, I, SOMA, DV, DV_INFORMADO;
var DIGITO = new Array(10);
DV_INFORMADO = CPF.substr(9, 2); // Retira os dois últimos dígitos do número informado

// Desemembra o número do CPF na array DIGITO
for (I=0; I<=8; I++) {
  DIGITO[I] = CPF.substr( I, 1);
}

// Calcula o valor do 10º dígito da verificação
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];
}

// Calcula o valor do 11º dígito da verificação
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];
   }

// Verifica se os valores dos dígitos verificadores conferem
DV = DIGITO[9] * 10 + DIGITO[10];
   if (DV != DV_INFORMADO) {
      alert('CPF inválido');
      campo.value = '';
      campo.focus();
      return false;
   }
}


//// AJAX simples

function ajax()
{
    try {
        return new ActiveXObject("Microsoft.XMLHTTP");
    } catch(e) {
        try {
            return new ActiveXObject("Msxml2.XMLHTTP");
        } catch(ex) {
            try {
                return new XMLHttpRequest();
            } catch(exc) {
                alert("Esse browser nao tem recursos para uso do AJAX");
                return false;
            }
        }
    }
}

//// init contato ajax

ajax1 = new ajax;
function contato()
{	
    var nome  = document.getElementById("nome").value;
    var email = document.getElementById("email").value;
    var cep   = document.getElementById("cep").value +"-"+ document.getElementById("cepdigitos").value;	
	var fone  = document.getElementById("ddd").value +" - "+ document.getElementById("fone").value;
	var msg   = document.getElementById("msg").value;

    ajax1.open("POST", "_contato.php", true );
    ajax1.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    ajax1.send("nome="+nome+"&email="+email+"&cep="+cep+"&fone="+fone+"&msg="+msg);

	document.getElementById("left").innerHTML = "Por favor, aguarde...";

    ajax1.onreadystatechange = function() { 
        if (ajax1.readyState == 4) {
            document.getElementById("left").innerHTML = ajax1.responseText;
        } else {
            document.getElementById("left").innerHTML = "Por favor, aguarde...";
        }
    }
}

//// DW Stuff

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

////////

