function postForm(form, handleAs, responseMsg) {
	var response;
	var xhrArgs = {

		form : form.domNode,
		handleAs : handleAs,
		load : function(data) {
			response = (responseMsg ? responseMsg : data);

			showDialog('success', 'Success', response);
		},
		error : function(error) {
			// We'll 404 in the demo, but that's okay. We don't have a 'postIt'
			// service on the
			// docs server.
			alert("An error ocurred please try again. " + error);
		}
	}

	// Call the asynchronous xhrPost

	var deferred = dojo.xhrPost(xhrArgs);

}

function showMessengerDialog(msgClass, msgTitle) {
	var msgClass = msgClass;
	var msgTitle = msgTitle;
	var dialog = new dijit.Dialog();

	if (msgClass) {
		dialog.attr('href', baseUrl + 'messenger/show/id/'
				+ encodeURIComponent(dialog.id) + '/type/' + msgClass + '/');
	} else {
		dialog.attr('href', baseUrl + 'messenger/show/id/'
				+ encodeURIComponent(dialog.id) + '/');
	}
	dialog.attr('class', msgClass);
	dojo.body().appendChild(dialog.domNode);
	dialog.startup();

	dialog.show();
}

function closemessengerDialog(dId) {

	dijit.byId(dId).destroy();
}

function showDialog(msgClass, msgTitle, msgContent, msgHref) {

	var dialog = new dijit.Dialog();
	if (msgTitle) {
		dialog.attr('title', msgTitle);
	}
	if (msgClass) {
		dialog.attr('class', msgClass);
	}
	dialog.attr('content', msgContent);
	if (msgHref) {
		dialog.attr('href', msgHref + '/dialogId/'
				+ encodeURIComponent(dialog.id) + '/');
	}
	dialog.attr('parseOnLoad', true);
	dojo.body().appendChild(dialog.domNode);

	var btn = new dijit.form.Button({
		label : "Close",
		style : "display:block;width:50px;margin:25px auto 0px auto;"
	});
	dialog.containerNode.appendChild(btn.domNode);
	dojo.connect(btn, "onClick", function() {
		dialog.destroy();
	});

	dialog.startup();
	dialog.show();
	return dialog;
}

function generateToken() {

	var getData = function() {
		var ret;
		dojo.xhrGet({
			url : baseUrl + 'token/generate/',
			sync : true,
			load : function(data) {
				ret = data
			}
		});
		return ret;
	};

	var token = getData();

	return token;
}
