function handleHttpResponse(){
   if (http.readyState == 4) {
      document.getElementById("conteudo").innerHTML = http.responseText;
   }
}
function getHTTPObject() {
   var xmlhttp;
   /*@cc_on
        @if (@_jscript_version >= 5)
         try {
           xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
           try {
             xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
           } catch (e) {
             xmlhttp = false;
           }
         }
         @else
         xmlhttp = false;
   @end @*/
   if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
     try {
       xmlhttp = new XMLHttpRequest();
     } catch (e) {
       xmlhttp = false;
     }
   }
   return xmlhttp;
}
var http = getHTTPObject();
var httpi = getHTTPObject();
var httpx = getHTTPObject();
var httpe = getHTTPObject();
var httpequipe = getHTTPObject();

var historico = new Array(new Array("normal","none","ajx=main"));
var historicoCounter = 0;
var historicoCounterLast = 0;

function addHistorico(tipo, indoc, valor){
    historicoCounter++;
    historico[historicoCounter] = new Array(tipo,indoc,valor);
    historicoCounterLast = historicoCounter;
}
function backHistorico(){
    if(historicoCounter==0){
        alert("Você não pode retornar páginas, você está na página inicial!");
    }else{
        historicoCounter--;
        if(historico[historicoCounter][0]=="indoc"){
             ajaxIndocH("index.php",historico[historicoCounter][1],historico[historicoCounter][2]);
        }else{
             ajaxCommandH("index.php",historico[historicoCounter][2]);
        }
    }
}
function forwardHistorico(){
    if(historicoCounter==historicoCounterLast){
        alert("Não é possível avançar, você está na ultima página que visitou!");
    }else{
        historicoCounter++;
        if(historico[historicoCounter][0]=="indoc"){
             ajaxIndocH("index.php",historico[historicoCounter][1],historico[historicoCounter][2]);
        }else{
             ajaxCommandH("index.php",historico[historicoCounter][2]);
        }
    }
}

function ajaxCommand(page, valor){
      document.getElementById("conteudo").innerHTML = '<table border="0" style="height:100%;width:100%"><tr><td valign="middle" align="center"><img src="./imgs/loading.gif" alt="Carregando..." /><br /><br /> Carregando... por favor aguarde...</td></tr></table>';
      http.open("GET", page+"?nocache="+(Math.random())+"&"+valor, true);
      http.onreadystatechange = handleHttpResponse;
      http.send(null);
      autoLocalSite(valor);
      addHistorico("normal","none",valor);
}

function ajaxIndoc(page,indoc, valor){
      document.getElementById(indoc).innerHTML = '<table border="0" style="height:100%;width:100%"><tr><td valign="middle" align="center"><img src="./imgs/loading.gif" alt="Carregando..." /><br /><br /> Carregando... por favor aguarde...</td></tr></table>';
      httpi.open("GET", page+"?nocache="+(Math.random())+"&"+valor, true);
      iot = valor.split("=");
      try{
      gt = document.getElementById("bannerimg");
      if(gt!=false){
          gt.innerHTML = "<img src=\"./iss.php?banner="+iot[iot.length-1]+"\" alt=\"CliniOnco\" />";
      }
      }catch(e){
      }
      httpi.onreadystatechange = function (){
          if (httpi.readyState == 4) {
               document.getElementById(indoc).innerHTML = httpi.responseText;
               myLightbox.updateImageList();
          }
      };
      httpi.send(null);
      addHistorico("indoc",indoc,valor);
}

function ajaxCommandH(page, valor){
      document.getElementById("conteudo").innerHTML = '<table border="0" style="height:100%;width:100%"><tr><td valign="middle" align="center"><img src="./imgs/loading.gif" alt="Carregando..." /><br /><br /> Carregando... por favor aguarde...</td></tr></table>';
      http.open("GET", page+"?nocache="+(Math.random())+"&"+valor, true);
      http.onreadystatechange = handleHttpResponse;
      http.send(null);
      autoLocalSite(valor);
}

function ajaxIndocH(page,indoc, valor){
      document.getElementById(indoc).innerHTML = '<table border="0" style="height:100%;width:100%"><tr><td valign="middle" align="center"><img src="./imgs/loading.gif" alt="Carregando..." /><br /><br /> Carregando... por favor aguarde...</td></tr></table>';
      httpi.open("GET", page+"?nocache="+(Math.random())+"&"+valor, true);
      iot = valor.split("=");
      try{
      gt = document.getElementById("bannerimg");
      if(gt!=false){
          gt.src = "./iss.php?banner="+iot[iot.length-1];
      }
      }catch(e){
      }
      httpi.onreadystatechange = function (){
          if (httpi.readyState == 4) {
               document.getElementById(indoc).innerHTML = httpi.responseText;
               myLightbox.updateImageList();
          }
      };
      httpi.send(null);
}

function localSite(local){
      locais = local.split(",");
      lugar = '<table border="0" style="height:100%;width:100%"><tr><td valign="middle" align="right">';
      for(i=0;i<locais.length;i++){
          l = locais[i].split("|");
          if(i!=0) lugar += '&raquo;';
          if(l[1]=="#"){
             lugar += ' '+l[0]+' ';
          }else lugar += ' <a href="javascript:;" onclick="ajaxCommand(\'index.php\',\'ajx='+l[1]+'\')">'+l[0]+'</a> ';
      }
      lugar += '</td></tr></table>';
      document.getElementById("local").innerHTML = lugar;
}

function autoLocalSite(local){
      local = local.split("&");
      switch(local[0]){
      case 'ajx=main': localSite("Home|main"); break;
      case 'ajx=direitosdopaciente': localSite("Home|main,Direitos do Paciente|direitosdopaciente"); break;
      case 'ajx=tiposdecancer': localSite("Home|main,Tipos de Câncer|tiposdecancer"); break;
      case 'ajx=farmacia': localSite("Home|main,Orientações da equipe|#,Farmácia|farmacia"); break;
      case 'ajx=enfermagem': localSite("Home|main,Orientações da equipe|#,Enfermagem|enfermagem"); break;
      case 'ajx=psiquiatria': localSite("Home|main,Orientações da equipe|#,Psiquiatria|psiquiatria"); break;
      case 'ajx=nutricao': localSite("Home|main,Orientações da equipe|#,Nutrição|nutricao"); break;
      case 'ajx=fisioterapia': localSite("Home|main,Fisioterapia|fisioterapia"); break;
      case 'ajx=psiconcologia': localSite("Home|main,Orientações da equipe|#,Psiconcologia|psiconcologia"); break;
      case 'ajx=definicoes': localSite("Home|main,Definições|definicoes"); break;
      case 'ajx=marcacaodeconsulta': localSite("Home|main,Marcação de consulta|marcacaodeconsulta"); break;
      case 'ajx=depoimentos': localSite("Home|main,Depoimentos|depoimentos"); break;
      case 'ajx=manuaisdeorientacoes': localSite("Home|main,Manuais de orientações|manuaisdeorientacoes"); break;
      case 'ajx=prevprimaria': localSite("Home|main,Prevenção|#,Prevenção primária e secundária|prevprimaria"); break;
      case 'ajx=orientacoesgerais': localSite("Home|main,Orientações gerais|orientacoesgerais"); break;
      case 'ajx=manprev': localSite("Home|main,Manuais de Prevenção|manprev"); break;
      case 'ajx=novostratamentos': localSite("Home|main,Novos Tratamentos|novostratamentos"); break;
      case 'ajx=terapiasantineoplas': localSite("Home|main,Terapias Antineoplásicas|terapiasantineoplas"); break;
      case 'ajx=radioterapia': localSite("Home|main,Radioterapia|radioterapia"); break;
      case 'ajx=terapiascomplementares': localSite("Home|main,Terapias Complementares|terapiascomplementares"); break;
      case 'ajx=eventoscientificos': localSite("Home|main,Eventos Científicos|eventoscientificos"); break;
      case 'ajx=eventos': localSite("Home|main,Outros Eventos|eventos"); break;
      case 'ajx=producaocientifica': localSite("Home|main,Produção Científica|producaocientifica"); break;
      case 'ajx=linksnacionais': localSite("Home|main,Links|link"); break;
      case 'ajx=nossamissao': localSite("Home|main,Nossa Missão|nossamissao"); break;
      case 'ajx=pesquisaclinica': localSite("Home|main,Pesquisa Clínica|pesquisaclinica"); break;
      case 'ajx=estudosdesenvolvimento': localSite("Home|main,Estudos em desenvolvimento|estudosdesenvolvimento"); break;
      case 'ajx=historia': localSite("Home|main,História do site|historia"); break;
      case 'ajx=ambiente': localSite("Home|main,Ambiente|ambiente"); break;
      case 'ajx=equipe': localSite("Home|main,Equipe|equipe"); break;
      case 'ajx=convenios': localSite("Home|main,Convênios|convenios"); break;
      case 'ajx=busca': localSite("Home|main,Resultado da busca|busca"); break;
      case 'ajx=contato': localSite("Home|main,Contato|contato"); break;


      }
}
function exibeMenu(mar){
      document.getElementById(mar).style.visibility = "visible";
}

function assinarNewsLetter(){
    email = document.getElementById('newsemail');
    nome = document.getElementById('newsnome');
    if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email.value))){
        alert("E-Mail Inválido! \nPor favor preencha o campo com um e-mail válido e tente novamente.");
        email.focus();
    }else if(nome.value.length<3){
        alert("Nome Inválido! \nPor favor preencha o campo Nome com o seu nome e tente novamente.");
        nome.focus();
    }else{
          httpi.open("GET", "iss.php?newsletter="+email.value+"&nome="+nome.value, true);
          httpi.onreadystatechange = function(){
               if (httpi.readyState == 4) {
                     if (httpi.responseText == "OK"){
                       alert("Obrigado! \nSeu E-Mail foi cadastrado na newsletter com sucesso!")
                     }else{
                       alert("Não foi possível cadastrar o seu e-mail no newsletter \n"+httpi.responseText);
                     }
                     email.value = "";
               }
          }
          httpi.send(null);
          email.value = "Enviando...";
          nome.value = "";
    }
}

function sendForm(f) {
      var exibeResultado;
      var resultado = getFormValues(f);

      httpx.open("POST", "iss.php", true);
      httpx.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
      httpx.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
      httpx.setRequestHeader("Pragma", "no-cache");

      httpx.onreadystatechange = function() {
         if (httpx.readyState == 4) {
            if (httpx.status == 200) {
               if(httpx.responseText=="OK"){
                    document.getElementById(f).innerHTML = "Seu formulário foi enviado com sucesso!<br />Aguarde retorno por e-mail ou por telefone!";
               }else{
                    document.getElementById(f).innerHTML = "Não foi possível enviar o formulário, tente mais tarde!";
               }
            }
         }
      }
      document.getElementById(f).innerHTML = "Enviando...";
      httpx.send(resultado);
}
function getFormValues(f) {
   form = document.getElementById(f);
   var str = "";
   for(var i=0; i<form.elements.length; i++) {
      str += i==0 ? '' : '&';
      str += form.elements[i].id+'='+form.elements[i].value;
   }
   return str;
}
function proximosEventos(){
          eventoAtual = parseInt(document.getElementById('evento_cont_h').value);
          httpe.open("GET", "iss.php?eventos="+(eventoAtual+1), true);
          document.getElementById('evento_desc').innerHTML = "Carregando...";
          httpe.onreadystatechange = function() {
             if (httpe.readyState == 4) {
                 ev = httpe.responseText.split("####");
                 document.getElementById('evento_cont_h').value = ev[0];
                 document.getElementById('evento_cont_id').value = ev[2];
                 document.getElementById('evento_tipo').value = ev[4];
                 document.getElementById('evento_desc').innerHTML = ev[3];
                 document.getElementById('evento_cont').innerHTML = "("+(parseInt(ev[0])+1)+" de "+ev[1]+")";
             }
          }
          httpe.send(null);
}

function gotoEvento(){
	ajaxCommand('index.php','ajx='+document.getElementById('evento_tipo').value+'&io='+document.getElementById('evento_cont_id').value);
}


function opPP(pag,w,h){
      if(window.open(pag,'popupclinionco',"width="+w+",height="+h+",scrollbars=yes")){
      }else alert("Ocorreu um erro quando o site tentou abrir uma janela Popup! \nDesabilite o bloqueador de popups e tente novamente");
}


function opPic(img,w,h){
	wi = window.open('iss.php?eventopic='+img,'popupclinionco',"width="+w+",height="+h+",scrollbars=yes")
      if(wi){
		  wi.focus();
      }else alert("Ocorreu um erro quando o site tentou abrir uma janela Popup! \nDesabilite o bloqueador de popups e tente novamente");
}

function switchNewsletter(numb){
	document.getElementById('campo').innerHTML = '<object type="application/x-shockwave-flash" data="./imgs/newsshow.swf?day='+numb+'" width="720" height="1200"><param name="wmode" value="transparent" /><param name="movie" value="./imgs/newsshow.swf?day='+numb+'" /></object>';
}

function primeiraConsulta(){
	wi = window.open('http://gemed.clinionco.com.br/agendaweb2.0/','popupclinirec',"width=550,height=500,scrollbars=yes")
      if(wi){
		  wi.focus();
      }else alert("Ocorreu um erro quando o site tentou abrir uma janela Popup! \nDesabilite o bloqueador de popups e tente novamente");
}
function reconsulta(){
	wi = window.open('http://gemed.clinionco.com.br/agendaweb2.0/','popupclinirec',"width=550,height=500,scrollbars=yes")
      if(wi){
		  wi.focus();
      }else alert("Ocorreu um erro quando o site tentou abrir uma janela Popup! \nDesabilite o bloqueador de popups e tente novamente");
}

function opFoto(img,w,h){
	wi = window.open('iss.php?imagempic='+img,'popupclinionco',"width="+w+",height="+h+",scrollbars=yes")
      if(wi){
		  wi.focus();
      }else alert("Ocorreu um erro quando o site tentou abrir uma janela Popup! \nDesabilite o bloqueador de popups e tente novamente");
}

function curriculo(page){
      document.getElementById('bannerimg').innerHTML = '<table border="0" style="height:100%;width:100%"><tr><td valign="middle" align="center"><img src="./imgs/loading.gif" alt="Carregando..." /><br /><br /> Carregando... por favor aguarde...</td></tr></table>';
      httpequipe.open("GET", "iss.php?nocache="+(Math.random())+"&curriculo="+page, true);
      httpequipe.onreadystatechange = function (){
          if (httpequipe.readyState == 4) {
               document.getElementById('bannerimg').innerHTML = httpequipe.responseText;
          }
      };
      httpequipe.send(null);
}
function curriculoDetail(page){
      document.getElementById('campo').innerHTML = '<table border="0" style="height:100%;width:100%"><tr><td valign="middle" align="center"><img src="./imgs/loading.gif" alt="Carregando..." /><br /><br /> Carregando... por favor aguarde...</td></tr></table>';
      httpequipe.open("GET", "iss.php?nocache="+(Math.random())+"&curriculodet="+page, true);
      httpequipe.onreadystatechange = function (){
          if (httpequipe.readyState == 4) {
               document.getElementById('campo').innerHTML = httpequipe.responseText;
          }
      };
      httpequipe.send(null);
}