	/*
	* File: news_details.js
	* Custom logic for the page: user gallery
	*/

	$(document).ready(function () {

		// submit comment
		$("#btnSubmitComment").click(function () {
			var html = "";
			var headlineID = $("#headline_id").val();
			var comment = $("#c_comments").val();

			var now = new Date();

			if (comment == "")
			{
				alert ("Please enter your comment");
				return false;
			}

			$.post("/ajax/news_comments",
				{
					headline_id: headlineID,
					comment: comment
				},
	  		function(data)
	  		{
	    		if (data == "SUCCESS")
	    		{
						$("#be_the_first").hide();

						html += '<div class="ar_item">';
						html += '	<div class="ar_image"><a href="/user/' + username + '"><img src="' + user_photo + '" width="56" alt="' + full_name + '" title="' + full_name + '" /></a></div>';
						html += '	<div class="ar_body">';
						html += '		<div class="ar_date">' + dateFormat(now, "mmm d, yyyy, h:MM TT") + '</div>';
						html += '		<div class="ar_desc">';
						html += '			<a href="/user/' + username + '">' + full_name + '</a> wrote:';
						html += '			<div class="c" style="height: 5px;"></div>';
						html += '			<div style="padding-left: 20px;">';
						html += 				comment.replace(/\n/g,"<br />");
						html += '			</div>';
						html += '		</div>';
						html += '	</div>';
						html += '	<div class="c"></div>';
						html += '</div>';
						html += '<div class="c"></div>';
						html += '<div class="a_item_delim"></div>';

						$("#news_comments").prepend(html);
						$("#c_comments").val("");
	    		}
	    		else
	    		{
						//error
						alert ("Error while inserting comment. Please, try again later.");
	    		}
	  		},
	  		"text"
	  	);
		});

	});

