//Captura URL e parâmetros
function getQueryVariable(url, variable){
	var url = url.toLowerCase();
	var variable = variable.toLowerCase();
	var vars = url.replace('?', '&').split('&');
	
	for(var i = 0; i < vars.length; i++){
		if(vars[i].split("=")[0] == variable){
			return vars[i].split('=')[1];
		}
	}
}
var pais = getQueryVariable(window.location.href, 'area');
//
//Função para exibir/ocultar as layers
function showP(num){
	var i = 1;
	for (i=0;i<1000;i++){
		if (document.getElementById('p' + i)){
			eval("document.getElementById('p" + i +"').style.display = 'none'");
			if (i == num) {
				displayClick();
				eval("document.getElementById('container_shape').style.display = 'block'");
				eval("document.getElementById('p" + num +"').style.display = 'block'");
				eval("document.getElementById('pp" + num +"').style.display = 'none'");
				eval("document.getElementById('conteudo_unico').scrollTop = '0'");
			}
		}
	}
}
//
//Função para fechar a layer pai
function clearAll() {
	displayClick();
	eval("document.getElementById('container_shape').style.display = 'none'");
}

//
//Função para por display block em todos os click for details
function displayClick()
{
	for(var i = 1; i <= 10; i++)
	{
		eval("document.getElementById('pp" + i +"').style.display = 'block'");
	}	
}
//
//Função para mostrar uma área ativa ao carregar a página
function mostraPaises(myArea) {
	var myArea = pais;
	if (myArea != undefined) {
		showP(myArea);
	}
}

//
//Função para abrir arquivos PDF
function openPDF(filePath)
{
    window.open(filePath, 'PDF', 'toolbar=no, left=0, top=0, width=794, height=514, location=no, Directory=no, Status=no, menubar=no, scrollbars=yes, resizable=yes');
}

//Função para exibir o layer correspondente a cada país
function openlayer(pais)
{   
    //Rota - Homologação:    
    //var url = "http://ww137.itau/" + pais;
    
    //Rota - Produção:    
    var url = "http://www.itauprivatebank.com/" + pais;
    
    if (pais == "us")
        url += "/index2.htm";
    else 
        url += "/index.htm";
    
    if (url != "")
        window.open(url, '_self');     
}

function fnRedirect() {

    var url = document.location.host;
    
    if (url == 'www.itaupb.com' || url == 'www.itauinternational.com' || url == 'www.itauwealthmanagement.com'){
        window.location = 'http://www.itauprivatebank.com/index.htm';
    }
    
    var linkdestino = '';
    var indexpais = url.lastIndexOf('.')+1;
    if (indexpais > 1) {
        var pais = url.substring(indexpais, url.length);

        if (pais.toLowerCase() != 'com') {
            
            if (pais == 'uy' || pais == 'cl' || pais == 'lu' || pais == 'ar' || pais == 'py' || pais == 'ky' || pais == 'bs' || pais == 'ch')
            {
                linkdestino = 'http://www.itauprivatebank.com/' + pais + "/index.htm";
            }
            else if (pais == 'us')
            {
                linkdestino = 'http://www.itauprivatebank.com/' + pais + "/index2.htm";
            }
            else if (pais == 'co' || pais == 'mx' || pais == 've' || pais == 'pe' || pais == 'ec' || pais == 'bo')
            {
                linkdestino = 'http://www.itauprivatebank.com/index.htm';
            }
        }
        
        if (linkdestino != '')
            window.location = linkdestino;
    }
}


function fnRedirect2() {

    var url = document.location.host;
    
    if (url == 'www.itaupb.com' || url == 'www.itauinternational.com' || url == 'www.itauwealthmanagement.com'){
        window.location = 'http://www.itauprivatebank.com/index.htm';
    }
    
    var linkdestino = '';
    var indexpais = url.lastIndexOf('.')+1;
    if (indexpais > 1) {
        var pais = url.substring(indexpais, url.length);

        if (pais.toLowerCase() != 'com') {
            
            if (pais == 'uy' || pais == 'cl' || pais == 'lu' || pais == 'ar' || pais == 'py' || pais == 'ky' || pais == 'bs' || pais == 'ch')
            {
                linkdestino = 'http://www.itauprivatebank.com/' + pais + "/index.htm";
            }
            else if (pais == 'us')
            {
                linkdestino = 'http://www.itauprivatebank.com/' + pais + "/index2.htm";
            }
            else if (pais == 'co' || pais == 'mx' || pais == 've' || pais == 'pe' || pais == 'ec' || pais == 'bo')
            {
                linkdestino = 'http://www.itauprivatebank.com/index.htm';
            }
        }
        
        if (linkdestino != '')
            window.location = linkdestino;
    }
}







