$debug = false;

function submitLogin() {
	new Ajax.Request('/account/action/login.php', {
		method:			'post',
		onSuccess:		processResponse,				  
		parameters:		$('login_form').serialize(true),
		requestHeaders:	{ 'X-JSON-REQUEST': 'TRUE' }
	});
}

function processResponse() {
	response = arguments[0];
	var rTxt = new $A( response.responseText.strip().split("|") );
	var rspStr = '';
	if( rTxt[0] == 'error' ) {
		switch( rTxt[1] ) {
			case 'notfound':
				rspStr = 'We need additional information to complete your online registration. Please contact customer service to finish setting up your account at 877 866-8965.';
				break;
			case 'invalid':
				rspStr = 'The username or password you entered is incorrect.';
				showMsgWrapper();
				break;
			case 'mismatch':
				rspStr = "The passwords you entered did not match. Please re-enter your passwords.";
				showMsgWrapper();
				break;
			case 'invalidun':
				rspStr = "Usernames must be 3 to 24 characters long and can contain letters, numbers, and underscores.";
				showMsgWrapper();
				break;
			default:
				rspStr = 'An unknown error occurred. Please contact customer service to finish placing your order, at 877 866-8965';
		}
	} else if( rTxt[0] == 'ok' ) {
		switch( rTxt[1] ) {
			case 'multiple':
				rspStr = 'We need additional information to complete your online registration. Please contact customer service to finish setting up your account at 877 866-8965';
				break;
			case 'exists':
				rspStr = 'There is already an account associated with this email address. If you have lost your password, please click the password reset link on the login screen to have reset instructions emailed to you, or contact Customer Service if you need additional assistance at 877 866-8965.';
				break;
			default:
				rspStr = 'An unknown error occurred. Please contact customer service to finish placing your order at 877 866-8965.';
		}
	} else if( rTxt[0] == 'redirect' ) {
		document.location.href = rTxt[1];
	}
	if ($debug) alert(response.responseText);
	if( rspStr ) $('message_wrapper').innerHTML = rspStr;
}
