<!--//
function abrejanela(url,nome,tamhor,tamver,scrollyn,usesize,resize,xLeft,yTop) 
{
  if(resize=='')
    {
    resize='no'
    }
  if (xLeft != null)
		{
		x = xLeft;
		}
	else
		{
		x=(screen.availWidth/2)-(tamhor/2)
		}
	if (yTop != null)
		{
		y = yTop;
		}
	else
		{
		y=(screen.availHeight/2)-(tamver/2)-20
		}
  
  if (navigator.appName=='Netscape')
    {
    if (usesize=='1')
      {
      outsidewd = window.open (url,nome,'toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,hotkeys=no')
      }
    else if (usesize!='1')
      {
      outsidewd = window.open(url,nome,"screenX=0,resizable="+resize+",hotkeys=no,scrollbars=" + scrollyn + ",screenY=0,outerWidth=" + tamhor + ",outerHeight=" + tamver+ ",left=" + x + ",top=" + y)
      }
    }
  else
    {
    if (usesize=='1')
      {
	  outsidewd = window.open (url,nome,'toolbar=yes,location=yes,hotkeys=no,status=yes,menubar=yes,scrollbars=yes,resizable='+resize)
	  }
	else if (usesize!='1')
	  {
	  outsidewd = window.open(url,nome,'resizable='+resize+',hotkeys=no,scrollbars=' + scrollyn + ',Width=' + tamhor + ',Height=' + tamver + ',left=' + x + ',top=' + y + ' ')
      }
  }
}

/*-------------------------------------------------------
 Objectivo: Faz o replace de uma string em outra, 
			funciona em NN4+ e IE4+
*/
function replace(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

/*-------------------------------------------------------
 Objectivo: Fecha a janela de negociação quando a sessão é encerrada
*/
function JanelaTopo(sRef) {

	if (parent.opener != null) 
		{
			alert("A sua sessão expirou. Se quer continuar a negociar, por favor, volte a fazer o logon.");
			window.parent.close();
			//parent.opener.location.href='<%=c_sLinkSeguro & c_sNomeServidor%>/pt/logon_S/acessorestrito.asp?Type=C&Pag=Mybolsa';
			parent.opener.location.href=sRef;
		}
	else
	{
	if (window.opener != null)
	{
		alert("A sua sessão expirou. Se quer continuar a negociar, por favor, volte a fazer o logon.");
		window.close();
		window.opener.location.href=sRef;
	}
	}
}

/*-------------------------------------------------------
 Objectivo: Fecha a janela de negociação quando a sessão é encerrada
*/
function JanelaTopoMyBolsa() 
{
	if (window.opener != null) 
	{
		alert("A sua sessão expirou. Se quer continuar a negociar, por favor, volte a fazer o logon.");
		window.close();
		window.opener.location.href='<%=c_sLinkSeguro & c_sNomeServidor%>/pt/popups/mybolsa_s/closewindow.asp';
	}
	else
	{
	if (parent.opener != null) 
		{
			alert("A sua sessão expirou. Se quer continuar a negociar, por favor, volte a fazer o logon.");
			window.parent.close();
			parent.opener.location.href='<%=c_sLinkSeguro & c_sNomeServidor%>/pt/logon_S/acessorestrito.asp?Type=C&Pag=Mybolsa';
		}
	}	
	
}



/*-------------------------------------------------------
 Função: preload

 Objectivo: Faz o preload das imagens para o mouseover
 
 Criada: JAC - 21/12/1999
-------------------------------------------------------*/
function preload(imgObj,imgSrc) {
        eval(imgObj+' = new Image()')
        eval(imgObj+'.src = "'+imgSrc+'"')
}

/*-------------------------------------------------------
 Função: mouseover

 Objectivo: Faz o onMouseOver e onMouseOut da navegacao.
 			Se nao existir layer, deixar null
 
 Criada: JAC - 21/12/1999
-------------------------------------------------------*/
function msover(layer,imgName,imgObj) {

ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false

        if (ns4 && layer!=null) eval('document.'+layer+'.document.images["'+imgName+'"].src = '+imgObj+'.src');
        else document.images[imgName].src = eval(imgObj+".src");
}	

function openBoxNoScroll(url, width, height) {
        var Win = window.open(url,"BoxNoSroll",'width=' + width + ',height=' + height + ',resizable=0,scrollbars=no,menubar=no,status=no' );
}

function openBoxScroll(url, width, height) {
        var Win = window.open(url,"BoxNoSroll",'width=' + width + ',height=' + height + ',resizable=0,scrollbars=yes,menubar=no,status=no' );
}

/*-------------------------------------------------------
 Funções: para Layers

 Objectivo: Mostra e esconde Layers
 
 Criada: Macromedia Dreamweaver - 31/01/2000
-------------------------------------------------------*/

function MM_findObj(n, d) { //v3.0
  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); return x;
}

function MM_showHideLayers() { //v3.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3){
		if ((obj=MM_findObj(args[i]))!=null) {
			v=args[i+2];
			if (obj.style) { 
				obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; 
			}
		obj.visibility=v; 
		}}
}

/*-------------------------------------------------------
 Objectivo: Formata um valor com 2 casas decimais e tira os
			zeros à direita
*/
function formatar(sValor)
{
  var s = "";
  var decimal;

  dValor = parseFloat(sValor);
  if (!(isNaN(dValor))) {
    // round to nearest cent
    dValor = Math.round(dValor * 100);
    dValor = dValor / 100;

    // format the output
    s = new String(dValor);
    decimal = s.indexOf(".");
    if (decimal == -1) {
      // whole number
      s+= ".00";
    } else {
      if (decimal == (s.length - 2)) {
        // needs a trailing zero
        s+= "0";
      }
    }
  } else {
    // not a number so return zero
    s = "0.00";
  }
  return s;
}

/*-------------------------------------------------------
 Objectivo: Faz o submit da página
*/
function Submit() {
  self.document.Formulario.submit();
}

/*
 FUNÇÕES RELATIVAS AOS GRÁFICOS!
*/
var imagegraph=new Array()
imagegraph[1]="0"
imagegraph[2]="1"
imagegraph[3]="1"

function swapgraph(graph,linkname,newimage,num,numgraph)
{
  eval("document.botintraday"+numgraph+".src='/common/images/intraday.gif'")
  eval("document.botlastmonth"+numgraph+".src='/common/images/ultimomes.gif'")
  eval("document.botlastyear"+numgraph+".src='/common/images/ultimoano.gif'")
  ultimonome=newimage
  ultimaimg=eval("document."+linkname+".src")
  eval("document.grafico"+numgraph+".src=graph");
  eval("document."+linkname+".src='"+newimage+"'");
  for(numb=1;numb<=3;numb++)
  {
    imagegraph[numb]="1";
  }
  imagegraph[num]="0";
  numgrafico=num
}


function swapgraph3(graph,linkname,newimage,num,numgraph)
{
  eval("document.botlastmonth"+numgraph+".src='/common/images/ultimomes.gif'")
  eval("document.botlastyear"+numgraph+".src='/common/images/ultimoano.gif'")
  eval("document.botlast2years"+numgraph+".src='/common/images/ultimos2anos.gif'")
  ultimonome=newimage
  ultimaimg=eval("document."+linkname+".src")
  eval("document.grafico"+numgraph+".src=graph");
  eval("document."+linkname+".src='"+newimage+"'");
  for(numb=4;numb<=7;numb++)
  {
    imagegraph[numb]="1";
  }
  imagegraph[num]="0";
  numgrafico=num
}

function swapgraphwithtitle(graph,linkname,newimage,num,numgraph)
{
  eval("document.botintraday"+numgraph+".src='/common/images/intraday.gif'")
  eval("document.botlastmonth"+numgraph+".src='/common/images/ultimomes.gif'")
  eval("document.botlastyear"+numgraph+".src='/common/images/ultimoano.gif'")
  ultimonome=newimage
  ultimaimg=eval("document."+linkname+".src")
  eval("document.grafico"+numgraph+".src=graph");

  eval("document.all['a1'].style.display='none'");
  eval("document.all['a3'].style.display='none'");
  eval("document.all['a4'].style.display='none'");

  eval("document.all['a"+num+"'].style.display=''");
  eval("document."+linkname+".src='"+newimage+"'");

  for(numb=1;numb<=3;numb++)
  {
    imagegraph[numb]="1";
  }
  imagegraph[num]="0";
  numgrafico=num
}







//para os fundos
function swapgraph2(graph,linkname,newimage,num,numgraph)
{
  eval("document.botlastyear"+numgraph+".src='/common/images/ultimoano.gif'")
  eval("document.botlast2years"+numgraph+".src='/common/images/ultimos2anos.gif'")
  ultimonome=newimage
  ultimaimg=eval("document."+linkname+".src")
  eval("document.grafico"+numgraph+".src=graph");
  eval("document."+linkname+".src='"+newimage+"'");
  for(numb=1;numb<=2;numb++)
  {
    imagegraph[numb]="1";
  }
  imagegraph[num]="0";
  numgrafico=num
}

function swapImageRestoregraph()
{
  if(imagegraph[numero]!="0")
  {
  eval("document."+nomeimg+".src='"+lastimage+"'");
  }
}

function swapImagegraph(nome,highlight,num)
{
  numero=num
  if(imagegraph[num]!="0")
  {
  nomeimg=nome
  eval("lastimage=document."+nome+".src")
  eval("document."+nome+".src='"+highlight+"'");
  }
}



function swapRotateGraph(graph,numgraph)
{
  eval("document.grafico"+numgraph+".src=graph");
}
function swapRotateLink(linkname,newimage,num)
{
  eval("document.botintraday.src='/common/images/intraday.gif'")
  eval("document.botlastmonth.src='/common/images/ultimomes.gif'")
  eval("document.botlastyear.src='/common/images/ultimoano.gif'")
  eval("document."+linkname+".src='"+newimage+"'");
  for(numb=1;numb<=3;numb++)
  {
    imagegraph[numb]="1";
  }
  imagegraph[num]="0";
  numgrafico=num
}


/*-------------------------------------------------------
 Objectivo: Fecha a janela Pop-Up e redirecciona a janela origem 
*/
function JanelaTopoNav(sRef, bFechar) {
	if (window.opener != null) {
		if (bFechar) window.close();
		window.opener.location.href=sRef;
	}
}


/*-------------------------------------------------------
 Objectivo: Dado o indice, selecciona o respectivo elemento da combo 
 */
function SelecionarElemCb(sPagName) 
{
  var obj;
  var i;
  var sTemp;
  
  if (vElem[0]*1 < 0) return;
  for (i=0; i< vElem.length; i++) 
  {
	eval('obj=document.Formulario.cbCriterio' + i);
	if (vElem[i]*1 >= 0) obj.selectedIndex=vElem[i];    
  }
}


function submeteframe(frame,pagina)
{
	eval('parent.' + frame + '.location ="' + pagina + '"')
}	

/*-------------------------------------------------------
  Objectivo: Usada em todas as páginas. Serve para redireccionamento nas combobox
	de acesso rápido.
*/
function CombosAcessoRapido(sCombo)
{
	if (sCombo=='cbAcessoDirecto')
		{
			if (document.Formulario.cbAcessoDirecto.options[document.Formulario.cbAcessoDirecto.selectedIndex].value != '0')
				{
				window.location.href = document.Formulario.cbAcessoDirecto.options[document.Formulario.cbAcessoDirecto.selectedIndex].value
				}

		}
	else if (sCombo=='cbNegociar')
		{
			if (document.FormComboAcessoRapido.cbNegociar.options[document.FormComboAcessoRapido.cbNegociar.selectedIndex].value != '0')
				{
							window.location.href = document.FormComboAcessoRapido.cbNegociar.options[document.FormComboAcessoRapido.cbNegociar.selectedIndex].value
				}
		}
	else if (sCombo=='cbNoticias')
		{
			if (document.FormComboNoticias.cbNoticias.options[document.FormComboNoticias.cbNoticias.selectedIndex].value != '0')
				{
							window.location.href = document.FormComboNoticias.cbNoticias.options[document.FormComboNoticias.cbNoticias.selectedIndex].value
				}
		}
	else if (sCombo=='cbTiposConta')
		{
			if (document.FormComboTiposConta.cbTiposConta.options[document.FormComboTiposConta.cbTiposConta.selectedIndex].value != '0')
				{
							window.location.href = document.FormComboTiposConta.cbTiposConta.options[document.FormComboTiposConta.cbTiposConta.selectedIndex].value
				}
		}
}

/*-------------------------------------------------------
funções relativas ao MyFuturos
*/

var imagetab=new Array()

imagetab[1]="0"
imagetab[2]="1"
imagetab[3]="1"
imagetab[4]="1"

function swapImageMF(nome,highlight,num)
{
  numero=num
  nomeimg=nome
  eval("lastimage=document."+nome+".src")
  eval("document."+nome+".src='"+highlight+"'");
}

function swapImageRestoreMF()
{
  eval("document."+nomeimg+".src='"+lastimage+"'");
}

function swapMF(frame,pagina,linkname,newimage,num)
{
  eval("document.tab1.src='/pt/popups/images/posicoes_off.gif'")
  eval("document.tab2.src='/pt/popups/images/ordens_off.gif'")
  eval("document.tab3.src='/pt/popups/images/operacoes_off.gif'")
  eval("document.tab4.src='/pt/popups/images/posicao_off.gif'")
  ultimonome=newimage
  ultimaimg=eval("document."+linkname+".src")
  eval("document."+linkname+".src='"+newimage+"'");
  for(numb=1;numb<=4;numb++)
  {
    imagetab[numb]="1";
  }
  imagetab[num]="0";
  lastimage=eval("document."+linkname+".src")
  eval('parent.' + frame + '.location ="' + pagina + '"')
}

/*-------------------------------------------------------
funções relativas ao MyBolsa
*/

var imagetabMB=new Array()

imagetabMB[1]="0"
imagetabMB[2]="1"
imagetabMB[3]="1"
imagetabMB[4]="1"
imagetabMB[5]="1"

function swapImageMB(nome,highlight,num)
{
  numero=num
  nomeimg=nome
  eval("lastimage=document."+nome+".src")
  eval("document."+nome+".src='"+highlight+"'");
}

function swapImageRestoreMB()
{
  eval("document."+nomeimg+".src='"+lastimage+"'");
}

function swapMB(frame,pagina,linkname,newimage,num)
{
  eval("document.tab1.src='/pt/popups/images/carteira_off.gif'")
  eval("document.tab2.src='/pt/popups/images/negociacao_off.gif'")
  eval("document.tab3.src='/pt/popups/images/efectuadas_off.gif'")
  eval("document.tab4.src='/pt/popups/images/tecnica_off.gif'")
  eval("document.tab5.src='/pt/popups/images/noticias_off.gif'")
  ultimonome=newimage
  ultimaimg=eval("document."+linkname+".src")
  eval("document."+linkname+".src='"+newimage+"'");
  for(numb=1;numb<=5;numb++)
  {
    imagetabMB[numb]="1";
  }
  imagetabMB[num]="0";
  lastimage=eval("document."+linkname+".src")
  eval('parent.' + frame + '.location ="' + pagina + '"')
}

/*-------------------------------------------------------
funções relativas ao MyBolsaAjax
*/

var imagetabMBAjax=new Array()

imagetabMBAjax[1]="1"
imagetabMBAjax[2]="0"
imagetabMBAjax[3]="1"
imagetabMBAjax[4]="1"
imagetabMBAjax[5]="1"
imagetabMBAjax[6]="1"

function swapImageMBAjax(nome,highlight,num)
{
  numero=num
  nomeimg=nome
  eval("lastimage=document."+nome+".src")
  eval("document."+nome+".src='"+highlight+"'");
}

function swapImageRestoreMBAjax()
{
  eval("document."+nomeimg+".src='"+lastimage+"'");
}

function swapMBAjax(frame,pagina,linkname,newimage,num)
{
  eval("document.tab1.src='/pt/popups/mybolsaajax_s/imgs/01_posicao_integrada_off.gif'")
  eval("document.tab2.src='/pt/popups/mybolsaajax_s/imgs/02_carteira_off.gif'")
  eval("document.tab3.src='/pt/popups/mybolsaajax_s/imgs/03_ordens_off.gif'")
  eval("document.tab4.src='/pt/popups/mybolsaajax_s/imgs/04_analise_tecnica_off.gif'")
  eval("document.tab5.src='/pt/popups/mybolsaajax_s/imgs/05_noticias_off.gif'")
  eval("document.tab6.src='/pt/popups/mybolsaajax_s/imgs/06_realstream_off.gif'")
  ultimonome=newimage
  ultimaimg=eval("document."+linkname+".src")
  eval("document."+linkname+".src='"+newimage+"'");
  for(numb=1;numb<=6;numb++)
  {
    imagetabMBAjax[numb]="1";
  }
  imagetabMBAjax[num]="0";
  lastimage=eval("document."+linkname+".src")
  eval('parent.' + frame + '.location ="' + pagina + '"')
}


function formatarV2(sValor,nNumDigits)
{
  var s = "";
  var decimal;
  
  dValor = parseFloat(sValor);
  if (!(isNaN(dValor))) {
    // round to nearest cent
    dValor = Math.round(dValor * Math.pow(10,nNumDigits));
    dValor = dValor / Math.pow(10,nNumDigits);

    // format the output
    s = new String(dValor);
    decimal = s.indexOf(".");
    if (decimal == -1) {
      // whole number
      s+= ".00";
    } else {
      if (decimal == (s.length - 2)) {
        // needs a trailing zero
        s+= "0";
      }
    }
  } else {
    // not a number so return zero
    s = "0.00";
  }
  return s;
}


function CombosAcessoRapidoFooter(sCombo)
{
	if (document.FormularioFooter.cbAcessoDirecto.options[document.FormularioFooter.cbAcessoDirecto.selectedIndex].value != '0')
		{
		window.location.href = document.FormularioFooter.cbAcessoDirecto.options[document.FormularioFooter.cbAcessoDirecto.selectedIndex].value
		}
}




function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

/*
	* CopyRight -> Banco BiG© 2009
	* Author -> Luis Castanheira 
	* Date -> 25/06/2009
	*
	* function randomImageLink(links, percent, size)
	* 	this function randomly writes pre-selected image links on a website with a specified occurrence percentage
	*
	* PARAMETERS
	* 	LINKS -> array that contains the links destination url and image url
	* 		links = [[targetUrl 1, imageUrl 1], [targetUrl 2, imageUrl 2], [targetUrl 3, imageUrl 3], ..., [targetUrl N, imageUrl N]];
	* 	PERCENT -> array used to control how often should a specified image link be selected
	* 		percent = [index 1, index 1, index 1, index 2, index 2, index 3, index 3, ...,index N];
	* 	SIZE -> object that allows to control the image size
	* 		size = 'width="565" height="250"'
*/
function randomImageLink(links, percent, size){
		//INDICE
		var i = Math.floor(percent.length * Math.random()) + 1;
		if(i < 0) i = 0
		else if( i >= percent.length) i = percent.length-1;
		document.write('<a href="' + links[percent[i]][0] + '" ><img src="' + links[percent[i]][1] + '" border="0" ' + size + '></a>');
}

//-->
