$(function(){
	$('#comment_link').click(function(){
		$('#comment_div').dialog('open');
		return false;
});	
	
	$('#comment_div').dialog({
		autoOpen: false,
		resizable: false,
		width: 900,
		height: 600,
		bgiframe: true,
		modal: true,
		buttons: {
			"Close": function() { 
				$(this).dialog("close"); 
			} 
		}
});
	

	$('#comment_movie_link').click(function(){
		$('#comment_movie').dialog('open');
		return false;
});		
	$('#comment_tv_link').click(function(){
		$('#comment_tv').dialog('open');
		return false;
});	
	
	$('#comment_movie').dialog({
		autoOpen: false,
		resizable: false,
		width: 900,
		bgiframe: true,
		modal: true,
		buttons: {
			"Post": function() { 
				//$(this).dialog("close"); 
				title = $("#frm_title").val()
				post = $("#frm_text").val()
				movieid  = $("#hid_movieid").val()
				
				$.post("/comments/post", { frm_title: title, frm_text: post, hid_movieid : movieid },
				  function(data){
		
					if (data == "Done"){
						$("#frm_comment").css('visibility','hidden');
						$("#message").html("<center><b>Posted</b></center>");
					}
					else
					{
						$("#message").html(data);
					}
				  });
							}, 
			"Cancel": function() { 
				$(this).dialog("close"); 
			} 
		}
});
	
	$('#comment_tv').dialog({
		autoOpen: false,
		resizable: false,
		width: 900,
		bgiframe: true,
		modal: true,
		buttons: {
			"Post": function() { 
				//$(this).dialog("close"); 
				title = $("#frm_title").val()
				post = $("#frm_text").val()
				tvshowid  = $("#hid_tvshowid").val()
				tvepisodeid =  $("#hid_tvepisodeid").val()
				$.post("/comments/post", { frm_title: title, frm_text: post, hid_tvshowid : tvshowid, hid_tvepisodeid : tvepisodeid },
				  function(data){
		
					if (data == "Done"){
						$("#frm_comment").css('visibility','hidden');
						$("#message").html("<center><b>Posted</b></center>");
					}
					else
					{
						$("#message").html(data);
					}
				  });
							}, 
			"Cancel": function() { 
				$(this).dialog("close"); 
			} 
		}
});
});