document.title = "-=[MarkPrint]=-";
var ie = document.all;
var pathSite = "http://www.markprint.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 = "" + escape(fObj.query.value);
  return false;
}

function mostraBoxChic() {
box  = '<form style="margin:0px;" onsubmit="validaBusca(this); return false;">\n';
box += '<input type="Hidden" name="id" value="1">\n';
//	box  = "<form style='margin:0px;' action='' onsubmit='return concStrBus(this)' name='formulario'>\n";
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="default_arquivos/logo_MP.gif" width="146" height="43"></td>\n';
box += '			    <td width="185">\n';
box += '					<!-- form busca -->\n';
box += '					<form style="margin:0px;" onsubmit="validaBusca(this); return false;">\n';
box += '					<input type="Hidden" name="id" value="1">\n';
box += '					<div style="padding:4px; background:#F3F3F3; width:170px;">\n';
box += '						<table width="170" cellspacing="0" cellpadding="0" border="0" bgcolor="#F3F3F3">\n';
box += '							<tr>\n';
box += '								<td width="78" valign="middle"><a href="http://mailing.chic.com.br" target="_blank"><img src="http://image.ig.com.br/chic/imagens/box_cadastro_txt_cadastro.gif" width="70" height="11" alt="" border="0"></a></td>\n';
box += '								<td><img src="http://image.ig.com.br/chic/imagens/box_cadastro_linha_vert.gif" width="1" height="11" alt="" border="0"></td>\n';
box += '								<td width="83" align="center" valign="middle"><a href="#"><img src="http://image.ig.com.br/chic/imagens/box_cadastro_txt_fale.gif" width="75" height="11" alt="" border="0"></a></td>\n';
box += '							</tr>\n';
box += '							<tr>\n';
box += '								<td colspan="3" valign="top">\n';
box += '									<table width="162" cellpadding="0" cellpadding="0" border="0">\n';
box += '										<tr>\n';
box += '											<td width="119" valign="middle"><input type="Text" style="font-size: 11px; width: 112px; border: 1px solid #D0D0D0;" name="query"></td>\n';
box += '											<td width="43" valign="middle"><input type="Image" src="http://images.ig.com.br/chic/nova_home/box_cadastro_txt_busca_novo.gif" width="39" height="16" onclick="validaBusca(this.form); return false;"></td>\n';
box += '										</tr>\n';
box += '										<tr>\n';
box += '											<td width="119" valign="middle">\n';
box += '											<select name="escolha" style="width:112px; height:15px; font:10px verdana;">\n';
box += '												<option value="">escolha a ação</option>\n';
box += '												<option value="">escolha a ação</option>\n';
box += '												<option value="">escolha a ação</option>\n';
box += '												<option value="">escolha a ação</option>\n';
box += '												<option value="">escolha a ação</option>\n';
box += '												<option value="">escolha a ação</option>\n';
box += '												<option value="">escolha a ação</option>\n';
box += '											</select>\n';
box += '											</td>\n';
box += '										</tr>\n';
box += '									</table>\n';
box += '								</td>\n';
box += '							</tr>\n';
box += '						</table>\n';
box += '					</div>\n';
box += '					</form>\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 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 = "principal";
			nomeCanal = "principal";
			nomeFormatado = "principal";
		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 carregaComboCidades() {
	form = document.arquivosChic;

	form.elements['cidadesDesfiles'].options[0] = new Option("Selecione a Marca", -1);
	form.elements['estacaoDesfiles'].options[0] = new Option("Selecione o Modelo", -1);
	form.elements['estilistasDesfiles'].options[0] = new Option("Selecione o SO", -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='http://www.markprint.com.br/novo/drivers/wizard.html' 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 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="";
	}
}