// JavaScript Document
function colocaImgOpcao2(op){
	
	
	document.getElementById("imgopcoes").innerHTML = op;
	}	
		
function ampliaFoto(){

	window.open(imgs[current].src,'mywindow','width=500,height=500,left=10,top=10');
	}

function colocaImgOpcao(op){
	
	if(op){
	if(document.getElementById("try").value == 'Stop')
	document.getElementById("imgopcoes").innerHTML = 'Parar slideshow';
	else
	document.getElementById("imgopcoes").innerHTML = 'Continuar slideshow';
	}else
	document.getElementById("imgopcoes").innerHTML = '';
	}
	
function mudaSlideImg(){

	if(document.getElementById("try").value == 'Stop'){
		document.getElementById("try").value = 'Play';
		document.getElementById("pauseBtn").src = 'ngest/images/play.jpg';		
	}else{
		document.getElementById("try").value = 'Stop';
		document.getElementById("pauseBtn").src = 'ngest/images/stop.jpg';
		}
	}	
	
function mudaSlideImg2(op){

	if(op == 'Play'){
		document.getElementById("try").value = 'Play';
		document.getElementById("pauseBtn").src = 'ngest/images/play.jpg';		
	}
	if(op == 'Stop'){
		document.getElementById("try").value = 'Stop';
		document.getElementById("pauseBtn").src = 'ngest/images/stop.jpg';
		}
	}	


function starImovel(nome, id, n){
	
	if(n<6){
		if(confirm('Deseja destacar o imóvel: '+nome+' ?'))
			document.location.href="index.php?progoption=imoveis&do=starimovel&id="+id;
}else{
		alert('Tem um máximo de 6 destaques já definidos. Para destacar este imóvel, por favor retire de destaque algum dos imóvel já destacados!');
}
	}
	
function destarImovel(nome, id, n){
	
	if(confirm('Deseja retirar de destaque o imóvel: '+nome+' ?'))
		document.location.href="index.php?progoption=imoveis&do=destarimovel&id="+id;
	
	
	}	

function page1login(){
	
	document.form1.login.value=document.getElementById("login2").value;
	document.form1.pwd.value=document.getElementById("pwd2").value;
	document.form1.url.value=document.getElementById("url2").value;
	
	document.form1.submit();
	
	}
var antigo="";
function form1pagecg(op){
	
	colocar="";
	if(document.getElementById("userx").value=='nao')
		colocar='<div style="width:450px;" align="right"><span class="formlabel" style="color:#94202f;">username&nbsp;&nbsp;</span><input id="login2" type="text" class="formuser" /><span class="formlabel" style="color:#94202f;">password&nbsp;&nbsp;</span><input id="pwd2" type="password" class="formuser" /><input id="url2" type="hidden" value="default.php?progoption=page1login#page1form1"/><a href="javascript:page1login();" class="formbotao" style="margin:3px;"/>&nbsp;Ok&nbsp;</a><a href="index.php?progoption=novoregisto" class="formbotao" style="margin:3px;">&nbsp;&nbsp;Registe-se aqui&nbsp;&nbsp;</a></div>';
	else
		colocar='<div style="width:450px;margin-bottom:10px;" align="right">Como já se registou no sistema, pode enviar os dados do seu imóvel <a href="index.php?progoption=imoveis&do=imovelinsertform" style="font-weight:bold;">- aqui -</a></div>';
	
	box = document.getElementById("desejo");
	des = box.options[box.selectedIndex].value;
	if(des=='vender'||op=='vender'){
		//antigo=document.getElementById("form1page").innerHTML;
		document.getElementById("form1page").innerHTML='<a href="default.php" class="ngesttextbold" style="margin-left:15px;"><li>- Voltar</li></a><ul><li>Para poder colocar o seu imóvel tem de estar registado;</li><li>Colocar através da funcionalidade respectiva os dados do imóvel;</li><li>Aguardar que o seu registo seja validado após confirmação e formalização do contracto. Será contactado para esse fim.</li></ul>'+colocar;
	
	}
}
function pesRap(){
	
	nat=conc=freg=dist="";
	box = document.getElementById("pnatureza");
	nat = box.options[box.selectedIndex].value;
	
	box = document.getElementById("pdistrito");
	dist = box.options[box.selectedIndex].value;
	
	box = document.getElementById("pconcelho");
	conc = box.options[box.selectedIndex].value;
	
	box = document.getElementById("pfreguesia");
	freg = box.options[box.selectedIndex].value;
	
	document.location.href="index.php?progoption=imoveis&do=imovelsearch&nat="+nat+"&conc="+conc+"&freg="+freg+"&dist="+dist;
	
	}
	
var infovisivel='inicio';

function veInfo(nome){
	if(nome!=infovisivel){
	document.getElementById(nome+'but').style.backgroundColor="#006699";
	document.getElementById(nome+'but').style.color="#FFFFFF";
	if(infovisivel!='inicio'){
	document.getElementById(infovisivel+'but').style.backgroundColor="#E4E4E4";
	document.getElementById(infovisivel+'but').style.color="#999999";
	}
	document.getElementById('informacao').innerHTML=document.getElementById(nome).innerHTML;
	infovisivel=nome;
	}
	}

function apagarImovel(nome, id){
	
	if(confirm('Tem a certeza que deseja apagar o imóvel: '+nome+' ?'))
		document.location.href="index.php?progoption=imoveis&do=apagaimovel&id="+id;
	
	}

function apagardistrito(nome, id){
	if(confirm('Tem a certeza que deseja apagar o distrito: '+nome+' ?'))
		document.location.href="index.php?progoption=imoveis&do=apagadistrito&distid="+id;
	
	}
function apagarconcelho(nome, id){
	if(confirm('Tem a certeza que deseja apagar o concelho: '+nome+' ?'))
		document.location.href="index.php?progoption=imoveis&do=apagaconcelho&concid="+id;
	
	}	
function apagarnatureza(nome, id){
	if(confirm('Tem a certeza que deseja apagar a natureza: '+nome+' ?'))
		document.location.href="index.php?progoption=imoveis&do=apaganatureza&naturid="+id;
	
	}	
function apagartipologia(nome, id){
	if(confirm('Tem a certeza que deseja apagar a tipologia: '+nome+' ?'))
		document.location.href="index.php?progoption=imoveis&do=apagatipologia&tipolid="+id;
	
	}
function apagartiponegocio(nome, id){
	if(confirm('Tem a certeza que deseja apagar o tipo de negócio: '+nome+' ?'))
		document.location.href="index.php?progoption=imoveis&do=apagatiponegocio&tiponid="+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";
	
}

