// ----------- SWITCH CONTENT --------------------------------------------------------------------
var enablepersist="on" //Enable saving state of content structure using session cookies? (on/off)
var collapseprevious="no" //Collapse previously open content when opening present? (yes/no)

var contractsymbol='- ' //HTML for contract symbol. For image, use: <img src="whatever.gif">
var expandsymbol='+ ' //HTML for expand symbol.


if (document.getElementById){
document.write('<style type="text/css">')
document.write('.switchcontent{display:none;}')
document.write('</style>')
}

function getElementbyClass(rootobj, classname){
var temparray=new Array()
var inc=0
var rootlength=rootobj.length
for (i=0; i<rootlength; i++){
if (rootobj[i].className==classname)
temparray[inc++]=rootobj[i]
}
return temparray
}

function sweeptoggle(ec){
var thestate=(ec=="expand")? "block" : "none"
var inc=0
while (ccollect[inc]){
ccollect[inc].style.display=thestate
inc++
}
revivestatus()
}


function contractcontent(omit){
var inc=0
while (ccollect[inc]){
if (ccollect[inc].id!=omit)
ccollect[inc].style.display="none"
inc++
}
}

function expandcontent(curobj, cid){
var spantags=curobj.getElementsByTagName("SPAN")
var showstateobj=getElementbyClass(spantags, "showstate")
if (ccollect.length>0){
if (collapseprevious=="yes")
contractcontent(cid)
document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
if (showstateobj.length>0){ //if "showstate" span exists in header
if (collapseprevious=="no")
showstateobj[0].innerHTML=(document.getElementById(cid).style.display=="block")? contractsymbol : expandsymbol
else
revivestatus()
}
}
}

function revivecontent(){
contractcontent("omitnothing")
selectedItem=getselectedItem()
selectedComponents=selectedItem.split("|")
for (i=0; i<selectedComponents.length-1; i++)
document.getElementById(selectedComponents[i]).style.display="block"
}

function revivestatus(){
var inc=0
while (statecollect[inc]){
if (ccollect[inc].style.display=="block")
statecollect[inc].innerHTML=contractsymbol
else
statecollect[inc].innerHTML=expandsymbol
inc++
}
}

function get_cookie(Name) { 
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { 
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function getselectedItem(){
if (get_cookie(window.location.pathname) != ""){
selectedItem=get_cookie(window.location.pathname)
return selectedItem
}
else
return ""
}

function saveswitchstate(){
var inc=0, selectedItem=""
while (ccollect[inc]){
if (ccollect[inc].style.display=="block")
selectedItem+=ccollect[inc].id+"|"
inc++
}

document.cookie=window.location.pathname+"="+selectedItem
}

function do_onload(){
uniqueidn=window.location.pathname+"firsttimeload"
var alltags=document.all? document.all : document.getElementsByTagName("*")
ccollect=getElementbyClass(alltags, "switchcontent")
statecollect=getElementbyClass(alltags, "showstate")
if (enablepersist=="on" && ccollect.length>0){
document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0" 
firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load
if (!firsttimeload)
revivecontent()
}
if (ccollect.length>0 && statecollect.length>0)
revivestatus()
}

if (window.addEventListener)
window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
window.attachEvent("onload", do_onload)
else if (document.getElementById)
window.onload=do_onload

if (enablepersist=="on" && document.getElementById)
window.onunload=saveswitchstate

//------------- ABAS --------------------------------------------------------------------------------

// ---- função que cria em cada posição do array 3 novos objectos
function stAba(menuAbasBg,menuAbas,conteudo)
{
	this.menuAbasBg = menuAbasBg;
	this.menuAbas = menuAbas;
	this.conteudo = conteudo;
}

// ---- array dos conteudos exisistentes
var arAbas = new Array();
arAbas[0] = new stAba('1','teste1','div_teste1');
arAbas[1] = new stAba('2','teste2','div_teste2');
arAbas[2] = new stAba('3','teste3','div_teste3');
arAbas[3] = new stAba('4','teste4','div_teste4');
arAbas[4] = new stAba('5','teste5','div_teste5');
arAbas[5] = new stAba('6','teste6','div_teste6');
arAbas[6] = new stAba('7','teste7','div_teste7');
arAbas[7] = new stAba('8','teste8','div_teste8');
arAbas[8] = new stAba('9','teste9','div_teste9');
arAbas[9] = new stAba('10','teste10','div_teste10');


var arAbas2 = new Array();
arAbas2[0] = new stAba('1','teste1','div_teste1');
arAbas2[1] = new stAba('2','teste2','div_teste2');
arAbas2[2] = new stAba('3','teste3','div_teste3');
arAbas2[3] = new stAba('4','teste4','div_teste4');
arAbas2[4] = new stAba('5','teste5','div_teste5');
arAbas2[5] = new stAba('6','teste6','div_teste6');
arAbas2[6] = new stAba('7','teste7','div_teste7');
arAbas2[7] = new stAba('8','teste8','div_teste8');
arAbas2[8] = new stAba('9','teste9','div_teste9');
arAbas2[9] = new stAba('10','teste10','div_teste10');
arAbas2[10] = new stAba('11','teste11','div_teste11');
arAbas2[11] = new stAba('12','teste12','div_teste12');
arAbas2[12] = new stAba('13','teste13','div_teste13');
arAbas2[13] = new stAba('14','teste14','div_teste14');
arAbas2[14] = new stAba('15','teste15','div_teste15');
arAbas2[15] = new stAba('16','teste16','div_teste16');
arAbas2[16] = new stAba('17','teste17','div_teste17');
arAbas2[17] = new stAba('18','teste18','div_teste18');
arAbas2[18] = new stAba('19','teste19','div_teste19');


var arAbas3 = new Array();
arAbas3[0] = new stAba('1','91','991');
arAbas3[1] = new stAba('2','92','992');
arAbas3[2] = new stAba('3','93','993');
arAbas3[3] = new stAba('4','94','994');
arAbas3[4] = new stAba('5','95','995');
arAbas3[5] = new stAba('6','96','996');
arAbas3[6] = new stAba('7','97','997');
arAbas3[7] = new stAba('8','98','998');
arAbas3[8] = new stAba('9','99','999');
arAbas3[9] = new stAba('10','910','9910');
arAbas3[10] = new stAba('11','911','9911');
arAbas3[11] = new stAba('12','912','9912');
arAbas3[12] = new stAba('13','913','9913');
arAbas3[13] = new stAba('14','914','9914');
arAbas3[14] = new stAba('15','915','9915');
arAbas3[15] = new stAba('16','916','9916');
arAbas3[16] = new stAba('17','917','9917');
arAbas3[17] = new stAba('18','918','9918');
arAbas3[18] = new stAba('19','919','9919');
arAbas3[19] = new stAba('20','920','9920');
arAbas3[20] = new stAba('21','921','9921');



// função que onclick muda a class da div
function AlternarAbas(menuAbasBg,menuAbas,conteudo,abas)
{
	
	//alert(menuAbasBg+ " " + menuAbas + " " + conteudo);	
	
	
	// percorre o array e atribui uma class 
	for (i=0;i<abas.length;i++)
	{
		if(document.getElementById(abas[i].menuAbasBg)!=null &&
		   document.getElementById(abas[i].menuAbas)!=null &&
		   document.getElementById(abas[i].conteudo) !=null){
		
		b = document.getElementById(abas[i].menuAbasBg);
		b.className = 'menuAbasBg';		
		m = document.getElementById(abas[i].menuAbas);
		m.className = 'menuAbas';
		c = document.getElementById(abas[i].conteudo);
		c.style.display = 'none';}
	//alert("--" + abas[i].menuAbasBg+ " " + abas[i].menuAbas + " " + abas[i].conteudo);	
		
	}
	//atribui uma class ao objecto selecionado
	
	if(document.getElementById(menuAbasBg)!=null &&
		document.getElementById(menuAbas)!=null &&
		document.getElementById(conteudo)!=null
		){
			
	//alert("--" + menuAbasBg+ " " + menuAbas + " " + conteudo);	
		
	
	b = document.getElementById(menuAbasBg);
	b.className = 'menuAbasBg-sel';	
	m = document.getElementById(menuAbas);
	m.className = 'menu-sel';
	c = document.getElementById(conteudo);
	c.style.display = '';
	
	}
}


function window_url(stranchor){
				var pos = window.location.href.indexOf("#")
				if (pos>=0){
					window.location = window.location.href.substr(0,pos) + stranchor
				}else{
					window.location = window.location + stranchor
				} 
			}
			
function window_noticias(){
				
	var pos2 = window.location.href.indexOf("?");
	var pos = window.location.href.indexOf("#");
	if (pos>=0){
		window.location = "_GA_C401.psml" + window.location.href.substr(pos2,pos) 
	}else{
		window.location = "_GA_C401.psml" + window.location.href.substr(pos2,1000) 
	} 
}
			
function window_eventos(){
				
	var pos2 = window.location.href.indexOf("?");
	var pos = window.location.href.indexOf("#");
	if (pos>=0){
		window.location = "_GA_C402.psml" + window.location.href.substr(pos2,pos) 
	}else{
		window.location = "_GA_C402.psml" + window.location.href.substr(pos2,1000) 
	} 
}	



