function mostraMsg(msg,i){
	if (msg !=''){
		document.getElementById('ajuda',i).innerHTML = msg;
	}
}

function Selecionado()
{
	if (document.frmacao.acao.value != 'c')
		if((document.frmacao.pConsulta0.checked) && (document.frmacao.pHora.value == ''))
			{
			alert("Para consultas por Hora o campo: Hora deve ser preenchido");
			document.getElementById('pHora').focus();
			return false;
			}

	if (document.frmacao.LDN.value.toLowerCase() == 'false') 
		{
		if (document.getElementById('pMudou').value == 'X')
			{
			exibirRegiao(document.getElementById('pCodPais').value);
					
			if (document.frmacao.pRegiao.style.display == 'none') 
				{
				document.frmacao.pIndRegiaoPais.value = 0;
				document.frmacao.pIndTodoPais.value = 0;

				document.frmacao.acao.value = 'c';
				document.frmacao.submit();
				return true;
				}
			}
		else
			{
			if (document.frmacao.acao.value != 'c')
				{
				if (document.frmacao.pRegiao.style.display != 'none') 
					{
					var combo = document.getElementById('pRegiao');
					var arValor = combo.options[combo.options.selectedIndex].value.split("$");

					if (arValor[0] == 999) 
						{
						document.frmacao.pIndTodoPais.value = 1;
						}
					else 
						{
						document.frmacao.pIndTodoPais.value = 0;
						}
										
					document.frmacao.pIndRegiaoPais.value = 1;
					}
				else
					{
					document.frmacao.pIndRegiaoPais.value = 0;
					document.frmacao.pIndTodoPais.value = 0;
					}
				}
			
			document.frmacao.acao.value = 'c';
			document.frmacao.submit();
			return true;
			}
		}
	else
		{
		document.frmacao.acao.value = 'c';
		document.frmacao.submit();
		return true;
		}
}

function entrarParametros()
{
	document.frmacao.acao.value = 'p';
	document.frmacao.submit();
    return true;
}

function abre(janela) 
{
	hwnd = window.open(janela,"LocDet","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=620,height=410,left=200,Align=center");
	hwnd.focus();
}

function Sugestoes() 
{
	window.open("mailto:sipt@anatel.gov.br","LocDet","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=620,height=410,left=200,Align=center");
}

function Instrucoes() 
{
	abre('Instrucoes.asp?LDN='+document.frmacao.LDN.value);
}

function Importante() 
{
	abre('ImportanteLeia.asp');
}

function Solicitacoes() 
{
	var	link;
	link = "http://www.anatel.gov.br/TOOLS/DEFAULTCAB.ASP?LINK=HTTP://200.252.158.173/FACO/ATENDIMENTO/ATENDIMENTO.ASP";
	abre(link);
}

//Verificar qual browser o usuário está usando
var isIE = document.all ? true : false;
var isNS = document.layers ? true : false;
		
String.prototype.inRoaming = function(e) {

	var exibir;
	var cnOrigem = document.frmacao.pCNOrigem.value;
	var hantes, hdepois;

	if (this.length == 0) {
		var key = (isIE) ? window.event.keyCode : e.which;
		exibir = (key > 55 && key < 58) ? true : false;
	}
	else { 
		exibir = (parseInt(this.substr(0,1)) > 7) ? true : false;
	}
	
	if(exibir)
		{
		document.all('TitpNumeroOrigem').style.display = 'none';
		document.frmacao.pNumeroOrigem.value = '';
		transformaCampoObrigatorio(document.getElementById('pNumeroOrigem'), 'n');
		document.frmacao.pNumeroOrigem.style.display = 'none';
		}
		
	hantes=document.body.scrollHeight;
	document.getElementById('divroaming').style.display = (exibir) ? '' : 'none';
	hdepois = document.body.scrollHeight
	if (hantes != hantes) parent.resizeConteudo(document.body.scrollHeight); 
}

String.prototype.isTelefoneFixo = function(e) {

	if (this.length > 0) { return (true) }
	var decimal = false;
	var key = (isIE) ? window.event.keyCode : e.which;
	var obj = (isIE) ? event.srcElement : e.target;
	var isNum = (key > 47 && key < 56) ? true:false;
	var dotOK = (key==46 && decimal && (obj.value.indexOf(".")<0 || obj.value.length==0)) ? true:false;
	window.event.keyCode = (!isNum && !dotOK && isIE) ? 0:key;
	e.which = (!isNum && !dotOK && isNS) ? 0:key;
	return (isNum || dotOK);
}

function exibirRegiao(codPais, server) 
{
	var cnOrigem = document.getElementById('pCNOrigem').value;
	var prefOrigem = document.getElementById('pPrefixoOrigem').value;
	var arPais = codPais.split("$");
	var codPais = arPais[0].split("/");
	var select = document.getElementById('pRegiao');
	if ((cnOrigem != '') && (prefOrigem != '') && (codPais != ''))
	{
		window.status = 'Carregando dados...';
		recuperaConteudoCombo('http://' + server + '/SIPT/Atualizacao/N_ConsultaTarifas/xml.asp?sql=1&CNOrigem=' + cnOrigem + '&PrefOrigem=' + prefOrigem + '&CodPais=' + codPais[0], select);
		
		if (select.length>0)
			show(true);
		else
			show(false);
		window.status = '';
	}
	document.getElementById('pMudou').value = '';
}

function show(exibir) {

	// mocozar ou exibir a combo de regiões
	document.getElementById('pRegiao').style.display = (exibir) ? '' : 'none';
	document.getElementById('TitpRegiao').style.display = (exibir) ? '' : 'none';
	document.getElementById('ImgObrigatoriopRegiao').style.display = (exibir) ? '' : 'none';
}

function voltar()
{
	var URL;

	URL = "tela.asp?pCNOrigem=" + document.getElementById('vCNOrigem').value;
	URL = URL + "&pPrefixoOrigem=" + document.getElementById('vPrefixoOrigem').value;
	URL = URL + "&pNumeroOrigem=" + document.getElementById('vNumeroOrigem').value;
	URL = URL + "&pCNRoaming=" + document.getElementById('vCNRoaming').value;
	URL = URL + "&LDN=" + document.getElementById('LDN').value;

	document.location.href = URL;
}
function resizeConteudo(width)
{
	document.getElementById('tabelaRoot').style.height = width;
}

function verificaLocalidade(CN, Prefixo, TipoOD) 
{
	//Verifica a necessida de informacao do numero completo
	if((Prefixo.substr(0,1) < 8) && (Prefixo.substr(0,1) != ''))
		{
		window.status = 'Carregando dados';
		var xml = new ActiveXObject("Microsoft.XMLDOM");
		xml.async = false;
		xml.load("xml.asp?xml=s&sql=4&pCN=" + CN + "&pPrefixo=" + Prefixo);
		var xsl = new ActiveXObject("Microsoft.XMLDOM");
		xsl.async = false;
		xsl.load("/SIPT/Atualizacao/Funcoes/XSL.asp?Estilo=Label");
		window.status = 'Concluído';

		if (xml.transformNode(xsl).substr(0,1) == 'I')
			{
			if (TipoOD == 'O')
				{
				document.all('TitpNumeroOrigem').style.display = '';
				document.frmacao.pNumeroOrigem.style.display = '';
				document.getElementById('pNumeroOrigem').focus();
				transformaCampoObrigatorio(document.getElementById('pNumeroOrigem'), 's');
				}
			else
				{
				document.all('TitpNumeroDestino').style.display = '';
				document.frmacao.pNumeroDestino.style.display = '';
				document.getElementById('pNumeroDestino').focus();
				transformaCampoObrigatorio(document.getElementById('pNumeroDestino'), 's');
				}
			}
		else
			{
			document.getElementById('pCNDestino').focus();
			
			if (TipoOD == 'O')
				{
				document.all('TitpNumeroOrigem').style.display = 'none';
				document.frmacao.pNumeroOrigem.style.display = 'none';
				document.frmacao.pNumeroOrigem.value = '';
				transformaCampoObrigatorio(document.getElementById('pNumeroOrigem'), 'n');
				}
			else
				{
				document.all('TitpNumeroDestino').style.display = 'none';
				document.frmacao.pNumeroDestino.style.display = 'none';
				document.frmacao.pNumeroDestino.value = '';
				transformaCampoObrigatorio(document.getElementById('pNumeroDestino'), 'n');
				}
			}
		}
}