/* 
 * comment form ajax
 */


$(document).ready(function(){

	 // prepare the form when the DOM is ready
    var options = {
        //target:			'.success',   // target element(s) to be updated with server response
		beforeSubmit:	showRequest,  // pre-submit callback
        success:		showResponse,  // post-submit callback
		dataType:		'json'        // 'xml', 'script', or 'json' (expected server response type)

        // other available options:
        // url:      url         // override for form's 'action' attribute
        //type:      type        // 'get' or 'post', override for form's 'method' attribute
        
        //clearForm: true        // clear all form fields after successful submit
        //resetForm: true        // reset the form after successful submit

        // $.ajax options can be used here too, for example:
        //timeout:   3000
    };

    // bind form using 'ajaxForm'
    $('.cystadleuaeth_cwestiwn_form').ajaxForm(options);
	
});

// pre-submit callback
function showRequest(formData, jqForm, options)
{
	// show loading graphic
	// send data
	
	$('.formentry').hide('slow');
    return true;
}

// post-submit callback
function showResponse(responseText, statusText)
{
    // for normal html responses, the first argument to the success callback
    // is the XMLHttpRequest object's responseText property

	
	
	//$('.success').show();

	$('.cystadleuaeth_cwestiwn').append(responseText.message);
	
	if(responseText.status == 'fail')
		{
			$('.formentry').show();
			$('.cystadleuaeth_cwestiwn').append(responseText.errors);
		}	
}

