String.prototype.startsWith = function(str) {
	return (this.match("^"+str)==str)
}

var firstCat = new Array(0,1446,1508,1514,1513,0,1520,1535,1518,1547,1610,
1551,1570,0,1582,0,1430,1612,1696,1584,1568,1422,1641,1580,1586,0,1704,0,
0,1678,1644,0,0,1600,1702,1614,1560,1643,0,1684,1692,1680,1426,0,0,1698,
1736,1700,1516,0,0,0,0,0,0,0,0,0,0,0,0,1531,1627,1718,1729);

var url = document.URL;
var country = "br";
var countryCode = "BRA";
var countryPath = "br";
var catId = firstCat[1];
var resSportId = "1";
var resCatId = firstCat[1];
var erro_busca = false;


var agendaUrl = "http://agendaesportiva.terra.com.br/olimpiadas/2008";
var urlFastCgi = "http://playersearch.terra.com/playersearch/playersearch.fcgi";
var urlFanZone = "http://fanzone.terra.com.br/olimpiadas/2008";
var countryCapitalName = "*Hor&aacute;rio de Bras&iacute;lia";

var date = new Date();
var today = 6;
if (date.getFullYear() == 2008 && date.getMonth() == 7 && date.getDate() > 5 && date.getDate() < 25) {
	today = date.getDate();
}
today = today < 10 ? '0' + today : today;

// TESTE PARA COUNTRY CODE DO USUARIO //
if ( url.indexOf(".com.ar") > -1 ){
	countryCode = "ARG";
	country = "ar";
	countryPath = "arg";
	countryCapitalName = "*Hora de Buenos Aires";
	urlFanZone = "http://fanzone.terra.com.ar/olimpiadas/2008";
} else if ( url.indexOf(".com.co") > -1 ){
	countryCode = "COL";
	country = "co";
	countryPath = "col";
	countryCapitalName = "*Hora de Bogot&aacute;";
	urlFanZone = "http://fanzone.terra.com.co/olimpiadas/2008";
} else if ( url.indexOf("terra.cl") > -1  ){
	countryCode = "CHI";
	country = "cl";
	countryPath = "chi";
	countryCapitalName = "*Hora de Santiago";
	urlFanZone = "http://fanzone.terra.cl/olimpiadas/2008";
} else if ( url.indexOf(".com.ec") > -1  ){
	countryCode = "ECU";
	country = "ec";
	countryPath = "ecu";
	countryCapitalName = "*Hora de Quito";
	urlFanZone = "http://fanzone.terra.com.ec/olimpiadas/2008";
} else if ( url.indexOf(".com.mx") > -1  ){
	countryCode = "MEX";
	country = "mx";
	countryPath = "mex";
	countryCapitalName = "*Hora de Ciudad de M&eacute;xico";
	urlFanZone = "http://fanzone.terra.com.mx/olimpiadas/2008";
} else if ( url.indexOf(".com.pe") > -1  ){
	countryCode = "PER";
	country = "pe";
	countryPath = "per";
	countryCapitalName = "*Hora de Lima";
	urlFanZone = "http://fanzone.terra.com.pe/olimpiadas/2008";
} else if ( url.indexOf(".com.ve") > -1  ){
	countryCode = "VEN";
	country = "ve";
	countryPath = "ven";
	countryCapitalName = "*Hora de Caracas";
	urlFanZone = "http://fanzone.terra.com.ve/olimpiadas/2008";
} else if (url.indexOf(".com.br") > -1 ) {
	countryCode = "BRA";
	country = "br";
	countryPath = "br";
} else {
	countryCapitalName = "*ET";
	countryCode = "USA";
	country = "us";
	if (url.indexOf("sportscoverage.terra") > -1) {
		countryPath = "en";
		//country = "en";
		urlFanZone = "http://en.fanzone.terra.com/olympics/2008";
	} else {
		countryPath = "usa";
		//country = "us";
		urlFanZone = "http://fanzone.terra.com/olimpiadas/2008";
	}
}

// tag de publicidade
var tgmKey=country+'.olimpiadas2008.deportes';

function printTag(arg) {
	var script = "var terra_info_id = 'Agenda Esportiva'; " +
		"var terra_stats_regCLK = 0;";
		
	if (country=='br') {
		script+="var terra_info_channel='br.esportes.olimpiadas';var terra_stats_idCrtfc=24743;";
	} else if (country=='ar') {
		script+="var terra_info_channel='ar.deportes.olimpiadas';var terra_stats_idCrtfc=24735;";
	} else if (country=='co') {
		script+="var terra_info_channel='co.deportes.olimpiadas';var terra_stats_idCrtfc=24737;";
	} else if (country=='cl') {
		script+="var terra_info_channel='cl.deportes.olimpiadas';var terra_stats_idCrtfc=24736;";
	} else if (country=='ec') {
		script+="var terra_info_channel='ec.deportes.olimpiadas';var terra_stats_idCrtfc=24738;";
	} else if (country=='us' && countryPath=='usa') {
		script+="var terra_info_channel='us.deportes.olimpiadas';var terra_stats_idCrtfc=24742;";
	} else if (country=='us' && countryPath=='en') {
		script+="var terra_info_channel='us.sports.olympics';var terra_stats_idCrtfc=24742;";
	} else if (country=='mx') {
		script+="var terra_info_channel='mx.deportes.olimpiadas';var terra_stats_idCrtfc=24740;";
	} else if (country=='pe') {
		script+="var terra_info_channel='pe.deportes.olimpiadas';var terra_stats_idCrtfc=24741;";
	} else if (country=='ve') {
		script+="var terra_info_channel='ve.deportes.olimpiadas';var terra_stats_idCrtfc=24739;";
	}
	
	if (arg=='res') {
		script+="var terra_info_service = 'Resultados';";
		script+="var terra_info_type = 'RES';";
	} else if (arg=='rec') {
		script+="var terra_info_service = 'Recordes';";
		script+="var terra_info_type = 'REC';";
	} else if (arg=='med') {
		script+="var terra_info_service = 'Medalhas';";
		script+="var terra_info_type = 'MED';";
	} else if (arg=='atl') {
		script+="var terra_info_service = 'Atletas';";
		script+="var terra_info_type = 'ATL';";
	} else if (arg=='agn') {
		script+="var terra_info_service = 'Agenda';";
		script+="var terra_info_type = 'AGE';";
	}
	printScriptFrag(script);
	printScript("http://rtsmoc.terra.com.mx/js/metrics.js");
}

function printTag2(arg) {
	var script = "var terra_info_id = 'Agenda Esportiva'; " +
		"var terra_stats_regCLK = 0;";
		
	if (country=='br') {
		script+="var terra_info_channel='br.esportes.olimpiadas';var terra_stats_idCrtfc=24743;";
	} else if (country=='ar') {
		script+="var terra_info_channel='ar.deportes.olimpiadas';var terra_stats_idCrtfc=24735;";
	} else if (country=='co') {
		script+="var terra_info_channel='co.deportes.olimpiadas';var terra_stats_idCrtfc=24737;";
	} else if (country=='cl') {
		script+="var terra_info_channel='cl.deportes.olimpiadas';var terra_stats_idCrtfc=24736;";
	} else if (country=='ec') {
		script+="var terra_info_channel='ec.deportes.olimpiadas';var terra_stats_idCrtfc=24738;";
	} else if (country=='us' && countryPath=='usa') {
		script+="var terra_info_channel='us.deportes.olimpiadas';var terra_stats_idCrtfc=24742;";
	} else if (country=='us' && countryPath=='en') {
		script+="var terra_info_channel='us.sports.olympics';var terra_stats_idCrtfc=24742;";
	} else if (country=='mx') {
		script+="var terra_info_channel='mx.deportes.olimpiadas';var terra_stats_idCrtfc=24740;";
	} else if (country=='pe') {
		script+="var terra_info_channel='pe.deportes.olimpiadas';var terra_stats_idCrtfc=24741;";
	} else if (country=='ve') {
		script+="var terra_info_channel='ve.deportes.olimpiadas';var terra_stats_idCrtfc=24739;";
	}
	
	if (arg=='res') {
		script+="var terra_info_service = 'Resultados';";
		script+="var terra_info_type = 'RES';";
	} else if (arg=='rec') {
		script+="var terra_info_service = 'Recordes';";
		script+="var terra_info_type = 'REC';";
	} else if (arg=='med') {
		script+="var terra_info_service = 'Medalhas';";
		script+="var terra_info_type = 'MED';";
	} else if (arg=='atl') {
		script+="var terra_info_service = 'Atletas';";
		script+="var terra_info_type = 'ATL';";
	} else if (arg=='agn') {
		script+="var terra_info_service = 'Agenda';";
		script+="var terra_info_type = 'AGE';";
	}
	printScriptFrag(script);
	//printScript("http://rtsmoc.terra.com.mx/js/metrics.js");	
	 
}

var hdr='res';
if ((url.indexOf("/atletas/") > -1) || (url.indexOf("/playersearch/") > -1)) {
	hdr='atl'
} else if (url.indexOf("/agenda/") > -1) {
	hdr='age';
}
function defineHeader() {
	var h = document.getElementById('ifr-header');
	if ( h != null ){
		if (country=='br') {
			if (hdr=='age') {
				h.setAttribute('src', 'http://www.terra.com.br/esportes/beijing2008/cabecera_agenda.htm');
			} else if (hdr=='atl') {
				h.setAttribute('src', 'http://www.terra.com.br/esportes/beijing2008/cabecera_atletas.htm');
			} else {
				h.setAttribute('src', 'http://www.terra.com.br/esportes/beijing2008/cabecera_resultados.htm');
			}
		} else if (country=='us' && countryPath=="en") {
			if (hdr=='age') {
				h.setAttribute('src', 'http://www.us.terra.com/include/olympics2008/cabecera_agenda.htm');
			} else if (hdr=='atl') {
				h.setAttribute('src', 'http://www.us.terra.com/include/olympics2008/cabecera_atletas.htm');
			} else {
				h.setAttribute('src', 'http://www.us.terra.com/include/olympics2008/cabecera_resultados.htm');
			}
		} else {
			if (hdr=='age') {
				h.setAttribute('src', 'http://www.'+country+'.terra.com/include/pekin20082/cabecera_agenda.htm');
			} else if (hdr=='atl') {
				h.setAttribute('src', 'http://www.'+country+'.terra.com/include/pekin20082/cabecera_atletas.htm');
			} else {
				h.setAttribute('src', 'http://www.'+country+'.terra.com/include/pekin20082/cabecera_resultados.htm');
			}
		}
	}

}

function printAcessories(id) {
	if (id % 2 == 1) {
		defineHeader();
	}
	
	if (id==0) {
		loadCss('http://dsv-webx1.terra.com.br/boxLomas/v4/css/classBoxLomas.css');
		loadScript("http://dsv-webx1.terra.com.br/boxLomas/v4/js/classBoxLoMas.js");
		document.write('<div id="contentDefault"><div id="divBox"></div></div>');
		printScriptFrag("objBox = new classBoxLomas({ " +
			"terra_lomas_lang: 'pt-br', " +
			"terra_lomas_country: 'br', " +
			"terra_lomas_show_videos: 'yes', " +
			"terra_lomas_nr_thumbs_videos: 2, " +
			"terra_lomas_nr_thumbs: 4, " +
			"terra_lomas_nr_news: 2, " +
			"terra_lomas_br_tags: 10, " +
			"elemResult: 'divBox', " +
			"objLomasName: 'objBox' " +
		"});objBox.showLomasOutput();");
	} else if (id==1) {
		var url = 'http://fanzone.terra.com.br/olimpiadas/2008/widget.html';
		document.write('<iframe src="'+url+'" height="410px" frameborder="0" scrolling="no"></iframe>');
		
		/* Tag de UV */
		document.write("<SCRIPT>var uv_c='esportes.olimpiadas2008_agenda';" +
				"var uv_SERVER='uv.terra.com.br';</SCRIPT>");
		document.write("<SCRIPT src=\"http://img.terra.com.br/uv/uv.js\"></SCRIPT>");
		document.write("<NOSCRIPT>" +
				"<img src=\"http://uv.terra.com.br/UV?c=esportes.olimpiadas2008_agenda\" width=1 height=1 border=0 alt=\"\">" +
				"</NOSCRIPT>");
				
		document.write("<SCRIPT>uv_c='esportes.olimpiadas2008';" +
				"var uv_SERVER='uv.terra.com.br';</SCRIPT>");
		document.write("<SCRIPT src=\"http://img.terra.com.br/uv/uv.js\"></SCRIPT>");
		document.write("<NOSCRIPT>" +
				"<img src=\"http://uv.terra.com.br/UV?c=esportes.olimpiadas2008\" width=1 height=1 border=0 alt=\"\">" +
				"</NOSCRIPT>");
		/* */
		
	} else if (id==2) {
		var url = 'http://www.terra.com.br/esportes/beijing2008/include-celular.htm';
		document.write('<br/><br/><br/><iframe src="'+url+'" height="400px" frameborder="0" scrolling="no"></iframe>');
	} else if (id==3) {
		var url = 'http://www.'+country+'.terra.com/include/pekin20082/include-fanzone.htm';
		document.write('<iframe src="'+url+'" height="440px" frameborder="0" scrolling="no"></iframe>');
 	} else if (id==4) {
 		var url = 'http://www.'+country+'.terra.com/shared/pekin20082/include-celular.htm';
		document.write('<br/><br/><br/><iframe src="'+url+'" height="400px" frameborder="0" scrolling="no"></iframe>');
 	}
}

function loadScript(src) {
	var spt = document.createElement('script');
    spt.setAttribute('type', 'text/javascript');
    spt.setAttribute('src', src);
    document.getElementsByTagName('head')[0].appendChild(spt);
}

function printScript(src) {
	document.write(unescape("%3Cscript type='text/javascript; charset=iso-8859-1' src='"+src+"'%3E%3C/script%3E"));
}

function printScriptFrag(script) {
	document.write(unescape("%3Cscript type='text/javascript; charset=iso-8859-1'%3E"+script+"%3C/script%3E"));
}

function loadCss(url) {
    var lnk = document.createElement('link');
    lnk.setAttribute('type', 'text/css');
    lnk.setAttribute('rel', 'stylesheet');
    lnk.setAttribute('href', url);
    document.getElementsByTagName('head')[0].appendChild(lnk);
}
function verifica(){

	var queryString = document.frm.query.value;
	if ( queryString != "" && queryString.trim().length > 2 ){
		return true;
	}else{
		return false;
	}

}