$(document).ready(function() {
	$(document).asMask();
	showBadge('as');
	/*$(document).oneTime(2000 ,function(i) {		
		$('#assistent').animate({
			marginTop: '300px'
		 },1000, function() {
		// Animation complete.
		});
	}, 0,false);*/
	
	
	
    $('#formulario').validate({
		remoteValidation: false,
		remoteValidationEmail: false,
		onfocusout: false,
        onWait:function(){
            $("#loader1").show();
            $("#btn1").hide();
        },
        invalidHandler: function(){
            $("#loader1").hide();
            $("#btn1").show();           
        }, 
        submitHandler: function(form) {
			check();
			document.getElementById('formulario').submit();
		},
        showMessageOn: 'alert',
        inputHighlight:true
    });
});
	
function check(){
	var str= $("#txIdade").val();
	teste = (str.split("-",3));
	var oneDay = 24*60*60*1000;	
	var firstDate = new Date();
	var secondDate = new Date(teste[2],teste[1]-1,teste[0]);
	if(secondDate.getTime() > firstDate.getTime()){
			alert("Introduza a sua Data de Nascimento, correctamente.");
			$("#btn1").show();
			$("#loader1").hide();
			$("#txIdade").focus();
			return false;
		}
	var yearDiff = firstDate.getFullYear()-secondDate.getFullYear();
	var monthDiff = (firstDate.getMonth())-(secondDate.getMonth());
	var dayDiff = firstDate.getDate()-secondDate.getDate();            
	
	if(yearDiff < 18 || (yearDiff == 18 && monthDiff<0) || (yearDiff == 18 && monthDiff<=0 && dayDiff<0)){
		  var idade = "menor";
	}else{
		  var idade = "maior";
	}
	if(idade=="menor") {
		alert("A sua idade deve ser igual ou superior a 18 anos.");
		$("#btn1").show();
		$("#loader1").hide();
		$("#txIdade").focus();	
		return false;
	}
}

function popitup(url) {
	newwindow=window.open(url,'','height=300,width=400,scrollbars=1');
    if (window.focus) {newwindow.focus()}
    return false;
}



