// Funções diversas
var ffX, ffY;

function pegacoordenadas(e){
	if(document.all)e = event;
	ffX = e.clientX;
	ffY = e.clientY
}
document.documentElement.onmousemove =  pegacoordenadas;


function trocafundo(obj,flag)
{
	var f_ativo = '#ffead5';
	var t_ativo = '#000000';

	var f_inativo = '#eeeeee';
	var t_inativo = '#666666';
	
	if(flag == 1){ // se for ativo
		obj.style.background = f_ativo;
		obj.style.color      = t_ativo;
	}else if(flag == 0){ // se for inativo
		obj.style.background = f_inativo;
		obj.style.color      = t_inativo;
	}
}

function trocafundob(obj,flag)
{
	var f_ativo = '#ff6600';
	var t_ativo = '#ffffff';

	var f_inativo = '#eeeeee';
	var t_inativo = '#000000';
	
	if(flag == 1){ // se for ativo
		obj.style.background = f_ativo;
		obj.style.border     = 'solid 2px #000000';
		obj.style.color      = t_ativo;
	}else if(flag == 0){ // se for inativo
		obj.style.background = f_inativo;
		obj.style.color      = t_inativo;
		obj.style.border     = 'solid 2px #666666';
	}
}

function navegador()
{
	if(navigator.appName.indexOf('Explorer') > -1)
		nav = 'IE';
	else if(navigator.appName.indexOf('Opera') > -1)
		nav = 'OP';
	else
		nav = 'FF';

	return nav;
}

function elemento(id)
{
	if(document.getElementById){
		return document.getElementById(id);
	}else if(document.all){
		return document.all(id);
	}else if(document.layers){
		return document.layers[id];
	}else if(document.getElementByName){
		return document.getElementByName(id);
	}

	return false;
}

function seta_ajax()
{
	var ajaxObj = null;

	try{
		// Firefox, Opera 8.0+, Safari...
		ajaxObj=new XMLHttpRequest();
	}catch (e){
		// Internet Explorer
		try{
			ajaxObj=new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e){
			try{
				ajaxObj=new ActiveXObject("Microsoft.XMLHTTP");
			}catch (e){
				alert("Seu navegador não possui suporte ao AJAX!");
			}
		}
	}

	return ajaxObj;
}

function entities2html(str)
{
	var values = new Array("&", " ", "¡", "¢", "£", "¤", "¥", "¦", "§", "¨", "©", "ª", "«", "¬", "­", "®", "¯", "°", "±", "²", "³", "´", "µ", "¶", "·", "¸", "¹", "º", "»", "¼", "½", "¾", "¿", "À", "Á", "Â", "Ã", "Ä", "Å", "Æ", "Ç", "È", "É", "Ê", "Ë", "Ì", "Í", "Î", "Ï", "Ð", "Ñ", "Ò", "Ó", "Ô", "Õ", "Ö", "×", "Ø", "Ù", "Ú", "Û", "Ü", "Ý", "Þ", "ß", "à", "á", "â", "ã", "ä", "å", "æ", "ç", "è", "é", "ê", "ë", "ì", "í", "î", "ï", "ð", "ñ", "ò", "ó", "ô", "õ", "ö", "÷", "ø", "ù", "ú", "û", "ü", "ý", "þ", "ÿ", "\"", "<", ">", "");
	var keys   = new Array("&amp;", " ", "&iexcl;", "&cent;", "&pound;", "&curren;", "&yen;", "&brvbar;", "&sect;", "&uml;", "&copy;", "&ordf;", "&laquo;", "&not;", "&shy;", "&reg;", "&macr;", "&deg;", "&plusmn;", "&sup2;", "&sup3;", "&acute;", "&micro;", "&para;", "&middot;", "&cedil;", "&sup1;", "&ordm;", "&raquo;", "&frac14;", "&frac12;", "&frac34;", "&iquest;", "&Agrave;", "&Aacute;", "&Acirc;", "&Atilde;", "&Auml;", "&Aring;", "&AElig;", "&Ccedil;", "&Egrave;", "&Eacute;", "&Ecirc;", "&Euml;", "&Igrave;", "&Iacute;", "&Icirc;", "&Iuml;", "&ETH;", "&Ntilde;", "&Ograve;", "&Oacute;", "&Ocirc;", "&Otilde;", "&Ouml;", "&times;", "&Oslash;", "&Ugrave;", "&Uacute;", "&Ucirc;", "&Uuml;", "&Yacute;", "&THORN;", "&szlig;", "&agrave;", "&aacute;", "&acirc;", "&atilde;", "&auml;", "&aring;", "&aelig;", "&ccedil;", "&egrave;", "&eacute;", "&ecirc;", "&euml;", "&igrave;", "&iacute;", "&icirc;", "&iuml;", "&eth;", "&ntilde;", "&ograve;", "&oacute;", "&ocirc;", "&otilde;", "&ouml;", "&divide;", "&oslash;", "&ugrave;", "&uacute;", "&ucirc;", "&uuml;", "&yacute;", "&thorn;", "&yuml;", "&quot;", "&lt;", "&gt;", "");

	for(var i=0; i<keys.length; i++)
	{
		if(values[i]!=" "){str=str.replace(keys[i], values[i]);}
	}
	return str;
}

function exibe_mensagem(pFlag)
{
	var obj = document.getElementById('msgipb');
	
	$nav = navegador();

	if(pFlag == 1){
		if(nav == 'IE'){
			obj.style.left   = event.x + 35;
			obj.style.top   = event.y;
			obj.style.filter = 'alpha(Opacity=85)';
		}else{
			obj.style.left    = (ffX + 35).toString()+'px';
			obj.style.top     = (ffY).toString()+'px';
			obj.style.opacity = '0.85';
		}

		obj.style.display = 'block';
	}else{
		obj.style.display = 'none';
	}
}


// Funções de visualização de imagens, áudio e vídeo
function abre_imagem(pImagem, pLegenda, pLarg, pAlt)
{
	var obj = elemento('palco'), largPagina = null, altPagina = null, imgLeft = null, nav = navegador();

	largPagina = document.body.clientWidth+(nav == 'IE' ? 19 : 15);
	altPagina  = document.body.clientHeight;
	topo       = (nav == 'IE' ? document.documentElement.scrollTop : window.pageYOffset);
	imgLeft    = (largPagina/2) - (pLarg/2);

	escurece();

	obj.style.left       = imgLeft.toString()+'px';
	obj.style.top        = (topo+10).toString()+'px';
	obj.style.background = '#ffffff';
	obj.style.border     = 'solid 5px #006d33';
	obj.style.padding    = '10px';
	obj.style.textAlign  = 'center';
	obj.innerHTML       += '<img src="'+pImagem+'" onClick="fechar();" style="cursor:pointer;" title="Clique para fechar." alt=""><br /><br />';
	obj.innerHTML       += '<span class="legenda">'+pLegenda+'</span>';
	obj.style.display    = 'block';
	
}

function assiste(pArquivo)
{
	var obj = elemento('palco'), largPagina = null, altPagina = null, pLarg = null, imgLeft = null, nav = navegador();

	pLarg = 320;

	largPagina = document.body.clientWidth+(nav == 'IE' ? 19 : 15);
	altPagina  = document.body.clientHeight;
	topo       = (nav == 'IE' ? document.documentElement.scrollTop : window.pageYOffset);
	imgLeft    = (largPagina/2) - (pLarg/2);

	escurece();

	obj.style.left       = imgLeft.toString()+'px';
	obj.style.top        = (topo+10).toString()+'px';
	obj.style.background = '#ffffff';
	obj.style.border     = 'solid 5px #006d33';
	obj.style.padding    = '10px';
	obj.style.textAlign  = 'center';
	obj.innerHTML       += entities2html(pArquivo);
	obj.innerHTML       += '<br /><br /><a href="javascript:fechar()">FECHAR</a>';
	obj.style.display    = 'block';
	
}

function ouvir(pArquivo,pLegenda)
{
	var obj = elemento('palco'), largPagina = null, pLarg = null, altPagina = null, imgLeft = null, nav = navegador();
	
	pLarg = 300;
	
	largPagina = document.body.clientWidth+(nav == 'IE' ? 19 : 15);
	altPagina  = document.body.clientHeight;
	topo       = (nav == 'IE' ? document.documentElement.scrollTop : window.pageYOffset);
	imgLeft    = (largPagina/2) - (pLarg/2);

	escurece();

	obj.style.left       = imgLeft.toString()+'px';
	obj.style.top        = (topo+100).toString()+'px';
	obj.style.background = '#ffffff';
	obj.style.border     = 'solid 5px #006d33';
	obj.style.padding    = '10px';
	obj.style.textAlign  = 'center';

	obj.innerHTML       += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="300" height="70">';
	obj.innerHTML       += '	<param name="movie" value="flash/player.swf?arquivo='+pArquivo+'&legenda='+pLegenda+'" />';
	obj.innerHTML       += '	<param name="quality" value="high" />';
	obj.innerHTML       += '	<embed src="flash/player.swf?arquivo='+pArquivo+'&legenda='+pLegenda+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="300" height="70"></embed>';
	obj.innerHTML       += "</object>";
	obj.innerHTML       += '<br /><br /><a href="javascript:fechar()">FECHAR</a>';

	obj.style.display    = 'block';
}

function escurece()
{
	var obj = elemento('escuro'), largJanela = null, altJanela = null, nav = navegador();

	largJanela = document.body.clientWidth+(nav == 'IE' ? 19 : 15);
	altJanela  = document.documentElement.clientHeight;
	topo       = (nav == 'IE' ? document.documentElement.scrollTop : window.pageYOffset);
	
	obj.style.background = '#000000';
	if(nav == 'IE')
		obj.style.filter = 'alpha(opacity=80)';
	else
		obj.style.opacity = '0.8';
	obj.style.left       = 0;
	obj.style.top        = topo.toString()+'px';
	obj.style.width      = largJanela.toString()+'px';
	obj.style.height     = altJanela.toString()+'px';
	obj.style.display    = 'block';
}

function fechar()
{
	obj1 = elemento('palco'); obj2 = elemento('escuro');
	
	obj1.innerHTML = ''; obj1.style.display = 'none';
	obj2.style.display = 'none';
}
