//_submitting = false;

function login() {
	/* request url */
	/* should use MD5 from this side to encrypt password */
//	if (!_submitting) {
//		_submitting = true;
		var url = "validate.php?username=" + $("username").value + "&password=" + $("password").value;
		var newUrl = modifyUrl(url,1);
		new Ajax.Request(newUrl, {
			method: 'get',
			onSuccess: function(transport, json) {
//				_submitting = false;
				json = transport.responseText.evalJSON(true)

				if (json.error) {
					alert(unescape(json.error.text));
				}

				if (json.location) {
					window.location = json.location;
				}

			}
		});
//	}
}

/**
 * modifies a rul by appending a datetime
 * @param {string} url - url
 * @param {bool} hasQS - if url has querystring parameters or not
 * @return {string}
 */
function modifyUrl(url, hasQS) {
	var tempDate = new Date();
	var newUrl = url;
	if (hasQS)
	{
		newUrl += "&";
	}
	else
	{
		newUrl += "?";
	}
	newUrl += "d=" + tempDate.getTime() + tempDate.getMilliseconds();
	return newUrl;
}
