
//*****************************************************************************
// Objetivo  : Abrir janela de Consulta do DXW - Demonstrativos Financeiros
// Premissas : --
// Entradas  : strLink - Link da janela
// Retorno   : --
//*****************************************************************************  
function ConsultarDXW(strLink)
{
    window.open(strLink,"ConsultaDXW","resizable=no,width=800,height=520,scrollbars=yes");
}

//*****************************************************************************
// Objetivo  : Retorna a janela anterior do histÃ³rico
// Premissas : --
// Entradas  : --
// Retorno   : --
//*****************************************************************************  
function Voltar()
{
    window.history.back();
}

/********************************************************************************\
| Objetivo  : Monta e exibe o hint para o ITR e DFP
| Premissas : N/A
| Entradas  : objCombo - combo que contem os dados do hint
| Retorno   : Nenhum
\********************************************************************************/
/*
function MontaHint(objCombo)
{
	try{
		var objOption = objCombo
		//var objOption = objCombo.options[objCombo.selectedIndex]
		return "<b>Data de ReferÃªncia:</b> " + objOption.value + "<br>" +
		       "<b>Modalidade:</b> " + objOption.modalidade + "<br>" +
		       "<b>Entrega:</b> " + objOption.entrega + "<br>" +
		       "<b>Data de Recebimento:</b> " + objOption.dataentrega
	}catch(e){}
}
*/

function MontaHint(dataReferencia, modalidade, entrega, dataRecebimento, idioma) {
    try {
        if (idioma == "P") {
            return "<b>Data de Refer&ecirc;ncia:</b> " + dataReferencia + "<br>" +
		                   "<b>Modalidade:</b> " + modalidade + "<br>" +
		                   "<b>Entrega:</b> " + entrega + "<br>" +
		                   "<b>Data de Recebimento:</b> " + dataRecebimento
        }
        if (idioma == "I") {
            return "<b>Date of Reference:</b> " + dataReferencia + "<br>" +
		                   "<b>Modality:</b> " + modalidade + "<br>" +
		                   "<b>Delivery:</b> " + entrega + "<br>" +
		                   "<b>Reception Date:</b> " + dataRecebimento
        }
        if (idioma == "E") {
            return "<b>Fecha de Referencia:</b> " + dataReferencia + "<br>" +
		                   "<b>Modalidad:</b> " + modalidade + "<br>" +
		                   "<b>Entrega:</b> " + entrega + "<br>" +
		                   "<b>Fecha del Recibimiento:</b> " + dataRecebimento
        }
    }
    catch (e) { }
}

//*****************************************************************************
// Objetivo:              Codigo para geracao dos hint
// Autor:                 (*)(ver comentarios)
// Data:                  06/06/2007
//
// ComentÃ¡rios:          (*) codigo extraÃ­do da internet: http://www.dynamicdrive.com/
//                           adaptado para o manual do desenvolvedor
//                           segue o comentario original da pagina
//
//                        ALTTXT V1.2
//                        BY: BRIAN GOSSELIN OF SCRIPTASYLUM.COM
//                        ADDED FADING EFFECT FOR IE4+ AND NS6+ ONLY AND OPTIMIZED THE CODE A BIT.
//                        SCRIPT FEATURED ON DYNAMIC DRIVE (http://www.dynamicdrive.com)
//                        Modifed by DD for doctype bug on Nov 13th, 2003
//
// Alterado Por:
// Data:
// Motivo da AlteraÃ§Ã£o:
//*****************************************************************************
// Componentes Usados:    nao se aplica
// Entradas:              nenhuma
// retorno:               nenhum
//*****************************************************************************

var blnDoFade     = false; // ENABLES FADE-IN EFFECT FOR IE4+ AND NS6 ONLY
var blnCenter     = false; // CENTERS THE BOX UNER THE MOUSE, OTHERWISE DISPLAYS BOX TO THE RIGHT OF THE MOUSE
var blnCenterText = false; // CENTERS THE TEXT INSIDE THE BOX. YOU CAN'T SIMPLY DO THIS VIA STYLE BECAUSE OF NS4.
                           // OTHERWISE, TEXT IS LEFT-JUSTIFIED.






////////////////////////////// NO NEED TO EDIT BEYOND THIS POINT //////////////////////////////////////





//*****************************************************************************
// Objetivo  : Buscar referencia para ...
// Premissas : --
// Entradas  : --
// Retorno   : referencia para ...
//*****************************************************************************
function ietruebody()
{
	return (document.compatMode && document.compatMode!="BackCompat") ? document.documentElement : document.body
}

var blnNS4 = (navigator.appName.indexOf("Netscape") >= 0 && !document.getElementById) ? true : false; // NS4
var blnIE4 = (document.all && !document.getElementById) ? true : false;                               // IE4
var blnIE5 = (document.getElementById && document.all) ? true : false;                                // IE5
var blnNS6 = (document.getElementById && navigator.appName.indexOf("Netscape") >= 0 ) ? true : false; // NS6
var blnW3C = (document.getElementById) ? true : false;                                                // W3C
var intWY, intWX, navtxt, intBoxHeight, intBoxWidth; // WY, WX, boxh, boxw
var blnIsHover = false;  // ishover
var blnIsLoaded = false; // isloaded
var intIEOP = 0;         // ieop
var intOPID = 0;         // opid

//*****************************************************************************
// Objetivo  : Recupera os limites da janela
// Premissas : --
// Entradas  : --
// Retorno   : --
//*****************************************************************************
function getwindowdims()
{
	intWY = (blnNS4 || blnNS6 || window.opera) ? window.innerHeight : (blnIE5 || blnIE4) ? document.body.clientHeight : 0;
	intWX = (blnNS4 || blnNS6 || window.opera) ? window.innerWidth  : (blnIE5 || blnIE4) ? document.body.clientWidth  : 0;
}

//*****************************************************************************
// Objetivo  : Recupera o boxwidth
// Premissas : --
// Entradas  : --
// Retorno   : --
//*****************************************************************************
function getboxwidth()
{
	if(blnNS4)           intBoxWidth = (navtxt.document.width)   ? navtxt.document.width        : navtxt.clip.width;
	if(blnIE5 || blnIE4) intBoxWidth = (navtxt.style.pixelWidth) ? navtxt.style.pixelWidth      : navtxt.offsetWidth;
	if(blnNS6)           intBoxWidth = (navtxt.style.width)      ? parseInt(navtxt.style.width) : parseInt(navtxt.offsetWidth);
}

//*****************************************************************************
// Objetivo  : Recupera o boxheight
// Premissas : --
// Entradas  : --
// Retorno   : --
//*****************************************************************************
function getboxheight()
{
	if(blnNS4)           intBoxHeight = (navtxt.document.height    )? navtxt.document.height  : navtxt.clip.height;
	if(blnIE4 || blnIE5) intBoxHeight = (navtxt.style.pixelHeight) ? navtxt.style.pixelHeight : navtxt.offsetHeight;
	if(blnNS6)           intBoxHeight = parseInt(navtxt.offsetHeight);
}

//*****************************************************************************
// Objetivo  : Move o hint
// Premissas : --
// Entradas  : intX -> posicao horizontal
//             intY -> posicao vertical
// Retorno   : --
//*****************************************************************************
function movenavtxt(intX, intY)
{
	if(blnNS4) navtxt.moveTo(intX, intY);
	if(blnW3C || blnIE4)
	{
		navtxt.style.left = intX + 'px';
		navtxt.style.top = intY + 'px';
	}
}

//*****************************************************************************
// Objetivo  : Recupera o pagescrolly
// Premissas : --
// Entradas  : --
// Retorno   : --
//*****************************************************************************
function getpagescrolly()
{
	if(blnNS4 || blnNS6) return window.pageYOffset;
	if(blnIE5 || blnIE4) return ietruebody().scrollTop;
}

//*****************************************************************************
// Objetivo  : Recupera o pagescrollx
// Premissas : --
// Entradas  : x -> posicao horizontal
//             y -> posicao vertical
// Retorno   : --
//*****************************************************************************
function getpagescrollx()
{
	if(blnNS4 || blnNS6) return window.pageXOffset;
	if(blnIE5 || blnIE4) return ietruebody().scrollLeft;
}

//*****************************************************************************
// Objetivo  : Escreve no div
// Premissas : --
// Entradas  : strText -> texto a escrever
// Retorno   : --
//*****************************************************************************
function writeindiv(strText)
{
	if(blnNS4)
	{
		navtxt.document.open();
		navtxt.document.write(strText);
		navtxt.document.close();
	}
	if(blnW3C || blnIE4) navtxt.innerHTML = strText;
}

//**** END UTILITY FUNCTIONS ****//

//*****************************************************************************
// Objetivo  : Escreve
// Premissas : --
// Entradas  : strText -> text
// Retorno   : --
//*****************************************************************************
function writetxt(strText)
{    
	if(blnIsLoaded)
	{
		if(strText != 0)
		{		
			blnIsHover=true;
			if(blnNS4) strText = '<div class="navtext">' + ((blnCenterText) ? '<center>' : '') + strText + ((blnCenterText) ? '</center>':'') + '</div>';
			writeindiv(strText);
			getboxheight();
			if((blnW3C || blnIE4) && blnDoFade)
			{
				intIEOP = 0;
				incropacity();
			}
		}
		else
		{	
			if(blnNS4)navtxt.visibility = "hide";
			if(blnIE4 || blnW3C)
			{
				if(blnDoFade)clearTimeout(intOPID);
				navtxt.style.visibility = "hidden";
			}
			writeindiv('');
			blnIsHover = false;
		}
	}
}

//*****************************************************************************
// Objetivo  : Seta opacity
// Premissas : --
// Entradas  : --
// Retorno   : --
//*****************************************************************************
function incropacity()
{
	if(intIEOP <= 100)
	{
		intIEOP += 7;
		if(blnIE4 || blnIE5) navtxt.style.filter = "alpha(opacity=" + intIEOP + ")";
		if(blnNS6)           navtxt.style.MozOpacity = intIEOP / 100;
		intOPID = setTimeout('incropacity()', 50);
	}
}

//*****************************************************************************
// Objetivo  : Move o objeto
// Premissas : --
// Entradas  : objEVT -> objeto do evento
// Retorno   : --
//*****************************************************************************
function moveobj(objEVT)
{
	var intMX;     // mx
	var intMY;     // my
	var intXOFF;   // xoff
	var intYOFF;   // yoff
	var intMargin; // margin
	
	if(blnIsLoaded && blnIsHover)
	{
		intMargin = (blnIE4 || blnIE5) ? 1 : 23;
		if(blnNS6) if(document.height + 27 - window.innerHeight < 0) intMargin = 15;
		if(blnNS4) if(document.height - window.innerHeight < 0)      intMargin = 10;
		//intMX = (blnNS4||blnNS6)? objEVT.pageX : (blnIE5 || blnIE4) ? event.clientX : 0;
		//intMY = (blnNS4||blnNS6)? objEVT.pageY : (blnIE5 || blnIE4) ? event.clientY : 0;
		if (blnNS4)
		{
			intMX = objEVT.pageX
			intMY = objEVT.pageY
		}
		else if (blnNS6)
		{
			intMX = objEVT.clientX
			intMY = objEVT.clientY
		}
		else if (blnIE5)
		{
			intMX = event.clientX
			intMY = event.clientY
		}
		else if (blnIE4)
		{
			intMX = 0
			intMY = 0
		}

		if(blnNS4)
		{
			intMX -= getpagescrollx();
			intMY -= getpagescrolly();
		}
		intXOFF = (blnCenter) ? intMX - intBoxWidth / 2 : intMX + 9;
		intYOFF = (intMY + intBoxHeight + -18 - getpagescrolly() + intMargin >= intWY) ? -15 - intBoxHeight : -18;
		movenavtxt( Math.min(intWX - intBoxWidth - intMargin , Math.max(2, intXOFF)) + getpagescrollx(), intMY + intYOFF + getpagescrolly());
		if(blnNS4)          navtxt.visibility       = "show";
		if(blnW3C ||blnIE4) navtxt.style.visibility = "visible";
	}
}

if(blnNS4) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = moveobj;

//*****************************************************************************
// Objetivo  : Carrega o hint
// Premissas : --
// Entradas  : --
// Retorno   : --
//*****************************************************************************  
function loadnavtxt()
{
	navtxt = (blnNS4) ? document.layers['navtxt'] : (blnIE4) ? document.all['navtxt'] : (blnW3C) ? document.getElementById('navtxt') : null;
	getboxwidth();
	getboxheight();
	getwindowdims();
	blnIsLoaded = true;
	if((blnW3C || blnIE4) && blnCenterText) navtxt.style.textAlign = "center";
	if(blnW3C)                              navtxt.style.padding   = '4px';
	if(blnIE4 || blnIE5 && blnDoFade)       navtxt.style.filter    = "alpha(opacity=0)";
}

window.onresize = getwindowdims;


/***************************************************************************
Objetivo  :Abre popup com as informacoes ITR/DFP/IAN
Premissas :Não possui
Entradas  :intTipo - itr/dfp/ian
           dtmData - data da consulta
           strPagina - consulta / download   
Retorno   :Não possui
Data	  :Janeiro 2003
Autor	  :Leandro Reis
***************************************************************************/
function ConsultaItrDfpIan(intTipo, dtmData, razaoSocial, pregao, mercado, codigoCvm, download){
	var strLink;//configura link
	var strParametros; //Monta os parâmetros	
	var strSite; // o site
	
	if(mercado == 7)
	{
	    strSite = 'S';
	}
	else
	{
	    strSite = 'B';
	}
		            	
	strLink = (download == 1) ? 'DownloadArquivo.aspx?moeda=L&' : 'ResumoMenu.aspx?';
	
	strParametros = 'site=' + strSite + '&mercado=' + mercado + '&razao=' + razaoSocial + '&pregao='+ pregao +'&ccvm=' + codigoCvm + '&data='+dtmData+'&tipo='+intTipo;
	strLink = '../../dxw/' + strLink + strParametros;
	
	if(download == 0)
	{	    
	    window.open(strLink,'Divulgacao','toolbar=no,status=no,width=700,height=500,scrollbars=yes,resizable=yes,location=no');
	}
	else
	{	 
	    location.href = strLink;
	}	    	    
}


function submitForm(formulario, pagina, target)
{
    //recupera os valores originais do form.
    var _target = document.getElementById(formulario).target;
    var _action = document.getElementById(formulario).action;
    //define as propriedades
    if(target != '')
    {
        document.getElementById(formulario).target = target;
    }    
    document.getElementById(formulario).action = pagina;
    //envia o formulário
    document.getElementById(formulario).submit();
    //volta os valores padrões das propriedades
    if(target != '')
    {
        document.getElementById(formulario).target = _target;
    }    
    document.getElementById(formulario).action = _action;
}

/********************************************************************************
' Objetivo           : Abre janela exibindo locais de publicacao
' Premissas          : Nenhuma
' Entradas           : nao possui
' retorno            : Nenhum
'********************************************************************************/
function publicacao (strProtocolo)
{
    window.open(href='DetalheDemonstrativoFinanceiroLocalPublicacao.aspx?protocolo='+strProtocolo, '', 'width=850,height=600,directories=0,toolbar=0,status=0,location=0,resizable=1,scrollbars=1, title=0')
}

/********************************************************************************
' Objetivo           : Visualizar o arquivo
' Premissas          : Nenhuma
' Entradas           : Código CVM da empresa, Protocolo do documento, motivo 
                        do cancelamento, idioma
' retorno            : Nenhum
'********************************************************************************/
function consultaArquivo(codigoCvm, protocolo, motivoCancelamento, idioma)
{
    window.location.href = 'ConsultaArquivo.aspx?codigoCvm=' + codigoCvm + '&protocolo=' + protocolo + '&motivo=' + motivoCancelamento + '&idioma=' + idioma;
    //, 'width=650,height=400,directories=0,toolbar=0,status=0,location=0,resizable=1,scrollbars=1, title=0'
}

/********************************************************************************
' Objetivo           : Abre popup com as informacoes do DRI ativo
' Autor	             : 
' Data	             : 
' Comentários        :
' Alterado Por       :
' Data               : 
' Motivo da Alteração:
' Componentes Usados :
' Premissas          : Nenhuma
' Entradas           : Código Cvm da empresa, idioma
' retorno            : Nenhum
'********************************************************************************/
function AbreDri(codigoCvm, idioma)
{
    window.open(href='DetalheDemonstrativoFinanceiroDri.aspx?idioma=' + idioma + '&codigoCvm=' + codigoCvm, '', 'width=500,height=200,directories=0,toolbar=0,status=0,location=0,resizable=0,scrollbars=1, title=0')
}

/********************************************************************************
' Objetivo           : Abre popup com as informacoes do DRI ativo
' Autor	             : 
' Data	             : 
' Comentários        :
' Alterado Por       :
' Data               : 
' Motivo da Alteração:
' Componentes Usados :
' Premissas          : Nenhuma
' Entradas           : Tipo do período
                        1 - No dia
                        2 - Na última semana
                        3 - Nos últimos 30 dias;
                        Campo da data de início, campo da data fim, data atual,
                        data da última semana e a data de 30 dias atrás
' retorno            : Nenhum
'********************************************************************************/
function PeriodoDocumento(tipoPeriodo, txtDataInicio, txtDataFim, dataAtual, dataUltimaSemana, dataUltimoTrintaDias)
{
    switch(tipoPeriodo)
    {
        case 1:
            window.alert(tipoPeriodo);
            document.getElementById(txtDataInicio).value = dataAtual;
            document.getElementById(txtDataFim).value = dataAtual;
            break;
        case 2:
            window.alert(tipoPeriodo);
            document.getElementById(txtDataInicio).value = dataUltimaSemana;
            document.getElementById(txtDataFim).value = dataAtual;
            break;
        case 3:
            window.alert(tipoPeriodo);
            document.getElementById(txtDataInicio).value = dataUltimoTrintaDias;
            document.getElementById(txtDataFim).value = dataAtual;
            break;        
    }
}

function ExibirLocalPublicacao(controle)
{    
    if(document.getElementById(controle).style.display == 'block')
    {
        document.getElementById(controle).style.display = 'none';
    }
    else
    {
        document.getElementById(controle).style.display = 'block';
    }
}

/***************************************************************************
Objetivo:Abre popup 
Entrada	:strURL - URL a ser aberta
        :strWinName - nome da janela
        :strFeatures - parâmetros da janela
Data	:Janeiro 2003
***************************************************************************/
function MM_openBrWindow(strURL,strWinName,strFeatures) { //v2.0
  window.open(strURL,strWinName,strFeatures);
}


function DesmarcarPeriodo(controle)
{    
    for (i=0;i < controle.childNodes[0].getElementsByTagName("input").length;i++)
    {
        controle.childNodes[0].getElementsByTagName("input")[i].checked = false;    
    }
}

function valida(controle, campo)
{
    if (document.getElementById(controle.id).value == '')
        alert('Campo ' + campo + ' é obrigatório.');
}

function validaData(controle, dtIni, dtFim)
{
    if ((controle.childNodes[0].getElementsByTagName("input")[0].checked==false && 
        controle.childNodes[0].getElementsByTagName("input")[1].checked==false) &&
        (document.getElementById(dtIni.id).childNodes[0].childNodes[1].value == '' && 
         document.getElementById(dtFim.id).childNodes[0].childNodes[1].value == ''))
        alert('Por favor marque uma opção de pesquisa de data \n Ou escolha livremente o período da consulta');
}

function exibir(objeto)
{
    var nomeObjeto = new String();        
    nomeObjeto = objeto;
    
    //Se o display do objeto é none, atribuo block, senão, atribuo none
    document.getElementById(objeto).style.display = (document.getElementById(objeto).style.display == 'none')? 'block': 'none';
}

function cotacaoRapida(ativo)
{
    window.open('../../cotacao-rapida/cotacaorapida.aspx?codigoAtivo=' + ativo, '', 'width=352px,height=300px,scrollbars=1');
}

function AbreFormularioCadastral(url)
{
    window.open(url, '', 'width=800px,height=520px,scrollbars=1')
}
