
var PERSONALIZACAO;

function posicionaRodape(){
	if(PERSONALIZACAO == "usp"){
		posicionaRodapeComAbas();
	} else if(PERSONALIZACAO == "rnp"){
		posicionaRodapeSemAbas();
	} else if(PERSONALIZACAO == "nic"){
		posicionaRodapeSemAbas();
	} else if(PERSONALIZACAO == "red"){
		posicionaRodapeSemAbas();
	}
}

function posicionaRodapeComAbas(){

	var rodape = document.getElementById("rodape");
	if(rodape == null){	
		return;
	}

	rodape.style.position = "relative";
	rodape.style.top = "";
	rodape.style.bottom = "";
	
	var menuBusca = document.getElementById("menuBusca");
	
	// parece que as abas n�o est�o no body... (mas est�o sim! s� n�o s�o levadas em considera��o ao pegar alturaBody)
	var alturaAbas = menuBusca.offsetTop + menuBusca.clientHeight;
	var alturaBody = document.body.clientHeight;
	var alturaJanela = document.documentElement.clientHeight;
	
	if(alturaBody < alturaJanela){
		rodape.style.position = "absolute";
		if(alturaAbas + rodape.clientHeight > alturaJanela){
			rodape.style.top = (alturaAbas + rodape.clientHeight) + "px";
		} else {
			rodape.style.bottom = "0px";
		}
	} else {
		rodape.style.position = "relative";
	}
	
}

function posicionaRodapeSemAbas(){

	var rodape = document.getElementById("rodape");
	if(rodape == null){	
		return;
	}

	var heightMenuLateral = document.getElementById("menuLateral").clientHeight;
	var heightConteudo = document.getElementById("conteudo").clientHeight;
	var heightTitulo = document.getElementById("title").clientHeight;
	var heightRodape = rodape.clientHeight;

	var altura = document.documentElement.clientHeight;
	
	// argh! 10?!
	if(10 + Math.max(heightConteudo, heightMenuLateral) + heightRodape + heightTitulo > altura){
		rodape.style.position = "relative";
	} else{
		rodape.style.position = "absolute";
	}

}

function cancelar(){
	history.go(-1);
}

function link(destino){
	document.location = destino;
}

function alternaExibicao(idDoElemento){

	elemento = document.getElementById(idDoElemento);
	
	if(elemento.style.display == "none"){
		elemento.style.display = "inline";
	} else {
		elemento.style.display = "none";
	}
	
	posicionaRodape();
	
}

function alternaExibicaoSimbolo(idDoElemento, idDoSimboloColapsa, idDoSimboloExpande, idMantemEstado, id){

	elemento = document.getElementById(idDoElemento);
	elemento2 = document.getElementById(idDoSimboloColapsa);	
	elemento3 = document.getElementById(idDoSimboloExpande);	
		
	if(elemento.style.display == "none"){ //expande
		
		elemento.style.display = "inline";
		elemento2.style.display = "none";
		elemento3.style.display = "inline";
		
		if(idMantemEstado != undefined){
			var mEstado = $(idMantemEstado);
			if(mEstado.idsExpandidos == undefined){
				mEstado.idsExpandidos = new Object();
			}
			mEstado.idsExpandidos[id] = true;
		}
		
	} else { //colapsa
		
		elemento.style.display = "none";
		elemento2.style.display = "inline";
		elemento3.style.display = "none";
		
		if(idMantemEstado != undefined){
			var mEstado = $(idMantemEstado);
			if(mEstado.idsExpandidos == undefined){
				mEstado.idsExpandidos = new Object();
			}
			mEstado.idsExpandidos[id] = false;
		}
		
	}
	
	
	
	posicionaRodape();
	
}

function destacaElementos(){
	
	candidatos = document.getElementsByTagName("li");
	
	for(var i = 0; i < candidatos.length; i++){
		var elemento = candidatos[i];
		if(elemento.className == "destaca"){
			elemento.onmouseover = destaca;
			elemento.onmouseout = tiraDestaque;
		}
	}
	
}

function destaca(evento){
	getAlvoDestaca(evento).style.backgroundColor = "#BBBBBB";
}

function tiraDestaque(evento){
	getAlvoDestaca(evento).style.backgroundColor = "";
}

function getAlvoDestaca(evento){
	var targ;
	if (!evento) var evento = window.event;
	if (evento.target) targ = evento.target;
	else if (evento.srcElement) targ = evento.srcElement;
	if (targ.nodeType == 3) targ = targ.parentNode;
	
	while(targ.className != "destaca"){
		targ = targ.parentNode;
	}

	return targ;
}

function getTextoExibicao(texto, tam){
	var resultado = texto;
	if(resultado.length > tam){
		resultado =  texto.substring(0, tam);
		resultado = resultado + "...";
	}
	return resultado;
}

function checkPublicoPrivadoOK() {

	if (document.getElementsByName('acesso')[1].checked){
		if ((document.getElementById('grupo').checked) || (document.getElementById('projeto').checked)){
			document.getElementById('publicoPrivadoOK').value = "ok";
		}
	} else {
		document.getElementById('publicoPrivadoOK').value = "ok";
	}
}

// possibilita [].indexOf
Array.prototype.indexOf = function(obj){
	for(var i=0; i<this.length; i++){
		if(this[i]==obj){
			return i;
		}
	}
    return -1;
}


/*
 * Permite a remoção de itens de uma array de maneira mais eficiente.
 * 
 * Ex:
 * arrayTeste.remove(1)		Remove o segundo elemento da array
 * arrayTeste.remove(-1)	Remove o ultimo elemento da array
 */
Array.prototype.remove = function(from, to) {
  var rest = this.slice((to || from) + 1 || this.length);
  this.length = from < 0 ? this.length + from : from;
  return this.push.apply(this, rest);
};
