// JavaScript Document
function validaCadastro(){
	var form	= document.getElementById('frmCadastro');
	var vc_erro = "";
	var vc_foco	= "";
	
	if(form.nomecompletoVC.value == ""){
		vc_erro += "- Digite o Nome Completo! \n";
		vc_foco = focusOnError(vc_foco,form.nomecompletoVC);
	}
	
	if(form.apelidoVC.value == ""){
		vc_erro += "- Informe Como prefere ser Chamado! \n";
		vc_foco = focusOnError(vc_foco,form.apelidoVC);
	}
	
	if(form.nascimentoDT.value == ""){
		vc_erro += "- Digite a data de Nascimento! \n";
		vc_foco = focusOnError(vc_foco,form.nascimentoDT);
	}
	
	if(form.rgVC.value == ""){
		vc_erro += "- Digite o RG! \n";
		vc_foco = focusOnError(vc_foco,form.rgVC);
	}
	
	if(form.telefone1VC.value == "" && form.telefone2VC.value == "" && form.telefone3VC.value == ""){
		vc_erro += "- Digite ao menos 1 telefone. \n"
		vc_foco = focusOnError(vc_foco,form.telefone1VC);
	}
	
	if (form.emailVC.value.length != 0) {
		vc_erro +=  verficaEmail(form.emailVC.value);
		vc_foco = focusOnError(vc_foco,form.emailVC);
	} else {
		vc_erro	+= "- Digite o E-MAIL.\n";
		vc_foco = focusOnError(vc_foco,form.emailVC);
	}
	
	if(vc_erro == ""){
		var botao = document.getElementById('btAtualizar');
		botao.disabled = true;
		botao.src = 'imagens/bt_20_off.gif';
		return true;
	}
	else{
		alert("Atenção! \n" + vc_erro);
		vc_foco.focus();
		return false;
	}
}


function focusOnError(vc_foco,campo){
	if(vc_foco == ""){
		vc_foco = campo
		return vc_foco;
	}
	else{
		return vc_foco;
	}
}

function temBlog(id_resposta) {
	if(id_resposta == 121)
		document.getElementById('div_pergunta_62').style.display = 'block';
	else
		document.getElementById('div_pergunta_62').style.display = 'none';	
}

function conhecerLugar(id_resposta) {
	if(id_resposta == 192){
		document.frm_cadastro.pergunta_90[2].checked = false;
		if(document.getElementById('vc_pergunta_90192').style.display == 'none'){
			document.getElementById('vc_pergunta_90192').style.display  = 'block';
		}else{
			document.getElementById('vc_pergunta_90192').style.display  = 'none';
			document.frm_cadastro.vc_pergunta_90192.value 				= '';
		}
	}else if(id_resposta == 193){
		document.frm_cadastro.pergunta_90[2].checked = false;
		if(document.getElementById('vc_pergunta_90193').style.display == 'none'){
				document.getElementById('vc_pergunta_90193').style.display  = 'block';
		}else{
				document.getElementById('vc_pergunta_90193').style.display  = 'none';
				document.frm_cadastro.vc_pergunta_90193.value 				= '';
		}
	}else{
				document.frm_cadastro.pergunta_90[0].checked = false;
				document.getElementById('vc_pergunta_90192').style.display  = 'none';
				document.frm_cadastro.vc_pergunta_90192.value	 			= '';
				document.frm_cadastro.pergunta_90[1].checked = false;				
				document.getElementById('vc_pergunta_90193').style.display  = 'none';
				document.frm_cadastro.vc_pergunta_90193.value 				= '';
	}
}


function muda(id_pergunta, id_resposta, id_resposta_correta){
	var tr_muda = document.getElementById('tr_'+id_pergunta);
	if(id_resposta == id_resposta_correta) {
		tr_muda.style.display = 'block';
		document.getElementById('pergunta_103').setAttribute('obrigatorio','1');
	} else {
		tr_muda.style.display = 'none';
		document.getElementById('pergunta_103').setAttribute('obrigatorio','0');
	}
}

function revistaOutras(){
	if(document.getElementById('vc_pergunta_89').style.display		== 'none'){
		document.getElementById('vc_pergunta_89').style.display 	=  'block';
		document.getElementById('vc_pergunta_89_campo').focus();
	} 
	else{
		document.getElementById('vc_pergunta_89').style.display 	=  'none';
		document.getElementById('vc_pergunta_89_campo').value		=	'';
	}
}


/********************************************************************************
'Desenvolvido em:		23/03/2006		Autor: 			PETERSON
'Atualização: 			23/03/2006		Alterado por: 	PETERSON

'Funcionalidade:	Limpar os chekBox que estiverem selecionados ao trocar a resposta mora com quem
'Utilizado por: 	formaclub/dadoscomplemento
'********************************************************************************/
function limpaCheckParentes(id_pergunta){

	var bxParentes = eval('document.getElementsByName("pergunta_'+id_pergunta+'")');
	for(cont=0;cont < bxParentes.length;cont++){
		bxParentes[cont].checked = false;
	}
}



function valida() {
	ar_perguntas = document.frm_cadastro.elements;
	var erro = false;

	for(j=0; j<ar_perguntas.length; j++) {

		if(ar_perguntas[j].type == "select-one") {
			if(ar_perguntas[j].value == null || ar_perguntas[j].value == "")  {
				if(ar_perguntas[j].name == "vc_pergunta_51"){
					if(document.frm_cadastro.pergunta_44[0].checked){
						erro = true;
						break;
					}
				} else {
					erro = true;
					break;
				}
			}
		} else if(ar_perguntas[j].type == "checkbox" || ar_perguntas[j].type == "radio") {
			if(!is_checked(eval("document.frm_cadastro."+ar_perguntas[j].name))) {
				if(ar_perguntas[j].name == "pergunta_61") {
					if(document.frm_cadastro.pergunta_48.value != 101) {
						break;
					}
				}
				erro = true;
				break;
			}
		}
	}
	if(erro) {
		alert('Todas as perguntas são obrigatórias.');
		return false;
	} else {
		return true;
	}
}

/********************************************************************************
'Desenvolvido em:		13/04/2006		Autor: 			PETERSON
'Atualização: 			13/04/2006		Alterado por: 	PETERSON

'Funcionalidade:	Verificar as perguntas que não foram preenchidas pelo usuário
'Utilizado por: 	formaclub/dadoscomplemento
'********************************************************************************/
function alertapergunta(){
	var arr_ids	= document.getElementById('id_perguntas').value.split('|');
		for(i=0;i<arr_ids.length;i++){
			var ok = false;
			// verifica se o tipo da caixa é "checkbox"
			if(document.getElementById('pergunta_'+arr_ids[i]).type == 'checkbox'){
				var campo = eval('document.all.pergunta_'+arr_ids[i]);
					//loop interno para verificar se a caixa possui valor
					for(j=0;j < campo.length;j++){
						if(campo[j].checked == true){
							ok = true;
						}
					}
					//verifica se a var "ok" é false caso esteja uma função verifica a pergunta pelo id e retorna o alerta de preenchimento
					if(ok == false){
						if(arr_ids[i] != 61){
							//função que mostra o alerta da pergunta
							valida_pergunta(arr_ids[i]);
							break;
						}
					}
			}
			//verifica se o tipo da caixa é "select-box"
			else if(document.getElementById('pergunta_'+arr_ids[i]).type == 'select-one'){
				var campo = eval('document.all.pergunta_'+arr_ids[i]);
					//loop interno para verificar se a caixa possui valor
					for(j=0;j < campo.length;j++){
						if(campo.options[j].selected == true){
							ok = true;
						}
					}
					//verifica se a var "ok" é false caso esteja uma função verifica a pergunta pelo id e retorna o alerta de preenchimento
					if(ok == false){
						//função que mostra o alerta da pergunta					
						valida_pergunta(arr_ids[i]);
						break;
					}
			}
			//condição que diz que a caixa é do tipo "radio"
			else{
				var campo = eval('document.all.pergunta_'+arr_ids[i]+'")');
					//loop interno para verificar se a caixa possui valor
					for(y=0;y < campo.length; y++){
						if(campo[y].checked == true){
							ok = true;
						}
					}
					//verifica se a var "ok" é false caso esteja uma função verifica a pergunta pelo id e retorna o alerta de preenchimento				
					if(ok == false){
						//função que mostra o alerta da pergunta					
						valida_pergunta(arr_ids[i]);
						break;
					}
	 		}
	}
	if(ok == true){
		return true;
	}
	else{
		return false;
	}
}

function botaoDinamico(){
	var botao = document.getElementById('btResponder');
	botao.disabled = true;
	botao.src = 'imagens/bt_20_off.gif'
}

// Função para verificar o funcionamento de formulario
// o onsubmit do formulario não funciona como o esperado
function verificarValidacaoFormulario() {
	if (validaFormulario('frm_cadastro')) {
		document.frm_cadastro.submit();
	}
}
