var dirAtual = 0;
var Timer;
var velocidade = 5;
var distancia = 150;
var n = 0;

bolEsquerda = true;

function Navega(url)
{	
	if (bolEsquerda)
	{
		AbrirPagina(url,'esquerda','GET',null,2);
		Esquerda();
		bolEsquerda = false;
	}
	else
	{
		AbrirPagina(url,'direita','GET',null,2);
		Direita();
		bolEsquerda = true;
	}
}

function GoogleTrack(aux)
{
	try
	{
		pageTracker._trackPageview(aux);
	}
	catch(e){}	
}

function Home()
{
	Navega('/inc/home.asp');
	GoogleTrack('/home');
}

function Responsa()
{
	Navega('/inc/responsa.asp');
	GoogleTrack('/responsa');
}

function Trabalhe()
{
	Navega('/inc/trabalhe.asp');
	GoogleTrack('/trabalhe');
}

function Agenda()
{
	Navega('/inc/agenda.asp');
	GoogleTrack('/agenda');
}

function Historico()
{
	Navega('/inc/historico.asp');
}

function Localizacao()
{
	Navega('/inc/localizacao.asp');
	GoogleTrack('/localizacao');
}
function Promocoes()
{
	Navega('/inc/promocoes.asp');		
	GoogleTrack('/promocoes');
}
function Promo(str)
{
	document.getElementById('miolo').style.display = 'none';
	document.getElementById('divPromoHome').style.display = '';
	AbrirPagina('/promo.asp','divPromoHome','POST','str='+str,1);
	//f = window.open('/promo.asp?str='+str);
	//f.focus();
}
function FecharPromo()
{
	document.getElementById('divPromoHome').innerHTML = '';
	document.getElementById('divPromoHome').style.display = 'none';
	document.getElementById('miolo').style.display = '';
}
function EscreveFlash(path,div,w,h)
{
	str =  '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="'+w+'" height="'+h+'">';
	str += '<param name="movie" value="'+path+'" />';
	str += '<param name="quality" value="high" />';
	str += '<embed src="'+path+'" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="'+w+'" height="'+h+'"></embed>';
	str += '</object>';
	document.getElementById(div).innerHTML = str;
}
function Contato()
{
	Navega('/inc/contato.asp');
	GoogleTrack('/contato');
}
function Lojas()
{	
	Navega('/inc/lojas.asp');	
	GoogleTrack('/lojas');
}
function Loja(id)
{
	if (id!=0)
	{		
		Navega('/inc/lojaDetalhe.asp?idLoja='+id);
		GoogleTrack('/lojas/'+id);
	}
}
function LojaNaoDetalhe(id)
{
	if (id!=0)
	{		
		AbrirPagina('/inc/lojaNao.asp?idLoja='+id,'divLojaNao','GET',null,1);						
	}
	else
	{
		document.getElementById('divLojaNao').innerHTML = '';
	}
}
function LojaHome(id,div)
{
	if (id!=0)
	{		
		AbrirPagina('/inc/boxLojaHome.asp?idLoja='+id,div,'GET',null,1);						
	}
	else
	{
		document.getElementById(div).innerHTML = '';
	}
}

function LojaMarca(id)
{
	if (id!=0)
	{		
		Navega('/inc/lojaMarca.asp?idMarca='+id);
		GoogleTrack('/lojas/marcas/'+id);
	}	
}

function Dicas()
{
	Navega('/inc/noticias.asp');	
	GoogleTrack('/noticia/');
}
function Noticia(id)
{	
	Navega('/inc/noticiaDetalhe.asp?idNoticia='+id);
	GoogleTrack('/noticia/'+id);
}


//NAVEGACAO AUTOMATICA
function VaiDireita()
{	
	oMiolo.scrollLeft  = oMiolo.scrollWidth;
}

function GetPosicao()
{
	return document.getElementById("miolo").scrollLeft;
}

function GetPosicaoMaxima()
{
	return document.getElementById("miolo").scrollWidth - 952;
}

function Esquerda()
{
	posicaoAtual = GetPosicao();
	posicaoMaxima = GetPosicaoMaxima();
	//alert('Esquerda\n\n'+posicaoAtual+'\n'+posicaoMaxima);
	if (posicaoAtual>0)
	{
		document.getElementById("miolo").scrollLeft -= distancia;
		Timer = window.setTimeout("Esquerda()",velocidade);
	}
	else
	{		
		Para();
		document.getElementById("direita").innerHTML = '';
	}
}

function Direita()
{	
	posicaoAtual = GetPosicao();
	posicaoMaxima = GetPosicaoMaxima();
	//alert('Direita\n\n'+posicaoAtual+'\n'+posicaoMaxima);
	if (posicaoAtual<posicaoMaxima)
	{
		document.getElementById("miolo").scrollLeft += distancia;
		Timer = window.setTimeout("Direita()",velocidade);
	}
	else
	{		
		Para();
		document.getElementById("esquerda").innerHTML = '';
	}
}

function Para()
{
	clearInterval(Timer);
}

function Zera()
{	
	document.getElementById("miolo").scrollLeft = 0;	
}

function PopupNewsletter()
{	
	c = window.open ("/inc/newsletter.asp","newsletter","width=300,height=500");
	c.focus();
}

function EnviarContato()
{
	if (checaEnvioContato())
	{
		par = GetDadosForm('fContato');
		AbrirPagina('/inc/contatoEnviar.asp','divContato','POST',par,1);
	}
}

function checaEnvioContato()
{	
	if (document.fContato.nome.value=='')
	{
		alert("preencha o nome");
		document.fContato.nome.focus();
		return false;
	}
	if (document.fContato.email.value=='')
	{
		alert("preencha o email");
		document.fContato.email.focus();
		return false;
	}
	if (document.fContato.assunto.value=='')
	{
		alert("preencha o assunto");
		document.fContato.assunto.focus();
		return false;
	}
	if (document.fContato.mensagem.value=='')
	{
		alert("preencha a mensagem");
		document.fContato.mensagem.focus();
		return false;
	}
	return true;
}	
