var pagina_inicial = false;

function popups(nome, posX, posY, dia_expira, mes_expira, ano_expira, pg_inicial)
{
	this.nome  = nome;
	this.posX  = posX;
	this.posY  = posY;
	this.ativo = true;
	this.pg_inicial = pg_inicial;

	var ns = navigator.appName == "Netscape";
	ano_aux = 0;
	if (ns)
		ano_aux = 1900;

	hoje = new Date();
	dia  = hoje.getDate();
	mes  = hoje.getMonth()+1;
	ano  = hoje.getYear() + ano_aux;
	
	if (((dia_expira == 0 || mes_expira == 0 || ano_expira == 0) && (pg_inicial == pagina_inicial)) || pg_inicial == null)
		 this.ativo = true;
	else
	{
		if (new Date(ano, mes, dia) >= new Date(ano_expira, mes_expira, dia_expira))
			this.ativo = false;
		else
		{
			if ((pg_inicial == pagina_inicial) || (pg_inicial == null))
				this.ativo = true;
			else
				this.ativo = false;
		}
	}
}	

function getObject(nome_popup)
{
	var ns = navigator.appName == "Netscape";
	var ns4 = (ns && parseInt(navigator.appVersion) == 4);
	var ns5 = (ns && parseInt(navigator.appVersion) > 4); 

	if (ns4)
	   tDiv = document[nome_popup];
	else if (ns5)
	   tDiv = document.getElementById(nome_popup)
	else
	  tDiv = document.all[nome_popup];
	  
	return tDiv;
}

function atualizarPosicaoPopups(arr)
{
	
	for (i=0;i<arr.length;i++)
	{
		if (arr[i].ativo)
		{
			MostrarDIV(getObject(arr[i].nome));
			atualizarPosicaoPopup(arr[i].nome, arr[i].posX, arr[i].posY);
		}
		else
			esconder(arr[i].nome);
	}

}

function atualizarPosicaoPopup(nome_popup, posX, posY)
{
	tDiv = getObject(nome_popup);	  
	tDiv.style.top = posY;
	largura = document.body.offsetWidth;

	if (largura < 780)
		pedaco = 0;
	else
		pedaco = (largura-780)/2;
	
	tDiv.style.left = pedaco + posX;
}

function irParaAncora(nome_da_ancora)
{
	document.location = document.location + '#' + nome_da_ancora;
}

function MostrarDIV(layer)
{
	layer.style.visibility = 'visible';
}

function esconder(obj)
{
	obj_aux = getObject(obj);
    obj_aux.style.visibility='hidden';
}

//Função usada para troca automática de imagens
function trocaImg(objetos, tempo, imagens, lnks)
{
	var hoje = new Date();
	var numero_de_imagens = imagens.length;
	var segundos = hoje.getSeconds();
	var ini = segundos % numero_de_imagens;
	
	this.imagens = imagens;
	this.lnks = lnks;
	
	this.animacao = animacao;

	function animacao()
	{
	
		
		if (ini >= numero_de_imagens)
		{
			ini = 0;
		}
		
		objetos[1].src  = imagens[ini];
		objetos[0].href = lnks[ini];
		
		ini++;
		setTimeout(animacao,tempo);
	}
}

//Função que põe cor na TR (linha) dos anúncios
function MouseOver(obj)
{
	obj.style.background = "#FDFBD0";
	obj.style.cursor = "hand";
	obj.style.color = "#FF0000";
}

//Função que retira a cor da TR (linha) dos anúncios
function MouseOut(obj)
{
	obj.style.background = "#FFFFFF";	
	obj.style.color = "#000000";
}

//Função que passa as imagens do anúncio caso tenha mais de uma imagem
function trocaImgAnuncio(obj, imagem)
{	
	bloqueado = true;
	obj.src=imagem;
}

i = 0;
bloqueado = false;
function mudar_imagens()
{
	if (i >= arr_imagens.length)
	{
		i = 0;
	}
	
	Form1.ListaGeralAnunciosAtivos1_ExibicaoAnuncio1_imgVeiculo.src = arr_imagens[i];
	
	if (!bloqueado)
	{
		i++;
		setTimeout("mudar_imagens()", 10500);
	}
}

function MostrarDescricaoCarro(obj, altura, carro, modelo, motor, ano, cor, combustivel, opcionais, obs, valor, img)
{
	var espacamentoY  = (window.event.clientY + document.body.scrollTop) - 80;
	var espacamentoX  = window.event.clientX + 100;

	window.document.all['cursor'].style.top        = espacamentoY;
	window.document.all['cursor'].style.left       = espacamentoX;
	window.document.all['cursor'].style.visibility = "visible";
	window.document.all['cursor'].innerHTML=MontarHTMLVeiculo(carro, modelo, motor, ano, cor, combustivel, opcionais, obs, valor, img);
}

function MontarHTMLVeiculo(carro, modelo, motor, ano, cor, combustivel, opcionais, obs, valor, img){
	var htm;

	htm = "<table width=\"250\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" bgcolor=\"#993300\">";
	htm+= "<tr><td>";
	htm+= "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"2\" bgcolor=\"#FFFFCC\" class=\"Verdana t10px\">";
	htm+= "<tr><td colspan=\"2\" bgcolor=\"#F7D9A0\" align=\"center\" class=\"Verdana t12px Negrito\">" + carro + " " + modelo + " " + motor + "</td></tr>";
	htm+= "<tr align=\"center\"><td width=\"100\" valign=\"top\">";
	htm+= "<img src=\"" + img + "\" width=\"100\" height=\"75\"></td>";
	htm+= "<td class=\"Verdana\"><table class=\"Verdana t10px\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">";
	htm+= "<tr><td><strong>Ano:</strong></td><td>" + ano + "</td></tr>";
	htm+= "<tr><td><strong>Cor:</strong></td><td>" + cor + "</td></tr>";
	htm+= "<tr><td><strong>Comb:</strong></td><td>" + combustivel + "</td></tr>";
	htm+= "<tr><td><strong>Obs:</strong></td><td>" + obs + "</td></tr>";
	htm+= "</table></td>";
	htm+= "<tr><td valign=\"top\">" + opcionais + "</td>";
	htm+= "</tr><tr><td class=\"Verdana t14px Vermelho2 negrito\">Valor:</td>";
	htm+= "<td class=\"Verdana t14px Vermelho2 Negrito\"> " + valor.replace('R$ 0,00','R$ A combinar') + "</td>";
	htm+= "</tr></table></td></tr></table>";
	
	return htm;
}

function EsconderDescricaoCarro()
{
	window.document.all['cursor'].style.visibility="hidden";
}