function logon(frm) {

	if (!logon_check(frm)) {
    return false;
	}

	var callback =
	{
		success:	function(oResponse) {

								var oResults = parsejson(oResponse);

								if (oResults) {
									//put session id in cookie and go to maintenance page
									set_session_cookie(oResults.ResultSet.useid);
									frm.submit();
									return true;
								}
								return false;
							},

		failure:	function(oResponse) {
								if (oResponse.responseText !== undefined) {
									alert('Transaction id: ' + oResponse.tId +
												'\nHTTP status: '  + oResponse.status +
												'\nStatus code message: ' + oResponse.statusText);
								}
							},

		argument:	['foo','bar']
	};

	var sUrl = 'ajax_logon.php';
	YAHOO.util.Connect.setForm(frm);
	var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback);

	return false;

}


function logon_check(frm) {
  var error = 0;
  var error_message = '';

  if (trim(frm.un.value) == '') {
    error_message = error_message + 'Email must be entered.\n';
    error = 1;
  }

//any user name can be entered
//  if (trim(frm.un.value) != '') {
//		if (!val_email(trim(frm.un.value))) {
//	    error_message = error_message + 'Please provide a valid email address.\n';
//	    error = 1;
//		} 
//	}

  if (trim(frm.pw.value) == '') {
    error_message = error_message + 'Password must be entered.\n';
    error = 1;
  }

//any password can be entered
//  if (trim(frm.pw.value) != '') {
//		if (!val_password(trim(frm.pw.value))) {
//			error_message = error_message + 'Your password must satisfy the following. \n\n* Password should be 4 to 12 character long. \n* Password should have at least one alpha character. \n* Password should have at least one numeric character. \n* Password should only contain letters, numbers or underscores.';
//			error = 1;
//		}
//	}

	//strip invalid characters from username and password
	frm.un.value = trim(frm.un.value).replace(/[^a-zA-Z0-9@._-]+/g,'');
	frm.pw.value = trim(frm.pw.value).replace(/[^a-zA-Z0-9]+/g,'');

  if (error == 1) {
    alert(error_message);
    return false;
  } else {
    return true;
  }

}


function signup(frm) {
	if (!signup_check(frm)) {
    return false;
	}

	var callback =
	{
		success:	function(oResponse) {

								var oResults = parsejson(oResponse);

								if (oResults) {
									//put session id in cookie and go to maintenance page
									set_session_cookie(oResults.ResultSet.useid);
									frm.submit();
									return true;
								}
								return false;
							},

		failure:	function(oResponse) {
								if (oResponse.responseText !== undefined) {
									alert('Transaction id: ' + oResponse.tId +
												'\nHTTP status: '  + oResponse.status +
												'\nStatus code message: ' + oResponse.statusText);
								}
							},

		argument:	['foo','bar']
	};

	var sUrl = 'ajax_logon.php';
	YAHOO.util.Connect.setForm(frm);
	var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback);

	return false;
}


function signup_check(frm) {
  var error = 0;
  var error_message = '';

  if (frm.usr_email.value == '') {
    error_message = error_message + 'Email must be entered.\n';
    error = 1;
  }
  if (trim(frm.usr_email.value) != '') {
		if (!val_email(trim(frm.usr_email.value))) {
	    error_message = error_message + 'Please provide a valid email address.\n';
	    error = 1;
		} 
	}
  if (frm.usr_name.value == '') {
    error_message = error_message + 'Name must be entered.\n';
    error = 1;
  }
  if (frm.usr_password.value == '') {
    error_message = error_message + 'Password must be entered.\n';
    error = 1;
  }
  if (frm.usr_password.value != frm.usr_password_confirm.value) {
    error_message = error_message + 'Password confirmation does not match.\n';
    error = 1;
  }
  if (trim(frm.usr_password.value) != '') {
		if (!val_password(trim(frm.usr_password.value))) {
			error_message = error_message + 'Your password must satisfy the following. \n\n* Password should be 4 to 12 character long. \n* Password should have at least one alpha character. \n* Password should have at least one numeric character. \n* Password should only contain letters, numbers or underscores.';
			error = 1;
		}
	}

  if (error == 1) {
    alert(error_message);
    return false;
  } else {
    return true;
  }

}


function set_session_cookie(useid) {
	YAHOO.util.Cookie.set("award",useid);
}


function forgottenpassword(email) {
	if (email == '') {
		alert('Email must be entered.');
		return false;
	}

	var callback =
	{
		success:	function(oResponse) {

								var oResults = parsejson(oResponse);

								if (oResults) {
									alert('Your password has been reset and sent to the email address entered.');
								}
								return false;
							},

		failure:	function(oResponse) {
								if (oResponse.responseText !== undefined) {
									alert('Transaction id: ' + oResponse.tId +
												'\nHTTP status: '  + oResponse.status +
												'\nStatus code message: ' + oResponse.statusText);
								}
							},

		argument:	['foo','bar']
	};

	var sUrl = 'ajax_forgottenpassword.php';
	var postData = 'email='+email;
	var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);
	return false;
}


function setusrid(usrid,frm) {
	//set the given usrid in the current session record

	if (usrid == '') {
    return false;
	}

	var callback =
	{
		success:	function(oResponse) {

								var oResults = parsejson(oResponse);

								if (oResults) {
									//go to the maintenance page
									frm.submit();
								}
								return false;
							},

		failure:	function(oResponse) {
								if (oResponse.responseText !== undefined) {
									alert('Transaction id: ' + oResponse.tId +
												'\nHTTP status: '  + oResponse.status +
												'\nStatus code message: ' + oResponse.statusText);
								}
							},

		argument:	['foo','bar']
	};

	var sUrl = 'ajax_setusrid.php';
	var postData = 'usrid='+usrid;
	var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);

}
