String.prototype.trim = function(){return this.replace(/^\s+|\s+$/g,"");}

function VerificaEmail(pcampo)
{
	pcampo.value = pcampo.value.toLowerCase();					
	parametro = pcampo.value;								
	teste_parametro = "false"; 
	tamanho_parametro = parametro.length;
	aposicao = 0; //posicao @
	pposicao = 0; //poiscao ponto
	narrobas = 0; // numero de @
	for (i = 0; i < tamanho_parametro; i++) { /*verifica se existe espaco em branco */
		if (parametro.charAt(i) == "@"){
			narrobas = narrobas + 1
			aposicao = i;
		}
		if (parametro.charAt(i) == "."){
			pposicao = i;
		}
	}
	if (aposicao > 0 && aposicao+1 < pposicao && narrobas<2){
		teste_parametro = "true"; 
	}

	for (i = 0; i < tamanho_parametro; i++) { /*verifica se existe espaco em branco */
		if (parametro.charAt(i) == " "){
			teste_parametro = "false"; 
		}
	}
	
	if (tamanho_parametro < 5){
		teste_parametro = "false"; /*tamanho minimo*/
	}
		
	if (parametro.charAt(0) == " " || parametro.charAt(1) == " ") { /*Primeiros chars em branco */
		teste_parametro = "false"; 
	}
	
	if (teste_parametro == "false" && tamanho_parametro != 0 ) { /*Existe algum problema no preenchiento do nome */
		MsgBox.Show("Dados Inválidos", "Verifique seu e-mail.", "alerta");
		pcampo.value = "";
		pcampo.focus();
		return false;
	}
	else
		return true;
}

/*******************
* Método: limpar/mostrar
* Finalidade: limpa o campo no foco e repõe mensagem se o texto não for digitado
*********************/
function limpar (objeto, msg) {
    if (objeto.value == msg)objeto.value = '';
}

function mostrar (objeto, msg) {
    if (objeto.value == '')objeto.value = msg;
}

/*******************
* Método: aplicaFlash
* Finalidade: insere o Flash no HTML
*********************/
function aplicaFlash(swf, width, height, wmode, flashVars, cache ) {
	var noCache = "";
	if (cache == undefined || cache == '') {var noCache = "?" + new Date();}
	if (wmode != "opaque" && wmode != "transparent") {wmode = "transparent";}
	var monta_swf = "";
	monta_swf += "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='"+ width +"' height='"+ height +"' title=''>";
	monta_swf += "<param name='movie' value='"+ swf + noCache +"'>";
	monta_swf += "<param name='quality' value='high'>";
	monta_swf += "<param name='AllowScriptAccess' value='always' />";
	monta_swf += "<param name='menu' value='0'>";
	monta_swf += "<param name='wmode' value='"+ wmode +"'>";
	if (!(flashVars == undefined || flashVars == '')){
		monta_swf += "<param name='flashvars' value='"+ flashVars +"'>";
	}
	monta_swf += "<embed AllowScriptAccess=\"always\" src='"+ swf + noCache +"' quality='high' wmode='"+ wmode + "'";
	if (!(flashVars == undefined || flashVars == '')){
		monta_swf += " flashvars='" + flashVars + "' ";
	}
	monta_swf += " pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='"+ width +"' height='"+ height +"'></embed>";
	monta_swf += "</object>";
	document.write(monta_swf);
}

/*******************
* Método: aplicaFlashseguro
* Finalidade: insere o Flash no HTML
*********************/
function aplicaFlashseguro(swf, width, height, wmode, flashVars, cache ) {
	var noCache = "";
	if (cache == undefined || cache == '') {var noCache = "?" + new Date();}
	if (wmode != "opaque" && wmode != "transparent") {wmode = "transparent";}
	var monta_swf = "";
	monta_swf += "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='"+ width +"' height='"+ height +"' title=''>";
	monta_swf += "<param name='movie' value='"+ swf + noCache +"'>";
	monta_swf += "<param name='quality' value='high'>";
	monta_swf += "<param name='AllowScriptAccess' value='always' />";
	monta_swf += "<param name='menu' value='0'>";
	monta_swf += "<param name='wmode' value='"+ wmode +"'>";
	if (!(flashVars == undefined || flashVars == '')){
		monta_swf += "<param name='flashvars' value='"+ flashVars +"'>";
	}
	monta_swf += "<embed AllowScriptAccess=\"always\" src='"+ swf + noCache +"' quality='high' wmode='"+ wmode + "'";
	if (!(flashVars == undefined || flashVars == '')){
		monta_swf += " flashvars='" + flashVars + "' ";
	}
	monta_swf += " pluginspage='https://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='"+ width +"' height='"+ height +"'></embed>";
	monta_swf += "</object>";
	document.write(monta_swf);
}


/*******************
* Método: scrollTo
* Finalidade: acessa uma âncora, rolando a página dinamicamente
*********************/
$.getPos = function (e)
{
	var l = 0;
	var t  = 0;
	var w = $.intval($.css(e,'width'));
	var h = $.intval($.css(e,'height'));
	var wb = e.offsetWidth;
	var hb = e.offsetHeight;
	while (e.offsetParent){
		l += e.offsetLeft + (e.currentStyle?$.intval(e.currentStyle.borderLeftWidth):0);
		t += e.offsetTop  + (e.currentStyle?$.intval(e.currentStyle.borderTopWidth):0);
		e = e.offsetParent;
	}
	l += e.offsetLeft + (e.currentStyle?$.intval(e.currentStyle.borderLeftWidth):0);
	t  += e.offsetTop  + (e.currentStyle?$.intval(e.currentStyle.borderTopWidth):0);
	return {x:l, y:t, w:w, h:h, wb:wb, hb:hb};
};

$.getClient = function(e)
{
	if (e) {
		w = e.clientWidth;
		h = e.clientHeight;
	} else {
		w = (window.innerWidth) ? window.innerWidth : (document.documentElement && document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.offsetWidth;
		h = (window.innerHeight) ? window.innerHeight : (document.documentElement && document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.offsetHeight;
	}
	return {w:w,h:h};
};

$.getScroll = function (e) 
{
	if (e) {
		t = e.scrollTop;
		l = e.scrollLeft;
		w = e.scrollWidth;
		h = e.scrollHeight;
	} else  {
		if (document.documentElement && document.documentElement.scrollTop) {
			t = document.documentElement.scrollTop;
			l = document.documentElement.scrollLeft;
			w = document.documentElement.scrollWidth;
			h = document.documentElement.scrollHeight;
		} else if (document.body) {
			t = document.body.scrollTop;
			l = document.body.scrollLeft;
			w = document.body.scrollWidth;
			h = document.body.scrollHeight;
		}
	}
	return { t: t, l: l, w: w, h: h };
};

$.intval = function (v)
{
	v = parseInt(v);
	return isNaN(v) ? 0 : v;
};

$.fn.ScrollTo = function(s) {
	o = $.speed(s);
	return this.each(function(){
		new $.fx.ScrollTo(this, o);
	});
};

$.fx.ScrollTo = function (e, o)
{
	var z = this;
	z.o = o;
	z.e = e;
	z.p = $.getPos(e);
	z.s = $.getScroll();
	z.clear = function(){clearInterval(z.timer);z.timer=null};
	z.t=(new Date).getTime();
	z.step = function(){
		var t = (new Date).getTime();
		var p = (t - z.t) / z.o.duration;
		if (t >= z.o.duration+z.t) {
			z.clear();
			setTimeout(function(){z.scroll(z.p.y, z.p.x)},13);
		} else {
			st = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.y-z.s.t) + z.s.t;
			sl = ((-Math.cos(p*Math.PI)/2) + 0.5) * (z.p.x-z.s.l) + z.s.l;
			z.scroll(st, sl);
		}
	};
	z.scroll = function (t, l){window.scrollTo(l, t)};
	z.timer=setInterval(function(){z.step();},13);
};

/*	Autor: Eder Ávila Prado
*	Data: 10/06/2009
*	Ação: Carrosel de produtos carregando por ajax os demais produtos OnDemand.
*	Exemplo: Utilizado na página de detalhes de produtos na navegação de similares
*/
function CarroselProdutos(numItensRenderizados, numItensTotal, strIdDivExterna, strIdDivInterna, strIdBtnNavegacaoEsquerda, strIdBtnNavegacaoDireita, strIdUlToInner, strPaginaAjaxRequisicao, strIdLinha, strIdSetor)
{
	//---------- Atributos para o objeto carrosel ----------
	this.primeiroItem = 1;
	this.htmlOriginal = "";
	this.bolProsseguir = true;
	//larguraItens = Largura do campo + padding-right entre um campo e outro.
	this.larguraItens = 186 + 9;
	//larguraNecessariaItem = larguraItens - diferença por conta do ultimo item que não precisa ser apresentado com seu padding (Não tem mais nenhum produto a direita para ser apresentado).
	this.larguraNecessariaItem = this.larguraItens - 1.5;
	this.itensRenderizados = numItensRenderizados;
	this.itensTotal = numItensTotal;
	this.idDivExterna = strIdDivExterna;
	this.idDivInterna = strIdDivInterna;
	this.idBotaoNavegacaoEsquerda = strIdBtnNavegacaoEsquerda;
	this.idBotaoNavegacaoDireita = strIdBtnNavegacaoDireita;
	this.idUlToInner = strIdUlToInner;
	this.strPaginaAjax = strPaginaAjaxRequisicao;
	this.strLinha = strIdLinha;
	this.strSetor = strIdSetor;
	this.strCodigoProduto = "";
	//---------------------------------------------------------------
	
	//Métodos para o objeto carrosel
	CarroselProdutos.prototype.GetUltimo = function()
	{
		var ultimo = (parseInt($("#" + this.idDivExterna).width() / this.larguraNecessariaItem)) + this.primeiroItem - 1;
		return ultimo;
	}
	
	CarroselProdutos.prototype.GetWidthDivExterna = function()
	{
		var largura = $("#" + this.idDivExterna).width();
		return largura;
	}
	
	CarroselProdutos.prototype.MoveEsquerda = function()
	{
		var itensMove = parseInt(this.GetWidthDivExterna() / this.larguraNecessariaItem);
		var itensApresentados = itensMove;
		
		if (itensMove >= this.primeiroItem)
			itensMove = this.primeiroItem - 1;
		
		$("#" + this.idDivInterna).animate({"marginLeft": "+=" + (this.larguraItens * itensMove) + "px"}, "slow");
		this.primeiroItem = this.primeiroItem - itensMove;
		
		this.AtivarBotoesNavegacao(this.primeiroItem, this.primeiroItem + itensApresentados - 1);
	}
	
	CarroselProdutos.prototype.MoveDireita = function()
	{
		if (this.bolProsseguir == true)
		{
			var itensMove = parseInt(this.GetWidthDivExterna() / this.larguraNecessariaItem);
			var itensApresentados = itensMove;
			var ultimo = this.primeiroItem + itensMove * 2;
			
			if (ultimo > this.itensTotal)
				itensMove = this.itensTotal - (this.primeiroItem + itensMove - 1);
			
			this.primeiroItem = this.primeiroItem + itensMove;
			ultimo = this.primeiroItem + itensApresentados - 1;
			
			$("#" + this.idDivInterna).animate({"marginLeft": "-=" + this.larguraItens * itensMove + "px"}, "slow");
			
			if (ultimo > this.itensRenderizados)
			{
				this.NextItens(this.itensRenderizados, ultimo - this.itensRenderizados);
				this.itensRenderizados = ultimo;
			}
			this.AtivarBotoesNavegacao(this.primeiroItem, ultimo);
		}
	}
	
	CarroselProdutos.prototype.AtivarBotoesNavegacao = function(intPrimeiroItem, intUltimoItem)
	{
		if (intPrimeiroItem == 1)
			$("#" + this.idBotaoNavegacaoEsquerda).attr("style", "display:none");
		else
			$("#" + this.idBotaoNavegacaoEsquerda).attr("style", "display:block");
		
		if (intUltimoItem >= this.itensTotal)
			$("#" + this.idBotaoNavegacaoDireita).attr("style", "display:none");
		else
			$("#" + this.idBotaoNavegacaoDireita).attr("style", "display:block");
	}
	
	CarroselProdutos.prototype.NextItens = function(intItenInicial, intQtdItensMostrar)
	{
		var htmlOnLoad = "";
		var thisCarrosel;
		
		this.bolProsseguir = false;
		this.htmlOriginal = $("#" + this.idUlToInner).html();
		
		for (i = 0; i < intQtdItensMostrar; i++)
		{
			htmlOnLoad = htmlOnLoad + "<li class=\"vitrine_similares\"><img src=\"/imagens/layout2008/carregando_3.gif\" title=\"aguarde, carregando produtos...\"/><br /><br /><span class=\"produtoNome\">aguarde, carregando produto...</span></li>";
		}
		
		$("#" + this.idUlToInner).html(this.htmlOriginal + htmlOnLoad);
		//Obtem objeto para poder utilizar dentro do retorno do ajax (objeto dentro de objeto)
		thisCarrosel = this;
		$.ajax(
		{
			type: "GET",
			url: this.strPaginaAjax,
			data: "rnd=" + Math.floor(Math.random()*252525) + "&strCodigoProduto=" + this.strCodigoProduto + "&itemInicial=" + intItenInicial + "&qtdItens=" + intQtdItensMostrar + "&linha=" + this.strLinha + "&setor=" + this.strSetor,
			success: function(htmlRetorno)
			{
				var tCarrosel = setTimeout(function(){
					$("#" + thisCarrosel.idUlToInner).html(thisCarrosel.htmlOriginal + htmlRetorno);
					thisCarrosel.bolProsseguir = true;
				}, 1000);
			}
		});
	}
	
	CarroselProdutos.prototype.SetaAcoes = function()
	{
		var thisCarrosel = this;
		this.AtivarBotoesNavegacao(this.primeiroItem, this.GetUltimo());
		$("#" + this.idBotaoNavegacaoEsquerda).click(function(){thisCarrosel.MoveEsquerda();});
		$("#" + this.idBotaoNavegacaoDireita).click(function(){thisCarrosel.MoveDireita();});
		$(window).resize(function(){thisCarrosel.AtivarBotoesNavegacao(thisCarrosel.primeiroItem, thisCarrosel.GetUltimo());});
	}
}

// Busca por texto no corpo do script
// Utilizado na /produtos/corpo-detalhe.asp
function findAndReplace(searchText, replacement, searchNode)
{
	if (!searchText || typeof replacement === 'undefined')
	{ 
        // Throw error here if you want... 
        return;
    }
		
	var regex = typeof searchText === 'string' ? 
        new RegExp(searchText, "ig") : searchText, 
        childNodes = (searchNode || document.body).childNodes, 
        cnLength = childNodes.length, 
        excludes = 'html,head,style,title,link,meta,script,object,iframe'; 
    
	while (cnLength--)
	{ 
        var currentNode = childNodes[cnLength];
		
        if (currentNode.nodeType === 1 && 
            (excludes + ',').indexOf(currentNode.nodeName.toLowerCase() + ',') === -1) {
			arguments.callee(searchText, replacement, currentNode);
        } 
        if (currentNode.nodeType !== 3 || !regex.test(currentNode.data) ) {
            continue; 
        } 
        var parent = currentNode.parentNode, 
            frag = (function(){ 
                var html = currentNode.data.replace(regex, replacement), 
                    wrap = document.createElement('div'), 
                    frag = document.createDocumentFragment(); 
                wrap.innerHTML = html; 
                while (wrap.firstChild) { 
                    frag.appendChild(wrap.firstChild); 
                } 
                return frag; 
            })(); 
        parent.insertBefore(frag, currentNode); 
        parent.removeChild(currentNode); 
    } 
} 

//	Ação: Abre HighSlide de acordo com as configurações de formato passadas como parâmetro
//	Exemplo: onclick=" return AbreHs(this, player.video);"
var player = {"video" : 0, "ampliarimagem" : 1, "slideshow" : 2, "podcast" : 3, "detalheProduto" : 4, "servicomontagem" : 5, "indiqueproduto" : 6, "instalacaogratis" : 7, "televendas" : 8};
function AbreHs(objCampo, formatoExibir)
{
	var retorno = false;
	var hrefOriginal = "";
	hs.creditsHref = 'javascript: void(0);';
	hs.marginLeft = 15;
	hs.allowSizeReduction = false;
	
	// Configura componente hs de acordo com o formato
	switch(formatoExibir)
	{
		case player.video:
			hs.height = 450;
			hs.minWidth = 450;
			hs.lang.creditsText = "Aprenda tudo e faça a melhor compra!";
			break;
			
		case player.podcast:
			hs.height = 195;
			hs.minWidth = 490;
			hs.lang.creditsText = "";
			break;
		case player.detalheProduto:
			hs.height = undefined;
			hs.minWidth = 480;
			hs.lang.creditsText = "";
			break;
		case player.ampliarimagem:
			hs.height = 548;
			hs.minWidth = 722;
			hs.lang.creditsText = "<h5 class=\"imagemAmpliadaTit\">Imagem Ampliada</h5>";
			hs.marginLeft = ($(document).width() - hs.minWidth) / 2;
			
			var parametros = $(objCampo).attr("href");
			hrefOriginal = parametros;
			parametros = parametros + "&strUrlImagemAtual=" + $("#imagemPrincipal").attr("src")
			$(objCampo).attr("href", parametros);
			break;
		
		case player.slideshow:
			hs.height = 368;
			hs.minWidth = 440;
			hs.lang.creditsText = "<h5 class=\"slideShowTit\">Slide Show</h5>";
			hs.marginLeft = ($(document).width() - hs.minWidth) / 2;
			break;
			
		case player.servicomontagem:
			hs.height = undefined;
			hs.minWidth = 515;
			hs.lang.creditsText = "<h5 class=\"montagem_gratis_moveis\">Montagem Grátis</h5>";
			break;
			
		case player.indiqueproduto:
			hs.height = undefined;
			hs.minWidth = 570;
			hs.lang.creditsText = "<h6 class=\"header_pop_indicacao\">Indique este produto</h6>";
			break;
			
		case player.instalacaogratis:
			hs.height = undefined;
			hs.minWidth = 515;
			hs.lang.creditsText = "<h5 class=\"instalacao_gratis\">Instalação Grátis</h5>";
			break;
			
		case player.televendas:
			hs.height = undefined;
			hs.minWidth = undefined;
			hs.lang.creditsText = "<h5 class=\"box_televendas\">Televendas</h5>";
			break;
	}
	
	retorno = hs.htmlExpand(objCampo, {objectType: 'iframe'});
	
	if (formatoExibir == player.ampliarimagem)
		$(objCampo).attr("href", hrefOriginal);

	return retorno;
}

//	Ação: Abre HighSlide do Flash (Enviado por Wéverton)

   function AbreHSFlash(urlFlash,w,h,titulo) {
   	hs.allowSizeReduction = false;
   	hs.lang.creditsText = titulo
	hs.height = h;
	hs.minWidth = w;
    hs.htmlExpand (null, {
    objectType: 'iframe',
                  src: urlFlash
      });
   };

//	Ação: Abre HighSlide de acordo com as configurações de formato passadas como parâmetro
//	Exemplo: onclick=" return AbreHsGenerico(this, 100, 100 'titulo');"
function AbreHsGenerico(objCampo, altura, largura, titulo)
{
	hs.creditsHref = 'javascript: void(0);';
	hs.allowSizeReduction = false;
	
	hs.height = altura;
	hs.minWidth = largura;
	hs.lang.creditsText = titulo;
	
	return hs.htmlExpand(objCampo, {objectType: 'iframe'});
}

/* <componente_messagebox> */
function CustomMessageBox()
{
	this.caption = "";
	this.mensagem = "";
	this.tipoIcone = "";
	this.blnTabAtivo = true;
	this.SrcImgOk = "";
	this.SrcImgCancel = "";
	
	document.write ("<div id=\"divMsgBox\" ></div>");
	
	CustomMessageBox.prototype.Close = function()
	{
		$("#divInternoMsgBox").hide();
		$("#divMsgBox").hide().html();
		this.blnTabAtivo = true;
	}
	
	CustomMessageBox.prototype.PressClose = function()
	{
		this.Close();
	}
	
	CustomMessageBox.prototype.PressOk = function()
	{
		this.Close();
	}
	
	CustomMessageBox.prototype.PressCancel = function()
	{
		this.Close();
	}
	
	CustomMessageBox.prototype.Show = function(strCaption, strMensagem, idTipoIcone)
	{
		var htmlToInject;
		this.caption = strCaption;
		this.mensagem = strMensagem;
		this.tipoIcone = idTipoIcone;
		
		if (this.tipoIcone == "")
		{
			htmlToInject = "<div id=\"divInternoMsgBox\" class=\"interno_simple_msgbox\"><div class=\"topo_msgbox\">";
			htmlToInject = htmlToInject + "<a id=\"btnFecharMsgBox\" href=\"javascript:MsgBox.PressClose();\" title=\"fechar esta mensagem\">fechar esta mensagem</a></div>";
			htmlToInject = htmlToInject + "<div class=\"corpo_msgbox\"><div class=\"interno_corpo_msgbox\"><span class=\"caption_msgbox\">";
			htmlToInject = htmlToInject + this.caption;
			htmlToInject = htmlToInject + "</span><span class=\"mensagem_msgbox\">";
			htmlToInject = htmlToInject + this.mensagem;
			htmlToInject = htmlToInject + "</span></div></div><div class=\"rodape_msgbox\"></div></div>";
		}
		else
			if (this.tipoIcone == "alerta")
			{
				htmlToInject = "<div id=\"divInternoMsgBox\" class=\"interno_alert_msgbox\"><div class=\"topo_msgbox\">";
				htmlToInject = htmlToInject + "<a id=\"btnFecharMsgBox\" href=\"javascript:MsgBox.PressClose();\" title=\"fechar esta mensagem\">fechar esta mensagem</a></div>";
				htmlToInject = htmlToInject + "<div class=\"corpo_msgbox\"><div class=\"interno_corpo_msgbox\"><div class=\"bloco_icone\"><span class=\"icone_alerta\">icone_alerta</span></div>";
				htmlToInject = htmlToInject + "<div class=\"bloco_texto\"><span class=\"caption_msgbox\">";
				htmlToInject = htmlToInject + this.caption;
				htmlToInject = htmlToInject + "</span><span class=\"mensagem_msgbox\">";
				htmlToInject = htmlToInject + this.mensagem;
				htmlToInject = htmlToInject + "</span></div><br clear=\"all\"/></div></div><div class=\"rodape_msgbox\"></div></div>";
			}
			else
				if (this.tipoIcone == "pergunta")
				{
					htmlToInject = "<div id=\"divInternoMsgBox\" class=\"interno_question_msgbox\"><div class=\"topo_msgbox\"></div><div class=\"corpo_msgbox\">";
					htmlToInject = htmlToInject + "<div class=\"interno_corpo_msgbox\"><span class=\"mensagem_msgbox\">";
					htmlToInject = htmlToInject + this.mensagem;
					htmlToInject = htmlToInject + "</span>";
					htmlToInject = htmlToInject + "<a id=\"btnYesMsgBox\" href=\"javascript:MsgBox.PressOk();\">";
					htmlToInject = htmlToInject + "<img src=\""  + this.SrcImgOk + "\" />";
					htmlToInject = htmlToInject + "</a>&nbsp;&nbsp;";
					htmlToInject = htmlToInject + "<a id=\"btnNoMsgBox\" href=\"javascript:MsgBox.PressCancel();\">";
					htmlToInject = htmlToInject + "<img src=\""  + this.SrcImgCancel + "\" />";
					htmlToInject = htmlToInject + "</a>";
					htmlToInject = htmlToInject + "</div></div>";
					htmlToInject = htmlToInject + "<div class=\"rodape_msgbox\"></div></div>";
				}
		
		$("#divMsgBox").html(htmlToInject);
		$("#divMsgBox").show();
		$("#divInternoMsgBox").show();

		$("#btnFecharMsgBox").focus();
		
		if (($.browser.msie) && ( $.browser.version <=6 )) {
			$('#divInternoMsgBox').pngFix(); 


		}
		this.blnTabAtivo = false;
	}
}

var MsgBox = new CustomMessageBox();
		
$(document).keydown(function (e)
{	
	if (MsgBox.blnTabAtivo == false)
	{
		if (e.which == 27 || e.which == 13)
		{
			MsgBox.PressClose();
			return false;
		}
		else
		{
			if (MsgBox.tipoIcone = "pergunta")
				$("#btnNoMsgBox").focus();
			else
				$("#btnFecharMsgBox").focus();
			return false;
		}
	}
});
/* </componente_messagebox> */

// Ação: Realiza a busca por lojas físicas do magazine luiza.
// Exemplo: Utilizado no /includes/rodape.asp
function RealizarBuscaLojas(strIdCampo)
{
	if($("#" + strIdCampo).val().trim().length < 2)
	{
		MsgBox.Show("Localize nossas Lojas", "Entre com pelo menos duas letras para continuar!", "alerta");
		$("#strCidade").val("");
		$("#" + strIdCampo).focus();
	}
	else
	{
		$("#strCidade").val($("#" + strIdCampo).val().trim());
		document.frmPesquisaLoja.submit();
	}
}

//Função: ContarCaracteres(idTextArea, qtdMaxCaracteres, spaInjectRestantes)
//Ação:  Conta caracteres em uma textarea a bloquea para que o usuário não entre com um valor superior.
//Exemplo: Utilizado na página /indique/popup_indicacao.asp
function ContarCaracteres(idTextArea, qtdMaxCaracteres, spaInjectRestantes)
{	
	$("#" + spaInjectRestantes).html("" + (qtdMaxCaracteres - $("#" + idTextArea).val().length));
	
	//Verifica se usuário de alguma forma não entrou com a quantidade maior que a possível
	$("#" + idTextArea).blur(function(){
		$("#" + idTextArea).val($("#" + idTextArea).val().substr(0, qtdMaxCaracteres));
		$("#" + spaInjectRestantes).html("" + (qtdMaxCaracteres - $("#" + idTextArea).val().length));
	});

	$("#" + idTextArea).keyup(function(e){
		if ($("#" + idTextArea).val().length >= qtdMaxCaracteres)
		{
			var tecla = e.which;
			if (!(tecla == '\t' || tecla == 8 || tecla == 9 || tecla == 46 || (tecla >= 37 && tecla <= 40)))
				$("#" + idTextArea).val($("#" + idTextArea).val().substr(0, qtdMaxCaracteres));
		}
		$("#" + spaInjectRestantes).html("" + (qtdMaxCaracteres - $("#" + idTextArea).val().length));
	});
	
	$("#" + idTextArea).keydown(function(e){
		var tecla = e.which;
		$("#" + spaInjectRestantes).html("" + (qtdMaxCaracteres - $("#" + idTextArea).val().length));
		
		if ($("#" + idTextArea).val().length < qtdMaxCaracteres)
			return true;
		else
		{
			//Resumo das teclas= 8: backspace | 9:tab | 46: Del | 37 a 40: setas de navegação
			if (tecla == '\t' || tecla == 8 || tecla == 9 || tecla == 46 || (tecla >= 37 && tecla <= 40))
				return true;
			else
				return false;
		}
	});
}


/*******************
* Método: tooltips
* Finalidade: substitui o "title" dos elementos com informação complementar
*********************/
function applyToolTip()
{
	$(function() {
	$('.glossario').tooltip({
		track: true,
		delay: 0,
		showURL: false,
		showBody: " - ",
		extraClass: "glossario",
		fixPNG: true,
		top: 5,
		left: 0
	});
	});	
}
