function verifica_pw(){
	
	if (document.pw.t_pw.value==""){
		msg= "Tem que preencher o campo Password." + "\n" ;
		window.alert (msg);
		document.pw.t_pw.focus(); 
		return false;
	} else if (document.pw.t_pw.value.length<5){
		msg= "O campo Password tem que ter pelo menos 5 dígitos." + "\n" ;
		window.alert (msg);
		document.pw.t_pw.focus(); 
		return false;
	}
	if (document.pw.t_pw.value!=document.pw.b_pw.value){
		msg= "A Password de confirmação não coincide - ." + "\n" ;
		window.alert (msg);
		document.pw.t_pw.focus(); 
		return false;
	}
	
	return true
}

function verifica_login_topo(){
	
	if (document.login_topo.idu.value==""){
		msg= "Tem que preencher o campo IDENTIFICAÇÂO." + "\n" ;
		window.alert (msg);
		document.login_topo.idu.focus(); 
		return false;
	}	
	
	if (document.login_topo.pw.value==""){
		msg= "Tem que preencher o campo PASSWORD." + "\n" ;
		window.alert (msg); 
		document.login_topo.pw.focus(); 
		return false;
	}
	
	return true
}

function verifica_rec_pw(){
	
	if (!(valida_email(document.rec_pw.t_email.value))){
		document.rec_pw.t_email.focus(); 
		return false;
	}	
	
	return true
}

function verifica_login_centro(){
	
	if (document.login_centro.idu.value==""){
		msg= "Tem que preencher o campo IDENTIFICAÇÂO." + "\n" ;
		window.alert (msg);
		document.login_centro.idu.focus(); 
		return false;
	}	
	
	if (document.login_centro.pw.value==""){
		msg= "Tem que preencher o campo PASSWORD." + "\n" ;
		window.alert (msg); 
		document.login_centro.pw.focus(); 
		return false;
	}
	
	return true
}


function verifica_registo(){

	if (document.registo.t_username.value==""){
		msg= "Tem que preencher o campo USERNAME." + "\n" ;
		window.alert (msg);
		document.registo.t_username.focus(); 
		return false;
	} else if (document.registo.t_username.value=="Insira a sua identificação"){
		msg= "Tem que preencher o campo USERNAME." + "\n" ;
		window.alert (msg);
		document.registo.t_username.focus(); 
		return false;
	}else if (document.registo.t_username.value.length<5){
		msg= "O campo USERNAME tem que ter pelo menos 5 dígitos." + "\n" ;
		window.alert (msg);
		document.registo.t_username.focus(); 
		return false;
	}
	
	if (!(valida_email(document.registo.t_email.value))){
		document.registo.t_email.focus(); 
		return false;
	}
	
	if (document.registo.t_alcunha.value=="Insira o seu nick"){
		msg= "Tem que preencher o campo NICK ou apagar a mensagem de" + "\n ajuda que se encontra na caixa." ;
		window.alert (msg);
		document.registo.t_alcunha.focus(); 
		return false;
	}
	
	if (document.registo.t_nome.value=="Insira o seu nome"){
		msg= "Tem que preencher o campo NOME ou apagar a mensagem de" + "\n ajuda que se encontra na caixa." ;
		window.alert (msg);
		document.registo.t_nome.focus(); 
		return false;
	}
	
	if (document.registo.t_apelido.value=="Insira o seu apelido"){
		msg= "Tem que preencher o campo APELIDO ou apagar a mensagem de" + "\n ajuda que se encontra na caixa." ;
		window.alert (msg);
		document.registo.t_apelido.focus(); 
		return false;
	}
	
	if (document.registo.t_telef.value=="Insira o seu telefone"){
		msg= "Tem que preencher o campo TELEFONE ou apagar a mensagem de" + "\n ajuda que se encontra na caixa." ;
		window.alert (msg);
		document.registo.t_telef.focus(); 
		return false;
	}
	
	if (document.registo.t_morada.value=="Insira a sua morada"){
		msg= "Tem que preencher o campo MORADA ou apagar a mensagem de" + "\n ajuda que se encontra na caixa." ;
		window.alert (msg);
		document.registo.t_morada.focus(); 
		return false;
	}
	
	if (document.registo.t_localidade.value=="Insira a Localidade"){
		msg= "Tem que preencher o campo LOCALIDADE ou apagar a mensagem de" + "\n ajuda que se encontra na caixa." ;
		window.alert (msg);
		document.registo.t_localidade.focus(); 
		return false;
	}
	
	var dn=document.registo.d_d_nasc
	if (dn.value=="DD/MM/AAAA"){
		msg= "Tem que preencher o campo DATA DE NASCIMENTO ou apagar a mensagem de" + "\n ajuda que se encontra na caixa." ;
		window.alert (msg);
		dn.focus()
		return false;
	}	
	
	if (document.registo.t_obs.value=="Insira a sua observação"){
		msg= "Tem que preencher o campo OBSERVAÇÃO ou apagar a mensagem de" + "\n ajuda que se encontra na caixa." ;
		window.alert (msg);
		document.registo.t_obs.focus(); 
		return false;
	}
	
	return true
}

function verifica_upd_registo(){


	
	if (!(valida_email(document.registo.t_email.value))){
		document.registo.t_email.focus(); 
		return false;
	}
	
	return true
}

function valida_agenda(){

	if (document.frmAddMessage.t_titulo.value==""){
		msg= "Tem que preencher o campo TÍTULO." + "\n" ;
		window.alert (msg);
		document.frmAddMessage.t_titulo.focus(); 
		return false;
	}
	return true
}


function verifica_livro(){

	if (document.livro.t_nome.value==""){
		msg= "Tem que preencher o campo Nome." + "\n" ;
		window.alert (msg);
		document.livro.t_nome.focus(); 
		return false;
	} else if (document.livro.t_nome.value.length<3){
		msg= "O campo Nome tem que ter pelo menos 3 dígitos." + "\n" ;
		window.alert (msg);
		document.livro.t_nome.focus(); 
		return false;
	}		
		
	
	if (document.livro.t_email.value=="")
	{
		msg= "Tem que preencher o campo Email." + "\n" ;
		window.alert (msg);
		document.livro.t_email.focus(); 
		return false;
	}		

	
	if (document.livro.t_email.value!="")
		{
			if (!(valida_email(document.livro.t_email.value)))
			{
				document.livro.t_email.focus(); 
				return false;
			}
		}
		
	if (document.livro.t_msg.value==""){
		msg= "Tem que introduzir uma Mensagem." + "\n" ;
		window.alert (msg); 
		document.livro.t_msg.focus(); 
		return false;
	} else if (document.livro.t_msg.value.length>256){
		msg= "O campo MENSAGEM não pode conter mais do que 256 caracteres." + "\n" ;
		window.alert (msg);
		document.livro.t_msg.focus(); 
		return false;	
	}			

	msg= "A sua mensagem vai ser enviada." + "\nIrá ser validada pela administração" + "\ne colocada no livro de visitas." ;
	window.alert(msg);	
	
	return true
}

function verifica_newsletter(){

	if (document.mailling.nome.value=="Insira o seu nome"){
		msg= "Tem que preencher o campo Nome." + "\n" ;
		window.alert (msg);
		document.mailling.nome.focus(); 
		return false;
	} else if (document.mailling.nome.value==""){
		msg= "Tem que preencher o campo Nome." + "\n" ;
		window.alert (msg);
		document.mailling.nome.focus(); 
		return false;
	} 	else if (document.mailling.nome.value.length<3){
		msg= "O campo Nome tem que ter pelo menos 3 dígitos." + "\n" ;
		window.alert (msg);
		document.mailling.nome.focus(); 
		return false;	
	}
	
	if (document.mailling.email.value=="Insira o seu e-mail"){
		msg= "Tem que preencher o campo Email." + "\n" ;
		window.alert (msg);
		document.mailling.email.focus(); 
		return false;
	} else if (document.mailling.email.value==""){
		msg= "Tem que preencher o campo Email." + "\n" ;
		window.alert (msg);
		document.mailling.email.focus(); 
		return false;		
	}
	
	if (document.mailling.email.value!="")
		{
			if (!(valida_email(document.mailling.email.value)))
			{
				document.mailling.email.focus(); 
				return false;
			}
		}
	
	return true
}

function verifica_reclama(){

	if (document.reclama.t_nome.value=="Insira o seu nome"){
		msg= "Tem que preencher o campo NOME" ;
		window.alert (msg);
		document.reclama.t_nome.focus(); 
		return false;
	} else if (document.reclama.t_nome.value==""){
		msg= "Tem que preencher o campo NOME." + "\n" ;
		window.alert (msg);
		document.reclama.t_nome.focus(); 
		return false;
	}
	
	if (!(valida_email(document.reclama.t_email.value))){
		document.reclama.t_email.focus(); 
		return false;
	}
	
	if (document.reclama.t_assunto.value=="Insira o assunto"){
		msg= "Tem que preencher o campo ASSUNTO" ;
		window.alert (msg);
		document.reclama.t_assunto.focus(); 
		return false;
	}else if (document.reclama.t_assunto.value==""){
		msg= "Tem que preencher o campo ASSUNTO" + "\n" ;
		window.alert (msg);
		document.reclama.t_assunto.focus(); 
		return false;
	}
	
	if (document.reclama.t_descr.value=="Insira a descrição do assunto"){
		msg= "Tem que preencher o campo DESCRIÇÃO" ;
		window.alert (msg);
		document.reclama.t_descr.focus(); 
		return false;
	}else if (document.reclama.t_descr.value==""){
		msg= "Tem que preencher o campo DESCRIÇÃO" + "\n" ;
		window.alert (msg);
		document.reclama.t_descr.focus(); 
		return false;
	}
	
	return true
}

function valida_email(email)
{
	var result = /^.+\@.+\..+$/ ;

	if ((email == null) || (email.length == 0)) {
       	if (valida_email.arguments.length == 1) {
       		alert("Tem que preencher um E-Mail válido.");
       		return false ;
       	} else {
       		if (!(valida_email.arguments[1] == true)) {
       			alert("Tem que preencher um E-Mail válido.");
       		}
       		return (valida_email.arguments[1] == true);
       	}
    } else {
		if (!(result.test(email))) {
			alert("Tem que preencher um E-Mail válido.");
		}
       return result.test(email);
    }
}


var ns6=document.getElementById&&!document.all

function restrictinput(maxlength,e,placeholder){
if (window.event&&event.srcElement.value.length>=maxlength)
return false
else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
if (pressedkey.test(String.fromCharCode(e.which)))
e.stopPropagation()
}
}

function countlimit(maxlength,e,placeholder){
var theform=eval(placeholder)
var lengthleft=maxlength-theform.value.length
var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
if (window.event||e.target&&e.target==eval(placeholder)){
if (lengthleft<0)
theform.value=theform.value.substring(0,maxlength)
placeholderobj.innerHTML=lengthleft
}
}

function displaylimit(theform,thelimit){
var limit_text='Pode introduzir <b><span id="'+theform.toString()+'">'+thelimit+'</span></b> caracteres!!'
if (document.all||ns6)
document.write(limit_text)
if (document.all){
eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
}
else if (ns6){
document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); 
document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); 
}
}

