function seps(oque){

	if(oque == 'emprego'){
		document.getElementById('empregotab').style.background = '#525251';
		document.getElementById('empregadotab').style.background = '#797979';
		document.getElementById('empregados').style.display = 'block';
		document.getElementById('empregadores').style.display = 'none';
	}else{
		document.getElementById('empregotab').style.background = '#797979';
		document.getElementById('empregadotab').style.background = '#525251';
		document.getElementById('empregados').style.display = 'none';
		document.getElementById('empregadores').style.display = 'block';
	}


}
function limpaEmail(){
	
	var subscr_email = document.getElementById('subscr_email');

	if(subscr_email.value == "E-mail"){ subscr_email.value = ""; }
	
}
function subscrever(myForm){

	if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(subscr_email.value))){
		alert("E-mail Incorrecto!");
		return(false);
	}

	return(true);
	
}
function assocMais(){
	
	if (document.getElementById('assoc_mais').checked == 1)
		document.getElementById('outro_benef').style.display = 'block';
	else
		document.getElementById('outro_benef').style.display = 'none';
		
	
	if (document.getElementById('assoc_novo').checked == 1)
		document.getElementById('assoc_novo').checked = false;
	
}
function assocNovo(){
	
	if (document.getElementById('assoc_mais').checked == 1){
		document.getElementById('assoc_mais').checked = false;
		document.getElementById('outro_benef').style.display = 'none';
	}
	
}
function checkInscricao(myForm){
	
	if(myForm.nome.value == ""){ alert("Preencha o campo Nome!"); return(false); }
	
	if(myForm.morada.value == ""){ alert("Preencha o campo Morada!"); return(false); }
	
	if(myForm.codpostal1.value == ""){ alert("Preencha o campo Código Postal!"); return(false); }
	
	if(myForm.localidade.value == ""){ alert("Preencha o campo Localidade!"); return(false); }
	
	if(myForm.distrito.value == ""){ alert("Preencha o campo Distrito!"); return(false); }
	
	if(myForm.tlfn.value == ""){ alert("Preencha o campo Telefone!"); return(false); }
	
	if(myForm.cat.value == ""){ alert("Preencha o campo Categoria Profissinal!"); return(false); }

	if(myForm.anos_serv.value == ""){ alert("Preencha o campo Anos de Serviço!"); return(false); }

	if(myForm.funcao.value == ""){ alert("Preencha o campo Função que exerce!"); return(false); }

	if(myForm.entid.value == ""){ alert("Preencha o campo Entidade Empregadora!"); return(false); }

	if(myForm.local.value == ""){ alert("Preencha o campo Local onde exerce!"); return(false); }

	var ValidChars = "0123456789";
	var Char;
	for (i = 0; i < myForm.nib.value.length; i++) { 
		Char = myForm.nib.value.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) {
			alert("O campo NIB apenas pode ter números!"); return(false);
		}
	}
	
	if(myForm.nib.value.length != 21){ alert("O campo NIB tem que ter 21 dígitos!"); return(false); }
	
	return(true);
	
}
function checkActualizacao(myForm){
	
	if(myForm.nr_assoc.value == ""){ alert("Preencha o campo Nº de Associado!"); return(false); }
	
	return(true);
	
}
function checkFormacao(myForm){
	
	if(myForm.accao.value == ""){ alert("Preencha o campo Acção!"); return(false); }
	
	if(myForm.nbi.value == ""){ alert("Preencha o campo Nº BI!"); return(false); }

	if(myForm.tlfn.value == "" && myForm.tlmvl.value == "" && myForm.email.value == ""){ alert("Preencha pelo menos um campo de contacto: Telefone, Telemóvel ou E-mail!"); return(false); }

	return(true);
	
}
function checkEmprego(myForm){
	
	if(myForm.nome.value == ""){ alert("Preencha o campo Nome!"); return(false); }
	
	if(myForm.tlfn.value == "" && myForm.email.value == ""){ alert("Preencha o campo Telefone ou o campo E-mail!"); return(false); }
	
	return(true);
	
}
function checkAssinar(myForm){
	
	if(myForm.edicao.value == ""){ alert("Seleccione a Edição que pretende assinar!"); return(false); }
	
	if(myForm.nome.value == ""){ alert("Preencha o campo Nome!"); return(false); }
	
	if(myForm.morada.value == ""){ alert("Preencha o campo Morada!"); return(false); }
	
	if(myForm.codpostal1.value == ""){ alert("Preencha o campo Código Postal!"); return(false); }
	
	if(myForm.localidade.value == ""){ alert("Preencha o campo Localidade!"); return(false); }
	
	if(myForm.distrito.value == ""){ alert("Preencha o campo Distrito!"); return(false); }
	
	if(myForm.tlfn.value == ""){ alert("Preencha o campo Telefone!"); return(false); }

	var ValidChars = "0123456789";
	var Char;
	for (i = 0; i < myForm.nib.value.length; i++) { 
		Char = myForm.nib.value.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) {
			alert("O campo NIB apenas pode ter números!"); return(false);
		}
	}
	
	if(myForm.nib.value.length != 21){ alert("O campo NIB tem que ter 21 dígitos!"); return(false); }
	
	return(true);
	
}
function checkEncontro(myForm){
	
	if(myForm.nome.value == ""){ alert("Preencha o campo Nome!"); return(false); }
	
	if(myForm.tlfn.value == "" && myForm.tlmvl.value == ""){ alert("Preencha o campo Telefone ou Telemóvel!"); return(false); }

	if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.email.value))){
		alert("E-mail Incorrecto!");
		return(false);
	}
	
	if(myForm.file.value == ""){ alert("Seleccione o Comprovativo de Transferência!"); return(false); }
	
	if(myForm.assoc_mais.value == 1 && myForm.nome_outro.value == ""){ alert("Para aderir à Campanha Associado + tem de indicar o nome do outro beneficiário!"); return(false); }

	return(true);
	
}
var apei = {
	addEvent: function(elm,evType,fn,useCapture){
		if(elm.addEventListener){ elm.addEventListener(evType,fn,useCapture); }
		else if(elm.attachEvent){ var r = elm.attachEvent('on' + evType, fn); return r; }
		else{ elm['on' + evType] = fn; }
	},
	edicoes: function(){

		if(document.getElementById){
				
			if(apei.anos.length > 7){
					
				var next = document.getElementById('next');
				var prev = document.getElementById('prev');
				apei.addEvent(next,'click',apei.next,false);
				apei.addEvent(prev,'click',apei.prev,false);
				
				if(document.getElementById('sel')){

					var ano = document.getElementById('sel').innerHTML;
					for(var i=0;i<apei.anos.length;i++){
						if(ano == apei.anos[i]){
							var indiceSel = i;
						}
					}
					
					var divisao = parseInt(indiceSel/7)
					
					next.indice = divisao * 7;
					prev.indice = next.indice + 6;
					
					if(next.indice > 0){
						next.style.display = 'inline';
					}
					
					if(prev.indice + 1 < apei.anos.length){
						prev.style.display = 'inline';
					}
					
					for(var i=next.indice;i<=prev.indice;i++){
						document.getElementById(apei.anos[i]).style.display = 'inline';
					}
					
				}else{
					
					prev.style.display = 'inline';
					next.indice = 0;
					prev.indice = 6;
					
					for(var i=0;i<=6;i++){
						document.getElementById(apei.anos[i]).style.display = 'inline';
					}
					
				}
					
			}else{
				
				for(var i=0;i<apei.anos.length;i++){
					document.getElementById(apei.anos[i]).style.display = 'inline';
				}
				
			}
		
		}
		else{return;}

	},
	next: function(){
	
		var next = document.getElementById('next');
		var prev = document.getElementById('prev');
		
		if(prev.indice + 1 < apei.anos.length){
			for(var i=next.indice;i<=prev.indice;i++){
				document.getElementById(apei.anos[i]).style.display = 'none';
			}
		}else{
			for(var i=next.indice;i<apei.anos.length;i++){
				document.getElementById(apei.anos[i]).style.display = 'none';
			}
		}
		
		next.indice = next.indice - 7;
		if(next.indice > 0){
			next.style.display = 'inline';
		}else{
			next.style.display = 'none';
		}
		
		prev.indice = prev.indice - 7;
		prev.style.display = 'inline';
		
		for(var j=next.indice;j<=prev.indice;j++){
			document.getElementById(apei.anos[j]).style.display = 'inline';
		}
	
		if(next && next.stopPropagation && next.preventDefault){ next.stopPropagation(); next.preventDefault(); }
		if(window.event){ window.event.cancelBubble = true; window.event.returnValue = false; return false; }
	
	},
	prev: function(){

		var next = document.getElementById('next');
		var prev = document.getElementById('prev');
	
		for(var i=next.indice;i<=prev.indice;i++){
			document.getElementById(apei.anos[i]).style.display = 'none';
		}
		
		prev.indice = prev.indice + 7;
		if(prev.indice + 1 < apei.anos.length){
			prev.style.display = 'inline';
		}else{
			prev.style.display = 'none';
			var menos = 'sim';
		}
		
		next.indice = next.indice + 7;
		next.style.display = 'inline';

		if(menos == 'sim'){
			for(var j=next.indice;j<apei.anos.length;j++){
				document.getElementById(apei.anos[j]).style.display = 'inline';
			}
		}else{
			for(var j=next.indice;j<=prev.indice;j++){
				document.getElementById(apei.anos[j]).style.display = 'inline';
			}
		}
		
		if(prev && prev.stopPropagation && prev.preventDefault){ prev.stopPropagation(); prev.preventDefault(); }
		if(window.event){ window.event.cancelBubble = true; window.event.returnValue = false; return false; }

	},
	anos: []
};

function verificar_email(dom_id){
    var dom = document.getElementById(dom_id);
    var status = true;
    var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
    if (dom.value.search(emailRegEx) == -1) {
        alert("Por favor introduza um e-mail correcto.");
        status = false;
    }
    return status;
}