// JavaScript Document

<!-- =================================FUNÇÕES===========================================
function Mascara(src, mask){
	var len = src.value.length;
	var saida = mask.substring(0,1);
	var texto = mask.substring(len);
	if (texto.substring(0,1) != saida){src.value += texto.substring(0,1)};
	if (len>=mask.length) {src.value=src.value.substring(0,mask.length)};
}

function Valida_cpf(Objcpf) {
	var msg = true;
    var cpf = Objcpf;
    exp = /\.|\-/g
    cpf = cpf.toString().replace( exp, "" ); 
    var digitoDigitado = eval(cpf.charAt(9)+cpf.charAt(10));
    var soma1=0, soma2=0;
    var vlr =11;
    for(i=0;i<9;i++){
        soma1+=eval(cpf.charAt(i)*(vlr-1));
        soma2+=eval(cpf.charAt(i)*vlr);
        vlr--;
    }    
    soma1 = (((soma1*10)%11)==10 ? 0:((soma1*10)%11));
    soma2=(((soma2+(2*soma1))*10)%11);
    
    var digitoGerado=(soma1*10)+soma2;
    if(digitoGerado!=digitoDigitado){msg = false};
	return msg;
}

function Valida_cnpj(ObjCnpj) {
	var msg = true;
    var cnpj = ObjCnpj;
    var valida = new Array(6,5,4,3,2,9,8,7,6,5,4,3,2);
    var dig1= new Number;
    var dig2= new Number;
    exp = /\.|\-|\//g
    cnpj = cnpj.toString().replace( exp, "" ); 
    var digito = new Number(eval(cnpj.charAt(12)+cnpj.charAt(13)));
    for(i = 0; i<valida.length; i++){
        dig1 += (i>0? (cnpj.charAt(i-1)*valida[i]):0);    
        dig2 += cnpj.charAt(i)*valida[i];    
    }
    dig1 = (((dig1%11)<2)? 0:(11-(dig1%11)));
    dig2 = (((dig2%11)<2)? 0:(11-(dig2%11)));
    
    if(((dig1*10)+dig2) != digito){msg = false};
	return msg;
}

function jump_tel(de, para){
	if (de.length >= 2){
		para.focus();
	}
}
//===============================VALIDA FORMULARIOS===================================

function envia_form_cadastro(Form_CAD,url_proxima){
//****** fisica
	if (document[Form_CAD].pessoa_temp.value=="fisica"){
		  if (document[Form_CAD].nome.value == ""){
			document[Form_CAD].nome.focus();
			alert('Informe seu Nome !');
		  }
		  else if (document[Form_CAD].sexo.value == ""){
			document[Form_CAD].sexo.focus();
			alert('Informe seu Sexo !');
		  }
		  else if (document[Form_CAD].pais.value == "Brasil"){
				passo_2(Form_CAD,url_proxima);
			  }
		  else{
			passo_2(Form_CAD,url_proxima);
		  }
	}
//****** juridica	  
	else if (document[Form_CAD].pessoa_temp.value=="juridica"){
		  if (document[Form_CAD].razao.value == ""){
			document[Form_CAD].razao.focus();
			alert('Informe a Razão social !');
		  }
		  else if (document[Form_CAD].nome_contato.value == ""){
			document[Form_CAD].nome_contato.focus();
			alert('Informe corretamente um nome para contato !');
		  }
		  else if (document[Form_CAD].cnpj.value == ""){
			document[Form_CAD].cnpj.focus();
			alert('Informe seu número de CNPJ!');
		  }
		  else if (Valida_cnpj(document[Form_CAD].cnpj.value) == false){
			document[Form_CAD].cnpj.focus();
			alert('Informe corretamente o número do CNPJ !');
		  }
		  else if (document[Form_CAD].ie_isento.checked == false){
			if (document[Form_CAD].ie.value == "" || isNaN(document[Form_CAD].ie.value)==true){
			  document[Form_CAD].ie.focus();
			  alert('Informe seu número I.E.');
			}
		  }
		  else{
			passo_2(Form_CAD,url_proxima);
		  }
	}
}

function passo_2(Form_CAD2,url_proxima){
		

//****** D+	  
	if (document[Form_CAD2].email.value.match(/(\w+)@(.+)\.(\w+)$/) == null){
		document[Form_CAD2].email.focus();
		document[Form_CAD2].email.select();
	alert('Endereço de email inválido !');
	}
	else if(document[Form_CAD2].senha.value == "")
	{
		alert("Informe sua Senha!");
		document[Form_CAD2].senha.focus();
	}
	else if(document[Form_CAD2].conf_senha.value == "")
	{
		alert("Confirme sua Senha!");
		document[Form_CAD2].conf_senha.focus();
	}
	else if(document[Form_CAD2].senha.value != document[Form_CAD2].conf_senha.value)
	{
		alert("Senhas não Coincidem!");
		document[Form_CAD2].conf_senha.focus();
	}
//	else if (document[Form_CAD2].pais.value == "Brasil"){
//		if (document[Form_CAD2].cep.value == ""){
//			document[Form_CAD2].cep.focus();
//			alert('Informe seu cep !');
//		}
//		else{
//			document[Form_CAD2].action = url_proxima;
//			document[Form_CAD2].submit();
//		}
//	}
	else{
		document[Form_CAD2].action = url_proxima;
		document[Form_CAD2].submit();
	}
}


function envia_cadastro(Form_END){
	if (document[Form_END].endereco.value == ""){
	  document[Form_END].endereco.focus();
	  alert('Informe seu endereco !');
	}
	else if (document[Form_END].numero.value == "" || isNaN(document[Form_END].numero.value)==true){
		document[Form_END].numero.focus();
		alert('Informe o numero de sua residência !');
	}
	else if (document[Form_END].pais.value == "Brasil"){
		if (document[Form_END].bairro.value == ""){
			document[Form_END].bairro.focus();
			alert('Informe seu bairro !');
			}
		else if (document[Form_END].cidade.value == ""){
			document[Form_END].cidade.focus();
			alert('Informe sua cidade !');
		}
		else if (document[Form_END].estado.value == ""){
			document[Form_END].estado.focus();
			alert('Informe seu estado !');
		}
		else if (document[Form_END].telefone.value == ""){
			document[Form_END].telefone.focus();
			alert('Informe seu telefone !');
		}
		else{
			document[Form_END].submit();
		}
	}
	else if (document[Form_END].pais.value != "Brasil"){
		if (document[Form_END].cidade.value == ""){
			document[Form_END].cidade.focus();
			alert('Informe sua cidade !');
		}
		else if (document[Form_END].estado.value == ""){
			document[Form_END].estado.focus();
			alert('Informe seu estado !');
		}
		else if (document[Form_END].telefone.value == ""){
			document[Form_END].telefone.focus();
			alert('Informe seu telefone !');
		}
		else{
			document[Form_END].submit();
		}
	}
}

function envia_form_contato(Form_SAC){
	if (document[Form_SAC].area.value == ""){
		document[Form_SAC].area.focus();
		alert('Informe corretamente uma área !');
	}
	else if (document[Form_SAC].nome.value == ""){
		document[Form_SAC].nome.focus();
		alert('Informe corretamente um nome !');
	}
	else if (document[Form_SAC].email.value.match(/(\w+)@(.+)\.(\w+)$/) == null){
	  document[Form_SAC].email.focus();
	  document[Form_SAC].email.select();
	  alert('Endereço de email inválido !');
	}
	else if (document[Form_SAC].telefone.value == ""){
		document[Form_SAC].telefone.focus();
		alert('Informe corretamente o telefone !');
	}
	else if (document[Form_SAC].cidade.value == ""){
		document[Form_SAC].cidade.focus();
		alert('Informe corretamente a cidade !');
	}
	else if (document[Form_SAC].estado.value == ""){
		document[Form_SAC].estado.focus();
		alert('Informe corretamente o estado !');
	}
	else if (document[Form_SAC].mensagem.value == ""){
		document[Form_SAC].mensagem.focus();
		alert('Digite corretamente uma mensagem !');
	}
	else{
		document[Form_SAC].submit();
	}
}

function envia_form_DP(Form_DP){
	
	if (document[Form_DP].pessoaF.value=="1"){
		if (document[Form_DP].nome.value == ""){
			document[Form_DP].nome.focus();
			alert('Informe seu nome !');
		}
		else if (document[Form_DP].nascido.value == ""){
			document[Form_DP].nascido.focus();
			alert('Informe corretamente sua Data de Nascimento !');
		}
		else if (document[Form_DP].sexo.value == ""){
			document[Form_DP].sexo.focus();
			alert('Informe seu sexo !');
		}
		else if (document[Form_DP].rg.value == "" || isNaN(document[Form_DP].rg.value)==true){
			document[Form_DP].rg.focus();
			alert('Informe corretamente o número do RG !');
		}
/*		cpf
		else if (document[Form_DP].cpf.value == ""){
			document[Form_DP].cpf.focus();
			alert('Informe seu número de CPF !');
		}
		else if (Valida_cpf(document[Form_DP].cpf.value) == false){
			document[Form_DP].cpf.focus();
			alert('Informe corretamente o número do CPF !');
		}
*/		else{
			passo_2DP(Form_DP);
		}
		
	}
	else if (document[Form_DP].pessoaF.value=="0"){
		if (document[Form_DP].razao.value == ""){
			document[Form_DP].razao.focus();
			alert('Informe a razão social !');
		}
		else if (document[Form_DP].nome_contato.value == ""){
			document[Form_DP].nome_contato.focus();
			alert('Informe o nome contato !');
		}
		else if (document[Form_DP].cnpj.value == "" || isNaN(document[Form_DP].cnpj.value)==true){
			document[Form_DP].cnpj.focus();
			alert('Informe seu número de CNPJ!');
		}
		else if (checa_cnpj_heth(document[Form_DP].cnpj.value) == false){
			document[Form_DP].cnpj.focus();
			alert('Informe corretamente o número do CNPJ !');
		}
		else if (document[Form_DP].ie_isento.checked == false){
			if (document[Form_DP].ie.value == "" || isNaN(document[Form_DP].ie.value)==true){
				document[Form_DP].ie.focus();
				alert('Informe seu número I.E.');
			}
		}
		else{
			passo_2DP(Form_DP);
		}
	}
}

function passo_2DP(Form_DP2){
	x=0
	if (document[Form_DP2].email.value.match(/(\w+)@(.+)\.(\w+)$/) == null){
		document[Form_DP2].email.focus();
		document[Form_DP2].email.select();
		alert('Endereço de email inválido !');
		x=1
	}
	else{
	 if (document[Form_DP2].nova_senha.value != "" && document[Form_DP2].nova_senha.value.length < 4){
		document[Form_DP2].nova_senha.focus();
		alert('Mínimo 4 caracteres !');
		x=1
	}else {
	 if (document[Form_DP2].nova_senha.value != document[Form_DP2].confirma_senha.value){
		document[Form_DP2].confirma_senha.focus();
		alert('Senhas não conferem !');
		x=1
	}else{
		if (x==0){
		document[Form_DP2].submit();}
	}
	}
}
}

//=======================================================================================================

function env_amigo(formx){
	if (document.getElementById(formx).email.value.match(/(\w+)@(.+)\.(\w+)$/) == null){
		document.getElementById(formx).email.focus();
		document.getElementById(formx).email.select();
		alert('Endereço de email inválido !');
	}
	else if (document.getElementById(formx).nome.value == "" || document.getElementById(formx).nome.value.length < 2){
		document.getElementById(formx).nome.focus();
		alert('Digite Corretamente o nome!');
	}

	else{
		document[formx].submit();
	}
}



function checa_cpf_heth(CPF) {
	var msg = true;
	if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
	  CPF == "22222222222" ||	CPF == "33333333333" || CPF == "44444444444" ||
	  CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
	  CPF == "88888888888" || CPF == "99999999999")
	msg = false;
	soma = 0;
	for (y=0; y < 9; y ++)
	soma += parseInt(CPF.charAt(y)) * (10 - y);
	resto = 11 - (soma % 11);
	if (resto == 10 || resto == 11)resto = 0;
	if (resto != parseInt(CPF.charAt(9)))
	  msg = false; soma = 0;
	for (y = 0; y < 10; y ++)
	  soma += parseInt(CPF.charAt(y)) * (11 - y);
	resto = 11 - (soma % 11);
	if (resto == 10 || resto == 11) resto = 0;
	if (resto != parseInt(CPF.charAt(10)))
	  msg = false;
	return msg;
}

function checa_cnpj_heth(s) {
	var msg = true;
	var y;
	var c = s.substr(0,12);
	var dv = s.substr(12,2);
	var d1 = 0;
	for (y = 0; y < 12; y++)
	{
	d1 += c.charAt(11-y)*(2+(y % 8));
	}
	if (d1 == 0) msg = false;
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1)msg = false;
	d1 *= 2;
	for (y = 0; y < 12; y++)
	{
	d1 += c.charAt(11-y)*(2+((y+1) % 8));
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1) msg = false;
	return msg;
}

function dataproximo(de, para){
	if (de.length == 2){
		para.focus();
	}
}
function campoCEP(valor){
	if (valor.value.length == 5){
		valor.value=valor.value+'-';
	}
}
function campoTEL(valor){
	if (valor.value.length == 4){
		valor.value=valor.value+'-';
	}
}
//-->