$(function(){

// Runs in 0.054ms in Firefox 4.

	/// Begin gravedig caution.
	
	// "YYYY-MM-DD HH:MM:SS" = $("#latestReplyPosted").text().
	
	// Turns string "YYYY-MM-DD HH:MM:SS" into array ["YYYY","MM","DD"].
	var YMD = ( $("#latestReplyPosted").text().split(" ") )[0].split("-");
	
	var latestReplyPosted = new Date(YMD[0],YMD[1],YMD[2]);
	var today = new Date();
	
	
	// Days since last post = Math.round((today - latestReplyPosted)/86400000).

	if ( Math.round((today - latestReplyPosted)/86400000) >= 14) {

		var postMessageForm = $("form[action^='post.php']");
		
		// Turn reply field's background red when entering text.
		$("textarea[name='req_message']",postMessageForm)
        .focus(function(){
            $(this).css("backgroundColor","#900");
        })
        .blur(function(){
            $(this).css("backgroundColor","");
        });
		
		var submitButton = $("input[name='submit']",postMessageForm);
		
		submitButton.attr("value","Reply with Gravedig");
		/*submitButton.after("<input type='reset' value='Cancel' />");*/
		
		//Parent paragraph.
		submitButton.closest('p').prepend(
			'<strong>Caution</strong><br/>This thread has been inactive for more than two weeks,\
			 and is considered dead. Replying is called, "gravedigging."\
			 Only reply if you are reviving the thread with new content.<br/><br/>\
			 <span style="color:#f00;font-weight:bold">Gravedigging with a simple reply will result in a warning.</span>\
			 <br/><br/>');
		 
		 return;
	}
	/// End gravedig caution.
		 
	/// Begin double post caution. 
	var latestReplyUsername = $("#latestReplyUsername").text();
	var myUsername = $("#brdwelcome strong:first").text();
	
	if (latestReplyUsername == myUsername) {
		var latestReplyId = $("#latestReplyId").text();
		var postMessageForm = $("form[action^='post.php']");
		
		// Turn reply field's background red when entering text.
		$("textarea[name='req_message']",postMessageForm)
        .focus(function(){
            $(this).css("backgroundColor","#900");
        })
        .blur(function(){
            $(this).css("backgroundColor","");
        });
		
		var submitButton = $("input[name='submit']");
		
		submitButton.attr("value","Reply with Double Post");
		/*submitButton.after("<input type='reset' value='Cancel' />");*/
		
		//Parent paragraph.
		submitButton.closest('p').prepend(
			'<strong>Caution</strong><br/>You already have the latest reply to this thread. Instead of double-posting, please <a href="/edit.php?id='+latestReplyId+'">add the message onto your current reply.</a><br/>'+
			 '<span style="color:#f00;font-weight:bold">Double posting is against the rules and will likely result in a warning.</span><br/><br/>');
		 
		 return;
	}
	/// End double post caution. 
});
