var FJAjaxMail = {};

FJAjaxMail.send = function(mode) {
	var form = $('#mail_form');

	if(form.validate().form()) {
	    $('#mail_preview').attr({ disabled : true });
	    $('#mail_post').attr({ disabled : true });
	    var params = form.serialize();
	   // $('#ajax_mail').html(FJAjaxMail.waitMsg);
	    $('#ajax_mail')
	    	.find('#send')
		        .attr('src','/img/loading.gif')
		        .css({
		            'width':'40px',
		            'height':'40px'
		        })
		    .end()
		    .find('#reset').remove();
	    if (mode == "post") {
	        params += "&mail_post=1";
	    }
	    else if (mode == "preview") {
	        params += "&mail_preview=1";
	    }
    
    }else{
	 	return false;
 	}

    $.ajax({
        type : 'post',
        url : FJAjaxMail.cgiPath + 'plugins/MailForm/mt-mail-form.cgi',
        data : params,
        xhr : window.XDomainRequest ? hookXhr : undefined, 
        success : function(html) {
        	form.find('div.button-area').html(html);
            form.find('input,textarea').val('');
        },
        error : function(html) {
            form.html(FJAjaxMail.failureMsg);
//            $('#send_status').style.display = 'none';
        }
    });
    location.hash = 'ajax_mail';
    return false;
};
