<!--
$(function() {


	function ShowBox(sBoxID)
	{
		var aOptions = {};
		$(sBoxID).show("blind",aOptions,500);
	        $(sBoxID).toggleClass("ItemShow").toggleClass("ItemHide");
	}


	function HideBox(sBoxID)
	{
		var aOptions = {};
		$(sBoxID).hide("blind",aOptions,500);
	        $(sBoxID).toggleClass("ItemShow").toggleClass("ItemHide");
	}

	function ToggleBox(sBoxID, sButtonID)
	{
		var aOptions = {};
		$(sBoxID).toggle("blind",aOptions,500);
	        $(sBoxID).toggleClass("ItemShow").toggleClass("ItemHide");
	        $(sButtonID).toggleClass("ButtonShow").toggleClass("ButtonHide");
	}

	function ToggleBoxLrg(sBoxID, sButtonID)
	{
		var aOptions = {};
		$(sBoxID).toggle("blind",aOptions,500);
	        $(sBoxID).toggleClass("ItemShow").toggleClass("ItemHide");
	        $(sButtonID).toggleClass("LrgButtonShow").toggleClass("LrgButtonHide");
	}

        function ToggleCommentOrder()
        {
                 $.get("AjaxFunctions.php", {Act: "ToggleCommentsOrder" });
                 return false;
        }

	function RefreshComments(sID)
	{
		$.get("AjaxFunctions.php", {Act: "RefreshComments", BlogID: sID }, function(xml)
			{
				$("Comments",xml).each(function(i)
				{
	  				var sComments = $(this).find('CommentsText').text();
					$('#CommContainer').html(sComments);
	  				var sCommentCount = $(this).find('CommentCount').text();
	  				if (sCommentCount != '0')
	  				{
						$('#Comments').html(sCommentCount + ' Comments');
						$('#CommentCount').val(sCommentCount);
						$('#refreshComments').html("Refresh Comments");
					}
	  				var sFirstComment = $(this).find('FirstComment').text();
					$('#changeOrder').html(sFirstComment);
					$('#changeCommentOrder').html(sFirstComment);
				});
				AddTZOffset();
			},"xml"
		);
	}

	function GetCommentCount()
	{
		var sID = document.getElementById("BlogID").value;
		$.get("AjaxFunctions.php", {Act: "GetCommentCount", BlogID: sID }, function(xml)
			{
				$("Comments",xml).each(function(i)
				{
	  				var nCommentCount = $(this).find('CommentCount').text();
					// Get current count from list
					var nLastUpdateCount = $('#CommentCount').val();

					// If different, update link
					if(nCommentCount > nLastUpdateCount)
					{
						$('#refreshComments').text("Refresh Comments (" + (nCommentCount - nLastUpdateCount) + " new)");
						$('#Comments').html(nCommentCount + ' Comments');
					}
				});
			},"xml"
		);
	}

	$("#showlogin").click(function() {
		ToggleBox("#loginbox", "#showlogin");
		return false;
	});

	$("#showaboutus").click(function() {
		ToggleBox("#aboutusbox");
		return false;
	});

    	$("#showaboutus").hover(function () {
    		$(this).addClass("hilite"); }, function () {$(this).removeClass("hilite");
    	});

	$("#LatestMenu").click(function() {
		window.location.href = "Blog.php?Act=Latest";
	});

    	$("#LatestMenu").hover(function () {
    		$(this).addClass("hilite"); }, function () {$(this).removeClass("hilite");
    		$(this).addClass("SetPointer"); }, function () {$(this).removeClass("SetPointer");
    	});


	$("#showSearch").click(function() {
		ToggleBox("#searchbox", "#showSearch");
		return false;
	});

	$("#showEditButtons").click(function() {
		ToggleBox("#EditPane", "#showEditButtons");
		$.post("AjaxFunctions.php", {Act: "JQSetValue", ValName: "ShowEdit" } );
		return false;
	});

	$("#showEmoticons").click(function() {
		ToggleBox("#EmoticonPane", "#showEmoticons");
		$.post("AjaxFunctions.php", {Act: "JQSetValue", ValName: "ShowEmoticons" } );
		return false;
	});

	$("#showUserEmoticons").click(function() {
		ToggleBox("#UserEmoticonPane", "#showUserEmoticons");
		return false;
	});

	$("#showAudicons").click(function() {
		ToggleBox("#AudiconPane", "#showAudicons");
		$.post("AjaxFunctions.php", {Act: "JQSetValue", ValName: "ShowAudicons" } );
		return false;
	});

	$("#showBlog").click(function() {
		ToggleBox("#BlogPane", "#showBlog");
		return false;
	});

	$("#showLatest").click(function() {
		ToggleBox("#LatestPane", "#showLatest");
		$.post("AjaxFunctions.php", {Act: "JQSetValue", ValName: "LastestMenu" } );
		return false;
	});

	$("#showActions").click(function() {
		ToggleBox("#ActionsPane", "#showActions");
		$.post("AjaxFunctions.php", {Act: "JQSetValue", ValName: "ActionItems" } );
		return false;
	});

	$("#showBlogRoll").click(function() {
		ToggleBox("#BlogRollPane", "#showBlogRoll");
		$.post("AjaxFunctions.php", {Act: "JQSetValue", ValName: "BlogRoll" } );
		return false;
	});

	$("#showLinks").click(function() {
		ToggleBox("#LinksPane", "#showLinks");
		$.post("AjaxFunctions.php", {Act: "JQSetValue", ValName: "OtherLinks" } );
		return false;
	});

	$("#showShareThis").click(function() {
		ToggleBox("#SharePane", "#showShareThis");
		return false;
	});

	$("#showBlogPost").click(function() {
		ToggleBoxLrg("#BlogPostPane", "#showBlogPost");
		$.post("AjaxFunctions.php", {Act: "JQSetValue", ValName: "Hide" } );
		return false;
	});

	var bLoginVisible = false;

	$("#dialog-form-opts").dialog({
		autoOpen: false,
		resizable: false,
		show: 'slide',
		height: 640,
		width: 380,
		modal: true,
		dialogClass: 'QuoteBox'
	});

	$("#dialog-form-cgpw").dialog({
		autoOpen: false,
		resizable: false,
		show: 'slide',
		height: 400,
		width: 400,
		modal: true,
		dialogClass: 'QuoteBox'
	});

	$("#dialog-form-delcom").dialog({
		autoOpen: false,
		resizable: false,
		show: 'slide',
		height: 400,
		width: 800,
		modal: true,
		dialogClass: 'QuoteBox'
		});

	$('#ChgUserOpts').click(function() {
		document.body.style.cursor="wait";
		$.get("AjaxFunctions.php", {Act: "GetUserOptions"}, function(xml)
			{
				$("DialogContent",xml).each(function(i)
				{
	  				var sContent = $(this).find('DialogHTML').text();
					$("#dialog-form-opts").html(sContent);
					document.body.style.cursor="default";
					$('#dialog-form-opts').dialog( "moveToTop" );
					$('#dialog-form-opts').dialog('open');
				});
			},"xml"
		);
		document.body.style.cursor="default";
	});

    	$("#ChgUserOpts").hover(function () {
    		$(this).addClass("hilite"); }, function () {$(this).removeClass("hilite");
    	});


	$('#ChgPswd').click(function() {
		document.body.style.cursor="wait";
		$.get("AjaxFunctions.php", {Act: "GetChgPswd"}, function(xml)
			{
				$("DialogContent",xml).each(function(i)
				{
	  				var sContent = $(this).find('DialogHTML').text();
					$("#dialog-form-cgpw").html(sContent);
					document.body.style.cursor="default";
					$('#dialog-form-cgpw').dialog( "moveToTop" );
					$('#dialog-form-cgpw').dialog('open');
				});
			},"xml"
		);
		document.body.style.cursor="default";
	});

    	$("#ChgPswd").hover(function () {
    		$(this).addClass("hilite"); }, function () {$(this).removeClass("hilite");
    	});

	$("#PopCancelOpts").live('click', function() {
		$("#dialog-form-opts").dialog('close');
	});

	$("#PopCancelCgpw").live('click', function() {
		$("#dialog-form-cgpw").dialog('close');
	});

	$("#PopSubmitOpts").live('click',function() {
		$.get("AjaxFunctions.php", $("form#UserOptsForm").serialize(), function(data) { alert("Result: " + data) });
		$("#dialog-form-opts").dialog('close');
	});

	$("#PopSaveCgpw").live('click',function() {
		$.get("AjaxFunctions.php", $("form#ChgPswd").serialize(), function(data) { alert("Result: " + data) });
		$("#dialog-form-cgpw").dialog('close');
	});

	$('.QuoteButton').live('click',function(evt)
	{
		if (evt.button != 0)
		{
			// wasn't the left button - ignore
			return true;
		}

		var oButton = $(this);
		var oParentDIV = oButton.parent('.BlogComment');
		var sID = oParentDIV.attr("id")

		document.body.style.cursor="wait";
		$.get("AjaxFunctions.php", {Act: "QuoteComment", CommentID: sID, FormatComment: "0" }, function(xml)
			{
				$("Comment",xml).each(function(i)
				{
	  				var sComment = $(this).find('CommentText').text();
					$('#MainEdit').val(sComment);
					document.body.style.cursor="default";
					$('#MainEdit').focus();
				});
			},"xml"
		);
		document.body.style.cursor="default";
	});

	$('.CommentDel').live('click',function(evt)
	{
		if (evt.button != 0)
		{
			// wasn't the left button - ignore
			return true;
		}

		var oButton = $(this);
		var oParentDIV = oButton.parent('.BlogComment');
		var sID = oParentDIV.attr("id")

		document.body.style.cursor="wait";
		$.get("AjaxFunctions.php", {Act: "QuoteComment", FormatComment: "1", CommentID: sID }, function(xml)
			{
				$("Comment",xml).each(function(i)
				{
	  				var sComment = $(this).find('CommentText').text();
					sComment = sComment + "<br><br>" + "Are you sure you want to delete this comment?";
					$("#dialog-form-delcom").html(sComment);
					$("#dialog-form-delcom").dialog( "option", "buttons", {});
					$("#dialog-form-delcom").dialog( "option", "buttons", { "Yes": function() {
						$.get("AjaxFunctions.php", {Act: "DeleteComment", CommentID: sID }, function(data) {
							if(data.substr(0,3) == 'Err')
								alert(data);
							else
								RefreshComments(data);
						$("#dialog-form-delcom").dialog('close');
						} );
					      	}, "No": function() {$("#dialog-form-delcom").dialog('close');} }
					);
					document.body.style.cursor="default";
					$("#dialog-form-delcom").dialog('moveToTop');
					$("#dialog-form-delcom").dialog('open');
				});
			},"xml"
		);

		document.body.style.cursor="default";
	});

	$("#AddComment").live('click', function(evt)
	{
		if (evt.button != 0)
		{
			// wasn't the left button - ignore
			return true;
		}

		var oButton = $(this);
		  var oParentDIV = oButton.parents('.CommentEditArea');
		  var sID = oParentDIV.attr("id");

		document.body.style.cursor="wait";
		$.post("AjaxFunctions.php", $("form#EditArea").serialize(), function(data) {
			data = jQuery.trim(data);
			if(data != '')
			{
				document.body.style.cursor="default";
				alert(data);
			}
			else
				$("#MainEdit").val("");
			RefreshComments(sID);
			});
		document.body.style.cursor="default";
	});

	$("#refreshComments").click(function() {
		  var oLink = $(this);
		  var oParentDIV = oLink.parent('.FirstComment');
		  var sID = oParentDIV.attr("id");
		document.body.style.cursor="wait";
  		  RefreshComments(sID);
		document.body.style.cursor="default";
	});

	$("#changeCommentOrder").click(function() {
		  var oLink = $(this);
		  var oParentDIV = oLink.parent('.FirstComment');
		  var sID = oParentDIV.attr("id");
		document.body.style.cursor="wait";
  		  ToggleCommentOrder();
  		  RefreshComments(sID);
		document.body.style.cursor="default";
	});

	$("#DateField").ready(function() { AddTZOffset(); });

	$("#TZOffset").ready(function() { SetBlogTZOffset(); });

	$("#DateField").live('load', function() { AddTZOffset(); });

	$("#DisplayDate").live('load', function() { AddTZOffset(); });

	$('#RestoreFromCache').click(function(data) {
		$.get("AjaxFunctions.php", {Act: "GetTempBlogEntry"}, function(xml)
			{
				$("BlogEntry",xml).each(function(i)
				{
	  				var sText = $(this).find('BlogText').text();
					$('#MainEdit').html(sText);
					$('#MainEdit').focus();
				});
			},"xml");
	});

 	$(document).ready(function() {
		var refreshId = setInterval(function() {
			var sTempBlog = $('#MainEdit').html();
			if(sTempBlog != '')
			$.get("AjaxFunctions.php", {Act: "SetTempBlogEntry", TempBlog: sTempBlog} );
		}, 9000);
		setInterval(function() {GetCommentCount();}, 30000);
	});

});
//-->

