/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ESTE ARQUIVO CONTEM FUNÇÕES JAVASCRIPT PARA MANIPULAÇÃO DE EVENTOS DIVERSOS DENTRO DO SITE

TODO EVENTO (CLICK, MOUSEOVER, MOUSEOUT, ) EXISTE EM UM CONTROLE HTML (A, BUTTON, IMG), DEVERÁ SER CRIADO AQUI
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/


/* ************************************************************************ */
/*                  CARREGA A FUNÇÃO DE ADIÇÃO DOS EVENTOS                  */
/* ************************************************************************ */
window.onload = Page_Load;



/* ************************************************************************ */
/*                  ADICIONA UM EVENTO A UM OBJETO                          */
/*     EX.: $addEv(objeto, "Tipo Evento", função relacionada ao evento);    */
/* ************************************************************************ */
function $addEv(obj, 
    type, 
    fn) {
	/*Verifica se o objeto realmente existe (valor diferente de nulo).*/
	if (obj) {
		//Verifica qual o função ideal a ser utilizado para a criação do evento.
		if (obj.addEventListener) //Função recomendada pela W3C.
			obj.addEventListener(type, fn, true)
		if (obj.attachEvent) //Função de uso no Internet Explorer.
			obj.attachEvent("on"+type, fn)
	}
} //Fim da função "$addEv".



/* ************************************************************************ */
/*              CARREGA TODOS OS CONTROLES ADICIONANDO EVENTOS              */
/*        CARGA DE OBJETOS DIVERSOS (ARQUIVOS FLASH E CONTROLE DE BOX       */
/* ************************************************************************ */
function Page_Load() {
    CapturarControles();
    carregaFlashHome();
    carregaFlashClientes();
    carregaFlashBanner();

    //Criação de eventos
    $addEv(lkFaqTodas, "click", fcn_faq);
    $addEv(lkVerAtualizacoes, "click", fcn_atualizacao);
    $addEv(lkVerDownload, "click", fcn_download);
    $addEv(imgMenos, "click", fcn_subtrairAno);
    $addEv(imgMais, "click", fcn_somarAno);
    
    if (!document.getElementById("my_menu")) {
    } else {
        myMenu = new SDMenu("my_menu");
	    myMenu.init();
    }
}



/* ************************************************************************ */
/*              CAPTURA CONTROLES PARA ADIÇÃO DE EVENTOS                    */
/* ************************************************************************ */
function CapturarControles() {
    //Link A.
	lkFaqTodas = document.getElementById("lkVerTodas");
	lkVerAtualizacoes = document.getElementById("lkAtualizacao");
	lkVerDownload = document.getElementById("lkDownload");
	
	//IMG
	imgMenos = document.getElementById("setaMenos");
	imgMais = document.getElementById("setaMais");
}



/* ************************************************************************ */
/*                  FUNÇÕES PARA MANIPULAÇÃO DE EVENTOS                     */
/* ************************************************************************ */
function fcn_faq()
{
    location.href = "faq.aspx";
}

function fcn_atualizacao()
{
    location.href = "atualizacao.aspx";
}

function fcn_download()
{
    location.href = "download.aspx";
}

function fcn_subtrairAno()
{
    var anoAtual, novoAno;
    anoAtual = parseInt(document.getElementById("ctl00_ContentPlaceHolder1_txtAno").value);
    novoAno = anoAtual - 1;
    document.getElementById("ctl00_ContentPlaceHolder1_txtAno").value = novoAno;
}

function fcn_somarAno()
{
    var anoAtual, novoAno;
    anoAtual = document.getElementById("ctl00_ContentPlaceHolder1_txtAno").value;
    novoAno = (parseInt(anoAtual)) + 1;
    document.getElementById("ctl00_ContentPlaceHolder1_txtAno").value = novoAno;
}


/* ************************************************************************ */
/*                      ADIÇÃO DE ARQUIVOS FLASH                            */
/* ************************************************************************ */
function carregaFlashHome() {
    var caminho;
    caminho = '';
    caminho += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="1009" height="295" align="middle">';
    caminho += '    <param name="allowScriptAccess" value="sameDomain" />';
    caminho += '    <param name="movie" value="images/swf/topo.swf?n='+ new Date().getTime() + '" />';
    caminho += '    <param name="quality" value="high" />';
    caminho += '    <param name="wmode" value="transparent" />';
    caminho += '    <param name="bgcolor" value="#ffffff" />';
    caminho += '    <embed src="images/swf/topo.swf?n='+ new Date().getTime() + '" quality="high" wmode="transparent" bgcolor="#ffffff" width="1009" height="295" name="topo" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
    caminho += '</object>';
    
    document.getElementById("dvTopo").innerHTML = caminho;
}

/* ************************************************************************ */
/*                      ADIÇÃO DE ARQUIVOS FLASH                            */
/* ************************************************************************ */
function carregaFlashClientes() {
    var caminho;
    caminho = '';
    caminho += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="480" height="53" align="middle">';
    caminho += '    <param name="allowScriptAccess" value="sameDomain" />';
    caminho += '    <param name="movie" value="images/swf/banner_clientes.swf?n='+ new Date().getTime() + '" />';
    caminho += '    <param name="quality" value="high" />';
    caminho += '    <param name="wmode" value="transparent" />';
    caminho += '    <param name="bgcolor" value="#ffffff" />';
    caminho += '    <embed src="images/swf/banner_clientes.swf?n='+ new Date().getTime() + '" quality="high" wmode="transparent" bgcolor="#ffffff" width="480" height="53" name="topo" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
    caminho += '</object>';
    
    if (document.getElementById("dvClientesFlash") != null)
    {
        document.getElementById("dvClientesFlash").innerHTML = caminho;
    }
}

/* ************************************************************************ */
/*                      ADIÇÃO DE ARQUIVOS FLASH                            */
/* ************************************************************************ */
function carregaFlashBanner() {
    var caminho;
    caminho = '';
    caminho += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="500" height="195">';
    caminho += '    <param name="allowScriptAccess" value="sameDomain" />';
    caminho += '    <param name="movie" value="images/swf/banner.swf?n='+ new Date().getTime() + '" />';
    caminho += '    <param name="quality" value="high" />';
    caminho += '    <param name="wmode" value="transparent" />';
    caminho += '    <param name="bgcolor" value="#ffffff" />';
    caminho += '    <embed src="images/swf/banner.swf?n='+ new Date().getTime() + '" quality="high" wmode="transparent" bgcolor="#ffffff" width="500" height="195" name="banner" align="middle" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">';
    caminho += '</object>';
    
    if (document.getElementById("dvBannerH") != null)
    {
        document.getElementById("dvBannerH").innerHTML = caminho;
    }
}


/* ************************************************************************ */
/*              SCRIPTS PARA EFEITO DE EXPANSÃO (ABERTURA) DE BOX           */
/* ************************************************************************ */
function SDMenu(id) {
	if (!document.getElementById || !document.getElementsByTagName)
		return false;
	this.menu = document.getElementById(id);
	this.submenus = this.menu.getElementsByTagName("div");
	this.remember = true;
	this.speed = 15;
	this.markCurrent = true;
	this.oneSmOnly = false;
}
SDMenu.prototype.init = function() {
	var mainInstance = this;
	for (var i = 0; i < this.submenus.length; i++) {
		if (this.submenus[i].id == "mnPrincipal") {
			this.submenus[i].getElementsByTagName("span")[0].onclick = function() {
				mainInstance.toggleMenu(this.parentNode);
			};
		}
	}

	if (this.markCurrent) {
		var links = this.menu.getElementsByTagName("p");
	}

	if (this.remember) {
		var regex = new RegExp("sdmenu_" + encodeURIComponent(this.menu.id) + "=([01]+)");
		var match = regex.exec(document.cookie);
		if (match) {
			var states = match[1].split("");
			for (var i = 0; i < states.length; i++)
				this.submenus[i].className = (states[i] == 0 ? "collapsed" : "");
		}
	}
};
SDMenu.prototype.toggleMenu = function(submenu) {
	if (submenu.className == "collapsed")
		this.expandMenu(submenu);
	else
		this.collapseMenu(submenu);
};
SDMenu.prototype.expandMenu = function(submenu) {
	var fullHeight = submenu.getElementsByTagName("span")[0].offsetHeight;
	var links = submenu.getElementsByTagName("p");
	for (var i = 0; i < links.length; i++)
		fullHeight += links[i].offsetHeight;
	var moveBy = Math.round(this.speed * links.length);
	
	var mainInstance = this;
	var intId = setInterval(function() {
		var curHeight = submenu.offsetHeight;
		var newHeight = curHeight + moveBy;
		if (newHeight < fullHeight)
			submenu.style.height = newHeight + "px";
		else {
			clearInterval(intId);
			submenu.style.height = "";
			submenu.className = "";
			mainInstance.memorize();
		}
	}, 30);
	this.collapseOthers(submenu);
};
SDMenu.prototype.collapseMenu = function(submenu) {
	var minHeight = submenu.getElementsByTagName("span")[0].offsetHeight;
	var moveBy = Math.round(this.speed * submenu.getElementsByTagName("p").length);
	var mainInstance = this;
	var intId = setInterval(function() {
		var curHeight = submenu.offsetHeight;
		var newHeight = curHeight - moveBy;
		if (newHeight > minHeight)
			submenu.style.height = newHeight + "px";
		else {
			clearInterval(intId);
			submenu.style.height = "";
			submenu.className = "collapsed";
			mainInstance.memorize();
		}
	}, 30);
};
SDMenu.prototype.collapseOthers = function(submenu) {
	if (this.oneSmOnly) {
		for (var i = 0; i < this.submenus.length; i++)
			if (this.submenus[i] != submenu && this.submenus[i].className != "collapsed")
				this.collapseMenu(this.submenus[i]);
	}
};
SDMenu.prototype.expandAll = function() {
	var oldOneSmOnly = this.oneSmOnly;
	this.oneSmOnly = false;
	for (var i = 0; i < this.submenus.length; i++)
		if (this.submenus[i].className == "collapsed")
			this.expandMenu(this.submenus[i]);
	this.oneSmOnly = oldOneSmOnly;
};
SDMenu.prototype.collapseAll = function() {
	for (var i = 0; i < this.submenus.length; i++)
		if (this.submenus[i].className != "collapsed")
			this.collapseMenu(this.submenus[i]);
};
SDMenu.prototype.memorize = function() {
	if (this.remember) {
		var states = new Array();
		for (var i = 0; i < this.submenus.length; i++)
			states.push(this.submenus[i].className == "collapsed" ? 0 : 1);
		var d = new Date();
		d.setTime(d.getTime() + (30 * 24 * 60 * 60 * 1000));
		document.cookie = "sdmenu_" + encodeURIComponent(this.menu.id) + "=" + states.join("") + "; expires=" + d.toGMTString() + "; path=/";
	}
};

function fcn_menuFlash(pagina) {
    if(pagina == "home"){
        location.href = "default.aspx";
    }
     if(pagina == "imprensa"){
        location.href = "conteudo.aspx?idPagina=18";
    }
    
    if(pagina == "faq"){
        location.href = "faq.aspx";
    }
    if(pagina == "easyway"){
        location.href = "conteudo.aspx?idPagina=8";
    }
    if(pagina == "eventos"){
        location.href = "eventos.aspx";
    }
    if(pagina == "produtos"){
        location.href = "produtos.aspx";
    }
    if(pagina == "servicos"){
        location.href = "servicos.aspx";
    }
    if(pagina == "noticias"){
        location.href = "noticias.aspx";
    }
    if(pagina == "clientes"){
        location.href = "clientes.aspx";
    }
    if(pagina == "contato"){
        location.href = "contato.aspx";
    }
    if(pagina == "links"){
        location.href = "links.aspx";
    }
    if(pagina == "trabalhe"){
        location.href = "trabalhe.aspx";
    }
    if(pagina == "mapa"){
        location.href = "mapasite.aspx";
    }
    if(pagina == "atualizacao"){
        location.href = "atualizacao.aspx";
    }
    if(pagina == "noticia2"){
        location.href = "noticiasler.aspx";
    }
    if(pagina == "download"){
        location.href = "download.aspx";
    }
    if(pagina == "easy_quem"){
        location.href = "conteudo.aspx?idPagina=1";
    }
    if(pagina == "easy_mvv"){
        location.href = "conteudo.aspx?idPagina=2";
    }
    if(pagina == "easy_historia"){
        location.href = "conteudo.aspx?idPagina=3";
    }
    if(pagina == "easy_premios"){
       location.href = "conteudo.aspx?idPagina=4";
    }
    if(pagina == "easy_parcerias"){
        location.href = "conteudo.aspx?idPagina=5";
    }
    if(pagina == "easy_respsocial"){
        location.href = "conteudo.aspx?idPagina=6";
    }
    if(pagina == "easy_palavradir"){
        location.href = "conteudo.aspx?idPagina=7";
    }
    
    /*novos menus*/
    if(pagina == "assessoria_implantacao"){
        location.href = "assessoria_implantacao.aspx";
    }
    
    if(pagina == "atualizacao_permanente"){
        location.href = "atualizacao_permanente.aspx";
    }
    
    if(pagina == "assessoria_permanente"){
        location.href = "assistencia_permanente.aspx";
    }
    
    if(pagina == "treinamento"){
        location.href = "treinamento.aspx";
    }
    
    if(pagina == "cases"){
        location.href = "cases.aspx";
    }    
}

function fcn_Banner(pagina){
    if(pagina == "Produto1"){
        location.href = "produtos.aspx?id_produto=116";
    }
    if(pagina == "Produto2"){
        location.href = "produtos.aspx?id_produto=119";
    }
    if(pagina == "Produto3"){
        location.href = "produtos.aspx?id_produto=121";
    }  
}


function fcn_abrirMenu(id, id_img, id_texto){
	if (document.getElementById(id).style.display == "none"){
		document.getElementById(id).style.display = "block";
		document.getElementById(id_texto).style.color = "#006991";
		document.getElementById(id_img).innerHTML = "<img alt='' src='/images/gifs/setinha_subTituloFechar.gif' />";
	}
	else{
		document.getElementById(id).style.display = "none";
		document.getElementById(id_texto).style.color = "#262a2b";
		document.getElementById(id_img).innerHTML = "<img alt='' src='/images/gifs/setinha_subTituloAbrir.gif' />";
	}
}


function fcn_abrirMenu(id, id_img){
	if (document.getElementById(id).style.display == "none"){
		document.getElementById(id).style.display = "block";
		document.getElementById(id_img).innerHTML = "<img alt='' src='images/gifs/setinha_subTituloFechar.gif' />";
	}
	else{
		document.getElementById(id).style.display = "none";
		document.getElementById(id_img).innerHTML = "<img alt='' src='images/gifs/setinha_subTituloAbrir.gif' />";
		var elements = 	document.getElementById(id).getElementsByTagName("div");
	}
}


function fcn_validaDados(){
	if(document.frm_inside.txt_assunto.value == "")	{
		alert('Por favor preencha o campo Assunto!');
		document.frm_inside.txt_assunto.focus();
		return false;
	}
	
	if(document.frm_inside.txt_mensagem.value == ""){
		alert('Por favor preencha o campo Mensagem!');
		document.frm_inside.txt_mensagem.focus();
		return false;
	}
}

//Função para que só seja digitado número no campo número e não texto
function fcn_validaCaracter(pstr_campo) {
	var campo = pstr_campo.value
	campo = campo.length
	
	var vstr_caracter = document.layers ? evt.which
						: document.all ? event.keyCode
						: evt.keyCode;
	
	//alert(vstr_caracter)		
	if(parseInt(vstr_caracter)!=8 && parseInt(vstr_caracter)!=9){
	    if ((parseInt(vstr_caracter)<46 || parseInt(vstr_caracter) > 57) && (parseInt(vstr_caracter)<96 || parseInt(vstr_caracter) > 105)){			
		    return false;
	    }
	}	
		
}

function getPosition(elemID){
    var offsetTrail = document.getElementById(elemID);
    var offsetLeft = 0;
    var offsetTop = 0;
    var offsetRight = 0;
    
    while (offsetTrail) 
    {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
        offsetRight += offsetTrail.offsetRight;
        offsetTrail = offsetTrail.offsetParent;
    }
    if (navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined")
    {
        offsetLeft += document.body.leftMargin;
        offsetTop += document.body.topMargin;
    }
    
    return {left:offsetLeft, top:offsetTop};
}

//Função para validação de caracteres
function only(t, o, e) {
    if (window.event) {
        key = window.event.keyCode;
    } else if (e) {
        key = e.which;
    } else {
        return true;
    }
    S = o ? o : "";
    if (t == "num" || t == "number" || t == "numeric") {
        S += "0123456789";
    }
    if (t == "tel") {
        S += "0123456789()- ";
    }
    if (t == "valor") {
        S += "0123456789.,";
    }
    if (t == "alnum" || t == "alphanumeric") {
        S += "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\xE1\xE0\xE3\xE2\xE4\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF3\xF2\xF5\xF4\xF6\xFA\xF9\xFB\xFC\xE7\xC1\xC0\xC3\xC2\xC4\xC9\xC8\xCA\xCB\xCD\xCC\xCE\xCF\xD3\xD2\xD5\xD4\xD6\xDA\xD9\xDB\xDC\xC7 0123456789";
    }
    if (t == "let" || t == "letters") {
        S += "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\xE1\xE0\xE3\xE2\xE4\xE9\xE8\xEA\xEB\xED\xEC\xEE\xEF\xF3\xF2\xF5\xF4\xF6\xFA\xF9\xFB\xFC\xE7\xC1\xC0\xC3\xC2\xC4\xC9\xC8\xCA\xCB\xCD\xCC\xCE\xCF\xD3\xD2\xD5\xD4\xD6\xDA\xD9\xDB\xDC\xC7 ";
    }
    if (t == "rest" || t == "restrict") {
        S += "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    }
    if (t == "email") {
        S += "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@-_.";
    }
    if (key == null ||
        key == 0 || key == 8 || key == 9 || key == 13 || key == 27) {
        return true;
    } else if (S.indexOf(String.fromCharCode(key)) != -1) {
        return true;
    } else {
        return false;
    }
}

function VisualizarImgAmpliada(arquivo)
    {
            var height_ = $(document).height();
            var width_ = $(document).width();
        var left_ = (width_ - 450) / 2;
        var top_ = parseInt(getPageScroll().yScroll + (($(document).height() - 800) / 2),10) + 'px';
   
        $('.dvFundo').css({display:'block', opacity:0, height:height_, width:'100%'}).fadeTo("slow", 0.85);
        $('.dvImgAmpliada').css({display:'block', opacity:0, left:left_, top:top_}).fadeTo("slow", 1);
   
        $('#imgAmpliada').attr('src', arquivo);
    }

function FecharImgAmpliada()
{
    $('.dvFundo').hide();
    $('.dvImgAmpliada').hide();
}

function getPageScroll(){
        var yScroll;

    if(self.pageYOffset)
        yScroll = self.pageYOffset;
        else if(document.documentElement && document.documentElement.scrollTop)
            yScroll = document.documentElement.scrollTop;
        else if(document.body)
        yScroll = document.body.scrollTop;  

    arrayPageScroll = {yScroll:yScroll};
    return arrayPageScroll;
}

function Count(text,long) 
{
	var maxlength = new Number(long); // Change number to your max length.
	if (text.value.length > maxlength){
		text.value = text.value.substring(0,maxlength);
		alert("Limite de Caracteres Atingido!");
	}
}

function centerPopUp(url, name, width, height, scrollbars)
{
    str  = "";
    str +=  "menu=no,";
    str +=  "directories=no,";
    str +=  "menubar=no,";
    str +=  "resizable=yes,";
    str +=  "location=no,";
    str +=  "statusbars=yes,";
    str +=  "toolbar=no,";
    str +=  "status=no,";
    str += "scrollbars=" + scrollbars + ",";
    str += "width=" + width + ",";
    str += "height=" + height + ",";

    if ( window.screen ) {
                        var ah = screen.availHeight;
                        var aw = screen.availWidth;

                        var xc = ( aw - width ) / 2;
                        var yc = ( ah - height ) / 2;

                        str += ",left=" + xc + ",screenX=" + xc;
                        str += ",top=" + yc + ",screenY=" + yc;
    }
    window.open(url, name, str);
}
