/*
'********************************************************************************
'	Desenvolvido em:	16/05/2006  	Autor:    		RAFAEL FORTE
'	Atualizado em  :	14/08/2006		Autor:			RONI COSTA
'	Atualizado em  :	15/08/2006		Autor:			RONI COSTA
'	Atualizado em  :	29/06/2007		Autor:			RONI COSTA
'********************************************************************************
*/

/*# VERIFICAR #*/
function cadastroVerificar() {
	erroVC		= '';

	if (document.cadastroFRM.clienteVC.value.length == 0) {
	 	erroVC	= erroVC + '- Digite o NOME.\n';
	}
	
	if (document.cadastroFRM.apelidoVC.value.length == 0) {
	 	erroVC	= erroVC + '- Digite o COMO PREFERE SER CHAMADO.\n';
	}
	
	if (document.cadastroFRM.sexoN.value == 0) {
	 	erroVC	= erroVC + '- Selecione o SEXO.\n';
	}
		
	if (document.cadastroFRM.emailVC.value.length != 0) {
		invalidChars	= "/:,;!?<>*&^%$#(){}|~`"
		atPos			= document.cadastroFRM.emailVC.value.indexOf("@",1)
		periodPos		= document.cadastroFRM.emailVC.value.indexOf(".",atPos)
		
		for (i=0; i<invalidChars.lenght; i++) {
			badChar		= invalidChars.charAt(i)
			
			if (document.cadastroFRM.emailVC.value.length.indexOf(badChar,0) > -1) {
			 	erroVC = '- O E-MAIL informado não é válido. Por favor, verifique.\n';
			}
		}
		if (atPos == -1) {
			 erroVC	= '- O E-MAIL informado não é válido. Por favor, verifique.\n';
		}
		if(document.cadastroFRM.emailVC.value.indexOf("@",atPos+1) > -1) {
			 erroVC	= '- O E-MAIL informado não é válido. Por favor, verifique.\n';
		}
		if (periodPos == -1) {
			 erroVC	= '- O E-MAIL informado não é válido. Por favor, verifique.\n';
		}
		if ((periodPos+3) > document.cadastroFRM.emailVC.value.length) {
			 erroVC	= '- O E-MAIL informado não é válido. Por favor, verifique.\n';
		}
	} else {
		erroVC		= erroVC + '- Digite o E-MAIL.\n';
	}
		
	if (document.cadastroFRM.emailVC.value.length > 0 && (document.cadastroFRM.emailVC.value != document.cadastroFRM.email2VC.value)) {
	 	erroVC	= erroVC + '- O E-MAIL digitato é diferente do E-MAIL de confirmação.\n';
	}
	/* # VERIFICAÇÃO DESATIVADA EM 26-09-2006	
	if (document.cadastroFRM.loginVC.value.length < 6) {
	 	erroVC	= erroVC + '- Escolha um LOGIN com pelo menos 6 caracteres.\n';
	}
	*/
	if (document.cadastroFRM.senhaVC.value.length < 6) {
	 	erroVC	= erroVC + '- Escolha uma SENHA com pelo menos 6 caracteres.\n';
	}
		
	if (document.cadastroFRM.senhaVC.value.length > 0 && (document.cadastroFRM.senhaVC.value != document.cadastroFRM.senha2VC.value)) {
	 	erroVC	= erroVC + '- A SENHA CONFIRMADA não confere com a original.\n';
	}
	
	if (document.cadastroFRM.paisID.value == 0) {
	 	erroVC	= erroVC + '- Selecione o PAÍS.\n';
	}
	
	if (document.cadastroFRM.estadoID.value == -1) {
	 	erroVC	= erroVC + '- Selecione o ESTADO.\n';
	}
	
	if (document.cadastroFRM.estadoID.value == 0 && document.cadastroFRM.estadoVC.value.length == 0) {
	 	erroVC	= erroVC + '- Digite o ESTADO.\n';
	}
	
	if (document.cadastroFRM.cidadeID.value == -1) {
	 	erroVC	= erroVC + '- Selecione a CIDADE.\n';
	}
	
	if (document.cadastroFRM.cidadeID.value == 0 && document.cadastroFRM.cidadeVC.value.length == 0) {
	 	erroVC	= erroVC + '- Digite a CIDADE.\n';
	}
	
	if (document.cadastroFRM.enderecoVC.value.length == 0) {
	 	erroVC	= erroVC + '- Digite o ENDEREÇO.\n';
	}
	
	if (document.cadastroFRM.bairroVC.value.length == 0) {
	 	erroVC	= erroVC + '- Digite o BAIRRO.\n';
	}
	
	if (document.cadastroFRM.paisID.value == 1 && document.cadastroFRM.cepVC.value.length == 0) {
	 	erroVC	= erroVC + '- Digite o CEP.\n';
	}
	
	if (document.cadastroFRM.fone1VC.value.length == 0) {
	 	erroVC	= erroVC + '- Digite o TELEFONE.\n';
	}
	
	if (document.cadastroFRM.atividadeID.value == -1) {
	 	erroVC	= erroVC + '- Selecione a PRINCIPAL ATIVIDADE.\n';
	}
	
	if (document.cadastroFRM.atividadeID.value == 0 && document.cadastroFRM.atividadeVC.value.length == 0) {
	 	erroVC	= erroVC + '- Digite a PRINCIPAL ATIVIDADE.\n';
	}
	
	if (document.cadastroFRM.conhecimentoID.value == -1) {
	 	erroVC	= erroVC + '- Selecione COMO NOS CONHECEU.\n';
	}
	
	if ((document.cadastroFRM.conhecimentoID.value == 0 || document.cadastroFRM.conhecimentoID.value == 3 || document.cadastroFRM.conhecimentoID.value == 4 || document.cadastroFRM.conhecimentoID.value == 6 ) && document.cadastroFRM.conhecimentoVC.value.length == 0) {
	 	erroVC	= erroVC + '- Digite COMO NOS CONHECEU.\n';
	}

	if (erroVC.length == 0) {
		document.cadastroFRM.cadastrarBT.value		= 'aguarde';
		document.cadastroFRM.cadastrarBT.disabled	= true;
		document.cadastroFRM.submit();
	} else {
		alert('ATENÇÃO!\n\n' + erroVC);
		return false;
	}
}

/* LIMPA MASCARA DOS CAMPOS */
function limpa_string(stringVC) {
    var validos		= '0123456789';
    var digito		= '';
    var novo		= '';

    for (var i=0; i<stringVC.length; i++) {
        digito		= stringVC.charAt(i);
		
        if (validos.indexOf(digito) >= 0) {
            novo	= novo+digito;
		}
    }
    return novo
}

/*# COMBOS DINÂMICAS #*/
function sl_estado(paisID) {
	var dropdown1				= eval('document.getElementById(\'estadoID\')');
	var dropdown2				= eval('document.getElementById(\'cidadeID\')');
	
	/*#LIMPAR CAIXA#*/
	for (var x = dropdown1.length; x >= 0; x--) {
		dropdown1.options[x]	= null;
	}
	
	for (var x = dropdown2.length; x >= 0; x--) {
		dropdown2.options[x]	= null;
	}
	
	if (paisID == 0) {
		dropdown1.options[0]	= new Option('Selecione um pais', '-1');
		dropdown2.options[0]	= new Option('Selecione um estado', '-1');
	} else {
		dropdown1.options[0]	= new Option('Carregando...', '-1');

		iframeVirtual('temp/pais_estado_cidade.asp?paisID='+paisID);
	}
}

function pr_estado(estadoID,estadoVC) {
	var array_id 					= estadoID.split("|");
	var array_nome 					= estadoVC.split("|");
	var dropdown1					= eval('document.getElementById(\'estadoID\')');
	var dropdown2					= eval('document.getElementById(\'cidadeID\')');
	
	campoHidden('estadoID','-1','estadoVC')
	campoHidden('cidadeID','-1','cidadeVC')
	
	/*#LIMPAR CAIXA#*/
	for (var x = dropdown1.length; x >= 0; x--) {
		dropdown1.options[x]	= null;
	}	
	
	for (var x = dropdown2.length; x >= 0; x--) {
		dropdown2.options[x]	= null;
	}	

	/*#INSERE NOVOS#*/
	var n = 0;
//		dropdown1.options[0] 		= new Option('Selecione uma opção', '-1');

	for (var t = 0; t < (array_id.length)-1 ; t++) {
		dropdown1.options[n]	= new Option(array_nome[t], array_id[t]);
		n++;
	}
	
	dropdown2.options[0] = new Option('Selecione um estado', '-1');	
}

/*	CIDADE	*/
function sl_cidade(estadoID) {
	var dropdown1				= eval('document.getElementById(\'cidadeID\')');

	/*#LIMPAR CAIXA#*/
	for (var x = dropdown1.length; x >= 0; x--) {
		dropdown1.options[x]	= null;
	}
	
	if (estadoID == -1) {
		dropdown1.options[0]	= new Option('Selecione um estado', '-1');
	} else {
		dropdown1.options[0]	= new Option('Carregando...', '-1');

		iframeVirtual('temp/pais_estado_cidade.asp?estadoID='+estadoID);
	}
}

function pr_cidade(cidadeID,cidadeVC) {
	var array_id 					= cidadeID.split("|");
	var array_nome 					= cidadeVC.split("|");
	var dropdown1					= eval('document.getElementById(\'cidadeID\')');
	
	campoHidden('cidadeID','-1','cidadeVC')

	/*#LIMPAR CAIXA#*/
	for (var x = dropdown1.length; x >= 0; x--) {
		dropdown1.options[x]	= null;
	}	

	/*#INSERE NOVOS#*/
	var n = 0;
//		dropdown1.options[0] 		= new Option('Selecione uma opção', '-1');

	for (var t = 0; t < (array_id.length)-1 ; t++) {
		dropdown1.options[n]	= new Option(array_nome[t], array_id[t]);
		n++;
	}
}

/*	HIDDEN	*/
function campoHidden(campoID,campoN,campoVC) {
	var tr					= document.getElementById(campoID+'TR');
	var td1					= document.getElementById(campoID+'TD1');
	var td2					= document.getElementById(campoID+'TD2');
	var campo				= document.getElementById(campoVC);
	
	if (campoN == 0) {
		tr.style.display	= 'block';
		td1.style.display	= 'block';
		td2.style.display	= 'block';
		campo.focus();
	} else {
		td1.style.display	= 'none';
		td2.style.display	= 'none';
		tr.style.display	= 'none';
		campo.value			= '';
	}
}


/*	HIDDEN - CONHECIMENTO	*/
function campoHiddenConhecimento(campoID,campoN,campoVC) {
	var tr					= document.getElementById(campoID+'TR');
	var td1					= document.getElementById(campoID+'TD1');
	var td2					= document.getElementById(campoID+'TD2');
	var campo				= document.getElementById(campoVC);
	
	if (campoN == 0 || campoN == 3 || campoN == 4 || campoN == 6) {
		tr.style.display	= 'block';
		td1.style.display	= 'block';
		td2.style.display	= 'block';
		campo.focus();
	} else {
		td1.style.display	= 'none';
		td2.style.display	= 'none';
		tr.style.display	= 'none';
		campo.value			= '';
	}
}


/*	DUPLICIDADE	*/
function duplicidadeVerificar(campoID,valorVC) {
	if (valorVC.length > 0) {
		iframeVirtual('temp/cadastro.asp?campoID='+campoID+'&valorVC='+valorVC);
	}
}

/*	GERAR ATIVIDADES SECUNDARIAS	*/
function gerarAtividadesSecundarias(id_cliente,id_atividade,actA) {
	if (id_atividade != -1) {
		iframeVirtual('temp/cadastro_atividade_secundaria.asp?atividadeID='+id_atividade+'&clienteID='+id_cliente+'&actA='+actA);
	}else{
		if (actA == 1) {
			document.all.td_atividade_secundaria.innerHTML	= 'Selecione uma Atividade Principal';
		}
	}
}