var ctxt=((countryPath=='en')?'/olympics':'/olimpiadas');

// TESTE PARA ATLETAS //
if ((url.indexOf("/atletas/") > -1) || (url.indexOf("/playersearch/") > -1)) {

	if (url.indexOf("/playersearch/") > -1){
		if ( url.indexOf("%5B") > -1 ){
			countryPath = url.substring( url.indexOf("%5B") + 3 , url.indexOf("%5D") );	
		}else{
			countryPath = url.substring( url.indexOf("[") + 1 , url.indexOf("]") );
		}
	}
	
	var atletas = $('span.spn-athletesname a');
	for( var i = 0; i < atletas.length; i++ ){
		atletas[i].href = atletas[i].href.replace("/br/","/");
		atletas[i].href = atletas[i].href.replace("/en/","/");
		atletas[i].href = atletas[i].href.replace("/<DESTINATION>/","/");
		atletas[i].href = atletas[i].href.replace("/%3CDESTINATION%3E/","/");
	}


	var link_res = $('a.link_res');
	for( var i = 0; i < link_res.length; i++ ){
		link_res[i].href = link_res[i].href.replace("countryPath",countryPath);
	}

    document.frm.action = urlFastCgi;

	if (url.indexOf("sportscoverage.terra") > -1) {
	    document.frm.country.value = "en";
	}else{
	    document.frm.country.value = country;
	}
    document.frm.countryPath.value = "[" + countryPath.toUpperCase() + "]";

	// fan zone
	$("#url_fanzone").attr('href', urlFanZone );

	var extra = $('div.ctn-athletesfanzone a').get(1);
	if (extra!=null){extra.href = extra.href.replace("http://url",urlFanZone);}
}

// TESTE PARA AGENDA //
if (url.indexOf("/agenda/") > -1) {
	var hours = $('div.ctn-scheduledate p');
	for (var i = 0; i < hours.length; i++) {
		hours[i].innerHTML = countryCapitalName;
	}
	var days = $('div.ctn-tabcontent a');
	for( var i = 0; i < days.length; i++ ){
		if ( days[i].id == 'day' ) {
			days[i].href = days[i].href.replace("countryPath",countryPath);
			days[i].href = days[i].href.replace("countryCode",countryCode);
		}
	}
	
	var resultados = $('td.col-schedulecol2 a');
	for (var i = 0; i < resultados.length; i++) {
		if (resultados[i].id == 'resultado'){			
			resultados[i].href = resultados[i].href.replace("countryPath",countryPath);
		}
	}
	if (country != 'br') {
		$('a.int_daynav24').attr('rel', 'ctn-layer-fim|-130,68');
	}
}

$(document).ready(function() {
	// Links
	if (countryPath=='en') {
		$('a[href]').each(function() {
			var a=$(this);
			if (a.attr('href').indexOf('/olimpiadas/2008') > -1) {
				a.attr('href', a.attr('href').replace('/olimpiadas/2008', ctxt+'/2008'));
			}
		});
	}
});

$('#ifr-footer').attr('height', '50px');
if (country=='br') {
	$('#ifr-footer').attr('src', 'http://www.terra.com.br/rodape/rodape-beijing.htm');
} else if (country=='us' && countryPath=="en") {
	$('#ifr-footer').attr('src', 'http://www.us.terra.com/include/olympics2008/rodape.htm');
} else {
	$('#ifr-footer').attr('src', 'http://www.'+country+'.terra.com/include/pekin20082/rodape.htm');
}

function getRequestAJAX() {
	if ( window.XMLHttpRequest )
		return new XMLHttpRequest();
	else if ( window.ActiveXObject )
		return new ActiveXObject( "Microsoft.XMLHTTP" );
	else {
		//alert( "ERROR" );
		return null;
	}
}

function comboPaisAgenda(data){
	var url = ctxt+"/2008/includes/filtro_agenda_xml.xml";
	var ajax = getRequestAJAX();

	var COUNTRIES;
	var COUNTRY

	var id;
	var value;

	var total = 0;

	// REMOVE PRIMEIRO ITEM, TITULO
	var cmb_country = $('div.ctn-listvalues ul').get(0);
	cmb_country.removeChild( cmb_country.childNodes[0] );
	
	if ( ajax != null ) {
		ajax.open( "GET", url, false );
		ajax.send( null );
		if ( ajax.readyState == 4 ) {
			if ( ajax.status == 200 ) {
				var regs = ajax.responseXML.documentElement.childNodes;
				for ( var i = 0; i < regs.length; i++ ){
					if ( regs[i].nodeName == 'COUNTRIES' ){
						COUNTRIES = regs[i].childNodes;
						for ( var j = 0; j < COUNTRIES.length; j++ ){
							if ( COUNTRIES[j].nodeName == 'COUNTRY' ){
								COUNTRY= COUNTRIES[j].childNodes;
								li = document.createElement("LI");
								for ( var k = 0; k < COUNTRY.length; k++ ){
									if ( COUNTRY[k].nodeName == 'COUNTRY_CODE' )
										id = COUNTRY[k].firstChild.nodeValue;
									if ( COUNTRY[k].nodeName == 'COUNTRY_NAME' )
										value = COUNTRY[k].firstChild.nodeValue;
								}
								li.innerHTML = "<a href='"+ctxt+"/2008/agenda/pais/"+id+"/calendario_"+data+".html'>"+value+"</a>";
								cmb_country.appendChild(li);
								total++;
							}
						}
					}
				}
			} else {
				//alert( "Error ("+ajax.status+")." );					
			}
		}
	}

	var scroll = $('div.ctn-scrollbar').get(0);
	if ( total < 10 ){		
		scroll.style.display = "none";
	}else{
		scroll.style.display = "block";
	}
	
}

function comboEsporteAgenda(){
	var url = ctxt+"/2008/includes/filtro_agenda_xml.xml";
	var ajax = getRequestAJAX();

	var SPORT_CATEGORIES;
	var SPORT_CATEGORY;

	var id;
	var value;

	var total = 0;

	var cmb_sport = $('div.ctn-listvalues ul').get(0);

	// LIMPA LISTA DE UL E LI
	var listLi = cmb_sport.childNodes;
	for(var i = listLi.length - 1; i >= 0; i-- ) {
		if( listLi[i].tagName == 'LI' ) {
	     		cmb_sport.removeChild( listLi[i] );
		}	
  	}
	
	if ( ajax != null ) {
		ajax.open( "GET", url, false );
		ajax.send( null );
		if ( ajax.readyState == 4 ) {
			if ( ajax.status == 200 ) {
				var regs = ajax.responseXML.documentElement.childNodes;
				for ( var i = 0; i < regs.length; i++ ){
					if ( regs[i].nodeName == 'SPORT_CATEGORIES' ){
						SPORT_CATEGORIES= regs[i].childNodes;
						for ( var j = 0; j < SPORT_CATEGORIES.length; j++ ){
							if ( SPORT_CATEGORIES[j].nodeName == 'SPORT_CATEGORY' ){
								SPORT_CATEGORY= SPORT_CATEGORIES[j].childNodes;
								li = document.createElement("LI");
								for ( var k = 0; k < SPORT_CATEGORY.length; k++ ){
									if ( SPORT_CATEGORY[k].nodeName == 'ID_SPORT' )
										id = SPORT_CATEGORY[k].firstChild.nodeValue;
									if ( SPORT_CATEGORY[k].nodeName == 'NAME' )
										value = SPORT_CATEGORY[k].firstChild.nodeValue;
								}
								li.innerHTML = "<a href='"+ctxt+"/2008/agenda/esporte/"+id+"/"+firstCat[id]+"/calendario.html'>"+value+"</a>";
								cmb_sport.appendChild(li);
								total++;
							}
						}
					}
				}
			} else {
			}
		}
	}

	var scroll = $('div.ctn-scrollbar').get(0);
	if ( total < 10 ){		
		scroll.style.display = "none";
	}else{
		scroll.style.display = "block";
	}

}

function comboCategoriaAgenda(esp_id){
	var url = ctxt+"/2008/agenda/esporte/"+esp_id+"/calendario_xml.xml";
	var ajax = getRequestAJAX();
	var CATEGORIES;
	var CATEGORY;

	var id;
	var value;

	var total = 0;

	var cmb_cat = $('div.ctn-listvalues ul').get(1);

	// LIMPA LISTA DE UL E LI
	var listLi = cmb_cat.childNodes;
	for(var i = listLi.length - 1; i >= 0; i-- ) {
		if( listLi[i].tagName == 'LI' ) {
	    	cmb_cat.removeChild( listLi[i] );
		}	
  	}

	if ( ajax != null ) {
		ajax.open( "GET", url, false );
		ajax.send( null );
		if ( ajax.readyState == 4 ) {
			if ( ajax.status == 200 ) {
				CATEGORIES= ajax.responseXML.documentElement.childNodes;
				for ( var j = 0; j < CATEGORIES.length; j++ ){
					if ( CATEGORIES[j].nodeName == 'CATEGORY' ){
						CATEGORY = CATEGORIES[j].childNodes;
						li = document.createElement("LI");
						for ( var k = 0; k < CATEGORY.length; k++ ){
							if ( CATEGORY[k].nodeName == 'ID_CATEGORY' )
								id = CATEGORY[k].firstChild.nodeValue;
							if ( CATEGORY[k].nodeName == 'CATEGORY_NAME' )
								value = CATEGORY[k].firstChild.nodeValue;
						}
						li.innerHTML = "<a href='"+ctxt+"/2008/agenda/esporte/"+esp_id+"/"+id+"/calendario.html'>"+value+"</a>";
						cmb_cat.appendChild(li);
						total++;
					}
				}
			} else {
				//alert( "Error ("+ajax.status+")." );					
			}
		}
	}

	var scroll = $('div.ctn-scrollbar').get(1);
	if ( total < 10 ){		
		scroll.style.display = "none";
	}else{
		scroll.style.display = "block";
	}

}

function hideComboEsporteAgenda(n){
	var cmb_sport = $('div.ctn-listvalues').get(0);
	var cmb_value = $('div.ctn-combovalue').get(0);
	cmb_value.innerHTML = n;
	cmb_sport.style.display = "none";
}

function comboPaisAtletas(path1,path2){
	var url = ctxt+"/2008/includes/filtro_atletas_xml.xml";
	var ajax = getRequestAJAX();

	var COUNTRIES;
	var COUNTRY;

	var id;
	var value;

	var total = 0;

	// REMOVE PRIMEIRO ITEM, TITULO
	var cmb_country = $('div.ctn-listvalues ul').get(0);
	cmb_country.removeChild( cmb_country.childNodes[0] );
	
	if ( ajax != null ) {
		ajax.open( "GET", url, false );
		ajax.send( null );
		if ( ajax.readyState == 4 ) {
			if ( ajax.status == 200 ) {
				var regs = ajax.responseXML.documentElement.childNodes;
				for ( var i = 0; i < regs.length; i++ ){
					if ( regs[i].nodeName == 'COUNTRIES' ){
						COUNTRIES = regs[i].childNodes;
						for ( var j = 0; j < COUNTRIES.length; j++ ){
							if ( COUNTRIES[j].nodeName == 'COUNTRY' ){
								COUNTRY= COUNTRIES[j].childNodes;
								li = document.createElement("LI");
								for ( var k = 0; k < COUNTRY.length; k++ ){
									if ( COUNTRY[k].nodeName == 'COUNTRY_CODE' )
										id = COUNTRY[k].firstChild.nodeValue;
									if ( COUNTRY[k].nodeName == 'COUNTRY_NAME' )
										value = COUNTRY[k].firstChild.nodeValue;
								}
								li.innerHTML = "<a href='"+ctxt+"/2008/atletas/pais/"+id+"/atletas_A.html'>"+value+"</a>";
								cmb_country.appendChild(li);
								total++;
							}
						}
					}
				}
			} else {
				//alert( "Error ("+ajax.status+")." );					
			}
		}
	}

	var scroll = $('div.ctn-scrollbar').get(0);
	if ( total < 10 ){		
		scroll.style.display = "none";
	}else{
		scroll.style.display = "block";
	}
}

function comboEsportePais(path1,path2){
	var url = ctxt+"/2008/includes/filtro_atletas_xml.xml";

	var ajax = getRequestAJAX();

	var SPORT_CATEGORIES;
	var SPORT_CATEGORY;

	var id;
	var value;

	var total = 0;

	var cmb_sport = $('div.ctn-listvalues ul').get(1);

	// LIMPA LISTA DE UL E LI
	var listLi = cmb_sport.childNodes;
	for(var i = listLi.length - 1; i >= 0; i-- ) {
		if( listLi[i].tagName == 'LI' ) {
	     		cmb_sport.removeChild( listLi[i] );
		}	
  	}
	
	if ( ajax != null ) {
		ajax.open( "GET", url, false );
		ajax.send( null );
		if ( ajax.readyState == 4 ) {
			if ( ajax.status == 200 ) {
				var regs = ajax.responseXML.documentElement.childNodes;
				for ( var i = 0; i < regs.length; i++ ){
					if ( regs[i].nodeName == 'SPORT_CATEGORIES' ){
						SPORT_CATEGORIES= regs[i].childNodes;
						for ( var j = 0; j < SPORT_CATEGORIES.length; j++ ){
							if ( SPORT_CATEGORIES[j].nodeName == 'SPORT_CATEGORY' ){
								SPORT_CATEGORY= SPORT_CATEGORIES[j].childNodes;
								li = document.createElement("LI");
								for ( var k = 0; k < SPORT_CATEGORY.length; k++ ){
									if ( SPORT_CATEGORY[k].nodeName == 'ID_SPORT' )
										id = SPORT_CATEGORY[k].firstChild.nodeValue;
									if ( SPORT_CATEGORY[k].nodeName == 'NAME' )
										value = SPORT_CATEGORY[k].firstChild.nodeValue;
								}
								li.innerHTML = "<a href='"+ctxt+"/2008/atletas/esporte/"+id+"/atletas_A.html'>"+value+"</a>";
								cmb_sport.appendChild(li);
								total++;
							}
						}
					}
				}
			} else {
				//alert( "Error ("+ajax.status+")." );					
			}
		}
	}

	var scroll = $('div.ctn-scrollbar').get(1);
	if ( total < 10 ){		
		scroll.style.display = "none";
	}else{
		scroll.style.display = "block";
	}


}

/* Filtros resultados */
function comboEsporteResultados(date){
	var url = ctxt+"/2008/includes/filtro_resultados_xml.xml";
	var ajax = getRequestAJAX();

	var SPORT_CATEGORIES;
	var SPORT_CATEGORY;

	var id;
	var value;

	var total = 0;

	var cmb_sport = $('div.ctn-listvalues ul').get(0);

	// LIMPA LISTA DE UL E LI
	var listLi = cmb_sport.childNodes;
	for(var i = listLi.length - 1; i >= 0; i-- ) {
		if( listLi[i].tagName == 'LI' ) {
	     		cmb_sport.removeChild( listLi[i] );
		}	
  	}
	
	if ( ajax != null ) {
		ajax.open( "GET", url, false );
		ajax.send( null );
		if ( ajax.readyState == 4 ) {
			if ( ajax.status == 200 ) {
				var regs = ajax.responseXML.documentElement.childNodes;
				for ( var i = 0; i < regs.length; i++ ){
					if ( regs[i].nodeName == 'SPORT_CATEGORIES' ){
						SPORT_CATEGORIES= regs[i].childNodes;
						for ( var j = 0; j < SPORT_CATEGORIES.length; j++ ){
							if ( SPORT_CATEGORIES[j].nodeName == 'SPORT_CATEGORY') {
								SPORT_CATEGORY= SPORT_CATEGORIES[j].childNodes;
								li = document.createElement("LI");
								for (var k=0; k<SPORT_CATEGORY.length; k++) {
									if (SPORT_CATEGORY[k].nodeName=='ID_SPORT' )
										id = SPORT_CATEGORY[k].firstChild.nodeValue;
									if (SPORT_CATEGORY[k].nodeName=='NAME' )
										value=SPORT_CATEGORY[k].firstChild.nodeValue;
								}
								$(li).html("<a href=\""+ctxt+"/2008/resultados/esporte/"+id+"/resultados_"+date+".html\">"+value+"</a>");
								cmb_sport.appendChild(li);
								total++;
							}
						}
					}
				}
			}
		}
	}

	var scroll = $('div.ctn-scrollbar').get(0);
	if (total < 10) {		
		scroll.style.display="none";
	} else {
		scroll.style.display="block";
	}
}

function comboEsporteResultados2(){
	var url = ctxt+"/2008/includes/filtro_resultados_xml.xml";
	var ajax = getRequestAJAX();
	var SPORT_CATEGORIES;
	var SPORT_CATEGORY;
	var id;
	var value;
	var total = 0;
	var cmb_sport = $('div.ctn-listvalues ul').get(0);

	// LIMPA LISTA DE UL E LI
	var listLi = cmb_sport.childNodes;
	for(var i = listLi.length - 1; i >= 0; i-- ) {
		if (listLi[i].tagName=='LI') {
	    	cmb_sport.removeChild( listLi[i] );
		}	
  	}
	
	if (ajax != null) {
		ajax.open("GET", url, false);
		ajax.send(null);
		if (ajax.readyState==4) {
			if (ajax.status==200) {
				var regs = ajax.responseXML.documentElement.childNodes;
				for (var i = 0; i < regs.length; i++ ){
					if (regs[i].nodeName == 'SPORT_CATEGORIES') {
						SPORT_CATEGORIES= regs[i].childNodes;
						for (var j = 0; j < SPORT_CATEGORIES.length; j++) {
							if (SPORT_CATEGORIES[j].nodeName == 'SPORT_CATEGORY') {
								SPORT_CATEGORY= SPORT_CATEGORIES[j].childNodes;
								li = document.createElement("LI");
								for (var k = 0; k < SPORT_CATEGORY.length; k++) {
									if (SPORT_CATEGORY[k].nodeName == 'ID_SPORT')
										id = SPORT_CATEGORY[k].firstChild.nodeValue;
									if (SPORT_CATEGORY[k].nodeName == 'NAME')
										value = SPORT_CATEGORY[k].firstChild.nodeValue;
								}
								li.innerHTML = "<a href='"+ctxt+"/2008/resultados/esporte/"+id+"/resultados_cat"+firstCat[id]+".html'>"+value+"</a>";
								cmb_sport.appendChild(li);
								total++;
							}
						}
					}
				}
			}
		}
	}
	var scroll = $('div.ctn-scrollbar').get(0);
	if ( total < 10 ){		
		scroll.style.display = "none";
	}else{
		scroll.style.display = "block";
	}
}

function comboCategoriaResultados(esp_id){
	var url = ctxt+"/2008/resultados/esporte/"+esp_id+"/categorias_xml.xml";
	var ajax = getRequestAJAX();
	var CATEGORIES;
	var CATEGORY;

	var id;
	var value;

	var total = 0;

	var cmb_cat = $('div.ctn-listvalues ul').get(1);

	// LIMPA LISTA DE UL E LI
	var listLi = cmb_cat.childNodes;
	for(var i = listLi.length - 1; i >= 0; i-- ) {
		if( listLi[i].tagName == 'LI' ) {
	     		cmb_cat.removeChild( listLi[i] );
		}	
  	}

	if ( ajax != null ) {
		ajax.open( "GET", url, false );
		ajax.send( null );
		if ( ajax.readyState == 4 ) {
			if ( ajax.status == 200 ) {
				CATEGORIES= ajax.responseXML.documentElement.childNodes;
				for ( var j = 0; j < CATEGORIES.length; j++ ){
					if ( CATEGORIES[j].nodeName == 'CATEGORY' ){
						CATEGORY = CATEGORIES[j].childNodes;
						li = document.createElement("LI");
						for ( var k = 0; k < CATEGORY.length; k++ ){
							if ( CATEGORY[k].nodeName == 'ID_CATEGORY' )
								id = CATEGORY[k].firstChild.nodeValue;
							if ( CATEGORY[k].nodeName == 'CATEGORY_NAME' )
								value = CATEGORY[k].firstChild.nodeValue;
						}
						li.innerHTML = "<a href='"+ctxt+"/2008/resultados/esporte/"+esp_id+"/resultados_cat"+id+".html'>"+value+"</a>";
						cmb_cat.appendChild(li);
						total++;
					}
				}
			}
		}
	}
	var scroll = $('div.ctn-scrollbar').get(1);
	if ( total < 10 ){		
		scroll.style.display = "none";
	}else{
		scroll.style.display = "block";
	}
}

function hideComboEsporteResultados(n){
	var cmb_sport = $('div.ctn-listvalues').get(0);
	var cmb_value = $('div.ctn-combovalue').get(0);
	$(cmb_value).html(n);
	$(cmb_sport).hide();
}

function comboPaisResultados(){
	var url = ctxt+"/2008/includes/filtro_resultados_xml.xml";
	var ajax = getRequestAJAX();

	var COUNTRIES;
	var COUNTRY;

	var id;
	var value;

	var total = 0;

	// REMOVE PRIMEIRO ITEM, TITULO
	var cmb_country = $('div.ctn-listvalues ul').get(0);
	cmb_country.removeChild( cmb_country.childNodes[0] );
	
	if ( ajax != null ) {
		ajax.open( "GET", url, false );
		ajax.send( null );
		if ( ajax.readyState == 4 ) {
			if ( ajax.status == 200 ) {
				var regs = ajax.responseXML.documentElement.childNodes;
				for ( var i = 0; i < regs.length; i++ ){
					if ( regs[i].nodeName == 'COUNTRIES' ){
						COUNTRIES = regs[i].childNodes;
						for ( var j = 0; j < COUNTRIES.length; j++ ){
							if ( COUNTRIES[j].nodeName == 'COUNTRY' ){
								COUNTRY= COUNTRIES[j].childNodes;
								li = document.createElement("LI");
								for ( var k = 0; k < COUNTRY.length; k++ ){
									if ( COUNTRY[k].nodeName == 'COUNTRY_CODE' )
										id = COUNTRY[k].firstChild.nodeValue;
									if ( COUNTRY[k].nodeName == 'COUNTRY_NAME' )
										value = COUNTRY[k].firstChild.nodeValue;
								}
								li.innerHTML = "<a href=\"javascript:comboEsportesPaisResultados('"+id+"');hideComboEsporteResultados('"+value+"');\">"+value+"</a>";
								cmb_country.appendChild(li);
								total++;
							}
						}
					}
				}
			} else {
				//alert( "Error ("+ajax.status+")." );					
			}
		}
	}

	var scroll = $('div.ctn-scrollbar').get(0);
	if ( total < 10 ){		
		scroll.style.display = "none";
	}else{
		scroll.style.display = "block";
	}

}


function comboPaisResultados2(){
	var url = ctxt+"/2008/includes/filtro_resultados_xml.xml";
	var ajax = getRequestAJAX();

	var COUNTRIES;
	var COUNTRY;

	var id;
	var value;

	var total = 0;

	// REMOVE PRIMEIRO ITEM, TITULO
	var cmb_country = $('div.ctn-listvalues ul').get(0);
	cmb_country.removeChild( cmb_country.childNodes[0] );
	
	if ( ajax != null ) {
		ajax.open( "GET", url, false );
		ajax.send( null );
		if ( ajax.readyState == 4 ) {
			if ( ajax.status == 200 ) {
				var regs = ajax.responseXML.documentElement.childNodes;
				for ( var i = 0; i < regs.length; i++ ){
					if ( regs[i].nodeName == 'COUNTRIES' ){
						COUNTRIES = regs[i].childNodes;
						for ( var j = 0; j < COUNTRIES.length; j++ ){
							if ( COUNTRIES[j].nodeName == 'COUNTRY' ){
								COUNTRY= COUNTRIES[j].childNodes;
								li = document.createElement("LI");
								for ( var k = 0; k < COUNTRY.length; k++ ){
									if ( COUNTRY[k].nodeName == 'COUNTRY_CODE' )
										id = COUNTRY[k].firstChild.nodeValue;
									if ( COUNTRY[k].nodeName == 'COUNTRY_NAME' )
										value = COUNTRY[k].firstChild.nodeValue;
								}								
								li.innerHTML = "<a href='"+ctxt+"/2008/resultados/pais/"+id+"/resultados_1.html'>"+value+"</a>";
								cmb_country.appendChild(li);
								total++;
							}
						}
					}
				}
			} else {
				//alert( "Error ("+ajax.status+")." );					
			}
		}
	}

	var scroll = $('div.ctn-scrollbar').get(0);
	if ( total < 10 ){		
		scroll.style.display = "none";
	}else{
		scroll.style.display = "block";
	}

}

/* Filtros medalhas */
function comboPaisResultadosCapa(){
	var url = ctxt+"/2008/includes/filtro_resultados_xml.xml";
	var ajax = getRequestAJAX();

	var COUNTRIES;
	var COUNTRY;

	var id;
	var value;

	// REMOVE PRIMEIRO ITEM, TITULO
	var cmb_country = $('div.ctn-listvalues ul').get(1);
	//cmb_country.removeChild( cmb_country.childNodes[0] );
	
	if ( ajax != null ) {
		ajax.open( "GET", url, false );
		ajax.send( null );
		if ( ajax.readyState == 4 ) {
			if ( ajax.status == 200 ) {
				var regs = ajax.responseXML.documentElement.childNodes;
				for ( var i = 0; i < regs.length; i++ ){
					if ( regs[i].nodeName == 'COUNTRIES' ){
						COUNTRIES = regs[i].childNodes;
						for ( var j = 0; j < COUNTRIES.length; j++ ){
							if ( COUNTRIES[j].nodeName == 'COUNTRY' ){
								COUNTRY= COUNTRIES[j].childNodes;
								li = document.createElement("LI");
								for ( var k = 0; k < COUNTRY.length; k++ ){
									if ( COUNTRY[k].nodeName == 'COUNTRY_CODE' )
										id = COUNTRY[k].firstChild.nodeValue;
									if ( COUNTRY[k].nodeName == 'COUNTRY_NAME' )
										value = COUNTRY[k].firstChild.nodeValue;
								        }
								li.innerHTML = "<a href='"+ctxt+"/2008/resultados/pais/"+id+"/resultados_1.html'>"+value+"</a>";
								cmb_country.appendChild(li);
							}
						}
					}
				}
			} else {
				//alert( "Error ("+ajax.status+")." );					
			}
		}
	}
}

function comboEsportesPaisResultados(idCountry) {
	var url = ctxt+"/2008/resultados/pais/"+idCountry+"/esportes_xml.xml";
	
	var ajax = getRequestAJAX();
	var CATEGORIES;
	var CATEGORY;

	var id;
	var value;

	var total = 0;

	var cmb_cat = $('div.ctn-listvalues ul').get(1);

	// LIMPA LISTA DE UL E LI
	var listLi = cmb_cat.childNodes;
	for(var i = listLi.length - 1; i >= 0; i-- ) {
		if( listLi[i].tagName == 'LI' ) {
	     		cmb_cat.removeChild( listLi[i] );
		}	
  	}

	if ( ajax != null ) {
		ajax.open( "GET", url, false );
		ajax.send( null );
		if ( ajax.readyState == 4 ) {
			if ( ajax.status == 200 ) {
				CATEGORIES= ajax.responseXML.documentElement.childNodes;
				for ( var j = 0; j < CATEGORIES.length; j++ ){
					if ( CATEGORIES[j].nodeName == 'SPORT' ){
						CATEGORY = CATEGORIES[j].childNodes;
						li = document.createElement("LI");
						for ( var k = 0; k < CATEGORY.length; k++ ){
							if ( CATEGORY[k].nodeName == 'ID_SPORT' )
								id = CATEGORY[k].firstChild.nodeValue;
							if ( CATEGORY[k].nodeName == 'SPORT_NAME' )
								value = CATEGORY[k].firstChild.nodeValue;
						}
						li.innerHTML = "<a href=\""+ctxt+"/2008/resultados/pais/"+idCountry+"/resultados_"+id+".html\">"+value+"</a>";
						cmb_cat.appendChild(li);
						total++;
					}
				}
			} else {
				//alert( "Error ("+ajax.status+")." );					
			}
		}
	}

	var scroll = $('div.ctn-scrollbar').get(1);
	if ( total < 10 ){		
		scroll.style.display = "none";
	}else{
		scroll.style.display = "block";
	}

}

/* Filtros medalhas */
function comboPaisMedalhas(){
	var url = ctxt+"/2008/includes/filtro_medalhas_xml.xml";
	var ajax = getRequestAJAX();

	var COUNTRIES;
	var COUNTRY;

	var id;
	var value;

	var total = 0;

	// REMOVE PRIMEIRO ITEM, TITULO
	var cmb_country = $('div.ctn-listvalues ul').get(0);
	cmb_country.removeChild( cmb_country.childNodes[0] );
	
	if ( ajax != null ) {
		ajax.open( "GET", url, false );
		ajax.send( null );
		if ( ajax.readyState == 4 ) {
			if ( ajax.status == 200 ) {
				var regs = ajax.responseXML.documentElement.childNodes;
				for ( var i = 0; i < regs.length; i++ ){
					if ( regs[i].nodeName == 'COUNTRIES' ){
						COUNTRIES = regs[i].childNodes;
						for ( var j = 0; j < COUNTRIES.length; j++ ){
							if ( COUNTRIES[j].nodeName == 'COUNTRY' ){
								COUNTRY= COUNTRIES[j].childNodes;
								li = document.createElement("LI");
								for ( var k = 0; k < COUNTRY.length; k++ ){
									if ( COUNTRY[k].nodeName == 'COUNTRY_CODE' )
										id = COUNTRY[k].firstChild.nodeValue;
									if ( COUNTRY[k].nodeName == 'COUNTRY_NAME' )
										value = COUNTRY[k].firstChild.nodeValue;
								        }
								li.innerHTML = "<a href='"+ctxt+"/2008/medalhas/"+id+"/medalheiro_1.html'>"+value+"</a>";
								cmb_country.appendChild(li);
								total++;
							}
						}
					}
				}
			} else {
				//alert( "Error ("+ajax.status+")." );					
			}
		}
	}

	var scroll = $('div.ctn-scrollbar').get(0);
	if ( total < 10 ){		
		scroll.style.display = "none";
	}else{
		scroll.style.display = "block";
	}

}

function clearText(){
	document.frm.query.value = "";
}

function buscaAtleta(url_agenda){

	var atletas = $('span.spn-athletesname a');
	for( var i = 0; i < atletas.length; i++ ){	

		atletas[i].id = atletas[i].id.replace("/br/","/");
		atletas[i].id = atletas[i].id.replace("/en/","/");
		atletas[i].id = atletas[i].id.replace("/<DESTINATION>/","/");
		atletas[i].id = atletas[i].id.replace("/%3CDESTINATION%3E/","/");
		atletas[i].id = atletas[i].id.replace("http://playersearch.terra.com/","/");
		atletas[i].id = atletas[i].id.replace("http//playersearch.terra.com/","/");
		atletas[i].href = url_agenda + "" + atletas[i].id;
	}

	var links = $('li.lk_li a');	
	for( var i = 0; i < links.length; i++ ){
		links[i].id = links[i].id.replace("http://playersearch.terra.com/","/");
		links[i].id = links[i].id.replace("http//playersearch.terra.com/","/");
		links[i].href = url_agenda + "" + links[i].id;
	}

	var x = url.indexOf("&query=") + 7;
	var y = url.substring(x);
	var query = y.substring(0, y.indexOf("&"));

	if ( atletas.length > 0 ){
		document.getElementById("searchOk").innerHTML += "<strong>" + unescape(query) + "</strong>";
		document.getElementById("searchOk").style.display = "block";
	}else{
		document.getElementById("searchNOk").innerHTML += "<strong>" + unescape(query) + "</strong>";
		document.getElementById("searchNOk").style.display = "block";
	}

}