var status_username = 0;
var status_email = 0;
var status_password = 0;
var status_security = 0;

function c_username() {	
	var found_error = 0;
	var this_regexp = new RegExp("^[a-z0-9\-_]+$", "i");
	var this_field = document.getElementById('reg_username').value;
	
	if ( this_field.length < 2 ) {		
		document.getElementById('help_username').innerHTML = 'Your username must be at least 2 characters in length.';
		found_error = 1;
	}
	
	if ( this_regexp.test(this_field) == false ) {
		document.getElementById('help_username').innerHTML = 'Your username contains invalid characters. Valid characters are a-z, 0-9 and the _ and - characters.';
		found_error = 1;
	}
	
	if ( found_error == 1 ) {		
		document.getElementById('help_username').style.display = 'block';
		status_username = 0;
	}
	else {
		document.getElementById('help_username').style.display = 'none';
		status_username = 1;
	}
}

function c_email() {
	var found_error = 0;
	var this_regexp = new RegExp("^([a-z0-9_\.\-])+\@(([a-z0-9\-])+\.)+([a-z0-9]{2,4})+$", "i");
	var this_field = document.getElementById('reg_email').value;
	
	if ( this_regexp.test(this_field) == false ) {
		document.getElementById('help_email').innerHTML = 'Your e-mail address is in an invalid format.';
		found_error = 1;
	}
	
	if ( found_error == 1 ) {
		document.getElementById('help_email').style.display = 'block';
		status_email = 0;
	}
	else {
		document.getElementById('help_email').style.display = 'none';
		status_email = 1;
	}
}

function c_password() {
	var found_error = 0;
	var this_field = document.getElementById('reg_password').value;
	
	if ( this_field.length < 2 ) {		
		document.getElementById('help_password').innerHTML = 'Your password must be at least 6 characters in length.';
		found_error = 1;
	}
	
	if ( found_error == 1 ) {
		document.getElementById('help_password').style.display = 'block';
		status_password = 0;
	}
	else {
		document.getElementById('help_password').style.display = 'none';
		status_password = 1;
	}
}

function c_security() {
	var found_error = 0;
	var this_field = document.getElementById('reg_security').value;
	
	if ( this_field.length < 1 ) {		
		document.getElementById('help_security').innerHTML = 'Your security answer cannot be left blank.';
		found_error = 1;
	}
	
	if ( found_error == 1 ) {
		document.getElementById('help_security').style.display = 'block';
		status_security = 0;
	}
	else {
		document.getElementById('help_security').style.display = 'none';
		status_security = 1;
	}
}

function c_all() {
	if ( status_username == 1 && status_email == 1 && status_password == 1 && status_security == 1 ) {
		document.getElementById('reg_button').disabled = false;
	}
	else {
		//document.getElementById('reg_button').disabled = true;
		document.getElementById('reg_button').disabled = false;
	}
}
