function preloadImages() {
	var d=document;
	if(d.images) {	
		if (! d.arr_preImgs) {
				d.arr_preImgs=new Array();
		}
		var i, j=d.arr_preImgs.length, a=preloadImages.arguments;
		for (i=0; i<a.length; i++) {
			if (a[i].indexOf("#")!=0) {
				d.arr_preImgs[j]=new Image;
				d.arr_preImgs[j++].src=a[i];
			}
		}
	}
}

function validaEmail(email) {
	var reg_email = /^[a-z0-9_.-]+@([a-z0-9_]+\.)+[a-z]{2,4}$/i;
	return reg_email.test(email);
}

function changeFontSize(s,pai) {
	if (s == 1) {
		resize = '12px';
		line_height = '16px';
	}
	if (s == 2) {
		resize = '14px';
		line_height = '18px';
	}
	if (s == 3) {
		resize = '16px';
		line_height = '22px';
	}
	o = document.getElementById(pai);
	pes = o.getElementsByTagName("p");
	bs = o.getElementsByTagName("b");
	fonts = o.getElementsByTagName("font");
	lis = o.getElementsByTagName("li");
	as = o.getElementsByTagName("a");
	h2s = o.getElementsByTagName("h2");
	spans = o.getElementsByTagName("span");
	for (i=0; i < pes.length; i++) {
		pes[i].style.fontSize = resize;
		pes[i].style.lineHeight = line_height;
	}
	for (i=0; i < bs.length; i++) {
		bs[i].style.fontSize = resize;
		bs[i].style.lineHeight = line_height;
	}
	for (i=0; i < fonts.length; i++) {
		fonts[i].style.fontSize = resize;
		fonts[i].style.lineHeight = line_height;
	}
	for (i=0; i < lis.length; i++) {
		lis[i].style.fontSize = resize;
		lis[i].style.lineHeight = line_height;
	}
	for (i=0; i < as.length; i++) {
		as[i].style.fontSize = resize;
	}
	for (i=0; i < h2s.length; i++) {
		h2s[i].style.fontSize = resize;
	}
	for (i=0; i < spans.length; i++) {
		spans[i].style.fontSize = resize;
	}

}

function mostraMsg(msg, fechar_msg) {
	ov = document.getElementById('overlay');
	m = document.getElementById('msg');
	m.innerHTML = msg + '<a class="fechar" href="javascript: fechaMsg()">' + fechar_msg + '</a>';
	m.style.display = 'block';
	ov.style.display = 'block';
	arr_page_size = getPageSize();
	ov.style.height = arr_page_size[1] + 'px';
}

function fechaMsg() {
	ov = document.getElementById('overlay');
	m = document.getElementById('msg');
	m.style.display = 'none';
	ov.style.display = 'none';
}

function getPageSize(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

//--------------------------------------------------------

var atualizaBoxVideosAlfabeticos=true;
var atualBoxVideosAlfabeticos='';
function mostraVideosDeAaF() {
	if (atualBoxVideosAlfabeticos != 'aaf' && atualizaBoxVideosAlfabeticos)	{
		document.getElementById('abas_menu').style.background = 'url(../img/menu_box_videos_alfabeticos.gif) no-repeat 0 1px';
		atualBoxVideosAlfabeticos = 'aaf';
		mostraVideosAlfabeticos('/central_de_videos/videos_alfabeticos.php?idx=af');		
	}
}

function mostraVideosDeGaL() {
	if (atualBoxVideosAlfabeticos != 'gal' && atualizaBoxVideosAlfabeticos)	{
		document.getElementById('abas_menu').style.background = 'url(../img/menu_box_videos_alfabeticos.gif) no-repeat 0 -27px';
		atualBoxVideosAlfabeticos = 'gal';
		mostraVideosAlfabeticos('/central_de_videos/videos_alfabeticos.php?idx=gl');		
	}
}

function mostraVideosDeMaR() {
	if (atualBoxVideosAlfabeticos != 'mar' && atualizaBoxVideosAlfabeticos)	{
		document.getElementById('abas_menu').style.background = 'url(../img/menu_box_videos_alfabeticos.gif) no-repeat 0 -56px';
		atualBoxVideosAlfabeticos = 'mar';
		mostraVideosAlfabeticos('/central_de_videos/videos_alfabeticos.php?idx=mr');		
	}
}

function mostraVideosDeSaZ() {
	if (atualBoxVideosAlfabeticos != 'saz' && atualizaBoxVideosAlfabeticos)	{
		document.getElementById('abas_menu').style.background = 'url(../img/menu_box_videos_alfabeticos.gif) no-repeat 0 -85px';
		atualBoxVideosAlfabeticos = 'saz';
		mostraVideosAlfabeticos('/central_de_videos/videos_alfabeticos.php?idx=sz');		
	}
}

function mostraVideosAlfabeticos(pagina) {
	if (atualizaBoxVideosAlfabeticos) {
		atualizaBoxVideosAlfabeticos = false;
		document.getElementById('lista_videos_alfabeticos').innerHTML = '';
		document.getElementById('waiting_alfabeticos').style.display='block';
		if (window.XMLHttpRequest) {
			xmlhttp_va = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			xmlhttp_va = new ActiveXObject("Microsoft.XMLHTTP")
		}
		if (xmlhttp_va) {
			xmlhttp_va.onreadystatechange = handlerVideosAlfabeticos;
			xmlhttp_va.open('GET',pagina,true);
			xmlhttp_va.send('');
		} else {
			alert('Seu browser não suporta esse recurso.');	
		}
	}
}

function handlerVideosAlfabeticos() {
	if (xmlhttp_va.readyState == 4) {
		if (xmlhttp_va.status == 200) {
			html = '';
			json = eval(xmlhttp_va.responseText);
			for(i=0;i < json.length; i++) {
				if (typeof(json[i]) != 'undefined') {
					html = html + '<li>' + json[i]['data'] + ' - ' + '<a href="' + json[i]['url'] + '">' + json[i]['titulo'] + '</a></li>';									
				}
			}
			document.getElementById('waiting_alfabeticos').style.display='none';
			document.getElementById("lista_videos_alfabeticos").innerHTML = html;
			atualizaBoxVideosAlfabeticos = true;
		}
	}
}

//--------------------------------------------------------

var atualizaBoxTopsVideosAtivo=true;
var atualBoxTopsVideos='sugestoes';
function mostraSugestoesEditor() {
	if (atualBoxTopsVideos != 'sugestoes' && atualizaBoxTopsVideosAtivo) {
		document.getElementById('aba_on_sugestoes_editor').style.background = 'url(../img/menu_box_top_videos.gif) no-repeat 0 0';
		mostraTops('/central_de_videos/top_sugestoes_editor.php');
		atualBoxTopsVideos = 'sugestoes';
	}
}

function mostraTopVideosDia() {
	if (atualBoxTopsVideos != 'dia' && atualizaBoxTopsVideosAtivo) {
		document.getElementById('aba_on_sugestoes_editor').style.background = 'url(../img/menu_box_top_videos.gif) no-repeat 0 -23px';
		mostraTops('/central_de_videos/top_videos_dia.php');
		atualBoxTopsVideos = 'dia';
	}
}

function mostraTopVideosSemana() {
	if (atualBoxTopsVideos != 'semana' && atualizaBoxTopsVideosAtivo) {
		document.getElementById('aba_on_sugestoes_editor').style.background = 'url(../img/menu_box_top_videos.gif) no-repeat 0 -23px';
		mostraTops('/central_de_videos/top_videos_semana.php');
		atualBoxTopsVideos = 'semana';
	}
}

function mostraVideosRecentes() {
	if (atualBoxTopsVideos != 'recentes' && atualizaBoxTopsVideosAtivo) {
		document.getElementById('aba_on_sugestoes_editor').style.background = 'url(../img/menu_box_top_videos.gif) no-repeat 0 -46px';
		mostraTops('/central_de_videos/top_videos_recentes.php');
		atualBoxTopsVideos = 'recentes';
	}
}

function mostraTops(pagina) {
	erro=false;
	if (atualizaBoxTopsVideosAtivo) {
		atualizaBoxTopsVideosAtivo=false;
		document.getElementById('chamadas').innerHTML = '';
		document.getElementById('waiting').style.display='block';
		if (window.XMLHttpRequest) {
			xmlhttp_ss = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			xmlhttp_ss = new ActiveXObject("Microsoft.XMLHTTP")
		}
		if (xmlhttp_ss) {
			xmlhttp_ss.onreadystatechange = handlerTops;
			url = pagina + '?r=' + Math.random();
			xmlhttp_ss.open('GET',url,true);
			//setTimeout("xmlhttp_ss.send('')",500);
			xmlhttp_ss.send('');
		}
	}
}
function handlerTops() {
	if (xmlhttp_ss.readyState == 4) {
		if (xmlhttp_ss.status == 200) {
			try {
				if (xmlhttp_ss.responseText != '') {
					json = eval(xmlhttp_ss.responseText);
					atualizou = false;
					html_tops = '';
					for (i=0; i<json.length;i++) {
						if (typeof(json[i]) != 'undefined') {
							id_conteudo = json[i]['id_conteudo'];
							caminho_template_visualizacao = json[i]['caminho_template_visualizacao'];
							caminho_arquivo = json[i]['caminho_arquivo'];
							titulo = json[i]['titulo'];
							descricao = json[i]['descricao'];
							onclick = json[i]['onclick'];
							
							html_tops += '<div class="chamada">';
							html_tops += '<a href="' + caminho_template_visualizacao + '"' + onclick + '><img src="' + caminho_arquivo + '" /></a><a href="' + caminho_template_visualizacao + '" class="title"' + onclick + '>' + titulo + '</a><p>' + descricao + '</p>'
							html_tops += '</div>';
						}
					}
					document.getElementById('waiting').style.display='none';
					document.getElementById('chamadas').innerHTML = html_tops;
					atualizaBoxTopsVideosAtivo=true;
				}
			} catch(e) {
				document.getElementById('waiting').style.display='none';
				alert('Erro inesperado. Não foi possível atualizar.');
				atualizaBoxTopsVideosAtivo=true;
			}
		}
	}
}

function mostraPopVideo(path_video) {
	width = 758;
	height = 442;
	leftVal = (screen.width - width) / 2;
	topVal = (screen.height - height) / 3.5;
	window.open('/central_de_videos/video_pop.php?path_video=' + path_video,'video_pop_' + id_conteudo,'width=' + width + ',height=' + height + ',toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,top=' + topVal + ',left=' + leftVal);
	return false;
}

function destacaPlayer(path_video) {
	width = 466;
	height = 380;
	leftVal = (screen.width - width) / 2;
	topVal = (screen.height - height) / 3.5;
	window.open('/pop_player.php?path_video=' + path_video,'video_pop_','width=' + width + ',height=' + height + ',toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,top=' + topVal + ',left=' + leftVal);
	window.location = '/incs/inc_iframe_escolha_formato.php?flash=' + path_video + '';
	return false;
}

function destacaPlayerWide(path_video, tipo, titulo_video) {
	
	window.location.href = window.location.href + '&view=pop_wide';
	
}

function mostraPopPlayerWide(path_video, tipo, titulo_video) {
	width = 640;
	height = 415;
	leftVal = (screen.width - width) / 2;
	topVal = (screen.height - height) / 3.5;
	//window.open('/pop_player_wide.php?path_video=' + path_video + '&tipo=' + tipo + '&titulo_video=' + titulo_video,'video_pop_' + parseInt(Math.random()*100000)),'width=' + width + ',height=' + height + ',toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes,top=' + topVal + ',left=' + leftVal);
	window.open('/pop_player_wide.php?path_video=' + path_video + '&tipo=' + tipo + '&titulo_video=' + titulo_video, 'video_pop_', 'width=' + width + ',height=' + height + ',toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes,top=' + topVal + ',left=' + leftVal + '');
}

function destacaPlayer_wmv(path_video) {
	width = 365;
	height = 365;
	leftVal = (screen.width - width) / 2;
	topVal = (screen.height - height) / 3.5;
	window.open('/pop_player_wmv.php?path_video=' + path_video,'video_pop_','width=' + width + ',height=' + height + ',toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,top=' + topVal + ',left=' + leftVal);
	return false;
}

var ultimo_valor_mascara='';
function mascara(o,f){
	v_obj=o
	v_fun=f
	if (v_obj.value == ultimo_valor_mascara) {
		return;
	}
	ultimo_valor_mascara = v_obj.value;
	//setTimeout("execmascara()",1)
    execmascara();
}

function execmascara(){
	v_obj.value = v_fun(v_obj.value)
}

function data(v) {
	v = v.replace(/\D/g,"")
	v = v.replace(/(\d{2})(\d)/,"$1/$2")
	v = v.replace(/(\d{2})(\d)/,"$1/$2")
	return v
}

function alterData(data_ini, data_fim) {
	d_ini = document.getElementById('data_ini');
	d_fim = document.getElementById('data_fim');
	d_ini.value = data_ini;
	d_fim.value = data_fim;
	document.getElementById('frm_busca_acervo').submit();
}