// JavaScript Document
function apagaGaleria(id, nome){
	
	if(confirm('Tem a certeza que deseja apagar a galeria:\n'+nome+'?'))
		document.location.href="index.php?progoption=photoexp&do=deletegallery&galleryid="+id;
	
	}

function apagaSeccao(id, nome){
	
	if(confirm('Tem a certeza que deseja apagar a secção:\n'+nome+'?'))
		document.location.href="index.php?progoption=seccao&do=apagaseccao&secid="+id;
	
	}

function apagaNoticia(id, topico, titulo){
	
	if(confirm('Tem a certeza que deseja apagar a notícia:\n'+titulo+'?'))
		document.location.href="index.php?progoption=news&do=apaganoticia&pageid="+id+"&topicid="+topico;
	
	}

function escolherCategoria(){
	
	document.getElementById("editoria").style.visibility = "visible";
	
	}

function fechaCat(space){
	
	document.getElementById(space).style.height="45px";
	newImage = "url(images/catclose.gif)";
    document.getElementById(space+'topo').style.backgroundImage = newImage;
	document.getElementById(space+'botao').href = "javascript:abreCat(\'"+space+"\');";
	document.getElementById(space+'botao').innerHTML = "<img border=\"0\" src=\"images/mais.gif\"/>";
	}

function abreCat(space){
	
	document.getElementById(space).style.height="auto";
	newImage = "url(images/cattopo.gif)";
    document.getElementById(space+'topo').style.backgroundImage = newImage;
	document.getElementById(space+'botao').href = "javascript:fechaCat(\'"+space+"\');";
	document.getElementById(space+'botao').innerHTML = "<img border=\"0\" src=\"images/menos.gif\"/>";
	}

function newsMostraCats(){
	qual=document.getElementById("topictype").value;
	if(qual=='news'){
		document.getElementById("topiccategory").style.visibility = "visible";
		document.getElementById("categorialabel").style.visibility = "visible";
	}else{
		document.getElementById("topiccategory").selectedIndex=0;
		document.getElementById("topiccategory").style.visibility = "hidden";
		document.getElementById("categorialabel").style.visibility = "hidden";		
		}
	
	}

function apagaEditoria(id, nome){
	
	if(confirm('Deseja apagar a editoria '+nome+'?\n\nAtenção: vai desactivar todas as notícias para esta editoria!!'))
		document.location.href="index.php?progoption=news&do=apagaEditoria&topicid="+id;
	
	}

//parte dos destaques---------------------------

function destacarPrincipal(id, topic){
	
	if(confirm("deseja destacar esta noticia?"))
			document.location.href='index.php?progoption=news&do=destacaprincipal&pageid='+id+'&topicid='+topic;
	
}

function destacar2Principal(id, topic){
	
	if(confirm("deseja destacar esta noticia como outros destaques?"))
			document.location.href='index.php?progoption=news&do=destaca2principal&pageid='+id+'&topicid='+topic;
	
}

function retira2Principal(id, topic){
	
	if(confirm("deseja tirar do destaque esta notícia?"))
			document.location.href='index.php?progoption=news&do=retira2principal&pageid='+id+'&topicid='+topic;
	
}

	

//----------------------------------------------

function apagarpubseccao(seccao,id){

if(confirm ("Apagar espaço: "+seccao+"?\nATENÇÃO: Isto desactivará todas as publicidades associadas!")){

location.href="index.php?progoption=publicidades&do=delpubsec&pubsec="+id;
	}
}

function apagarbanner(seccao,id,ban){

if(confirm ("Apagar banner: "+seccao+"?\nATENÇÃO: Isto desactivará esta publicidade!")){

location.href="index.php?progoption=publicidades&do=delbanner&banid="+id+"&ban="+ban;
	}
}

function limitText(limitField, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} 
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function validateGallery(){
	
	var acolocar, i, erros='', args=validateGallery.arguments;
	acolocar=MM_findObj('galleryname');
	acolocar=acolocar.value;
	for(i=0; i<args.length; i++){
		
			if(args[i].toString()==acolocar.toString())
				erros='O nome da galeria introduzido já se encontra atribuido.\n Por favor introduza outro nome\n';
		}
		
		if (erros) alert('Ocorreram os seguintes erros:\n\n'+erros);
  		document.returnval = (erros == '');
	
}


function validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- O campo '+nm+' deve conter um endereço válido de e-mail.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- O campo '+nm+' deve conter um número.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- O campo '+nm+' deve conter um número entre '+min+' e '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- O campo '+nm+' é obrigatório.\n'; }
  } if (errors) alert('Ocorreram os seguintes erros:\n\n'+errors);
  document.vf_returnval = (errors == '');
}



function doPause()  {
	if(pause) {
		pause = false;
		document.getElementById("pauseBtn").value = "Parar slideshow";
	} else {
		pause = true;
		document.getElementById("pauseBtn").value = "Continuar slideshow";
	}
}


//window.addEventListener?window.addEventListener("load",so_init,false):window.attachEvent("onload",so_init);

var d=document, imgs = new Array(), textos = new Array(), zInterval = null, current=0, pause=false;

textos[0]="texto1";
textos[1]="texto2";
textos[2]="texto3";
textos[3]="texto4";
textos[4]="texto5";
textos[5]="texto6";

function so_init() {
	if(!d.getElementById || !d.createElement)return;
	
	css = d.createElement("link");
	css.setAttribute("href","xfade2.css");
	css.setAttribute("rel","stylesheet");
	css.setAttribute("type","text/css");
	d.getElementsByTagName("head")[0].appendChild(css);
	
	imgs = d.getElementById("imageContainer").getElementsByTagName("img");
	//txts= d.getElementById("texto");
	for(i=1;i<imgs.length;i++) imgs[i].xOpacity = 0;
	imgs[0].style.display = "block";
	imgs[0].xOpacity = .99;
	//txts.innerHTML=textos[current];
	
	setTimeout(so_xfade,5000);
}

function so_xfade() {
	if(pause)setTimeout(so_xfade,35);
	else{
	//txts.innerHTML=textos[(current+1)<=5?(current+1):0];
	cOpacity = imgs[current].xOpacity;
	nIndex = imgs[current+1]?current+1:0;
	nOpacity = imgs[nIndex].xOpacity;
	
	cOpacity-=.05; 
	nOpacity+=.05;
	
	imgs[nIndex].style.display = "block";
	imgs[current].xOpacity = cOpacity;
	imgs[nIndex].xOpacity = nOpacity;
	
	setOpacity(imgs[current]); 
	setOpacity(imgs[nIndex]);
	
	if(cOpacity<=0) {
		imgs[current].style.display = "none";
		current = nIndex;
		
		setTimeout(so_xfade,5000);
				
	} else {
		setTimeout(so_xfade,35);
	}
	}
}
	
	function setOpacity(obj) {
		if(obj.xOpacity>.99) {
			obj.xOpacity = .99;
			return;
		}
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
	}
	


function changeFoto(it)  {
	pause=true;
	imgs[it].style.display = "block";
	imgs[it].xOpacity = .99;
	setOpacity(imgs[it]);
	for(i=0;i<imgs.length;i++) {
		if(i!=it)imgs[i].xOpacity = 0;
		if(i!=it)imgs[i].style.display = "none";
		if(i!=it)setOpacity(imgs[i]);
	}
	imgs[it].style.display = "block";
	imgs[it].xOpacity = .99;
	setOpacity(imgs[it]);
	
	current=it;
	
	document.getElementById("pauseBtn").value = "Continuar slideshow";
	pause=true;
}

function apagarUser(login,id,nome)
{
if(confirm("Apagar utilizador com o login: "+login+" \ne o nome: "+nome+"?\n\nEsta operação não pode ser anulada!"))
{
	
	location.href="index.php?progoption=users&do=del&id="+id;
	
	}
}

function sucessoEditUser()
{
alert("Dados alterados com sucesso");

	
	location.href="index.php?progoption=users&do=list";
	
}


