// JavaScript Document
function mostra(){
	
	// PESSOA JURIDICA
	if(document.getElementsByName("pessoa")[1].checked == true){
		
		// esconde e esvazia campos pessoa fisica
		document.getElementById('nome').alt='';
		document.getElementById('cpf').alt='';	
		document.getElementById('nome').value='';
		document.getElementById('cpf').value='';
		document.getElementById('F').style.display='none';
		
		// mostra campos pessoa juridica
		document.getElementById('J').style.display='block';	
		document.getElementById('razao').alt='blank';
		document.getElementById('contato').alt='blank';
		document.getElementById('cnpj').alt='blank';

		
		
	}
	
	// PESSOA FISICA
	if(document.getElementsByName("pessoa")[0].checked == true){
		
		// esconde, e limpa campos pessoa juridica
		document.getElementById('razao').alt='';
		document.getElementById('contato').alt='';
		document.getElementById('cnpj').alt='';
		document.getElementById('razao').value='';
		document.getElementById('contato').value='';
		document.getElementById('cnpj').value='';		
		document.getElementById('J').style.display='none';	
		
		// mostra campos pessoa fisica
		document.getElementById('F').style.display='block';	
		document.getElementById('nome').alt='blank';
		document.getElementById('cpf').alt='blank';
	}

}



function enviar(){
	if(validateForm(document.getElementById('form1'))){
	document.getElementById('form1').target="_top";
	document.getElementById('form1').submit();
	}
}


//----------------------------------------------------------------------
	function i_ajax_mail(valor) {
		if(document.getElementById('email').value!=""){
			document.getElementById("msg").innerHTML = '...Verificando disponibilidade';
		}
		x_ajax_mail(valor, do_ajax_mail);
	}

	// funcao que retorna o valor para o <div>
	function do_ajax_mail(valor_retornado) {
	//meu_array=valor_retornado.split("|")
		if(valor_retornado == "1"){
			document.getElementById("msg").innerHTML = 'NÃO disponível, escolha outro.';
			document.getElementById('email').value='';
			document.getElementById('email').focus();
		}else{
			document.getElementById("msg").innerHTML = '';	
		}
	}
//----------------------------------------------------------------------

function valida_cpf(){
	// CPF
	if(document.getElementById('cpf').value!=""){
		if(isCpf(document.getElementById('cpf').value) == false){
		alert('CPF inválido!\n\nSomente números, sem pontos ou traços, 11 posições');
		document.getElementById('cpf').value='';
		document.getElementById('cpf').focus();
		return false
		}
	}
}

function valida_cnpj(){
	// CPF
	if(document.getElementById('cnpj').value!=""){
		if(isCnpj(document.getElementById('cnpj').value) == false){
		alert('CNPJ inválido!\n\nSomente números, sem pontos ou traços, 14 posições');
		document.getElementById('cnpj').value='';
		document.getElementById('cnpj').focus();
		return false
		}
	}
}
