$(document).ready(function() {

	var options = { 
		target:        '#komentar',   // target element(s) to be updated with server response 
		beforeSubmit:  chkFormKomentar   // pre-submit callback 
		//success:       reLocateWindow  // post-submit callback
		//clearForm: true
		//success: function() { $('#formKomentar').fadeIn('slow'); }

		// other available options: 
		//url:       url         // override for form's 'action' attribute 
		//type:      type        // 'get' or 'post', override for form's 'method' attribute 
		//dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
		//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' 
	$('#frmComment').ajaxForm(options);

	var clickfbox = function() {
		//alert('Horeee!');
		var toload = $(this).attr('href');
		jQuery.facebox(toload);
		/**
		jQuery.get(toload, function(data) {
			jQuery.facebox(data)
		});
		/* */
		return false;
	};

    $('a[rel*=facebox]').livequery('click', clickfbox);

/**
	var addComment = function() {
		alert("Tombol save diklik...");
		var name = $("input#author").val();
		alert("name: " + name);
		if (name == "") {
			$("input#author").css("background-color:red");
			$("input#author").focus();
			return false;
		}
		alert("formData " + formData);
        return false;
	};

	$('input.tambahKomentar').livequery('click', addComment);
/**/
});

function chkFormKomentar() {

	if (document.frmComment.author.value == "")
	{
		alert("Silakan isi nama anda!");
		document.frmComment.author.focus();
		return false
	} else if (document.frmComment.email.value == "")
	{
		alert("Silakan isi alamat email anda!");
		document.frmComment.email.focus();
		return false
	} else if (document.frmComment.comment.value == "")
	{
		alert("Silakan isi komentar anda!");
		document.frmComment.comment.focus();
		return false
	} else if (document.frmComment.confirmCaptcha.value == "")
	{
		alert("Mohon diisi karakter yang ditampilkan!");
		document.frmComment.confirmCaptcha.focus();
		return false
	}
	return true;
}

function reLocateWindow() {
	// = '';
	document.frmComment.confirmCaptcha.value = '';
	window.location = "#komentar" ;
}

function showRequest(formData, jqForm, options) { 
    // formData is an array; here we use $.param to convert it to a string to display it 
    // but the form plugin does this for you automatically when it submits the data 
    var queryString = $.param(formData); 
 
    // jqForm is a jQuery object encapsulating the form element.  To access the 
    // DOM element for the form do this: 
    // var formElement = jqForm[0]; 
 
    ////alert('About to submit: \n\n' + queryString); 
 
    // here we could return false to prevent the form from being submitted; 
    // returning anything other than false will allow the form submit to continue 
    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 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'xml' then the first argument to the success callback 
    // is the XMLHttpRequest object's responseXML property 
 
    // if the ajaxForm method was passed an Options Object with the dataType 
    // property set to 'json' then the first argument to the success callback 
    // is the json data object returned by the server 
	window.location = "#komentar" ;
    //alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + '\n\nThe output div should have already been updated with the responseText.'); 
}


