function verifica_invest_en(){

	if (document.invest.nome.value==""){
		msg= "You must fill out the field NAME." + "\n" ;
		window.alert (msg);
		document.invest.nome.focus(); 
		return false;
	}	
	if (document.invest.nacionalidade.value==""){
		msg= "You must fill out the field NATIONALITY." + "\n" ;
		window.alert (msg);
		document.invest.nacionalidade.focus(); 
		return false;
	}
	if (document.invest.telefone.value==""){
		msg= "You must fill out the field PHONE." + "\n" ;
		window.alert (msg);
		document.invest.telefone.focus(); 
		return false;
	}
	if (document.invest.email.value==""){
		msg= "You must fill out the EMAIL field." + "\n" ;
		window.alert (msg);
		document.invest.email.focus(); 
		return false;
	}	
	if (document.invest.tipo_produto.value==""){
		msg= "You must fill out the field TYPE OF PRODUCT." + "\n" ;
		window.alert (msg);
		document.invest.tipo_produto.focus(); 
		return false;
	}
	if (document.invest.pais.value==""){
		msg= "You must fill out the field COUNTRY." + "\n" ;
		window.alert (msg);
		document.invest.pais.focus(); 
		return false;
	}
	if (document.invest.regiao.value==""){
		msg= "You must fill out the field REGION." + "\n" ;
		window.alert (msg);
		document.invest.regiao.focus(); 
		return false;
	}
	if (document.invest.valor.value==""){
		msg= "You must fill out the field VALUE." + "\n" ;
		window.alert (msg);
		document.invest.valor.focus(); 
		return false;
	}	
	
	msg= "Your request for information will be sent." + "\nSoon you will be contacted." + "\n" ;
	window.alert(msg);
	
	return true

}


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=="Your name"){
		msg= "You have to put your name." + "\n" ;
		window.alert (msg);
		document.mailling.nome.focus(); 
		return false;
	} else if (document.mailling.nome.value==""){
		msg= "You have to put your name." + "\n" ;
		window.alert (msg);
		document.mailling.nome.focus(); 
		return false;
	} 	else if (document.mailling.nome.value.length<3){
		msg= "You have to put at least 3 digits in The Field Name." + "\n" ;
		window.alert (msg);
		document.mailling.nome.focus(); 
		return false;	
	}
	
	if (document.mailling.email.value=="Your E-mail"){
		msg= "You have to put your E-mail." + "\n" ;
		window.alert (msg);
		document.mailling.email.focus(); 
		return false;
	} else if (document.mailling.email.value==""){
		msg= "You have to put your E-mail." + "\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 verifica_info(){

	if (document.info.nome.value==""){
		msg= "Tem que preencher o campo NOME." + "\n" ;
		window.alert (msg);
		document.info.nome.focus(); 
		return false;
	}
	
	if (document.info.telef.value==""){
		msg= "Tem que preencher o campo TELEFONE." + "\n" ;
		window.alert (msg);
		document.info.telef.focus(); 
		return false;
	}
	
	if (!(valida_email(document.info.email.value))){
		document.info.email.focus(); 
		return false;
	}
	
	if (document.info.assunto.value==""){
		msg= "Tem que preencher o campo ASSUNTO." + "\n" ;
		window.alert (msg);
		document.info.assunto.focus(); 
		return false;
	}
	
	msg= "A sua mensagem foi enviada." + "\n " ;
	window.alert(msg);	
	
	return true
}

function valida_pesq(){

	if (isNaN(document.pesquisa.pgeral.value)){
	msg= "Os campo PREÇO tem que ser numérico." + "\n" ;
	window.alert (msg);
	document.pesquisa.pgeral.focus(); 
	return false;
	}
	
	if (isNaN(document.pesquisa.pgeral1.value)){
	msg= "Os campo PREÇO tem que ser numérico." + "\n" ;
	window.alert (msg);
	document.pesquisa.pgeral1.focus(); 
	return false;
	}
		
	if (isNaN(document.pesquisa.kms.value)){
	msg= "Os campo KMS tem que ser numérico." + "\n" ;
	window.alert (msg);
	document.pesquisa.kms.focus(); 
	return false;
	}
	
	if (isNaN(document.pesquisa.kms1.value)){
	msg= "Os campo KMS tem que ser numérico." + "\n" ;
	window.alert (msg);
	document.pesquisa.kms1.focus(); 
	return false;
	}
	
	return true
}

function valida_simulador(){
	
	
	if (document.simula.ANO.value==""){
		msg= "Tem que preencher o campo ANO." + "\n" ;
		window.alert (msg);
		document.simula.ANO.focus(); 
		return false;
	} else if (isNaN(document.simula.ANO.value)){
		msg= "Os campo ANO tem que ser numérico." + "\n" ;
		window.alert (msg);
		document.simula.ANO.focus(); 
		return false;
	} else if (document.simula.ANO.value < 1860 || document.simula.ANO.value > 2006){
		msg= "O campo ANO tem que estar entre 1860 e 2006." + "\n" ;
		window.alert (msg);
		document.simula.ANO.focus(); 
		return false;
	} 
	
	if (document.simula.PRECO.value==""){
		msg= "Para fazer a simulação tem que colocar" + "\n" + "o valor do veículo.";
		window.alert (msg);
		document.simula.PRECO.focus(); 
		return false;
	}else if (isNaN(parseFloat(document.simula.PRECO.value))){
		msg= "Os campo VALOR tem que ser numérico." + "\n" ;
		window.alert (msg);
		document.simula.PRECO.focus(); 
		return false;
	}
	
	if (document.simula.ENTRADA.value==""){
		msg= "Se não desejar entrada coloque 0." + "\n" ;
		window.alert (msg);
		document.simula.ENTRADA.focus(); 
		return false;
	}else if (isNaN(parseFloat(document.simula.ENTRADA.value))){
		msg= "Os campo ENTRADA tem que ser numérico." + "\n" ;
		window.alert (msg);
		document.simula.ENTRADA.focus(); 
		return false;
	}

	return true
}


function ano(an)
{
	getYear() 
	
	var variavel_data=new date(); 
	var an=variavel_data.getYear(); 
	var an="20"+variavel_data.getYear(); 
}

function valida_email(email)
{

	//var result = /^.+\@.+\..+$/ ;
	var result = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

	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); 
}
}


