function validate(frm){
	var er = ''; var reg = /^[a-z0-9-]+$/i;
	var uname = $('user_login').value.strip()
	if (uname.length == '') er = er + '<li>Please enter username</li>'
		else {
			if (uname.length < 5) er = er + '<li>Username must be at least 5 characters in length</li>'
			if (!reg.test(uname)) er = er + '<li>Username can only contain letters, numbers and hypens</li>'
	}
	if ($('user_password').value.strip().length == '') er = er + '<li>Please enter password</li>'
	if ($('user_password2').value.strip().length == '') er = er + '<li>Please retype password</li>'
	if ($('user_password').value != $('user_password2').value) er = er + '<li>Retyped password does not match password</li>'
	var name = $('user_name').value.strip()
	if (name.length == '') er = er + '<li>Please enter your name</li>'
		else {
			var name_p = name.split(" ")
			if (!name_p[1]) er = er + '<li>Your name must contain your first and last name</li>'
		}
	if ($('user_email').value.strip().length == '' || !ValidateEmail($('user_email'), true)) er = er + '<li>Please enter valid email</li>'

	if (er != '')	{
		$('errors-list').innerHTML = er
		Element.show('errorbox')
		return false
	}
	return
}

function doCheckLink() {
	var input = $('user_login').value.strip();
	if (input.length >= 5) {
		if ($('checklink').style.display != 'block') {
			$('checklink').style.display = 'block';
		}
	}
	else {
		if ($('checklink').style.display != 'none') {
			$('checklink').style.display = 'none';
		}
	}
}

var curUserID = '';

function checkIt() {
	var input = $('user_login').value.strip();
	if (curUserID != input && input != '') {
		curUserID = input;
		Element.toggle('checkthrobber');	
		new Ajax.Request(spath + '?fuseaction=ajax.checkLogin', {method: 'post', parameters: 'data='+input, onComplete: checkItFinish});
	}
}

function checkItFinish(r) {
	Element.toggle('checkthrobber');
	var json = ajaxError(r);
    if (json != '') {
		$('checkresult').innerHTML = json.message;
		Element.show('checkresult');
		new Effect.Highlight('checkresult');
	}
}

function getPassword() {
	var input = $('email').value.strip();
	Element.hide('msg');
	if (input != '') {
		new Ajax.Request(spath + '?fuseaction=ajax.resendPassword', {method: 'post', parameters: 'data='+input, onComplete: getPasswordFinish});
	}
}

function getPasswordFinish(r) {
var json = ajaxError(r);
    if (json != '') {
		if (json.response == 1) {
			Element.hide('fperrors');
			Element.hide('fpform');
			Element.show('msg');
			new Effect.Highlight('msg', {restorecolor: '#ffff99'});
		}
		else {
			$('errorcontent').innerHTML = '<li>'+json.message+'</li>';
			Element.show('fperrors');
		}
	}
}
