// Chama URL da BARRA GOVERNO
function comboChange(comoBox,usado) {
	window.open( comoBox.options[comoBox.selectedIndex].value);
	if (usado) { 
		comoBox.selectedIndex = 0;
	}
}


// ALTERA O CSS DA PÁGINA
// Recebe a variavel CSS como flag para o CSS que deve ser carregado.
// Possui um erro com IE, pois ele não consegue carregar um arquivo CSS que já foi carregado. Isso faz com que o Internet Explorer trave.
// Por Alexandre Quinto - Cast TI
function trocaCSS(CSS) {
	switch (CSS)
	{
	case 1 :
		document.getElementById("styles").href = "n1-investidor.css";
		break;
	case 2 :
		document.getElementById("styles").href = "n1-academico.css";
		break;
	case 3 :
		document.getElementById("styles").href = "n1-juridico.css";
		break;
	case 4 :
		document.getElementById("styles").href = "n1-estrangeiro.css";
		break;
	}
}


// ALTERA GRAFICO PAINEL INVESTIDOR
// Função para alterar (via OnClick) o grafico do Painel do Investidor
// Simples alteração de HTML DOM recebendo a variavel "aba" como parametro
// Por Alexandre Quinto - Cast TI
function painelInvestidorTrocaGrafico(aba) {
	if (aba == 1) {
		// MOSTRA GRAFICO 1
		document.getElementById("painel_investidor_grafico_intradiario").style.display = "block";
		// ESCONDE GRAFICO 2
		document.getElementById("painel_investidor_grafico_diario").style.display = "none";
	} else {
		if (aba == 2) {
			// MOSTRA GRAFICO 1
			document.getElementById("painel_investidor_grafico_intradiario").style.display = "none";
			// ESCONDE GRAFICO 2
			document.getElementById("painel_investidor_grafico_diario").style.display = "block";
		}
	}
}


// ALTERA ABA PAINEL INVESTIDOR
// Função para alterar (via OnClick) a aba do Painel do Investidor
// Simples alteração de HTML DOM recebendo a variavel "aba" como parametro
// Por Alexandre Quinto - Cast TI
function painelInvestidorAba(aba) {
	// Verifica se "aba" é igual a 1, ou seja, "Oscilação"
	if (aba == 1) {
		// Altera cor de fundo da ABA 1
		document.getElementById("aba1").style.backgroundColor = "#EFEFEF";
		// Altera cor de fonte da ABA 1
		document.getElementById("aba1").style.color = "#333";
		// Altera cor de fundo da ABA 2
		document.getElementById("aba2").style.backgroundColor = "#FAFAFA";
		// Altera cor de fonte da ABA 2
		document.getElementById("aba2").style.color = "#333";

		// Altera borda ABA 1
		document.getElementById("aba1").style.borderBottomWidth = "2px";
		document.getElementById("aba1").style.borderBottomStyle = "solid";
		document.getElementById("aba1").style.borderBottomColor = "#EFEFEF";	
		document.getElementById("aba1").style.borderLeftWidth = "1px";
		document.getElementById("aba1").style.borderLeftStyle = "solid";
		document.getElementById("aba1").style.borderLeftColor = "#AAA";	
		document.getElementById("aba1").style.borderTopWidth = "1px";
		document.getElementById("aba1").style.borderTopStyle = "solid";
		document.getElementById("aba1").style.borderTopColor = "#AAA";	
		document.getElementById("aba1").style.borderRightWidth = "1px";
		document.getElementById("aba1").style.borderRightStyle = "solid";
		document.getElementById("aba1").style.borderRightColor = "#AAA";
		// Altera borda ABA 2
		document.getElementById("aba2").style.borderBottomWidth = "0px";
		document.getElementById("aba2").style.borderBottomStyle = "solid";
		document.getElementById("aba2").style.borderBottomColor = "#000";	
		document.getElementById("aba2").style.borderLeftWidth = "0px";
		document.getElementById("aba2").style.borderLeftStyle = "solid";
		document.getElementById("aba2").style.borderLeftColor = "#000";	
		document.getElementById("aba2").style.borderTopWidth = "1px";
		document.getElementById("aba2").style.borderTopStyle = "solid";
		document.getElementById("aba2").style.borderTopColor = "#DDD";	
		document.getElementById("aba2").style.borderRightWidth = "1px";
		document.getElementById("aba2").style.borderRightStyle = "solid";
		document.getElementById("aba2").style.borderRightColor = "#DDD";

		// MOSTRA ABA 1 (DIV OSCILAÇÃO)
		document.getElementById("oscilacao").style.display = "block";
		// ESCONDE ABA 2 (DIV PREÇOS)
		document.getElementById("precos").style.display = "none";
	} else {
		if (aba == 2) {
			// Altera cor de fundo da ABA 1
			document.getElementById("aba1").style.backgroundColor = "#FAFAFA";
			// Altera cor de fonte da ABA 1
			document.getElementById("aba1").style.color = "#333";
			// Altera cor de fundo da ABA 2
			document.getElementById("aba2").style.backgroundColor = "#EFEFEF";
			// Altera cor de fonte da ABA 2
			document.getElementById("aba2").style.color = "#333";

			// Altera borda ABA 1
			document.getElementById("aba1").style.borderBottomWidth = "0px";
			document.getElementById("aba1").style.borderBottomStyle = "solid";
			document.getElementById("aba1").style.borderBottomColor = "#CCC";	
			document.getElementById("aba1").style.borderLeftWidth = "1px";
			document.getElementById("aba1").style.borderLeftStyle = "solid";
			document.getElementById("aba1").style.borderLeftColor = "#DDD";	
			document.getElementById("aba1").style.borderTopWidth = "1px";
			document.getElementById("aba1").style.borderTopStyle = "solid";
			document.getElementById("aba1").style.borderTopColor = "#DDD";	
			document.getElementById("aba1").style.borderRightWidth = "0px";
			document.getElementById("aba1").style.borderRightStyle = "solid";
			document.getElementById("aba1").style.borderRightColor = "#000"
			// Altera borda ABA 2;
			document.getElementById("aba2").style.borderBottomWidth = "2px";
			document.getElementById("aba2").style.borderBottomStyle = "solid";
			document.getElementById("aba2").style.borderBottomColor = "#EFEFEF";	
			document.getElementById("aba2").style.borderLeftWidth = "1px";
			document.getElementById("aba2").style.borderLeftStyle = "solid";
			document.getElementById("aba2").style.borderLeftColor = "#AAA";	
			document.getElementById("aba2").style.borderTopWidth = "1px";
			document.getElementById("aba2").style.borderTopStyle = "solid";
			document.getElementById("aba2").style.borderTopColor = "#AAA";	
			document.getElementById("aba2").style.borderRightWidth = "1px";
			document.getElementById("aba2").style.borderRightStyle = "solid";
			document.getElementById("aba2").style.borderRightColor = "#AAA";

			// ESCONDE ABA 1 (DIV OSCILAÇÃO)
			document.getElementById("oscilacao").style.display = "none";
			// MOSTRA ABA 2 (DIV PREÇOS)
			document.getElementById("precos").style.display = "block";
		}
	}
}

// Função para mascara
/*
caracteres: # - caracter a ser mascarado
            | - separador de mascaras
Exemplos:
mascara simples: "###-####"                   mascara utilizando a mascara passada
mascara composta: "###-####|####-####"        mascara de acordo com o tamanho (length) do valor passado
mascara dinâmica: "[###.]###,##"              multiplica o valor entre colchetes de acordo com o length
                                              do valor para que a mascara seja dinâmica ex: ###.###.###.###,##
utilizar no onkeyup do objeto
ex: onkeyup="this.value = mascara_global('#####-###',this.value);"
tratar o maxlength do objeto na página (a função não trata isso)
*/

function mascara_global(mascara, valor){
      var mascara_utilizar;
      var mascara_limpa;
      var temp;
      var i;
      var j;
      var caracter;
      var separador;
      var dif;
      var validar;
      var mult;
      var ret;
      var tam;
      var tvalor;
      var valorm;
      var masct;
      tvalor = "";
      ret = "";
      caracter = "#";
      separador = "|";
      mascara_utilizar = "";
      //valor = trim(valor);
      if (valor == "")return valor;
      temp = mascara.split(separador);
      dif = 1000;
      valorm = valor;
      //tirando mascara do valor já existente
      for (i=0;i<valor.length;i++){
            if (!isNaN(valor.substr(i,1))){
                  tvalor = tvalor + valor.substr(i,1);
            }
      }
      valor = tvalor;
      //formatar mascara dinamica
      for (i = 0; i<temp.length;i++){
            mult = "";
            validar = 0;
            for (j=0;j<temp[i].length;j++){
                  if (temp[i].substr(j,1) == "]"){
                        temp[i] = temp[i].substr(j+1);
                        break;
                  }
                  if (validar == 1)mult = mult + temp[i].substr(j,1);
                  if (temp[i].substr(j,1) == "[")validar = 1;
            }
            for (j=0;j<valor.length;j++){
                  temp[i] = mult + temp[i];
            }
      }
      //verificar qual mascara utilizar
      if (temp.length == 1){
            mascara_utilizar = temp[0];
            mascara_limpa = "";
            for (j=0;j<mascara_utilizar.length;j++){
                  if (mascara_utilizar.substr(j,1) == caracter){
                        mascara_limpa = mascara_limpa + caracter;
                  }
            }
            tam = mascara_limpa.length;
      }else{
            //limpar caracteres diferente do caracter da máscara
            for (i=0;i<temp.length;i++){
                  mascara_limpa = "";
                  for (j=0;j<temp[i].length;j++){
                        if (temp[i].substr(j,1) == caracter){
                             mascara_limpa = mascara_limpa + caracter;
                        }
                  }
                  if (valor.length > mascara_limpa.length){
                        if (dif > (valor.length - mascara_limpa.length)){
                             dif = valor.length - mascara_limpa.length;
                             mascara_utilizar = temp[i];
                             tam = mascara_limpa.length;
                        }
                  }else if (valor.length < mascara_limpa.length){
                        if (dif > (mascara_limpa.length - valor.length)){
                             dif = mascara_limpa.length - valor.length;
                             mascara_utilizar = temp[i];
                             tam = mascara_limpa.length;
                        }
                  }else{
                        mascara_utilizar = temp[i];
                        tam = mascara_limpa.length;
                        break;
                  }
            }
      }
      //validar tamanho da mascara de acordo com o tamanho do valor
      if (valor.length > tam){
            valor = valor.substr(0,tam);
      }else if (valor.length < tam){
            masct = "";
            j = valor.length;
            for (i = mascara_utilizar.length-1;i>=0;i--){
                  if (j == 0) break;
                  if (mascara_utilizar.substr(i,1) == caracter){
                        j--;
                  }
                  masct = mascara_utilizar.substr(i,1) + masct;
            }
            mascara_utilizar = masct;
      }
      //mascarar
      j = mascara_utilizar.length -1;
      for (i = valor.length - 1;i>=0;i--){
            if (mascara_utilizar.substr(j,1) != caracter){
                  ret = mascara_utilizar.substr(j,1) + ret;
                  j--;
            }
            ret = valor.substr(i,1) + ret;
            j--;
      }
      return ret;
}

// Função para abertura de Alert
function alertMsg(msg) { //v1.0
  alert(msg);
}

// Função para abertura de Alert
function alertMsg(msg) { //v1.0
  alert(msg);
}

// FONT SIZE MANAGEMENT 
function FindObj(n, d) { //v4.01
	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=FindObj(n,d.layers[i].document);
	if(!x && d.getElementById) 
		x=d.getElementById(n); 
	return x;
}

function ChangeProp(objName,x,theProp,theValue) { //v6.0
	var obj;
	obj = FindObj(objName);
	if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
		if (theValue == true || theValue == false){
			eval("obj."+theProp+"="+theValue);
		}else{
			eval("obj."+theProp+"='"+theValue+"px'");
		}
	}
}

function LoadActualFontSize() {
	tempArray = document.cookie.split(";");
	for (tA = 0; tA < tempArray.length; tA++){
		if (tempArray[tA].indexOf('fontSize') > -1){
			fontSizeValue = tempArray[tA].split("=");
			ACTUAL_FONTSIZE = parseInt(fontSizeValue[1]);
		}
	}
}

function SaveActualFontSize() {
	var expire = new Date ();
	expire.setTime (expire.getTime() + (6000 * 24 * 3600000));
	expire = expire.toGMTString();
	document.cookie="fontSize="+ACTUAL_FONTSIZE+"; path=/; expires="+expire;
}

function Bigger() {
	LoadActualFontSize();
	ACTUAL_FONTSIZE = ACTUAL_FONTSIZE+2;
	if (ACTUAL_FONTSIZE > LARGEST_FONTSIZE){ 
		ACTUAL_FONTSIZE = LARGEST_FONTSIZE;
	}
	ChangeProp('dnn_ContentPane','','style.fontSize',ACTUAL_FONTSIZE,'SPAN');
	SaveActualFontSize();
}

function Smaller() {
	LoadActualFontSize();
	ACTUAL_FONTSIZE = ACTUAL_FONTSIZE-2;
	if (ACTUAL_FONTSIZE < SMALLEST_FONTSIZE){
		ACTUAL_FONTSIZE = SMALLEST_FONTSIZE;
	}
	ChangeProp('dnn_ContentPane','','style.fontSize',ACTUAL_FONTSIZE,'SPAN');
	SaveActualFontSize();
}

ACTUAL_FONTSIZE = 16;
SMALLEST_FONTSIZE = 16;
LARGEST_FONTSIZE = 24;
