
/*-----------------------------------------------------------------*
  goto_url
  Descricao   : Verifica se esta logado para o redirecionamento
  Parametros  : sessão true or false , endereço de url
    Atualizacoes: [00] Versao Inicial    Data: 27/03/2007     Autor: Fábio Calixto
 *-----------------------------------------------------------------*/
function goto_url(sessao,url){
	if ( sessao == 0 ){
		window.location.href = "cadastro.asp";
	}else{	
		window.location.href = "redirect.asp?sessao=" + sessao + "&url=" + url + "";
	}
}


/*-----------------------------------------------------------------*
  IsNumber
  Descricao   : Verifica se e' um numero
  Parametros  : Numero que contém dígitos de 0 a 9
    Atualizacoes: [00] Versao Inicial    Data: 22/03/2006     Autor: Fábio Calixto
 *-----------------------------------------------------------------*/
function IsNumber (Numero)
{
   var i;
   if (Numero == "")
      return false;
   for (i=0; i < Numero.length; i++)
   {
   		if(Numero.charAt(i) != ","){   
		  if (Numero.charAt(i) < "0" || Numero.charAt(i) > "9")
			 return false;
		}   
   }
   return true;
}


/*-----------------------------------------------------------------*
 | isNumber      Retorna True se o String dada for um número      |
 |                com casas decimais dadas.                        |
 *-----------------------------------------------------------------*/
function isNumberVA(sNumero, iDecimais) {
  var bRet
  var i
  bRet = true
  if (iDecimais > 0)
    {
    if ((sNumero.length < iDecimais + 2) || (sNumero.indexOf(",", 0) == -1))
      bRet = false
    }
  if (bRet)
    {
    i = 0
    while(i < sNumero.length && bRet)
      {
      if (iDecimais > 0)
        {
        if (i == sNumero.length - (iDecimais + 1))
          {
          if (sNumero.charAt(i) != ",")
            bRet = false
          }
        else
          {
          if (sNumero.charAt(i) < "0" || sNumero.charAt(i) > "9")
            bRet = false
          }
        }
      else
        {
        if (sNumero.charAt(i) < "0" || sNumero.charAt(i) > "9")
          bRet = false
        }
      i++
      }
    }
  return bRet
}




/*-----------------------------------------------------------------*
  Descricao   : Tira brancos à esquerda e à direita
    Atualizacoes: [00] Versao Inicial    Data: 22/03/2006     Autor: Fábio Calixto
 *-----------------------------------------------------------------*/
function trim(s)
{
    return s.replace (/^\s+/,'').replace (/\s+$/,'');
}


/*-----------------------------------------------------------------------------------------*
 Nome........: left
 Descricao...: pega X caratres a esquerda
 Paramentros.: data: 
 Retorno.....: string
 Atualizacoes: [00] Versao Inicial    Data: 26/10/2007     Autor: Fábio Calixto
 *-----------------------------------------------------------------------------------------*/
function left(texto, posicao){
	
	return texto.substr(0,posicao);

}

/*-----------------------------------------------------------------------------------------*
 Nome........: right
 Descricao...: pega X caratres a direita
 Paramentros.: data: 
 Retorno.....: string
 Atualizacoes: [00] Versao Inicial    Data: 26/10/2007     Autor: Fábio Calixto
 *-----------------------------------------------------------------------------------------*/
function right(texto, posicao){
	
	return texto.substr(texto.length-posicao , posicao);

}

/*-----------------------------------------------------------------------------------------*
 Nome........: mid
 Descricao...: pega X caratres da posicao informada
 Paramentros.: data: 
 Retorno.....: string
 Atualizacoes: [00] Versao Inicial    Data: 26/10/2007     Autor: Fábio Calixto
 *-----------------------------------------------------------------------------------------*/
function mid(texto, inicio, tamanho){
	
	return texto.substr(inicio , tamanho);

}

/*-----------------------------------------------------------------*
 Nome........: VerificaCPFCNPJ
 Descricao...: Verifica se é nunero de CPF ou CNPJ válido.
               Verificamos se o digitado está correto de acordo com seus dígitos verificadores
 Paramentros.: txtcpfcgc: CPF ou CNPJ a ser testado sem a formatacao de / e -
 Retorno.....: sRetorno: true (ok) ou false (nok)
    Atualizacoes: [00] Versao Inicial    Data: 22/03/2006     Autor: Fábio Calixto
 *-----------------------------------------------------------------*/
function VerificaCNPJCPF (txtCpfCgc, iTipo)
{

   var sAux, iTam;

   sAux = txtCpfCgc;

   //-- Tamanho da string sem o digito verificador
   iTam = sAux.length - 2;

   if (sAux.length <= 1)
      return false;

   if (fValidaDV (sAux.substring (0, iTam) ,iTipo) != sAux.substring (sAux.length-2, sAux.length))
      return false;

   if (iTipo == 1)
      if ( (sAux.substring(0,1) == sAux.substring(1,2)) && (sAux.substring(2,3) == sAux.substring(3,4)) && (sAux.substring(3,4) == sAux.substring(4,5)) && (sAux.substring(4,5) == sAux.substring(5,6)) && (sAux.substring(5,6) == sAux.substring(6,7)) && (sAux.substring(6,7) == sAux.substring(7,8)) && (sAux.substring(7,8) == sAux.substring(8,9)) && (sAux.substring(9,10) == sAux.substring(10,11)) )
      return false;

   return true;
}

/*-----------------------------------------------------------------*
 Nome........: fValidaDV
 Descricao...: Verifica se o dígito verificador do CPF/CGC está correto
 Paramentros.: iValor: Valor do CPF/CGC
               sTipoValidacao: 2 -> CPF; 1 -> CNPJ
 Retorno.....: sAux: sString contendo apenas os números
    Atualizacoes: [00] Versao Inicial    Data: 22/03/2006     Autor: Fábio Calixto
 *-----------------------------------------------------------------*/
function fValidaDV(iValor,sTipoValidacao)
{
   var iCont1,iCont2,iSoma=0,iMult,iLimiteMult
   if (sTipoValidacao==2) iLimiteMult = 12
   if (sTipoValidacao==1) iLimiteMult = 9
   for (iCont1 = 1; iCont1<=2; iCont1++)
   {
      iSoma = 0;
      iMult = 2;
      for (iCont2 = iValor.length; iCont2>=1; iCont2--)
      {
         iSoma = iSoma + (iMult * (iValor.substring(iCont2-1,iCont2)*1));
         iMult++;
         if (iMult > iLimiteMult)
            iMult = 2;
      }
      iValor = iValor + (((iSoma * 10) % 11) % 10);
   }
   return (iValor.substring(iValor.length-2,iValor.length));
}

/*-----------------------------------------------------------------*
 Nome........: fFormataCPFCGC
 Descricao...: Formata o CPF/CGC passado
 Paramentros.: sNumero: Valor do CPF/CGC
               iTipo: 2 -> CPF; 1 -> CGC
 Retorno.....: sRetorno: sString contendo o CPF/CGC formatado
    Atualizacoes: [00] Versao Inicial    Data: 22/03/2006     Autor: Fábio Calixto
 *-----------------------------------------------------------------*/
function FormataCNPJCPF(sNumero,iTipo)
{
   var sRetorno = ""
   if (iTipo == 2) // CPF
   {
      for (iCont=0; iCont<sNumero.length; iCont++)
      {
         if (iCont == 3 || iCont == 6)
            sRetorno = sRetorno + "."
         if (iCont == 9)
            sRetorno = sRetorno + "-"
         sRetorno = sRetorno + sNumero.charAt(iCont)
      }
   }
   else //CNPJ
   {
      for (iCont=0; iCont<sNumero.length; iCont++)
      {
         if (iCont == 2 || iCont == 5)
            sRetorno = sRetorno + "."
         if (iCont == 8)
            sRetorno = sRetorno + "/"
         if (iCont == 12)
            sRetorno = sRetorno + "-"
         sRetorno = sRetorno + sNumero.charAt(iCont)
      }
   }
   return (sRetorno)
   
   
   if(sTipo==1){
   	form.cnpj.value=sRetorno;
   }else{
   	form.cpf.value=sRetorno;
   }
   
}


/*-----------------------------------------------------------------------------------------*
 Nome........: ValidaEmail
 Descricao...: Verifica se o E-mail é válido
 Paramentros.: email: String de E-mail
 Retorno.....: true(ok) ou false(nok)
 Atualizacoes: [00] Versao Inicial    Data: 22/03/2006     Autor: Fábio Calixto
 *-----------------------------------------------------------------------------------------*/
function ValidaEmail(email)
{
   var aux;
   //checando se a string não é vazia
   if((email.replace (/^\s+/,'').replace (/\s+$/,'') == ""))
   {
      return false;
   }
   //checando se existe pelo menos uma arroba e pelo menos algum ponto
   if((email.indexOf("@") == -1)||(email.indexOf(".") == -1))
   {
      return false;
   }
   //checando se a string tem pelo menos 5 caracteres
   if(email.length<5)
   {
      return false
   }
   //checando se existe brancos
   if(email.indexOf(" ") != -1)
   {
      return false;
   }
   //checando se depois de . não tem outra @, ou um ponto ou espaço
   if((email.substr(email.lastIndexOf(".")+1,1) == "")||(email.substr(email.indexOf(".")+1,1) == "@")||(email.substr(email.indexOf(".")+1,1) == "."))
   {
      return false;
   }
   //checando se depois de @ não tem outra @, ou um ponto ou espaço
   if((email.substr(email.lastIndexOf("@")+1,1) == "")||(email.substr(email.indexOf("@")+1,1) == "@")||(email.substr(email.indexOf("@")+1,1) == "."))
   {
      return false;
   }
   //procurando por mais de uma @
   aux = email.substr(email.indexOf("@")+1);
   if(aux.indexOf("@") != -1)
   {
      return false
   }
   //checando se o primeiro caracter é @
   if(email.substr(0, 1) == "@")
   {
      return false
   }
   return true
}

/*-----------------------------------------------------------------------------------------*
 Nome........: IsDate
 Descricao...: Verifica se a data é valida
 Paramentros.: data: String de data 10 posicoes
 Retorno.....: true(ok) ou false(nok)
 Atualizacoes: [00] Versao Inicial    Data: 28/03/2006     Autor: Fábio Calixto
 *-----------------------------------------------------------------------------------------*/
function isDate(data){

	var dia = data.substr(0,2);
	var mes = data.substr(3,2);
	var ano = data.substr(6,4);


	if (data.substr(2,1)!="/" || data.substr(5,1)!="/"){
		return false;
	}

	if (data.length<10){
		return false;
	}

	if (isNaN(dia) || isNaN(mes) || isNaN(ano)){
		return false;
	}

	if(dia < 0 || dia > 31 || mes < 0 || mes > 12 || ano < 1800 || ano > 2100){
		return false;	
	}

	if(mes == "04" && dia > 30 || mes=="06" && dia > 30 || mes=="09" && dia > 30 || mes=="11" && dia > 30){
		return false;	
	}

	if(mes == "02" && dia > 28){
		return false;	
	}

	return true;

}


/*-----------------------------------------------------------------------------------------*
 Nome........: onlyNumbers
 Descricao...: permite apenas digitas numeros
 Paramentros.: data: 
 Retorno.....: presskey
 Atualizacoes: [00] Versao Inicial    Data: 28/03/2006     Autor: Fábio Calixto
 *-----------------------------------------------------------------------------------------*/
function onlyNumbers(){
    if( event.keyCode < 44 || (event.keyCode > 57 && event.keyCode < 96) || event.keyCode > 105){ //Nao Numericos
       if(event.keyCode != 8  && event.keyCode != 46 && event.keyCode != 37 && event.keyCode != 39 &&
          event.keyCode != 16 && event.keyCode != 9  && event.keyCode != 35 && event.keyCode != 36){ //Teclas Especiais
          return false;
      }
    }  

}

/*-----------------------------------------------------------------------------------------*
 Nome........: left
 Descricao...: pega X caratres a esquerda
 Paramentros.: data: 
 Retorno.....: string
 Atualizacoes: [00] Versao Inicial    Data: 26/10/2007     Autor: Fábio Calixto
 *-----------------------------------------------------------------------------------------*/
function left(texto, posicao){
	
	return texto.substr(0,posicao);

}

/*-----------------------------------------------------------------------------------------*
 Nome........: right
 Descricao...: pega X caratres a direita
 Paramentros.: data: 
 Retorno.....: string
 Atualizacoes: [00] Versao Inicial    Data: 26/10/2007     Autor: Fábio Calixto
 *-----------------------------------------------------------------------------------------*/
function right(texto, posicao){
	
	return texto.substr(texto.length-posicao , posicao);

}


function popup_video(language){
	if (language==1){
		window.open("http://www.ensinoeconhecimento.com/video_ehealth.html","_video","width=482,height=310,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no");
	}

	if (language==2){
		window.open("http://www.ensinoeconhecimento.com/video_ehealth_ingles.html","_video","width=482,height=310,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no");
	}
	
	if (language==3){
		window.open("http://www.ensinoeconhecimento.com/video_ehealth_frances.html","_video","width=482,height=310,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no");
	}	
	
}


function popup_colunista_email(codigo){
	window.open("colunista_email.asp?codigo="+codigo+"","_email","width=450,height=305,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no");
}


function popup_console(evento, video){
	window.open("http://208.101.42.35/e-health_console/player.aspx?evento=" + evento + "&video=" + video + "","_console","width=870,height=580,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no");
}


function goto_evento(evento, video){
	window.location.href = "ehealth_console.asp?evento=" + evento + "&video=" + video + "";
}


function abre_pedido(codigo, pedido){
	window.location.href = "cadastro_pedidos_detalhe.asp?codigo="+codigo+"&codigopedido="+pedido+"";
}


/*-----------------------------------------------------------------------------------------*
 Nome........: mOver
 Descricao...: seta luz de foco na TR da tabela
 Paramentros.: campo , cor: 
 Atualizacoes: [00] Versao Inicial    Data: 26/10/2007     Autor: Fábio Calixto
 *-----------------------------------------------------------------------------------------*/
function mOvr(src,clrOver) { 
	if (!src.contains(event.fromElement)) {
		src.bgColor = clrOver;
	}
} 

/*-----------------------------------------------------------------------------------------*
 Nome........: mOut
 Descricao...: seta luz de foco na TR da tabela
 Paramentros.: campo , cor: 
 Atualizacoes: [00] Versao Inicial    Data: 26/10/2007     Autor: Fábio Calixto
 *-----------------------------------------------------------------------------------------*/
function mOut(src,clrIn) {
	if (!src.contains(event.toElement)) {
	  	src.bgColor = clrIn;
	}
} 


/*
*************************************************
função mostra ou oculta o layer da pagina contato
*************************************************
*/

function ShowHideLayerZoom(img){
	var nameLayer = "layer_zoom";
	var navegador = navigator.appName;

	if(navegador == "Netscape"){	
		var largura = eval(parent.document.getElementById(nameLayer).offsetWidth);			
		var altura	= eval(parent.document.getElementById(nameLayer).offsetHeight);			
		
	}else{
		var largura = eval(parent.document.getElementById(nameLayer).scrollWidth);	
		var altura  = eval(parent.document.getElementById(nameLayer).scrollHeight);					
		
	}

	var top = 0; //(screen.height - altura)/4;
	var left = 0; //(screen.width - largura)/2;
	
	if (top < 0){top =0;}

	parent.document.getElementById(nameLayer).style.width = screen.width-22 + 'px';
	parent.document.getElementById(nameLayer).style.height = screen.height-150 + 'px';	

	parent.document.getElementById("img_zoom").src = img;

	parent.document.getElementById(nameLayer).style.top = top + 'px';
	parent.document.getElementById(nameLayer).style.left = left + 'px';	

	if(parent.document.getElementById(nameLayer).style.visibility=="visible"){
		parent.document.getElementById(nameLayer).style.visibility='hidden';
	}else{
		parent.document.getElementById(nameLayer).style.visibility='visible';
		window.location.href="#";
	}


}
