varZero	= "000";

// validação dos parâmetros da tela
function confirmarconsulta(plataforma, botao){
	if(validaSubmitInterface()){
	    if (document.getElementById('pNumCnpjCpf').value != '' && document.getElementById('IdtSolicitacaoServico').value != '')
	    {
			document.getElementById('acao').value = 'n';
	    }
	    else if (document.getElementById('pNumCnpjCpf').value == '' && document.getElementById('IdtSolicitacaoServico').value == '' && plataforma == 'E')
	    {
			document.getElementById('acao').value = 'n';
	    }
	    else
	    {
			document.getElementById('acao').value = 'c';
		}
		document.frmTela.submit();
	}
}

function confirmar(botao){
	if(document.getElementById('pNumCpfSolicitante') !=	null){
		if(document.getElementById('pNumCpfSolicitante').value == '' ){
			alert('Entidade Solicitante inválida!');
			document.getElementById('divsolicitante').style.display='';
			document.getElementById('divsolicitacao').style.display='none';
			document.getElementById('pNumCpfSolicitante').focus();
			return false;				
		}
	}

	if(document.getElementById('NomeSocilicitante') !=	null){
		if(document.getElementById('NomeSocilicitante').value == '' ){
			alert('Nome da Entidade Solicitante inválido!');
			document.getElementById('divsolicitante').style.display='';
			document.getElementById('divsolicitacao').style.display='none';
			document.getElementById('NomeSocilicitante').focus();
			return false;				
		}
	}

	if(document.getElementById('EndEletronico') !=	null){
		if(document.getElementById('EndEletronico').value.replace(' ','') == '' ){
			alert('A Entidade Solicitante não possui um Endereço Eletrônico cadastrado.\nFavor preencher a informação.');
			document.getElementById('divsolicitante').style.display='';
			document.getElementById('divsolicitacao').style.display='none';
			document.getElementById('EndEletronico').focus();
			return false;
		}	
	}

  if(document.getElementById('pNumCnpjCpfSol') !=	null){
    if(document.getElementById('pNumCnpjCpfSol').value == '' ) {
      alert('Entidade Solicitada inválida!');
      document.getElementById('pNumCnpjCpfSol').focus();
      return false;				
    }
  }

	if(document.getElementById('NomeSolicitado') !=	null){
		if(document.getElementById('NomeSolicitado').value == '' ){
			alert('Nome da Entidade Solicitada inválido!');
			document.getElementById('pNumCnpjCpfSol').focus();
			return false;				
		}
	}

	if(document.getElementById('EndEletronicoSolicitado') !=	null) {
		if(document.getElementById('EndEletronicoSolicitado').value.replace(' ','') == '' ) {
			alert('A Entidade Solicitada não possui um Endereço Eletrônico.\nFavor solicitar a atualização do cadastro à Anatel ou selecione outra Entidade.');
			document.getElementById('EndEletronicoSolicitado').focus();
			return false;
		}
	}

	if(document.getElementById('IndConfirmacao').checked == false) {
		alert('Leia atentamente a declaração e confirme.');
		document.getElementById('IndConfirmacao').focus();
		return false;
	}

  if(document.getElementById('UsuarioExterno').value == 'False') {
		if(document.getElementById('IndMovimentoEmpresa').checked == true) {
			if(document.getElementById('txtComentario').value == '') {
				alert('Preencha o texto com o motivo da recusa da solicitação.');
				document.getElementById('txtComentario').focus();
				return false;
			}
		}

    if((document.getElementById('IndMovimentoEmpresa').checked == false && document.getElementById('IndMovimentoAnalise').checked == false) || (document.getElementById('IndMovimentoEmpresa').checked == true && document.getElementById('IndMovimentoAnalise').checked == true)) {
      alert('Aprove ou Reprove a solicitação.');
			document.getElementById('IndMovimentoAnalise').focus();
      return false;
		}
	}

	if(validaSubmitInterface()) {
		document.getElementById('acao').value = 's';
		document.frmTela.action = 'banco.asp';
		document.frmTela.submit();
	}
}

function AdicionarSolicitacao(NumCpfSolicitante) {
	document.getElementById('IdtSolicitacaoServico').value = '';
	if (NumCpfSolicitante != '') {
		document.getElementById('pNumCnpjCpf').value = NumCpfSolicitante;
	}

	document.getElementById('acao').value = 'n';
	document.frmTela.submit();
}

//-------------------------------------------------------------------------					  
function Limpar(tipoObjeto, ref) {
	
	var el = document.all.tags(tipoObjeto);
	if (el!=null) {
		for(i=0;i<el.length;i++) {
			if(el[i].referencia == ref) el[i].value = '';
		}
	}
}

function VerificaSolicitadoXML() {
	varStatusCNPJCPF = false;			
	// Verifica se é um CNPJ ou CPF
	if (document.frmTela.pNumCnpjCpfSol.value.length > 0 && document.frmTela.pNumCnpjCpfSol.value.length <=14) 
	{
	    if (document.frmTela.pNumCnpjCpfSol.value.length == 11)
	    {
		    varStatusCNPJCPF = ValidaCPFSemMascara(document.frmTela.pNumCnpjCpfSol,"Sim");
		}
		else
		{
		    varStatusCNPJCPF = ValidaCNPJSemMascara(document.frmTela.pNumCnpjCpfSol,"Sim");
		}
	}
	else {
		varStatusCNPJCPF = true;
	}

	if (varStatusCNPJCPF && document.getElementById('pNumCnpjCpfSol').value != '') 
	{
		window.status = 'Localizando os Dados do Solicitado ...';
    
		var xml = new ActiveXObject("Microsoft.XMLDOM");
		xml.async = false;
		xml.load('bancoXML.asp?NumCnpjCpfSol=' + document.frmTela.pNumCnpjCpfSol.value);
    
		if (xml.xml != '') 
		{
			var atributo = xml.documentElement.childNodes.item(1).childNodes.item(0).attributes;
			
			texto = atributo.item(0).text;
			var arrTxt = texto.split('$');
			
			if (atributo.item(0).name == 'DadosSolicitado') {
				document.getElementById('IdtEntidadeSolicitada').value = arrTxt[0];
				document.getElementById('NomeSolicitado').value = arrTxt[1];
				document.getElementById('CodCep').value = arrTxt[2];
				document.getElementById('EndLogradouro').value = arrTxt[3];
				document.getElementById('EndNumero').value = arrTxt[4];
				document.getElementById('EndComplemento').value = arrTxt[5];
				document.getElementById('EndEletronicoSolicitado').value = arrTxt[6];
				document.getElementById('NomeMunicipio').value = arrTxt[7];
				document.getElementById('SiglaUF').value = arrTxt[8];
				document.getElementById('NumCodigoNacional').value = arrTxt[9];
				document.getElementById('NumTelefone').value = arrTxt[10];
				document.getElementById('incluiEntidadeSolicitada').value = 'N';
			}
			else {
			    if (document.getElementById('incluiEntidadeSolicitada').value != 'C')
			    {
    				alert('Dados da Entidade Solicitada não localizados.');
                }
				document.getElementById('IdtEntidadeSolicitada').value = '';
				document.getElementById('NomeSolicitado').value = '';
				document.getElementById('CodCep').value = '';
				document.getElementById('EndLogradouro').value = '';
				document.getElementById('EndNumero').value = '';
				document.getElementById('EndComplemento').value = '';
				document.getElementById('EndEletronicoSolicitado').value = '';
				document.getElementById('NomeMunicipio').value = '';
				document.getElementById('SiglaUF').value = '';
				document.getElementById('NumCodigoNacional').value = '';
				document.getElementById('NumTelefone').value = '';
           		document.getElementById('incluiEntidadeSolicitada').value = 'S';

				document.frmTela.pNumCnpjCpfSol.focus();
			}
		}
		else 
		{
		    if (document.getElementById('incluiEntidadeSolicitada').value != 'C')
		    {
    			alert('Dados não localizados.');
            }
			document.getElementById('IdtEntidadeSolicitada').value = '';
			document.getElementById('NomeSolicitado').value = '';
			document.getElementById('CodCep').value = '';
			document.getElementById('EndLogradouro').value = '';
			document.getElementById('EndNumero').value = '';
			document.getElementById('EndComplemento').value = '';
			document.getElementById('EndEletronicoSolicitado').value = '';
			document.getElementById('NomeMunicipio').value = '';
			document.getElementById('SiglaUF').value = '';
			document.getElementById('NumCodigoNacional').value = '';
			document.getElementById('NumTelefone').value = '';
    		document.getElementById('incluiEntidadeSolicitada').value = 'S';

			document.frmTela.pNumCnpjCpfSol.focus();
		}
   		window.status = '';
	}
}

function VerificaSolicitanteXML() {
	varStatusCNPJCPF = false;			
	// Verifica se é um CNPJ ou CPF
	if (document.frmTela.pNumCpfSolicitante.value.length > 0 && document.frmTela.pNumCpfSolicitante.value.length <=11) 
	{
	    varStatusCNPJCPF = ValidaCPFSemMascara(document.frmTela.pNumCpfSolicitante,"Sim");
	}
	else {
		varStatusCNPJCPF = true;
	}

	if (varStatusCNPJCPF) 
	{
		window.status = 'Localizando os Dados do Solicitante ...';
    	varStatusLeitura = true;			

		var xml = new ActiveXObject("Microsoft.XMLDOM");
		xml.async = false;
		xml.load('bancoXML.asp?NumCpfSolicitante=' + document.frmTela.pNumCpfSolicitante.value);

		if (xml.xml != '') 
		{
			var atributo = xml.documentElement.childNodes.item(1).childNodes.item(0).attributes;
			
			texto = atributo.item(0).text;
			var arrTxt = texto.split('$');
			
			if (atributo.item(0).name == 'DadosSolicitante') 
			{
				for (i = 0; i < arrTxt.length; i++ ) 
				{
					document.getElementById('IdtEntidadeSolicitante').value = arrTxt[0];
					document.getElementById('NomeSolicitante').value = arrTxt[1];
					document.getElementById('CodCepSolicitante').value = arrTxt[2];
					document.getElementById('EndLogradouroSolicitante').value = arrTxt[3];
					document.getElementById('EndNumeroSolicitante').value = arrTxt[4];
					document.getElementById('EndComplementoSolicitante').value = arrTxt[5];
					document.getElementById('EndEletronico').value = arrTxt[6];
					document.getElementById('NomeMunicipioSolicitante').value = arrTxt[7];
					document.getElementById('SiglaUFSolicitante').value = arrTxt[8];
					document.getElementById('NumCodigoNacionalSolicitante').value = arrTxt[9];
					document.getElementById('NumTelefoneSolicitante').value = arrTxt[10];
            		document.getElementById('incluiEntidadeSolicitante').value = 'N';
				}
			}
			else 
			{
                if (document.getElementById('incluiEntidadeSolicitante').value != 'C')
                {
    			    alert('Dados da Entidade Solicitante não localizados.');
			    }
			    document.getElementById('IdtEntidadeSolicitante').value = '';
			    document.getElementById('NomeSolicitante').value = '';
			    document.getElementById('CodCepSolicitante').value = '';
			    document.getElementById('EndLogradouroSolicitante').value = '';
			    document.getElementById('EndNumeroSolicitante').value = '';
			    document.getElementById('EndComplementoSolicitante').value = '';
			    document.getElementById('NomeMunicipioSolicitante').value = '';
			    document.getElementById('SiglaUFSolicitante').value = '';
			    document.getElementById('NumCodigoNacionalSolicitante').value = '';
			    document.getElementById('NumTelefoneSolicitante').value = '';
			    document.getElementById('EndEletronico').value = '';
    		    document.getElementById('incluiEntidadeSolicitante').value = 'S';

			    document.frmTela.pNumCpfSolicitante.focus();
			}
		}
		else 
		{
            if (document.getElementById('incluiEntidadeSolicitante').value != 'C')
            {
    			alert('Dados não localizados.');
			}
		    document.getElementById('IdtEntidadeSolicitante').value = '';
		    document.getElementById('NomeSolicitante').value = '';
		    document.getElementById('CodCepSolicitante').value = '';
		    document.getElementById('EndLogradouroSolicitante').value = '';
		    document.getElementById('EndNumeroSolicitante').value = '';
		    document.getElementById('EndComplementoSolicitante').value = '';
		    document.getElementById('NomeMunicipioSolicitante').value = '';
		    document.getElementById('SiglaUFSolicitante').value = '';
		    document.getElementById('NumCodigoNacionalSolicitante').value = '';
		    document.getElementById('NumTelefoneSolicitante').value = '';
		    document.getElementById('EndEletronico').value = '';
		    document.getElementById('incluiEntidadeSolicitante').value = 'S';

		    document.frmTela.pNumCpfSolicitante.focus();
       	    window.status = 'Dados não localizados.';
		}
	    window.status = '';
	}
}

function replace( str , chSrc , chDst )
{
	//Preparar a variável para retorno
	var ret = "";

	//Percorrer a string toda rocando chSrc por chDst
	for( var i = 0 ; i < str.length ; i++ )
		if( str.charAt( i ) == chSrc )
			ret = ret + chDst;
		else
			ret = ret + str.charAt( i );
			
	return ret;
}

function navega(IdtSolicitacaoServico, NumCnpjCpf, acao){
	
	document.all('IdtSolicitacaoServico').value = IdtSolicitacaoServico;
	document.all('pNumCnpjCpf').value = NumCnpjCpf;
	document.all['acao'].value = acao;
	document.frmTela.submit();
}

function validaAndamentoEmpresaGerente(objName){
	if(objName == 'IndMovimentoEmpresa'){
		if (document.getElementById('IndMovimentoAnalise').checked){
			document.getElementById('IndMovimentoAnalise').checked = false;
		}
	}else if(objName == 'IndMovimentoAnalise'){
	    if (document.getElementById('IndMovimentoEmpresa').checked){
		    document.getElementById('IndMovimentoEmpresa').checked = false;
	    }
	}
}


function confirmaExclusao(IdtSolicitacaoServico, tipoExclusao){
	if (abreAviso("Esta opção excluirá todos os dados referentes à esta solicitação. Tem certeza que deseja continuar?")) {
		window.open('cancelaSolicitacao.asp?IdtSolicitacaoServico=' + IdtSolicitacaoServico+'&exclui=' + tipoExclusao);
	}
}

function IncluirEntidade(tipoentidade, indIncluiEntidade)
{
// tipoentidade = n - solicitante
// tipoentidade = s - solititando

    if (tipoentidade == 'n')
    {
        document.getElementById('incluiEntidadeSolicitante').value = 'C';
        VerificaSolicitanteXML();
        if (document.getElementById('incluiEntidadeSolicitante').value == 'S')
        {
            window.open('/STEL/Chamada/Entidade.asp?OP=I&varRotinaOrigem=Solicitacao&pNumCnpjCpf='+document.frmTela.pNumCpfSolicitante.value);
        }
        else
        {
            if (document.getElementById('incluiEntidadeSolicitante').value != 'C')
            {
                alert('Solicitante já cadastrado em nossas bases!');
	            document.frmTela.pNumCpfSolicitante.focus();
	        }
        }
    }
    else
    {
        document.getElementById('incluiEntidadeSolicitada').value = 'C';
        VerificaSolicitadoXML();
        if (document.getElementById('incluiEntidadeSolicitada').value == 'S')
        {
            window.open('/STEL/Chamada/Entidade.asp?OP=I&varRotinaOrigem=Solicitacao&pNumCnpjCpf='+document.frmTela.pNumCnpjCpfSol.value);
        }
        else
        {
            if (document.getElementById('incluiEntidadeSolicitada').value != 'C')
            {
                alert('Solicitado já cadastrado em nossas bases!');
	            document.frmTela.pNumCnpjCpfSol.focus();
	        }
        }
    }
}

function marcarTodos(obj){
	var qtde = 0
	for (var i=0; i<=document.all.tags('input').length-1; i++) {
		if (document.all.tags('input')[i].type == 'checkbox' && document.all.tags('input')[i].disabled == false) {
			if (document.all.tags('input')[i].name.indexOf('CheckAprovacao') != -1){
				document.all.tags('input')[i].checked = true;
				document.getElementById('hdnMarcado').value = document.getElementById('hdnMarcado').value + document.all.tags('input')[i].value + ',';
			}
		}
	}
}


function desmarcarTodos(obj)
{
	for (var i=0; i<=document.all.tags('input').length-1; i++) {
		if (document.all.tags('input')[i].type == 'checkbox') {
			if (document.all.tags('input')[i].name.indexOf('CheckAprovacao') != -1) {
				document.all.tags('input')[i].checked = false;
			}
		}
	}
	document.getElementById('hdnMarcado').value = '';
}
function verificaAprovacao(obj){
	
	if(obj.checked==true)
	{
		//insere no hdnMarcado
		document.frmTela.hdnMarcado.value = document.frmTela.hdnMarcado.value + obj.value + ',';
		
	}else{

		//retira do hdnMarcado
		var s = document.frmTela.hdnMarcado.value.indexOf(obj.value+',')
		if(s!=-1)
		{
			document.frmTela.hdnMarcado.value = document.frmTela.hdnMarcado.value.substring(0, s) + document.frmTela.hdnMarcado.value.substring(s+1+obj.value.length);
		}
	}
}

function AprovarSolicitacoes() {
    if (document.getElementById('hdnMarcado').value != '')
    {
	    if (abreAviso("As solicitações marcadas serão encaminhadas para o próximo movimento. Deseja continuar?")) {
		    document.getElementById('hdnMarcado').value = document.getElementById('hdnMarcado').value.substring(0,document.getElementById('hdnMarcado').value.length-1)
		    document.all('acao').value = 'APROVA';
		    document.frmTela.action = 'banco.asp'
		    document.frmTela.submit();
	    }
	}
}


