/*
	This is a script which can be attached in the head of a page to allow it to use this login functionality. Have the submit button on the page call userLogin() with
	parameters username and password (the username and password in plain text, respectively).
	
	This script requries that the AJAX.js script (found in /support) be included as well
*/

// an AJAX-based login script
// you can alternatively use the older and less-user friendly HTML form-based login by submitting a form to /support/dispatch.php with a parameter called action with a
// value of "login"
function userLogin(username, password)
{
	var parameters = Array();
	parameters["userName"] = username;
	parameters["password"] = password;
	
	var callback = function(response) {
		// if login was successful, redirect to the new page, otherwise report the error
		if(response["status"])
		{
			// passing an empty or blank parameter to window.location will hang some browsers (Internet Explorer at least) so double check before redirecting
			if(typeof(response["redirectURL"]) != "undefined" && response["redirectURL"] != null && response["redirectURL"] != "")
				window.location = response["redirectURL"];
		}
		else
			alert(html_entity_decode(response["message"]));
	};
	
	AJAXRequestExecute("/support/login_support.php", false, true, parameters, callback);
	
	// return false in order to suppress submission of the HTML login form
	return false;
}
