// WAX_FTPZONE
WAX_FTPZONE = {

		initcheckLogin			: function (p_form) {
			$('errormessage').update("");
			if (!formChecker.checkForm(p_form)) {
				return false;
			} else {
				p_form.action.value = "AJAX_checkLogin"; 
				WAX_FTPZONE.checkLogin(p_form);
			}
		},

		checkLogin			: function (p_form) {
			// prep postbody
			var urlparams = Form.serialize(p_form);
			var postBody	= urlparams;

			new Ajax.Request(
				window.location,
				{
					method		: "post",
					postBody	: postBody,
					onSuccess	: function(t) {
						var json	= t.responseText.parseJSON();

						if (json.status.code == "success") {
							window.location.href = 'index.php?p=/ftpzone/';
						} else {
							new Effect.Highlight('loginform',
								{startcolor:'#FFB5AF', endcolor:'#ffffff', duration:'2'});
							$('errormessage').update(json.status.message);
							
							// hide the spinner + re-enable the submitbutton
							$('spinner').style.visibility 	= 'hidden';
							$('formSubmit').disabled		= false;								
						}
					},
					onFailure	: function(t) {
						alert("Critical Error, please contact administration with this info:\n" + t.status + " -- " + t.statusText);
				
						// hide the spinner + re-enable the submitbutton
						$('spinner').style.visibility 	= 'hidden';
						$('formSubmit').disabled		= false;							
					}
				}
			);

		},

		doneCheckLogin	: function(p_form, responseText) {
			var json	= responseText.parseJSON();

			if (json.status.code == "success") {
				//alert("added with id " +json.status.message);

				if ($('noitems')) {
					Element.remove('noitems');
				}

				// do the insertion
				new Insertion.Top($('itemsList'), "<li id=\"user_"+json.status.message+"\" class=\"" + u_name + "\">"
										  + "<em>"+ u_name + "</em>"
										  + "<a class=\"manage_edit\" href=\"index.php?p=/users/edit/" + json.status.message + "/\" title=\" Manage this user\">Manage this user</a>"
										  + "<a class=\"manage_delete\" href=\"index.php?p=/users/delete/" + json.status.message + "/\" title=\"Delete this user\" onclick=\"javascript:WAX_CMS.users.doDelete("+json.status.message+"); return false;\"  >Delete this user</a>"
										  + "</li>");

				// highlight
				new Effect.Highlight('user_' + json.status.message,
					{startcolor:'#ffff33', endcolor:'#FFFFFF', duration:'2'});
				
				// highlight
				new Effect.Highlight('edit',
					{startcolor:'#ffff33', endcolor:'#FFFFFF', duration:'2'});


				// reset the form
				p_form.reset();
				
				// hide the spinner + re-enable the submitbutton
				$('spinner').style.visibility 	= 'hidden';
				$('formSubmit').disabled		= false;

			} else {
				alert("User was not added. Server returned:\n" + json.status.message);

				// hide the spinner + re-enable the submitbutton
				$('spinner').style.visibility 	= 'hidden';
				$('formSubmit').disabled		= false;				
			}
		}

}
/*
repearing code for firebug!! thx to firebug
document.getElementById("formSubmit").disabled = "";
$('spinner').style.display= "none";

*/
