$(document).ready(function(){
	registro_listener();	
});
function registro_listener(){
	// formulario registro
	$('#fregistro').ajaxForm({target:'#fregistro_result', data:{js:'1'}, beforeSubmit:fregistro_beforesubmit,success:fregistro_response,clearForm: true,replaceTarget:false});
}
function fregistro_beforesubmit(formData, jqForm, options) { 
		$('#Nombre').css('border',''); 
		$('#ApellidoPaterno').css('border',''); 
		$('#ApellidoMaterno').css('border','');
		$('#Correo').css('border','');
		$('#Pass').css('border','');
		$('#RePass').css('border','');
		$('#captcha-code').css('border','');
		
		if($('#Nombre').val() == ''){ 			
			$('#Nombre').css('border','solid 1px #f00'); 
			$('#fregistro_result').html('Escribe tu nombre');
			return false; 
		} 
		if($('#ApellidoPaterno').val() == ''){ 			
			$('#ApellidoPaterno').css('border','solid 1px #f00'); 
			$('#fregistro_result').html('Escribe tu apellido paterno');
			return false; 
		} 
		if($('#ApellidoMaterno').val() == ''){ 			
			$('#ApellidoMaterno').css('border','solid 1px #f00'); 
			$('#fregistro_result').html('Escribe tu apellido materno');
			return false; 
		} 
		if($('#Correo').val() == ''){ 			
			$('#Correo').css('border','solid 1px #f00'); 
			$('#fregistro_result').html('Escribe tu correo electronico');
			return false; 
		} 
		var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; 
		if( emailPattern.test($('#Correo').val()) == false){
			$('#Correo').css('border','solid 1px #f00');
			$('#fregistro_result').html('Porfavor escribe una direccion de correo valida');
			return false;
		}
		if($('#Pass').val() == ''){ 			
			$('#Pass').css('border','solid 1px #f00'); 
			$('#fregistro_result').html('Escribe tu contraseña');
			return false; 
		} 
		if($('#RePass').val() == ''){ 			
			$('#RePass').css('border','solid 1px #f00'); 
			$('#fregistro_result').html('Re-Escribe tu contraseña');
			return false; 
		} 
		if($('#Pass').val() != $('#RePass').val()){
			$('#RePass').css('border','solid 1px #f00'); 
			$('#fregistro_result').html('Las contraseñas no coinciden');
			return false; 
		}
		if($('#captcha-code').val() == ''){
			$('#captcha-code').css('border','solid 1px #f00'); 
			$('#fregistro_result').html('Escribe el texto que vez en la imagen');
			return false; 
		}
		$('#btnsubmit').hide();
		return true;
}
function fregistro_response(responseText, statusText, xhr, $form)  {
	if( responseText == '1'){
		$('#fregistro_result').html('');
		$('#fregistro_success').show();
		$('#fregistro').hide();
	}else{
		$('#btnsubmit').show(); $('#fregistro_result').html(responseText);
	}
}
function change_captcha(){
	document.getElementById('captcha').src="mvc/get_captcha.php?rnd=" + Math.random();
}

