var oAjax;
var oForm;
var varcMensagemAtual;

window.onload = function()
{
	fctLinkExterno();
	fctRodapeDinamico();
		
	oAjax	= new Ajax();
	oForm	= document.getElementById('frm_filie_se');
	if(document.getElementById('frm_filie_se') == null) return;
	
	if(document.getElementById("intePassos").value != 1 ){
		//oForm.intePassos.value	= "";
		fctCarregaEmail();
		fctCarregaTipoAdm();
		fctCarregaRepresentante();
		fctCarregaSocioPJ();
		fctCarregaSocioPF();
		fctCarregaFiliais();
		fctCarregaTipoAdmVinculado();
	}

	if(document.getElementById("intePassos").value != 1){
		inteSessionCategoriaID	= document.getElementById('SessionAdmConsorcioCategoriaID').value;
		if (inteSessionCategoriaID != 43){ //LOCAL É 42, MAS PARA ENVIAR PARA O AR, TEM QUE SER 43
			fctVerificaCategoria('Alterar');
		}
	}
	//varcMensagemAtual	= document.getElementById('txtMensagem').innerHTML;
}
//#############################//
//             Processar       //
//#############################// 
function fctProcessar(intePassos){
	
	switch (intePassos)
	{
		case 2:
			if(document.getElementById('varcRazaoSocial').value.isEmpty()){
				alert('Por favor, informe a razão social.');
				document.getElementById('varcRazaoSocial').focus();
				return false;
			}
			
			if(document.getElementById('varcNomeFantasia').value.isEmpty()){
				alert('Por favor, informe o nome fantasia.');
				document.getElementById('varcNomeFantasia').focus();
				return false;
			}
			
			if(document.getElementById('varcCNPJ').value.isEmpty()){
				alert('Por favor, informe o CNPJ.');
				document.getElementById('varcCNPJ').focus();
				return false;
			}
			
			if(document.getElementById('varcCEP').value.isEmpty()){
				alert('Por favor, informe o CEP.');
				document.getElementById('varcCEP').focus();
				return false;
			}
			
			if(document.getElementById('varcEndereco').value.isEmpty()){
				alert('Por favor, informe o endereço.');
				document.getElementById('varcEndereco').focus();
				return false;
			}
			
			if(document.getElementById('varcEnderecoNum').value.isEmpty()){
				alert('Por favor, informe o numero do endereço.');
				document.getElementById('varcEnderecoNum').focus();
				return false;
			}
				
			if(document.getElementById('inteCidadeID').selectedIndex == 0) {
				alert('Por favor, informe a cidade.');
				document.getElementById('inteCidadeID').focus();
				return false;
			}
			
			if(document.getElementById('varcCodTelefone').value.isEmpty()) {
				alert('Por favor, informe o código de área.');
				document.getElementById('varcCodTelefone').focus();
				return false;
			}
			
			if(document.getElementById('varcTelefone').value.isEmpty()) {
				alert('Por favor, informe o telefone.');
				document.getElementById('varcTelefone').focus();
				return false;
			}
			
			if(!document.getElementById('sdtaInicioAtividades').value.isEmpty()) {
			  if(!document.getElementById('sdtaInicioAtividades').value.isValidDate()) {
				alert('Por favor, informe uma data válida.');
				document.getElementById('sdtaInicioAtividades').focus();
				return false;
				}	
			}
			
			return true;
		break;
		
		case 3:

			if(!document.getElementById('varcEmailPrincipal').value.isValidEmail()) {
				alert('Por favor, informe o e-mail principal para o recebimento de circulares.');
				//oForm.varcEmailPrincipal.focus();
				return false;
			}			

			/*if(oForm.varcListaEmail.length == 0 ) {
				alert('Por favor, informe no mínimo um e-mail válido para o recebimento de circulares.');
				oForm.varcListaEmail.focus();
				return false;
			}*/

			return true;
		break;

		case 4:

			if(document.getElementById('varcNomeCobranca').value.isEmpty()) {
				alert('Por favor, informe o nome do responsável pela cobrança.');
				document.getElementById('varcNomeCobranca').focus();
				return false;
			}

			/*if(oForm.varcFuncaoCobranca.value.isEmpty()) {
				alert('Por favor, informe a função do responsável pela cobrança.');
				oForm.varcFuncaoCobranca.focus();
				return false;
			}

			if(oForm.varcDepartamentoCobranca.value.isEmpty()) {
				alert('Por favor, informe o departamento do responsável pela cobrança.');
				oForm.varcDepartamentoCobranca.focus();
				return false;
			}*/

			if(!document.getElementById('sdtaNascimentoCobranca').value.isEmpty()) {
				if(!document.getElementById('sdtaNascimentoCobranca').value.isValidDate())
				{
					alert('Por favor, informe uma data válida.');
					document.getElementById('sdtaNascimentoCobranca').focus();
					return false;
				}
			}

			if(document.getElementById('varcEmailCobranca').value.isEmpty()) {
				alert('Por favor, informe o email do responsável pela cobrança.');
				document.getElementById('varcEmailCobranca').focus();
				return false;
			}

			if(!document.getElementById('varcEmailCobranca').value.isValidEmail()) {
				alert('Por favor, informe o email valido do responsável pela cobrança.');
				document.getElementById('varcEmailCobranca').focus();
				return false;
			}

			/*if(oForm.varcCodTelefoneCobranca.value.isEmpty()) {
				alert('Por favor, informe o código de área.');
				oForm.varcCodTelefoneCobranca.focus();
				return false;
			}

			if(oForm.varcTelefoneCobranca.value.isEmpty()) {
				alert('Por favor, informe o telefone do responsável pela cobrança');
				oForm.varcTelefoneCobranca.focus();
				return false;
			}*/
			return true;

		break;
		case 5:
								
			/*if(! oForm.inteTipoAdministradora[0].checked && ! oForm.inteTipoAdministradora[1].checked && !oForm.inteTipoAdministradora[2].checked){
				alert('Por favor, selecione o tipo de administradora.');
				//oForm.inteTipoAdministradora.focus();
				return false;
			}*/
			
			if(document.getElementById('bitAlterar').value == 0){
				if(document.getElementById('varcCategoriaAdministradora').selectedIndex == 0){
					alert('Por favor, informe a categoria da administradora');
					document.getElementById('varcCategoriaAdministradora').focus();
					return false;  			
				}
			}

			
			if(document.getElementsByName('inteTipoAdministradora')[1].checked && document.getElementById('varcRevenda_fabricante').value.isEmpty()){
				alert('Por favor, informe a que revenda/lojas está vinculado.');
				document.getElementById('admIndependente').focus();
				return false;
			}

			if(document.getElementsByName('inteTipoAdministradora')[2].checked && document.getElementById('varcRevenda_fabricante').value.isEmpty()){
				alert('Por favor, informe a que fabricante está vinculado.');
				document.getElementById('varcRevenda_fabricante').focus();
				return false;
			}
			return true;
		break;
		case 6:
			fctRetornaArray(document.getElementById('varcDepartamentos'),document.getElementById('arraRepresentanteDepartamento'));
			var arraDepartamentos = document.getElementById('arraRepresentanteDepartamento').value.slice(0,document.getElementById('arraRepresentanteDepartamento').value.length - 2).split("#?");

			if(document.getElementById('varcNomeRepresentante').value.isEmpty()) {
				alert('Por favor, informe o Nome do Representante Legal.');
				document.getElementById('varcNomeRepresentante').focus();
				return false;
			}
			if(document.getElementById('varcFuncaoRepresentante').value.isEmpty()) {
				alert('Por favor, informe a Função do Representante Legal.');
				document.getElementById('varcFuncaoRepresentante').focus();
				return false;
			}			
			if(document.getElementById('sdtaNascimentoRepresentante').value.isEmpty()) {
				alert('Por favor, informe a Data de Nascimento do Representante Legal.');
				document.getElementById('sdtaNascimentoRepresentante').focus();
				return false;
			}
			if(document.getElementById('varcEmailRepresentante').value.isEmpty()) {
				alert('Por favor, informe o Email do Representante Legal.');
				document.getElementById('varcEmailRepresentante').focus();
				return false;
			}
			/*if(oForm.varcUsuarioRepresentante.value.isEmpty()) {
				alert('Por favor, informe o Usuário do Representante Legal.');
				oForm.varcUsuarioRepresentante.focus();
				return false;
			}*/
			if(!document.getElementById('varcEmailRepresentante').value.isValidEmail()) {
				alert('Por favor, informe um Email do Representante válido.');
				document.getElementById('varcEmailRepresentante').focus();
				return false;
			}
			if(document.getElementById('bitAlterar').value == 0){
				//if(oForm.varcSenhaRepresentante.value.isEmpty()){
				//	alert('Por favor, informe a Senha do Representante');
				//	oForm.varcSenhaRepresentante.focus();
				//	return false;  			
				//}
			}
			for(indx=0;indx < arraDepartamentos.length;indx+=8) {			
				if(arraDepartamentos[indx + 2] == 1) {
					bitDepartamentoDiretoria = false;
					break;
				}
				else
					bitDepartamentoDiretoria = true;
			}

//			if(bitDepartamentoDiretoria) {
//				alert("Por Favor, informe ao menos um representante da diretoria.");
//				return false;
//			}
			
//			if(oForm.varcDepartamentos.length == 0 ) {
//				alert('Por favor, informe no minímo um representante junto à entidade.');
//				oForm.varcDepartamentos.focus();
//				return false;
//			}
			
			return true;		
		break;
		
		case 7:
			return true;		
		break;		
		
		case 8:
			return true;		
		break;
		
		case 9:
			if(!fctRetornaSegmento()) {
				return false; 				
			}
			return true;		
		break;
		
		case 10:
			return true;		
		break;
	}	
}
function fctEnviar() {	
	fctRetornaArray(document.getElementById('varcListaEmail'),document.getElementById('arraEmailComplementares'));
	fctRetornaArray(document.getElementById('varcDepartamentos'),document.getElementById('arraRepresentanteDepartamento'));
	fctRetornaArray(document.getElementById('varcSocioPJ'),document.getElementById('arraSocioPJ'));
	fctRetornaArray(document.getElementById('varcSocioPF'),document.getElementById('arraSocioPF'));
	fctRetornaArray(document.getElementById('varcFiliais'),document.getElementById('arraFiliais'));

	if(document.getElementById('varcAdmConsorcioLinkSite').value.isEmpty()) {
		alert('Por favor, informe o link do site da administradora onde contém os endereços de Filiais/Representantes.');
		document.getElementById('varcAdmConsorcioLinkSite').focus();
		return false;
	}
	if(document.getElementById('varcAdmConsorcioResponsavelNome').value.isEmpty()) {
		alert('Por favor, informe o nome do responsável.');
		document.getElementById('varcAdmConsorcioResponsavelNome').focus();
		return false;
	}
	if(document.getElementById('varcAdmConsorcioResponsavelDDD').value.isEmpty()) {
		alert('Por favor, informe o DDD do responsável.');
		document.getElementById('varcAdmConsorcioResponsavelDDD').focus();
		return false;
	}
	if(document.getElementById('varcAdmConsorcioResponsavelTelefone').value.isEmpty()) {
		alert('Por favor, informe o telefone do responsável.');
		document.getElementById('varcAdmConsorcioResponsavelTelefone').focus();
		return false;
	}
	document.getElementById('frm_filie_se').submit();
}
//#############################//
//         fctAnterior         //
//#############################//
function fctAnterior() {
var intePassos;
	
	if(document.getElementById('intePassos').value == '')
		document.getElementById('intePassos').value = 1;
	
	intePassos = parseInt(document.getElementById('intePassos').value,10);
	
	if(intePassos > 1){
		intePassos -= 1;
		fctAbas();
		fctPassos(intePassos,10);		
	}
}
//#############################//
//		    fctProximo         //
//#############################//
function fctProximo() {
var intePassos;
    
	if(document.getElementById('intePassos').value == '')
		document.getElementById('intePassos').value = 1;

	intePassos = parseInt(document.getElementById('intePassos').value,10);

	if(intePassos < 10) {
		intePassos += 1;
		fctAbas();
		if(!fctPassos(intePassos,10))
			return;
	}
}
//#############################//
//			fctPassos          //
//#############################//
function fctPassos(PassoAtual,QtdePassos,obj) {
	var oDivPasso;
	var oMenu;
	var intePassos;
	
	if(document.getElementById("intePassos")== null || document.getElementById("intePassos").value.isEmpty())
		document.getElementById("intePassos").value = 1;
	
	intePassos = parseInt(document.getElementById("intePassos").value,10);
	
	if(PassoAtual < intePassos || fctVerificaPassos(intePassos,PassoAtual)) {
		for(indx=1;indx <= QtdePassos;indx++) {
			oDivPasso = eval('document.getElementById("passo'+ indx +'")');
			if(PassoAtual == indx) {
				oDivPasso.style.display = 'block';		
			}
			else
				oDivPasso.style.display = 'none';
		}		
		document.getElementById("intePassos").value = PassoAtual;
		fctAbas(obj);
		fctMenuNavegacao();
	}else
		return false;		
}

function fctMenuNavegacao(){
	
	PassoAtual = parseInt(document.getElementById("intePassos").value,10);

	if(PassoAtual < 10 ) {	
		document.getElementById("btnProximo").style.display = 'block';	
		document.getElementById("btnProximo").style.left = '335px';	
		document.getElementById("btnProximo").style.top = '-15px';	
	}else
		document.getElementById("btnProximo").style.display = 'none';			
	
	if(PassoAtual > 1)
		document.getElementById("btnAnterior").style.display = 'block';	
	else 
		document.getElementById("btnAnterior").style.display = 'none';	
}

//#############################//
//                        fctVerificaPassos    		                 //
//#############################//
function fctVerificaPassos(inicio,fim) {
	var oDivPasso;
	var oDivPassoAtivo;
	var total = 0;
	var indx;
	var indx1;

	if(inicio == 1 && fim <= 2)	
		return true;			

	if((fim - inicio) == 1) {
		if(! fctProcessar(inicio)) {
			return false;		
		}else {
			return true;			
		}		
	}else {
		for(indx=inicio;indx < fim;indx++) {
			if(! fctProcessar(indx)) {
				oDivPassoAtivo = eval('document.getElementById("passo'+ indx +'")');
			
				for(indx1=1;indx1 < fim;indx1++) {
					oDivPasso = eval('document.getElementById("passo'+ indx1 +'")');
					oDivPasso.style.display = 'none';
				}
				
				document.getElementById("intePassos").value = indx;
				oDivPassoAtivo.style.display = 'block';
				fctAbas();
				fctMenuNavegacao();
				return false;
			}					
		}
		return true;
	}
}

//#############################//
//                  		fctAbas    		                 //
//#############################//
function fctAbas(obj) {
	var oMenu = document.getElementById("menu_passos");
	var inteLength = oMenu.childNodes.length;
	var intePassos = parseInt(document.getElementById("intePassos").value,10);
	var count = 0;

//intePassos++;
	for(indx=0; indx < inteLength;indx++) {
		if(oMenu.childNodes[indx].tagName != undefined) {
			oMenu.childNodes[indx].style.backgroundImage = 'url(estilo/img/internas/formulario/1_escuro.gif)';
			//oMenu.childNodes[indx].style.borderBottom = '1px solid #BBB';
			
			count++;
			if(intePassos == count) {
				oMenu.childNodes[indx].style.backgroundImage = 'url(estilo/img/internas/formulario/1.gif)';
				//oMenu.childNodes[indx].style.borderBottom = '0px';
			}
		}	
	}
}

//#############################//
//                                  ADICIONAR                              //
//#############################// 
function fctAddDepartamento() {
	var oList 		= document.getElementById('varcDepartamentos');
	var indxSelect 	= document.getElementById('varcTipoDepartamento').selectedIndex;
	var intLength 	= 0;
	

	if(document.getElementById('varcTipoDepartamento').selectedIndex == 0) {
		alert('Por favor, informe o departamento a ser adicionado.');
		document.getElementById('varcTipoDepartamento').focus();
		return;
	} 
	
	if(document.getElementById('varcNomeDepartamento').value.isEmpty()) {
		alert('Por favor, informe o nome do representante.');
		document.getElementById('varcNomeDepartamento').focus();
		return;
	}
/*		
	if(oForm.varcFuncaoDepartamento.value.isEmpty()) {
		alert('Por favor, informe a função do representante.');
		oForm.varcFuncaoDepartamento.focus();
		return;
	}
	
	if(!oForm.sdtaNascimentoDepartamento.value.isEmpty()) {
		if(!oForm.sdtaNascimentoDepartamento.value.isValidDate()) {
			alert('Por favor, informe uma data válida.');
			oForm.sdtaNascimentoDepartamento.focus();
			return false;
		}
	}	
	
	if(oForm.varcEmailDepartamento.value.isEmpty()) {
		alert('Por favor, preencha o e-mail do representante.');
		oForm.varcEmailDepartamento.focus();
		return;
	}
	
	if(!oForm.varcEmailDepartamento.value.isValidEmail()) {
		alert('Por favor, preencha o e-mail com um endereço válido.');
		oForm.varcEmailDepartamento.focus();
		return;
	}
	
//	if(oForm.varcSenhaDepartamento.value.isEmpty()) {
//		alert('Por favor,informe a senha do representante.');
//		oForm.varcSenhaDepartamento.focus();
//		return;
//	}

	if(oForm.varcCodTelefoneDepartamento.value.isEmpty()) {
		alert('Por favor, informe o código de área do telefone');
		oForm.varcCodTelefoneDepartamento.focus();
		return;
	}
	if(oForm.varcTelefoneDepartamento.value.isEmpty()) {
		alert('Por favor, informe o numero do telefone');
		oForm.varcTelefoneDepartamento.focus();
		return;
	}
	
*/	

	intLength = oList.length;
	oList.options[intLength] = new Option('Nome: '+document.getElementById('varcNomeDepartamento').value,document.getElementById('varcNomeDepartamento').value);
	intLength ++;
	oList.options[intLength] = new Option('Função: '+document.getElementById('varcFuncaoDepartamento').value,document.getElementById('varcFuncaoDepartamento').value);
	intLength ++;
	oList.options[intLength] = new Option('Departamento: '+document.getElementById('varcTipoDepartamento')[indxSelect].text,document.getElementById('varcTipoDepartamento').value);
	intLength ++;
	oList.options[intLength] = new Option('Data de Nasc.: '+document.getElementById('sdtaNascimentoDepartamento').value,document.getElementById('sdtaNascimentoDepartamento').value);
	intLength ++;
	oList.options[intLength] = new Option('Email: '+ document.getElementById('varcEmailDepartamento').value,document.getElementById('varcEmailDepartamento').value);
	intLength ++;
	oList.options[intLength] = new Option('Senha: Confidencial', document.getElementById('varcSenhaDepartamento').value);
	intLength ++;
	var varcCodTelefoneDepartamento = document.getElementById('varcCodTelefoneDepartamento').value;
	var varcCodCelularDepartamento = document.getElementById('varcCodCelularDepartamento').value;
	oList.options[intLength] = new Option('Telefone: ('+varcCodTelefoneDepartamento+')'+ document.getElementById('varcTelefoneDepartamento').value,document.getElementById('varcCodTelefoneDepartamento').value + document.getElementById('varcTelefoneDepartamento').value);
	intLength ++;
	oList.options[intLength] = new Option('Celular: ('+varcCodCelularDepartamento+')'+ document.getElementById('varcCelularDepartamento').value,document.getElementById('varcCodCelularDepartamento').value + document.getElementById('varcCelularDepartamento').value);
	intLength ++;
	oList.options[intLength] = new Option('--------------------------------------------------------------------------------------------------------------','-1');
	
	fctLimparCamposDepartamento();
}

//#############################//
//                         LIMPAR CAMPOS                               //
//#############################// 
function fctLimparCamposDepartamento() {
	document.getElementById('varcTipoDepartamento').selectedIndex = 0;
	document.getElementById('varcNomeDepartamento').value 		 = "";
	document.getElementById('varcFuncaoDepartamento').value 		 = ""
	document.getElementById('sdtaNascimentoDepartamento').value	 = "";
	document.getElementById('varcEmailDepartamento').value 		 = "";
	document.getElementById('varcSenhaDepartamento').value		 = "";	
	document.getElementById('varcCodTelefoneDepartamento').value  = "";	
	document.getElementById('varcTelefoneDepartamento').value 	 = "";
	document.getElementById('varcCodCelularDepartamento').value 	 = "";
	document.getElementById('varcCelularDepartamento').value 	 = "";
}

//#############################//
//                               REMOVER                                     //
//#############################// 
function fctRemoveDepartamento() {
	objPrv	= document.getElementById('varcDepartamentos');	
	for(Indx=0; Indx < objPrv.length; Indx++)
		if(objPrv.options[Indx].selected ) {
			objPrv.options[Indx] = null;
			Indx--;
		}
}

//#############################//
//                               Select Itens                                  //
//#############################// 
function fctSelectItens(objOne) {
	if(objOne == null)
		return;
	
	if(objOne.selectedIndex == -1)
		return;

	selIndx		= objOne.selectedIndex;
	posIni		=	0;
	posFim		=	0;
	Indx		=	selIndx;
	if(objOne[selIndx].value == -1)
		Indx	= selIndx -1;

	// Encontrar Posição Inicial
	for(; Indx >= 0 ;Indx--)
		if(objOne[Indx].value == -1) {
			posIni	= Indx +1;
			Indx	= -1;
		}

	// Encontrar Posição Final
	for(Indx=selIndx; Indx < objOne.length ;Indx++)
		if(objOne[Indx].value == -1) {
			posFim	= Indx;
			Indx	= objOne.length;
		}

	// Deseleciona Todos os Registros
	for(Indx=0; Indx < objOne.length ;Indx++)
		objOne[Indx].selected	= false;

	// Seleciona Todos os Registros entre 'posIni' e 'posFim'
	for(; posIni <= posFim ;posIni++)
		objOne[posIni].selected	= true;
}

//#############################//
//                                  EDITAR                                      //
//#############################// 
function fctEditDepartamento() {
	var oList 		= document.getElementById('varcDepartamentos');	
	var indxLength 	= 0; 
	
	if(oList.length == 0) {
		return;	
	}
	
	if(oList.selectedIndex == -1)
		return;
		
	for(indx=0;indx < oList.length;indx++) {
		if(oList[indx].selected) {
			indxLength = indx;
			break;
		}
	}	
	
	document.getElementById('varcNomeDepartamento').value 		 = oList[indxLength].value;
	document.getElementById('varcFuncaoDepartamento').value 		 = oList[indxLength + 1].value;
	document.getElementById('varcTipoDepartamento').value         = oList[indxLength + 2].value;
	document.getElementById('sdtaNascimentoDepartamento').value	 = oList[indxLength + 3].value;
	document.getElementById('varcEmailDepartamento').value 		 = oList[indxLength + 4].value;
	document.getElementById('varcSenhaDepartamento').value		 = oList[indxLength + 5].value;
	document.getElementById('varcCodTelefoneDepartamento').value  = oList[indxLength + 6].value.slice(0,2);	
	document.getElementById('varcTelefoneDepartamento').value  	 = oList[indxLength + 6].value.slice(2,oList[indxLength + 6].value.length);
	document.getElementById('varcCodCelularDepartamento').value 	 = oList[indxLength + 7].value.slice(0,2);
	document.getElementById('varcCelularDepartamento').value 	 = oList[indxLength + 7].value.slice(2,oList[indxLength + 7].value.length);
	
	fctRemoveDepartamento();
}

//#############################//
//                                  ADICIONAR                              //
//#############################// 
function fctAddSocioPj() {
	var oList 		= document.getElementById('varcSocioPJ');
	var indxLength	= document.getElementById('varcSocioPJ').length;
	
	
	if(document.getElementById('varcRazaoSocialSociosPJ').value.isEmpty()) {
		alert('Por favor, informe a razão social do sócio.');
		document.getElementById('varcRazaoSocialSociosPJ').focus();
		return;
	}
	
	if(document.getElementById('varcAtividadeSociosPJ').value.isEmpty()) {
		alert('Por favor, informe a atividade do sócio.');
		document.getElementById('varcAtividadeSociosPJ').focus();
		return;
	}
	
	if(document.getElementById('varcCapitalSociosPJ').value.isEmpty()) {
		alert('Por favor, informe o capital do sócio.');
		document.getElementById('varcCapitalSociosPJ').focus();
		return;
	}
	
	if(document.getElementById('varcQuotaSociosPJ').value.isEmpty()) {
		alert('Por favor, informe a quota do sócio.');
		document.getElementById('varcQuotaSociosPJ').focus();
		return;
	}
	
	if(document.getElementById('varcEnderecoSociosPJ').value.isEmpty()) {
		alert('Por favor, informe o endereço do sócio.');
		document.getElementById('varcEnderecoSociosPJ').focus();
		return;
	}
	
	if(document.getElementById('varcCodTelefoneSociosPJ').value.isEmpty()) {
		alert('Por favor, informe o código de área.');
		document.getElementById('varcCodTelefoneSociosPJ').focus();
		return;
	}
	
	if(document.getElementById('varcTelefoneSociosPJ').value.isEmpty()) {
		alert('Por favor, informe o telefone do sócio.');
		document.getElementById('varcTelefoneSociosPJ').focus();
		return;
	}
	
	if(document.getElementById('varcEmailSociosPJ').value.isEmpty()) {
		alert('Por favor, informe o email do sócio.');
		document.getElementById('varcEmailSociosPJ').focus();
		return;
	}	
	
	if(! document.getElementById('varcEmailSociosPJ').value.isValidEmail()) {
		alert('Por favor, informe um email válido.');
		document.getElementById('varcEmailSociosPJ').focus();
		return;
	}	
	
	if(document.getElementById('varcDiretorContatoSociosPJ').value.isEmpty()) {
		alert('Por favor, informe o diretor para contato.');
		document.getElementById('varcDiretorContatoSociosPJ').focus();
		return;
	}	

	oList.options[indxLength] = new Option('Razão Social: '+ document.getElementById('varcRazaoSocialSociosPJ').value,document.getElementById('varcRazaoSocialSociosPJ').value);
	indxLength ++;
	oList.options[indxLength] = new Option('Atividade: '+ document.getElementById('varcAtividadeSociosPJ').value,document.getElementById('varcAtividadeSociosPJ').value);
	indxLength ++;
	oList.options[indxLength] = new Option('Capital: '+ document.getElementById('varcCapitalSociosPJ').value,document.getElementById('varcCapitalSociosPJ').value);
	indxLength ++;
	oList.options[indxLength] = new Option('Quota: '+ document.getElementById('varcQuotaSociosPJ').value,document.getElementById('varcQuotaSociosPJ').value);
	indxLength ++;
	oList.options[indxLength] = new Option('Endereço: '+ document.getElementById('varcEnderecoSociosPJ').value,document.getElementById('varcEnderecoSociosPJ').value);
	indxLength ++;
	oList.options[indxLength] = new Option("Telefone: "+ '('+document.getElementById('varcCodTelefoneSociosPJ').value +')'+ document.getElementById('varcTelefoneSociosPJ').value,document.getElementById('varcCodTelefoneSociosPJ').value + document.getElementById('varcTelefoneSociosPJ').value);
	indxLength ++;
	oList.options[indxLength] = new Option('E-mail: '+ document.getElementById('varcEmailSociosPJ').value,document.getElementById('varcEmailSociosPJ').value);
	indxLength ++;
	oList.options[indxLength] = new Option('Diretor Contato: '+ document.getElementById('varcDiretorContatoSociosPJ').value,document.getElementById('varcDiretorContatoSociosPJ').value);
	indxLength ++;
	oList.options[indxLength] = new Option('-------------------------------------------------------------------------------------------------------','-1');

	fctLimparCamposSocioPJ();
}

//#############################//
//                               REMOVER                                     //
//#############################// 
function fctRemoveSocioPj() {
	
	objPrv	= document.getElementById('varcSocioPJ');	
	for(Indx=0; Indx < objPrv.length; Indx++)
		if(objPrv.options[Indx].selected) {
			objPrv.options[Indx] = null;
			Indx--;
		}
}

//#############################//
//                                  EDITAR                                      //
//#############################// 
function fctEditSocioPJ() {
	var oList 		= document.getElementById('varcSocioPJ');	
	var indxLength 	= 0; 
	
	if(oList.length == 0) {
		return;	
	}
	
	if(oList.selectedIndex == -1)
		return;
 	
	for(indx=0;indx < oList.length;indx++) {
		if(oList[indx].selected) {
			indxLength = indx;
			break;
		}
	}	
			
	document.getElementById('varcRazaoSocialSociosPJ').value			= oList[indxLength].value;
	document.getElementById('varcAtividadeSociosPJ').value			= oList[indxLength + 1].value;	
	document.getElementById('varcCapitalSociosPJ').value				= oList[indxLength + 2].value;	
	document.getElementById('varcQuotaSociosPJ').value				= oList[indxLength + 3].value;
	document.getElementById('varcEnderecoSociosPJ').value			= oList[indxLength + 4].value;
	document.getElementById('varcCodTelefoneSociosPJ').value			= oList[indxLength + 5].value.slice(0,2);
	document.getElementById('varcTelefoneSociosPJ').value			= oList[indxLength + 5].value.slice(2,oList[indxLength + 5].value.length);
	document.getElementById('varcEmailSociosPJ').value				= oList[indxLength + 6].value;
	document.getElementById('varcDiretorContatoSociosPJ').value		= oList[indxLength + 7].value;	
	
	fctRemoveSocioPj();	
}

//#############################//
//                         LIMPAR CAMPOS                               //
//#############################// 
function fctLimparCamposSocioPJ() {
	document.getElementById('varcRazaoSocialSociosPJ').value			= "";
	document.getElementById('varcAtividadeSociosPJ').value			= "";
	document.getElementById('varcCapitalSociosPJ').value				= "";
	document.getElementById('varcQuotaSociosPJ').value				= "";
	document.getElementById('varcEnderecoSociosPJ').value			= "";
	document.getElementById('varcCodTelefoneSociosPJ').value			= "";
	document.getElementById('varcTelefoneSociosPJ').value			= "";
	document.getElementById('varcEmailSociosPJ').value				= "";
	document.getElementById('varcDiretorContatoSociosPJ').value		= "";
}

//#############################//
//                                  ADICIONAR                              //
//#############################// 
function fctAddSocioPF() {
	var oList 		= document.getElementById('varcSocioPF');
	var indxLength	= document.getElementById('varcSocioPF').length;
	
	if(document.getElementById('varcNomeSociosPF').value.isEmpty()) {
		alert('Por favor, informe o nome do sócio.');
		document.getElementById('varcNomeSociosPF').focus();
		return;
	}
	
	if(document.getElementById('varcParticipacaoSociosPF').value.isEmpty()) {
		alert('Por favor, informe a participação do sócio.');
		document.getElementById('varcParticipacaoSociosPF').focus();
		return;
	}
	
	if(document.getElementById('varcCargoSociosPF').value.isEmpty()) {
		alert('Por favor, informe o cargo do sócio.');
		document.getElementById('varcCargoSociosPF').focus();
		return;
	}
	
	if(!document.getElementById('sdtaNascSociosPF').value.isEmpty()) {
		if(!document.getElementById('sdtaNascSociosPF').value.isValidDate()) {
			alert('Por favor, informe a data válida.');
			document.getElementById('sdtaNascSociosPF').focus();
			return;
		}
	}
	
	oList.options[indxLength] = new Option('Nome: '+ document.getElementById('varcNomeSociosPF').value,document.getElementById('varcNomeSociosPF').value);
	indxLength ++;
	oList.options[indxLength] = new Option('Participação: '+ document.getElementById('varcParticipacaoSociosPF').value,document.getElementById('varcParticipacaoSociosPF').value);
	indxLength ++;
	oList.options[indxLength] = new Option('Cargo: '+ document.getElementById('varcCargoSociosPF').value,document.getElementById('varcCargoSociosPF').value);
	indxLength ++;
	oList.options[indxLength] = new Option('Data Nasc.: '+ document.getElementById('sdtaNascSociosPF').value,document.getElementById('sdtaNascSociosPF').value);
	indxLength ++;
	oList.options[indxLength] = new Option('-------------------------------------------------------------------------------------------------------','-1');

	fctLimparCamposSocioPF();
}

//#############################//
//                               REMOVER                                     //
//#############################// 
function fctRemoveSocioPF(){
	objPrv	= document.getElementById('varcSocioPF');	
	for(Indx=0; Indx < objPrv.length; Indx++)
		if(objPrv.options[Indx].selected) {
			objPrv.options[Indx] = null;
			Indx--;
		}
}
//#############################//
//                                  EDITAR                                      //
//#############################// 
function fctEditSocioPF() {
	var oForm		= document.getElementById("frm_filie_se");
	var oList 		= document.getElementById('varcSocioPF');	
	var indxLength 	= 0; 
	
	if(oList.length == 0) {
		return;	
	}

	if(oList.selectedIndex == -1)
		return;	
		
	for(indx=0;indx < oList.length;indx++) {
		if(oList[indx].selected) {
			indxLength = indx;
			break;
		}
	}	
	
	document.getElementById('varcNomeSociosPF').value			= oList[indxLength].value;	
	document.getElementById('varcParticipacaoSociosPF').value	= oList[indxLength + 1].value;	
	document.getElementById('varcCargoSociosPF').value			= oList[indxLength + 2].value;
	document.getElementById('sdtaNascSociosPF').value			= oList[indxLength + 3].value;
	
	fctRemoveSocioPF();	
}

//#############################//
//                         LIMPAR CAMPOS                               //
//#############################// 
function fctLimparCamposSocioPF() {
	document.getElementById('varcNomeSociosPF').value			= "";
	document.getElementById('varcParticipacaoSociosPF').value	= "";
	document.getElementById('varcCargoSociosPF').value			= "";
	document.getElementById('sdtaNascSociosPF').value			= "";
}
//#############################//
//                                  ADICIONAR                              //
//#############################// 
function fctAddFiliais() {
	var indxSelectCidade  	= document.getElementById('inteFiliaisCidadeID').selectedIndex;
	var indxSelectUF	  	= document.getElementById('sintFiliaisEstadoID').selectedIndex;
	var oList 				= document.getElementById('varcFiliais');
	var indxLength			= oList.length;
	
//	if(oForm.varcNomeFiliais.value.isEmpty()) {
//		alert('Por favor, informe o nome da filial.');
//		oForm.varcNomeFiliais.focus();
//		return;
//	}
//	
//	if(oForm.varcEmailFiliais.value.isEmpty()) {
//		alert('Por favor, informe o email da filial.');
//		oForm.varcEmailFiliais.focus();
//		return;
//	}	
//	
//	if(oForm.varcFiliaisCEP.value.isEmpty()) {
//		alert('Por favor, informe o CEP.');
//		oForm.varcFiliaisCEP.focus();
//		return;
//	}
//	
//	if(oForm.varcFiliaisEndereco.value.isEmpty()) {
//		alert('Por favor, informe o endereço da filial.');
//		oForm.varcFiliaisEndereco.focus();
//		return;
//	}
//	
//	if(oForm.varcFiliaisEnderecoNum.value.isEmpty()) {
//		alert('Por favor, informe o numero do endereço da filial.');
//		oForm.varcFiliaisEnderecoNum.focus();
//		return;
//	}
//	
//	if(oForm.varcFiliaisBairro.value.isEmpty()) {
//		alert('Por favor, informe bairro.');
//		oForm.varcFiliaisBairro.focus();
//		return;
//	}
	
	if(document.getElementById('inteFiliaisCidadeID').selectedIndex == 0) {
		alert('Por favor, informe a cidade.');
		document.getElementById('inteFiliaisCidadeID').focus();
		return;
	}
	
//	if(oForm.varcCodTelefoneFiliais.value.isEmpty()) {
//		alert('Por favor, informe o código de área.');
//		oForm.varcCodTelefoneFiliais.focus();
//		return;
//	}
//	
//	if(oForm.varcTelefoneFiliais.value.isEmpty()) {
//		alert('Por favor, informe o telefone.');
//		oForm.varcTelefoneFiliais.focus();
//		return;
//	}
			
//	oList.options[indxLength] = new Option('Nome: '+ oForm.varcNomeFiliais.value,oForm.varcNomeFiliais.value);
//	indxLength ++;
//	oList.options[indxLength] = new Option('Endereço: '+ oForm.varcFiliaisEndereco.value +' Num. '+ oForm.varcFiliaisEnderecoNum.value ,oForm.varcFiliaisEndereco.value );
//	indxLength ++;
//	oList.options[indxLength] = new Option('Número: '+ oForm.varcFiliaisEnderecoNum.value , oForm.varcFiliaisEnderecoNum.value);
//	indxLength ++;
//	oList.options[indxLength] = new Option('Complemento: '+ oForm.varcFiliaisComplemento.value,oForm.varcFiliaisComplemento.value);
//	indxLength ++;
//	oList.options[indxLength] = new Option('Bairro: '+ oForm.varcFiliaisBairro.value,oForm.varcFiliaisBairro.value);
//	indxLength ++;
	oList.options[indxLength] = new Option('Cidade: '+ document.getElementById('inteFiliaisCidadeID')[indxSelectCidade].text,document.getElementById('inteFiliaisCidadeID').value);
	indxLength ++;
	oList.options[indxLength] = new Option('UF: '+ document.getElementById('sintFiliaisEstadoID')[indxSelectUF].text,document.getElementById('sintFiliaisEstadoID').value);
	indxLength ++;
//	oList.options[indxLength] = new Option('CEP: '+ oForm.varcFiliaisCEP.value,oForm.varcFiliaisCEP.value);
//	indxLength ++;
//	oList.options[indxLength] = new Option('Telefone: '+ '('+ oForm.varcCodTelefoneFiliais.value +')'+oForm.varcTelefoneFiliais.value,oForm.varcCodTelefoneFiliais.value+oForm.varcTelefoneFiliais.value);
//	indxLength ++;
//	oList.options[indxLength] = new Option('Email: '+ oForm.varcEmailFiliais.value,oForm.varcEmailFiliais.value);
//	indxLength ++;		
	oList.options[indxLength] = new Option('-------------------------------------------------------------------------------------------------------','-1');

	fctLimparCamposFiliais();
}

//#############################//
//                               REMOVER                                     //
//#############################// 
function fctRemoveFiliais() {
	
	objPrv	= document.getElementById('varcFiliais');	
	for(Indx=0; Indx < objPrv.length; Indx++)
		if(objPrv.options[Indx].selected ) {
			objPrv.options[Indx] = null;
			Indx--;
		}
}

//#############################//
//                                  EDITAR                                      //
//#############################// 
function fctEditFiliais() {
	var oList 		= document.getElementById('varcFiliais');	
	var indxLength 	= 0; 
	
	if(oList.length == 0) {
		return;	
	}
	
	if(oList.selectedIndex == -1)
		return;
	
	for(indx=0;indx < oList.length;indx++) {
		if(oList[indx].selected) {
			indxLength = indx;
			break;
		}
	}	
		
//	oForm.varcNomeFiliais.value 			= oList[indxLength].value;	
//	oForm.varcFiliaisEndereco.value			= oList[indxLength + 1].value;
//	oForm.varcFiliaisEnderecoNum.value		= oList[indxLength + 2].value;			
//	oForm.varcFiliaisComplemento.value		= oList[indxLength + 3].value;	
//	oForm.varcFiliaisBairro.value			= oList[indxLength + 4].value;	
	document.getElementById('inteFiliaisCidadeID').selectedIndex = 0;
	document.getElementById('sintFiliaisEstadoID').selectedIndex	= 0;
//	oForm.varcFiliaisCEP.value				= oList[indxLength + 7].value;	
//	oForm.varcCodTelefoneFiliais.value		= oList[indxLength + 8].value.slice(0,2);		
//	oForm.varcTelefoneFiliais.value			= oList[indxLength + 8].value.slice(2,oList[indxLength + 8].value.length);	
//	oForm.varcEmailFiliais.value 			= oList[indxLength + 9].value;
	
	fctRemoveFiliais();	
}

//#############################//
//                         LIMPAR CAMPOS                               //
//#############################// 
function fctLimparCamposFiliais() {
//	oForm.varcNomeFiliais.value 			= "";	
//	oForm.varcFiliaisEndereco.value			= "";
//	oForm.varcFiliaisEnderecoNum.value		= "";
//	oForm.varcFiliaisComplemento.value		= "";
//	oForm.varcFiliaisBairro.value			= "";
	document.getElementById('inteFiliaisCidadeID').selectedIndex = 0;
	document.getElementById('sintFiliaisEstadoID').selectedIndex	= 0;
//	oForm.varcFiliaisCEP.value				= "";
//	oForm.varcCodTelefoneFiliais.value		= "";
//	oForm.varcTelefoneFiliais.value			= "";
//	oForm.varcEmailFiliais.value			= "";
}

//#############################//
//                              ADD EMAIL                                   //
//#############################// 
function fctAddEmail() {
	var oList 		= document.getElementById('varcListaEmail');
	var indxLength	= oList.length;

	if(document.getElementById('varcEmailComplementar').value.isEmpty()) {
		alert('Por favor, informe o email.');
		document.getElementById('varcEmailComplementar').focus();
		return;
	}
	
	if(!document.getElementById('varcEmailComplementar').value.isValidEmail()) {
		alert('Por favor, informe o email valido.');
		document.getElementById('varcEmailComplementar').focus();
		return;
	}
				
	oList.options[indxLength] = new Option('E-mail: '+ document.getElementById('varcEmailComplementar').value,document.getElementById('varcEmailComplementar').value);
	indxLength ++;
	oList.options[indxLength] = new Option('-------------------------------------------------------------------------------------------------------','-1');

	fctLimparCamposEmail();
}

//#############################//
//                                  EDITAR                                      //
//#############################// 
function fctEditEmail() {
	var oList 		= document.getElementById('varcListaEmail');	
	var indxLength 	= 0; 
	
	if(oList.length == 0) {
		return;	
	}

	if(oList.selectedIndex == -1)
		return;	
	
	for(indx=0;indx < oList.length;indx++) {
		if(oList[indx].selected) {
			indxLength = indx;
			break;
		}
	}	
		
	document.getElementById('varcEmailComplementar').value 		= oList[indxLength].value;	
	
	fctRemoveEmail();	
}

//#############################//
//                         LIMPAR CAMPOS                               //
//#############################// 
function fctLimparCamposEmail() {
	document.getElementById('varcEmailComplementar').value 	= "";	
}

//#############################//
//                               REMOVER                                     //
//#############################// 
function fctRemoveEmail() {
	objPrv	= document.getElementById('varcListaEmail');	
	
	for(Indx=0; Indx < objPrv.length; Indx++)
		if(objPrv.options[Indx].selected) {
			objPrv.options[Indx] = null;
			Indx--;
		}
}

//#############################//
//                         fctRetornaArray                                 //
//#############################// 
function fctRetornaArray(oLista,oArray) {
	oArray.value = "";	

	for(Indx=0; Indx < oLista.length; Indx++)
		if(oLista.options[Indx].value != -1) {
			oArray.value += oLista.options[Indx].value +'#?';
		}
}

//#############################//
//                         fctRetornaSegmento                          //
//#############################//
function fctRetornaSegmento() {
var arraSegmento
var arraCategoria
var arraCategoriaTipo
var varcSegmentos = "";
var varcMsg
var varcMsg1
	
	if(document.getElementById('arraSegmento').value == ""){return true;}
	
	arraSegmento = document.getElementById('arraSegmento').value;
	arraSegmento = arraSegmento.slice(0,arraSegmento.length - 2);
	arraSegmento = arraSegmento.split('#?');
	
	for(indx=0;indx < arraSegmento.length;indx++) 
	{
		//arraCategoria = eval(objSegmento + arraSegmento[indx]); 
		//arraCategoria = document.getElementById('inteSegmento'+arraSegmento[indx+1]);
		arraCategoria = eval('oForm.inteSegmento'+ arraSegmento[indx]); 
		
		if(arraCategoria!=null)
		{
			if(arraCategoria.length == undefined ) 
			{
				    varcMsg = 'Selecione a categoria do segmento '+ arraSegmento[indx+1] +'.'
					if(arraCategoria.checked) 
					{			
						varcSegmentos += arraCategoria.value +'#?';
						varcSegmentos += '0#?0#?0#?';
					}
					/*else 
					{
						if(varcMsg != "") 
						{
							alert(varcMsg);
							arraCategoria.focus();
							return false;
						}		
					}*/		
			}else 
			{
						varcMsg = 'Selecione as categorias do segmento '+ arraSegmento[indx+1] +'.'
					
						for(indx1=0;indx1 < arraCategoria.length;indx1++) 
						{
							if(arraCategoria[indx1].checked) 
							{
								varcSegmentos +=	arraCategoria[indx1].value +'#?';
								//arraCategoriaTipo = eval('oForm.inteTipo'+ arraCategoria[indx1].value);
								//arraCategoriaTipo = document.getElementById('inteTipo'+ arraCategoria[indx1]).value;
								arraCategoriaTipo = eval('oForm.inteTipo'+ arraCategoria[indx1].value);
							    if(arraCategoriaTipo == undefined)
								    varcSegmentos += '0#?0#?0#?'
							    else 
							    {						
								    varcMsg1 = 'Selecione ao menos um tipo da categoria '+ arraCategoria[indx1].parentNode.childNodes[1].innerHTML +'.';
    								
								    for(indx2=0;indx2 < arraCategoriaTipo.length;indx2++)
								    {								
									    if(arraCategoriaTipo[indx2].checked) 
									    {
										    varcSegmentos += 1 + "#?";
										    varcMsg1 = "";
									    }
									    else 
									    {
										    varcSegmentos += 0 + "#?";					
									    }
								    }						
								        if(varcMsg1 != "") 
								    {
									    alert(varcMsg1);
									    arraCategoria[indx1].focus();
									    return;						
								    }
							    }
    							
							    varcMsg = ""
						}													
					}

					/*if(varcMsg != "") 
					{
						alert(varcMsg);
						//arraCategoria[indx1].focus();
						return false;
					}*/
				}
		}
	}
	document.getElementById('arraAllSegmentos').value = varcSegmentos;	
	return true;
}

//#############################//
//                         fctSelecionaCategoria                        //
//#############################//
function fctSelecionaCategoria(oCheck){
var oCategoria;	
	oCategoria = eval('document.getElementById("inteCategoria'+ oCheck.value +'")');	
	oCategoria.checked = true;	
}
//#############################//
//                         fctCarregaEmail                                  //
//#############################//
function fctCarregaEmail(){

var oList = document.getElementById('varcListaEmail');
var arraEmail = document.getElementById('varcEmailComplementares').value.slice(0,document.getElementById('varcEmailComplementares').value.length - 2).split('#?');
var len = 0;
	if(!document.getElementById('varcEmailComplementares').value.isEmpty())
	{
		
		for(indx=0;indx < arraEmail.length;indx++)
		{
			len = oList.length;
			oList.options[len] = new Option("E-mail: "+ arraEmail[indx], arraEmail[indx]);
			len++;
			oList.options[len] = new Option("-------------------------------------------------------------------------------", '-1');			
		}
		
	}

}
//#############################//
//                         fctCarregaTipoAdm                        //
//#############################//
function fctCarregaTipoAdm() {
    
	var inteTipo = document.getElementById('inteTipoAdm').value;
	var oTipoAdm = document.getElementsByName('inteTipoAdministradora');

	if(inteTipo == ""){return;}  

	//if(!document.getElementById('inteTipoEmpresaAdm').value.isEmpty()) 
	//{	
		for(var indx =0; indx < oTipoAdm.length;indx ++) 
		{
			if(oTipoAdm[indx].value == inteTipo)
				oTipoAdm[indx].checked = true;			
			else
				oTipoAdm[indx].checked = false;					
		}
	//}
}
//#############################//
//                         fctCarregaRepresentante                        //
//#############################//
function fctCarregaRepresentante()
{

var arraRepresentantes 	= document.getElementById('varcListaRepresentante').value.slice(0,document.getElementById('varcListaRepresentante').value.length -2).split('#?');

var oList 				= document.getElementById('varcDepartamentos');

	if(!document.getElementById('varcListaRepresentante').value.isEmpty())
	{	
		intLength = oList.length;
		for(indx=0;indx < arraRepresentantes.length;indx+= 9)
		{
			oList.options[intLength] = new Option('Nome: '+ arraRepresentantes[indx],arraRepresentantes[indx]);
			intLength ++;
			oList.options[intLength] = new Option('Função: '+ arraRepresentantes[indx + 1], arraRepresentantes[indx + 1]);
			intLength ++;
			oList.options[intLength] = new Option('Departamento: '+ arraRepresentantes[indx + 3], arraRepresentantes[indx + 2]);
			intLength ++;
			oList.options[intLength] = new Option('Data de Nasc.: '+ arraRepresentantes[indx + 4], arraRepresentantes[indx + 4]);
			intLength ++;
			oList.options[intLength] = new Option('Email: '+ arraRepresentantes[indx + 5], arraRepresentantes[indx + 5]);
			intLength ++;
			oList.options[intLength] = new Option('Senha: Confidencial', arraRepresentantes[indx + 6]);
			intLength ++;
			oList.options[intLength] = new Option('Telefone: ('+ arraRepresentantes[indx + 7].slice(0,2) +')'+ arraRepresentantes[indx + 7].slice(2,arraRepresentantes[indx + 7].length),arraRepresentantes[indx + 7]);
			intLength ++;
			oList.options[intLength] = new Option('Celular: ('+ arraRepresentantes[indx + 8].slice(0,2)+')'+ arraRepresentantes[indx + 8].slice(2,arraRepresentantes[indx + 8].length), arraRepresentantes[indx + 8]);
			intLength ++;
			oList.options[intLength] = new Option('--------------------------------------------------------------------------------------------------------------','-1');
			intLength ++;
		}	
	}

}
//#############################//
//                         fctCarregaSocioPJ                        //
//#############################//
function fctCarregaSocioPJ(){

var arraSocioPj =  document.getElementById('varcListaSocioPJ').value.slice(0,document.getElementById('varcListaSocioPJ').value.length -2).split('#?')
var oList = document.getElementById('varcSocioPJ');

	if(!document.getElementById('varcListaSocioPJ').value.isEmpty())
	{	
		indxLength = oList.length;
		for(indx=0;indx < arraSocioPj.length;indx +=8)
		{
			oList.options[indxLength] = new Option('Razão Social: '+ arraSocioPj[indx], arraSocioPj[indx]);
			indxLength ++;
			oList.options[indxLength] = new Option('Atividade: '+ arraSocioPj[indx + 1],arraSocioPj[indx + 1]);
			indxLength ++;
			oList.options[indxLength] = new Option('Capital: '+ arraSocioPj[indx + 2], arraSocioPj[indx + 2]);
			indxLength ++;
			oList.options[indxLength] = new Option('Quota: '+ arraSocioPj[indx + 3],arraSocioPj[indx + 3]);
			indxLength ++;
			oList.options[indxLength] = new Option('Endereço: '+ arraSocioPj[indx + 4], arraSocioPj[indx + 4]);
			indxLength ++;
			oList.options[indxLength] = new Option("Telefone: "+ '('+arraSocioPj[indx + 5].slice(0,2) +')'+ arraSocioPj[indx + 5].slice(2,arraSocioPj[indx + 5].length),arraSocioPj[indx + 5]);
			indxLength ++;
			oList.options[indxLength] = new Option('E-mail: '+ arraSocioPj[indx + 6],arraSocioPj[indx + 6]);
			indxLength ++;
			oList.options[indxLength] = new Option('Diretor Contato: '+ arraSocioPj[indx + 7],arraSocioPj[indx + 7]);
			indxLength ++;
			oList.options[indxLength] = new Option('-------------------------------------------------------------------------------------------------------','-1');
			indxLength ++;
		}	
	}
}
//#############################//
//                         fctCarregaSocioPF                        //
//#############################//
function fctCarregaSocioPF(){

var arraSocioPf	= document.getElementById('varcListaSocioPF').value.slice(0,document.getElementById('varcListaSocioPF').value.length -2).split('#?');
var oList 		= document.getElementById('varcSocioPF');
	
	if(!document.getElementById('varcListaSocioPF').value.isEmpty())
	{
		indxLength = oList.length;
		for(indx=0;indx < arraSocioPf.length;indx += 4)
		{
			oList.options[indxLength] = new Option('Nome: '+ arraSocioPf[indx],arraSocioPf[indx]);
			indxLength ++;
			oList.options[indxLength] = new Option('Participação: '+ arraSocioPf[indx + 1],arraSocioPf[indx + 1]);
			indxLength ++;
			oList.options[indxLength] = new Option('Cargo: '+ arraSocioPf[indx + 2],arraSocioPf[indx + 2]);
			indxLength ++;
			oList.options[indxLength] = new Option('Data Nasc.: '+ arraSocioPf[indx + 3],arraSocioPf[indx + 3]);
			indxLength ++;
			oList.options[indxLength] = new Option('-------------------------------------------------------------------------------------------------------','-1');
			indxLength ++;
		}
	}
}
//#############################//
//                         fctCarregaFiliais                        //
//#############################//
function fctCarregaFiliais(){
var arraFiliais	= document.getElementById('varcListaFiliais').value.slice(0,document.getElementById('varcListaFiliais').value.length -2).split('#?');
var oList 		= document.getElementById('varcFiliais');
	
	if(!document.getElementById('varcListaFiliais').value.isEmpty())
	{
		indxLength = oList.length;
		for(indx=0;indx < arraFiliais.length;indx += 12)
		{
//			oList.options[indxLength] = new Option('Nome: '+ arraFiliais[indx], arraFiliais[indx]);
//			indxLength ++;
//			oList.options[indxLength] = new Option('Endereço: '+ arraFiliais[indx + 1] , arraFiliais[indx + 1]);
//			indxLength ++;
//			oList.options[indxLength] = new Option('Número: '+ arraFiliais[indx + 2] , arraFiliais[indx + 2]);
//			indxLength ++;
//			oList.options[indxLength] = new Option('Complemento: '+ arraFiliais[indx + 3], arraFiliais[indx + 3]);
//			indxLength ++;
//			oList.options[indxLength] = new Option('Bairro: '+ arraFiliais[indx + 4],arraFiliais[indx + 4]);
//			indxLength ++;
			oList.options[indxLength] = new Option('Cidade: '+ arraFiliais[indx + 5],arraFiliais[indx + 6]);
			indxLength ++;
			oList.options[indxLength] = new Option('UF: '+ arraFiliais[indx + 7], arraFiliais[indx + 8]);
			indxLength ++;
//			oList.options[indxLength] = new Option('CEP: '+ arraFiliais[indx + 9],arraFiliais[indx + 9]);
//			indxLength ++;
//			oList.options[indxLength] = new Option('Telefone: '+ '('+ arraFiliais[indx + 10].slice(0,2) +')'+ arraFiliais[indx + 10].slice(2,arraFiliais[indx + 10].length),arraFiliais[indx + 10]);
//			indxLength ++;
//			oList.options[indxLength] = new Option('Email: '+ arraFiliais[indx + 11], arraFiliais[indx + 11]);
//			indxLength ++;			
			oList.options[indxLength] = new Option('-------------------------------------------------------------------------------------------------------','-1');
			indxLength ++;
		}
	}
}
//#############################//
//                         fctHabilitaCampo                 	       //
//#############################//
function fctHabilitaCampo(status){

var oAdmTipo = document.getElementById('varcRevenda_fabricante');

	if(status){
		oAdmTipo.value = "";
		oAdmTipo.readOnly = true
	}
	else
		oAdmTipo.readOnly = false
}
//#############################//
//                    fctCarregaTipoAdmVinculado                 //
//#############################//
function fctCarregaTipoAdmVinculado(){

var inteTipoAdm = document.getElementById('inteTipoAdm').value;

var oAdmTipo = document.getElementById('varcRevenda_fabricante');
		
	if(inteTipoAdm == ""){return;}
		
	if(inteTipoAdm == 1) 
		oAdmTipo.readOnly = true;
	else
		oAdmTipo.readOnly = false;
}
//#############################//
//                         fctValidaCnpj    		                    //
//#############################//
function fctValidaCnpj(){
var oFormBusca	=	document.getElementById("frm_filie_se");
var varcCnpj 	=	document.getElementById('varcCNPJ').value;
var varcCtrl 	=	document.getElementById('varcCNPJCtrol').value;
	
	if(! IsValidCNPJ(varcCnpj,varcCtrl)){
		alert("Por favor, informe um CNPJ válido.");
		document.getElementById('varcCNPJ').value = "";
		document.getElementById('varcCNPJCtrol').value = "";
		document.getElementById('varcCNPJ').focus();
		return;
	}

	oAjax.oParametros.Adicionar(new Parametro("intePassos", 1));
	oAjax.oParametros.Adicionar(new Parametro("varcCNPJ", varcCnpj + varcCtrl));
	oAjax.url			= "http_actions/act_verifica_cnpj.asp";
	oAjax.metodo 		= "GET";
	oAjax.callBack		= fctVerificaCNPJ;
	oAjax.Enviar();
}
function fctVerificaCNPJ() {
	var inteStatus;
	
	//Verificando o status da página
	if (oAjax.VerificarStatus() == 4) {
		//Recuperando o resultado como texto puro
		inteStatus = parseInt(oAjax.getText, 10);
		
		if (inteStatus == 0)
		{
			alert('Não foi possível localizar o CNPJ da administradora junto aos registros do Banco Central. Contate o administrador.');
			return;
		}
		
		document.getElementById('frm_filie_se').action += '&inteAcao='+ inteStatus;
		document.getElementById('frm_filie_se').submit();
	}
}

//#############################//
//    fctVerificaCategoria     //
//#############################//
function fctVerificaCategoria(Status){
var varcCategoria;
var oTable = document.getElementById('tbSegmentos');
var varcStatus = Status;
var inteTipoAdm = document.getElementById('inteTipoAdm').value;
		
	if(inteTipoAdm == ""){return;}
  
	if (varcStatus == 'Alterar'){
		varcCategoria = 2;
	}else{
		varcCategoria = document.getElementById('varcCategoriaAdministradora').selectedIndex;
	}

	switch (varcCategoria)
	{
		case 2:		
			document.getElementsByName('inteTipoAdministradora')[0].disabled = false;
			document.getElementsByName('inteTipoAdministradora')[1].disabled = false;
			document.getElementsByName('inteTipoAdministradora')[2].disabled = false;
			
			//Habilita os checkbox do Passo 8
			for(var iTable = 0; iTable < oTable.childNodes.length; iTable++){
				for(var iTbody = 0; iTbody < oTable.childNodes[iTable].childNodes.length; iTbody++){
					for(var iTr = 0; iTr < oTable.childNodes[iTable].childNodes[iTbody].childNodes.length; iTr++){
						for(var iTd = 0; iTd < oTable.childNodes[iTable].childNodes[iTbody].childNodes[iTr].childNodes.length; iTd++){
							if (oTable.childNodes[iTable].childNodes[iTbody].childNodes[iTr].childNodes[iTd].tagName != null && oTable.childNodes[iTable].childNodes[iTbody].childNodes[iTr].childNodes[iTd].type != null){
								if(oTable.childNodes[iTable].childNodes[iTbody].childNodes[iTr].childNodes[iTd].tagName.toLowerCase() == 'input' && oTable.childNodes[iTable].childNodes[iTbody].childNodes[iTr].childNodes[iTd].type.toLowerCase() == 'checkbox')
									oTable.childNodes[iTable].childNodes[iTbody].childNodes[iTr].childNodes[iTd].disabled = false;
							}
						}
					}
				}
			}
			break;
		case 1:
			document.getElementsByName('inteTipoAdministradora')[0].disabled = true;
			document.getElementsByName('inteTipoAdministradora')[1].disabled = true;
			document.getElementsByName('inteTipoAdministradora')[2].disabled = true;
			
			//Desabilita os checkbox do Passo 8
			for(var iTable = 0; iTable < oTable.childNodes.length; iTable++){
				for(var iTbody = 0; iTbody < oTable.childNodes[iTable].childNodes.length; iTbody++){
					for(var iTr = 0; iTr < oTable.childNodes[iTable].childNodes[iTbody].childNodes.length; iTr++){
						for(var iTd = 0; iTd < oTable.childNodes[iTable].childNodes[iTbody].childNodes[iTr].childNodes.length; iTd++){
							if (oTable.childNodes[iTable].childNodes[iTbody].childNodes[iTr].childNodes[iTd].tagName != null && oTable.childNodes[iTable].childNodes[iTbody].childNodes[iTr].childNodes[iTd].type != null){
								if(oTable.childNodes[iTable].childNodes[iTbody].childNodes[iTr].childNodes[iTd].tagName.toLowerCase() == 'input' && oTable.childNodes[iTable].childNodes[iTbody].childNodes[iTr].childNodes[iTd].type.toLowerCase() == 'checkbox')
									oTable.childNodes[iTable].childNodes[iTbody].childNodes[iTr].childNodes[iTd].disabled = false;
							}
						}
					}
				}
			}
		break;
	}
}
//#############################//
//                         fctHabilitaOutrosBens                        //
//#############################//
function fctHabilitaOutrosBens(oCampoCheckBox){
	var varcCampoOutrosBens = document.getElementById('varcSegmentoOutrosBens');

	if (oCampoCheckBox.checked)
		varcCampoOutrosBens.disabled = false;
	else
		varcCampoOutrosBens.disabled = true;
}

//###################################//
//#          fctValidaData          #//
//###################################//
function fctValidaData() {
		objeData	= document.getElementById('sdtaNascimentoRepresentante');
		if(objeData.value == '')
			return;

		dia	=	objeData.value.split("/")[0];
		mes	=	objeData.value.split("/")[1];
		ano	=	objeData.value.split("/")[2];				
				
		if(!IsValidDate(dia,mes,ano))
			{
			alert('Data inválida. Por favor preencha corretamente.');
			objeData.focus();
			}
	}
	
//################################################################################//
//  Function:  fctVerificaData()                                                  //
//  Description:  Formata a Data colocando as "/" automaticamente                 //
//################################################################################//
function fctVerificaData() {
	var input		= document.getElementById('sdtaNascimentoRepresentante');
	if( (event.keyCode<48) || (event.keyCode>57) )
		event.returnValue		= false; 
	else if( (input.value.length==2) || (input.value.length==5))
		input.value					= input.value +"/";
}	
//###################################//
//#          IsValidDate            #//
//###################################//
function IsValidDate(dia,mes,ano) {
	ano = parseFloat(ano);
	mes = parseFloat(mes);
	dia = parseFloat(dia);
	if(ano.toString().length < 4) return false;
	if(dia<1 || dia>31) return false;
	if(mes<1 || mes>12) return false;
	if(mes==2)
	{
		if(ano%4==0 && (ano%100!=0 || ano%400==0) && dia>29) return false;
		if(ano%4!=0 && (ano%100==0 || ano%400!=0) && dia>28) return false;
	}
	if((mes==4 || mes==6 || mes==9 || mes==11) && dia>30) return false;
	if((mes==1 || mes==3 || mes==5 || mes==7 || mes==8 || mes==10 || mes==12) && dia>31) return false;
	return true;
}