var sdsimbol = new Array("1", "2", "3", "4", "5", "6", "7", "8", "9", "0");

// ---------------------------------------- // ----------------------------------------

function accaoArt(escolha){

	var selecionado;

	if(idArtigo.length > 1){

		for(i=0; i<=idArtigo.length -1; i++){
			if(idArtigo[i].checked == true){
				selecionado = true;
				break
			}
		}
		if(selecionado == true){

			if(escolha == "associarFich")
				window.open("artigo.asp?idNav=" + idNav.value + "&act=6&ref="+idArtigo[i].value,"_self");

			if(escolha == "associarImg")
				window.open("artigo.asp?idNav=" + idNav.value + "&act=5&ref="+idArtigo[i].value,"_self");

			if(escolha == "preview")
				window.open("../../default.asp?idNav=" + idNav.value + "&ref="+idArtigo[i].value,"_blank");

			if(escolha == "associarMenu")
				window.open("artigo.asp?idNav=" + idNav.value + "&act=4&ref="+idArtigo[i].value,"_self");

			if(escolha == "associarArtigo")
				window.open("menu.asp?idNav=" + idNav.value + "&act=5&ref="+idArtigo[i].value,"_self");

			if(escolha == "associarFerramenta")
				window.open("../associaMenuFerramenta/associaMenuFerramenta.asp?idNav=" + idNav.value + "&act=1&ref="+idArtigo[i].value,"_self");

		}

	}else{

		if(idArtigo.checked == true){
			selecionado = true;
		}

		if(selecionado == true){

			if(escolha == "associarFich")
				window.open("artigo.asp?idNav=" + idNav.value + "&act=6&ref="+idArtigo.value,"_self");

			if(escolha == "associarImg")
				window.open("artigo.asp?idNav=" + idNav.value + "&act=5&ref="+idArtigo.value,"_self");

			if(escolha == "preview")
				window.open("../../default.asp?idNav=" + idNav.value + "&ref="+idArtigo.value,"_blank");

			if(escolha == "associarMenu")
				window.open("artigo.asp?idNav=" + idNav.value + "&act=4&ref="+idArtigo.value,"_self");

			if(escolha == "associarArtigo")
				window.open("menu.asp?idNav=" + idNav.value + "&act=5&ref="+idArtigo.value,"_self");

			if(escolha == "associarFerramenta")
				window.open("../associaMenuFerramenta/associaMenuFerramenta.asp?idNav=" + idNav.value + "&act=1&ref="+idArtigo.value,"_self");

		}

	}

}

// ---------------------------------------- // ----------------------------------------

function focusLogin(){
	frmLogon.login.focus();
}

// ---------------------------------------- // ----------------------------------------

function toggleCollapse( targetId ){
  if (document.getElementById){
//		alert(targetId);
		Collapse();
		target = document.getElementById( targetId );
			if (target.style.display == "none"){
				target.style.display = "";
			} else {
				target.style.display = "none";
			}
	}
}

function toggle( targetId ){
  if (document.getElementById){
//		alert(targetId);
		target = document.getElementById( targetId );
			if (target.style.display == "none"){
				target.style.display = "";
			} else {
				target.style.display = "none";
			}
	}
}


// togglehide('showclients')
function togglehide( targetId ){
  if (document.getElementById){
//		alert("togglehide");  
		target = document.getElementById( targetId );
		target.style.display = "none";
  }
}

// ---------------------------------------- // ----------------------------------------

function Collapse() {	
   divs=document.getElementsByTagName("DIV");
   for (i=0;i<divs.length;i++) {
	  
     divs[i].style.display="none";
	}
      
}

// ---------------------------------------- // ----------------------------------------

function testHtmlSourceViewTrue()
{
	//se esta variavel estiver a false quer dizer q a view esta em html
	if(htmlSwap==false){
		toggleHTML()
	}
}

// ---------------------------------------- // ----------------------------------------

function chkFrmLogon(){
	if(frmLogon.login.value == ""){
		alert("Por favor preencha o login.");
		frmLogon.login.focus();
		return false;
	}
	if(frmLogon.pwAcesso.value == ""){
		alert("Por favor preencha a password.");
		frmLogon.pwAcesso.focus();
		return false;
	}
	if(frmLogon.pwAcesso.value.length <= 3){
		alert("Por favor preencha a password com mais de 3 caracteres.");
		frmLogon.pwAcesso.focus();
		return false;
	}
}

// ---------------------------------------- // ----------------------------------------

function goUrl(strUrl){
	location.href= strUrl + "&opc=" + frmMenu.opc.value;
}

// ---------------------------------------- // ----------------------------------------

function goLingua(strUrl){
	location.href= strUrl + "&lng=" + frmMenu.lng.value  + "&opc=" + frmMenu.opc.value;
}

// ---------------------------------------- // ----------------------------------------

function openWinImagemThumb(strImg){
	window.open(strImg, "imagem", " width=50, height=50, navbar=false,maxbutton=true");
}

// ---------------------------------------- // ----------------------------------------

function openWinImagemGrande(strImg){
	window.open(strImg, "imagem", " navbar=false,maxbutton=true");
}

// ---------------------------------------- // ----------------------------------------

function openWinImagem(strImg){
	window.open(strImg, "imagem", "navbar=false,maxbutton=true");
}

// ---------------------------------------- // ----------------------------------------

function chkQuerApagar(){
var x = "";
x = window.confirm("Tem a certeza que quer apagar este registo?");

if (x==true){
	return true;
	}
else
	{
	return false;
	}

}

// ---------------------------------------- // ----------------------------------------

function chkQuerApagar(strApagar){
var x = "";
x = window.confirm(strApagar);

if (x==true){
	return true;
	}
else
	{
	return false;
	}

}

// ---------------------------------------- // ----------------------------------------

function check(input,simbol) {
  var ok = true;
  for (var i = 0; i < input.length; i++) {
    var chr = input.charAt(i);
    var found = false;
    for (var j = 0; j < simbol.length; j++) {
  
      if (chr == simbol[j]){
        found = true;
        break;
       }
    }
    if (!found) ok = false;
  }
  return ok;
}

// ---------------------------------------- // ----------------------------------------

function eQntValida(text) {
  if (!(text.value == "")) {
		strCheck=text.value;
		if (!check(strCheck,sdsimbol)) {
			alert("As quantidades tem de estar entre 1 e 999.");
			text.value = 1;
			text.focus();      
		}
   else {
		if (text.value < 1 || text.value > 999) {
			alert("As quantidades tem de estar entre 1 e 999."); 
			text.value = 1;
			text.focus();
		}		
    }
  }
}

// ---------------------------------------- // ----------------------------------------

function chkFrmConta(frmConta){
	if(frmConta.nome.value == ""){
		alert("Preencha o seu nome.");
		frmConta.nome.focus();
		return false;	
	}
	
/*	if(frmConta.apelido.value == ""){
		alert("Preencha o seu apelido.");
		frmConta.apelido.focus();
		return false;	
	}

	if(frmConta.morada.value == ""){
		alert("Preencha a sua morada.");
		frmConta.morada.focus();
		return false;	
	}

	if(frmConta.codigoPostal.value == ""){
		alert("Preencha o código Postal.");
		frmConta.codigoPostal.focus();
		return false;	
	}

	if(isNaN(frmConta.codigoPostal.value)){
		alert("Preencha o código postal só com numeros.");
		frmConta.codigoPostal.focus();
		return false;
	}

	if(frmConta.codigoPostal.value.length < 4){
		alert("Preencha o código postal com 4 numeros.");
		frmConta.codigoPostal.focus();
		return false;
	}

	if(frmConta.codigoPostal2.value != ""){

		if(isNaN(frmConta.codigoPostal2.value)){
			alert("Preencha o código postal só com numeros.");
			frmConta.codigoPostal2.focus();
			return false;
		}

		if(frmConta.codigoPostal2.value.length < 3){
			alert("Preencha o código postal com 3 numeros.");
			frmConta.codigoPostal2.focus();
			return false;
		}

	}

	if(frmConta.codigoPostal3.value == ""){
		alert("Preencha a Localidade.");
		frmConta.codigoPostal3.focus();
		return false;	
	}

	if(frmConta.numeroContribuinte.value == ""){
		alert("Preencha o numero de contribuinte.");
		frmConta.numeroContribuinte.focus();
		return false;	
	}
	
	if(isNaN(frmConta.numeroContribuinte.value)){
		alert("Preencha o numero de contribuinte só com numeros.");
		frmConta.numeroContribuinte.focus();
		return false;	
	}

	if(frmConta.tlf.value == ""){
		alert("Preencha o telefone.");
		frmConta.tlf.focus();
		return false;	
	}
	
	if(isNaN(frmConta.tlf.value)){
		alert("Preencha o telefone só com numeros.");
		frmConta.tlf.focus();
		return false;	
	}

	if(frmConta.tlf.value.length < 9){
		alert("Preencha o telefone com 9 numeros.");
		frmConta.tlf.focus();
		return false;	
	}

	if(frmConta.tlm.value != ""){
		if(isNaN(frmConta.tlm.value)){
			alert("Preencha o telemóvel só com numeros.");
			frmConta.tlm.focus();
			return false;	
		}

		if(frmConta.tlm.value.length < 9){
			alert("Preencha o telemóvel com 9 numeros.");
			frmConta.tlm.focus();
			return false;	
		}
	}
*/
	if(frmConta.email.value == ""){
		alert("Preencha o email.");
		frmConta.email.focus();
		return false;	
	}

	if (frmConta.email.value.indexOf(".")==-1 || frmConta.email.value.indexOf("@")==-1 ){
		alert("O email não está correctamente preenchido.");
		frmConta.email.focus();
		return false;
	}

	if(frmConta.pass.value == ""){
		alert("Preencha a password");
		frmConta.pass.focus();
		return false;	
	}
	
	if(frmConta.confPassword.value == ""){
		alert("Preencha a reconfirmação da password.");
		frmConta.confPassword.focus();
		return false;	
	}

	if(frmConta.pass.value != frmConta.confPassword.value){
		alert("A password e reconfirmação de password não coincidem.");
		frmConta.pass.focus();
		return false;	
	}
	
	if(frmConta.idNivelSeguranca.value == ""){
		alert("Escolha o nível de Acesso.");
		frmConta.idNivelSeguranca.focus();
		return false;	
	}
return true;
}

// ---------------------------------------- // ----------------------------------------

function chkFrmFicheiro(frmFicheiro){
	if(frmFicheiro.nome.value == ""){
		alert("Atenção, prencha o nome do ficheiro.");
		frmFicheiro.nome.focus();
		return false;
	}
	if(frmFicheiro.ficheiro.value == ""){
		alert("Atenção, escolha o ficheiro para realizar o upload.");
		frmFicheiro.ficheiro.focus();
		return false;
	}
	if(frmFicheiro.tipoFicheiro.value == ""){
		alert("Atenção, escolha o tipo de ficheiro.");
		frmFicheiro.tipoFicheiro.focus();
		return false;
	}
return true;
}

// ---------------------------------------- // ----------------------------------------

function chkFrmImagem(frmImagem){
	if(frmImagem.nome.value == ""){
		alert("Atenção, prencha o nome da imagem.");
		frmImagem.nome.focus();
		return false;
	}
	if(frmImagem.ficheiro.value == ""){
		alert("Atenção, escolha o ficheiro para realizar o upload.");
		frmImagem.ficheiro.focus();
		return false;
	}
	if(frmImagem.tipoFicheiro.value == ""){
		alert("Atenção, escolha o tipo de ficheiro.");
		frmImagem.tipoFicheiro.focus();
		return false;
	}
return true;
}

// ---------------------------------------- // ----------------------------------------

function chkFrmNivelSeguranca(frmNivelSeguranca){

	if(frmNivelSeguranca.descricao.value == ""){
		alert("Preencha a descrição.");
		frmNivelSeguranca.descricao.focus();
		return false;
	}

	if(frmNivelSeguranca.nivelSeguranca.value == ""){
		alert("Preencha o nível de segurança.");
		frmNivelSeguranca.nivelSeguranca.focus();
		return false;
	}

	if(isNaN(frmNivelSeguranca.nivelSeguranca.value)){
		alert("Preencha a nível de seguranca com um valor inteiro.");
		frmNivelSeguranca.nivelSeguranca.focus();
		return false;
	}
	if(frmNivelSeguranca.nivelSeguranca.value<1){
		alert("Preencha a nível de seguranca com um valor maior que 1.");
		frmNivelSeguranca.nivelSeguranca.focus();
		return false;
	}
return true;
}

// ---------------------------------------- // ----------------------------------------

function chkFrmCategoriaMenu(frmCategoriaMenu){

	if(frmCategoriaMenu.categoriaMenu.value == ""){
		alert("Preencha a categoria de Menu.");
		frmCategoriaMenu.categoriaMenu.focus();
		return false;
	}

	if(frmCategoriaMenu.idNivelSeguranca.value == ""){
		alert("Escolha o nível de segurança.");
		frmCategoriaMenu.idNivelSeguranca.focus();
		return false;
	}
return true;
}

// ---------------------------------------- // ----------------------------------------

function openTargetLink(URI, target, width, height, scrollbars, resizable, strLocation){
win = window.open(URI,"" + target + "","height=" + height + ",width=" + width + ",scrollbars=" + scrollbars + ",resizable=" + resizable + ",location=" + strLocation + "");
win.focus;
}

function validaNumerico()
{
	if (event.keyCode > 57 || event.keyCode < 48)
	{
		event.returnValue = false;
	}
}


function toggleMenu(item, str) {
   obj=document.getElementById("m" + item);
   visible=(obj.style.display!="none")
   key=document.getElementById("x" + item);
   if (visible) {
     obj.style.display="none";
     key.innerHTML="<IMG SRC='../images/tree/Plusbox.gif' WIDTH='15' HEIGHT='17' BORDER='0' ALT='" + str + "' align='left'><IMG SRC='../images/icons/icon_menus.jpg' WIDTH='20' HEIGHT='20' BORDER='0' ALT='" + str + "' align='left'>" + str;
   } else {
      obj.style.display="block";
      key.innerHTML="<IMG SRC='../images/tree/Minubox.gif' WIDTH='15' HEIGHT='17' BORDER='0' ALT='" + str + "' align='left'><IMG SRC='../images/icons/icon_menus.jpg' WIDTH='20' HEIGHT='20' BORDER='0' ALT='" + str + "' align='left'>" + str;
   }
}
function toggleMenuHyperlink(item, str) {
   obj=document.getElementById("m" + item);
   visible=(obj.style.display!="none")
   key=document.getElementById("x" + item);
   if (visible) {
     obj.style.display="none";
     key.innerHTML="<IMG SRC='../admin/images/tree/Plusbox.gif' WIDTH='15' HEIGHT='17' BORDER='0' ALT='" + str + "' align='left'><IMG SRC='../admin/images/icons/icon_menus.jpg' WIDTH='20' HEIGHT='20' BORDER='0' ALT='" + str + "' align='left'>" + str;
   } else {
      obj.style.display="block";
      key.innerHTML="<IMG SRC='../admin/images/tree/Minubox.gif' WIDTH='15' HEIGHT='17' BORDER='0' ALT='" + str + "' align='left'><IMG SRC='../admin/images/icons/icon_menus.jpg' WIDTH='20' HEIGHT='20' BORDER='0' ALT='" + str + "' align='left'>" + str;
   }
}

function expandMenu() {
   divs=document.getElementsByTagName("DIV");
   for (i=0;i<divs.length;i++) {
     divs[i].style.display="block";
     key=document.getElementById("x" + divs[i].id);
     key.innerHTML="<img src='../images/tree/Plusbox.gif' width='15' height='17' hspace='0' vspace='0' border='0' align='left'>";
   }
}

function collapseMenu() {
   divs=document.getElementsByTagName("DIV");
   for (i=0;i<divs.length;i++) {
     divs[i].style.display="none";
     key=document.getElementById("x" + divs[i].id);
     key.innerHTML="<img src='../images/tree/Minubox.gif' width='15' height='17' hspace='0' vspace='0' border='0' align='left'>";
   }
}

function togglePasta(item, str) {
   obj=document.getElementById("u" + item);
   visible=(obj.style.display!="none")
   key=document.getElementById("x" + item);
   if (visible) {
     obj.style.display="none";

     key.innerHTML="<IMG SRC='../images/tree/Plusbox.gif' WIDTH='15' HEIGHT='17' BORDER='0' ALT='" + str + "' align='left'><IMG SRC='../images/icons/icon_pastas.jpg' WIDTH='19' HEIGHT='16' BORDER='0' ALT='" + str + "' align='left'>" + str;
   } else {
      obj.style.display="block";
      key.innerHTML="<IMG SRC='../images/tree/Minubox.gif' WIDTH='15' HEIGHT='17' BORDER='0' ALT='" + str + "' align='left'><IMG SRC='../images/icons/icon_pastas.jpg' WIDTH='19' HEIGHT='16' BORDER='0' ALT='" + str + "' align='left'>" + str;
   }
}

function PrintThisPage() 
{ 
   var sOption="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
       sOption+="scrollbars=yes,width=750,height=600,left=100,top=25"; 

   var sWinHTML = document.getElementById('divPrint').innerHTML; 
   
   var winprint=window.open("","",sOption); 
       winprint.document.open(); 
       winprint.document.write('<html>\n')
	   winprint.document.write('<Link rel="stylesheet" href="<%=urlPath%>includes/wsb.css" type="text/css">\n');
	   winprint.document.write('<body bgcolor="<%=BGCOLORMENUFRONTEND%>" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"><br />\n'); 
       winprint.document.write(sWinHTML);          
       winprint.document.write('</body>\n</html>\n'); 
       winprint.document.close(); 
       winprint.focus(); 
}