// selecionar todas as checkboxes de um formulαrio
function selecionar(nomeform) {
var ncampos = document.forms[nomeform].length;
	for (i=0;i<ncampos;i++) {
		if (document.forms[nomeform].elements[i].type == "checkbox") {
			document.forms[nomeform].elements[i].checked=true;
		}
	}
}
// limpar todas as checkboxes de um formulαrio
function limpar_campos(nomeform) {
var ncampos = document.forms[nomeform].length;
	for (i=0;i<ncampos;i++) {
		if (document.forms[nomeform].elements[i].type == "checkbox") {
			document.forms[nomeform].elements[i].checked=false;
		}
	}
}
// trata o submit dos campos
function tratar_campos(nomeform) {
var ncampos = document.forms[nomeform].length;
	for (i=0;i<ncampos;i++) {
		if (document.forms[nomeform].elements[i].type == "checkbox") {
			if (document.forms[nomeform].elements[i].checked==true) {
				if (document.forms[nomeform].campos.value=="") {
					document.forms[nomeform].campos.value = document.forms[nomeform].elements[i].value;
				} else {
				document.forms[nomeform].campos.value = document.forms[nomeform].campos.value+","+document.forms[nomeform].elements[i].value;
				}
			}
		}
	}
	return true;
}
// validar a escolha do nϊmero de registos por pαgina
function validar_regpagina() {
	var campos = eval("document.regpagina");
	if (campos.pagesize.value=="") {alert("Preencha algo!");campos.pagesize.focus();return false;}
	if (isNaN(campos.pagesize.value)) {alert("Preencha um valor numιrico.");campos.pagesize.focus();return false;}
	var valor = eval(campos.pagesize.value);
	if (valor<0) {alert("O valor deve ser igual ou superior a 0!");campos.pagesize.focus();return false;}
	return true;
}

// funηυes para lidar com os menus de opηυes e filtro de campos
function mostrar_menu(nome) {
	if (is_ie4up) {
		if (document.all[nome].style.visibility=="hidden") {
			BeforeFirstOpen();
			document.all[nome].style.visibility="visible";
		} else {
			AfterCloseAll();
			mostraroff(nome);
		}
	} else if (is_gecko || is_nav6up) {
		divel=document.getElementById(nome);
		var vis = divel.style.visibility;
		if (vis=="hidden") {
			BeforeFirstOpen;
			divel.style.visibility="visible";
		} else {
			AfterCloseAll();
			mostraroff(nome);
		}
	} else {
		alert("Actualize o seu browser...!");
		document.location = "http://wwww.teladigital.net"
	}
}
// funηυes para lidar com os menus de opηυes e filtro de campos
function mostrar_menu1(nome) {
	if (is_ie4up) {
		if (document.all[nome].style.visibility=="hidden") {
			document.all[nome].style.visibility="visible";
		} else {
			mostraroff1(nome);
		}
	} else if (is_gecko || is_nav6up) {
		divel=document.getElementById(nome);
		var vis = divel.style.visibility;
		if (vis=="hidden") {
			divel.style.visibility="visible";
		} else {
			mostraroff1(nome);
		}
	} else {
		alert("Actualize o seu browser...!");
		document.location = "http://wwww.teladigital.net"
	}
}

function mostraroff(nome) {
	if (is_ie4up) {
		document.all[nome].style.visibility="hidden";
		AfterCloseAll();
	} else if (is_gecko || is_nav6up) {
		AfterCloseAll();
		divel=document.getElementById("nome");
		divel.style.visibility="hidden";
	}
}
function mostraroff1(nome) {
	if (is_ie4up) {
		document.all[nome].style.visibility="hidden";
	} else if (is_gecko || is_nav6up) {
		divel=document.getElementById("nome");
		divel.style.visibility="hidden";
	}
}

function abrejanela(url,janela,larg,alt) {
  var myLeft = (screen.width-larg)/2;
  var myTop = (screen.height-alt)/2;

  // acrescentar as dimensυes ao url
  if (url.indexOf("?")>0) {
  	tmp = "&width="+larg+"&height="+alt;
  } else {
  	tmp = "?width="+larg+"&height="+alt;
  }
  //var win = window.open("_blank","popup","width="+larg+",height="+alt+",left="+myLeft+",top="+myTop+",marginheight=0,marginwith=0,leftmargin=0,resizable=yes,scrollbars=yes,menubar=no,toolbar=no");
  //win.close();
  window.open(url+tmp,janela,"width="+larg+",height="+alt+",left="+myLeft+",top="+myTop+",marginheight=0,marginwith=0,leftmargin=0,resizable=yes,scrollbars=yes,menubar=no,toolbar=no");
}
function abrejanelanornal(url,janela,larg,alt) {
  var myLeft = (screen.width-larg)/2;
  var myTop = (screen.height-alt)/2;

  window.open(url,janela,"width="+larg+",height="+alt+",left="+myLeft+",top="+myTop+",marginheight=0,marginwith=0,leftmargin=0,resizable=yes,scrollbars=yes,menubar=no,toolbar=no");
}
// ----------------------------------------------------------
// limpa o conteϊdo de campos em ediηγo
function limpar(campo,campo1) {
	var mycampo = eval(campo);
	mycampo.value = "";
	if (campo1!="") {
		var mycampo1 = eval(campo1);
		mycampo1.value = "";
	}
}
// ----------------------------------------------------------
// limpa o conteϊdo de campos imagem em ediηγo
function limpar_foto(campo,imagem) {
	var mycampo = eval(campo);
	mycampo.value = "";
	document.images[imagem].src = "../imagens/types/picture.gif";
}
// ----------------------------------------------------------
// limpa o conteϊdo de campos imagem em ediηγo
function limpar_flash(campo,imagem) {
	var mycampo = eval(campo);
	var mycampo1 = eval("document."+imagem);
	mycampo.value = "";
	mycampo1.movie = "../imagens/types/flash.swf";
}
// ----------------------------------------------------------
// limpa o conteϊdo de campos cor em ediηγo
function limpar_cor(campo) {
	var mycampo = eval(campo);
	var mycampo1 = eval(campo+"1");
	mycampo.value = "";
	mycampo1.style.backgroundColor = "#FFFFFF";
}
// ----------------------------------------------------------
// limpa o conteϊdo de campos hora em ediηγo
function limpar_hora(campo) {
	var mycampo = eval(campo+"_hora");
	var mycampo1 = eval(campo+"_minuto");
	mycampo.selectedIndex=0;
	mycampo1.selectedIndex=0;
}
// ----------------------------------------------------------
// incrementa ou decrementa em 1 um determinado campo
function incrementar(campo,rotina) {
	var mycampo = eval(campo);
	var valor = mycampo.value;
	if (valor=="") {valor="0"};
	valor = valor.replace(",",".");

	if (isNaN(valor)) {
		alert("Um valor numιrico ι requerido para a operaηγo.");
	} else {
		myvalor = eval(valor);
		switch (rotina) {
			case "aumentar":
				mycampo.value = myvalor+1;
				break;
			case "diminuir":
				if (myvalor<=0) {
					alert("Nγo pode ser inferior a zero.");
				} else {
					mycampo.value = myvalor-1;
				}
				break;
		}
	}
}
// ----------------------------------------------------------
// abre um url em janela nova
function abre_url(campo) {
	var mycampo = eval(campo);
	if (mycampo.value!="" && mycampo.value!="http://") {
		abrejanela(mycampo.value,'url',700,400);
	}
}
// ----------------------------------------------------------
// linka para email
function abre_email(campo) {
	var mycampo = eval(campo);
	if (mycampo.value!="") {
		document.location = "mailto:"+mycampo.value;
	}
}
// 
// verifica a validade de um email
// 
function verificamail(mailstr){
	if (mailstr.length == 0) {
		return true;
	}
	// verifica se existe @
	if (mailstr.indexOf("@")==-1 || mailstr.indexOf("@")==0 || mailstr.lastIndexOf("@")==mailstr.length-1 || mailstr.indexOf("@") < 2 || mailstr.indexOf("@") != mailstr.lastIndexOf("@")) {
		alert("Email invαlido, introduza novamente!");
		return false;
	}
	// verifica o .
	if (mailstr.indexOf(".")==-1 || mailstr.indexOf(".")==0 || mailstr.lastIndexOf(".")==mailstr.length-1 || mailstr.lastIndexOf(".") < mailstr.indexOf("@") || mailstr.length-1-mailstr.lastIndexOf(".") < 2) {
		alert("Email invαlido, introduza novamente!");
		return false;
	}
	// verifica se existe dois caracteres entre @ e .
	if (mailstr.charAt(mailstr.indexOf("@")+1) == "." || mailstr.charAt(mailstr.indexOf("@")+2) == ".") {
		alert("Email invαlido, introduza novamente!");
		return false;
	}
	// verifica se existem espaηos pelo meio
	if (mailstr.indexOf(" ") != -1) {
		alert("Email invαlido, introduza novamente!");
		return false;
	}
	// verifica se existem caracteres invαlidos
	for (x=1;x<mailstr.length;x++) {
		if (mailstr.charCodeAt(x) < 45) {
			alert("Email invαlido, introduza novamente!");
			return false;
		}
		if (mailstr.charCodeAt(x) == 47) {
			alert("Email invαlido, introduza novamente!");
			return false;
		}
		if (mailstr.charCodeAt(x) >= 58 && mailstr.charCodeAt(x) <= 63) {
			alert("Email invαlido, introduza novamente!");
			return false;
		}
		if (mailstr.charCodeAt(x) >= 91 && mailstr.charCodeAt(x) <= 96 && mailstr.charCodeAt(x) != 95) {
			alert("Email invαlido, introduza novamente!");
			return false;
		}
		if (mailstr.charCodeAt(x) >= 123) {
			alert("Email invαlido, introduza novamente!");
			return false;
		}
	}
	return true;
}

// 
// verifica a validade de um campo numιrico
// 
function verificanumero(numero,nomecampo) {

	// substitui a virgula pelo ponto
	numero = numero.replace(",",".");
	// verifica se o resultado concatenado ι um nϊmero
	if (isNaN(numero)) {
		alert("O conteϊdo de "+nomecampo+" deve ser um valor numιrico.");
		return false;
	}
}

// 
// retira todos os espaηos numa string
// 
function killspace(texto) {
	var letra = new String(""); // para extraηγo letra a letra
	var tmpstr = new String(""); // vai acumular o resultado final
	for (i=0;i<texto.length;i++) {
		letra = texto.charAt(i);
		// se for diferente de espaηo acumula
		if (texto.charCodeAt(i) != 32) {
			tmpstr = tmpstr+letra;
		}
	}
	return tmpstr;
}

// 
// retira os espaηos antes e depois de uma string
// 
function jstrim(texto) {
	var letra = new String(""); // para extraηγo letra a letra
	var tmpstr = new String(""); // vai acumular o resultado final
	var existe = new String();
	// espaηos ΰ esquerda
	for (i=0;i<texto.length;i++) {
		letra = texto.charAt(i);
		if (texto.charCodeAt(i) != 32) {
			existe = "s";
			tmpstr = tmpstr+letra;
		}
		else {
			if (existe == "s") {
				tmpstr = tmpstr+letra;
			}
		}
	} // fecha espaηos ΰ esquerda

	// espaηos ΰ direita da string
	existe = "n"
	x = tmpstr.length;
	var tmpstr1 = new String();
	do {
		x = x - 1;
		letra = tmpstr.charAt(x);
		if (tmpstr.charCodeAt(x) != 32) {
			existe = "s";
			tmpstr1 = letra+tmpstr1;
		}
		else {
			if (existe == "s") {
				tmpstr1 = letra+tmpstr1;
			}
		}
	} while (x > 0);

	return tmpstr1;
}

// 
// verifica a validade um url
// 
function validaurl(texto) {
	// verifica a existκncia de http://
	if (texto.indexOf("http://")==-1) {
		alert("url invαlido, tente novamente.");
		return false;
	}
	// verifica se http:// estα no inνcio da string
	var letra = new String();
	var tmpstr = new String();
	for (x=0;x<7;x++) {
		letra = texto.charAt(x);
		tmpstr = tmpstr+letra;
	}
	if (tmpstr!="http://") {
		alert("url invαlido, tente novamente.");
		return false;
	}
	// verifica a existκncia de pelo menos um ponto
	if (texto.indexOf(".")==-1 || texto.lastIndexOf(".")==texto.length-1) {
		alert("url invαlido, tente novamente.");
		return false;
	}
	// verifica a existκncia de pelo menos dois caracteres a seguir a http://
	if (texto.indexOf(".")-(texto.indexOf("http://")+7)<2) {
		alert("url invαlido, tente novamente.");
		return false;
	}
	// verifica se o ϊltimo ponto tem pelo menos dois caracteres ΰ frente
	if (texto.length-1-texto.lastIndexOf(".")<2) {
		alert("url invαlido, tente novamente.");
		return false;
	}
	// verifica se existem caracteres invαlidos
	for (x=1;x<texto.length;x++) {
		if (texto.charCodeAt(x) < 45) {
			alert("url invαlido, tente novamente!");
			return false;
		}
		if (texto.charCodeAt(x) > 58 && texto.charCodeAt(x) <= 63) {
			alert("url invαlido, tente novamente!");
			return false;
		}
		if (texto.charCodeAt(x) >= 91 && texto.charCodeAt(x) <= 96 && texto.charCodeAt(x) != 95) {
			alert("url invαlido, tente novamente!");
			return false;
		}
		if (texto.charCodeAt(x) >= 123) {
			alert("url invαlido, tente novamente!");
			return false;
		}
	}
	return true;
}
// 
// verifica a validade em termos de caracteres de um campo codigo ou username
// 
function verifica_char(valor) {
	/*
	39 = '
	44 = ,
	92 = \
	96 = '
	126 = ~
	*/
	var chars = new Array("'",",","\\","΄","~");
	for (i=0;i<5;i++) {
		var letra = chars[i];
		if (valor.indexOf(letra)!=-1) {
			return false;
		}
	}
	return true;
}
// 
// seleciona ou limpa todas as checkboxes num formulαrio
// 
function selecionar_boxes() {
var ncampos = document.forms[0].length
	for (i=0;i<ncampos;i++) {
		if (document.forms[0].elements[i].type == "checkbox") {
			document.forms[0].elements[i].checked=true;
		}
	}
}
function limpar_boxes() {
var ncampos = document.forms[0].length
	for (i=0;i<ncampos;i++) {
		if (document.forms[0].elements[i].type == "checkbox") {
			document.forms[0].elements[i].checked=false;
		}
	}
}
// ________________________________________________________________________
function validar_hora(str) {
	if (str.indexOf(":")==-1) {
		alert("Hora deve ser preenchida no seguinte formato: hh:mm");
		return false;
	} else {
		tmp = str.split(":");
		if (tmp.length>2 || tmp.length<2) {
			alert("Hora deve ser preenchida no seguinte formato: hh:mm");
			return false;
		} else {
			horas = tmp[0];
			minutos = tmp[1];
			// horas
			if (isNaN(horas)) {
				alert("Hora deve ser preenchida no seguinte formato: hh:mm");
				return false;
			} else {
				if (eval(horas)>23) {
					alert("Hora deve ser preenchida no seguinte formato: hh:mm");
					return false;
				}
			}
			// minutos
			if (isNaN(minutos)) {
				alert("Hora deve ser preenchida no seguinte formato: hh:mm");
				return false;
			} else {
				if (eval(minutos)>59) {
					alert("Hora deve ser preenchida no seguinte formato: hh:mm");
					return false;
				}
			}
		}
	}
	return true;
}
function validar_username(var_username) {
	for (i=0;i<var_username.length;i++) {
		estado = 0;
		if (var_username.charCodeAt(i)>47 && var_username.charCodeAt(i)<58) {
			estado = 1;
		}
		if (var_username.charCodeAt(i)>64 && var_username.charCodeAt(i)<91) {
			estado = 1;
		}
		if (var_username.charCodeAt(i)>96 && var_username.charCodeAt(i)<123) {
			estado = 1;
		}
		if (estado==0) {
			return false;
		}
	}
	return true;
}
<!--
function show_men() {
	if (document.all) {
		if (document.all['menu_adm'].style.display=="none") {
			document.all['menu_adm'].style.display="";
		} else {
			document.all['menu_adm'].style.display="none";
		}
	} else {
		if (document.getElementById('menu_adm').style.display=="none") {
			document.getElementById('menu_adm').style.display="";
		} else {
			document.getElementById('menu_adm').style.display="none";
		}
	}
}
function show_desc_navegacao(titulo) {
	if (document.all) {
		objecto = eval("document.all['navegacaodesc']");
	} else {
		objecto = eval("document.getElementById('navegacaodesc')");
	}
	objecto.innerHTML = titulo;
}
function clean_desc_navegacao(titulo) {
	if (document.all) {
		objecto = eval("document.all['navegacaodesc']");
	} else {
		objecto = eval("document.getElementById('navegacaodesc')");
	}
	objecto.innerHTML = "&nbsp;";
}
function data_maior(valor,referencia) {
	// formato que deve ser retornada = dd-mm-yyyy

	tmp = referencia.split("-");
	ref_ano = eval(tmp[2]);
	ref_mes = eval(tmp[1]);
	ref_dia = eval(tmp[0]);

	tmp1 = valor.split("-");
	ano = eval(tmp1[2]);
	mes = eval(tmp1[1]);
	dia = eval(tmp1[0]);

	if (ref_ano<=ano) {
		if (ref_mes<=mes) {
			if (ref_dia<dia) {
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	} else {
		return false;
	}
}
function fechar_aviso() {
	if (document.all) {
		obj = eval("document.all['lay_aviso'].style");
	} else {
		obj = eval("document.getElementById('lay_aviso').style");
	}
	obj.visibility = "hidden";
}
//-->
