function init()
{

}
onload = init;

function openNewWindow(url) {window.open(url);}

function divideColunasClassificados(total, porColuna, vetor)
{
	var variavel = "<div id='classificados'>";
	var nroColuna = 0;

	for(i=0;i<total;i++)
	{
		if(i==0 || i == porColuna*nroColuna)
		{
			variavel += "<div>";
			nroColuna += 1;
		}
		variavel += "<div ><img src=\"/img/ico-classificados.gif\" width=\"16\" height=\"10\" alt=\"ico-classificados\" ><a href=\"/site/index.php?"+vetor[i][0]+"\">"+vetor[i][1]+"</a> "+vetor[i][2]+"</div>";
		if(i+1 == porColuna*nroColuna)
			variavel += "</div>";
	}
	variavel += "</div></div>";
	return variavel;
}


function abre_janela(pagina,largura,altura,scrolls)
{
	if(!scrolls)
		scrolls = 'no';
	window.open(pagina,'','toolbar=no,location=no,top=200,left=200,directories=no,status=no,menubar=no,scrollbars='+scrolls+',Resizable=no,copyhistory=no,width=' + largura + ',height=' + altura)
}

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

function abuse(id,url){
	var endereco = '';
	if(typeof url != 'undefined'){
		endereco = location.protocol+'//'+location.host+'/site/?n_link='+url;
	}
	else{
		endereco = document.location;
		if(typeof id != 'undefined' ){
			if((pos = (endereco.toString()).indexOf("#"))>0)
				endereco = (endereco.toString()).substr(0, pos);
			endereco += '#'+id
		}
	}
	endereco = '/site/?n_link=abuse&referer='+escape(endereco);
	abre_janela(endereco,400,340,true);
}

function amigo(id,nome){
	if(visivelCom){
		if(confirm('Você deseja realmente ser amigo de '+nome+'?')){ 
			//document.location = '/scripts/tornarAmigo.php?id='+id; 
			_$.get('/scripts/tornarAmigo.php?id='+id, function(data){ eval(data); }); 
		}
	}
	else{
		document.location = '/site/?n_link=comunidade_usuario_nao_visivel';
	}
}

function apagar(id,nome){
	if(visivelCom){
		if(confirm('Você deseja realmente excluir '+nome+' dos seus contatos?')){ 
			document.location = '/scripts/apagaContato.php?id='+id; 
		}
	}
	else{
		document.location = '/site/?n_link=comunidade_usuario_nao_visivel';
	}
}

function participar(id){
	if(visivelCom){
		if(confirm('Você deseja realmente participar desta comunidade?')){ 
			_$.get('/scripts/participar_comunidade.php?forum='+id, function(data){ eval(data); }); 
		}
	}
	else{
		document.location = '/site/?n_link=comunidade_usuario_nao_visivel';
	}
}


function deixar(id){
	if(visivelCom){
		if(confirm('Você deseja realmente deixar esta comunidade?')){ 
			_$.get('/scripts/deixar_comunidade.php?forum='+id, function(data){ eval(data); });
		}
	}
}

function buscar()
{
	var str = '';
	
	caderno_id = retornoJs['id_caderno'];
	var mes = document.getElementsByName('busca-mes')[0].value;
	var ano = document.getElementsByName('busca-ano')[0].value;
	
	if(typeof caderno_id != 'undefined')
		str = "&id_caderno="+caderno_id;
	if(mes != 'VAZIO')
		str += "&notmes="+mes;
	if(ano != 'VAZIO')
		str += "&notano="+ano;
	if(str != '')
		location.href="/site/?n_link=todas_noticias"+str;
}

function seleciona(obj,v){
	var i = 0;
	if(typeof v != 'undefined'){
		for(;i<obj.length;i++){
			if(obj[i].value = v){
				obj[i].selected = true;
			}
		}
	}
}

/*
function indicar_noticia(titulo){
	
	var endereco = '/site/?n_link=indicar_noticia&titulo='+titulo;
	abre_janela(endereco,490,490,true);
}
*/


function indicarPorEmail(titulo,ref,url){
	titulo = unescape(titulo);
	ref = unescape(ref);
	var endereco = '/site/?n_link=indicar_tudo&titulo='+titulo+'&ref='+ref;
	if(typeof url != 'undefined'){
		endereco = endereco + '&linkdestino='+escape(url);
	}
	//alert(endereco);
	abre_janela(endereco,490,510,true);
}


function arredondar(valor, casadecimais){

	valor = parseFloat(valor);
	var mul = Math.pow(10,casadecimais|0)
	valor = (Math.round(valor * mul) / mul);
	return valor.toString();
}

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!");
		
}

function parcial(){
	_$('#enquete').html(HTML_RESULTADO);
}
function voltarParaEnquete(){
	_$('#enquete').html(HTML_ENQUETE);
}
function swapBt(obj, vis){
	obj.src = (obj.src).replace( ( vis ? "-off" : "-on" ), ( vis ? "-on" : "-off" ));
}

function mostra(div_id){
	_$('#'+div_id).toggle();
}


function fontsizeup() {
  active = getActiveStyleSheet();
  switch (active) {
    case 'pqno' : 
      setActiveStyleSheet('medio');
      break;
    case 'medio' : 
      setActiveStyleSheet('grande');
      break;
    case 'grande' : 
      setActiveStyleSheet('ggrande');
      break;
    case 'ggrande' :
      break;
    default :
      setActiveStyleSheet('grande');
      break;
  }
}

function fontsizedown() {
  active = getActiveStyleSheet();
  switch (active) {
    case 'ggrande' : 
      setActiveStyleSheet('grande');
      break;
    case 'grande' : 
      setActiveStyleSheet('medio');
      break;
    case 'medio' : 
      setActiveStyleSheet('pqno');
      break;
    case 'pqno' : 
      break;
    default :
      setActiveStyleSheet('pqno');
      break;
  }
}

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  createCookie("style", title, 365);
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  return ('medio');
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}
/*
window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}
*/
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
if (title == 'null') {
  title = getPreferredStyleSheet();
}

setActiveStyleSheet(title);


function limitChars(textarea, limit, infodiv)
{
	var text = textarea.value;	
	var textlength = text.length;
	var info = document.getElementById(infodiv);

	if(textlength > limit)
	{
		info.innerHTML = 'Você ainda tem '+limit+' caracteres!';
		textarea.value = text.substr(0,limit);
		return false;
	}
	else
	{
		info.innerHTML = 'Você ainda tem '+ (limit - textlength) +' caracteres!';
		return true;
	}
}

function montaConvites(){
	var htmlConvite = "<h3>Faça novos amigos</h3>";
	var arrayid = [];
	if(visivelCom){
		arrayid[arrayid.length] = ""+
			"<div id=\"bloco-busca-regiao\">"+
			"	<p>Faça novos amigos e<br />contatos profissionais.</p>"+
			"	<p><a href=\"/site/?n_link=comunidade_busca\" title=\"Busca por Região\">Clique aqui</a> e procure<br />pela região que você<br />desejar.</p>"+
			"</div>";
		arrayid[arrayid.length] = ""+
			"<div id=\"bloco-busca-profissao\">"+
			"	<p>Faça novos amigos e<br />contatos profissionais.</p>"+
			"	<p><a href=\"/site/?n_link=comunidade_busca\" title=\"Busca por Região\">Clique aqui</a> e procure<br />pela profissão que<br />você desejar.</p>"+
			"</div>";
		
		var i = Math.floor((Math.ceil(Math.random()*100))/50);
		document.write(htmlConvite + arrayid[i]);
		document.close();
	}

}

function montaMensagem(msg, erro){
	_$("#msgsCentrais").html("<p id='msg"+(erro == true ? 1 : 0)+"'>"+msg+"</p>");
	_$("#msgsCentrais").show("slow");
}
function delicious(title){
	if(!title)
		title = "Âmbito Jurídico - O seu Portal Jurídico da internet";
	var endereco = "http://del.icio.us/post?title="+title+"&url="+escape(location.toString());
	window.open(endereco);
}
