// 2009 ThomasK, www.kessler-design.com

$(document).ready(function(){
	$('#nombreError').hide();
	$('#apellidoError').hide();
	$('#sexoError').hide();
	$('#edadError').hide();
	$('#codigopostalError').hide();
	$('#telefonoError').hide();
	$('#correoError').hide();
	$('#empleoError').hide();
	$('#horasporsemanaError').hide();
	$('#findesemanaError').hide();
	$('#tieneperroError').hide();
	$('#hablarError').hide();
	$('#cocheError').hide();
	$('#experienciaError').hide();
	$('#porqueunadiestradorError').hide();
	$('#duracionparamasterError').hide();
	//submit..
	$('#aprendizform').submit(function(){
		if ($('#nombre').val() == ""){
			$('#nombreError').show();
			$('#nombre').focus();
			return false;
		}
		if ($('#apellido').val() == ""){
			$('#apellidoError').show();
			$('#apellido').focus();
			return false;
		}
		if ($("input:radio[name='sexo[]']:checked").size() == 0){
			$('#sexoError').show();
			return false;
		}
		if ($('#edad').val() == "" || !checkTwoDigits($('#edad').val(), '#edadError') ){
			$('#edadError').show();
			$('#edad').focus();
			return false;
		}
		if ($('#codigopostal').val() == "" || !checkZip($('#codigopostal').val()) ){
			$('#codigopostalError').show();
			$('#codigopostal').focus();
			return false;
		}
		if ($('#telefono').val() == ""){
			$('#telefonoError').show();
			$('#telefono').focus();
			return false;
		}
		if ($('#correo').val() == "" || !checkMail($('#correo').val()) ){
			$('#correoError').show();
			$('#correo').focus();
			return false;
		}
		if ($("input:radio[name='empleo[]']:checked").size() == 0){
			$('#empleoError').show();
			return false;
		}
		if ($('#horasporsemana').val() == "" || !checkTwoDigits($('#horasporsemana').val(), '#horasporsemanaError') ){
			$('#horasporsemanaError').show();
			$('#horasporsemana').focus();
			return false;
		}
		if ($("input:radio[name='findesemana[]']:checked").size() == 0){
			$('#findesemanaError').show();
			return false;
		}
		if ($("input:radio[name='tieneperro[]']:checked").size() == 0){
			$('#tieneperroError').show();
			return false;
		}
		if ($("input:checkbox[name='hablar[]']:checked").size() == 0){
			$('#hablarError').show();
			return false;
		}
		if ($("input:radio[name='coche[]']:checked").size() == 0){
			$('#cocheError').show();
			return false;
		}
		if ($('#experiencia').val() == ""){
			$('#experienciaError').show();
			$('#experiencia').focus();
			return false;
		}
		if ($('#porqueunadiestrador').val() == ""){
			$('#porqueunadiestradorError').show();
			$('#porqueunadiestrador').focus();
			return false;
		}
		if ($("input:radio[name='duracionparamaster[]']:checked").size() == 0){
			$('#duracionparamasterError').show();
			return false;
		}
	});
	//end submit
	//blur..
	$("#nombre").blur(function(){ 
		if ($("#nombre").val() == ""){
			$('#nombreError').show();
		}else{
			$('#nombreError').hide();
		}
	});
	$("#apellido").blur(function(){ 
		if ($("#apellido").val() == ""){
			$('#apellidoError').show();
		}else{
			$('#apellidoError').hide();
		}
	});
	$("#sexo_0").blur(function(){ 	
		if ($("input:['sexo[]']:checked").size() == 0){
			$('#sexoError').show();
		}else{
			$('#sexoError').hide();
		}
	});
	$("#sexo_1").blur(function(){ 	
		if ($("input:radio[name='sexo[]']:checked").size() == 0){
			$('#sexoError').show();
		}else{
			$('#sexoError').hide();
		}
	});
	$("#edad").blur(function(){ 
		var re = /\d{1,2}/;
		if ($("#edad").val().search(re) == -1){

			$('#edadError').show();
		}else{
			$('#edadError').hide();
		}
	});
	$("#codigopostal").blur(function(){ 
		var re = /\d{5}/;
		if ($("#codigopostal").val().search(re) == -1){
			$('#codigopostalError').show();
		}else{
			$('#codigopostalError').hide();
		}
	});
	$("#telefono").blur(function(){ 
		if ($("#telefono").val() == ""){
			$('#telefonoError').show();
		}else{
			$('#telefonoError').hide();
		}
	});
	$("#correo").blur(function(){ 
		var re = /[-\w.]+@([A-z0-9][-A-z0-9]+\.)+[A-z]{2,4}/;
		if ($("#correo").val().search(re) == -1){
			$('#correoError').show();
		}else{
			$('#correoError').hide();
		}
	});
	$("#empleo_0").blur(function(){ 	
		if ($("input:radio[name='empleo[]']:checked").size() == 0){
			$('#empleoError').show();
		}else{
			$('#empleoError').hide();
		}
	});
	$("#empleo_1").blur(function(){ 	
		if ($("input:radio[name='empleo[]']:checked").size() == 0){
			$('#empleoError').show();
		}else{
			$('#empleoError').hide();
		}
	});
	$("#horasporsemana").blur(function(){ 
		var re = /\d{1,2}/;
		if ($("#horasporsemana").val().search(re) == -1){

			$('#horasporsemanaError').show();
		}else{
			$('#horasporsemanaError').hide();
		}
	});
	$("#findesemana_0").blur(function(){ 	
		if ($("input:radio[name='findesemana[]']:checked").size() == 0){
			$('#findesemanaError').show();
		}else{
			$('#findesemanaError').hide();
		}
	});
	$("#findesemana_1").blur(function(){ 	
		if ($("input:radio[name='findesemana[]']:checked").size() == 0){
			$('#findesemanaError').show();
		}else{
			$('#findesemanaError').hide();
		}
	});
	$("#tieneperro_0").blur(function(){ 	
		if ($("input:radio[name='tieneperro[]']:checked").size() == 0){
			$('#tieneperroError').show();
		}else{
			$('#tieneperroError').hide();
		}
	});
	$("#tieneperro_1").blur(function(){ 	
		if ($("input:radio[name='tieneperro[]']:checked").size() == 0){
			$('#tieneperroError').show();
		}else{
			$('#tieneperroError').hide();
		}
	});

	$("#hablar_0").blur(function(){ 	
		if ($("input:checkbox[name='hablar[]']:checked").size() == 0){
			$('#hablarError').show();
		}else{
			$('#hablarError').hide();
		}
	});
	$("#hablar_1").blur(function(){ 	
		if ($("input:checkbox[name='hablar[]']:checked").size() == 0){
			$('#hablarError').show();
		}else{
			$('#hablarError').hide();
		}
	});
	$("#hablar_2").blur(function(){ 	
		if ($("input:checkbox[name='hablar[]']:checked").size() == 0){
			$('#hablarError').show();
		}else{
			$('#hablarError').hide();
		}
	});
	$("#hablar_3").blur(function(){ 	
		if ($("input:checkbox[name='hablar[]']:checked").size() == 0){
			$('#hablarError').show();
		}else{
			$('#hablarError').hide();
		}
	});
	$("#hablar_4").blur(function(){ 	
		if ($("input:checkbox[name='hablar[]']:checked").size() == 0){
			$('#hablarError').show();
		}else{
			$('#hablarError').hide();
		}
	});
	$("#hablar_5").blur(function(){ 	
		if ($("input:checkbox[name='hablar[]']:checked").size() == 0){
			$('#hablarError').show();
		}else{
			$('#hablarError').hide();
		}
	});

	$("#coche_0").blur(function(){ 	
		if ($("input:radio[name='coche[]']:checked").size() == 0){
			$('#cocheError').show();
		}else{
			$('#cocheError').hide();
		}
	});
	$("#coche_1").blur(function(){ 	
		if ($("input:radio[name='coche[]']:checked").size() == 0){
			$('#cocheError').show();
		}else{
			$('#cocheError').hide();
		}
	});
	$("#experiencia").blur(function(){ 
		if ($("#experiencia").val() == ""){
			$('#experienciaError').show();
		}else{
			$('#experienciaError').hide();
		}
	});
	$("#porqueunadiestrador").blur(function(){ 
		if ($("#porqueunadiestrador").val() == ""){
			$('#porqueunadiestradorError').show();
		}else{
			$('#porqueunadiestradorError').hide();
		}
	});

	$("#duracionparamaster_0").blur(function(){ 	
		if ($("input:radio[name='duracionparamaster[]']:checked").size() == 0){
			$('#duracionparamasterError').show();
		}else{
			$('#duracionparamasterError').hide();
		}
	});
	$("#duracionparamaster_1").blur(function(){ 	
		if ($("input:radio[name='duracionparamaster[]']:checked").size() == 0){
			$('#duracionparamasterError').show();
		}else{
			$('#duracionparamasterError').hide();
		}
	});
	$("#duracionparamaster_2").blur(function(){ 	
		if ($("input:radio[name='duracionparamaster[]']:checked").size() == 0){
			$('#duracionparamasterError').show();
		}else{
			$('#duracionparamasterError').hide();
		}
	});
	$("#duracionparamaster_3").blur(function(){ 	
		if ($("input:radio[name='duracionparamaster[]']:checked").size() == 0){
			$('#duracionparamasterError').show();
		}else{
			$('#duracionparamasterError').hide();
		}
	});
	$("#duracionparamaster_4").blur(function(){ 	
		if ($("input:radio[name='duracionparamaster[]']:checked").size() == 0){
			$('#duracionparamasterError').show();
		}else{
			$('#duracionparamasterError').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 checkTwoDigits(f, id){
	var re = /\d{1,2}/;
	if (f.search(re) == -1){
		$(id).show();
		return false;
	}else{
		$(id).hide();
		return true;
	}
}
function checkZip(f){
	var re = /\d{5}/;
	if (f.search(re) == -1){
		$('#zipError').show();
		return false;
	}else{
		$('#zipError').hide();
		return true;
	}
}

