// 2009 ThomasK, www.kessler-design.com

$(document).ready(function(){
	$('#emailError').hide();
	$('#zipError').hide();
	//submit..
	$('#examin').submit(function(){
		if ($('#correo').val() == "" || !checkMail($('#correo').val()) ){
			$('#emailError').show();
			$('#correo').focus();
			return false;
		}
		if ($('#codigo').val() == "" || !checkZip($('#codigo').val()) ){
			$('#zipError').show();
			$('#codigo').focus();
			return false;
		}
	});
	//end submit
	//blur..
	$("#correo").blur(function(){ 
		var re = /[-\w.]+@([A-z0-9][-A-z0-9]+\.)+[A-z]{2,4}/;
		if ($("#correo").val().search(re) == -1){
			$('#emailError').show();
		}else{
			$('#emailError').hide();
		}
	});
	$("#codigo").blur(function(){ 
		var re = /\d{5}/;
		if ($("#codigo").val().search(re) == -1){
			$('#zipError').show();
		}else{
			$('#zipError').hide();
		}
	});
	//end blur
});

//called by submit...
function checkMail(f){
	var re = /[-\w.]+@([A-z0-9][-A-z0-9]+\.)+[A-z]{2,4}/;
	if (f.search(re) == -1){
		$('#emailError').show();
		return false;
	}else{
		$('#emailError').hide();
		return true;
	}
}
function checkZip(f){
	var re = /\d{5}/;
	if (f.search(re) == -1){
		$('#zipError').show();
		return false;
	}else{
		$('#zipError').hide();
		return true;
	}
}