// ----------- 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');

// função que onclick muda a class da div
function AlternarAbas(menuAbasBg,menuAbas,conteudo,abas)
{
	// percorre o array e atribui uma class 
	for (i=0;i<abas.length;i++)
	{
		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';
	}
	//atribui uma class ao objecto selecionado
	b = document.getElementById(menuAbasBg);
	b.className = 'menuAbasBg-sel';	
	m = document.getElementById(menuAbas);
	m.className = 'menu-sel';
	c = document.getElementById(conteudo);
	c.style.display = '';
}

//Função que muda a checkbox
function submitAndCheckGlobal(formname)
{
	error = false;
	if(document[formname].global_searchstring.value=="") error = true;
	if(document[formname].global_news.value=="0" && document[formname].global_members.value=="0" && document[formname].global_interviews.value=="0" && 
	   document[formname].global_events.value=="0" && document[formname].global_forum.value=="0" && document[formname].global_faq.value=="0")	 error = true;

	if(document[formname].global_searchstring.value.length<3) 
	{
		document[formname].global_searchstring.value+= " << more chars please!";
		error = true;
	}
	
	

	if(error)
	return false;
}
function submitAndCheck(formname)
{
	if(document[formname].searchstring.value=="")
	return false;
}
function selectNone(box,amount,formname,startElement)
{
	for(i=0;i<amount;i++)
	{
		document[box+""+i].src = "imagens/iconHover.gif";
		document[formname].elements[i+startElement].value = "0";		
	}
}

function selectAll(box,amount,formname,startElement)
{
	for(i=0;i<amount;i++)
	{
		document[box+""+i].src ="imagens/iconHover.gif";
		document[formname].elements[i+startElement].value = "1";		
	}
}

function setCheckbox(img,id,formname)
{
//alert(img);
 	if (document[formname][id].value=="0") 
	{
		document[img].src = "imagens/iconHover.gif";		
		document[formname][id].value = "1";		
	}
	else
	{
		document[img].src = "imagens/icon.gif";		
		document[formname][id].value = "0";		
	}	

}


// form validation ----------------------------------------------------------------------

/***********************************************
* Required field(s) validation v1.10- By NavSurf
* Visit Nav Surf at http://navsurf.com
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function formCheck(formobj,fieldRequired,fieldDescription,alertMsg){
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select":	
			case "file":
			case "checkbox":
			case "text":
			case "password":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}
// --------------  Chamada do editor de Html antes do header -------------------------------------------------------------
function Html(){
_editor_url = "";                     // URL to htmlarea files
var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
if (navigator.userAgent.indexOf('Mac')        >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Opera')      >= 0) { win_ie_ver = 0; }
if (win_ie_ver >= 5.5) {
  document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js"');
  document.write(' language="Javascript1.2"></scr' + 'ipt>');  
} else { document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); }
}
// --------------  Chamada do editor de Html -------------------------------------------------------------
function editorHtml(campo,w,h){

<!-- // load htmlarea
_editor_url = "";                     // URL to htmlarea files
var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
if (navigator.userAgent.indexOf('Mac')        >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Opera')      >= 0) { win_ie_ver = 0; }
if (win_ie_ver >= 5.5) {
  document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js"');
  document.write(' language="Javascript1.2"></scr' + 'ipt>');  
} else { document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); }
// -->


var config = new Object();    // create new config object

config.width = w;
config.height = h;
config.bodyStyle = 'background-color: white; font-family: "Verdana"; font-size: xx-small; color:#9d9d9d;';
config.debug = 0;

// NOTE:  You can remove any of these blocks and use the default config!

config.toolbar = [
    ['bold','italic','underline','htmlmode','separator'],
//    ['fontstyle'],
//    ['linebreak'],
//  ['strikethrough','subscript','superscript','separator'],
    ['OrderedList','UnOrderedList','Outdent','Indent','separator'],

];


//config.stylesheet = "http://www.domain.com/sample.css";
  
config.fontstyles = [   // make sure classNames are defined in the page the content is being display as well in or they won't work!
//  { name: "headline",     className: "headline",  classStyle: "font-family: arial black, arial; font-size: 28px; letter-spacing: -2px;" },
//  { name: "arial red",    className: "headline2", classStyle: "font-family: arial black, arial; font-size: 12px; letter-spacing: -2px; color:red" },
//  { name: "verdana blue", className: "headline4", classStyle: "font-family: verdana; font-size: 18px; letter-spacing: -2px; color:blue" }

// leave classStyle blank if it's defined in config.stylesheet (above), like this:
  { name: "verdana blue", className: "headline1", classStyle: "" }  
];

editor_generate(campo,config);
}
// --------------  Confirmação ao apagar -------------------------------------------------------------
function apaga(url){
		   if(confirm('Deseja Apagar o registo?')){
		      window.location=url;
		   }
		  }
function alterar(url){
		   if(confirm('Deseja Alterar o registo?')){
		      window.location=url;
		   }
		  }		




