var ContentUpdater = {
	/**
	 * update box containers
	 * @param {String} url
	 * @param {String|Object} form
	 */
	update: function(url, forms) {
		var params = [];
		if (typeof forms != 'undefined') {
			params.push(Form.serialize(forms));
		}
		new Ajax.Request(url, {
				method: 'post',
				parameters: params.join('&'),
				onSuccess: this.onUpdate.bind(this)
			});
		return true;
	},

	/**
	 * parse xml data and update containers
	 * @param {XMLHttpRequest} x
	 * @param {Object} json
	 */
	onUpdate: function(x, json) {
		var response = x.responseXML;
		if (response != null) {
			var atoms = $A(response.getElementsByTagName('content'));
			atoms.each( function(atom) {
				var id = atom.getAttribute('id');
				var container = $(id);
				if (container) {
					var text = [];
					$A(atom.childNodes).each( function(node) { text.push(node.data) });
					container.replace(text.join(''));
				}
			});

			
		}
	},

	hideMessage: function () {
	    if (typeof this.waitMsg != "undefined" && this.waitMsg != null) {
	        this.waitMsg.hide();
	        this.waitMsg = null;
	    }
	}
};

var DiscussionValidation = {
		
	onSubmit: function(url) {
		new Ajax.Request(url, {
			method: 'get',
			asynchronous: false, // hehe
			onSuccess: this.onUpdate.bind(this)
		});
		return true;
	},
	
	onUpdate: function(x,json) {
		var response = x.responseXML;
		if (response != null) {
			var timestamp = $A(response.getElementsByTagName('timestamp'));
			var text = timestamp[0].firstChild.textContent;
			if($('discussion-timestamp'))
				$('discussion-timestamp').value = text;
		}
		return true;
	}
};

