// JavaScript Document

function mar(pos, speed)
{
 obj = document.getElementById('marquee');
 obj.direction = pos;
 obj.scrollAmount = speed;
}


/************ PARA MOSTRAR E ESCONDER LAYER ************/
// Script que verifica o browser a ser usado
if (document.all || document.layers) {
	IE4 = (document.all);
	NS4 = (document.layers);
	NS6 = false;
} else if (document.getElementById) {
	IE4 = false;
	NS4 = false;
	NS6 = (document.getElementById);
}
if ( navigator.userAgent.indexOf("Mozilla") != -1 ) {
	mozilla = true;
}
function getStyle(id){return NS4 ? document[id] : NS6 ? document.getElementById(id).style : document.all[id].style;}
function HideLayer(id){getStyle(id).visibility = NS4 ? "hide" : "hidden"; getStyle(id).display = "none";}
function ShowLayer(id){getStyle(id).visibility = NS4 ? "show" : "visible"; getStyle(id).display = "block";}
/******************************************************/

/************ PARA DESABILITAR TECLAS ****************/
// Desabilita teclas exceto números, ponto e vírgula
function desabilitateclas_parcial()
{
	var tecla = event.keyCode;
	alert(tecla);
	if ((tecla >= 0 && tecla <= 7)||(tecla >= 9 && tecla <= 12)||(tecla >= 14 && tecla <= 43)||(tecla >= 45 && tecla <= 47)||
	(tecla >= 58 && tecla <= 98)||(tecla >= 100 && tecla <= 127))
	{ return false; }
	return tecla;
}// fim da função desabilitateclas

// Desabilita todas as teclas exceto números
function desabilitateclas(event)
{
	// Detectando diferenças de browsers
	if( document.all && ! navigator.userAgent.match(/opera/gi) ) { // somente IE 
		var tecla = event.keyCode;
	} 
	else { // atende  no mínimo o Firefox, Netscape 6+,  e Opera 
		var tecla = event.which;
	}
	/*
	0: TAB
	8: BACKSPACE
	13: ENTER
	48 - 57: Númeris de 0 a 9
	*/
	if ((tecla == 0)||(tecla == 8)||(tecla == 13)||(tecla >=48 && tecla <= 57))
		return tecla;
	return false;
}
/******************************************************/

// Muda o focus do telefone
function muda_focus(a,b)
{
	if(a.length==2)
		b.focus();
}
// Função mascara de FONE
function mascaraFONE(objeto)
{
	campo = eval (objeto);
	separacao1 = '-';
	conjunto1 = 4;
	conjunto2 = 9;
	if (desabilitateclas(event))
	{
		if (campo.value.length < (conjunto2))
		{
		  if (campo.value.length == conjunto1)
				campo.value = campo.value + separacao1;
		}
	}
	else
		event.returnValue = false;
}

// Verifica inconsistência do e-mail
function email(obj)
{
	//email_de
	re=/^[A-Za-z0-9_.-]+@([A-Za-z0-9_.-]+\.)+[A-Za-z]{2,4}$/i;
	if(!re.test(obj.value)){
		alert('O e-mail informado parece não estar correto.');
		obj.focus();
		return false;
	}
}

// Para rede credenciada
function ir_rede_credenciada(n,plId)
{
	if(n==0) // Hospital TODOS
	{
		document.ordenacao.plId.value = plId;
		document.ordenacao.action="dt_rede_hospital_all.php";
	}
	if(n==1) // Hospital ZC
	{
		document.ordenacao.plId.value = plId;
		document.ordenacao.action="dt_rede_hospital_zc.php";
		document.ordenacao.regiao.value=5;
	}
	if(n==2) // Hospital ZN
	{
		document.ordenacao.plId.value = plId;
		document.ordenacao.action="dt_rede_hospital_zc.php";
		document.ordenacao.regiao.value=2;		
	}
	if(n==3) // Hospital ZS
	{
		document.ordenacao.plId.value = plId;
		document.ordenacao.action="dt_rede_hospital_zc.php";
		document.ordenacao.regiao.value=1;
	}
	if(n==4) // Hospital ZL
	{
		document.ordenacao.plId.value = plId;
		document.ordenacao.action="dt_rede_hospital_zc.php";
		document.ordenacao.regiao.value=3;		
	}
	if(n==5) // Hospital ZO
	{
		document.ordenacao.plId.value = plId;
		document.ordenacao.action="dt_rede_hospital_zc.php";	
		document.ordenacao.regiao.value=4;
	}
	if(n==6) // Hospital ZR
	{
		document.ordenacao.plId.value = plId;
		document.ordenacao.action="dt_rede_hospital_zc.php";	
	}
	if(n==7) // LABORATÓRIO
	{
		document.ordenacao.plId.value = plId;
		document.ordenacao.action="dt_rede_laboratorio.php";	
	}
	if(n==8) // CARÊNCIA
	{
		document.ordenacao.plId.value = plId;
		document.ordenacao.action="dt_carencia.php";	
	}
	if(n==9) // ADESÃO: QUEM PODE ADQUIRIR
	{
		document.ordenacao.plId.value = plId;
		document.ordenacao.action="dt_quem_pode_aderir.php";	
	}
	if(n==10) // ADESÃO: SAIBA MAIS
	{
		document.ordenacao.plId.value = plId;
		document.ordenacao.action="dt_maisinfo.php";	
	}
	if(n==11) // ODONTO: DOCUMENTAÇÃO NECESSÁRIA
	{
		document.ordenacao.plId.value = plId;
		document.ordenacao.action="dt_documentacao.php";	
	}
	if(n==12) // ODONTO: PROCEDIMENTOS
	{
		document.ordenacao.plId.value = plId;
		document.ordenacao.action="dt_procedimentos.php";	
	}
	if(n==13) // PME: DETALHES PLANOS
	{
		document.ordenacao.plId.value = plId;
		document.ordenacao.action="dt_plano.php";	
	}
	if(n==14) // REEMBOLSO
	{
		document.ordenacao.plId.value = plId;
		document.ordenacao.action="dt_reembolso.php";	
	}
	if(n==15) // ENDEREÇO
	{
		document.ordenacao.plId.value = plId;
		document.ordenacao.action="dt_endereco.php";	
	}
	document.ordenacao.submit();
}

// Para DETALHES DOS PLANO B2CBRASIL - MENOS ADESAO
function ir_rede_credenciada_brasil(plId,tipo,tipo_detalhe,valor)
{
	//BRASIL NOVOS
	document.ordenacao.plId.value = plId;
	document.ordenacao.tipo_detalhe.value = tipo_detalhe;
	document.ordenacao.preco.value = valor;
	document.ordenacao.tipo.value = tipo;

	if (tipo_detalhe=='proc')
		document.ordenacao.action="br_dt_procedimentos.php";
	else if(tipo_detalhe!='preco')
		document.ordenacao.action="detalhes_do_plano.php";		
	else
		document.ordenacao.action="br_dt_plano.php";	


	document.ordenacao.submit();
}

// Para DETALHES DOS PLANO B2CBRASIL - SOMENTE PARA ADESAO
function ir_rede_credenciada_br_adesao(plId,tipo,tipo_detalhe,valor,id_entidade)
{
	//BRASIL NOVOS
	document.ordenacao.plId.value = plId;
	document.ordenacao.tipo_detalhe.value = tipo_detalhe;
	document.ordenacao.preco.value = valor;
	document.ordenacao.tipo.value = tipo;
	document.ordenacao.id_entidade.value = id_entidade;

	if(tipo_detalhe!='preco')
		document.ordenacao.action="detalhes_do_plano_adesao.php";	
	else
		document.ordenacao.action="br_dt_plano_adesao.php";	


	document.ordenacao.submit();
}

// Abre pop-up
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function full(link,nome_janela) 
{
	largura = screen.width - 10;
	altura = screen.height - 220;
	
	if (link != '')
		window.open(link,''+nome_janela+'','width='+largura+',height='+altura+',top=0,left=0,screenX=0,screenY=0,status=yes,scrollbars=yes,toolbar=yes,resizable=yes,maximized=yes,menubar=yes,location=yes');
}

function esconde(id)
{
	
	if(document.getElementById(id).style.display == 'none')
	{
		document.getElementById(id).style.display='block';
	}
	else
	{
		document.getElementById(id).style.display='none';
	}
}


function tipo_do_plano(id)
{	
	if(id=='e')
	{
		document.getElementById('mostrar_empresarial').style.display='block';
		document.getElementById('mostrar_individual').style.display='none';
	}
	else
	{
		document.getElementById('mostrar_individual').style.display='block';
		document.getElementById('mostrar_empresarial').style.display='none';
	}

	document.getElementById('mostrar_opcoes').style.display='block';
}

function soma(campo)
{	
	inputs=document.getElementsByTagName('input');
	var t = 0;
	for(i=0;i<inputs.length;i++)
	{
		// se o atributo name contem 'faixa'
		if(/faixa/.test(inputs[i].name))
		{    // cria um novo link e um texto
			if(inputs[i].value>0)
			{
				t = parseInt(inputs[i].value)+t;
			}
		}
	}
	document.getElementById(campo).value = t;
}

function troca_botao()
{
	document.getElementById('imageField').style.backgroundPosition= "0px -30px";
	document.getElementById('imageField').setAttribute("onClick","alert('Aguarde enquanto sua pesquisa é processada !')");
}

function balao_help(texto)
{
	Tip(texto,BGCOLOR,'#FFFFCC',BORDERWIDTH,'0px',SHADOW,true,OFFSETY,'5',PADDING,'10')
}
