var WinLinks=null;
function open_new_window(vUrl, bFscreen){
	if (WinLinks)
		WinLinks.close();

	var loopCount=0;
	var i=0;
	var iLeft=bFscreen ? 0 : (screen.availWidth-800)/2;
	var iTop=bFscreen ? 0 : (screen.availHeight-600);
	var iWidth=bFscreen ? screen.availWidth : 400;
	var iHeight=bFscreen ? screen.availHeight : 350;
	var bMenu=bFscreen ? 1 : 0;
	
	WinLinks = open('about:blank',"linkWin","scrollbars=yes,menubar=" + bMenu + ",toolbar=no,resizeable=no,width=" + iWidth + ",height=" + iHeight + ",top=" + iTop + ",left=" + iLeft + "");

	while (!WinLinks.document.body)
		loopCount++;

	WinLinks.document.title="Upload de Imagem";
	//WinLinks.document.body.innerHTML=sHTML;
	WinLinks.document.body.style.backgroundColor='#ffffff';
	WinLinks.document.close();
	WinLinks.document.location=vUrl;
	WinLinks.focus();
}

function altera_tabs(mostra,esconde){
	if (mostra.style.display=='none'){
		mostra.style.display='';
		esconde.style.display='none'
	}else{
		mostra.style.display='none';
		esconde.style.display='';
	}
}

function imageCheck() {
	txt=document.forms[0].userfile.value; 
	tit=document.forms[0].titulo.value; 

	if(txt==""){
		alert("Deverá inserir um ficheiro primeiro.");
		return false; 
	}
	if((txt.indexOf(".jpg") == -1) && (txt.indexOf(".JPG") == -1)) {
		alert("Só poderá fazer upload de imagens no formato JPG.");
		return false; 
	}	
	if(tit=="") {
		alert("Deverá inserir um título.");
		return false; 
	}
	return true; 
}

function retornaTag(img){
	opener.document.all.conteudo.value+='<img src="imagens/'+img+'">';
	self.close();
}

function validaLink() {
	f=document.forms[0]; 
	if(f.catexistentes.value==""){
		alert("Deverá associar o Link a uma Categoria.");
		return false;
	}
	if(f.catexistentes.value=="novo" && f.novacat.value==""){
		alert('Deverá inserir o nome da Nova Categoria');
		return false;
	}
	if(f.nomelink.value==""){
		alert("Deverá associar um Nome ao Link.");
		return false; 
	}
	if(f.urllink.value==""){
		alert("Deverá inserir um URL.");
		return false; 
	}
	if(f.desclink.value==""){
		alert("Deverá associar uma pequena descrição do conteúdo do Link.");
		return false; 
	}
	// se a funcao chegar aqui...
	if(f.catexistentes.value=="novo"){
		f.categoria.value=f.novacat.value;
		return true;
	}else{
		f.categoria.value=f.catexistentes.value;
		return true;
	} 
}
function novaCateogoria(){
	f=document.forms[0];
	alert(f.categoria.value);
	if(f.categoria.value=="0"){
		newcat.style.display='';
	}else{
		newcat.style.display='none';
	}

}

function validaComent() {
	f=document.forms[0]; 
	if(f.nome.value==""){
		alert("Deverá inserir um Nome.");
		return false;
	}
	if(f.email.value==""){
		alert('Deverá inserir o seu email.');
		return false;
	}
	if(f.comentario.value==""){
		alert("Deverá inserir o Comentário!");
		return false; 
	}
}