var flashVideoDivCreated = false;

function appendEvents(){
	var objForm = document.getElementsByTagName("input");
	var objTextarea = document.getElementsByTagName("textarea");
	for(var i=0; i<objForm.length; i++){
		if(objForm[i].getAttribute("type") == "text") {
			objForm[i].onfocus = function(){
				this.className='on';
			}
			objForm[i].onblur = function(){
				this.className='off';
			}
		}
		if(objForm[i].getAttribute("type") == "password") {
			objForm[i].onfocus = function(){
				this.className='on';
			}
			objForm[i].onblur = function(){
				this.className='off';
			}
		}
	}

	for(var i=0; i<objTextarea.length; i++){
		if(objTextarea[i].getAttribute("type") == "textarea") {
			objTextarea[i].onfocus = function(){
				this.className='on';
			}
			objTextarea[i].onblur = function(){
				this.className='off';
			}
		}
	}
}

function abrirPalestra() {
	location='../_faleConosco/?abrir=4';
}

function loadDefaultVideo() {
  removeDefaultVideo();
  carregaFlash('../_swf/invTotal0070_0775.flv');
}

function createFlashVideoDiv(str) {
  if (!flashVideoDivCreated) {
    str ? divName = str : divName = 'videoFlash';
    var params = {wmode: "transparent"};
    var flashVars = {};
    swfobject.embedSWF("https://www.investotal.com/_swf/swf_mask.swf", divName, "320", "240", "9.0.0", "expressInstall.swf", flashVars, params);
    flashVideoDivCreated = true;
  }
}

//carregaFlash('../_swf/invTotal0070_0775.flv');
function removeDefaultVideo(input) {
  var obj;
  var id;
  if (input && input.id) {
    id = input;
  } else {
    id = document.getElementById('input');
  }
  id ? obj = id : obj = document.getElementById('videoFlashDiv');
  if (obj && obj.onclick != '') {
    obj.onclick = '';
  }
}
function carregaFlash(url,op){
  createFlashVideoDiv();
  //removeDefaultVideo();
	var params = {wmode: "transparent"};
	var flashVars = {caminho: url, caminhoSkin: '../_swf/ClearOverAll.swf'};
	if (op) params = op;
	swfobject.embedSWF("../_swf/video.swf", "videoFlash", "320", "240", "9.0.0", "expressInstall.swf", flashVars, params);
}



function start() {
	//appendEvents();
	if (this.msg) {
		alertbox(msg);
	}
}

function duvidas() {
	abreAjax('../_duvidas/glossario.php','conteudo');
}

var anterior = {el:null, classe:""};

function clickItem(elem, arquivo, classe) {
	abreAjax(arquivo,'conteudo');

	var oldClasse = elem.className;

	elem.className = classe;

	if(anterior.el) {
		anterior.el.className = anterior.classe;
	}
	anterior.el = elem;
	anterior.classe = oldClasse;
}

function mostrarResposta(i){
	var resposta=document.getElementById("resposta_"+i);
	if (resposta.style.display=='') {
		resposta.style.display='block';
	} else {
		if (resposta.style.display=='block') {
			resposta.style.display='';
		}
	}
}

function validaLogin(form){
  if(!formcheck(form, true, "../_actions/autenticarUsuario.php", document.name)) {
    return;
  }
}

function limitaTexto(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}

//*******************************
//** funções usadas pelos itens do menu
//*******************************


//usr_home.php
function excluirFoto(v){
  abreAjax("../_actions/actionExcluirFotoUsuario.php?CODPRIORIDADE="+v,"conteudo");
  document.getElementById("foto"+v).style.display='none';
  document.getElementById("foto"+v).parentNode.removeChild(document.getElementById("foto"+v));
}

function mudaPrioridade(v){
  abreAjax("../_actions/actionTrocarFotoExibicaoUsuario.php?CODPRIORIDADE="+v,"conteudo");
  //document.getElementById("foto"+v).parentNode.removeChild(document.getElementById("foto"+v));
}


//alterarUsuario.php
function validarInvestidor(form) {
  if(!formcheck(form, true, "../_actions/actionAlterarUsuario.php", document.name)) {
    return;
  }
  top.messagebox("Enviando...");
}

//item do menu "cotacoes"
function showMenuCotacoes(v, el){
  if (v==1){
    $("subMenuCotacoesDiv").style.display = "block";
    //if(el){$("subMenuCotacoesDiv").style.left = Element.cumulativeOffset($(el))([0]-1);}
  }else{
    $("subMenuCotacoesDiv").style.display = "none";
  }
}

//editar usuario : certificado financeiro > checkbox 'outros'
function desactiva(obj) {
  nForm = document.forms['form1'];
  if(obj.checked){
      nForm.elements['outros'].disabled = false;
  }else{
      nForm.elements['outros'].disabled = true;
  }
}

/*## FUNÇÕES DE OPACIDADE ##*/

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
    //if an element is invisible, make it visible, else make it ivisible
    if(document.getElementById(id).style.opacity == 0) {
        opacity(id, 0, 70, millisec);
    } else {
        opacity(id, 70, 0, millisec);
    }
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

/*## FIM DAS FUNÇÕES DE OPACIDADE ##*/

function aviso(idAlvo, texto, tempo){
	if (!texto) texto="";
	if (!tempo) tempo=5000;
	document.getElementById(idAlvo).style.display='block';
	document.getElementById('textoAviso').innerHTML=texto;
	opacity(idAlvo,0,70,1000);
	setTimeout("shiftOpacity('"+idAlvo+"',1000);",tempo);
	setTimeout("document.getElementById('"+idAlvo+"').style.display='';",tempo+1000);
}

//esqueceuLoginSenha.php

function validarEsqueceuSenha(form) {
  if(!formcheck(form, true, "../_actions/esqueceuLoginSenha.php", document.name)) {
    return;
  }
  messagebox("Enviando...");
}

//Seção Investimentos

function avisoLogar () {
	myLightWindow.deactivate();
	document.getElementById('nomeLogin').focus();
	aviso('avisoLogin', 'Faça login através dos campos <strong>login</strong> e <strong>senha</atrong>.');
}

var inter;

function descendo(obj){
	var el = document.getElementById(obj);
	el.scrollTop += 10;
}

function subindo(){
	var el = document.getElementById('linksFlashVideos');
	el.scrollTop -= 10;
}

function scrollDownObjeto(obj){
	inter = self.setInterval("descendo('"+obj+"');", 100);
}

function scrollUpObjeto(obj){
	inter = self.setInterval("subindo('"+obj+"');", 100);
}

function parar(){
	self.clearInterval(inter);
}

function confirmBoxMercadoNews() {
	if (confirm("Confirme para receber o Mercado News.")) {
		location.href="../_actions/actionAlterarUsuarioMercadoNews.php";
	}
}
