function obj(id){
	return document.getElementById(id);
}
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}
var time=null;
function apagaMenu(){
	obj('submenu').style.display='none';
	obj('banner').style.marginTop="8px";
}
function exibe_menu(n,hasSubMenu){//colocar zero para apagar os menus
	clearInterval(time);
	obj('banner').style.marginTop="0px";
	var divsOcultas = getElementsByClass('menu_oculto',document,'div');		
	if(n!=0 && divsOcultas[n-1].innerHTML!="")
		obj("submenu").style.display="block";			
	else
		obj("submenu").style.display="none";
	for (i=1;i<=divsOcultas.length;i++){
		if(i==parseInt(n)){
			var menu = obj("menu_oculto"+n);
			menu.style.display = "block";	
			obj('menu'+n).style.color="#000ccc";
			obj('menu'+n).style.backgroundColor="#FFFFFF";
		}else{
			var menu = obj("menu_oculto"+i);
			menu.style.display = "none";
			if(obj('menu'+i)!=null)
				obj('menu'+i).style.color="#848684";		
			obj('menu'+i).style.backgroundColor="#FFFFFF";
		}
	}
	if(n!=0)//apaga o menu
		time = setInterval("exibe_menu(0);", 10000);
	else
		clearInterval(time);
}
 function trocarAba(id){		
	var n=2;//número de abas. Caso necessário, incrementar no futuro
	for(i=1;i<n+1;i++){
		if(i==parseInt(id)){
			obj("aba"+id).className='aba_selected';
			obj("content_aba"+id).style.display="block";
		}else{
			obj("aba"+i).className='aba';
			obj("content_aba"+i).style.display="none";
		}
		obj("aba"+i).style.textDecoration='none';
	}
} 

function exibePopEmail(){
	var winl = (screen.width) / 2;
	winl = winl - (parseInt(obj("popEmail").style.width)/2);
	var wint = 100;//(screen.height) / 2;
	if(obj("popup"))
		fechar("popup");
	obj("popEmail").style.left = winl+"px";
	obj("popEmail").style.top = wint+"px";		
	obj("popEmail").style.display='block';
}
	
function centralizarPopup(){
	//alert(screen.width+" "+screen.height);
	if( obj("popup")){
		if(getCookie("HidePopup")){
			obj("popup").style.display='none';
		}else{				
			var winl = (screen.width) / 2;
			winl = winl - (parseInt(obj("popup").style.width)/2);
			var wint = 100;//(screen.height) / 2;
			obj("popup").style.left = winl+"px";
			obj("popup").style.top = wint+"px";		
			setCookie("HidePopup","Popup_sefa",1);		
		}
	}
}

function fechar(id){
	obj(id).style.display="none";
}

function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	document.cookie=c_name + "=" + escape(value) + ( (expiredays==null) ? "" : "; expires=" + exdate);
}
function getCookie(c_name){
	if (document.cookie.length>0){
		c_start=document.cookie.indexOf(c_name + "=")
		if (c_start!=-1){ 
			c_start=c_start + c_name.length+1 
			c_end=document.cookie.indexOf(";",c_start)
			if (c_end==-1) c_end=document.cookie.length
			//return unescape(document.cookie.substring(c_start,c_end));
			return true;
		} 
	}
	return false;
}
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);


/*************** Código dos Destaques ************/

//Pega o estilo da linha da tabela dependendo do navegador
function getDisplayStyle(){
	if(navigator.userAgent.indexOf("MSIE")>-1){
		return 'block';
	}else if(navigator.userAgent.indexOf("Mozilla/5.0")>-1){
		return 'table-row';
	}	
}

function toggleArrow(id, color){
		var img = obj(id);
		if(color == "gray"){
			if(img.src.indexOf("_gray.jpg")==-1){
				img.src = img.src.substring(0,img.src.indexOf(".jpg")) +"_gray.jpg";
				img.style.border = "1px #CCCCCC solid";	
				img.style.cursor = "default";
			}
		}else{
			if(img.src.indexOf("_gray.jpg")>-1){
				img.src = img.src.substring(0,img.src.indexOf("_gray.jpg")) +".jpg";
				img.style.border = "1px #666666 solid";
				img.style.cursor = "pointer";
			}
		}
}

//Move os destaques para cima ou para baixo
function rolarDestaques(action){
	var rows = obj('destaques').rows;
	var indeces = getDisplayRows(rows);
	var firstDisplay = indeces[0];
	var lastDisplay = indeces[indeces.length - 1];
	if(action == 'forward'){
		if(lastDisplay < rows.length-1){
			for(i=0;i<indeces.length;i++){							
				indeces[i]++;
			}
			j=0;
			for(i=0;i<rows.length;i++){
				if(indeces[j]==i){
					rows[indeces[j++]].style.display=getDisplayStyle();
				}else{
					rows[i].style.display='none';
				}
			}
		}
	}
	if(action == 'backward'){
		if(firstDisplay > 0){
			for(i=0;i<indeces.length;i++){							
				indeces[i]--;
			}
			j=0;
			for(i=0;i<rows.length;i++){
				if(indeces[j]==i){
					rows[indeces[j++]].style.display=getDisplayStyle();
				}else{
					rows[i].style.display='none';
				}
			}
		}
	}	
	if(indeces[0]==0)
		toggleArrow('arrowUp', 'gray');
	else
		toggleArrow('arrowUp');
	if(indeces[indeces.length-1]==(rows.length-1))
		toggleArrow('arrowDown','gray');
	else
		toggleArrow('arrowDown');
}

//Retorna um array com os indices das linhas que estão com o display igual a 'none'
function getDisplayRows(rows){
	var index = Array();
	var j=0;
	for(z=0;z<rows.length;z++){
		if(rows[z].style!='undefined' && rows[z].style.display!='none'){
			if(j!=3)
				index[j++] = z;								
		}							
	}
	return index;
}

function decorationAba(aba,decoration){
	if(aba.className!='aba_selected')
		aba.style.textDecoration=decoration;
}

