function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function ObjAjax(){
  try{return new XMLHttpRequest()}
  catch(e){try{return new ActiveXObject("Msxml2.XMLHTTP")}
  catch(e){return new ActiveXObject("Microsoft.XMLHTTP")}}
  return null;
}

function navegar(page){
  ajax = new ObjAjax();
  var div = document.getElementById("conteudo");
  //alert("");
  ajax.onreadystatechange = function(){
    if(ajax.readyState == 1){div.innerHTML="Carregando...";}
    if(ajax.readyState == 4){div.innerHTML=ajax.responseText;}

  }
  ajax.open("GET",page,true);
  ajax.send(null);
}

function valida_email(email)
{
	if(email != "")
	{
		//ExpressÃ£o Regular utilizada para validar o endereÃ§o de email
		var ExpReg = /^[a-zA-Z0-9_\.-]{2,}@([A-Za-z0-9_-]{2,}\.)+[A-Za-z]{2,4}$/;
		
		if(!ExpReg.test(email))
		{
			return false;
		}
		return true;
	}
}

function troca_A(){	
	document.getElementById("centro_int").src = "_images/geral/interna_tit_c_integrado_over.gif";
	document.getElementById("rede_hospital").src = "_images/geral/interna_tit_r_hospitalar.gif";
}
function troca_B(){	
	document.getElementById("centro_int").src = "_images/geral/interna_tit_c_integrado.gif";
	document.getElementById("rede_hospital").src = "_images/geral/interna_tit_r_hospitalar_over.gif";
}
function troca_C(){	
	document.getElementById("coleta_adulto").src = "_images/geral/btn_coleta_adulto_over.gif";
	document.getElementById("coleta_infantil").src = "_images/geral/btn_coleta_infantil.gif";
	document.getElementById("coleta_executivo").src = "_images/geral/btn_coleta_execut.gif";
}
function troca_D(){	
	document.getElementById("coleta_adulto").src = "_images/geral/btn_coleta_adulto.gif";
	document.getElementById("coleta_infantil").src = "_images/geral/btn_coleta_infantil_over.gif";
	document.getElementById("coleta_executivo").src = "_images/geral/btn_coleta_execut.gif";
}
function troca_E(){	
	document.getElementById("coleta_adulto").src = "_images/geral/btn_coleta_adulto.gif";
	document.getElementById("coleta_infantil").src = "_images/geral/btn_coleta_infantil.gif";
	document.getElementById("coleta_executivo").src = "_images/geral/btn_coleta_execut_over.gif";
}

function oculta_mostra(iid) {
	if(document.getElementById(iid).style.display == "none") {
		document.getElementById(iid).style.display = "";
	} else {
		document.getElementById(iid).style.display = "none";
	}
}

function checa(){
	//validacao de radio buttons sem saber quantos sao
	
	if (document.nform.check[0].checked == false && document.nform.check[1].checked == false ) {        
     	 alert("Selecione Paciente ou Médico.");
     	 document.nform.check[0].focus();		 
     	 return false;   		
     }	 
	 
	 if (document.nform.check[0].checked == true) {	 
	
		document.nform.action="resultados_exames_pac.php";		  
	 }
	 if (document.nform.check[1].checked == true) {	
		document.nform.action="resultados_exames_med.php";
	 }	
	 
	 return true;
}

function validaHome(){
		   
   if (document.frm_home.resp[0].checked == false && document.frm_home.resp[1].checked == false ) {        
     	 alert("Selecione Paciente ou Médico.");
     	 document.frm_home.resp[0].focus();
     	 return false;   		
     } 
	 
	if (document.frm_home.protocolo.value == ""){
	alert("O campo Protocolo é obrigatório.");
	document.frm_home.protocolo.focus();
	return false;
	}
	if (document.frm_home.senha.value == ""){
	alert("O campo Senha é obrigatório.");
	document.frm_home.senha.focus();
	return false;
	}
	
	return true;
}

function validaMedico(){
	if (document.medico.crm.value == ""){
	alert("O campo CRM é obrigatório.");
	document.medico.crm.focus();
	return false;
	}
	if (document.medico.senha.value == ""){
	alert("O campo Senha é obrigatório.");
	document.medico.senha.focus();
	return false;
	}
	return true;
}

function validaPaciente(){
	if (document.paciente.protocolo.value == ""){
	alert("O campo Protocolo é obrigatório.");
	document.paciente.protocolo.focus();
	return false;
	}
	if (document.paciente.senha.value == ""){
	alert("O campo Senha é obrigatório.");
	document.paciente.senha.focus();
	return false;
	}
	return true;
}

function validaFale(){
		if (document.fale.mail_para.value == ""){
		alert("O campo Setor é obrigatório.");
		document.fale.mail_para.focus();
		return false;
		}
		if (document.fale.nome.value == ""){
		alert("O campo Nome é obrigatório.");
		document.fale.nome.focus();
		return false;
		}
		if (document.fale.txt_telefone.value == ""){
		alert("O campo Telefone é obrigatório.");
		document.fale.txt_telefone.focus();
		return false;
		}
		if(!valida_email(document.fale.email.value))
		{
			alert ("O campo E-mail deve conter um endereço eletrônico válido!");
			//document.fale.email.value = "";
			document.fale.email.focus();
			return false;
		}
	return true;
}

function validaVisita(){
		if (document.visita.txt_nome_empresa.value == ""){
			alert("O campo Nome da Empresa é obrigatório.");
			document.visita.txt_nome_empresa.focus();
			return false;
		}
		if (document.visita.txt_ramo.value == ""){
			alert("O campo Ramo de atividade é obrigatório.");
			document.visita.txt_ramo.focus();
			return false;
		}
		if (document.visita.txt_numero_funcionarios.value == ""){
			alert("O campo Número de funcionários é obrigatório.");
			document.visita.txt_numero_funcionarios.focus();
			return false;
		}
		if (document.visita.txt_telefone.value == ""){
			alert("O campo Telefone é obrigatório.");
			document.visita.txt_telefone.focus();
			return false;
		}
		if (document.visita.email.value == ""){
			alert("O campo Email é obrigatório.");
			document.visita.email.focus();
			return false;
		}
		if(!valida_email(document.visita.email.value))
		{
			alert ("O campo E-mail deve conter um endereço eletrônico válido!");
			//document.fale.email.value = "";
			document.visita.email.focus();
			return false;
		}
	return true;
}

function validaCad(){
	
	
   
	if (document.cadastro.razao_social.value == ""){
	alert("O campo Razão Social é obrigatório.");
	document.cadastro.razao_social.focus();
	return false;
	}
	if (document.cadastro.email.value == ""){
	alert("O campo E-mail é obrigatório.");
	document.cadastro.email.focus();
	return false;
	}
	
	parte1 = document.cadastro.email.value.indexOf("@");
	parte2 = document.cadastro.email.value.indexOf(".");
	parte3 = document.cadastro.email.value.length;		
	if (!(parte1 >= 3 && parte2 >= 6 && parte3 >= 9)) {
	alert ("O campo E-mail deve conter um endereço eletrônico válido!");
	//document.fale.email.value = "";
	document.cadastro.email.focus();
	return false;
	}
		
	
	if (document.cadastro.codigo.value == ""){
	alert("O campo Código é obrigatório.");
	document.cadastro.codigo.focus();
	return false;
	}	
		
	
   
      if (document.cadastro.plano[0].checked == false && document.cadastro.plano[1].checked == false && document.cadastro.plano[2].checked == false && document.cadastro.plano[3].checked == false && document.cadastro.plano[4].checked == false && document.cadastro.plano[5].checked == false ) {        
     	 alert("Selecione o Plano.");
     	 document.cadastro.plano[0].focus();
     	 return false;   		
     } 	
   
   
   if (document.cadastro.plano2[0].checked == false && document.cadastro.plano2[1].checked == false && document.cadastro.plano2[2].checked == false ) {        
     	 alert("Selecione uma ação (Incluir, Alterar, Desligar).");
     	 document.cadastro.plano2[0].focus();
     	 return false;   		
     } 
	
	if (document.cadastro.nome.value == ""){
	alert("O campo Nome é obrigatório.");
	document.cadastro.nome.focus();
	return false;
	}	
	if (document.cadastro.pis.value == ""){
	alert("O campo pis é obrigatório.");
	document.cadastro.pis.focus();
	return false;
	}
	if (document.cadastro.cpf.value == ""){
	alert("O campo CPF é obrigatório.");
	document.cadastro.cpf.focus();
	return false;
	}
	if (document.cadastro.nome_mae.value == ""){
	alert("O campo Nome da Mãe é obrigatório.");
	document.cadastro.nome_mae.focus();
	return false;
	}
	if (document.cadastro.data_nasc.value == ""){
	alert("O campo Data de Nascimento é obrigatório.");
	document.cadastro.data_nasc.focus();
	return false;
	}
	if (document.cadastro.data_adm.value == ""){
	alert("O campo Data de Admissão é obrigatório.");
	document.cadastro.data_adm.focus();
	return false;
	}	
	
	return true;
}

function validaTrabalhe()
{
	if(document.trabalhe.txt_oportunidade.selectedIndex == "0"){
		alert("O campo Oportunidade é obrigatório.");
		document.trabalhe.txt_oportunidade.focus();
		return false;
	}	
	if(document.trabalhe.txt_area_atuacao.selectedIndex == "0"){
		alert("O campo Área de Atuação é obrigatório.");
		document.trabalhe.txt_area_atuacao.focus();
		return false;
	}	
	
	if(document.trabalhe.nome.value == ""){
		alert("O campo Nome é obrigatório.");
		document.trabalhe.nome.focus();
		return false;
	}	
	
	if(document.trabalhe.txt_sexo[0].checked == false && document.trabalhe.txt_sexo[1].checked == false )
	{
	 alert("Selecione o Sexo.");
	 document.trabalhe.txt_sexo[0].focus();
	 return false;   		
	}
	
	if(document.trabalhe.txt_estado_civil.value == ""){
		alert("O campo Estado Civil é obrigatório.");
		document.trabalhe.txt_estado_civil.focus();
		return false;
	}
	
	if(document.trabalhe.txt_nascimento.value == ""){
		alert("O campo Nascimento é obrigatório.");
		document.trabalhe.txt_nascimento.focus();
		return false;
	}
	
	if(document.trabalhe.txt_endereco.value == ""){
		alert("O campo Endereço é obrigatório.");
		document.trabalhe.txt_endereco.focus();
		return false;
	}
	
	if(document.trabalhe.txt_bairro.value == ""){
		alert("O campo Bairro é obrigatório.");
		document.trabalhe.txt_bairro.focus();
		return false;
	}
	
	if(document.trabalhe.txt_cidade.value == ""){
		alert("O campo Cidade é obrigatório.");
		document.trabalhe.txt_cidade.focus();
		return false;
	}
	
	if(document.trabalhe.txt_cep.value == ""){
		alert("O campo Cep é obrigatório.");
		document.trabalhe.txt_cep.focus();
		return false;
	}
	if(document.trabalhe.txt_telefone.value == ""){
		alert("O campo Telefone é obrigatório.");
		document.trabalhe.txt_telefone.focus();
		return false;
	}
	
	if(!valida_email(document.trabalhe.email.value))
	{
		alert ("O campo Seu E-mail deve conter um endereço eletrônico válido!");
		document.trabalhe.email.focus();
		return false;
	}
	
	return true;
}

function validaPopNews()
{
	if (document.pop_news.nome.value == ""){
		alert("O campo Seu Nome é obrigatório.");
		document.pop_news.nome.focus();
		return false;
	}
	if (document.pop_news.email.value == ""){
		alert("O campo Seu E-mail é obrigatório.");
		document.pop_news.email.focus();
		return false;
	}
	
	if (!valida_email(document.pop_news.email.value))
	{
		alert ("O campo Seu E-mail deve conter um endereço eletrônico válido!");
		document.pop_news.email.focus();
		return false;
	}	
	if (document.pop_news["nome_amigo1"].value == "")
	{
		alert("O campo Nome do destinatário é obrigatório.");
		document.pop_news["nome_amigo1"].focus();
		return false;
	}
	if (document.pop_news["email_amigo1"].value == ""){
		alert("O campo E-mail do destinatário é obrigatório.");
		document.pop_news["email_amigo1"].focus();
		return false;
	}	
	if (!valida_email(document.pop_news["email_amigo1"].value))
	{
		alert ("O campo E-mail do destinatário deve conter um endereço eletrônico válido!");
		document.pop_news["email_amigo1"].focus();
		return false;
	}
	for(x=2;x<=6;x++)
	{
		if (document.pop_news["nome_amigo"+x].value != "")
		{
			if (document.pop_news["email_amigo"+x].value == ""){
				alert("O campo Nome do destinatário é obrigatório.");
				document.pop_news["email_amigo"+x].focus();
				return false;
			}
			
			if (!valida_email(document.pop_news["email_amigo"+x].value))
			{
				alert ("O campo E-mail do destinatário deve conter um endereço eletrônico válido!");
				document.pop_news["email_amigo"+x].focus();
				return false;
			}
		}
	}
	return true;
}

function validaPopIndique()
{
	if (document.pop_indique.nome.value == ""){
		alert("O campo Seu Nome é obrigatório.");
		document.pop_indique.nome.focus();
		return false;
	}
	if (document.pop_indique.email.value == ""){
		alert("O campo Seu E-mail é obrigatório.");
		document.pop_indique.email.focus();
		return false;
	}
	if (!valida_email(document.pop_indique.email.value))
	{
		alert ("O campo Seu E-mail deve conter um endereço eletrônico válido!");
		document.pop_indique.email.focus();
		return false;
	}	
	if (document.pop_indique["nome_amigo1"].value == "")
	{
		alert("O campo Nome do amigo é obrigatório.");
		document.pop_indique["nome_amigo1"].focus();
		return false;
	}
	if (document.pop_indique["email_amigo1"].value == ""){
		alert("O campo E-mail do amigo é obrigatório.");
		document.pop_indique["email_amigo1"].focus();
		return false;
	}	
	if (!valida_email(document.pop_indique["email_amigo1"].value))
	{
		alert ("O campo E-mail do amigo deve conter um endereço eletrônico válido!");
		document.pop_indique["email_amigo1"].focus();
		return false;
	}
	for(x=2;x<=6;x++)
	{
		if (document.pop_indique["nome_amigo"+x].value != "")
		{
			if (document.pop_indique["email_amigo"+x].value == ""){
				alert("O campo E-mail do amigo é obrigatório.");
				document.pop_indique["email_amigo"+x].focus();
				return false;
			}
			
			if (!valida_email(document.pop_indique["email_amigo"+x].value))
			{
				alert ("O campo E-mail do amigo deve conter um endereço eletrônico válido!");
				document.pop_indique["email_amigo"+x].focus();
				return false;
			}
		}
	}
	return true;
}

function validaPopNewsletter()
{
		if (document.pop_newsletter.nome.value == ""){
			alert("O campo Seu Nome é obrigatório.");
			document.pop_newsletter.nome.focus();
			return false;
		}
		if (document.pop_newsletter.email.value == ""){
			alert("O campo Seu E-mail é obrigatório.");
			document.pop_newsletter.email.focus();
			return false;
		}
		if (!valida_email(document.pop_newsletter.email.value))
		{
			alert ("O campo Seu E-mail deve conter um endereço eletrônico válido!");
			document.pop_newsletter.email.focus();
			return false;
		}		
	return true;
}

function validaPopOpiniao(){
	
		if (document.pop_opiniao.nome.value == ""){
		alert("O campo Nome é obrigatório.");
		document.pop_opiniao.nome.focus();
		return false;
		}
		if (document.pop_opiniao.email.value == ""){
		alert("O campo E-mail é obrigatório.");
		document.pop_opiniao.email.focus();
		return false;
		}
		if (!valida_email(document.pop_opiniao.email.value))
		{
			alert ("O campo E-mail deve conter um endereço eletrônico válido!");
			//document.fale.email.value = "";
			document.pop_opiniao.email.focus();
			return false;
		}		
		if (document.pop_opiniao.sugestao.value == ""){
		alert("O campo Sugestão é obrigatório.");
		document.pop_opiniao.sugestao.focus();
		return false;		
		}
		
	return true;
}