
show_comment_form = function() {
	var form = document.getElementById('location_comments_form');

	if (form.style.display == 'block') return;


	YAHOO.util.Dom.setStyle(form, 'opacity', 0);
	form.style.display = 'block';

	var attributes = {
		opacity: { to: 1 }
	};


	var myAnim = new YAHOO.util.Anim(form, attributes, 0.3);
	myAnim.animate();

	var callback = function(str) {
		dialog = make_alert('dialog', 'Transfer successful', 'Your comment has been added.', function() {location.reload(true); } );
		dialog.show();
	}

	var validator = new AJAXFormValidator('location_comments_form', callback, '/manager-comment.php', true);
	validator.setActivityIndicator('form_activity_indicator');
	validator.setFading(fading_config);
}



init_comment_rating = function() {
	var anchors = document.getElementById('location_comments').getElementsByTagName('a');


	for (i=0; i<anchors.length; i++) {
		if (anchors[i].id && anchors[i].id.indexOf('comment_thumb') > -1) {

			var anchor = anchors[i];

			var parts = anchor.id.split('_');
			comment_id = parts[parts.length-1];

			user_rating = '';

			if (anchor.id.indexOf('comment_thumb_down') > -1) {
				user_rating = 'minus';
			} else if (anchor.id.indexOf('comment_thumb_up') > -1) {
				user_rating = 'plus';
			}

			set_comment_rating = function(e, arg) {
				callback = {
					success: function(o) {
						document.getElementById('comment_rating_container_'+o.argument.comment_id).innerHTML = o.responseText;

						//YAHOO.util.Event.removeListener('comment_thumb_down_'+o.argument.comment_id, 'click');
						//YAHOO.util.Event.removeListener('comment_thumb_up_'+o.argument.comment_id, 'click');
					},

					argument: {
						comment_id: arg.comment_id,
						user_rating: arg.user_rating
					}
				}

				document.getElementById('comment_rating_container_'+arg.comment_id).innerHTML = '<img src="/images/ajax-loader.gif" width="16" height="16" alt="" class="icon" />';

				postdata = 'action=rate&comment_id='+arg.comment_id+'&rating='+arg.user_rating;
				request = YAHOO.util.Connect.asyncRequest('POST', '/manager-comment.php', callback, postdata);
			}

			argu = {
				user_rating: user_rating,
				comment_id: comment_id
			}

			YAHOO.util.Event.addListener(anchor, 'click', set_comment_rating, argu);
		}
	}

}



YAHOO.util.Event.onDOMReady(function() {
	init_comment_rating();
});

YAHOO.util.Event.addListener('write_comment_link', 'click', show_comment_form);

