// 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;
  window.open(url,janela,"width="+larg+",height="+alt+",left="+myLeft+",top="+myTop+",marginheight=0,marginwith=0,leftmargin=0,resizable=no,scrollbars=no,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 imagem_zoom(url) {
	window.open(url,'Image','width=500,height=300,scrollbars=no,toolbar=no,location=no,status=no,resizable=yes,screenX=120,screenY=100');
}
function show_lai(lai,filelocation,filelocation1) {
	valido = false;
	if (document.all) {
		if (document.all[lai]) {
			valido = true;
			obj = eval("document.all['"+lai+"']");
		}
	} else {
		if (document.getElementById(lai)) {
			valido = true;
			obj = eval("document.getElementById('"+lai+"')");
		}
	}
	obj1 = eval("img_"+lai);
	if (obj.style.display=="") {
		obj.style.display = "none";
		obj1.src = filelocation;
	} else {
		obj.style.display = "";
		obj1.src = filelocation1;
	}
}


/***********************************************
* Bookmark site script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

/* Modified to support Opera */
function bookmarksite(title,url){
if (window.sidebar) // firefox
	window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print){ // opera
	var elem = document.createElement('a');
	elem.setAttribute('href',url);
	elem.setAttribute('title',title);
	elem.setAttribute('rel','sidebar');
	elem.click();
} 
else if(document.all)// ie
	window.external.AddFavorite(url, title);
}

var MAX_FONTSIZE = 70;
var ACTUAL_FONTSIZE = 0;
var MIN_FONTSIZE = -20;
function MagnifyText(iDirection)
{
  var oNewsMain = document.getElementById("artigo_corpo");
  if ( ACTUAL_FONTSIZE + 1*iDirection >= MIN_FONTSIZE &&  ACTUAL_FONTSIZE + 1*iDirection <= MAX_FONTSIZE){   
	 ACTUAL_FONTSIZE = ACTUAL_FONTSIZE + 1*iDirection;
	 SaveActualFontSize(); 
	 
	 var iGap = ( ACTUAL_FONTSIZE <= 0 ? 10: 30 );      
	 if ( ACTUAL_FONTSIZE == 0 )  {
		if (oNewsMain) oNewsMain.style.fontSize = "x-small";
	 }
	 else {
		if (oNewsMain) oNewsMain.style.fontSize = 100 + ACTUAL_FONTSIZE*iGap + "%";
	 }
  }
}
function SaveActualFontSize() 
{
  var expire = new Date ();
  expire.setTime (expire.getTime() + (6000 * 24 * 3600000));
  expire = expire.toGMTString();
  document.cookie="solFontSize=" + ACTUAL_FONTSIZE + "; path=/; expires=" + expire;
}

function LoadActualFontSize() 
{
  tempArray = document.cookie.split(";");
  for (tA = 0; tA < tempArray.length; tA++){
	 if (tempArray[tA].indexOf('solFontSize') > -1){
		fontSizeValue = tempArray[tA].split("=")
		ACTUAL_FONTSIZE = parseInt(fontSizeValue[1]);
	 }
  }
}
function ampliar_mapa() {
	abrejanelanornal('../images/memos/mapa.jpg','mapa',650,420);
}
function alphanumeric(alphane)
{
	var numaric = alphane;
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
		  {
		  }
		else	{
			 return false;
		  }
		}
 return true;
}
function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
}
//-->