// Funcoes Basicas

// troca a imagem de um objeto <IMG>
function trocaImagem( objeto, imagem ) {
	document.getElementById(objeto).src = imagem;
}

// solicita digitacao de informacao em campo TEXTO
function solicitaDigitacao ( objeto, textoPadrao ) {
	// se o objeto recebe foco e ainda nao possui informacoes digitadas
	// o script limpa o valor do objeto
	if (objeto.value == textoPadrao) {
		objeto.value = '';
	}
	// se o objeto perder o foco e nao possui informacoes digitadas
	// o script atribui o texto padrao ao valor do objeto
	else if (!objeto.value) {
		objeto.value = textoPadrao;
	}
	else
	{
		return true;
	}
}

// solicita digitacao de informacao em campo SENHA
function solicitaSenha ( objeto, textoPadrao ) {
	// se o objeto recebe foco e ainda nao possui informacoes digitadas
	// o script limpa o valor do objeto
	if (objeto.value == textoPadrao) {
		objeto.value = '';
		objeto.type = 'password';
	}
	// se o objeto perder o foco e nao possui informacoes digitadas
	// o script atribui o texto padrao ao valor do objeto
	else if (!objeto.value) {
		objeto.type = 'text';
		objeto.value = textoPadrao;
	}
	else
	{
		return true;
	}
}

//  mostra e esconde layers da publicidade full
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

// --------------------------------------------
// Funcao: mostraPopUp( caminho )
// --------------------------------------------
// Mostra um Pop Up com o conteudo informado no
// caminho
//
function mostraPopUp( caminho ){
	popUp = window.open(caminho,"","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=1, resizable=no, copyhistory=no, width=490, height=545");
	popUp.moveTo(250, 80);
}

// popup para mostrar fotos das noticias do site
function mostraImagem( nomeConteudo, idConteudo ){
	popUp = window.open("./popupImagem.php?" + nomeConteudo +"=" + idConteudo,"","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=600, height=490");
	popUp.moveTo(250, 80);
}

// popup para player
function popupPlayer( nomeConteudo, idaudio ){
	popUp = window.open("./popupPlayer.php?" + nomeConteudo +"=" + idaudio,"","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=308, height=365");
	popUp.moveTo(250, 80);
}

// popup para player
function popupAudioPlayer( nomeConteudo, idaudio ){
	popUp = window.open("../popupPlayer.php?" + nomeConteudo +"=" + idaudio,"","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=308, height=365");
	popUp.moveTo(250, 80);
}

// popup para player
function popupAdminPlayer( nomeConteudo, idaudio ){
	popUp = window.open("../popupPlayerProducao.php?" + nomeConteudo +"=" + idaudio,"","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=308, height=365");
	popUp.moveTo(250, 80);
}

// popup para player CD
function popupAdminPlayerCd( tipoConteudo, nomeConteudo, idaudio ){
	popUp = window.open("../popupPlayerCd.php?tipo=" + tipoConteudo + "&" + nomeConteudo +"=" + idaudio,"","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=308, height=295");
	popUp.moveTo(250, 80);
}

// popup para player CD
function popupPlayerCd( tipoConteudo, nomeConteudo, idaudio ){
	popUp = window.open("./popupPlayerCd.php?tipo=" + tipoConteudo + "&" + nomeConteudo +"=" + idaudio,"","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=308, height=295");
	popUp.moveTo(250, 80);
}

// popup para player audio produção
function popupPlayerProducao( nomeConteudo, idaudio ){
	popUp = window.open("./popupPlayerProducao.php?" + nomeConteudo +"=" + idaudio,"","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=308, height=365");
	popUp.moveTo(250, 80);
}

// --------------------------------------------
// Funcao: retornaSelecao
// --------------------------------------------
// Retorna valores de lista selecao multipla
//
// formDados : formulario
// opSel : lista de selecao
// opRetorno : variavel de retorno da selecao
function retornaSelecao ( formDados, opSel, opRetorno ) {
	
	var formulario = "document." + formDados;
	var tamSelecao = eval(formulario + "." + opSel + ".length");
	var retSelecao = eval(formulario + "." + opRetorno);
	var opSelecao = '';
	
	for (var i = 0; i < tamSelecao; i++) {
		if( eval(formulario + "." + opSel + ".options[" + i + "].selected") == true ) {
			opSelecao = eval(formulario + "." + opSel + ".options[" + i + "]" + ".value") + "," +opSelecao;
		}
	}
	opSelecao = opSelecao;
	retSelecao.value = opSelecao;
}

/* 
   ::: marcarCheckbox( matrizCheckbox, opcao ) :::
		Objetivo:	Marcar / Desmarcar os checkboxes da matrizCheckbox
					indicada.
		Variaveis:
					formulario			: Texto		:	Nome do formulario onde esta a matriz
					matrizCheckbox		: Texto		:	Nome da matriz de checkboxres
					opcao				: Inteiro	:	0 = desmarcar / 1 = marcar
*/
function marcarCheckbox( formulario, matrizCheckbox, opcao) {
	var elementos = eval("document." + formulario + ".elements");

	for (var i=0; i < elementos.length; i++) {
		if (elementos[i].name == matrizCheckbox){		
			if (opcao){
				elementos[i].checked = true;
			} else {
				elementos[i].checked = false;
			}
		}
	}
	
}

function urlencode( str ) {
 
    var histogram = {}, tmp_arr = [];
    var ret = (str+'').toString();
 
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
 
    // The histogram is identical to the one in urldecode.
    histogram["'"]   = '%27';
    histogram['(']   = '%28';
    histogram[')']   = '%29';
    histogram['*']   = '%2A';
    histogram['~']   = '%7E';
    histogram['!']   = '%21';
    histogram['%20'] = '+';
    histogram['\u20AC'] = '%80';
    histogram['\u0081'] = '%81';
    histogram['\u201A'] = '%82';
    histogram['\u0192'] = '%83';
    histogram['\u201E'] = '%84';
    histogram['\u2026'] = '%85';
    histogram['\u2020'] = '%86';
    histogram['\u2021'] = '%87';
    histogram['\u02C6'] = '%88';
    histogram['\u2030'] = '%89';
    histogram['\u0160'] = '%8A';
    histogram['\u2039'] = '%8B';
    histogram['\u0152'] = '%8C';
    histogram['\u008D'] = '%8D';
    histogram['\u017D'] = '%8E';
    histogram['\u008F'] = '%8F';
    histogram['\u0090'] = '%90';
    histogram['\u2018'] = '%91';
    histogram['\u2019'] = '%92';
    histogram['\u201C'] = '%93';
    histogram['\u201D'] = '%94';
    histogram['\u2022'] = '%95';
    histogram['\u2013'] = '%96';
    histogram['\u2014'] = '%97';
    histogram['\u02DC'] = '%98';
    histogram['\u2122'] = '%99';
    histogram['\u0161'] = '%9A';
    histogram['\u203A'] = '%9B';
    histogram['\u0153'] = '%9C';
    histogram['\u009D'] = '%9D';
    histogram['\u017E'] = '%9E';
    histogram['\u0178'] = '%9F';
 
    // Begin with encodeURIComponent, which most resembles PHP's encoding functions
    ret = encodeURIComponent(ret);
 
    for (search in histogram) {
        replace = histogram[search];
        ret = replacer(search, replace, ret) // Custom replace. No regexing
    }
 
    // Uppercase for full PHP compatibility
    return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
        return "%"+m2.toUpperCase();
    });
 
    return ret;
}
 
 
function urldecode( str ) {
 
    var histogram = {};
    var ret = str.toString();
 
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
 
    // The histogram is identical to the one in urlencode.
    histogram["'"]   = '%27';
    histogram['(']   = '%28';
    histogram[')']   = '%29';
    histogram['*']   = '%2A';
    histogram['~']   = '%7E';
    histogram['!']   = '%21';
    histogram['%20'] = '+';
    histogram['\u20AC'] = '%80';
    histogram['\u0081'] = '%81';
    histogram['\u201A'] = '%82';
    histogram['\u0192'] = '%83';
    histogram['\u201E'] = '%84';
    histogram['\u2026'] = '%85';
    histogram['\u2020'] = '%86';
    histogram['\u2021'] = '%87';
    histogram['\u02C6'] = '%88';
    histogram['\u2030'] = '%89';
    histogram['\u0160'] = '%8A';
    histogram['\u2039'] = '%8B';
    histogram['\u0152'] = '%8C';
    histogram['\u008D'] = '%8D';
    histogram['\u017D'] = '%8E';
    histogram['\u008F'] = '%8F';
    histogram['\u0090'] = '%90';
    histogram['\u2018'] = '%91';
    histogram['\u2019'] = '%92';
    histogram['\u201C'] = '%93';
    histogram['\u201D'] = '%94';
    histogram['\u2022'] = '%95';
    histogram['\u2013'] = '%96';
    histogram['\u2014'] = '%97';
    histogram['\u02DC'] = '%98';
    histogram['\u2122'] = '%99';
    histogram['\u0161'] = '%9A';
    histogram['\u203A'] = '%9B';
    histogram['\u0153'] = '%9C';
    histogram['\u009D'] = '%9D';
    histogram['\u017E'] = '%9E';
    histogram['\u0178'] = '%9F';
 
    for (replace in histogram) {
        search = histogram[replace]; // Switch order when decoding
        ret = replacer(search, replace, ret) // Custom replace. No regexing   
    }
 
    // End with decodeURIComponent, which most resembles PHP's encoding functions
    ret = decodeURIComponent(ret);
 
    return ret;
}

