$(document).ready(function() {
	var options = {
		target:			'#dialog_message',
		dataType:		'xml',
		beforeSubmit:	showRequest,
		success:		showResponse,
		data:			{ ajax: 1 },
		iframe:			true
	};
	
	$('.ajax_form').ajaxForm(options);
}); 

// pre-submit callback 
function showRequest(formData, jqForm, options) {
	// show loading
	$("#dialog_message").empty();
	$("#dialog_message").append('<img src="/img/frontend/loader.gif" alt="loading" />');
	
	// prepare the form for submit
	var queryString = $.param(formData);
	
	return true;
}

// post-submit callback 
function showResponse(responseXML)  {
	// get info from the returned xml
	var status	= $('status', responseXML).text();
	var message	= $('message', responseXML).text();
	
	// add this information to the ajax_dialog
	$("#dialog_message").empty();
	if (status == 1) {
		$("#dialog_message").append('<img src="/img/icon/accept.png" alt="accept" style="vertical-align: text-bottom;" /> ' + message);
		$(".ajax_form").clearForm();
	} else {
		$("#dialog_message").append('<img src="/img/icon/cross.png" alt="cross" style="vertical-align: text-bottom;" /> ' + message);
	}
}
