// rotacionar bannerd
var tempo_rotacao = 8000;
function cycle(grupo) {
	var currentAd = eval("currentAd"+grupo);
	var imgs = eval("imgs"+grupo);
	var links = eval("links"+grupo);
	var alts = eval("alts"+grupo);
	if (currentAd >= eval("imgs"+grupo+".length")) {
		currentAd = 0;
		eval("currentAd"+grupo+"=0");
	}
	var banner = document.getElementById('adbanner'+grupo);
	var conteudo_novo = '<a id="'+'adbanner'+grupo+"_"+currentAd+'" href="'+links[currentAd]+'" target="_blank"><img src="imagens/imagens_site/'+imgs[currentAd]+'" alt="'+alts[currentAd]+'" border="0" /></a>';
	banner.innerHTML += '<a id="'+'adbanner'+grupo+"_"+currentAd+'" href="'+links[currentAd]+'" target="_blank" style="top:-100px;"><img src="imagens/imagens_site/'+imgs[currentAd]+'" alt="'+alts[currentAd]+'" border="0" /></a>';
	var bannerm = document.getElementById('adbanner'+grupo+"_"+currentAd);
	var rotacao = 0;
	var intervalo = window.setInterval(function() {
		bannerm.style.top = (rotacao-98)+"px";
		rotacao=rotacao+5;
		if (rotacao>98)	{
			bannerm.style.top = "0px";
			banner.innerHTML = conteudo_novo;
			clearInterval(intervalo);
		}
	}, 50);
	eval("currentAd"+grupo+"++");
}
//Manipulação de Classe
function hasClass(ele,cls) {
	return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}
function addClass(ele,cls) {
	if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}
function removeClass(ele,cls) {
	if (hasClass(ele,cls)) {
		var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
		ele.className=ele.className.replace(reg,' ');
	}
}

var selecionadas = new Array ();
var pais = new Array ();
function mostrar(objId,caller) { //v9.0
  var obj = null; with (document){ if (getElementById)
  obj = getElementById(objId); }
  if (obj){
    if (obj.style.display == 'none') {
      eval("obj.style.display='block'");
			addClass (caller,"selecao_ativo");
		} else {
			eval("obj.style.display='none'");
			removeClass (caller,"selecao_ativo");
		}
  }
	var adiciona=true;
	for (i=0;i<selecionadas.length;i++) {
		if (selecionadas[i]==obj) {
			adiciona=false;
		}
	}
	if (adiciona) {
		selecionadas.push(obj);
		pais.push(caller);
	}
}
function mostrara(objId) { //v9.0
	var obj = null; with (document){ if (getElementById)
	obj = getElementById(objId); }
	if (obj){
		if (obj.style.display == 'none') {
			eval("obj.style.display='block'");		
			for (i=0;i<selecionadas.length;i++) {
				if (selecionadas[i]==obj) {
					addClass (pais[i],"selecao_ativo");
				}
			}
		}
	}
}

function mostrard(objId) { //v9.0
	var obj = null; with (document){ if (getElementById)
	obj = getElementById(objId); }
	if (obj){
		if (obj.style.display == 'block') {
			eval("obj.style.display='none'");		
			for (i=0;i<selecionadas.length;i++) {
				if (selecionadas[i]==obj) {
					removeClass (pais[i],"selecao_ativo");
				}
			}
		}
	}
}

function valida_selecao(base,todo) { //v9.0
	var obj = null; with (document){ if (getElementById)
	obj = getElementById("lista_"+base); }
	var obj2 = null; with (document){ if (getElementById)
	obj2 = getElementById(base+"_todas"); }
	if (obj && obj2){
		var caixas = obj.getElementsByTagName("input");
		tudo_inativo = true;
		if (todo=='1') {
			for(a = 0; a < caixas.length; a++) {
				if(caixas[a].type == "checkbox" && caixas[a]!=obj2) {
						caixas[a].checked = obj2.checked;
				}
			}
		} else {
			obj2.checked=true;
			for(a = 0; a < caixas.length; a++) {
				if(caixas[a].type == "checkbox" && caixas[a]!=obj2) {
					if (!caixas[a].checked) {
						obj2.checked=false;
					} else {
						tudo_inativo = false;
					}
				}
			}
		}
		var obj3 = null; with (document){ if (getElementById)
		obj3 = getElementById(base+"_mostra"); }
		if (obj2.checked || tudo_inativo) {
			obj3.innerHTML="<span>todas</span>";
		} else {
			var primeiro=true;
			var conteudo="<span>";
			for(a = 0; a < caixas.length; a++) {
				if(caixas[a].type == "checkbox" && caixas[a]!=obj2) {
					if (caixas[a].checked) {
						if (primeiro) {
							conteudo += caixas[a].value;
							primeiro=false;
						} else {
							conteudo += ", "+caixas[a].value;
						}
					}
				}
			}
			conteudo+="</span>";
			obj3.innerHTML=conteudo;
			
		}
	}
}
function valida_buscaass(mestre) {
	var obj = null; with (document){ if (getElementById)
	obj = getElementById("busca_associadas"); }
	var obj1 = null; with (document){ if (getElementById)
	obj1 = getElementById("ordem1"); }
	var obj2 = null; with (document){ if (getElementById)
	obj2 = getElementById("ordem2"); }
	var obj3 = null; with (document){ if (getElementById)
	obj3 = getElementById("ordem3"); }
	var obj4 = null; with (document){ if (getElementById)
	obj4 = getElementById("ordem4"); }
	var envia=true;
	if (!mestre.checked) {
		mestre.checked=true;
	}
	if (obj1!=mestre) obj1.checked=false;
	if (obj2!=mestre) obj2.checked=false;
	if (obj3!=mestre) obj3.checked=false;
	if (obj4!=mestre) obj4.checked=false;
  obj.submit();
}
//adiciona onload ao onload atual
var old_onclick = document.onclick;
if (typeof document.onclick != 'function') {
	document.onclick =check;
} else {
	document.onclick = function() {
		if (old_onclick) {
			old_onclick();
		}
		check(e);
	}
}
function check(e){
	var target = (e && e.target) || (event && event.srcElement); 
	for (i=0;i<selecionadas.length;i++) {
		if(checkParent(target,selecionadas[i])) {
			if(checkParent(target,pais[i])) {
				if (target!=pais[i]) {
					selecionadas[i].style.display='none';
					removeClass (pais[i],"selecao_ativo");
				}
			}
		}
	}
}
function checkParent(t,m){
	var valido = true;
	var ids;
	while(t.parentNode){ 
		if(t==m){ 
			valido = false; 
		} 
		ids +=","+t.id;
		t=t.parentNode;
	}
	//alert(ids+": "+valido+" , "+m.id);
	return valido; 
}
