/**
 * The login static class.
 * 
 * @version 2010-12-24
 * @author <a href="mailto:r.tennapel@griponservice.nl?SUBJECT=Login script.js">R. ten Napel, ing.</a>
 **/
function Login() {}

/**
 * Handle login action.
 * 
 * @param widgetId			The widget ID.
 * @param handler			The path to the login-handler.
 * @param action			The login action.
 **/
Login.send = function(widgetId, handler, action, locationUrl) {
	// Define the params string:
	var params = "widgetId=" + widgetId + "&action=" + action;
	params += (action == "login") ? "&" + $(widgetId).getValues("INPUT", "URL") : "";
	var lu = locationUrl;
	// Create / retrieve the widget:
	var widget = new Widget($(widgetId).$().parentNode, "Login", params);

	// Onsuccess handler:
	var onSuccess = function(response) {
		var response = JSON.parse(response);
		
		// If the action was succesfull, reload the page:
		if (response.success) {
			setTimeout(function() { document.location = './'+lu; }, 10);
		}

		// Refresh the widget:
		widget.refresh(params);
	};
	
	// Ajax-request:
	new Ajax(null, handler + "?" + params, null, null, onSuccess).request();
};
