

// JScript source code
function LoadMenuBovespa()
{
    var footer = document.getElementById('Footer');
    var QBovespa = document.getElementById('QuadroBovespa');
    var footerInternal = document.getElementById('InternalSubFooter');
    
    if(footer != null)
    {
        
        if(footer.offsetTop > 553)
        {
            QBovespa.style.height = footer.offsetTop + 64 + 'px';
        }
        else
        {
            QBovespa.style.height = getWindowHeight();
        }
        
    }
    if(footerInternal != null)
    {
        
        if(footerInternal.offsetTop > 553)
        {
            QBovespa.style.height = footerInternal.offsetTop + 64 + 'px';
        }
        else
        {
            QBovespa.style.height = getWindowHeight();
        }
        
     }

    
     
}

function verificaEmail()
{
    var nome = document.getElementById('ctl00_ContentPlaceHolderPrincipal_txtNome');
    var email = document.getElementById('ctl00_ContentPlaceHolderPrincipal_txtEmail');
    var assunto = document.getElementById('ctl00_ContentPlaceHolderPrincipal_ddlAssunto');
    var mensagem = document.getElementById('ctl00_ContentPlaceHolderPrincipal_txtMensagem');
    
    if(nome.value == "")
    {
        alert('Informe seu nome.');
        nome.focus();
        nome.select();
        return false;
    }
    if(email.value == "")
    {
        alert('Informe seu e-mail.');
        email.focus();
        email.select();
        return false;
    }
    else
    {
        if(email.value.indexOf("@") < 1)
        {
            alert('O e-mail parece estar em formato incorreto.');
            email.focus();
            email.select();
            return false;
        }
        if(email.value.indexOf(".") < 1)
        {
            alert('O e-mail parece estar em formato incorreto.');
            email.focus();
            email.select();
            return false;
        }
        if(email.value.indexOf(".@") > 0)
        {
            alert('O e-mail parece estar em formato incorreto.');
            email.focus();
            email.select();
            return false;
        }
        if(email.value.indexOf("@.") > 0)
        {
            alert('O e-mail parece estar em formato incorreto.');
            email.focus();
            email.select();
            return false;
        }
        if(email.value.indexOf(".com.br.") > 0)
        {
            alert('O e-mail parece estar em formato incorreto.');
            email.focus();
            email.select();
            return false;
        }
        if(email.value.indexOf("[") > 0)
        {
            alert('O e-mail parece estar em formato incorreto.');
            email.focus();
            email.select();
            return false;
        }
        if(email.value.indexOf("]") > 0)
        {
            alert('O e-mail parece estar em formato incorreto.');
            email.focus();
            email.select();
            return false;
        }
        if(email.value.indexOf('"') > 0)
        {
            alert('O e-mail parece estar em formato incorreto.');
            email.focus();
            email.select();
            return false;
        }
        if(email.value.indexOf("'") > 0)
        {
            alert('O e-mail parece estar em formato incorreto.');
            email.focus();
            email.select();
            return false;
        }
        if(email.value.indexOf("..") > 0)
        {
            alert('O e-mail parece estar em formato incorreto.');
            email.focus();
            email.select();
            return false;
        }
        if(email.value.indexOf("(") > 0)
        {
            alert('O e-mail parece estar em formato incorreto.');
            email.focus();
            email.select();
            return false;
        }
        if(email.value.indexOf("}") > 0)
        {
            alert('O e-mail parece estar em formato incorreto.');
            email.focus();
            email.select();
            return false;
        }
        if(email.value.indexOf("/") > 0)
        {
            alert('O e-mail parece estar em formato incorreto.');
            email.focus();
            email.select();
            return false;
        }
        if(email.value.indexOf(",") > 0)
        {
            alert('O e-mail parece estar em formato incorreto.');
            email.focus();
            email.select();
            return false;
        }
    }
    if(assunto.selectedIndex.text == "")
    {
        alert('Informe um assunto');
        assunto.focus();
        assunto.select();
        return false;
    }
    if(mensagem.value == "")
    {
        alert('Informe uma mensagem.');
        mensagem.focus();
        mensagem.select();
        return false;
    }

}


function setCookie(key, value, days)
{
	if(days == null) days = 300;
	
	var dt = new Date();
	var ms = days * 24 * 60 * 60 * 1000;
	dt.setTime(dt.getTime()+ms);
	
	var ck = key + "=" + value+";expires=" + dt.toGMTString();
	
	document.cookie = ck;

}

function getCookie(key)
{
	var arr=document.cookie.split(';');
	
	
	for(var i = 0; i < arr.length; ++i)
	{
		var c = arr[i].split('=');
		if(c[0] == key)
			return c[1];
	}
	return null;
}

function ControleMenuR()
{

	
		
    if (document.getElementById("QuadroBovespa").className == 'QBMenuFechado')
    {
    
		setCookie("SideBar", "1");
        document.getElementById("QuadroBovespa").className = 'QBMenuAberto';
        document.getElementById("QBOpenClose").className = 'QBovespaOpen';
        
    }
    else
    {
        var TelaHeight = getWindowHeight();
        var TelaDocumentHeight;
        
        if(document.all)
        {
            TelaDocumentHeight = document.body.scrollHeight;
        }
        else
        {
            TelaDocumentHeight = document.height;
        }
        setCookie("SideBar", "0");
        document.getElementById("QuadroBovespa").className = 'QBMenuFechado';
        document.getElementById("QBOpenClose").className = 'QBovespaClose';
        
        if(TelaHeight < TelaDocumentHeight)
        {
            document.getElementById("QBOpenClose").style.height = TelaDocumentHeight + 'px';
        }
    }
}

//function ControleMenuR()
//{
//    if (document.getElementById("QuadroBovespa").className == 'QBMenuFechado')
//    {
//        document.getElementById("QuadroBovespa").className = 'QBMenuAberto';
//        document.getElementById("QBOpenClose").className = 'QBovespaOpen';
//        
//    }
//    else
//    {
//        document.getElementById("QuadroBovespa").className = 'QBMenuFechado';
//        document.getElementById("QBOpenClose").className = 'QBovespaClose';
//    }
//}

function ControlMenuResolution()
{

	var vis = (getCookie("SideBar") != "0");
	

    if(screen.width > 800)
    {
		document.getElementById("QuadroBovespa").className = 'QBMenuAberto';
	    document.getElementById("QBOpenClose").className = 'QBovespaOpen';
    }
    else
    {
        document.getElementById("QuadroBovespa").className = 'QBMenuFechado';
        document.getElementById("QBOpenClose").className = 'QBovespaClose';
    }
    // força fechamento da barra lateral...
    if(!vis)
		ControleMenuR();
    
}

function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window. innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function setFooter() {
    if(document.getElementById('InternalSubFooter') != null) {
        if(document.getElementById('Principal') != null) {
            if (document.getElementById) {
		        var windowHeight = getWindowHeight();

		        if (windowHeight > 0) {
			        var contentHeight = document.getElementById('Master').offsetHeight;
			        var footerElement = document.getElementById('InternalSubFooter');
			        var footerHeight  = footerElement.offsetHeight;
			        if (windowHeight - (contentHeight + footerHeight) >= 0) {
				        footerElement.style.position = 'absolute';
				        //400 representa um tamanho minimo aonde o footer deveria ficar posicionado baseado na altura.
				        if (400 >= (windowHeight - footerHeight) ) {
					        footerElement.style.top = 458 + 'px'; //458 é a distancia para posicionar o footer sem danificar o layout
					        //footerElement.style.position = 'absolute';
				        }
				        else {
					        footerElement.style.top = contentHeight + 'px';
					        //footerElement.style.position = 'absolute';
				        }
			        }
			        else {
			            //Coloca o footer com posicionamento estático quando o conteúdo da página é pequeno
				        footerElement.style.position = 'static';
			        }
		        }
	        }
	    }
	}
}

function setFooterR() {
   if(document.getElementById('footer') != null) {
      var footerElement = document.getElementById('footer');
      footerElement.style.left = '0px';
      footerElement.style.width = '100%';
      footerElement.style.position = 'absolute';
/*    if(document.getElementById('footer') != null) {
	    if (document.getElementById) {
		    var windowHeight = getWindowHeight();

		    if (windowHeight > 0) {
		    alert("windowHeight: "+windowHeight);
			    var contentHeight = document.getElementById('MasterR').offsetHeight;
			    alert("contentHeight: "+contentHeight)
			    var footerElement = document.getElementById('footer');
			    var footerHeight  = footerElement.offsetHeight;
			    alert("footerHeight: "+footerHeight)
			    var soma = (contentHeight + footerHeight) - windowHeight
			    if (soma >= 0) {
			    alert(soma);
				    footerElement.style.position = 'absolute';
				    if (400 >= (windowHeight - footerHeight) ) {
					    footerElement.style.top = 458 + 'px';
					    footerElement.style.position = 'absolute';
					    alert("1: "+windowHeight - footerHeight);
				    }
				    else {
					    footerElement.style.top = (contentHeight) + 'px';
					    footerElement.style.position = 'absolute';
					    alert("2: "+contentHeight);
				    }
			    }
			    else {
				    footerElement.style.position = 'static';
			    }
		    }
	    }*/
	}
}
//function setLeftPanel()
//{
//    if(document.getElementById('LeftPanel') != null) {
//        var windowHeight = getWindowHeight();
//        var footer = document.getElementById('InternalSubFooter');
//        
//        if(windowHeight > 0)
//        {
//            var leftPanel = document.getElementById('LeftPanel');
//            var offsetDifference = (windowHeight - (leftPanel.offsetHeight - footer.offsetHeight - 84));
//            var principal = document.getElementById('Principal');
//            var img = document.getElementById('ImgLeftPanel');
//            var menuLeftPanel = document.getElementById('MenuLeftPanel');
//            if(offsetDifference >= 0)
//            {
//                leftPanel.style.height =  principal.offsetHeight  + 'px';
//                if(img != null)
//                {
//                    
//                    var imgtop = (leftPanel.offsetHeight - menuLeftPanel.offsetHeight - img.offsetHeight);
//                    if(imgtop > 0)
//                    {
//                       img.style.top = (leftPanel.offsetHeight - menuLeftPanel.offsetHeight - img.offsetHeight) + 'px';
//                    }
//                    else
//                    {
//                        img.style.top = '0px';
//                    }
//                }
//            }
//        }
//    }
//}






window.leftPanelFlag = false;

// Ajusta o painel esquerdo (cinza)
function setLeftPanel()
{   


	if(window.leftPanelFlag)
		return;
		
	window.leftPanelFlag = true;
	setTimeout("window.leftPanelFlag=false;", 100);


	//alert('eu');

	//verifica se objeto LeftPanel existe
    var leftPanel = document.getElementById('LeftPanel');
    var divPrincipal = document.getElementById('Principal');
    
    var windowHeight = getWindowHeight();
    
    /* RGL - Comentado a principio nao utilizado
    var heightPrincipal = divPrincipal.clientHeight;
    
    heightPrincipal = Math.max(heightPrincipal, windowHeight);
    
    heightPrincipal-=54;
    
   // alert(heightPrincipal)
    
    leftPanel.style.height = (heightPrincipal) + "px";
    */
    
    
    
    return
    
    if(leftPanel != null) {
        //Pega o tamanho do documento
        var windowHeight = getWindowHeight();
        
        
        
        
        //Pega por DOM o objeto InternalSubFooter
        var footer = document.getElementById('InternalSubFooter');
        
        if(windowHeight > 0)
        {   

            //pega o objeto principal
            var principal = document.getElementById('Principal');
            //pega o objeto onde se encontra uma imagem
            var img = document.getElementById('ImgLeftPanel');
            //pega o div com o menu
            var menuLeftPanel = document.getElementById('MenuLeftPanel');
            //seta a diferença entre um menu se existir dentro do leftpanel e um div com imagem
            var offsetDifference = (windowHeight - (leftPanel.offsetHeight - footer.offsetHeight - 84));
            //verifica se a diferença existe entre o div da imagem e o div do menu
            if(offsetDifference >= 0)
            {
                //seta o tamanho do leftPanel com o tamanho do div principal
                leftPanel.style.height =  (footer.offsetTop - 136) + 'px';
                if(img != null)
                {
                    
                    var imgtop = (leftPanel.offsetHeight - menuLeftPanel.offsetHeight - img.offsetHeight);
                    if(imgtop > 0)
                    {
                       img.style.top = (leftPanel.offsetHeight - menuLeftPanel.offsetHeight - img.offsetHeight) + 'px';
                    }
                    else
                    {
                        img.style.top = '0px';
                    }
                }
            }
        }
    }
}


function setLeftPanelR()
{
    if(document.getElementById('LeftPanelR') != null) {
        var windowHeight = getWindowHeight();
        var footer = document.getElementById('InternalSubFooterR');//
        
        if(windowHeight > 0)
        {
            var leftPanel = document.getElementById('LeftPanelR');
            var offsetDifference = (windowHeight - (leftPanel.offsetHeight - footer.offsetHeight - 84));
            var principal = document.getElementById('MasterR');
            var img = document.getElementById('ImgLeftPanelR');
            var menuLeftPanel = document.getElementById('MenuLeftPanelR');
            if(leftPanel != null)
            {
                leftPanel.style.height = (footer.offsetTop + principal.offsetHeight)+'px';
                if(img != null)
                {
                    
                    var imgtop = (leftPanel.offsetHeight - menuLeftPanel.offsetHeight - img.offsetHeight);
                    if(imgtop > 0)
                    {
                       img.style.top = (leftPanel.offsetHeight - menuLeftPanel.offsetHeight - img.offsetHeight) + 'px';
                    }
                    else
                    {
                        img.style.top = '0px';
                    }
                }
            }
        }
    }
}


//Função da API GOOGLE


function onLoadBusca(BuscaStr) {
if(BuscaStr != null)
{
	    if(document.getElementById('SearchResult') != null)
        {
        
        
        
	        var searchControl;
//	        window.onload = function() {
//		        onLoadBusca();
//	        }
		        // Create a search control
		        searchControl = new GSearchControl();
		        
		        
        	
		        // add a site-limited web search, with a custom label
		        var siteSearch = new GwebSearch();
		        siteSearch.setUserDefinedLabel("www.linkinvestimentos.com.br");
		        siteSearch.setSiteRestriction("http://www.linkinvestimentos.com.br");
        		
		        searchControl.addSearcher(siteSearch);
		        // setting the draw mode for the Google search
		        var drawOptions = new GdrawOptions();
		        // use tabbed view
		        drawOptions.setDrawMode(GSearchControl.DRAW_MODE_TABBED);
        		
        		
		        // set the input field (instead of the default one)
		        //drawOptions.setSearchFormRoot(document.getElementById("SearchControl"));
        		
		        // actually write the needed markup to the page
		        searchControl.draw(document.getElementById("SearchResult"), drawOptions);
		        // set the google logo container
		        //GSearch.getBranding(document.getElementById("branding"));
		        
		         searchControl.execute(BuscaStr);
	        }
	 }       
}
//Termina função API GOOGLE


function LoadMenuSelected(ContentID)
{
    switch(ContentID)
    {
        case "ContentWealth":
            document.getElementById("wealthmanagement").className = 'wealthmanagementMenuSelected';
            break;
        case "ContentAlink":
            document.getElementById("alink").className = 'alinkMenuSelected';
            break;
        case "ContentLinkTrade":
            document.getElementById("LinkTrade").className = 'linktradeMenuSelected';
            break;
        case "ContentResearch":
            document.getElementById("research").className = 'researchMenuSelected';
            break;
        case "ContentCorretora":
            document.getElementById("corretora").className = 'corretoraMenuSelected';
            break;
        case "ContentCommodities":
            document.getElementById("commodities").className = 'commoditiesMenuSelected';
            break;
		case "ContentParcerias":
            document.getElementById("parcerias").className = 'parceriasMenuSelected';
            break;
        default:
            //Não faz nada caso case não encontrado
            
    }
}

function HomeFlash()
{
// documento script que escreve no html um script flash. Usado para tirar proteção de script do IE FlashAnimationHome.js
//document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="506" height="350" id="filme_home" align="middle">');
 document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="506" height="433" id="filme_home" align="middle">');
document.write('<param name="allowScriptAccess" value="sameDomain" />');
document.write('<param name="allowFullScreen" value="false" />');
//document.write('<param name="movie" value="Images/EntendaACrise/banner_crise_big.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />	<embed src="filme_home.swf" quality="high" bgcolor="#ffffff" width="506" height="433" name="filme_home" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>');
document.write('<param name="movie" value="filme_home.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />	<embed src="filme_home.swf" quality="high" bgcolor="#ffffff" width="506" height="433" name="filme_home" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>');

}


function AbreNova(loc,janela,largura,altura)  
{
	largura='796';
	altura = '596';
	if (largura == 0) {largura = 1;}
	if (altura == 0) {altura = 1;}
	var window_left = (screen.width - largura)/2;
	var window_top = (screen.height - altura)/2;
	if (window_left < 0) {window_left = 0;}
	if (window_top < 0) {window_top = 1;}
	remote = null;

	 // Guto - coloquei isto aqui porque o cara da DSOne está chamando a página sem o .asp 
	loc = "http://www.linktrade.com.br/EntendaACrise.asp";
	remote = window.open(loc, '' + janela + '','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,menubar=no,width=' + largura + ',height='+ altura + ',top=' + window_top + ',left=' + window_left + '');

	if (remote != null) 
	{
		remote.location.href = loc;
		remote.focus(); 
	}
}


function HomeFlashEng()
{
// documento script que escreve no html um script flash EN. Usado para tirar proteção de script do IE FlashAnimationHome.js
document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="506" height="433" id="filme_home" align="middle">');
document.write('<param name="allowScriptAccess" value="sameDomain" />');
document.write('<param name="allowFullScreen" value="false" />');
document.write('<param name="movie" value="filme_home_en.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />	<embed src="filme_home_en.swf" quality="high" bgcolor="#ffffff" width="506" height="433" name="filme_home" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>');

}

// Função do Menu EN

function LoadMenuSelectedEN(ContentID)
{
    switch(ContentID)
    {
        case "ContentPrivate":
            document.getElementById("privateEN").className = 'privateMenuSelectedEN';
            break;
        case "ContentAlink":
            document.getElementById("alinkEN").className = 'alinkMenuSelectedEN';
            break;
        case "ContentCorporate":
            document.getElementById("corporateEN").className = 'corporateMenuSelectedEN';
            break;
        case "ContentResearch":
            document.getElementById("researchEN").className = 'researchMenuSelectedEN';
            break;
        case "ContentCorretora":
            document.getElementById("corretoraEN").className = 'corretoraMenuSelectedEN';
            break;
        case "ContentCommodities":
            document.getElementById("commoditiesEN").className = 'commoditiesMenuSelectedEN';
            break;
        default:
            //Não faz nada caso case não encontrado
            
    }
}



//Colocar flash pela htm via js e funcao

    function footerFlash(URL)
    {
        document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="237px" height="47px" >');
        document.write('<param name="movie" value="' + URL + '"/> <param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />	<embed src="'+ URL +'" quality="high" bgcolor="#ffffff" width="237" height="47" name="filme_footer" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
        document.write('<param name="quality" value="high" allowScriptAccess="sameDomain" allowFullScreen="false"/>');
        document.write('</object>');
    }

//Colocar flash pela htm via js e funcao - EN

    function footerFlashEN(URL)
    {
        document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="237px" height="47px" >');
        document.write('<param name="movie" value="' + URL + '"/> <param name="quality" value="high" /><param name="bgcolor" value="#ffffff" />	<embed src="'+ URL +'" quality="high" bgcolor="#ffffff" width="237" height="47" name="filme_footer" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
        document.write('<param name="quality" value="high" allowScriptAccess="sameDomain" allowFullScreen="false"/>');
        document.write('</object>');
    }
    
//Função obrigatória da Bovesopa para abrir a página de corretora credenciada	
function AbreEntao(page) {
   		window.open(page,'hb','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,menubar=no,width=505,height=300,top=10,left=10');
}

//Abre uma pagina com tamanho default para impressao
function PrintPage(pageName, titleName)
{
    window.open(pageName + '?PRINT=YES', titleName, 'width=800,height=550,status=no,toolbar=no,location=no,menubar=no,directories=no,scrollbars=yes,resizable=yes'); 
}


window.onload = function() {
	setFooter();
	LoadMenuBovespa();
	setLeftPanel();
	setLeftPanelR();
	setFooterR();
}
window.onresize = function() {
	setFooter();
	setFooterR();
	setLeftPanel();
	LoadMenuBovespa();
}


function UpdateContentPlace(widthPosition, leftPosition)
{
    var quadroBovespa = document.getElementById("QuadroBovespa");
    var QBOpenClose   = document.getElementById("QBOpenClose");
    var principalR    = document.getElementById("PrincipalR");
    var principalConteudoR = document.getElementById("PrincipalConteudoR");    
    
    QBOpenClose.style.left   = leftPosition + "px";
    quadroBovespa.style.left = leftPosition + "px"; 
    principalR.style.width   = (widthPosition + 200) + "px";     
    principalConteudoR.style.width = widthPosition + "px"; 
}


