var isFirefox = false;
var isIE7 = false;
var nomeImgSponsor = [	'banner_homesite_gde.gif', 
			'banner_cria1_gde.gif',
			'banner_homesite_gde.gif', 
			'banner_npracewear.gif'
			];

var linkImgSponsor = [	'http://www.homehost.com.br', 
			'http://www.cria1.com.br',
			'http://www.homehost.com.br', 
			'http://www.npracewear.com.br'
			];

if (window.navigator.appName == 'Netscape') isFirefox = true;

if (!isFirefox){
	var navVersion = navigator.appVersion;
	if (navVersion.indexOf("MSIE 7.") >= 0) isIE7 = true;
}

function getRace(parameter){
	var pos = parameter.indexOf("_");
	if (pos < 0) return -1;
	var raceNum = parameter.substring(pos + 1, parameter.length);
	return (eval(raceNum) - 1);
}

function getParameter(){
	var urlCall = window.location.search;
	
	if (urlCall == null || urlCall == "") return null
	var parameter = urlCall.toLowerCase().substring(1, urlCall.length);
	return parameter;
}

function reduceName(completeName){
	//Procuro o espaco
	var pos = completeName.indexOf(" ");
	
	//Depois separa os nomes
	var lastName= completeName.substring(pos + 1, completeName.length);
	var firstLetter = completeName.charAt(0);
	
	return firstLetter + ". " + lastName;
}

function escreveTitulo(str, titulo, cont){
	var strTitulo = '<div id="titulo" align="center">' + titulo + '</div>'

	if (cont == 0){
		document.write(strTitulo);
		if (isFirefox) document.write('<img src="' + str + 'images/divisao3.gif" width=193 height=5>');
	}else{
		document.write('	<h2>' + strTitulo + '</h2>');
	}
		
}

function manageSpan(spanId){
	var objSpan = document.getElementById(spanId);
	if (objSpan != null){
		if (objSpan.style.display == 'none') objSpan.style.display = 'block';
		else objSpan.style.display = 'none'
	}
}

function switchSpan(spanId, status){
	var objSpan = document.getElementById(spanId);
	if (objSpan != null) objSpan.style.display = status;
}

function menuEsquerdoSub(){
	menuEsquerdo("../");
}
function menuEsquerdoManchete(){
	menuEsquerdo("");
}
function menuEsquerdo(str){
	var cont = 0;
	document.write('<div id="lh-col">');
	document.write('');
	document.write('');
	document.write('');	

	escreveTitulo(str, 'Temporada 2010:', cont ++);
	document.write('	<p align="center">');
	document.write('	<div id="item_gde" align="center">');
	document.write('		<a href="' + str + 'temporadas/classificacao.html?2010bg_1">BondGirls 2010.1</a><br>');
	document.write('		<a href="' + str + 'temporadas/classificacao.html?2010bkc">BondKart Classic (BKC)</a><br>');
	document.write('		<a href="' + str + 'temporadas/classificacao.html?2010veloc">Campeonato de Velocidade</a><br>');
	document.write('		<a href="' + str + 'temporadas/calendario.html?2010">Calend&aacute;rio e Resultados</a><br>');/* e Resultados*/
	document.write('		<a href="' + str + 'temporadas/regulamento2010.html">Regulamento</a><br>');
	document.write('		<a href="http://www.bondkart.com/forum" target="_blank">Fórum de Discussões</a><br>');
	document.write('	</div>');
	
	document.write('	</p>');

	if (textoInscricoes != null && textoInscricoes != ""){
		escreveTitulo(str, tituloInscricoes, cont ++);
		document.write('	<p align="justify">');
		var pos = 1;
		while (pos > 0){
			pos = textoInscricoes.indexOf("#");
			if (pos > 0){
				textoInscricoes= textoInscricoes.substring(0, pos) + str + textoInscricoes.substring(pos + 1);
			}
		}

		document.write(textoInscricoes);	
		document.write('	</p>');
	}

	if (niver != null & mostraNiver){
		escreveTitulo(str, niver.titulo, cont ++);
		document.write('	<p align="left">');
		for (kk=0; kk < niver.array.length; kk++){
			document.write(niver.array[kk] + "<br>");
		}
		document.write('	</p>');
	}

	escreveTitulo(str, 'Veja Tamb&eacute;m:', cont ++);
	document.write('	<div id="item_gde" align="center">');
	document.write('		<a href="' + str + 'youtube.html">Nosso Vídeos</a><br>');
	document.write('		<a href="' + str + 'kartodromos/kartodromos.html">Kart&oacute;dromos</a><br>');
	document.write('		<a href="http://www.orkut.com/Community.aspx?cmm=3695763" target="_blank">Comunidade no Orkut</a><br>');
	document.write('		<a href="http://www.orkut.com.br/Main#Profile.aspx?rl=as&uid=11411167187592073646" target="_blank">Perfil no Orkut</a><br>');
	document.write('		<a href="http://twitter.com/bondkart" target="_blank">Siga-nos no Twitter</a><br>');
	document.write('	</div>');

	escreveTitulo(str, 'Outras Temporadas', cont ++);
	document.write('	<div id="item_gde" align="center">');
	document.write('		<a href="' + str + 'temporadas/2009.html">Temporada 2009</a><br>');
	document.write('		<a href="' + str + 'temporadas/2008.html">Temporada 2008</a><br>');
	document.write('		<a href="' + str + 'temporadas/2007.html">Temporada 2007</a><br>');
	document.write('		<a href="' + str + 'temporadas/2006.html">Temporada 2006</a><br>');
	document.write('		<a href="' + str + 'temporadas/2005.html">Temporada 2005</a><br>');
	document.write('	</div>');
	document.write('<br>');
	
	document.write('	</p>');
	document.write('</div>');
	

	
	
}
function menuDireitoSub(){
	menuDireito("../");
}
function menuDireitoManchete(){
	menuDireito("");
}

function mostraTops(str, tituloAnual, cont, classificacao, pontos, link){
	escreveTitulo(str, tituloAnual, cont++);
	document.write('	<p align="center">');
	document.write('		<table border=0 align="center">');
	
	for (i = 0; i < classificacao.length; i ++){
		var nome = classificacao[i];
		if (!isFirefox && nome.length > 16) nome = reduceName(nome);
		document.write('			<tr><td>' + (i + 1) + '&deg;-</td><td align="left">' + nome + '</td><td>' + pontos[i] + ' pts </tr>');
	}
	document.write('		</table>');
	if (link != "")  document.write('		<p align="center"><a href="' + str + 'temporadas/classificacao.html?' + link + '">Ver Classifica&ccedil;&atilde;o Completa</a></p>');
	document.write('	</p>');

}

function menuDireito(str){
	document.write('<div id="rh-col">');
	var cont = 0;

	//escreveTitulo(str, 'Procura-se Patrocinadores', cont++);
	escreveTitulo(str, 'Apoio:', cont++);
	document.write('	<p align="center" class="size11">');
	document.write('		<span id="sponsors"></span>');
	//document.write('<br><br>');
	//document.write(' <strong>Deseja patrocionar o BondKart em 2010 e ter sua marca exposta no nosso site, em nossas camisetas e nossos eventos? É só entrar em contato através do e-mail: contato@bondkart.com</strong>');
	//document.write('<br><br>');
	document.write('	</p>');
	
	if (mostraProx){
		escreveTitulo(str, strProxEtapa, cont++);
		document.write('	<p align="center"><strong>' + proxStatus + '</strong></p>');
		document.write('	<p align="left">');
		document.write('		<strong>Data:</strong> ' + proxData + '<br />');
		document.write('		<strong>Local:</strong> ' + kartCompleto[proxEtapa] + '<br />');
		if (proxHorario != "") document.write('		<strong>Hor&aacute;rio:</strong> ' + proxHorario);
		if (obsProxEtapa != ""){
			pos = 1;
			while (pos > 0){
				pos = obsProxEtapa.indexOf("#");
				if (pos > 0){
					obsProxEtapa  = obsProxEtapa.substring(0, pos) + str + obsProxEtapa.substring(pos + 1);
				}
			}
			document.write('<p align="center">' + obsProxEtapa + '</p>');
		}else if (link[proxEtapa] != null && link[proxEtapa] != ''){
			document.write('		<p align="center"><a href="' + str + 'kartodromos/' + link[proxEtapa] + '.html">Como chegar</a></p>');
		}
		document.write('	</p>');
	}

	if (mostraUlt || mostraUlt3){
		escreveTitulo(str, '&Uacute;ltimo Resultado', cont++);
		document.write ('<img src="' +  str + 'images/pixel_menu.bmp"><br>');
		document.write('	<div id="item_peq" align="center">');
		document.write('		<strong>Local:</strong> ' + kartCompleto[ultLocal] + '<br />');
		document.write('		<strong>Data:</strong> ' + ultData + '<br />');
		document.write ('<img src="' +  str + 'images/pixel_menu.bmp"><br>');
	}
		
	if (mostraUlt){
	    var arrayBats = null;
		if (nomesBat == null || nomesBat.length == 0) arrayBats = ["Bateria E", "Bateria D", "Bateria C", "Bateria B", "Bateria A"]; //Bat.Principal
		else arrayBats = nomesBat;
		 
		mostraUlt3 = false;
		var srtLinkUltRes = "";var nomeImgSponsor = [	'banner_homesite_gde.gif', 
			'banner_cria1_gde.gif',
			'banner_homesite_gde.gif', 
			'banner_npracewear.gif'
			];

		var beginIdx = arrayBats.length - vencedores.length;
		document.write('<strong>Vencedor');
		if (vencedores.length > 1) document.write('es');
		document.write('</strong><br>');
		document.write('<table>');
		for (i = 0; i < vencedores.length; i ++){
		
			srtLinkUltRes = '<td align="right"><strong>'; //Dupla Campeã
			srtLinkUltRes += arrayBats[beginIdx++];
			document.write(srtLinkUltRes);
			
						
			document.write(':</strong></td>');
			document.write('<td align="left">' + vencedores[i] + '</td>');
			document.write('</tr>');
		}
		document.write('</table>');
		document.write ('<img src="' +  str + 'images/pixel_menu.bmp"><br>');
		if (link_ultRes != "") document.write ('<a href="' + str + 'etapas/etapa.html?' + link_ultRes + '">Clique aqui para mais detalhes</a>');
	}
	
	if (mostraUlt3){
		var segundo = podium[1];
		if (segundo.length > 12) segundo = reduceName(segundo);
		var terceiro = podium[2];
		if (terceiro.length > 13) terceiro = reduceName(podium[2]);
		
		document.write('<strong>Pódio:</strong>');
		document.write('<table>');
		document.write('<tr align=center><td colspan=2><strong>1&deg;</strong> ' + podium[0] + '</td></tr>');
		document.write('<tr><td><strong>2&deg;</strong> ' + segundo + '</td><td><strong>3&deg;</strong> ' + terceiro + '</td></tr>');
		document.write('</table>');
		document.write ('<img src="' +  str + 'images/pixel_menu.bmp"><br>');
		if (link_ultRes != "") document.write ('<a href="' + str + 'etapas/etapa.html?' + link_ultRes + '">Clique aqui para ver o resultado</a>');
	}

	if (mostraUlt || mostraUlt3){
		document.write('	</div>');
	}

	if (noticias != null && noticias.length > 0){ 
		for (nn=0; nn < noticias.length; nn ++){
			if (noticias[nn].mostrar){
				escreveTitulo(str, noticias[nn].titulo, cont++);
				document.write('	<p align="left">');
				var pos = 1;
				var txtNoticias = "";
				for (i=0; i < noticias[nn].arrayNoticias.length;i++){
					txtNoticias = noticias[nn].arrayNoticias[i];
					pos = 1;
					while (pos > 0){
						pos = txtNoticias.indexOf("#");
						if (pos > 0){
							txtNoticias  = txtNoticias.substring(0, pos) + str + txtNoticias.substring(pos + 1);
						}
					}
					document.write (txtNoticias + '<br>');
				}	
				document.write('	</p>');
			}//if mostrar
		}//for
	
	}//noticias
	
	for (o = 0; o < ordemVisualizacao.length; o ++){
		classTop = ordemVisualizacao[o];
		if (classTop.mostrar) mostraTops(str, classTop.titulo, cont, classTop.classificacao, classTop.pontos, classTop.link);
		if (o == ordemVisualizacao.length - 1) document.write("<br>");
	}//for
	
	document.write('</div>');

	js_clock(str)
}

function headerSub(){
	headerGenerico("../");
}

function header(){
	headerGenerico("");
}

function headerGenerico(str){

	document.write('	<div id="top-left">');
	document.write('		<a href="http://www.bondkart.com/bondkart.html"><img border=0 src="' + str + 'images/logo_bondkart_transp.gif" alt=""></a>');
	document.write('	</div>');

	document.write('<div id="hdr">');
	document.write('	<span>');
	document.write('	<a href="' + str + 'bondkart.html">P&aacute;gina Principal</a> | ');
	document.write('	<a href="' + str + 'quem_somos.html">Quem Somos</a> | ');
	document.write('	<a href="' + str + 'patrocinadores.html">Patrocinadores</a> | ');
	//document.write('	<a href="' + str + 'compre_corra.html">Compre e Corra</a> | ');
	document.write('	<a href="' + str + 'faq.html">Dúvidas</a> | ');
	document.write('	<a href="' + str + 'contato.php">Contato</a>');
	//Lendo imagens
	for (i = 0; i < nomeImgSponsor.length; i ++){
		document.write('<img border=0 height="0" width="0" src="' + str + 'images/' + nomeImgSponsor[i] + '">');
	}
	document.write('	</span>');
	document.write('</div>');

}

function anuncioTopo(){
	document.write('<p class="anuncios">');	
	document.write('<a href="http://www.homehost.com.br" target="_blank"><img src="http://www.bondkart.com/images/banner_homehost.gif" border=0></a>');
	document.write('</p>');
}

function footerNoAds(){
	bannerDisplay(true, true);
}

function footer(){
	bannerDisplay(true, true);
}

function showBuyRunAdd(){
	/*
	var orderNum = Math.floor(Math.random()*100);
	var iframeName = "";
	if (orderNum < 20) iframeName = "suba";
	else if (orderNum < 40) iframeName = "suba2";
	else if (orderNum < 70) iframeName = "lasa";
	else iframeName = "toymania";
	document.write('<iframe name="afiliado" src="http://www.bondkart.com/bondfaro/iframe_' + iframeName + '.html" frameborder=0 width=500 height=70 scrolling=no allowtransparency=true></iframe>');
	*/
	document.write('<iframe name="afiliado" src="http://www.bondkart.com/bondfaro/iframe.html" frameborder=0 width=500 height=70 scrolling=no allowtransparency=true></iframe>');
	document.write('<br>');
}

function bannerDisplay(showAd, showRes){
	document.write('<div id="ftr" align="center"><p class="fotos">');
	if (showAd) showBuyRunAdd();
	document.write('<br>');
	if (showRes){
		document.write('Resolu&ccedil;&atilde;o Recomendada: 1024x768. Navegador: Firefox<br>');
		document.write('@2005-2009 BondKart. Todos os direitos reservados');
	}
	document.write('</p><br></div>');
}


function js_clock(str){
	var clock_time = new Date();
	var sec = clock_time.getSeconds();
	
	var interval = 4;
	var totalPics = nomeImgSponsor.length;
	
	var clock_div = document.getElementById('sponsors');
	var index = (Math.round(sec / interval) % totalPics)
	
	clock_div.innerHTML =  '<a href="' + linkImgSponsor[index] + '" target="_blank"><img border=0 src="' + str + 'images/' + nomeImgSponsor[index] + '"></a>';
	setTimeout("js_clock('" + str + "')", 1000);
}

