function listaJuizes(pag,total) {
  if (!pag){  pag = 0;  }
  executar('modulos/restrita/bd.getjuizes.php','pagina='+pag+'&total='+total,listaJuizesRe);
}

function listapagJuizes() {
  var pag  = this.attributes['pag'].value;
  var total  = this.attributes['total'].value;
  if (!pag){  pag = 0;  }
  executar('modulos/restrita/bd.getjuizes.php','pagina='+pag+'&total='+total,listaJuizesRe);
}

function listaJuizesRe() {
  if (xhReq.readyState == 4 && xhReq.status == 200){
    var resposta = xhReq.responseXML;

		obj = resposta.getElementsByTagName('juizes')[0].getElementsByTagName('juiz');
    pagina = resposta.getElementsByTagName('paginas');

	  var divjuizes		= document.getElementById('seccao_juizes');
    divjuizes.innerHTML = '';
		if (obj.length > 0){
		  for(i=0; i < obj.length; i++  ){

        juiz_id = obj[i].getAttribute("juiz_id");
        nome = unescape(obj[i].getAttribute("nome"));
        email = obj[i].getAttribute("email");
        vara = obj[i].getAttribute("vara");
        tel_1 = obj[i].getAttribute("tel_1");
        tel2 = obj[i].getAttribute("tel2");
        foto = obj[i].getAttribute("foto");
        sem_foto = obj[i].getAttribute("sem_foto");
        largura = obj[i].getAttribute("largura");
        altura = obj[i].getAttribute("altura");
        thumb = obj[i].getAttribute("thumb");
        tlargura = obj[i].getAttribute("tlargura");
        taltura = obj[i].getAttribute("taltura");

        var div;
        var img;
        var h4;
        var span;
        div                 = document.createElement('div');
        img                 = new Image();
        h4                  = document.createElement('h4');
        h4.className        = "h4";
        div.className       = "divJuiz";
       if (sem_foto == 0){
        div.appendChild(img);
        img.src             = "imagens/juizes/"+thumb;
        img.align           = "left";
        img.style.marginRight= "12px";
        img.setAttribute("largura",largura);
        img.setAttribute("altura",altura);
        img.setAttribute('caminho','imagens/juizes/'+foto);
        img.setAttribute('legenda',nome);
        img.onclick         = abrirImagem;
       } else{
        div.appendChild(img);
        img.src             = "images/semfoto.gif";
        img.align           = "left";
        img.style.marginRight= "12px";
        //img.setAttribute("largura",largura);
        //img.setAttribute("altura",altura);
        //img.setAttribute('caminho','imagens/juizes/'+foto);
        //img.setAttribute('legenda',nome);
        //img.onclick         = abrirImagem;
       }
        div.appendChild(h4);
        h4.appendChild(document.createTextNode(unescape(nome)));
        
        span                = document.createElement('span');
        strong                = document.createElement('strong');
        br                = document.createElement('br');
        div.appendChild(span);
        span.appendChild(strong);
        strong.appendChild (document.createTextNode('Email: '))
        span.appendChild (document.createTextNode(unescape(email)));
        span.appendChild (br);
        
        span                = document.createElement('span');
        strong                = document.createElement('strong');
        br                = document.createElement('br');
        div.appendChild(span);
        span.appendChild(strong);
        strong.appendChild (document.createTextNode('Vara: '));
        span.appendChild (document.createTextNode(unescape(vara)));
        span.appendChild (br);
        
        span                = document.createElement('span');
        strong                = document.createElement('strong');
        br                = document.createElement('br');
        div.appendChild(span);
        span.appendChild(strong);
        strong.appendChild (document.createTextNode('Telefone: '));
        span.appendChild (document.createTextNode(tel_1));
        span.appendChild (br);
        
        span                = document.createElement('span');
        strong                = document.createElement('strong');
        br                = document.createElement('br');
        div.appendChild(span);
        span.appendChild(strong);
        strong.appendChild (document.createTextNode('Telefone: '));
        span.appendChild (document.createTextNode(tel2));
        span.appendChild (br);

        document.getElementById('seccao_juizes').appendChild(div);
      }
    }
    else{
        div += "Sem dados cadastrados at&eacute; o momento" ;
    }

    if (pagina[0].getAttribute("ult") > 1){
      var pag;
      var a;
      pag = document.createElement('div');
      pag.align = "center";

      a   = document.createElement('a');
      pag.appendChild(a);
      a.href = "javascript:;";
      a.onclick = listapagJuizes;
      a.setAttribute( 'pag', pagina[0].getAttribute("ant"));
      a.setAttribute( 'total', pagina[0].getAttribute("ult"));

      a.appendChild(document.createTextNode('ANTERIOR'));
      
      pag.appendChild (document.createTextNode(' || '));
      
      a   = document.createElement('a');
      pag.appendChild(a);
      a.href = "javascript:;";
      //a.setAttribute('onclick','listaJuizes('+pagina[0].getAttribute("prox")+','+pagina[0].getAttribute("ult")+')');
      a.onclick = listapagJuizes;
      a.setAttribute('pag', pagina[0].getAttribute("prox"));
      a.setAttribute('total', pagina[0].getAttribute("ult"));
      a.appendChild(document.createTextNode('PROXIMA'));

      gin = document.createElement('div');
      gin.align = "center";
      gin.style.clear = "both";
      
      document.getElementById('seccao_juizes').appendChild(gin);
      document.getElementById('seccao_juizes').appendChild(pag);

    }

  }

}

function listaNoticias(pag,total) {
//alert ('ok1');
  if (!pag){  pag = 0;  }
  executar('modulos/restrita/bd.getnoticias.php','pagina='+pag+'&total='+total,listaNoticiasRe);
}
function listapagNoticias() {
  var pag  = this.attributes['pag'].value;
  var total  = this.attributes['total'].value;
//alert ('ok1');
  if (!pag){  pag = 0;  }
  executar('modulos/restrita/bd.getnoticias.php','pagina='+pag+'&total='+total,listaNoticiasRe);
}
function listaNoticiasRe() {
  if (xhReq.readyState == 4 && xhReq.status == 200){
    var resposta = xhReq.responseXML;
    //alert (resposta.getElementsByTagName('juizes').length);

		obj = resposta.getElementsByTagName('noticias')[0].getElementsByTagName('noticia');
    pagina = resposta.getElementsByTagName('paginas');
    total = pagina[0].getAttribute("ult");

	//	var div =  "";
	  var divnoti		= document.getElementById('seccao_noticias');
	  //var pagn = document.getElementById('noticias_paginacao');
    divnoti.innerHTML = '';
    //pagn.innerHTML = '';
		if (obj.length > 0){
		  for(i=0; i < obj.length; i++  ){

        id = obj[i].getAttribute("id");
        titulo = unescape(obj[i].getAttribute("titulo"));
        chamada = unescape(obj[i].getAttribute("chamada"));

        var div;
        //var a;
        var img;
        var h4;
        var span;
        var a;
        div                 = document.createElement('div');
        h4                  = document.createElement('h4');
        h4.className        = "h4";
        div.className       = "divNoticias";
        div.appendChild(h4);
        h4.appendChild(document.createTextNode(titulo));
        span                = document.createElement('span');
        br                = document.createElement('br');
        div.appendChild(span);
        a = document.createElement('a');
        span.appendChild (a);
        

        //a.setAttribute('href','javascript:;');

        a.href = "javascript:;";
        a.onclick = lerNoticia;
        a.appendChild (document.createTextNode(chamada));
        a.setAttribute('id', id);
        a.setAttribute('total', total);
        //a.setAttribute('onclick',"lerNoticia("+id+","+total+");");
        span.appendChild (br);


        document.getElementById('seccao_noticias').appendChild(div);
      }
    }
    else{
        div += "Sem dados cadastrados at&eacute; o momento" ;
    }

    //var pag =  "";

    //pag += "<div style='clear:both; border:none'></div>";
    if (pagina[0].getAttribute("ult") > 1){
      var pag;
      var a;
      pag = document.createElement('div');
      pag.align = "center";

      a   = document.createElement('a');
      pag.appendChild(a);
      a.href = "javascript:;";

      a.onclick = listapagNoticias;
      a.setAttribute( 'pag', pagina[0].getAttribute("ant"));
      a.setAttribute( 'total', pagina[0].getAttribute("ult"));
      a.appendChild(document.createTextNode('ANTERIOR'));
      pag.appendChild (document.createTextNode(' || '));
      a   = document.createElement('a');
      pag.appendChild(a);
      a.href = "javascript:;";
      //a.setAttribute('onclick','listaNoticias('+pagina[0].getAttribute("prox")+','+pagina[0].getAttribute("ult")+')');
      a.onclick = listapagNoticias;
      a.setAttribute( 'pag', pagina[0].getAttribute("prox"));
      a.setAttribute( 'total', pagina[0].getAttribute("ult"));
      a.appendChild(document.createTextNode('PROXIMA'));

      gin = document.createElement('div');
      gin.align = "center";
      gin.style.clear = "both";
      document.getElementById('seccao_noticias').appendChild(gin);
      document.getElementById('seccao_noticias').appendChild(pag);
    }

  }



//pagjuizes.innerHTML = pag;


//alert ('ok2');

}

function abreFoto() {
  alert(this);
  alert(this.attributes['altura'].value)
  alert(this.attributes['largura'].value)
  alert(this.attributes['caminho'].value)
}


//função para diminuir o tamanho do flsh em caso de foto unica
function getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY){
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	if(yScroll < windowHeight) pageHeight = windowHeight;
	else pageHeight = yScroll;
	if(xScroll < windowWidth) pageWidth = windowWidth;
	else pageWidth = xScroll;
	arrayPageSize = {pageWidth:pageWidth,pageHeight:pageHeight,windowWidth:windowWidth,windowHeight:windowHeight}
	return arrayPageSize;
}

function abrirImagem()
{


  var altura  = this.attributes['altura'].value;
  var largura = this.attributes['largura'].value;
  var caminho = this.attributes['caminho'].value;
  var legenda = this.attributes['legenda'].value;
  
  
 legenda	= legenda == null?"Clique para fechar":legenda;
	//pegando altura do body - ie6
	var pageSize = getPageSize();
	document.getElementById('mascara').style.height = (pageSize.pageHeight + 'px');

	document.getElementById('caixaImg').innerHTML 		= '<img src="'+caminho+'" height="'+altura+'" width="'+largura+'" alt="Clique na imagem para fechar"><div id="caixa_legenda">'+legenda+'</div>';

	document.getElementById('caixaImg').style.width 	= largura+'px';

	n_altura = parseInt(altura) + 20;

	document.getElementById('caixaImg').style.height 	= n_altura +'px';

	document.getElementById('caixaImg').style.margin = "-"+ altura/2 + "px 0 0 -" + largura/2 + "px";

	document.getElementById('mascara').style.display 	= '';

	document.getElementById('caixaImg').style.display 	= '';
}

function fechar()
{
	document.getElementById('caixaImg').innerHTML 		= '';
	document.getElementById('mascara').style.display 	= 'none';
	document.getElementById('caixaImg').style.display 	= 'none';
}

function lerNoticia(){
  var id  = this.attributes['id'].value;
  var total  = this.attributes['total'].value;
  include('./modulos/restrita/ler.php','noticiaID='+id+'&total='+total,'seccao_noticias');
}

function lerGaleria(id){
  //alert (id);
  document.getElementById('seccao_lergalerias').style.display 		= '';
  document.getElementById('seccao_galerias').style.display 		= 'none';
  include('./modulos/restrita/lergaleria.php','id='+id,'seccao_lergalerias');

}

function abrirImagemgaleria(caminho,largura,altura,legenda)
{

	var legenda	= legenda == null?"Clique para fechar":legenda;
	//pegando altura do body - ie6
	var pageSize = getPageSize();
	document.getElementById('mascara').style.height = (pageSize.pageHeight + 'px');

	//document.getElementById('caixaImg').innerHTML 		= '<img src="'+caminho+'" height="'+altura+'" width="'+largura+'" alt="Clique na imagem para fechar"><div id="caixa_legenda">'+legenda+'</div>';
	      img                 = new Image();
        document.getElementById('caixaImg').appendChild(img);
        img.src             = caminho;


	document.getElementById('caixaImg').style.width 	= largura+'px';

	n_altura = parseInt(altura) + 20;

	document.getElementById('caixaImg').style.height 	= n_altura +'px';

	document.getElementById('caixaImg').style.margin = "-"+ altura/2 + "px 0 0 -" + largura/2 + "px";

	document.getElementById('mascara').style.display 	= '';

	document.getElementById('caixaImg').style.display 	= '';
}

function voltargaleria(){

  document.getElementById('seccao_lergalerias').style.display 		= 'none';
  document.getElementById('seccao_galerias').style.display 		= '';

}
function expandir(manipulador,seccao) {

	var sec = document.getElementById(seccao);
	//var img = document.getElementById(manipulador);

	//escondendo tudo

	  var down = document.getElementById('seccao_downloads');
    var conv = document.getElementById('seccao_convenios');
    var noti = document.getElementById('seccao_noticias');
    var gale = document.getElementById('seccao_galerias');
    var requ = document.getElementById('seccao_requerimentos');
    var vide = document.getElementById('seccao_videos');
    var juiz = document.getElementById('seccao_juizes');
    var lergal = document.getElementById('seccao_lergalerias');
    //var noti = document.getElementById('seccao_noticias');

	down.style.display = 'none';
	conv.style.display = 'none';
	noti.style.display = 'none';
	gale.style.display = 'none';
	requ.style.display = 'none';
	vide.style.display = 'none';
	juiz.style.display = 'none';
	lergal.style.display = 'none';

	//-----------


	if(sec.style.display == 'none'){

		sec.style.display = 'block';
		//img.src 		  = 'imagens/cima.png';

	}else {

		sec.style.display = 'none';
		//img.src 		  = 'imagens/baixo.png';

	}
}
