$.fn.ValidarForm = function(){
	var error = false;
	var errorMsg ='';

	$('.branco', this).each(function(){		
		if (!$(this).val().length || (jQuery.trim($(this).val())=='') || (jQuery.trim($(this).val()) == $(this).attr('data-placeholder'))) {			 
			 $(this).prev('p').html('Campo obrigat&oacute;rio');
			 $(this).addClass("erro");					
			 error = true;	
		}else{		
			$(this).removeClass("erro");	
			$(this).prev('p').html('');			
		}        
	});
	$('.data', this).each(function(){		
        if (validaData($(this).val()) || (jQuery.trim($(this).val())=='')|| (jQuery.trim($(this).val()) == $(this).attr('data-placeholder'))) {
            error = true;
			$(this).addClass("erro");
			$(this).prev('p').html('data inv&aacute;lida');		            
        }else{			
			$(this).removeClass("erro");
			$(this).prev('p').html('');			
		}      
	});
	
	
	$('.texto', this).each(function(){		
		if (!/^[a-z A-Z á-ú Á-Ú]*$/.test($(this).val()) || (jQuery.trim($(this).val())=='')|| (jQuery.trim($(this).val()) == $(this).attr('data-placeholder'))) {
			error = true;
			$(this).addClass("erro");
			$(this).prev('p').html('Alfab&eacute;tico');			
		}else{
			$(this).removeClass("erro");
			$(this).prev('p').html('');
		}    
	});
	
	$('.numero', this).each(function(){
		if (!/^[0-9]*$/.test($(this).val()) || (jQuery.trim($(this).val())=='')|| (jQuery.trim($(this).val()) == $(this).attr('data-placeholder'))) {
			error = true;
			$(this).addClass("erro");
			$(this).prev('p').html('num&eacute;rico');			
		}else{
			$(this).removeClass("erro");
			$(this).prev('p').html('');
		} 
	});
	
	
	$('.hora', this).each(function(){		
		if (validaHora($(this).val())) {
			error = true;
			$(this).addClass("erro");
			$(this).prev('p').html('inválida');			
		}else{
			$(this).removeClass("erro");
			$(this).prev('p').html('');
		} 
	});
	
	$('.required', this).each(function(){								
		var nome = $(this).attr('name');
		if (!$('[name="'+nome+'"]').is(':checked')) {
			error = true;			
			$(this).parents('ul').addClass("erro");
			$(this).parents('ul').prev('p').html('Esse campo precisa ser selecionado');			
		}else{
			$(this).parents('ul').removeClass("erro");
			$(this).parents('ul').prev('p').html('');
		} 
	});
	
	
	$('.email', this).each(function(){
		if (!/^[a-zA-Z0-9]{1}([\._a-zA-Z0-9-]+)(\.[_a-zA-Z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+){1,3}$/.test($(this).val()) & (jQuery.trim($(this).val()) != $(this).attr('data-placeholder'))) {
			
                error = true;
				$(this).addClass("erro");
				$(this).prev('p').html('E-mail Inv&aacute;lido');
			                
		}else{
			$(this).removeClass("erro");
			$(this).prev('p').html('');
		} 
	});
	
	
	$('.filhos', this).each(function(){
		if (!/^[0-9]*$/.test($(this).val())  || (jQuery.trim($(this).val())>20)) {
                error = true;
				$(this).addClass("erro");
				$(this).prev('p').html('Erro');                
		}else{
			$(this).removeClass("erro");
			$(this).prev('p').html('');
		} 
	});
	
	$('.seleciona', this).each(function(){	
		$(this).removeClass("erro");	
		$(this).prev('p').html('');			
		if ($(this).val()=='' || $(this).val()==0 || (jQuery.trim($(this).val()) == $(this).attr('data-placeholder'))) {			 
			 $(this).prev('p').html('Selecione');
			 $(this).addClass("erro");					
			 error = true;	
		}else{		
			$(this).removeClass("erro");	
			$(this).prev('p').html('');			
		}        
	});
	if(error==false)
		return true;
	else {		
		return false;
	}
		
}


function validaHora(horario){
	 hora = horario.split(':')[0];
	 minuto = horario.split(':')[1];
	// segundo = horario.split(':')[2];
	segundo = 11;
	if(parseFloat(hora)>=0 && parseFloat(hora)<24){		
		if(parseFloat(minuto)>=0 && parseFloat(minuto)<60){
			if(parseFloat(segundo)>=0 && parseFloat(segundo)<60){
				return false;
			}
			else
				return true;
		}else
			return true;
	}else
		return true;	
	
}


function validaData(datanascimento){
	
	 dia = datanascimento.split('/')[0];
	 mes = datanascimento.split('/')[1];
	 ano = datanascimento.split('/')[2];
	 
	var data = new Date();
	var anoAtual = data.getFullYear();	
	anoAtual = parseFloat(anoAtual);
	anoMenor = parseFloat(anoAtual) - 130;	
	if(parseFloat(dia)>0 && parseFloat(dia)<=31){
							if(parseFloat(mes)>0 && parseFloat(mes)<=12){
								if(parseFloat(ano)>parseFloat(anoMenor) && parseFloat(ano)<=parseFloat(anoAtual)){
									if((parseFloat(mes)=='2' || parseFloat(mes)=='4' || parseFloat(mes)=='6' || parseFloat(mes)=='9' || parseFloat(mes)=='11')){
										if(parseFloat(dia)>30){
											return true;									
										}
										if (parseFloat(ano)%4==0){ var bi = 29; }else{ var bi = 28};
										if(parseFloat(mes)=='2' && parseFloat(dia)>bi ) {
												 return true;												
										}
									}else{
											return false;									
									}									
								}else{																		 
									return true;	
								}
							}else{
								return true; 
								//$('#datanascimento').next().html('O mês informado é inválido para está data :'+dia+'/'+mes+'/'+ano);								
							}
					}else{
						return true;
						//$('#datanascimento').next().html('O Dia informado é inválido para está data :'+dia+'/'+mes+'/'+ano);	
					}
	
}

