function FocarNews (acao)
{
    var obj = document.getElementById('email_news');
    
    if (acao){
		if (obj.value == "seu e-mail")
            obj.value = "";
	} else {
		if (obj.value.length == 0)
            obj.value = "seu e-mail";
	}
}

function setMenu(ref)
{
	var obj = document.getElementById(ref);
	var Sub = document.getElementById("sub"+ref);
	
	if (obj.style.display == "none"){
		obj.style.display = "block";
		Sub.style.display = "none";
	} else {		
		obj.style.display = "none";
		Sub.style.display = "block";
	}
}

function busca(ref)
{
	var obj = document.getElementById('ctl00_EdProduto');
	
	if (ref){
		if (obj.value == "Procurar por..."){
			obj.value = "";
			obj.style.textTransform = "uppercase";
		}
	} else {
		if (obj.value.length == 0){
			obj.style.textTransform = "none";
			obj.value = "Procurar por..."
		}
	}
}


function resizeBody ()
{
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  
  document.getElementById('body').style.width = myWidth + "px";
  document.getElementById('body').style.height = myHeight + "px";
}

function bula()
{
	var view = document.getElementById('view');
	var left = document.getElementById('left');
	var right = document.getElementById('right');
	var hs = document.getElementById('hideShow');
	
	if (view.value == 0)
	{
		left.style.width = "0";
		left.style.paddingRight = "0";
		right.style.width = "663px";
		hs.title = "Diminuir Descricao";
		hs.style.left = "15px";
		hs.style.backgroundImage = "url(../imagens/detalhes/exibe_oculta2.gif)";
		view.value = 1;
	}
	else
	{
		left.style.width = "247px";
		left.style.paddingRight = "22px";
		right.style.width = "394px";
		hs.title = "Aumentar Descricao";
		hs.style.left = "284px";
		hs.style.backgroundImage = "url(../imagens/detalhes/exibe_oculta.gif)";
		view.value = 0;
	}
}

 function ajax(url,destino){
	  var obj = document.getElementById(destino);
	
	switch (destino){
	  case 'newsletter':
	    document.getElementById('newsletter').style.display         = 'none';
        document.getElementById('newsletter-load').style.display    = 'block';
        document.getElementById('newsletter-sucesso').style.display = 'none';
	    break;
	  
	  case 'atendimento':
	    document.getElementById(destino).innerHTML = '';
	    break;
	
	  default:
        obj.innerHTML = 'Processando...';
	  break;
	}

    var http; // referência ao objeto XMLHttpRequest

    if(window.XMLHttpRequest && navigator.appVersion.indexOf('MSIE') < 0){
        http = new XMLHttpRequest();
    }
    else if(window.ActiveXObject){
        http = new ActiveXObject("Msxml2.XMLHTTP");
        if(!http)
            http = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else{
        http = null;
        alert('Seu navegador nao possui o recurso necessário.');
    }	

    http.onreadystatechange = function(){
        if(http.readyState < 4)
        {
            //obj.className = (destino=='frame'?"loading":"loading2");
            //obj.innerHTML = "";
        }
        else if(http.readyState == 4)
        {
            switch (destino)
            {
                case 'newsletter':
                    document.getElementById('newsletter').style.display         = 'none';
                    document.getElementById('newsletter-load').style.display    = 'none';
                    document.getElementById('newsletter-sucesso').style.display = 'block';
                    break;
                
                case 'atendimento':
                    alert(http.responseText);
                    /*
                    if (http.responseText == '1')
                        document.getElementById(destino).innerHTML = '<img src="../imagens/layout/top-online.gif" alt="" />';
                    else if (http.responseText == '0')
                        document.getElementById(destino).innerHTML = '<img src="../imagens/layout/top-offline.gif" alt="" />';
                        */
                    break;
            }
        }
    }
    
    http.open("GET",url,true);
    http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 
    http.send(null); // variaveis de post
 }


//busca
function search (tcl,oEvent){
  var oEvent = oEvent ? oEvent : window.event;
  var tecla = (oEvent.keyCode) ? oEvent.keyCode : oEvent.which;
  var value = document.getElementById('ctl00_EdProduto').value;

  if (tcl == 'click')
  {
    if (value != 'Procurar por...' && value != '')
    {
      window.location.href = '../produto/frmprodutos.aspx?produto='+value;
      return false;
    }
    else
    {
      value = document.getElementById('ctl00_EdProduto').focus();
    }
  }
  return (tecla != 13);
}

load = new Image();
load.src = "../imagens/layout/load.gif";


//envia form PagSeguro
function enviaForm(pedido){
    var left = (screen.availWidth - 770)/2;
    var top  = (screen.availHeight - 500)/2;
    window.open('about:blank','frame','resizable=yes,scrollbars=yes,directories=no,location=no,menubar=no,status=yes,titlebar=no,toolbar=no,width='+left+',height='+top);
    document.documentGetElementById('formPagSeguro').submit();
    window.location = 'comprafinalizada.aspx?numped='+pedido;
}


//altera url - acao[ order, modo ];
function setUrl (selecao, acao)
{
  var urlCompleta = window.location.href;
  var destino = "";
  var end = "";
  var params = "";
  
  // havendo flutuantes
  if (urlCompleta.indexOf('?') > 0)
  {
    var url = urlCompleta.split('?');
        end = url[0];
     params = url[1];
    
    // havendo acao
    if (params.indexOf(acao + '=') < 0)
      destino = params + "&" + acao + "=" + selecao;
    else
    {
      params = params.split('&');
      for (i = 0; i < params.length; i++)
      {
        if (params[i].indexOf(acao + '=') >= 0)
          params[i] = acao + "=" + selecao;
        destino += (i > 0 ? "&" : "" ) + params[i];
      }
    } 
  }
  else
    destino = acao + "=" + selecao;
  
  window.location = end + "?" + destino;
}


//bulario
function Bulario(){
    var width = (screen.availWidth > 900 ? 820 : screen.availWidth);
    var height = 500;
    var left = (screen.availWidth - width)/2;
    var top  = (screen.availHeight - height)/2;
    window.open('http://www.anvisa.gov.br/bularioeletronico/','frame','width='+width+',height='+height+',top='+top+',left='+left+',resizable=yes,scrollbars=yes,directories=no,location=no,menubar=no,status=yes,titlebar=no,toolbar=no');
}


// abas login
function set (vlr)
{
	for (i = 1; i <= 3; i++){
		if (i == vlr){
			document.getElementById('opt_'+ i).className = "opt_on";
			document.getElementById('form_'+ i).style.display = "block";
		} else {
			document.getElementById('opt_'+ i).className = "opt_off";
			document.getElementById('form_'+ i).style.display = "none";
		}
	}
}


// popup generica

function popup(url, width, height)
{
    if (width == 0)
        width = screen.availWidth;
    if (height == 0)
        height = screen.availHeight;
   
    var left = (screen.availWidth - width)/2;
    var top  = (screen.availHeight - height)/2;
    window.open(url,'frame','width='+width+',height='+height+',top='+top+',left='+left+',resizable=yes,scrollbars=yes,directories=no,location=no,menubar=no,status=yes,titlebar=no,toolbar=no');
 } 