//------------------------------------------------------------------------------------
// Mostra Div

//Script para controlar DIV
var isIE=document.all?true:false;
var isDOM=document.getElementById?true:false;
var isNS4=document.layers?true:false;

/* _w : which ID (1) or (2) */
/* _h : (h)ide or (s)how */
function mostraDiv(_w,_h) {
  if (isDOM){
    if (_h=='s') document.getElementById(_w).style.display='';
    if (_h=='h') document.getElementById(_w).style.display='none';
	}
  
  else if (isIE){
    if (_h=='s') eval("document.all."+_w+".style.visibility='visible';");
    if (_h=='h') eval("document.all."+_w+".style.visibility='hidden';");
	}
  
  else if(isNS4){
    if (_h=='s') eval("document.layers['"+_w+"'].visibility='show';");
    if (_h=='h') eval("document.layers['"+_w+"'].visibility='hide';");
	}
}

function PreencheCombo(select, value, IndUfTodos, IndMunicTodos, PagSRD){	

	if(document.all('strMunicipio').value != ''){
		document.all('strMunicipio').value = '';
	}
	// muda a barra de status do browse mostrando a mensagem abaixo
	window.status = 'Carregando dados...';
	// cria uma instancia do DOM para executar a página
	var xml = new ActiveXObject("Microsoft.XMLDOM");
			
	// informa que é só de ida
	xml.async = false;
	// executa a página
	// verifica se é o combo dos plano

//location.href = 'bancoXML.asp?SiglaUF='+value+'&vIndUfTodos='+IndUfTodos+'&vIndMunicipioTodos='+IndMunicTodos+'&PagSRD='+PagSRD 
///*
	xml.load('bancoXML.asp?SiglaUF='+value+'&vIndUfTodos='+IndUfTodos+'&vIndMunicipioTodos='+IndMunicTodos+'&PagSRD='+PagSRD );
	
	if (xml.xml != '') {
		// cria outra instancia do DOM para executar o XSL
		var xsl = new ActiveXObject("Microsoft.XMLDOM");
		xsl.async = false;
		xsl.load("XSL.asp?Estilo=combo");

		while(select.length > 0){select.remove(0);}
	
		var strSelect = select.outerHTML;
		select.outerHTML = strSelect.substring(0, strSelect.length - 9) + xml.transformNode(xsl) + '</SELECT>';
	}
	window.status = '';	
//*/
}

function funSelecAcao(){
	
	if(document.all('NumServico').value == '231'){			
		mostraDiv('DivProcesso','s');
	}
	else{		
		mostraDiv('DivProcesso', 'h');
	}
	
	if(document.all('OP').value == '1' && document.all('NumServico').value == '221' && (document.all('PagSRD').value != '/SRD/CADASTROADM/OUTORGA/OUTORGA.ASP' && document.all('PagSRD').value != 'CARACESTACAO')){
		mostraDiv('DivFrequenciaOT','s');
	}
	else{
		mostraDiv('DivFrequenciaOT','h');		
	}
	
	if((document.all('PagSRD').value == 'CaracEstacao' || document.all('PagSRD').value == 'DESCSISTEMA') && (document.all('OP').value == '5')){	
		mostraDiv('DivSituacao','s');
	}
	else{
		mostraDiv('DivSituacao','h');
	}
}

function funSelecServico(){
	
	if(document.all('NumServico').value == '231'){	
		mostraDiv('DivProcesso','s');
	}				
	else{
		mostraDiv('DivProcesso','h');		
	}

	if(document.all('NumServico').value == '221' && document.all('OP').value == '1' && (document.all('PagSRD').value != '/SRD/CADASTROADM/OUTORGA/OUTORGA.ASP' || document.all('PagSRD').value != 'PLANOBASICO' || document.all('PagSRD').value != 'CARACESTACAO')){			
		mostraDiv('DivFrequenciaOT','s');		
		transformaCampoObrigatorio(document.all('IdtCanalizacaoMedPortadoraAudio'), 's');
	}	
	else{		
		mostraDiv('DivFrequenciaOT','h');
		transformaCampoObrigatorio(document.all('IdtCanalizacaoMedPortadoraAudio'), 'n');
	}
	
	if((document.all('PagSRD').value == 'CARACESTACAO' || document.all('PagSRD').value == 'DESCSISTEMA') && (document.all('OP').value == '5')){	

		mostraDiv('DivSituacao','s');
	}
	else{
		mostraDiv('DivSituacao','h');		
	}	
}

function confirma(){
	if(document.all('PagSRD').value == 'CARACESTACAO' && document.all('OP').value == '1' && document.all('NumServico').value == '730'){
		document.all('acao').value = '';
		document.frmListagem.action = '/SRD/CadastroTec/CaracEstacao/Tela.asp';
	}
	else{
		document.all('acao').value = 'listagem';
		document.frmListagem.action = '/SRD/TelaListagem.asp';
	}	
	
	document.frmListagem.submit();
}

function funSubmit(){
	var strAction;
	if(document.all('PagSRD').value == '/SRD/RADCOM/OUTORGA/PEDIDO/ADMPEDIDO.ASP' && 
		document.all('NumServico').value == '231' && document.all('op').value != '1'){
			document.all('acao').value = 'listagem';
			strAction = '/SRD/TelaListagem.asp';
		}
	else{	
		strAction = document.all('strAction').value;
	}		
	
	//Quando for Alteração ou Exclusão do Plano básico - Submeter para Telalistagem novamente
	if(document.all('PagSRD').value == 'PLANOBASICO' && document.all('OP').value != '1'){
		document.all('acao').value = 'listagem';
		strAction = '/SRD/TelaListagem.asp';
	}
	
	if(document.all('PagSRD').value == 'CARACESTACAO' & document.all('OP').value == '1' & document.all('NumServico').value=='730'){
		document.all('acao').value = '';
		strAction = '/SRD/CadastroTec/CaracEstacao/Tela.asp';
	}

	//Apenas para a tela Quantidade de Canais por fase - Djalma
	if(document.all('PagSRD').value == '/SRD/RELATORIOS/RADIODIFUSAO/RELQTDFASESERVICO.ASP') {
		if((document.all('MES').value != '') && (document.all('ANO').value != '')) {
			if ((document.all('DtInicial').value != '') || (document.all('DtFinal').value != '')) {
				alert('Preencha apenas uma ou outra opção de consulta.');
				return;
			}
		}

		if((document.all('DtInicial').value != '') && (document.all('DtFinal').value != '')) {
			if ((document.all('MES').value != '') || (document.all('ANO').value != '')) {
				alert('Preencha apenas uma ou outra opção de consulta.');
				return;
			}
		}

		if(document.all('MES').value != '') {
			if (document.all('ANO').value == '') {
				alert('Informe o ano.');
				return;
			}
		}

		if(document.all('ANO').value != '') {
			if (document.all('MES').value == '') {
				alert('Informe o mês.');
				return;
			}
		}

		if(document.all('DtInicial').value != '') {
			if (document.all('DtFinal').value == '') {
				alert('Informe a Data Final.');
				return;
			}
		}

		if(document.all('DtFinal').value != '') {
			if (document.all('DtInicial').value == '') {
				alert('Informe a Data Inicial.');
				return;
			}
		}

		strAction = '/SRD/Relatorios/Radiodifusao/RelQtdFaseServico.asp'

	}

	document.frmListagem.action = strAction;
	document.frmListagem.submit();

}

function TrataNumProc(){
	if(document.all('NumProcesso').value != ''){			
		transformaCampoObrigatorio(document.all('SiglaUF'), 'n');
		transformaCampoObrigatorio(document.all('CodMunicipio'), 'n');
	}
	else{
		transformaCampoObrigatorio(document.all('SiglaUF'), 's');
		transformaCampoObrigatorio(document.all('CodMunicipio'), 's');
	}
}

function Redir(strAction, PagSRD, OP, NumServico, SiglaServico, SiglaUF, CodMunicipio, IdtPlanoBasico, IdtPedidoRADCOM, IdtHabilitacao, IdtEstacao, NumProcesso, NumCnpjCpf, NumFistel, Frequencia, IndFase){
	var strAction = strAction;
	document.all('acao').value = '';
	document.all('PagSRD').value = PagSRD;
	document.all('OP').value = OP;
	document.all('NumServico').value = NumServico;
	document.all('SiglaServico').value = SiglaServico;
	document.all('SiglaUF').value = SiglaUF;
	document.all('CodMunicipio').value = CodMunicipio;
	document.all('IdtPlanoBasico').value = IdtPlanoBasico;
	document.all('IdtEstacao').value = IdtEstacao;
	document.all('IdtHabilitacao').value = IdtHabilitacao;
	document.all('IdtPedidoRADCOM').value = IdtPedidoRADCOM;
	document.all('NumProcesso').value = NumProcesso;
	document.all('NumCnpjCpf').value = NumCnpjCpf;
	document.all('NumFistel').value = NumFistel;
	document.all('Frequencia').value = Frequencia;	
	document.all('IndFase').value = IndFase;
	
	/*
	alert('Frequencia: ' + Frequencia);		
	alert('NumFistel: ' + NumFistel);		
	alert('NumCnpjCpf: ' + NumCnpjCpf);		
	alert('NumProcesso: ' + NumProcesso);		
	alert('IdtPedidoRADCOM: ' + IdtPedidoRADCOM);		
	alert('IdtHabilitacao: ' + IdtHabilitacao);		
	alert('IdtPlanoBasico: ' + IdtPlanoBasico);	
	alert('CodMunicipio: ' + CodMunicipio);	
	alert('SiglaUF: ' + SiglaUF);	
	alert('SiglaServico: ' + SiglaServico);		
	alert('acao: ' + document.all('acao').value);	
	alert('PagSRD: ' + PagSRD);		
	alert('OP: ' + OP);		
	alert('NumServico: ' + NumServico);		
	alert('IndFase: ' + IndFase);	
	*/
	
		
	if(PagSRD == 'CARACESTACAO' & OP == '1' & NumServico == '730'){
		document.all('acao').value = '';
		strAction = '/SRD/CadastroTec/CaracEstacao/Tela.asp';
	}

	if(PagSRD.substring(0,24) == '/SRD/CHAMADA/LICENCA.ASP'){		
		strAction = '/SRD/chamada/Licenca.asp?pNumFistel='+ NumFistel+'&pNumServico='+NumServico+'&acao=c';
	}	

	if(PagSRD == '/SRD/EmissaoDoc/GerarResumoAtoWord.asp'.toUpperCase()){	
		window.open('/SRD/EmissaoDoc/GerarResumoAto/Tela.asp?FlagControle=1&NumServico='+document.all('NumServico').value+'&IdtPlanoBasico='+document.all('IdtPlanoBasico').value+'&IdtPedidoRADCOM='+document.all('IdtPedidoRADCOM').value+'&IdtHabilitacao='+document.all('IdtHabilitacao').value,'janelaextrato','height=200,width=400;top=600;left=800;fullscreen=0;toolbar=0;menubar=0;scrollbars=0');
	}

	document.frmListagem.action = strAction;
	document.frmListagem.submit();
}
