//funções pra manter funcionando
function CloseFloater(){
	fechaFloater('regioesfloater',false);
}

function abreFloaterRegioes(){
	setTimeout("CloseFloater();", "10000");
	abreFloater('regioesfloater','/media/primeiro_acesso.swf','regioesfloater','457','258');
}

//funções de manipulação do floater
var floaters = 0; 

function fechaFloater(floaterId,naoAbreMais)
{
	document.getElementById(floaterId).style.display = 'none';
	document.getElementById(floaterId).innerHTML = '';
	
	if(naoAbreMais){
		SetCookie("cookie_"+floaterId, true, expdate);
	}
}

function negaFloater(floaterId){
	SetCookie("cookie_"+floaterId, true, expdate);
}

function habilitaFloater(floaterId){
	DeleteCookie("cookie_"+floaterId);
}
function rndnumber(howMany){
  		var randscript = -1;
   		while (randscript < 1 || randscript > howMany || isNaN(randscript)){ 
      		randscript = parseInt(Math.random()*(howMany+1));
   		}
   		return randscript; 
	} 
function abreFloater(floaterId, src, nome, largura, altura, fecharTimeout, naoAbreMais, seg, extra){
	if(GetCookie("cookie_"+floaterId) || floaters >0) 
		return true;

	if(!naoAbreMais)
		naoAbreMais = false;

	if(!seg)
		seg = 10000;
	
	if(!extra)
		extra = "";

if(src.indexOf(".swf")>-1){
	var strFloater = ''+
		'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+largura+'" height="'+altura+'">'+
		'	<param name="allowScriptAccess" value="sameDomain" />'+
		'	<param name="movie" value="'+src+'" />'+
                '       <param name="wmode" value="transparent" />'+
		'	<param name="quality" value="high" />'+
		'	<param name="bgcolor" value="#ffffff" />'+
		'	<embed wmode="transparent" src="'+src+'" quality="high" bgcolor="#ffffff" width="'+largura+'" height="'+altura+'" name="'+nome+'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'+
		'</object>';
}else{
	var strFloater = '<img src="'+src+'" width="'+largura+'" height="'+altura+'" usemap="'+extra+'" />';
}
	document.getElementById(floaterId).style.display = '';
	document.getElementById(floaterId).innerHTML = strFloater;
	if(fecharTimeout){
		if(naoAbreMais)
			setTimeout("fechaFloater('"+floaterId+"','"+naoAbreMais+"');", seg);
		else
			setTimeout("fechaFloater('"+floaterId+"');", seg);
	}
	floaters++;
}

/*onde estamos*/
function ondeEstamos(){
	var label = document.getElementsByTagName('label');
	for(var i=0;i<label.length;i++){
		if(i!=0 && (label[i].innerHTML=="" || label[i].innerHTML=="<br>" || label[i].innerHTML=="<BR>")){
			label[i].parentNode.removeChild(label[i]);
			var j = i-1;
			label[j].parentNode.removeChild(label[j]);
		}
	}
}
/*************/

function oposto(ele){
	elemento = document.getElementById(ele);
	if(elemento){
		if(elemento.style.display == 'none')
			elemento.style.display = '';
		else
			elemento.style.display = 'none';
	}
}
// PREVISÃO DO TEMPO
function previsao(qual,quando){
	var abrev = new Array();
	var relImgs = new Array();
	var imgTempo = "";
	abrev['Santana da Boa Vista'] = 'Sant. Boa Vista';
	abrev['Santa Vitória do Palmar'] = 'Santa Vitória';
	abrev['São Lourenço do Sul'] = 'São Lourenço';
	
	relImgs['pc.gif'] = "chuvaforte.gif";		//  Pancadas
	relImgs['ch.gif'] = "chuva.gif";			//  Chuvas
	relImgs['cc.gif'] = "sol.gif";				//  Céu Claro
	relImgs['pi.gif'] = "chuvasrapidas.gif";	//  Chuvas Rápidas
	relImgs['nb.gif'] = "nublado.gif";			//  Nublado
	relImgs['pn.gif'] = "solnuvens.gif";		//  Poucas Nuvens
	relImgs['nc.gif'] = "nublado.gif";			//  Nublado Com Chuva
	relImgs['en.gif'] = "nublado.gif";			//  Encoberto
	relImgs['ge.gif'] = "nublado.gif";			//  Geada
	relImgs['cv.gif'] = "chuvasrapidas.gif";	//  Chuviscos
		
	if(cidade.length>0)
	{
		if(typeof quando == 'undefined')
			quando = 0;
		if(typeof qual == 'undefined')
			for(var i=0;i<cidade.length;i++)
				if(cidade[i][quando][6] == global_qual)
					qual = i;
		if(typeof qual == 'undefined')
			qual = 0;
		
		/*quanto as cidades*/
		var cid_ant = qual-1;
		var cid_prox = qual+1;
		/*quanto aos dias*/
		var dia_ant = quando-1;	
		var dia_prox= quando+1;	
		var nomeCidade = "";
		if(typeof abrev[cidade[qual][quando][0]] !='undefined'){
			nomeCidade = abrev[cidade[qual][quando][0]];
		}else
			nomeCidade = cidade[qual][quando][0];
		if(typeof relImgs[cidade[qual][quando][2]] !='undefined'){
			imgTempo = relImgs[cidade[qual][quando][2]];
		}else
			imgTempo = 'desconhecida.gif';
		
		document.getElementById('id_previsao_minima').innerHTML = cidade[qual][quando][4];
		document.getElementById('id_previsao_maxima').innerHTML = cidade[qual][quando][3];
		document.getElementById('img_previsao').src = '/img/tempo/'+imgTempo;
//		document.getElementById('img_previsao').src = '/img/tempo/sol.gif';
		document.getElementById('img_previsao').alt = cidade[qual][quando][1];
		document.getElementById('img_previsao').title = cidade[qual][quando][1];
		
		var prev ="";
		if(typeof(cidade[cid_ant])!="undefined"){
			prev =	'<a href="javaScript:previsao('+cid_ant+',0)" title="'+cidade[cid_ant][quando][0]+'"><img src="/img/bt-tempo-anterior.gif" alt="'+cidade[cid_ant][quando][0]+'" title="'+cidade[cid_ant][quando][0]+'" width="10" height="15" /></a>';
		} else {
			prev =	'<img src="/img/bt-tempo-anterior-off.gif" alt="" title="" width="10" height="15" />';
		}
		var next ="";
		if(typeof(cidade[cid_prox])!="undefined"){
			next =	'<a href="javaScript:previsao('+cid_prox+',0)" title="'+cidade[cid_prox][quando][0]+'"><img src="/img/bt-tempo-proximo.gif" alt="'+cidade[cid_prox][quando][0]+'" title="'+cidade[cid_prox][quando][0]+'" width="10" height="15" /></a>';
		} else {
			next =	'<img src="/img/bt-tempo-proximo-off.gif" alt="" title="" width="10" height="15" />';
		}
		
		document.getElementById('tempo-cidade-prev').innerHTML = prev;
		document.getElementById('troca_cidade').innerHTML = '&nbsp;'+nomeCidade+'&nbsp;';
		document.getElementById('tempo-cidade-next').innerHTML = next;
			
		var prev ="";
		if(typeof(cidade[qual][dia_ant])!="undefined"){
			prev =	'<a href="javascript:previsao('+qual+','+dia_ant+')" title="'+cidade[qual][dia_ant][5]+'"><img src="/img/bt-tempo-anterior.gif" alt="'+cidade[qual][dia_ant][5]+'" title="'+cidade[qual][dia_ant][5]+'" width="10" height="15" /></a>';
		} else {
			prev =	'<img src="/img/bt-tempo-anterior-off.gif" alt="" title="" width="10" height="15" />';
		}
		
		var next ="";
		if(typeof(cidade[qual][dia_prox])!="undefined"){
			next =	'<a href="javascript:previsao('+qual+','+dia_prox+')" title="'+cidade[qual][dia_prox][5]+'"><img src="/img/bt-tempo-proximo.gif" alt="'+cidade[qual][dia_prox][5]+'" title="'+cidade[qual][dia_prox][5]+'" width="10" height="15" /></a>';
		} else {
			next =	'<img src="/img/bt-tempo-proximo-off.gif" alt="" title="" width="10" height="15" />';
		}
		
		document.getElementById('tempo-dia-prev').innerHTML = prev;
		document.getElementById('tempo-dia').innerHTML = '&nbsp;'+cidade[qual][quando][5]+'&nbsp;';
		document.getElementById('tempo-dia-next').innerHTML = next;
	}else{
		document.getElementById('tempo').style.display = 'none';
	}	 
}
// PREVISÃO DO TEMPO/END

// ENQUETE

function votaEnquete(){
	var selecionado = false;
	var tamanho = document.getElementsByName('respostas_id').length;
	for(cont=0;cont<tamanho;cont++)
	{
		if(document.getElementsByName('respostas_id')[cont].checked)
			selecionado = true;
	}
	if(selecionado)
		document.forms['formenquete'].submit();
	else
		alert("Selecione uma das opçoes para votar na enquete!");
		
}
// ENQUETE/END

// TROCA ABA
function trocaWebPainel(tipo){
	if(tipo=='webmail'){
		document.getElementById('webmail').style.display='block';
		document.getElementById('central').style.display='none';
		document.images['abasLogon'].src = '/img/abas/abas-logon-vetmail.gif'
	}else{
		document.getElementById('webmail').style.display='none';
		document.getElementById('central').style.display='block';
		document.images['abasLogon'].src = '/img/abas/abas-logon-central.gif'
	}
} 
// TROCA ABA/END


// TROCA ABA
function trocaPlano(tipo,quota1,quota2,quota3)
{
	// esconde
	document.getElementById('DIVdiamante').style.display='none';
	document.getElementById('DIVouro').style.display='none';
	document.getElementById('DIVprata').style.display='none';
	document.getElementById('DIVbronze').style.display='none';
	document.getElementById('DIVbasico').style.display='none';
	document.getElementById('DIVreserva').style.display='none';
	
	// mostra/
	document.getElementById('DIV'+tipo).style.display='block';
	document.images['abasPlanos'].src = '/img/abas/abas-plano'+tipo+'.gif'
	document.images['quotaSite'].src = '/img/abas/quota'+quota1+'.jpg'
	document.images['quotaEmail'].src = '/img/abas/quota'+quota2+'.jpg'
	document.images['quotaBD'].src = '/img/abas/quota'+quota3+'.jpg'
} 
// TROCA ABA/END


function esconderLinksRegioes(vetor){
	for(x=0; x<vetor.length; x++){
		try{
			document.getElementById('rp-'+vetor[x]).style.display = 'none';
		}catch(e){
		}
	}
}

function defineRegiao(regId){
	fechaFloater('regioesfloater', true);
	location.href = '/scripts/setCookie.php?regId='+regId;
}
function trocarCategoria(){var categoria = document.getElementById('categorias_download').value;location.href="/site/index.php?n_link=down_detalhes&cdown_id="+categoria;}
function trocarCategoria2(){var categoria = document.getElementById('categorias_download').value;location.href="/site/index.php?n_link=downloads_detalhes&cdown_id="+categoria;}
function trocaPagina(categoria){if(categoria != 0)location.href="/site/?n_link=noticiastodas&cat_not="+categoria;}
function trocaColuna(categoria){if(categoria != 0)location.href="/site/?n_link=colunasartigos&cat_col="+categoria;}
function trocaLinks(id_link){location.href="/site/?n_link=categoria_detalhes&link_id="+id_link;}
function trocarTelefones()
{
	var regiao = document.getElementById('regioes').value;
	if(regiao != 0)
		location.href="/site/index.php?n_link=canaisfones&regiao="+regiao;
}

function navega(url){location.href = url;}
function novaJanela(url){window.open(url);}

function troca_regiao (regiao_id,destino)
{
	if(regiao_id != 0)
	{
		if(typeof destino=='undefined')
		{
			if ((location.toString()).indexOf("&regiao_canais=")>-1){
				var link = (location.toString()).substring(0,(location.toString()).indexOf("&regiao_canais=")+15);
				window.location=link+regiao_id;
			}else{
				window.location=location+"&regiao_canais="+regiao_id;
			}
		}
		else
			window.location="/site/?n_link="+destino+"&regiao_canais="+regiao_id;	
	}
}

function troca_regiao_planos (regiao_id,destino)
{
	if(regiao_id != 9999)
	{
		if(typeof destino=='undefined'){
			if ((location.toString()).indexOf("&regiao_canais=")>-1){
				var link = (location.toString()).substring(0,(location.toString()).indexOf("&regiao_canais=")+15);
				window.location=link+regiao_id;
			}else{
				window.location=location+"&regiao_canais="+regiao_id;
			}
		}
		else
			window.location="/site/?n_link="+destino+"&regiao_canais="+regiao_id;	
	}
}

function assinePlano(catPs,codPs){location.href='/site/?n_link=assineIniciaProcesso&cat_ps='+catPs+'&cod_ps='+codPs}

function parceria_troca_regiao (regiao_id)
{
	if ((location.toString()).indexOf("&regiao_parceria=")>-1)
	{
		var link_agenda = (location.toString()).substring(0,(location.toString()).indexOf("&regiao_parceria=")+17);
		window.location=link_agenda+regiao_id;
	}
	else
	{
		window.location=location+"&regiao_parceria="+regiao_id;
	}	
}

function submeterFormulario()
{
	var palavra = document.getElementById('palavra-chave').value;
	
	//location.href="/site/index.php?n_link=noticias_dos_cadernos&id_caderno="+caderno_id+"&nanomes="+ano+"-"+mes;
	if(palavra == '')
		palavra = 'vazio';
	if (!(palavra == 'vazio'))
		{
			location.href="/site/index.php?n_link={N_LINK}&palavra_chave="+palavra;
		}
}

function envio_enquete(nomejan, w, h, scr)
{
	novajanela2 = window.open('about:blank', nomejan,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+scr+',resizable=no,copyhistory=no,width='+w+',height='+h);
	return true;
}

function limpaDados(){
	dados = document.getElementsByTagName('label');
	for(var i=0;i<dados.length;i++){
		var conteudo = dados[i].innerHTML;
		if(
			conteudo=="" || 
			conteudo==" " || 
			conteudo=="  " || 
			conteudo=="   "
					)
			dados[i].parentNode.style.display = 'none'
	}
}
