function confirmar(url,evento){
	if(confirm('Confirma '+evento)){
		window.location=url;
	}
}
function mostraFoto(idFoto) {
	obj = document.getElementById(idFoto);
	obj.style.display = 'block';
}

function ocultaFoto(idFoto) {
	obj = document.getElementById(idFoto);
	obj.style.display = 'none';
}

function loadXMLDoc(url,dado,valor)
{
    req = null;
    // Procura por um objeto nativo (Mozilla/Safari)
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url+"?"+dado+"="+valor, true);
        req.send(null);
    // Procura por uma versao ActiveX (IE)
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET",url+"?"+dado+"="+valor, true);
            req.send();
        }
    }
}


function processReqChange()
{
    // apenas quando o estado for "completado"
    if (req.readyState == 4) {
        // apenas se o servidor retornar "OK"
        if (req.status == 200) {
            // procura pela div id="atualiza" e insere o conteudo
            // retornado nela, como texto HTML
//			alert(_div);
            document.getElementById(_div).innerHTML = req.responseText;
        } else {
            alert("Houve um problema ao obter os dados:\n" + req.statusText);
        }
    }

}

function atualiza(valor,dado,div,url)
{
    _div = div;

    loadXMLDoc(url,dado,valor);
}


function loadXMLDoc2(url,dado,valor)
{
    req2 = null;
    // Procura por um objeto nativo (Mozilla/Safari)
    if (window.XMLHttpRequest) {
        req2 = new XMLHttpRequest();
        req2.onreadystatechange = processReqChange2;
        req2.open("GET", url+"?"+dado+"="+valor, true);
        req2.send(null);
    // Procura por uma versao ActiveX (IE)
    } else if (window.ActiveXObject) {
        req2 = new ActiveXObject("Microsoft.XMLHTTP");
        if (req2) {
            req2.onreadystatechange = processReqChange2;
            req2.open("GET",url+"?"+dado+"="+valor, true);
            req2.send();
        }
    }
}


function processReqChange2()
{
    // apenas quando o estado for "completado"
    if (req2.readyState == 4) {
        // apenas se o servidor retornar "OK"
        if (req2.status == 200) {
            // procura pela div id="atualiza" e insere o conteudo
            // retornado nela, como texto HTML
            document.getElementById(_div2).innerHTML = document.getElementById(_div2).innerHTML + req2.responseText;
        } else {
            alert("Houve um problema ao obter os dados:\n" + req2.statusText);
        }
    }

}


function atualiza2(valor,dado,div,url)
{
    _div2 = div;

    loadXMLDoc2(url,dado,valor);
}


function refresh()
{
    window.location='index.php';
}

function exibeOculto(objeto, objck) {
	obj = document.getElementById(objeto);
	obj.style.display = 'block';


	check = document.getElementById(objck.name);

	if(check.checked) {
		ck1 = document.getElementById('inserir-'+objck.name);
		ck1.checked = 'checked';

		ck2 = document.getElementById('alterar-'+objck.name);
		ck2.checked = 'checked';

		ck3 = document.getElementById('remover-'+objck.name);
		ck3.checked = 'checked';
	} else {
		ck1 = document.getElementById('inserir-'+objck.name);
		ck1.checked = '';

		ck2 = document.getElementById('alterar-'+objck.name);
		ck2.checked = '';

		ck3 = document.getElementById('remover-'+objck.name);
		ck3.checked = '';

		obj.style.display = 'none';
	}
}


function exibeOpcoes(objeto, objck) {

	obj = document.getElementById(objeto);
	obj.style.display = 'block';


	check = document.getElementById(objck.name);

	if(check.checked) {
		for (i=1;i<=maxcanal.value;i++)
		{
			document.getElementById(objck.name+'-remover-'+i).checked='checked';
			document.getElementById(objck.name+'-inserir-'+i).checked='checked';
			document.getElementById(objck.name+'-alterar-'+i).checked='checked';
		}
	} else {
		for (i=1;i<=maxcanal.value;i++)
		{
			document.getElementById(objck.name+'-remover-'+i).checked='';
			document.getElementById(objck.name+'-inserir-'+i).checked='';
			document.getElementById(objck.name+'-alterar-'+i).checked='';
		}

		obj.style.display = 'none';
	}
}

//###################################################//
//###### PACOTE DE FUNÇÕES PARA ALBUM DINAMICO ######//
//###################################################//


function carrega_foto_principal(array, indice, foto_principal_div){
	if(!foto_principal_div){foto_principal_div = "foto_principal";}
	foto_principal(foto_principal_div, array[indice], indice);
}

function foto_principal(foto_principal_div, img, indice, slideshow, ultimo){
	if(slideshow){
		if(!ultimo){
			document.getElementById("slideshow_letreiro").style.display = "none";
		}
		else{
			document.getElementById("slideshow_letreiro").style.display = "block";
		}
	}

	var publisher_url 	= document.getElementById("publisher_url").value;
	var array_config 	= document.getElementById("config_foto_principal").value.split(";");
	var largura_foto 	= array_config[0];
	var altura_foto 	= array_config[1];

	document.getElementById(foto_principal_div).style.background = "url('"+publisher_url+"/thumb.php?img="+img+"&w="+largura_foto+"&h="+altura_foto+"') no-repeat";
	document.getElementById(foto_principal_div).style.backgroundPosition = "center center";

	if(document.getElementById('array_alts')){
		var array_alts = document.getElementById('array_alts').value.split("|");
		document.getElementById(foto_principal_div).title = array_alts[indice];
	}

//	document.getElementById(foto_principal_div).innerHTML = publisher_url+"/thumb.php?img="+img+"&w="+largura_foto+"&h="+altura_foto;
	//deve haver um campo hidden com o mesmo nome do div da img principal + _hidden
	document.getElementById(foto_principal_div + "_hidden").value = indice;
	if(document.getElementById('fotolegenda')){
		var array_legendas = document.getElementById('array_legendas').value.split("|");
		document.getElementById('fotolegenda').innerHTML = array_legendas[indice];
	}
}


function proxima_foto(array, foto_principal_div){
	var indice_atual = parseInt(document.getElementById(foto_principal_div + "_hidden").value);
	if(array[indice_atual+1]){
		carrega_foto_principal(array, indice_atual+1);
	}
	else{
		carrega_foto_principal(array, 0);
	}
}

function anterior_foto(array, foto_principal_div){
	var indice_atual = parseInt(document.getElementById(foto_principal_div + "_hidden").value);
	if(array[indice_atual-1]){
		carrega_foto_principal(array, indice_atual-1);
	}
	else{
		carrega_foto_principal(array, array.length-1);
	}
}

function carrega_thumbs(array, indice, caixa_thumbs_ul, array_botoes, foto_principal_div){
	var publisher_url = document.getElementById("publisher_url").value;
	var array_config = document.getElementById("config_album").value.split(";");
	var largura = array_config[0];
	var altura = array_config[1];
	var limitador = array_config[2];

	if(!largura){largura = 90};
	if(!altura){altura = 90};
	if(!limitador){limitador = 4};

	if(array.length < 2){
		for(b=0; b < array_botoes.length; b++){
			document.getElementById(array_botoes[b]).style.display = "none";
		}
	}

	if(!foto_principal_div){foto_principal_div = "foto_principal"};

	if(indice < 0){
		indice = array.length + parseInt(indice);
	}
	if(indice >= array.length){
		indice = 0;
	}

	var str_html = "";
	var array_caixa = new Array();
	var ultimo_indice = indice-1;

	if(array.length < limitador){
		limitador = array.length;
	}

	for(x=0; x<limitador; x++){
		if(array[indice+x]){
			str_html += "<li><a href=\" javascript:carrega_foto_principal(array_imagens, "+(indice+x)+") \" onclick=\"thumbIDFOTO('" + array[indice+x] + "');\"><img src=\""+publisher_url+"/thumb.php?img="+array[indice+x]+"&w="+largura+"&h="+altura+"\" /></a></li>";
			ultimo_indice = indice+x;
			array_caixa[x] = indice+x;
		}
		else{
			if(html_temp = pega_thumb(array, ultimo_indice, array_caixa)){
				ultimo_indice = html_temp[0]
				str_html += html_temp[1];
			}
		}
	}

	document.getElementById(caixa_thumbs_ul).innerHTML = str_html;
	carrega_foto_principal(array, indice);
	document.getElementById(caixa_thumbs_ul+"_hidden").value = indice;
	if(limitador == 1){
		document.getElementById(caixa_thumbs_ul).style.display = 'none';
	}
}

function pega_thumb(array, indice, lista, largura, altura){

	var publisher_url = document.getElementById("publisher_url").value;
	var array_config = document.getElementById("config_album").value.split(";");
	var largura = array_config[0];
	var altura = array_config[1];

	if(!largura){ largura = 90};
	if(!altura){ altura = 90};

	array_retorno = new Array();
	if((indice+1) >= array.length){
		y = 0;
		pega = false;
		html = "";
		while(y < array.length && pega == false){
			if(!procura_array(lista,y)){
				html += "<li><a href=\" javascript:carrega_foto_principal(array_imagens, "+y+") \"><img src=\""+publisher_url+"/thumb.php?img="+array[y]+"&w="+largura+"&h="+altura+"\" /></a></li>";
				pega = true;
			}
			y++;
		}
		if(html){
			array_retorno[0] = y;
			array_retorno[1] = html;
			return array_retorno;
		}
		else{
			return false;
		}
	}
	else if(array[indice+1]){
		array_retorno[0] = indice+1;
		array_retorno[1] = "<li><a href=\" javascript:carrega_foto_principal(array_imagens, "+indice+") \"><img src=\""+publisher_url+"/thumb.php?img="+array[indice]+"&w="+largura+"&h="+altura+"\" /></a></li>";
		return array_retorno;
	}
	else if((indice+1) < array.length){
		return pega_thumb(array, indice+1, lista);
	}
}

function procura_array(array,elm){
	achou = false;
	for(z=0; z<array.length; z++){
		if(array[z] == elm){
			achou = true;
		}
	}
	return achou;
}

function separarIdFoto(valor)
{
		if(typeof valor != "undefined"){

			var parts = valor.split("/");
			var total = parts.length;
			var indice = total - 1;
			var valor2 = parts[indice];
			var parts2 = valor2.split(".");
			return parts2[0];

		}

}

function thumbIDFOTO(foto)
{
		var ID = separarIdFoto(foto);
		call_omniture(ID);
}

function call_omniture ( image_id ) {
 if( typeof uol_sc != "undefined" && (typeof uol_sc.t).toLowerCase() == 'function' ){
	uol_sc.prop5 = "fotoId=" + image_id ;
	uol_sc.t();
 }
}


function anterior_thumbs(array, caixa_thumbs_ul){

	var publisher_url = document.getElementById("publisher_url").value;
	var ultimo_indice = document.getElementById(caixa_thumbs_ul+"_hidden").value;
	var IDimg = separarIdFoto(array[parseInt(ultimo_indice) - parseInt(1)]);
	carrega_thumbs(array,parseInt(ultimo_indice) - parseInt(1),caixa_thumbs_ul, publisher_url, array_botoes);
	call_omniture(IDimg);
}


function proximo_thumbs(array, caixa_thumbs_ul){
	var publisher_url = document.getElementById("publisher_url").value;
	var ultimo_indice = document.getElementById(caixa_thumbs_ul+"_hidden").value;
	var ultimo_indice = parseInt(ultimo_indice) + parseInt(1);
	var IDimg = separarIdFoto(array[ultimo_indice]);
	carrega_thumbs(array,ultimo_indice,caixa_thumbs_ul, publisher_url, array_botoes);
	call_omniture(IDimg);
}

function slideshow(array_imagens, foto_principal_div){
	if(!foto_principal_div){foto_principal_div = "foto_principal";}
	delay = 0;
	for(x=0; x<array_imagens.length; x++){
		if(x >= (array_imagens.length-1)){
			ultimo = false;
		}
		else{
			ultimo = true;
		}
		img = array_imagens[x];
		slideshowTimeout(foto_principal_div, img, x, delay, ultimo);
		delay += 4000;
	}
}

function slideshowTimeout(foto_principal_div, img, indice, delay, ultimo){
	setTimeout("foto_principal('"+foto_principal_div+"', '"+img+"', "+x+", 'ok', "+ultimo+");", delay);
}


//###################################################//
//#### FIM PACOTE DE FUNÇÕES PARA ALBUM DINAMICO ####//
//###################################################//


function tamanhofonte(op, div) {

	if(!div){div = "text_mat";}

	var incremento = 2;
	var local_alterado = document.getElementById("texto_mat");
	var ar_font = local_alterado.getElementsByTagName("font");
	var ar_font2 = local_alterado.getElementsByTagName("p");
	var ar_font3 = local_alterado.getElementsByTagName("span");

	if (op == "mais") {
		executa_tamanho(ar_font, 15, +2);
		executa_tamanho(ar_font2, 15, +2);
		executa_tamanho(ar_font3, 15, +2);
	} else {
		executa_tamanho(ar_font, 14, -2);
		executa_tamanho(ar_font2, 14, -2);
		executa_tamanho(ar_font3, 14, -2);
	}
}


function executa_tamanho(array, media, fator){
	for(x=0; x < array.length; x++){
		if(!array[x].style.fontSize){
			array[x].style.fontSize = media + "px";
		}
		else{
			array[x].style.fontSize = parseInt(array[x].style.fontSize) + fator + "px";
		}
	}
}

function validaComentario(form) {
	if(form.nome.value == ""){
		alert("Por favor, preencha o campo nome.");
		form.nome.focus();
		return false;
	}
	if(form.email.value == ""){
		alert("Por favor, preencha o campo email.");
		form.email.focus();
		return false;
	}
	if(form.texto.value == ""){
		alert("Por favor, preencha o campo comentário.");
		form.texto.focus();
		return false;
	}
	if(!form.email.value.validaEmail()){
		alert("E-mail inválido!");
		form.email.focus();
		return false;
	}
	return true;

}


//var xmlhttp;
function adicionaPlaylist(url){
	xmlhttp=null;
	if (window.XMLHttpRequest){
		// code for all new browsers
		xmlhttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject){
		// code for IE5 and IE6
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp!=null){
		xmlhttp.onreadystatechange=adicionaPlaylistResponse;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	}
	else{
		alert("Seu navegador não suporta XMLHTTP.");
	}
}

function jsa(url){
	xmlhttp=null;
	if (window.XMLHttpRequest){
		// code for all new browsers
		xmlhttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject){
		// code for IE5 and IE6
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp!=null){
		xmlhttp.onreadystatechange=handleHttpResponse;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	}
	else{
		alert("Seu navegador não suporta XMLHTTP.");
	}
}

function handleHttpResponse(){
	if (xmlhttp.readyState==4){
		// 4 = carregado
		if (xmlhttp.status==200){
		// 200 = OK
		}
		else{
			alert("Houve um problema com XMLHTTP");
		}
	}
}

function adicionaPlaylistResponse(){
	if (xmlhttp.readyState==4){
		// 4 = carregado
		if (xmlhttp.status==200){
			// 200 = OK
			//debug
			dados = xmlhttp.responseText.split("|");
			if(dados[0] == "1"){
				add_li('ul_minhaplaylist', dados[3]);
			}
			if(dados[1]){
				alert(dados[1]);
			}
			if(dados[2]){
				document.getElementById('count_playlist').innerHTML = dados[2];
			}

		}
		else{
			alert("Houve um problema com XMLHTTP");
		}
	}
}


function add_li(lista, texto) {
	var lista = document.getElementById(lista);
	var li = document.createElement("li");
	li.innerHTML = texto;
	lista.appendChild(li);
}

function f_dinamica(url){
	xmlhttp=null;
	if (window.XMLHttpRequest){
		// code for all new browsers
		xmlhttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject){
		// code for IE5 and IE6
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp!=null){
		xmlhttp.onreadystatechange=f_dinamicaResponse;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	}
	else{
		alert("Seu navegador não suporta XMLHTTP.");
	}
}

function f_dinamicaResponse(){
	if (xmlhttp.readyState==4){
		// 4 = carregado
		if (xmlhttp.status==200){
		// 200 = OK
			array_dados = xmlhttp.responseText.split("|");
			eval(array_dados[0]+"(array_dados[1])");
		}
		else{
			alert("Houve um problema com XMLHTTP");
		}
	}
}

function aviso_processo(str){
	dados = str.split("#");
	document.getElementById('nota_avaliacao').innerHTML = "<span>Nota: "+dados[0]+"</span>";
	document.getElementById('li_avaliacao').innerHTML = "<span>"+dados[1]+"</span>";
}

function mostraComentarios(str){
	dados = str.split("#");
	var primeira = 0;
	var proximoUrl = dados[2];
	var prox = "";
	var proximo = proximoUrl.split("/");

	var total = proximo[7];
	var pg = proximo[6];
	if(total < 10){
		 primeira = 1;

	}
	var anteriorUrl = dados[1];
	var ant = "";
	var anterior = anteriorUrl.split("/");
	var totalAnt = anterior[7];
	var pgAnt = anterior[6];



	if(total > pg && primeira == 0){

		prox = "<span><a href=\"" + dados[2] + "\" title=\"próximas\">pr&oacute;ximas</a></span><a href=\"" + dados[2] + "\" title=\"próximas\"><img src=\"/imagens/" + dados[3] + "/layout/setas_proximas_cinza.gif\" alt=\"próximas\" /></a>";
	}
	if(pgAnt < 0){

		prox = "<span><a href=\"" + dados[2] + "\" title=\"próximas\">pr&oacute;ximas</a></span><a href=\"" + dados[2] + "\" title=\"próximas\"><img src=\"/imagens/" + dados[3] + "/layout/setas_proximas_cinza.gif\" alt=\"próximas\" /></a>";
	}
	if(pg > 5){
		ant = "<a href=\"" + dados[1] + "\" title=\"anteriores\"><img src=\"/imagens/" + dados[3] + "/layout/setas_anteriores_cinza.gif\" alt=\"anteriores\" /></a>	<span><a href=\"" + dados[1] + "\" title=\"anteriores\">anteriores</a>";

	}

	document.getElementById('listacomentarios').innerHTML = dados[0];

	document.getElementById('linkanterior').innerHTML = ant+"</span>";

	document.getElementById('linkposterior').innerHTML = prox;

}

function canais_cont_int(str) {
	document.getElementById('canais_cont_int').innerHTML = str;
}

function acendeBotao(pai, selected) {

	pai = document.getElementById(pai);
	if (pai.hasChildNodes)
	{
	   var children = pai.childNodes;
	   for (var i = 0; i < children.length; i++)
	   {
	   		children[i].className="";
	   };
	   selected.className="selected";
 	};
}


String.prototype.trim = function(){
	return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

String.prototype.removeStr = function(ocorrencia){
	var padrao = RegExp(ocorrencia, "g");
	return this.replace(padrao, "");
}

String.prototype.validaEmail = function(){
	var padrao=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
	if(padrao.test(this)){
		return true;
	}
	else{
		return false;
	}
}


function showInteracoes (id) {

	obj = document.getElementById(id);
	if (obj.className == "show") {
		obj.className = "hide";
	} else {
		document.getElementById("assinar").className = "hide";
		document.getElementById("envieporemail").className = "hide";
		document.getElementById("entrenoemail").className = "hide";
		document.getElementById("comunicarerros").className = "hide";
		obj.className = "show";
	}

	document.getElementById ( "div_comunicar_resposta" ).innerHTML = "" ;
	document.getElementById ( "div_enviar_resposta" ).innerHTML = "" ;

	obj2 = document.getElementById("compartilhar_select");
	if (id=="entrenoemail") {
		if (obj.className == "hide") {
			obj2.className = "show";
		} else {
			obj2.className = "hide";
		}
	} else if (obj2.className == "hide") {
		obj2.className = "show";
	}


}

function mudaRankingMusica(aba) {
	document.getElementById('musica1').className = '';
	document.getElementById('musica2').className = '';
	document.getElementById('musica3').className = '';
	document.getElementById('musica1_lista').className = 'abacontent hide';
	document.getElementById('musica2_lista').className = 'abacontent hide';
	document.getElementById('musica3_lista').className = 'abacontent hide';
	document.getElementById(aba.id).className = 'hi';
	document.getElementById(aba.id+'_lista').className = 'abacontent show';
}
function mudaRankingGanhadores(aba) {
	document.getElementById('ganhadores1').className = '';
	document.getElementById('ganhadores2').className = '';
	document.getElementById('ganhadores1_lista').className = 'abacontent hide';
	document.getElementById('ganhadores2_lista').className = 'abacontent hide';
	document.getElementById(aba.id).className = 'hi';
	document.getElementById(aba.id+'_lista').className = 'abacontent show';
}

function setarCampos ( form ) {

	if ( form == 'enviar-por-email' ) {
		var campos = "nome_remetente=" + encodeURI ( document.getElementById ( 'nome_remetente' ).value ) +
			"&end_remetente=" + encodeURI ( document.getElementById ( 'end_remetente' ).value ) +
			"&destinatarios=" + encodeURI ( document.getElementById ( 'destinatarios' ).value ) +
			"&tit_info=" + encodeURI ( document.getElementById ( 'tit_info' ).value ) +
			"&link_info=" + encodeURI ( window.location.href ) +
			"&com_info=" + encodeURI ( document.getElementById ( 'com_info' ).value ) ;
	}

	if ( form == 'comunicar-erros' ) {
		var campos = "nome_remetente=" + encodeURI ( document.getElementById ( 'nome_remetente1' ).value ) +
			"&end_remetente=" + encodeURI ( document.getElementById ( 'end_remetente1' ).value ) +
			"&txt_erro=" + encodeURI ( document.getElementById ( 'txt_erro1' ).value ) ;
	}

	if ( campos ) {
		document.getElementById ( "campos" ).value = campos ;
	}
}
