document.title = ":: Chic - Gloria Kalil";
var ie = document.all;
var pathSite = "http://chic.ig.com.br";
var video = [];
var ultimas = [];
var cidade = [];
var urlMateria = [];
var estacao = [];
var estilista = [];
var arrayBusca = [];
var indice = 0;
var videoAtual = 0;
var xmlHttpRequest;
var intervalo = "";
var conteudoFinal = "";
var tempoAUDIO = "";
var urlUltimosDesfiles = pathSite + "/listas/ultimos_desfiles.html";
var urlMaisCarinhas = pathSite + "/listas/mais_carinhas.html";
var urlMaisNews = pathSite + "/listas/mais_news.html";
var urlMaisEditorial = pathSite + "/listas/colunas_anteriores_editorial.html";
var urlAmigo = pathSite + "/enviar_amigo.html";
var urlListaGeral = pathSite + "/listas/lista_geral.html";

arrayBusca['assista'] = 6;
arrayBusca['ouca'] = 7;
arrayBusca['desfiles'] = 4;
arrayBusca['carinhas'] = 5;
arrayBusca['chic_news'] = 2;
arrayBusca['editorial'] = 3;

function inicializaAquivo() {
	for(a=0; a<100; a++) {
		estacao[a] = [];
		estilista[a] = [];
		urlMateria[a] = [];
		
		for(b=0; b<30; b++) {
			estilista[a][b] = [];
			urlMateria[a][b] = [];
		}
	}
}

function xmlOBJ() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
}

function Player() {
	this.player_name = "player";
	this.player_button_name = "btPlayPause";

	this.player_obj = null;
	this.btPlayer = null;

	this.volume_max = 100;
	this.volume_min = 0;
	this.volume_increm = 10;
	this.player_height = 180;
	this.player_width = 240;
	this.skip_percent = 0.05;

	this.Check = Player_Check;
	this.PlayPause = Player_PlayPause;
	this.IsPlaying = Player_IsPlaying;
	this.IsStoped = Player_IsStoped;
	this.Play = Player_Play;
	this.Pause = Player_Pause;
	this.Stop = Player_Stop;
	this.Anterior = Player_Anterior;
	this.Proximo = Player_Proximo;
	this.SetarUrl = Player_SetarUrl;
	this.LimparTempo = Player_Limpar_Tempo;
}

function Player_PlayPause() {
	if(this.Check()) {
		if(this.IsPlaying()) {
			this.btPlayer.src = "http://image.ig.com.br/chic/imagens/player_bot_play.gif";
			this.Pause();
		} else {
			this.Play();
			this.btPlayer.src = "http://image.ig.com.br/chic/imagens/player_bot_pause.gif";
		}
	}
}

function Player_Check() {
	if(this.player_obj != null && this.btPlayer != null) {
		return(true);
	} else {
		this.player_obj = document.getElementById(this.player_name);      // Player
		this.btPlayer = parent.document.getElementById(this.player_button_name); // Image Button
	
		return true;
	}
	return(false);
}

function Player_Pause() {
	if(this.Check()) {
		this.player_obj.controls.pause();
		this.LimparTempo();
	}
}

function Player_IsPlaying() {
	if(this.Check()) {
		if(this.player_obj.playState == 3) {
		return(true);
		}
	}
	return(false);
}

function Player_IsStoped() {
	if(this.Check()) {
		if(this.player_obj.playState == 1) {
			return(true);
		}
	}
	return(false);
}

function Player_Play() {
	if(this.Check()) {
		this.LimparTempo();
		this.player_obj.controls.play();
		intervalo = window.setInterval("Player_Duracao()", 1000);
	}
}

function Player_Stop() {
	if(this.Check()) {
		this.btPlayer.src = "http://image.ig.com.br/chic/imagens/player_bot_play.gif";
		document.getElementById("decorrer").width = 1;
		this.player_obj.controls.stop();
		window.clearInterval(intervalo);
	}
}

function Player_Anterior() {
	if(this.Check()) {
		if(videoAtual > 0) {
			videoAtual--;
			this.LimparTempo();
			this.SetarUrl();
			this.Play();
			this.btPlayer.src = "http://image.ig.com.br/chic/imagens/player_bot_pause.gif";
		}
	}
}

function Player_Proximo() {
	if(this.Check()) {
		if(videoAtual < (video.length - 1)) {
			videoAtual++;
			this.LimparTempo();
			this.SetarUrl();
			this.Play();
			this.btPlayer.src = "http://image.ig.com.br/chic/imagens/player_bot_pause.gif";
		}
	}
}

function Player_SetarUrl() {
	if(this.Check()) {
		this.player_obj.url = video[ videoAtual ];
	}
}

function Player_Duracao() {
	posicaoAtual = document.getElementById("player").controls.CurrentPosition;
	duracao      = document.getElementById("player").controls.currentItem.duration;
	
	if(document.getElementById("player").PlayState == 9 || document.getElementById("player").PlayState == 6) {
		document.getElementById("statusPlayer").innerHTML = "Carregando...";
	} else {
		document.getElementById("statusPlayer").innerHTML = "";
		document.getElementById("statusPlayer").style.display = "none";
	}
	
	if(document.getElementById("player").readyState == 4 && document.getElementById("player").PlayState == 1) {
		document.btPlayPause.src = "http://image.ig.com.br/chic/imagens/player_bot_play.gif";
		document.getElementById("decorrer").width = 1;
		window.clearInterval(intervalo);
		
	}
	
	if(posicaoAtual && duracao) {
		fator = 3.26;
		tamanhoPx = ((100 * fator) * posicaoAtual) / duracao;

		document.getElementById("decorrer").width = Math.ceil(tamanhoPx);		
	}
}

function Player_Limpar_Tempo() {
	window.clearInterval(intervalo);
	window.status = "";
}

function SegundosParaMinutos(val){
	minutos = 0; segundos = 0;

	while(val > 60){
		val = val - 60;
		minutos++;
	}
	segundos = Math.floor(val) + "";
	minutos = minutos + "";

	if(minutos.length < 2) minutos = "0" + minutos;
	if(segundos.length < 2) segundos = "0" + segundos;

	return minutos + ":" + segundos;
}

function buscaNo(codcnl) {
	parseNo  = "<form style='margin:0px;' onsubmit='validaBusca(this); return false;'>\n";
	parseNo += "<input type='Hidden' name='id' value='" + arrayBusca[ getNomeCanal(codcnl, '') ] + "'>\n";
	parseNo += "	<table width='160' cellspacing='0' cellpadding='0' border='0'>\n";
	parseNo += "	<tr>\n";
	parseNo += "		<td width='102' height='30' valign='middle'><input type='Text' name='query' class='inputBox'></td>\n";
	parseNo += "		<td width='58' valign='middle' class='txtBoxBusca'>buscar no " + getNomeCanal(codcnl, 2) + "<input type='Image' src='http://image.ig.com.br/chic/imagens/ic_bullet_transp.gif' align='absmiddle' hspace='2' onclick='validaBusca(this.form); return false;'></td>\n";
	parseNo += "	</tr>\n";
	parseNo += "</table>\n";
	parseNo += "</form>\n";	
	
	return parseNo;
}

function buscaNoXsl(codcnl) {
	document.getElementById("layerBuscaNo").innerHTML = buscaNo(codcnl);
}

function concStrBus(fObj){
  location.href = "http://farejador-1.ig.com.br/farejador/search?orig=ig_xml_br_search_canais&type=chic&q=site%3Achic.ig.com.br+" + escape(fObj.query.value);
  return false;
}

function mostraBoxChic() {
box = '<table width="100%" border="0" cellpadding="0" cellspacing="0">\n';
box += '	<tr>\n';
box += '		<td valign="top" align="center">\n';
box += '			<table width="768" border="0" cellspacing="0" cellpadding="0" align="center">\n';
box += '			  <tr> \n';
box += '			    <td height="1" colspan="3"><img src="http://image.ig.com.br/chic/imagens/spacer.gif" height="1"></td>\n';
box += '			  </tr>\n';
box += '			  <tr bgcolor="#FFFFFF"> \n';
box += '			    <td width="103"><img src="http://image.ig.com.br/chic/imagens/logo_chic.gif" width="103" height="76"></td>\n';
box += '			    <td width="185">\n';
box += '					<!-- form busca -->\n';
box += '					<div style="padding:4px; background:#F3F3F3; width:170px;">\n';
box += '						<table width="170" height="48" cellspacing="0" cellpadding="0" border="0" bgcolor="#F3F3F3">\n';
box += '							<form action="http://busca.igbusca.com.br/app/search" method="get" name="busca">\n';
box += '							<input type="Hidden" name="o" value="CHIC">\n';
box += '							<tr>\n';
box += '								<td valign="top">\n';
box += '									<div style="font:10px Trebuchet MS; color:#A6A6A6; padding:6px 2px 6px 55px; float:left">enhanced by</div>\n';
box += '									<div style="padding:4px 0 2px 2px; float:left"><img src="http://images.ig.com.br/chic/logo-google.gif" width="48" height="18" alt="" border="0"></div>\n';
box += '									<div style="padding:0px 0 0 9px; float:left;"><input type="Text" style="font-size: 11px; width: 112px; border: 1px solid #D0D0D0;" name="q" id="buscagoogle"></div>\n';
box += '									<div style="padding:0px 0 0 3px; _padding:2px 0 0 3px; float:left;"><input type="Image" src="http://images.ig.com.br/chic/nova_home/box_cadastro_txt_busca_novo.gif" width="39" height="16"></div>\n';
box += '								</td>\n';
box += '							</tr>\n';
box += '						</form>\n';
box += '						</table>\n';
box += '					</div>\n';
box += '					<!-- form busca -->\n';
box += '				</td>\n';
box += '			    <td align="center" width="477">\n';
	return box;
}
function mostraBoxChic2() {
box = '                </td>\n';
box += '			  </tr>\n';
box += '			</table>\n';
box += '		</td>\n';
box += '	</tr>\n';
box += '</table>\n';
	return box;
}

function mostraBoxFullBanner() {
box = '<table width="100%" border="0" cellpadding="0" cellspacing="0">\n';
box += '	<tr>\n';
box += '		<td valign="top" align="center">\n';
box += '			<table width="768" border="0" cellspacing="0" cellpadding="0" align="center">\n';
box += '			  <tr> \n';
box += '			    <td colspan="2" style="padding:5px 20px 12px;background:#fff;">\n';
	return box;
}

function mostraBoxFullBanner2() {
box = '          </td>\n';
box += '			  </tr>\n';
box += '			  <tr bgcolor="#FFFFFF"> \n';
box += '			    <td><a href="http://chic.ig.com.br/" title="Chic"><img src="http://image.ig.com.br/chic/imagens/logo_chic2.gif" width="94" height="60" style="padding:0 0 8px 20px;*margin-left:20px!important;border:0!important" /></a></td>\n';
box += '			    <td align="right">\n';
box += '					<!-- form busca -->\n';
box += '					<div style="margin:0 20px 10px 0;padding:0;background:#F3F3F3;width:365px;height:60px">\n';
box += '						<table cellspacing="0" cellpadding="0" border="0" bgcolor="#F3F3F3">\n';
box += '							<form action="http://busca.igbusca.com.br/app/search" method="get" name="busca">\n';
box += '							<input type="Hidden" name="o" value="CHIC">\n';
box += '							<tr>\n';
box += '								<td valign="top">\n';
box += '									<div style="font:10px Trebuchet MS; color:#A6A6A6; padding:6px 2px 6px 245px; float:left">enhanced by</div>\n';
box += '									<div style="padding:4px 0 2px 2px; float:left"><img src="http://images.ig.com.br/chic/logo-google.gif" width="48" height="18" alt="" border="0"></div>\n';
box += '									<div style="padding:0px 0 0 9px; float:left;"><input type="Text" style="font-size: 11px; width: 302px; border: 1px solid #D0D0D0;" name="q" id="buscagoogle"></div>\n';
box += '									<div style="padding:0px 0 0 3px; _padding:2px 0 0 3px; float:left;"><input type="Image" src="http://images.ig.com.br/chic/nova_home/box_cadastro_txt_busca_novo.gif" width="39" height="16"></div>\n';
box += '								</td>\n';
box += '							</tr>\n';
box += '						</form>\n';
box += '						</table>\n';
box += '					</div>\n';
box += '					<!-- form busca -->\n';
box += '				</td>\n';
box += '			  </tr>\n';
box += '			</table>\n';
box += '		</td>\n';
box += '	</tr>\n';
box += '</table>\n';
	return box;
}

function validaBusca(form) {
	if(form.query.value == '') {
		alert("Preencha corretamente o campo de busca!");
		form.query.focus();
	} else {
		urlGet = "http://chic.ig.com.br/busca/busca_geral.html?id=" + form.id.value + "&query=" + escape(form.query.value) + "&orig=ig_xml_br_search_canais&type=chic";
		location.href = urlGet;
	}
}

function validaBuscaCateg(form, cnl) {
	urlGet = "http://chic.ig.com.br/busca/busca_geral_midia.html?canal=" + cnl + "&codast=" + form.comboCategorias.value + "&dat=" + form.comboPeriodo.value;
	location.href = urlGet;
}

function mostraBoxChicXsl() {
	document.getElementById("layerBoxChic").innerHTML = mostraBoxChic();
}

function menuInternoFlash(cnl) {
	_menuInterno  = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0' width='768' height='56' id='menu_interno'>\n";
	_menuInterno += "	<param name=movie value='" + pathSite + "/flash/menu/menu_v01.swf?menuOver=" + getNomeCanal(cnl, 0) + "'>\n";
	_menuInterno += "	<param name=quality value=high>\n";
	_menuInterno += "	<param name=wmode value=transparent>\n";
	_menuInterno += "	<embed src='" + pathSite + "/flash/menu/menu_v01.swf?menuOver=" + getNomeCanal(cnl, 0) + "' wmode='transparent' quality=high pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width='768' height='56'></embed>\n";
	_menuInterno += "</object>\n";
	
	return _menuInterno;
}

function menuInternoFlashXsl(cnl) {
	document.getElementById("layerMenuFlash").innerHTML = menuInternoFlash(cnl);
}

function menuHomeFlash() {
	_menuHome  = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0' width='768' height='77' id='menu_interno'>\n";
	_menuHome += "	<param name=movie value='" + pathSite + "/flash/menu/menu_home_v01.swf'>\n";
	_menuHome += "	<param name=quality value=high>\n";
	_menuHome += "	<param name=wmode value=transparent>\n";
	_menuHome += "	<embed src='" + pathSite + "/flash/menu/menu_home_v01.swf' wmode='transparent' quality=high pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width='768' height='77'></embed>\n";
	_menuHome += "</object>\n";
	
	return _menuHome;
}

function getNomeCanal(cnl, op) {
	switch(cnl) {
		case 901:
		case 903:
			nome = "assista";
			nomeCanal = "assista";
			nomeFormatado = "Assista";
		break;
		
		case 902:
		case 907:
			nome = "ouça";
			nomeCanal = "ouca";
			nomeFormatado = "Ouça";
		break;
		
		case 914:
			nome = "desfiles";
			nomeCanal = "desfiles";
			nomeFormatado = "Desfiles";
		break;
		
		case 923:
			nome = "carinhas";
			nomeCanal = "carinhas";
			nomeFormatado = "Carinhas";
		break;
		
		case 924:
			nome = "news";
			nomeCanal = "chic_news";
			nomeFormatado = "Chic News";
		break;
		
		case 925:
			nome = "editorial";
			nomeCanal = "editorial";
			nomeFormatado = "Editorial da Glória";
		break;
		
		default:
			nome = "";
			nomeCanal = "";
			nomeFormatado = "";
		break;
	}
	
	if(op == 1) {
		return nomeFormatado;
	} else if(op == 2) {
		return nome;
	} else {
		return nomeCanal;
	}
}

/* Controle para o áudio ( Canal Ouça )*/
function playPauseAUDIO(op) {
	window.clearInterval(tempoAUDIO);
	
	if(isPlayingAUDIO() && op != "onload") {
		objIMgAUDIO.src = "http://image.ig.com.br/chic/imagens/player_bot_play_ouca.gif";
		objAUDIO.pause();
	} else {
		tempoAUDIO = window.setInterval("duracaoAUDIO()", 1000);
		objIMgAUDIO.src = "http://image.ig.com.br/chic/imagens/player_bot_pause_ouca.gif";
		objAUDIO.play();
	}
}

function stopAUDIO() {
	decorrerAUDIO.width = 1;
	objIMgAUDIO.src = "http://image.ig.com.br/chic/imagens/player_bot_play_ouca.gif";
	objAUDIO.stop();
	window.clearInterval(tempoAUDIO);
}

function duracaoAUDIO() {
	if(ie) {
		total = Math.floor(objAUDIO.Duration);
		segundos = Math.floor(objAUDIO.CurrentPosition);
	} else {
		total = objAUDIO.get_length();
		segundos = objAUDIO.get_time();
	}
	
	fator = 3.20;
	tamanhoPx = ((100 * fator) * segundos) / total;

	decorrerAUDIO.width = ((Math.ceil(tamanhoPx) > 0) ? Math.ceil(tamanhoPx) : 1);
	
	//window.status = segundos;
	
	if(segundos > 0) {
		document.getElementById("statusPlayer").style.display = "none";
		document.getElementById("statusPlayer").innerHTML = "";
		
		if(!isPlayingAUDIO()) {
			stopAUDIO();
		}
	} else {
		document.getElementById("statusPlayer").style.display = "";
		document.getElementById("statusPlayer").innerHTML = "Carregando...";
	}
}

function isPlayingAUDIO() {
	if(ie) {
		if(objAUDIO.readyState == 4 && objAUDIO.PlayState == 2) {
			return true;
		} else {
			return false;
		}
	} else {
		return objAUDIO.isplaying();
	}
}
/**/

function ultimosDesfiles() {
	return "<iframe src='" + urlUltimosDesfiles + "' name='iFrameUltimosDesfiles' width='440' height='177' scrolling='Auto' frameborder='0' marginheight='0' marginwidth='0'></iframe>";
}

function maisCarinhas() { 
	return "<iframe src='" + urlMaisCarinhas + "' name='iFrameMaisCarinhas' width='225' height='215' scrolling='No' frameborder='0' marginheight='0' marginwidth='0'></iframe>";
}

function maisNews() {
	return "<iframe src='" + urlMaisNews + "' name='iFrameMaisCarinhas' width='229' height='340' scrolling='Auto' frameborder='0' marginheight='0' marginwidth='0'></iframe>";
}

function maisEditorial() {
	return "<iframe src='" + urlMaisEditorial + "' name='iFrameMaisCarinhas' width='229' height='232' scrolling='Auto' frameborder='0' marginheight='0' marginwidth='0'></iframe>";
}

function executaLink(url, id) {
	if(url != '') {
		frames['galeriaChic'].location = url;
	}
	document.getElementById("layerNavegacaoGalerias").innerHTML = parent.frames['galeriaChic'].navegacaoGaleria(id);
}

function imprimirChic() {
	window.print();
}

function imprimirChicPop() {
	html =	'<html>'+
			'<head>'+
			'<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />'+
			'<title>Chic - Glória Kalil</title>'+
			'<link rel="stylesheet" href="http://image.ig.com.br/chic/css/chic.css" type="text/css">'+
			'<scrip'+'t>'+
			'function imprimir(){'+
				'var objBotoes = document.getElementById("idbotoes");'+
				'objBotoes.style.display = "none";'+
				'var objMais = document.getElementById("idmais");'+
				'objMais.style.display = "none";'+
				'window.print();'+
			'}'+
			'</scrip'+'t>'+
			'</head>'+
			'<body style="margin:0;background:#FFF;">'+
			''+ document.getElementById("idimprimir").innerHTML; +''

	html +=	'<scrip'+'t>imprimir()</scrip'+'t>'

	html +=	'</body>'+
			'</html>';
			
	//page=(document.all)?"":window.location
	page = window.location;
	novaJanela = window.open(page, 'janela', 'width=495, height=500, top='+(window.screen.height/2-500/2)+', left='+(window.screen.width/2-776/2)+', scrollbars=yes');
	if(document.all){
		novaJanela.document.write(html);
	}else{
		novaJanela.onload = function(){
			novaJanela.document.write(html);
		}
	}
}

function imprimirChicPop1() {
	html =	'<html>'+
			'<head>'+
			'<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />'+
			'<title>Chic - Glória Kalil</title>'+
			'<link rel="stylesheet" href="http://image.ig.com.br/chic/css/chic.css" type="text/css">'+
			'<scrip'+'t>'+
			'function imprimir(){'+
				'var objBotoes = document.getElementById("idbotoes");'+
				'objBotoes.style.display = "none";'+
				'window.print();'+
			'}'+
			'</scrip'+'t>'+
			'</head>'+
			'<body style="margin:0;background:#FFF;">'+
			''+ document.getElementById("idimprimir").innerHTML; +''

	html +=	'<scrip'+'t>imprimir()</scrip'+'t>'

	html +=	'</body>'+
			'</html>';
			
	//page=(document.all)?"":window.location
	page = window.location;
	novaJanela = window.open(page, 'janela', 'width=495, height=500, top='+(window.screen.height/2-500/2)+', left='+(window.screen.width/2-776/2)+', scrollbars=yes');
	if(document.all){
		novaJanela.document.write(html);
	}else{
		novaJanela.onload = function(){
			novaJanela.document.write(html);
		}
	}
}


function carregaComboCidades() {
	form = document.arquivosChic;

	form.elements['cidadesDesfiles'].options[0] = new Option("Selecione uma Cidade", -1);
	form.elements['estacaoDesfiles'].options[0] = new Option("Selecione uma Estação", -1);
	form.elements['estilistasDesfiles'].options[0] = new Option("Selecione um Estilista", -1);
	
	for(i=1; i<=cidade.length; i++) {
		form.elements['cidadesDesfiles'].options[i] = new Option(cidade[i-1], i-1);
	}
}

function carregaComboEstacao(id) {
	form = document.arquivosChic;
	
	limpaCombo(form.elements['estacaoDesfiles']);
	
	form.elements['estacaoDesfiles'].options[0] = new Option("Selecione uma Estação", -1);
	form.elements['estacaoDesfiles'].disabled = false;

	limpaCombo(form.elements['estilistasDesfiles']);
	
	form.elements['estilistasDesfiles'].options[0] = new Option("Selecione um Estilista", -1);
	form.elements['estilistasDesfiles'].disabled = true;
	
	for(i=1; i<=estacao[id].length; i++) {
		form.elements['estacaoDesfiles'].options[i] = new Option(estacao[id][i-1], i-1);
	}
}

function carregaComboEstilista(cid, estac) {
	form = document.arquivosChic;
	
	limpaCombo(form.elements['estilistasDesfiles']);
	
	form.elements['estilistasDesfiles'].options[0] = new Option("Selecione um Estilista", -1);
	form.elements['estilistasDesfiles'].disabled = false;
	
	estilista[cid][estac].sort();
	estilista[cid][estac].sort(ordena);
	
	for(i=1; i<=estilista[cid][estac].length; i++) {
		temp = estilista[cid][estac][i-1].split("||");
		form.elements['estilistasDesfiles'].options[i] = new Option(temp[0], temp[1]);
	}
}

function limpaCombo(campo) {
	while(campo.options.length > 1) {
		campo.remove(0);
	}
}

function arquivoDesfiles(hexa) {
	return "<iframe src='" + pathSite + "/chic_arquvios_desfiles.html?" + hexa + "' width='231' height='84' frameborder='0' marginheight='0' marginwidth='0' scrolling='No'></iframe>";
}

function listaGeralMaterias() {
	return "<iframe src='" + urlListaGeral + "' width='231' height='300' frameborder='0' marginheight='0' marginwidth='0' scrolling='Auto'></iframe>";
}

function enviarParaAmigo(titulo, url, codcnl) {
	top.location.href = urlAmigo + "?" + escape(titulo) + "|" + escape(url) + "|" + codcnl;
}

function validaSample(form) {
	campo1 = form.destinatario.value;
	campo2 = form.email.value;
	
	var mailValido1 = campo1.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
	var mailValido2 = campo2.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
	
	if(form.destinatario.value == "" || !mailValido1){
		alert("Preencha o e-mail do destinatário corretamente!");
		form.destinatario.focus();
	} else if(form.nome.value == "") {
		alert("Preencha o seu nome!");
	form.nome.focus();
	} else if(form.email.value == "" || !mailValido2) {
		alert("Preencha o seu e-mail corretamente!");
		form.email.focus();
	} else if(form.comentario.value == "") {
		alert("Preencha o comentário!");
		form.comentario.focus();
	} else {
		form.submit();
	}
}

function carregaDados() {
	url = document.location.search.toString();
	urlDados = url.substring(1, url.length);

	dados = urlDados.split("|");
	nomeCnl = getNomeCanal(parseInt(dados[2]), 1);

	document.enviarAmigo.urlMateria.value = unescape(dados[1]);
	document.enviarAmigo.materiaTitulo.value = nomeCnl + ": " + unescape(dados[0]);

	document.getElementById("descricaoEnvio").innerHTML = "<span class='bold envie" + dados[2] + "'>" + nomeCnl + ": </span>" + unescape(dados[0]);
}

function vejaTambem(cnlString) {
	document.write("<iframe src='" + pathSite + "/listas/ultimas_noticias_" + cnlString + ".xml' width='305' height='391' frameborder='0' marginheight='0' marginwidth='0' scrolling='No'></iframe>");
}

function linkHome() {
	top.location.href = pathSite;
}

function chicBuscar(oq, inicio, cnl) {
	objXML = new xmlOBJ();
	
	objXML.open("GET", "xml.php?id=" + cnl + "&query=" + escape(oq) + "&pagina=" + inicio, true);
	objXML.onreadystatechange = function() {
		if(objXML.readyState == 4 && objXML.status == 200) {
			restop = objXML.responseXML.getElementsByTagName("restop")[0];
			query = restop.getElementsByTagName("query")[0].attributes[0].nodeValue;
			
			de = restop.getElementsByTagName("info")[0].attributes[0].nodeValue;
			ate = restop.getElementsByTagName("info")[0].attributes[1].nodeValue;
			total = restop.getElementsByTagName("info")[0].attributes[2].nodeValue;
			
			resultado = objXML.responseXML.getElementsByTagName("res");

			if(total > 0) {
				de = ((de == 0) ? 1 : de);
			}
			
			informacoes = "Mostrando de " + de + " - " + ate + " de<span class='preto1'> " + total + "</span> melhores p&aacute;ginas que atendem a consulta <span class='preto1'>\"" + query + "\"<br><br>";
			lista       = "<table width='455' border='0' cellspacing='0' cellpadding='0' class='font11'>\n";
			
			limiteNavagacao = 4; // 0 ateh 4
			limitePorPagina = 10;
			paginaAtual  = Math.ceil(ate/limitePorPagina);
												
			totalPaginas = Math.ceil(total/limitePorPagina);
			navegacao    = ((total > 0) ? " | " : "");
							
			limiteNav = (((paginaAtual+limiteNavagacao) > totalPaginas) ? totalPaginas : paginaAtual+limiteNavagacao);
			anteriorFdp = limiteNavagacao - (totalPaginas - paginaAtual);
			
			inicioLoop = ((anteriorFdp > 0) ? paginaAtual - anteriorFdp : paginaAtual);
							
			for(i=inicioLoop; i<=limiteNav; i++) {						
				if(i>=1) {
					if(i == paginaAtual) {
						navegacao += "<b>" + i + "</b> | ";
					} else {
						inicioNav = (i-1)*limitePorPagina;
						navegacao += "<a href=\"javascript: chicBuscar('" + escape(oq) + "', " + inicioNav + ", " + cnl + ");\" class='font11 cinza2'>" + i + "</a> | ";
					}
				}
			}
			
                  lista += "    <tr>\n";
                  lista += "        <td height='10'>\n";
                  lista += "            <table border='0' cellspacing='0' cellpadding='0' align='right'>\n";
                  lista += "                <tr><td class='font11'><a href=\"javascript: " + ((paginaAtual > 1) ? "chicBuscar('" + escape(oq) + "', " + ((paginaAtual - 2) * limitePorPagina) + ", " + cnl + ");" : "void(0);") + "\"><img src='http://image.ig.com.br/chic/imagens/seta6_esq.gif' border='0' hspace='0'></a>&nbsp;&nbsp;" + navegacao + "&nbsp;&nbsp;<a href=\"javascript: " + ((paginaAtual < totalPaginas) ? "chicBuscar('" + escape(oq) + "', " + (paginaAtual * limitePorPagina) + ", " + cnl + ");" : "void(0);") + "\"><img src='http://image.ig.com.br/chic/imagens/seta6_dir.gif' border='0' hspace='0'></a>&nbsp;</td></tr>\n";
                  lista += "            </table>\n";
                  lista += "        </td>\n";
                  lista += "    </tr>\n";
			lista += "	  <tr><td height='10'><img src='http://image.ig.com.br/chic/imagens/spacer.gif' height='5'></td></tr>\n";
			
			for(var i=0; i<resultado.length; i++) {
				noh = resultado[i];
				
                      lista += "<tr><td class='bold'>" + (noh.getElementsByTagName("titulo")[0].attributes[0].nodeValue).replace(" - 00:00:00", ""); + "</td></tr>\n";
                      lista += "<tr><td style='padding-right: 10px;'><a href='" + noh.getElementsByTagName("url")[0].attributes[0].nodeValue + "' class='cinza2' target='_blank'>" + noh.getElementsByTagName("corpo")[0].attributes[0].nodeValue + "</a></td></tr>\n";
                      lista += "<tr><td height='5'><img src='http://image.ig.com.br/chic/imagens/spacer.gif' height='5'></td></tr>\n";
                      lista += "<tr><td><img src='http://image.ig.com.br/chic/imagens/separador.gif' width='455' height='3'></td></tr>\n";
                      lista += "<tr><td height='10'><img src='http://image.ig.com.br/chic/imagens/spacer.gif' height='5'></td></tr>\n";
			}
			
                  lista += "    <tr>\n";
                  lista += "        <td height='10'>\n";
                  lista += "            <table border='0' cellspacing='0' cellpadding='0' align='right'>\n";
                  lista += "                <tr><td class='font11'><a href=\"javascript: " + ((paginaAtual > 1) ? "chicBuscar('" + escape(oq) + "', " + ((paginaAtual - 2) * limitePorPagina) + ", " + cnl + ");" : "void(0);") + "\"><img src='http://image.ig.com.br/chic/imagens/seta6_esq.gif' border='0' hspace='0'></a>&nbsp;&nbsp;" + navegacao + "&nbsp;&nbsp;<a href=\"javascript: " + ((paginaAtual < totalPaginas) ? "chicBuscar('" + escape(oq) + "', " + (paginaAtual * limitePorPagina) + ", " + cnl + ");" : "void(0);") + "\"><img src='http://image.ig.com.br/chic/imagens/seta6_dir.gif' border='0' hspace='0'></a>&nbsp;</td></tr>\n";
                  lista += "            </table>\n";
                  lista += "        </td>\n";
                  lista += "    </tr>\n";
                  lista += "</table>\n";
							
			document.getElementById("info").innerHTML     = informacoes;
			document.getElementById("conteudo").innerHTML = lista;					
			document.getElementById("status").innerHTML   = "";
		} else {
			document.getElementById("status").innerHTML = "Buscando...";
		}
	}
	objXML.send(null);
}

function chicBuscarPorCategoria(codast, dta, inicio) {
	objXML = new xmlOBJ();
	
	objXML.open("GET", "busca_por_categoria.php?codast=" + codast + "&dta=" + dta, true);
	objXML.onreadystatechange = function() {
		if(objXML.readyState == 4 && objXML.status == 200) {
			restop = objXML.responseXML.getElementsByTagName("restop")[0];
			query = restop.getElementsByTagName("query")[0].attributes[0].nodeValue;
			
			de = restop.getElementsByTagName("info")[0].attributes[0].nodeValue;
			ate = restop.getElementsByTagName("info")[0].attributes[1].nodeValue;
			total = restop.getElementsByTagName("info")[0].attributes[2].nodeValue;
			
			resultado = objXML.responseXML.getElementsByTagName("res");

			if(total > 0) {
				de = ((de == 0) ? 1 : de);
			}
			
			informacoes = "Mostrando de " + de + " - " + ate + " de<span class='preto1'> " + total + "</span> melhores p&aacute;ginas que atendem a consulta <span class='preto1'>\"" + query + "\"<br><br>";
			lista       = "<table width='455' border='0' cellspacing='0' cellpadding='0' class='font11'>\n";
			
			limiteNavagacao = 4; // 0 ateh 4
			limitePorPagina = 10;
			paginaAtual  = Math.ceil(ate/limitePorPagina);
												
			totalPaginas = Math.ceil(total/limitePorPagina);
			navegacao    = ((total > 0) ? " | " : "");
							
			limiteNav = (((paginaAtual+limiteNavagacao) > totalPaginas) ? totalPaginas : paginaAtual+limiteNavagacao);
			anteriorFdp = limiteNavagacao - (totalPaginas - paginaAtual);
			
			inicioLoop = ((anteriorFdp > 0) ? paginaAtual - anteriorFdp : paginaAtual);
							
			for(i=inicioLoop; i<=limiteNav; i++) {						
				if(i>=1) {
					if(i == paginaAtual) {
						navegacao += "<b>" + i + "</b> | ";
					} else {
						inicioNav = (i-1)*limitePorPagina;
						navegacao += "<a href=\"javascript: chicBuscar('" + escape(oq) + "', " + inicioNav + ", " + cnl + ");\" class='font11 cinza2'>" + i + "</a> | ";
					}
				}
			}
			
                  lista += "    <tr>\n";
                  lista += "        <td height='10'>\n";
                  lista += "            <table border='0' cellspacing='0' cellpadding='0' align='right'>\n";
                  lista += "                <tr><td class='font11'><a href=\"javascript: " + ((paginaAtual > 1) ? "chicBuscar('" + escape(oq) + "', " + ((paginaAtual - 2) * limitePorPagina) + ", " + cnl + ");" : "void(0);") + "\"><img src='http://image.ig.com.br/chic/imagens/seta6_esq.gif' border='0' hspace='0'></a>&nbsp;&nbsp;" + navegacao + "&nbsp;&nbsp;<a href=\"javascript: " + ((paginaAtual < totalPaginas) ? "chicBuscar('" + escape(oq) + "', " + (paginaAtual * limitePorPagina) + ", " + cnl + ");" : "void(0);") + "\"><img src='http://image.ig.com.br/chic/imagens/seta6_dir.gif' border='0' hspace='0'></a>&nbsp;</td></tr>\n";
                  lista += "            </table>\n";
                  lista += "        </td>\n";
                  lista += "    </tr>\n";
			lista += "	  <tr><td height='10'><img src='http://image.ig.com.br/chic/imagens/spacer.gif' height='5'></td></tr>\n";
			
			for(var i=0; i<resultado.length; i++) {
				noh = resultado[i];
				
                      lista += "<tr><td class='bold'>" + (noh.getElementsByTagName("titulo")[0].attributes[0].nodeValue).replace(" - 00:00:00", ""); + "</td></tr>\n";
                      lista += "<tr><td style='padding-right: 10px;'><a href='" + noh.getElementsByTagName("url")[0].attributes[0].nodeValue + "' class='cinza2' target='_blank'>" + noh.getElementsByTagName("corpo")[0].attributes[0].nodeValue + "</a></td></tr>\n";
                      lista += "<tr><td height='5'><img src='http://image.ig.com.br/chic/imagens/spacer.gif' height='5'></td></tr>\n";
                      lista += "<tr><td><img src='http://image.ig.com.br/chic/imagens/separador.gif' width='455' height='3'></td></tr>\n";
                      lista += "<tr><td height='10'><img src='http://image.ig.com.br/chic/imagens/spacer.gif' height='5'></td></tr>\n";
			}
			
                  lista += "    <tr>\n";
                  lista += "        <td height='10'>\n";
                  lista += "            <table border='0' cellspacing='0' cellpadding='0' align='right'>\n";
                  lista += "                <tr><td class='font11'><a href=\"javascript: " + ((paginaAtual > 1) ? "chicBuscar('" + escape(oq) + "', " + ((paginaAtual - 2) * limitePorPagina) + ", " + cnl + ");" : "void(0);") + "\"><img src='http://image.ig.com.br/chic/imagens/seta6_esq.gif' border='0' hspace='0'></a>&nbsp;&nbsp;" + navegacao + "&nbsp;&nbsp;<a href=\"javascript: " + ((paginaAtual < totalPaginas) ? "chicBuscar('" + escape(oq) + "', " + (paginaAtual * limitePorPagina) + ", " + cnl + ");" : "void(0);") + "\"><img src='http://image.ig.com.br/chic/imagens/seta6_dir.gif' border='0' hspace='0'></a>&nbsp;</td></tr>\n";
                  lista += "            </table>\n";
                  lista += "        </td>\n";
                  lista += "    </tr>\n";
                  lista += "</table>\n";
							
			document.getElementById("info").innerHTML     = informacoes;
			document.getElementById("conteudo").innerHTML = lista;					
			document.getElementById("status").innerHTML   = "";
		} else {
			document.getElementById("status").innerHTML = "Buscando...";
		}
	}
	objXML.send(null);
}

function ordena(a, b) {
	a = normaliza(a.substring(0, 1)).charCodeAt();
	b = normaliza(b.substring(0, 1)).charCodeAt();

	if(a == b) {
		return 0;
	} else if(a > b) {
		return 1;
	} else if(a < b) {
		return -1;
	}
}

function normaliza($) {
	busca = "ÁÉÍÓÚÀÈÌÒÙÄËÏÖÜÂÊÎÔÛÃÕÇ".indexOf($.toUpperCase());
	
	if(busca != -1){
		return "AEIOUAEIOUAEIOUAEIOUAOC".charAt(busca).toString();
	} else {
		return $.toUpperCase();
	}
}



function hasFrames(){
	return !(top == self);
}

function barra_iG(){
	if(!hasFrames()){
		document.getElementById("barraig").style.display="";
	}
}

window.onload = function(){
	document.getElementById('buscagoogle').focus();
}