

// Usada para abrir os menus da home  //
function some_menus()
{ 
	mn_secoes.style.display = 'none'
	mn_regioes.style.display = 'none'
	some_tudo.style.display = 'none'
}


function display_menu(m)
{
	if (m == 's')
	{
		if (mn_secoes.style.display == 'none')
		{
			mn_secoes.style.display = ''
			mn_regioes.style.display = 'none'
		}
		else
		{
			mn_secoes.style.display = 'none'
			mn_regioes.style.display = 'none'
		}
	}	
	
	if (m == 'r')
	{
		if (mn_regioes.style.display == 'none')
		{
			mn_regioes.style.display = ''
			mn_secoes.style.display = 'none'

		}
		else
		{
			mn_regioes.style.display = 'none'
			mn_secoes.style.display = 'none'
		}
	}				
	some_tudo.style.display = ''
}

// Usada para abrir o popup de contato, anuncie e assinatura //
function rodape(){
	var roda = window.open('popup_seletor.htm', '', 'width=620,height=400 ,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no')
}

// Usada pra abrir o Texto de como pesquisar do guia
function guia_como(){
	var desktop = window.open('guia_como.asp', 'como', 'width=467, height=450 ,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no')
}

// Usada para abrir o popup que é gerado através do TooL //
function abrepopup2(){
window.open('images/popup_farmaceutico.gif','', 'height= 258,width=230,left=50,top=155,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,directories=no,status=no')
}

function abrepopup(arq, altura, largura){
window.open(arq, 'popup', 'height=' + altura + ',width=' + largura + ',left=200,top=155,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,directories=no,status=no')
}


// Usada para limpar o text box quando clicado (Onchange) //
function limpa_box_busca()
{
if(form_busca.texto.value="Busca no portal")
{
form_busca.texto.value='';
}
}

// Usada na home para ativar o rollover do footer //
	function MM_jumpMenu(targ,selObj,restore)
	{
	  	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  	  	if (restore) selObj.selectedIndex=0;
	}


// Usada na home para abrir o popup do glossário //
function abre(){
	var desktop = window.open('glossario.asp', 'glossario', 'width=468,height=450 ,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no')
}

// Usada na home para limpar o text do glossário quando clicado //
function limpa_box_glossario()
{
if(glossario.palavra.value="Digite um termo")
{
glossario.palavra.value='';
}
}

// Usada na home para limpar o text do guia quando clicado //
function limpa_box_guia()
{
if(document.form_guia.texto2.value="Busca no guia")
{
document.form_guia.texto2.value='';
}
}


// Usadas para ativar o rollover dos links do rodapé//
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_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_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 isEmail(mail) {
	var ponto = 0;
	var arroba = 0;
	var letraAntes = 0;
	var letraDepois = 0;
	var i = 0;
	var l = mail.length;
	var ch = 0;
	if (l < 10)	return (false);
	for (i = 0; i < l; i++) {
		ch = mail.charCodeAt(i);
		if (ch == 46) {
			if (arroba > 0)	ponto += 1;
		} else {
			if (ch == 64) {
				arroba += 1;
			} else {
				if (((ch >= 65) && (ch <= 90)) || ((ch >= 97) && (ch <= 122))) {
					if (arroba > 0)
						letraDepois += 1;
					else
						letraAntes += 1;
				} else {
					if ((ch != 45) && (ch != 95)) {
						if ((ch < 48) || (ch > 57)) {
							return (false);
						}
					}
				}
			}
		}
	}
	if ((arroba == 1) && (ponto > 0) && (letraAntes > 1) && (letraDepois >= 5)) {
		return (true);
	} else {
		return (false);
	}
}
//=================================================================================== 
function retornaCodigoPagina(url){
	//alert(url);
	
	var objXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP")
	
	objXMLHTTP.Open("GET", url, false)
	objXMLHTTP.Send();

	var objXMLHTTP;
	
	//alert(objXMLHTTP.responseText);
	return objXMLHTTP.responseText;
	
}
//=========================================================================
	function consisteNum(){
		
		var key = event.keyCode;
		
		if  (!((key >= 48) && (key <= 57)))
		{
			event.keyCode = 0;
		}
	}
//=================================================================================== 
	function consisteData(){
		
		var key = event.keyCode;
		
		var contBarra = contaString(event.srcElement.value,'/');

		if (key == 92 || key == 47){
			if (contBarra < 2)
				event.keyCode = 47;
			else
				event.keyCode = 0;
		}else if (!((key >= 48) && (key <= 57))){
			event.keyCode = 0;
		}
	}
//=================================================================================== 	
	function contaString(vString,vString2){
		var temp = 0;
		if (vString.length>0 && vString2.length>0){
			for(i=0;i<vString.length;i++){
				//alert(vString.substr(i,vString2.length) + ' = ' + vString2)
				if (vString.substr(i,vString2.length)==vString2){
					temp++;
				}
			}
			return temp;
		}
		else return 0;
	}	
//=================================================================================== 	
function consisteTelefone(){
		
	var key = event.keyCode;
		
	if  (!((key >= 48) && (key <= 57)) && !(key == 45))
	{
		event.keyCode = 0;
	}
}


//=================================================================================== 
	function consisteChar()
	{
		var key = event.keyCode;
		
		if  ((key == 34) || (key == 39))
		{
			event.keyCode = 0;
		}
	}
//=================================================================================== 
	function consisteCharNum()
	{
		var key = event.keyCode;
		
		if (((key >= 48) && (key <= 57)) || ((key >= 65) && (key <= 90)) || ((key >= 97) && (key <= 122)))
        {
			event.keyCode = key;
        }
        else
        {
			event.keyCode = 0;
        }
    }
//=================================================================================== 
function consisteHexa()
	{
		
		var key = event.keyCode;
		
		if  (!((key >= 48) && (key <= 57)) && !((key >= 97)&& (key <= 102)) && !((key >= 65) && (key <= 70)))
		{
			event.keyCode = 0;
		}
		
	}
//=================================================================================== 
	function consisteDecimal(){
		var key = event.keyCode;
		
		if(key == 44 && (inStr(event.srcElement.value, '.') == 0)){
			event.keyCode = 46;
		}else if  (!(((key >= 48) && (key <= 57)) || (key==46)) || ((inStr(event.srcElement.value, '.') > 0) && (key==46)) ){
			event.keyCode = 0;
		}
	}
//===================================================================================
function isDate(campo) {
	if (campo != ""){
		if(campo.charAt(2) != "/" || campo.charAt(5) != "/" || campo.length != 10){
			return(false);
		}
		for(i=0;i<10;i++){
			if(i != 2 && i != 5){
				if(campo.charAt(i) != 0 && campo.charAt(i) != 1 && campo.charAt(i) != 2 && campo.charAt(i) != 3 && campo.charAt(i) != 4 && campo.charAt(i) != 5 && campo.charAt(i) != 6 && campo.charAt(i) != 7 && campo.charAt(i) != 8 && campo.charAt(i) != 9 || campo.charAt(i) == " "){
					return(false);
				}
			}
		}
		var Dia = 0;
		var Mes = 0;
		var Ano = 0;
		var Resto = 0;
		Dia = campo.substring(0,2);
		Mes = campo.substring(3,5);
		Ano = campo.substring(6,10);
		if (Ano < 1900) {
			return(false);
		}
		if ((Mes < 1) || (Mes > 12)) {
			return(false);
		}
		if ((Dia < 1) || (Dia > 31)) {
			return(false);
		}
		if ((Mes == "01") && (Dia <= 31)) {
			return(true);
		}
		if (Mes == "02") {
			Resto = Ano % 4;
			if ((Resto == 0) && (Dia <= 29)) {
				return(true);
			}
			if ((Resto != 0) && (Dia <= 28)) {
				return(true);
			}
		}
		if ((Mes == "03") && (Dia <= 31)) {
			return(true);
		}
		if ((Mes == "04") && (Dia <= 30)) {
			return(true);
		}
		if ((Mes == "05") && (Dia <= 31)) {
			return(true);
		}
		if ((Mes == "06") && (Dia <= 30)) {
			return(true);
		}
		if ((Mes == "07") && (Dia <= 31)) {
			return(true);
		}
		if ((Mes == "08") && (Dia <= 31)) {
			return(true);
		}
		if ((Mes == "09") && (Dia <= 30)) {
			return(true);
		}
		if ((Mes == "10") && (Dia <= 31)) {
			return(true);
		}
		if ((Mes == "11") && (Dia <= 30)) {
			return(true);
		}
		if ((Mes == "12") && (Dia <= 31)) {
			return(true);
		}
		return(false);
	}
}
//=========================================================================
function replace(texto,palavraBusca,palavraSubstitui) {
  // by Malaca
  var vvarrTemp =  texto.split(palavraBusca);
  return vvarrTemp.join(palavraSubstitui);
}
//=========================================================================
function autoFormat2(objForm, strField, sMask, evtKeyPress) {
 //autoFormat(document.forms[0], this.name, "99/99/9999", event)
   var i, nCount, sValue, fldLen, mskLen, bolMask, sCod, nTecla;

   if(document.all) { // Internet Explorer
      nTecla = evtKeyPress.keyCode;
   }
   else if(document.layers) { // Nestcape
      nTecla = evtKeyPress.which;
   }else{
   	  
   	  nTecla = evtKeyPress.charCode;	
	  if (nTecla == 0)
	   	  nTecla = evtKeyPress.keyCode;
   }
   //sValue = objForm[strField].value;
   sValue = document.getElementById(strField).value;

   // Limpa todos os caracteres de formatação que
   // já estiverem no campo.
   sValue = sValue.toString().replace( "-", "" );
   sValue = sValue.toString().replace( "-", "" );
   sValue = sValue.toString().replace( ".", "" );
   sValue = sValue.toString().replace( ".", "" );
   sValue = sValue.toString().replace( "/", "" );
   sValue = sValue.toString().replace( "/", "" );
   sValue = sValue.toString().replace( "(", "" );
   sValue = sValue.toString().replace( "(", "" );
   sValue = sValue.toString().replace( ")", "" );
   sValue = sValue.toString().replace( ")", "" );
   sValue = sValue.toString().replace( ":", "" );
   sValue = sValue.toString().replace( " ", "" );
   sValue = sValue.toString().replace( " ", "" );
   fldLen = sValue.length;
   mskLen = sMask.length;

   i = 0;
   nCount = 0;
   sCod = "";
   mskLen = fldLen;

   while (i <= mskLen) {
      bolMask = ((sMask.charAt(i) == ":") || (sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
      bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

      if (bolMask) {
         sCod += sMask.charAt(i);
         mskLen++;
      }
      else {
         sCod += sValue.charAt(nCount);
         nCount++;
      }

      i++;
   }

   //objForm[strField].value = sCod;
   document.getElementById(strField).value = sCod;

   if (nTecla != 8 && nTecla != 0) { // backspace
	  if(sMask.charAt(i-1) == ''){
		return false;
	}
      if (sMask.charAt(i-1) == "9") { // apenas números...
         return ((nTecla > 47) && (nTecla < 58));
      } else { // qualquer caracter...
         return true;
      }
   }
   else{
      return true;
   }
}
//=========================================================================================================================
function autoFormat_pt2(vObj,sMask,evtKeyPress){
	var i, nCount, sValue, fldLen, mskLen, bolMask, sCod, nTecla,sValorAntigo,sValorAtual;
//	   var vObj = document.getElementById(vstrObj);
	var sValorAntigo = vObj.getAttribute('_valorAntigo_Mask');
	var sValorAtual = vObj.value;
	if (!sValorAntigo)
		sValorAntigo = sValorAtual;

	sValorAntigo = vObj.getAttribute('_valorAntigo_Mask') + '';
	sValorAtual = vObj.value;

	if (vObj.getAttribute('nTecla_ult') == 8){	
		sValorAntigo = sValorAntigo.substr(0,sValorAntigo.length-1);
	}else{
		sValorAtual = sValorAtual.substr(0,sValorAtual.length-1);
	}

   if(document.all) { // Internet Explorer
      nTecla = evtKeyPress.keyCode;
   }
   else if(document.layers) { // Nestcape
      nTecla = evtKeyPress.which;
   }else{
   	  nTecla = evtKeyPress.charCode;
	  if (nTecla == 0)
	   	  nTecla = evtKeyPress.keyCode;	  
   }

	vObj.setAttribute('nTecla_ult',nTecla);

	if (nTecla==9 || nTecla==8 || nTecla==37 || nTecla==38 || nTecla==39 || nTecla==40 || nTecla==116 || nTecla==27 || nTecla==46 || nTecla==34 || nTecla==33 || nTecla==36 || nTecla==35 || nTecla==120 ){
        vObj.setAttribute('_valorAntigo_Mask',vObj.value);	
		return true;
	}

		if(sMask.charAt(i-1) == ''){
			autoFormat_colocaMask(vObj,sMask);	  
			return false;
		}

	  if (sValorAntigo == sValorAtual){
		  autoFormat_colocaMask(vObj,sMask);
      }else{
		  vObj.setAttribute('_valorAntigo_Mask',vObj.value);
	  }
}
//=========================================================================================================================
function autoFormat_colocaMask(vObj,sMask){
	var i, nCount, sValue, fldLen, mskLen, bolMask, sCod, nTecla,sValorAntigo,sValorAtual;
	
	   sValue = vObj.value;
	   sValue = sValue.toString().replace( "-", "" );
	   sValue = sValue.toString().replace( "x", "" );	   
	   sValue = sValue.toString().replace( "x", "" );	   
	   sValue = sValue.toString().replace( "-", "" );
	   sValue = sValue.toString().replace( ".", "" );
	   sValue = sValue.toString().replace( ".", "" );
	   sValue = sValue.toString().replace( "/", "" );
	   sValue = sValue.toString().replace( "/", "" );
	   sValue = sValue.toString().replace( "(", "" );
	   sValue = sValue.toString().replace( "(", "" );
	   sValue = sValue.toString().replace( ")", "" );
	   sValue = sValue.toString().replace( ")", "" );
	   sValue = sValue.toString().replace( ":", "" );
	   sValue = sValue.toString().replace( " ", "" );
	   sValue = sValue.toString().replace( " ", "" );
	   fldLen = sValue.length;
	   mskLen = sMask.length;
	
	   i = 0;
	   nCount = 0;
	   sCod = "";
	   mskLen = fldLen;
	
	   while (i <= mskLen) {
		  bolMask = ((sMask.charAt(i) == ":") || (sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
		  bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " ") || (sMask.charAt(i) == "x"))
	
		  if (bolMask) {
			 sCod += sMask.charAt(i);
			 mskLen++;
		  }
		  else {
			 sCod += sValue.charAt(nCount);
			 nCount++;
		  }
	
		  i++;
	   }
	  vObj.value = sCod;
	  vObj.setAttribute('_valorAntigo_Mask',sCod);
}
//=========================================================================================================================
function autoFormat(vObj, sMask, evtKeyPress) {

	if (!vObj.getAttribute('marcouKeyUp')){
	   try{
	        vObj.addEventListener('keyup',function(e){autoFormat_pt2(this,sMask,e)},true);
	   }catch(ee){
	        try{
	            vObj.attachEvent('keyup',function(e){autoFormat_pt2(this,sMask,e)},true);
	        }catch(ee2){}
	   }
	   
       vObj.setAttribute('marcouKeyUp',1);
	}
   var i, nCount, sValue, fldLen, mskLen, bolMask, sCod, nTecla,sValorAntigo,sValorAtual;
	var debug = document.getElementById("debug")
   if(document.all) { // Internet Explorer
      nTecla = evtKeyPress.keyCode;
   }
   else if(document.layers) { // Nestcape
      nTecla = evtKeyPress.which;
   }else{
   	  nTecla = evtKeyPress.charCode;
	  if (nTecla == 0)
	   	  var nTecla2 = evtKeyPress.keyCode;
   }

	if (nTecla==13)
		autoFormat_colocaMask(vObj,sMask);

	if (nTecla2==9 || nTecla2==8 || nTecla2==37 || nTecla2==38 || nTecla2==39 || nTecla2==40 || (nTecla2 == 116) || nTecla2==27 || nTecla2==46 || nTecla2==34 || nTecla2==33 || nTecla2==36 || nTecla2==35 || nTecla2==120 ){
	   vObj.setAttribute('nTecla',nTecla);	
		return true;
	}




//   debug.innerHTML += 'sValorAtual=' + sValorAtual + '<BR>';
//   debug.innerHTML += 'sValorAntigo_ant=' + vObj.getAttribute('_valorAntigo_Mask') + '<BR>';   
//   debug.innerHTML += 'sValorAntigo=' + sValorAntigo + '<BR>';

	   sValue = vObj.value;
	   sValue = sValue.toString().replace( "-", "" );
	   sValue = sValue.toString().replace( "x", "" );	   
	   sValue = sValue.toString().replace( "x", "" );	   
	   sValue = sValue.toString().replace( "-", "" );
	   sValue = sValue.toString().replace( ".", "" );
	   sValue = sValue.toString().replace( ".", "" );
	   sValue = sValue.toString().replace( "/", "" );
	   sValue = sValue.toString().replace( "/", "" );
	   sValue = sValue.toString().replace( "(", "" );
	   sValue = sValue.toString().replace( "(", "" );
	   sValue = sValue.toString().replace( ")", "" );
	   sValue = sValue.toString().replace( ")", "" );
	   sValue = sValue.toString().replace( ":", "" );
	   sValue = sValue.toString().replace( " ", "" );
	   sValue = sValue.toString().replace( " ", "" );
	   fldLen = sValue.length;
	   mskLen = sMask.length;
	
	   i = 0;
	   nCount = 0;
	   sCod = "";
	   mskLen = fldLen;
	
	   while (i <= mskLen) {
		  bolMask = ((sMask.charAt(i) == ":") || (sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
		  bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " ") || (sMask.charAt(i) == "x"))
	
		  if (bolMask) {
			 sCod += sMask.charAt(i);
			 mskLen++;
		  }
		  else {
			 sCod += sValue.charAt(nCount);
			 nCount++;
		  }
	
		  i++;
	   }
	if (!sValorAntigo || sValorAtual == sValorAntigo){	
//	   vObj.value = sCod;
	}

//   vObj.setAttribute('_valorAntigo_Mask',vObj.value);
//   debug.innerHTML = debug.innerHTML + '_valorAntigo_Mask='+vObj.getAttribute('_valorAntigo_Mask') + '<BR>';



	if (nTecla != 8 && nTecla != 0) { // backspace
		if(sMask.charAt(i-1) == ''){
			autoFormat_colocaMask(vObj,sMask);	  
			return false;
		}
		if (sMask.charAt(i-1) == "9") { // apenas números...
			return ((nTecla > 47) && (nTecla < 58));
		} else { // qualquer caracter...
			return true;
		}
	}else{
		return true;
	}
}
//=================================================================================== 
function blockNonNumbers(obj, e, allowDecimal, allowNegative){


	var key;
	var isCtrl = false;
	var keychar;
	var reg;
		
	if(window.event) {
		key = e.keyCode;
		isCtrl = window.event.ctrlKey
	}
	else if(e.which) {
		key = e.which;
		isCtrl = e.ctrlKey;
	}
	
	if (isNaN(key)) return true;
	
	keychar = String.fromCharCode(key);
	
	// check for backspace or delete, or if Ctrl was pressed
	if (key == 8 || isCtrl)
	{
		return true;
	}

	reg = /\d/;
	var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
	var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
	
	return isFirstN || isFirstD || reg.test(keychar);
}


//=========================================================================
function mostrarBalao(){
    var object = document.getElementById('img_caixa_cep');
    var object_referencia = document.getElementById('img_caixa_cep_referencia');
    
    if (object){
        object.style.left = (object_referencia.offsetLeft + 40) + 'px';
        object.style.top = (object_referencia.offsetTop  - 93) + 'px';
        object.style.display = '';
    }
}
//=========================================================================
function esconderBalao(){
    var object = document.getElementById('img_caixa_cep');
    
    if (object){
        object.style.display = 'none';
    }
}
//===========================================================================
function sair(){
	alert('Dr(a), obrigado por acessar o portal Torrent on-line.\nSua sessão foi encerrada com sucesso.');
	window.location.href='Logoff.asp';
}
//===========================================================================
function isNumeric(ptexto) {
    var numeric = true;
    for (i=0; i < ptexto.length; i++) {
        if (!isDigit(ptexto.charAt(i)) ) {
            numeric = false;
            break;
        }
    }
    return numeric;
}
//===================================================================================
function isDigit(pchar) {
    return ("0123456789,.".indexOf(pchar)>=0);
}

