	
	$(document).ready(function(){
		
		var options = {
	        success:	showResponse,
	        beforeSubmit:  validate
	    }; 
	 
	    $('#passform').submit(function() {
	      	return false;
	    });
	    
		$('.send')
			.click(function(){
				$('#passform').ajaxSubmit(options); 
				return false;
			});
			
		$('.clear')
			.click(function(){
				$('#passform').resetForm();
				return false;
			});
	    
	});
	
	function validate(formData, jqForm, options) { 
		
		var form = jqForm[0]; 
    	if ( !form.email.value || !form.code.value ){
    		
       		showAlert('Debes completar todos los campos');
        	return false;
        	
    	} else if( !check_mail_format(form.email.value) ){
    		
    		showAlert("Formato de email incorrecto");
    		return false;
    		
    	}
		
	}
	
	function showResponse(txt, status){
		
		var error = false;
			
		if		(txt == "E1"){ error = true; showAlert('Este correo no se encuentra registrado'); }
		else if	(txt == "E2"){ error = true; showAlert('El código verificador no corresponde.'); }
		else if	(txt == "E3"){ error = true; showAlert('Debes activar primero tu cuenta antes de poder recuperar tu clave.'); }
		
		if(!error){
			
			if(txt == "OK"){
				window.location = "/?recover";
			}
			
		}
				
		
			
	}