// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
(function($){
	$(function(){
		$('form.validate').bind('submit', function(e){
			var result = true;
			var x = $('input.is-email')
			x.each(function(){
			var test = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i.test( $(this).val() )
				if(!test) {
					if($('#' + $(this).attr('id') + '_msg').length == 0){
						$(this).after('<div id="' + $(this).attr('id') + '_msg" style="color:red;padding:5px;"><img src="/images/silk/error.png" alt="error" /> Es Requerido y debe ser una dirección de email</div>')
					}
					$(this).addClass('error');
					result = false
				}else{
					if($('#' + $(this).attr('id') + '_msg').length > 0){
						$('#' + $(this).attr('id') + '_msg').remove()
					}
					$(this).removeClass('error');
				}
	
			});
			
			x = $('input.is-numeric')
			x.each(function(){
			var test = /[0-9]/.test( $(this).val() )
				if(!test) {
					if($('#' + $(this).attr('id') + '_msg').length == 0){
						$(this).after('<div id="' + $(this).attr('id') + '_msg" style="color:red;padding:5px;"><img src="/images/silk/error.png" alt="error" /> Es Requerido y debe ser Númerico</div>')
					}
					$(this).addClass('error');
					result = false
				}else{
					if($('#' + $(this).attr('id') + '_msg').length > 0){
						$('#' + $(this).attr('id') + '_msg').remove()
					}
					$(this).removeClass('error');
				}
			});
			
			x = $('input.is-required')
			x.each(function(){
				var test = /./.test( $(this).val() )
				if(!test) {
					if($('#' + $(this).attr('id') + '_msg').length == 0){
						$(this).after('<div id="' + $(this).attr('id') + '_msg" style="color:red;padding:5px;"><img src="/images/silk/error.png" alt="error" /> Es Requerido</div>')
					}
					$(this).addClass('error');
					result = false
				}else{
					if($('#' + $(this).attr('id') + '_msg').length > 0){
						$('#' + $(this).attr('id') + '_msg').remove()
					}
					$(this).removeClass('error');
				}
			});
			
			if(!result){
				e.preventDefault();
			}
		});
	});
})(jQuery);
