function AjaxComment(form) {
var url = 'http://nanoosenativeplants.org/wp-content/themes/k20508/comments-ajax.php';
	new Ajax.Updater( {
		success: 'commentlist',
		failure: 'error'
	}, url, {
		asynchronous: true,
		evalScripts: true,
		insertion: Insertion.Bottom,
		onLoading: function() { 
			$('commentload').show();
			$('error').update('');
			$('error').setStyle( { visibility: 'hidden' } );
			Form.disable('commentform');
		},
		onComplete: function(request) {
 				if (request.status == 200) {
					if ($('leavecomment')) { $('leavecomment').remove(); }
					new Effect.Appear($('commentlist').lastChild);
					$('comments').innerHTML = parseInt($('comments').innerHTML) + 1;
					Field.clear('comment');
					Form.disable('commentform');
					setTimeout('Form.enable("commentform")',15000);
				}
  			Element.hide('commentload');
		},
		onFailure: function() { 
			$('error').setStyle( { visibility: 'visible', width: '100%', textAlign: 'center', padding: '1px 0', margin: '5px 0', background: '#ffff99' } );
			Form.enable('commentform');
		},
		parameters: Form.serialize(form) 
		}
	);
}

function initComment() {
	$('commentform').onsubmit = function() { AjaxComment(this); return false; };
	new Insertion.Before('submit', '<p id="error"></p>');
	new Insertion.After('submit','<img src="http://nanoosenativeplants.org/wp-content/themes/k20508/images/spinner.gif" id="commentload" />');
	$('commentload').setStyle( { paddingTop: '3px', cssFloat: 'right' } );
	$('commentload').hide();
}

Event.observe(window, 'load', initComment, false);
