var isLock = false;
function checkusername(el){
	if(isLock){return true;} //If its locked return.. shouldn't this be void or checking..?
	isLock = true; //We're starting the check, lock the function
	var isLockCheck = getUserName(el)
	if(!isLockCheck){
    	el.errors.push( 'Ya existe un usuario de redribera con este nick.<br/> Intenta registrate con un nombre de usuario diferente!' );
        isLock = false; // release the function we're done
        return false; //return the error message to the user
	}
	isLock = false; //release the function we're done
	return true; //no error message
}

function getUserName(el){
	var isLockCheck = true; //default to no errors
	var myRequest = new Request({url:'includes/userexists.php', method: 'post', //This can be post as well
	evalResponse: true, //Evaluate the Requested pages response.
	async: false, //IMPORTANT! STOP SCRIPTS FROM RUNNING UNTIL REQUEST IS DONE!!!!
	data: {'nickname' : $(el).get('value')}, // The data to send this is the same as ?username=this.form.element.value
	onSuccess : function(response){
		if(response == 'existe'){
			//false = show error to user
			isLockCheck = false;
		}
	},
	onFailure : function(){
		isLockCheck = false; //There was an Error don't let the user submit...
	}
	}).send();
	return isLockCheck; //return our results
}

var eisLock = false;
function checkDupEmail(el){
	if(eisLock){return true;} //If its locked return.. shouldn't this be void or checking..?
	eisLock = true; //We're starting the check, lock the function
	var eisLockCheck = getEmail(el)
	if(!eisLockCheck){
    	el.errors.push( 'Ya existe un usuario con este email.<br/> Utilice un email diferente!' );
        eisLock = false; // release the function we're done
        return false; //return the error message to the user
	}
	eisLock = false; //release the function we're done
	return true; //no error message
}

function getEmail(el){
	var eisLockCheck = true; //default to no errors
	var myRequest = new Request({url:'includes/emailexists.php', method: 'post', //This can be post as well
	evalResponse: true, //Evaluate the Requested pages response.
	async: false, //IMPORTANT! STOP SCRIPTS FROM RUNNING UNTIL REQUEST IS DONE!!!!
	data: {'email' : $(el).get('value')}, // The data to send this is the same as ?username=this.form.element.value
	onSuccess : function(response){
		if(response == 'existe'){
			//false = show error to user
			eisLockCheck = false;
		}
	},
	onFailure : function(){
		eisLockCheck = false; //There was an Error don't let the user submit...
	}
	}).send();
	return eisLockCheck; //return our results
}
