// formas
function initForm(){
	//cambios en campos
	$(':text, textarea').bind('mouseover mouseout', function(){
		$(this).toggleClass('hover');
	}).bind('focus blur', function(){
		$(this).toggleClass('focus');
	});
	//
	$('button').bind('mouseover mouseout', function(){
		$(this).toggleClass('hover');
	}).bind('focus blur', function(){
		$(this).toggleClass('focus');
	})
}

function checkForm(){
	var isErrorAviso = false;
	$('#enviar').click(function(){
		$('.error').hide();
		var hasError = false;
		
		var nombreVal = $('#nombre').val();
		if(nombreVal.length < 3) {
			$('#nombre').after('<div class="error">Ingresa tu nombre.</div>');
			hasError = true;
		}

		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		var emailVal = $('#email').val();
		if(emailVal.length < 3) {
			$('#email').after('<div class="error">Ingresa tu correo electr&oacute;nico.</div>');
			hasError = true;
		} else if(!emailReg.test(emailVal)) {	
			$('#email').after('<div class="error">Ingresa una direcci&oacute;n de correo v&aacute;lida.</div>');
			hasError = true;
		}
		
		var mensajeVal = $('#mensaje').val();
		if(mensajeVal != undefined && mensajeVal.length < 3) {
			$('#mensaje').after('<div class="error">No olvides contarnos el motivo de tu contacto.</div>');
			hasError = true;
		}
		
		if(hasError == true) {
			if(!isErrorAviso){
				$('form fieldset:first').before('<div id="error">Revisa los datos solicitados.</div>');
				isErrorAviso = true;
			}
			return false;
		}
	});
}

$('document').ready(function(){
	initForm();
	checkForm();
});