var intURL = "includes/content/interpret/interpretlist_server.php";
var rowspan = ""; 
var processingbar = '<div id="int-processing" align="center" style="vertical-align:middle;"><tr><td colspan="4"><strong>Gathering Dream List</strong>&nbsp;&nbsp;&nbsp;&nbsp;<img id="processingbar" src="images/processing_bar.gif" /></td></tr></div>';
var dreamlist_max = 25; 
var limit_cur = 0;
var limit_max = dreamlist_max;
var sortby = "";
var sortorder = "ASC";
var thesearch = "";
var dreamid = "";
var interp_id = "";
var from_interp = true;
$(document).ready(function()
	{
		IntPageLoad();
		$('#dialog-viewdream').dialog(
			{
				bgiframe:true,
				autoOpen:false,
				resizable:false,
				width:600,
				modal:true,
				closeOnEscape:false,
				overlay:
				{
					backgroundColor: '#000',
					opacity: 0.7
				},
				buttons:
				{
					'Close': function()
						{
						$(this).dialog('close');
						}
				}
			});
		$('#dialog-int-error').dialog(
			{
				bgiframe:true,
				autoOpen:false,
				resizable:false,
				width:400,
				modal:true,
				closeOnEscape:false,
				overlay:
				{
					backgroundColor: '#000',
					opacity: 0.7
				},
				buttons:
				{
					'Close': function()
						{
						$(this).dialog('close');
						}
				}
			});
		$('#dialog-comment-reply').dialog(
			{
				bgiframe:true,
				autoOpen:false,
				resizable:false,
				width:600,
				modal:true,
				closeOnEscape:false,
				overlay:
				{
					backgroundColor: '#000',
					opacity: 0.7
				},
				buttons:
				{
					'Submit': function()
						{
							comment_newreply = $('#c-comment-replytext').val();
							validate = true;
							
							validate = validate && FillCheck(comment_newreply,"Please enter a response before submitting a reply",$('#c-comment-replytext'),$('#tips-comment-reply'));

						
							if(validate)
								{
									SendCommentReply(dreamid,comment_newreply);	
								}
						},
					'Close': function()
						{
						$(this).dialog('close');
						}
				}
			});
		$('#dialog-int-mandatory').dialog(
			{
				bgiframe:true,
				autoOpen:false,
				resizable:false,
				width:400,
				modal:true,
				closeOnEscape:false,
				overlay:
				{
					backgroundColor: '#000',
					opacity: 0.7
				},
				buttons:
				{
					'Yes': function()
						{
							GetInterpretSearchList(thesearch);
							$(this).dialog('close');
						},
					'No': function()
						{
						$(this).dialog('close');
						}
				}
			});
		$('#dialog-int-success').dialog(
			{
				bgiframe:true,
				autoOpen:false,
				resizable:false,
				width:400,
				modal:true,
				closeOnEscape:false,
				overlay:
				{
					backgroundColor: '#000',
					opacity: 0.7
				},
				buttons:
				{
					'Close': function()
						{
						$(this).dialog('close');
						}
				}
			});
		$('#int-a-live').click(function()
			{ 
				if(interp_loggedin == "yes")
					{
						$('#int-thead-livedreamlist').hide();
						$('#int-tbody-dreamlist').empty();
						$('#int-text-listamount').empty();
						$('#int-text-comment').empty();
						sortby = "";
						sortorder = "ASC";
						limit_cur = 0;
						limit_max = dreamlist_max;
						GetInterpretLiveList();
					}
				else
					{
						UpdateInterpretText("notloggedin");	
					}
			})
		.hover(
			function(){ 
				$(this).addClass("int-a-hover");
			},
			function(){ 
				$(this).removeClass("int-a-hover"); 
			}
			).mousedown(function(){
				$(this).addClass("ui-state-active"); 
			})
			.mouseup(function(){
					$(this).removeClass("ui-state-active");
			});
		$('#int-a-mandatory').click(function()
			{
				if(interp_loggedin == "yes")
					{	
					$('#int-tbody-dreamlist').empty();
					$('#int-text-listamount').empty();
					$('#int-text-comment').empty();
					$('#int-thead-mandatorydreamlist').hide();
					$('#int-tbody-dreamlist').empty();
					sortby = "";
					sortorder = "ASC";
					limit_cur = 0;
					limit_max = dreamlist_max;
					GetInterpretMandatoryList();
				}
				else
					{
						UpdateInterpretText("notloggedin");	
					}
			})
		.hover(
			function(){ 
				$(this).addClass("int-a-hover");
			},
			function(){ 
				$(this).removeClass("int-a-hover"); 
			}
			).mousedown(function(){
				$(this).addClass("ui-state-active"); 
			})
			.mouseup(function(){
					$(this).removeClass("ui-state-active");
			});
		$('#int-a-current').click(function()
			{
				if(interp_loggedin == "yes")
					{
						$('#int-tbody-dreamlist').empty();
						$('#int-text-listamount').empty();
						$('#int-text-comment').empty();
						$('#int-thead-currentdreamlist').hide();
						limit_cur = 0;
						limit_max = dreamlist_max;
						sortby = "";
						sortorder = "ASC";
						GetInterpretCurrentList();
					}
				else
					{
						UpdateInterpretText("notloggedin");	
					}
			})
		.hover(
			function(){ 
				$(this).addClass("int-a-hover");
			},
			function(){ 
				$(this).removeClass("int-a-hover"); 
			}
			).mousedown(function(){
				$(this).addClass("ui-state-active"); 
			})
			.mouseup(function(){
					$(this).removeClass("ui-state-active");
			});
		$('#int-a-passed').click(function()
			{
				if(interp_loggedin == "yes")
					{
						$('#int-tbody-dreamlist').empty();
						$('#int-text-listamount').empty();
						$('#int-text-comment').empty();
						$('#int-thead-passeddreamlist').hide();
						limit_cur = 0;
						limit_max = dreamlist_max;
						sortby = "";
						sortorder = "ASC";
						GetInterpretPassedList();
					}
				else
					{
						UpdateInterpretText("notloggedin");	
					}
			})
		.hover(
			function(){ 
				$(this).addClass("int-a-hover");
			},
			function(){ 
				$(this).removeClass("int-a-hover"); 
			}
			).mousedown(function(){
				$(this).addClass("ui-state-active"); 
			})
			.mouseup(function(){
					$(this).removeClass("ui-state-active");
			});
		$('#int-a-mydreams').click(function()
			{
				if(interp_loggedin == "yes")
					{
						$('#int-tbody-dreamlist').empty();
						$('#int-text-listamount').empty();
						$('#int-text-comment').empty();
						$('#int-thead-mydreamsdreamlist').hide();
						sortby = "";
						sortorder = "ASC";
						limit_cur = 0;
						limit_max = dreamlist_max;
						GetInterpretMyDreamsList();
					}
				else
					{
						UpdateInterpretText("notloggedin");	
					}
			})
		.hover(
			function(){ 
				$(this).addClass("int-a-hover");
			},
			function(){ 
				$(this).removeClass("int-a-hover"); 
			}
			).mousedown(function(){
				$(this).addClass("ui-state-active"); 
			})
			.mouseup(function(){
					$(this).removeClass("ui-state-active");
			});
		$('#int-a-stats').click(function()
			{
				if(interp_loggedin == "yes")
					{
						$('#int-tbody-dreamlist').empty();
						$('#int-text-listamount').empty();
						$('#int-text-comment').empty();
						$('#int-thead-statlist').hide();
						GetInterpretStatsList();
					}
				else
					{
						UpdateInterpretText("notloggedin");	
					}
			})
		.hover(
			function(){ 
				$(this).addClass("int-a-hover");
			},
			function(){ 
				$(this).removeClass("int-a-hover"); 
			}
			).mousedown(function(){
				$(this).addClass("ui-state-active"); 
			})
			.mouseup(function(){
					$(this).removeClass("ui-state-active");
			});
		$('#int-button-search').click(function()
			{
				window.location.hash = "search";
				thesearch = $('#searchbox-field').val();
				$('#int-tbody-dreamlist').empty();
				$('#int-text-listamount').empty();
				$('#int-text-comment').empty();
				$('#int-thead-searchdreamlist').hide();
				GetInterpretSearchList(thesearch);
			})
		.hover(
				function(){ 
					$(this).addClass("ui-state-hover");
				},
				function(){ 
					$(this).removeClass("ui-state-hover"); 
				}
			).mousedown(function(){
				$(this).addClass("ui-state-active"); 
			})
			.mouseup(function(){
					$(this).removeClass("ui-state-active");
			});
		$('#int-a-comments').click(function()
			{ 
				if(interp_loggedin == "yes")
					{
						$('#int-thead-commentdreamlist').hide();
						$('#int-tbody-dreamlist').empty();
						$('#int-text-listamount').empty();
						$('#int-text-comment').empty();
						GetInterpretCommentsList();
					}
				else
					{
						UpdateInterpretText("notloggedin");	
					}
			})
		.hover(
			function(){ 
				$(this).addClass("int-a-hover");
			},
			function(){ 
				$(this).removeClass("int-a-hover"); 
			}
			).mousedown(function(){
				$(this).addClass("ui-state-active"); 
			})
			.mouseup(function(){
					$(this).removeClass("ui-state-active");
			});
		$('#int-button-previous').click(function()
			{
				limit_cur = limit_cur - dreamlist_max;
				limit_max = limit_max - dreamlist_max;
				$('#int-thead-livedreamlist').hide();
				$('#int-thead-mandatorydreamlist').hide();
				$('#int-thead-currentdreamlist').hide();
				$('#int-thead-passeddreamlist').hide();
				$('#int-thead-mydreamsdreamlist').hide();
				$('#int-thead-searchdreamlist').hide();
				GetDreamList();
			})
		.hover(
				function(){ 
					$(this).addClass("ui-state-hover");
				},
				function(){ 
					$(this).removeClass("ui-state-hover"); 
				}
			).mousedown(function(){
				$(this).addClass("ui-state-active");  
			})
			.mouseup(function(){
					$(this).removeClass("ui-state-active");
			});
		$('#int-button-next').click(function()
			{
				limit_cur = limit_cur + dreamlist_max;
				limit_max = limit_max + dreamlist_max;
				$('#int-thead-livedreamlist').hide();
				$('#int-thead-mandatorydreamlist').hide();
				$('#int-thead-currentdreamlist').hide();
				$('#int-thead-passeddreamlist').hide();
				$('#int-thead-mydreamsdreamlist').hide();
				$('#int-thead-searchdreamlist').hide();
				GetDreamList();
			})
		.hover(
				function(){ 
					$(this).addClass("ui-state-hover");
				},
				function(){ 
					$(this).removeClass("ui-state-hover"); 
				}
			).mousedown(function(){
				$(this).addClass("ui-state-active"); 
			})
			.mouseup(function(){
					$(this).removeClass("ui-state-active");
			});
		$('.th-datesubmitted').click(function()
			{
				sortby = "submitted";
				if(sortorder == "ASC")
					{
						sortorder = "DESC";
					}
				else
					{
						sortorder = "ASC";	
					}
				GetDreamList();
			})
		.hover(
				function(){ 
					$(this).addClass("ui-state-hover");
				},
				function(){ 
					$(this).removeClass("ui-state-hover"); 
				}
			).mousedown(function(){
				$(this).addClass("ui-state-active"); 
			})
			.mouseup(function(){
					$(this).removeClass("ui-state-active");
			});
        $('.th-title').click(function()
			{
				sortby = "dream_title";
				if(sortorder == "ASC")
					{
						sortorder = "DESC";
					}
				else
					{
						sortorder = "ASC";	
					}
				GetDreamList();
			})
		.hover(
				function(){ 
					$(this).addClass("ui-state-hover");
				},
				function(){ 
					$(this).removeClass("ui-state-hover"); 
				}
			).mousedown(function(){
				$(this).addClass("ui-state-active"); 
			})
			.mouseup(function(){
					$(this).removeClass("ui-state-active");
			});									  
        $('.th-dreamer').click(function()
			{
				sortby = "dreamer";
				if(sortorder == "ASC")
					{
						sortorder = "DESC";
					}
				else
					{
						sortorder = "ASC";	
					}
				GetDreamList();
			})
		.hover(
				function(){ 
					$(this).addClass("ui-state-hover");
				},
				function(){ 
					$(this).removeClass("ui-state-hover"); 
				}
			).mousedown(function(){
				$(this).addClass("ui-state-active"); 
			})
			.mouseup(function(){
					$(this).removeClass("ui-state-active");
			});			
		$('.th-level').click(function()
			{
				sortby = "cert_type_used_for";
				if(sortorder == "ASC")
					{
						sortorder = "DESC";
					}
				else
					{
						sortorder = "ASC";	
					}
				GetDreamList();
			})
		.hover(
				function(){ 
					$(this).addClass("ui-state-hover");
				},
				function(){ 
					$(this).removeClass("ui-state-hover"); 
				}
			).mousedown(function(){
				$(this).addClass("ui-state-active"); 
			})
			.mouseup(function(){
					$(this).removeClass("ui-state-active");
			});			
		$('.th-dateentered').click(function()
			{
				sortby = "dream_date";
				if(sortorder == "ASC")
					{
						sortorder = "DESC";
					}
				else
					{
						sortorder = "ASC";	
					}
				GetDreamList();
			})
		.hover(
				function(){ 
					$(this).addClass("ui-state-hover");
				},
				function(){ 
					$(this).removeClass("ui-state-hover"); 
				}
			).mousedown(function(){
				$(this).addClass("ui-state-active"); 
			})
			.mouseup(function(){
					$(this).removeClass("ui-state-active");
			});	
	});
function IntPageLoad()
	{
		$('#int-a-comments').hide();
		if(interp_loggedin == "yes")
			{
				
				$('#searchbox').show();
				$('#int-button-previous').hide();
				$('#int-button-next').hide();
				GetDreamList();
				UpdateInterpretText("");
			}	
		else
			{
				
				$('#int-thead-livedreamlist').show();
				$('#int-thead-mandatorydreamlist').hide();
				$('#int-thead-currentdreamlist').hide();
				$('#int-thead-passeddreamlist').hide();
				$('#int-thead-mydreamsdreamlist').hide();
				$('#int-thead-searchdreamlist').hide();
				$('#int-thead-commentdreamlist').hide();
				$('#int-thead-statlist').hide();
				$('#searchbox').hide();
				$('#int-text-level').empty();
				$('#int-text-listamount').empty();
				$('#int-tbody-dreamlist').append('<tr><td colspan="7">'+"You must have an active recurring subscription in order to interpret dreams. <a href='http://www.stirthewater.com/members/signup.php'>Click Here </a>to subscribe."+'</td></tr>');
			}
	}
function GetInterpretLiveList() 
	{
		$('#int-thead-livedreamlist').show();
		$('#int-thead-mandatorydreamlist').hide();
		$('#int-thead-currentdreamlist').hide();
		$('#int-thead-passeddreamlist').hide();
		$('#int-thead-mydreamsdreamlist').hide();
		$('#int-thead-searchdreamlist').hide();
		$('#int-thead-commentdreamlist').hide();
		$('#int-thead-statlist').hide();
		$('#int-tbody-dreamlist').empty();
		$('#int-tbody-dreamlist').append(processingbar);
		$.post(intURL,
		{
			request:"interpretlive",
			sortby:sortby,
			sortorder:sortorder,
			limit_cur:limit_cur,
			limit_max:limit_max
		},
		function(res)
		{
			var livelist = $.json.deserialize(res); 
			var livelist_result = "";
			for(key in livelist)
				{
					//alert(livelist[key].date_submitted);
					livelist_result += '<tr>';
					livelist_result += '<td>' + livelist[key].date_submitted + '</td>';
					livelist_result += '<td>' + livelist[key].dream_title + '</td>';
					livelist_result += '<td>' + livelist[key].dreamer + '</td>';
					livelist_result += '<td>' + livelist[key].int_status + '</td>';
					livelist_result += '<td>' + livelist[key].int_action + '</td>';
					livelist_result += '<td>' + livelist[key].dream_credit + '</td>';
					livelist_result += '<td>' + livelist[key].dream_count + '</td>';
					livelist_result += '</tr>';
				}
				UpdateDreamListText("live","");
				$('#int-tbody-dreamlist').empty();
				$('#int-tbody-dreamlist').append(livelist_result);
				$('#int-tbody-dreamlist tr:odd').css("background-color", "#e1e7f3");
				$('#int-tbody-dreamlist tr:even').css("background-color", "#f3f6fa");
		});
	}
function GetInterpretMandatoryList()
	{
		$('#int-thead-livedreamlist').hide();
		$('#int-thead-mandatorydreamlist').show();
		$('#int-thead-currentdreamlist').hide();
		$('#int-thead-passeddreamlist').hide();
		$('#int-thead-mydreamsdreamlist').hide();
		$('#int-thead-searchdreamlist').hide();
		$('#int-thead-commentdreamlist').hide();
		$('#int-thead-statlist').hide();
		$('#int-tbody-dreamlist').empty();
		$('#int-tbody-dreamlist').append(processingbar);
		$.post(intURL,
		{
			request:"interpretmandatory",
			sortby:sortby,
			sortorder:sortorder,
			limit_cur:limit_cur,
			limit_max:limit_max
		},
		function(res)
		{
			var mandatorylist = $.json.deserialize(res); 
			var mandatorylist_result = "";
			
			for(key in mandatorylist)
				{
					//alert(mandatorylist[key].date_submitted);
					mandatorylist_result += '<tr>';
					mandatorylist_result += '<td>' + mandatorylist[key].dream_title + '</td>';
					mandatorylist_result += '<td>' + mandatorylist[key].int_status + '</td>';
					mandatorylist_result += '<td>' + mandatorylist[key].int_action + '</td>';
					mandatorylist_result += '<td>' + mandatorylist[key].mandatory_level + '</td>';
					mandatorylist_result += '</tr>';
				}
				UpdateDreamListText("mandatory","");
				$('#int-tbody-dreamlist').empty();
				$('#int-tbody-dreamlist').append(mandatorylist_result);
				$('#int-tbody-dreamlist tr:odd').css("background-color", "#e1e7f3");
				$('#int-tbody-dreamlist tr:even').css("background-color", "#f3f6fa");
		});
	}
function GetInterpretCurrentList()
	{
		$('#int-thead-livedreamlist').hide();
		$('#int-thead-mandatorydreamlist').hide();
		$('#int-thead-currentdreamlist').show();
		$('#int-thead-passeddreamlist').hide();
		$('#int-thead-mydreamsdreamlist').hide();
		$('#int-thead-searchdreamlist').hide();
		$('#int-thead-commentdreamlist').hide();
		$('#int-thead-statlist').hide();
		$('#int-tbody-dreamlist').empty();
		$('#int-tbody-dreamlist').append(processingbar);
		$.post(intURL,
		{
			request:"interpretcurrent",
			sortby:sortby,
			sortorder:sortorder,
			limit_cur:limit_cur,
			limit_max:limit_max
		},
		function(res)
		{
			var currentlist = $.json.deserialize(res); 
			var currentlist_result = "";
			
			for(key in currentlist)
				{
					//alert(currentlist[key].date_submitted);
					currentlist_result += '<tr>';
					currentlist_result += '<td>' + currentlist[key].date_submitted + '</td>';
					currentlist_result += '<td>' + currentlist[key].dream_title + '</td>';
					currentlist_result += '<td>' + currentlist[key].dreamer + '</td>';
					currentlist_result += '<td>' + currentlist[key].int_status + '</td>';
					currentlist_result += '<td>' + currentlist[key].int_action + '</td>';
					currentlist_result += '<td>' + currentlist[key].dream_credit + '</td>';
					currentlist_result += '<td>' + currentlist[key].dream_count + '</td>';
					currentlist_result += '</tr>';
				}
				UpdateDreamListText("current","");
				$('#int-tbody-dreamlist').empty();
				$('#int-tbody-dreamlist').append(currentlist_result);
				$('#int-tbody-dreamlist tr:odd').css("background-color", "#e1e7f3");
				$('#int-tbody-dreamlist tr:even').css("background-color", "#f3f6fa");
		});
	}
function GetInterpretPassedList()
	{
		$('#int-thead-livedreamlist').hide();
		$('#int-thead-mandatorydreamlist').hide();
		$('#int-thead-currentdreamlist').hide();
		$('#int-thead-passeddreamlist').show();
		$('#int-thead-mydreamsdreamlist').hide();
		$('#int-thead-searchdreamlist').hide();
		$('#int-thead-commentdreamlist').hide();
		$('#int-thead-statlist').hide();
		$('#int-tbody-dreamlist').empty();
		$('#int-tbody-dreamlist').append(processingbar);
		$.post(intURL,
		{
			request:"interpretpassed",
			sortby:sortby,
			sortorder:sortorder,
			limit_cur:limit_cur,
			limit_max:limit_max
		},
		function(res)
		{
			var passedlist = $.json.deserialize(res); 
			var passedlist_result = "";
			
			for(key in passedlist)
				{
					//alert(passedlist[key].date_submitted);
					passedlist_result += '<tr>';
					passedlist_result += '<td>' + passedlist[key].dream_title + '</td>';
					passedlist_result += '<td>' + passedlist[key].dreamer + '</td>';
					passedlist_result += '<td>' + passedlist[key].int_status + '</td>';
					passedlist_result += '<td>' + passedlist[key].int_action + '</td>';
					passedlist_result += '<td>' + passedlist[key].int_level + '</td>';
					passedlist_result += '</tr>';
				}
				UpdateDreamListText("passed","");
				$('#int-tbody-dreamlist').empty();
				$('#int-tbody-dreamlist').append(passedlist_result);
				$('#int-tbody-dreamlist tr:odd').css("background-color", "#e1e7f3");
				$('#int-tbody-dreamlist tr:even').css("background-color", "#f3f6fa");
		});
	}
function GetInterpretMyDreamsList()
	{
		$('#int-thead-livedreamlist').hide();
		$('#int-thead-mandatorydreamlist').hide();
		$('#int-thead-currentdreamlist').hide();
		$('#int-thead-passeddreamlist').hide();
		$('#int-thead-mydreamsdreamlist').show();
		$('#int-thead-searchdreamlist').hide();
		$('#int-thead-commentdreamlist').hide();
		$('#int-thead-statlist').hide();
		$('#int-tbody-dreamlist').empty();
		$('#int-tbody-dreamlist').append(processingbar);
		$.post(intURL,
		{
			request:"interpretmydreams",
			sortby:sortby,
			sortorder:sortorder,
			limit_cur:limit_cur,
			limit_max:limit_max
		},
		function(res)
		{
			var mydreamslist = $.json.deserialize(res); 
			var mydreamslist_result = "";
			
			for(key in mydreamslist)
				{
					//alert(mydreamslist[key].date_submitted);
					mydreamslist_result += '<tr>';
					mydreamslist_result += '<td>' + mydreamslist[key].dream_date + '</td>';
					mydreamslist_result += '<td>' + mydreamslist[key].dream_title + '</td>';
					mydreamslist_result += '<td>' + mydreamslist[key].dreamer + '</td>';
					mydreamslist_result += '<td>' + mydreamslist[key].int_action + '</td>';
					mydreamslist_result += '</tr>';
				}
				UpdateDreamListText("mydreams","");
				$('#int-tbody-dreamlist').empty();
				$('#int-tbody-dreamlist').append(mydreamslist_result);
				$('#int-tbody-dreamlist tr:odd').css("background-color", "#e1e7f3");
				$('#int-tbody-dreamlist tr:even').css("background-color", "#f3f6fa");
		});
	}
function GetInterpretSearchList(thesearch)
	{
		$('#int-thead-livedreamlist').hide();
		$('#int-thead-mandatorydreamlist').hide();
		$('#int-thead-currentdreamlist').hide();
		$('#int-thead-passeddreamlist').hide();
		$('#int-thead-mydreamsdreamlist').hide();
		$('#int-thead-searchdreamlist').show();
		$('#int-thead-commentdreamlist').hide();
		$('#int-thead-statlist').hide();
		$('#int-tbody-dreamlist').empty();
		$('#int-tbody-dreamlist').append(processingbar);
		from_interp = true;
		$.post(intURL,
			{
				request:"interpretsearch", 
				thesearch:thesearch
			},
		function(res)
			{
				//alert(res);
				var searchlist = $.json.deserialize(res);
				var searchlist_result = "";
				var search_total = 0;
				var searchword = thesearch;
				//alert(res);
				for(key in searchlist)
				{
					searchlist_result += '<tr>';
					searchlist_result += '<td>' + searchlist[key].grouping + '</td>';
					searchlist_result += '<td>' + searchlist[key].dream_title + '</td>';
					searchlist_result += '<td>' + searchlist[key].dreamer + '</td>';
					searchlist_result += '<td>' + searchlist[key].int_status + '</td>';
					searchlist_result += '<td>' + searchlist[key].int_action + '</td>';
					//searchlist_result += '<td>' + searchlist[key].dream_credit + '</td>';
					//searchlist_result += '<td>' + searchlist[key].dream_count + '</td>';
					search_total += searchlist[key].total_rows;
					searchword = searchlist[key].searchword;
					searchlist_result += '</tr>';
				}
				UpdateDreamListText("search",searchword,search_total);
				$('#searchbox-field').val("");
				$('#int-tbody-dreamlist').empty();
				$('#int-tbody-dreamlist').append(searchlist_result);
				$('#int-tbody-dreamlist tr:odd').css("background-color", "#e1e7f3");
				$('#int-tbody-dreamlist tr:even').css("background-color", "#f3f6fa");
			});
	} 
function GetInterpretCommentsList()
	{
		$('#int-thead-livedreamlist').hide();
		$('#int-thead-mandatorydreamlist').hide();
		$('#int-thead-currentdreamlist').hide();
		$('#int-thead-passeddreamlist').hide();
		$('#int-thead-mydreamsdreamlist').hide();
		$('#int-thead-searchdreamlist').hide();
		$('#int-thead-commentdreamlist').show();
		$('#int-thead-statlist').hide();
		$('#int-tbody-dreamlist').empty();
		$('#int-tbody-dreamlist').append(processingbar);
		$.post(intURL,
			{
				request:"getcomments"
			},
		function(res)
			{
					var comment = $.json.deserialize(res);
					var commentlist_result = "";
					for(key in comment)
						{
							commentlist_result += '<tr>';
							commentlist_result += '<td>' + comment[key].dream_date + '</td>';
							commentlist_result += '<td>' + comment[key].dream_title + '</td>';
							commentlist_result += '<td>' + comment[key].int_status + '</td>';
							commentlist_result += '<td>' + comment[key].int_action + '</td>';
							commentlist_result += '</tr>';
						}
					
					UpdateDreamListText("comments","","");
					$('#int-tbody-dreamlist').empty();
					if(commentlist_result != "")
						{
							$('#int-tbody-dreamlist').append(commentlist_result);
							$('#int-tbody-dreamlist tr:odd').css("background-color", "#e1e7f3");
							$('#int-tbody-dreamlist tr:even').css("background-color", "#f3f6fa");
						}
			});
	}
function GetInterpretStatsList()
	{
		$('#int-thead-livedreamlist').hide();
		$('#int-thead-mandatorydreamlist').hide();
		$('#int-thead-currentdreamlist').hide();
		$('#int-thead-passeddreamlist').hide();
		$('#int-thead-mydreamsdreamlist').hide();
		$('#int-thead-searchdreamlist').hide();
		$('#int-thead-commentdreamlist').hide();
		$('#int-thead-statlist').show();
		$('#int-tbody-dreamlist').empty();
		$('#int-tbody-dreamlist').append(processingbar);
		$.post(intURL,
			{
				request:"getstats"
			},
		function(res)
			{
					var stats = $.json.deserialize(res);
					var statslist_result = "";
					for(key in stats)
						{
							statslist_result += '<tr>';
							statslist_result += '<td>' + stats[key].level_accuracy + '</td>';
							statslist_result += '<td>' + stats[key].overall_accuracy + '</td>';
							if(stats[key].firsttime_accuracy != null)
								{
									statslist_result += '<td>' + stats[key].firsttime_accuracy + '</td>';
								}
							statslist_result += '<td>' + stats[key].dreamer_rating + '</td>';
							statslist_result += '</tr>';
						}
					
					UpdateDreamListText("stats","","");
					$('#int-tbody-dreamlist').empty();
					if(statslist_result != "")
						{
							$('#int-tbody-dreamlist').append(statslist_result);
							$('#int-tbody-dreamlist tr:odd').css("background-color", "#e1e7f3");
							$('#int-tbody-dreamlist tr:even').css("background-color", "#f3f6fa");
						}
			});
	}
function UpdateInterpretText(hash) 
	{
		//alert(hash);
		$('#int-text-level').empty();
		$.post(intURL, 
			{
				request:"updateinterpleveltext",
				hash:hash
			},
		function(res)
		{
			var textform = $.json.deserialize(res);
			var text_result = "";
			
			for(key in textform)
				{
					text_result += textform[key].inttext;
				}
			$('#int-text-level').append(text_result).effect("highlight",{},3000);
		});
	}
function UpdateDreamListText(hash,thesearch,searchtotal)
	{
		$('#int-text-listamount').empty();
		$('#int-text-comment').empty();
		$('#int-button-next').hide();
		$('#int-button-previous').hide();
		$('#int-a-comments').hide();
		$.post(intURL, 
			{
				request:"updatedreamlisttext",
				hash:hash,
				thesearch:thesearch,
				search_total:searchtotal
			},
		function(res)
		{
			var textform = $.json.deserialize(res);
			var text_result = "";
			var dream_count = "";
			var comment = "";
			for(key in textform)
				{
					text_result += textform[key].dreamtext;
					dream_count += textform[key].dreamcount;
					comment += textform[key].iscomment;
				}
			$('#int-text-listamount').append('<br />' + text_result).effect("highlight",{},3000);
			if(hash != "search" && interp_loggedin == "yes")
				{
					if(dream_count > limit_max)
						{
							$('#int-button-next').show();
						}
					if(limit_cur > 0)
						{
							$('#int-button-previous').show();
						}
				}
			if(comment != "")
				{
					$('#int-a-comments').show();
					if(hash != "comments")
						{
							$('#int-text-comment').append('<br />'+comment).effect("highlight",{},3000);
						}
				}
		});
	}
function GetDreamList()
	{
		//TT 2009.07.13
			//LIMITS: if on interpret.php page and type in link OR click on link w/in favorites, info will not reload
		var DreamListHash = window.location.hash;
		if(DreamListHash == "#live" || DreamListHash == "")
			{
				rowspan = 7;
				getDefaultInterpTab();
			}
		else if(DreamListHash == "#mandatory")
			{
				rowspan = 4;
				GetInterpretMandatoryList();
			}
		else if(DreamListHash == "#current")
			{
				rowspan = 7;
				GetInterpretCurrentList();
			}
		else if(DreamListHash == "#passed")
			{
				rowspan = 5;
				GetInterpretPassedList();
			}
		else if(DreamListHash == "#mydreams")
			{
				rowspan = 4;
				GetInterpretMyDreamsList();
			}
		else if(DreamListHash == "#search")
			{
				rowspan = 7;
				GetInterpretSearchList(thesearch);
			}
		else if(DreamListHash == "#stats")
			{
				rowspan = 4;
				GetInterpretStatsList();
			}
		else if(DreamListHash == "#comments")
			{
				rowspan = 7;
				GetInterpretCommentsList();
			}
	}
function CommentReply(dream_id)
	{
		$('#c-dreamtitle').empty();
		$('#c-comment-info').empty();
		$('#c-comment-replytext').val("");
		$.post(intURL,
			{
				request:"commentreply",
				dream_id:dream_id
			},
		function(res)
			{
				var commentreply = $.json.deserialize(res);
				var commentreply_dreamtitle = "";
				var commentreply_info = "";
				var dream_id = "";
				for(key in commentreply)
					{
						commentreply_dreamtitle = commentreply[key].dream_title;
						commentreply_info += '<span>' + commentreply[key].question_timestamp + " " + commentreply[key].commentor + '</span><br />';
						commentreply_info += '<span>' + commentreply[key].question_text + '</span><br /><br />';
						dream_id = commentreply[key].dream_id;
					}
				if(commentreply_dreamtitle == "")
					{
						updateTips("There are no open comments at this time",$('#tips-comment-reply'));
					}
				else
					{
						$('#c-dreamtitle').append(commentreply_dreamtitle);
						$('#c-comment-info').append(commentreply_info);
						dreamid = dream_id;
					}
				$('#dialog-comment-reply').dialog('open');
			});
	}
function SendCommentReply(dreamid,comment_newreply)
	{
		$.post(intURL,
			{
				request:"sendcommentreply",
				dream_id:dreamid,
				comment_newreply:comment_newreply
			},
		function(res)
			{
				var commentsent = $.json.deserialize(res);
				var commentsent_result = "";
				for(key in commentsent)
					{
						commentsent_result = commentsent[key].replysent;
					}
				if(commentsent_result == "yes")
					{
						updateTips("Your comment was successfully sent",$('#tips-int-success'));
						$('#dialog-int-success').dialog('open');
						$('#dialog-comment-reply').dialog('close');
						GetInterpretCommentsList();
					}
				else
					{
						updateTips("There was a problem submitting your comment. Please try again",$('#tips-int-error'));
						$('#dialog-int-error').dialog('open');
						$('#int-thead-commentdreamlist').hide();
						$('#int-tbody-dreamlist').empty();
						$('#int-text-listamount').empty();
						$('#int-text-comment').empty();
						GetInterpretCommentsList();
					}
			});
	}
function getDream(dream_id, member_id)
	{
		$('#dream_content').hide();
		$('#viewdream-process').show();
		$('#dialog-viewdream').dialog('open');
		
		$('#dream_name').empty();
		$('#dream_text').empty();
		$('#dream_date').empty();
		//alert(request + param1 + param2 + param3 + param4 + param5 + param6 + eid + login)
		$.post('includes/content/interpret/interpret_server.php', 
			{
				request:"view_dream",
				dream_id:dream_id,
				member_id:member_id
				
			},
		function(xml)
			{
				$(xml).find('dream').each(function()
					{
						var dream_name = $("dream_name",this).text();
						var dream_text = $("dream_text",this).text();
						var dream_date = $("dream_date",this).text();
						
						$('#dream_name').append(dream_name);
						$('#dream_text').append(dream_text);
						$('#dream_date').append(dream_date);
						
						
						$('#viewdream-process').hide();
						$('#dream_content').show();
					});
			});
	}
function getDefaultInterpTab()
	{
		$.post(intURL,
			{
				request:"getinterplevel"
			},
		function(res)
			{
				var info = $.json.deserialize(res);
				var inforesult = "";
				
				for(key in info)
					{
						inforesult = info[key].intlevel;	
					}
				if(inforesult < 6)
					{
						window.location = "#mandatory";
						rowspan = 4;
						GetInterpretMandatoryList();	
					}
				else
					{
						GetInterpretLiveList();
					}
			});
	}
