$(document).ready(function() {

	flagLinks();

});

var data;
var strBasePath;

function flagLinks()
	{
	$(".ajaxable").live("click", function () {
		AjaxLoad();
			
		return false;
	})		
	}


function AjaxLoad(str)
	{

	$("#txtBody").val(commentEditor.getEditorHTML());


	if (!Validate())
		return;

	
	strBasePath = window.location.href;
	if (strBasePath.indexOf('?') != -1)
    	strBasePath = strBasePath.substring(0, strBasePath.indexOf('?'));
		
	if (strBasePath.indexOf('#') != -1)
    	strBasePath = strBasePath.substring(0, strBasePath.indexOf('#'));	
		
	var position = $(".ajaxForm").position();
	var height = $(".ajaxForm").height();	
	var width = $(".ajaxForm").width();		
	$(".ajaxForm").prepend("<p class=\"overlay\"></p>")
	$(".overlay").css("opacity", 0.3).css("position", "absolute").css("top", position.top).css("left", position.left).css("height", height).css("width", width).css("background-color", "Gray");
	$(".ajaxForm").prepend("<h3 id=\"loadimage\" class=\"ajax-loading-icon-heading\"><span class=\"ajax-loading-icon\">&nbsp;</span><span class=\"ajax-loading-text\">Loading.</span></h3>")
	var imageWidth = $("#loadimage").width();
	$("#loadimage").css("position", "absolute").css("z-index", 100001);
	var data = $(".ajaxForm").serialize();
	$.post("/dynamic_content/processForm.php", data, LoadResponse);
	}

function LoadResponse(str)
	{
	if (str.search(/FAIL!/) != -1)
		{
		$("#loadimage").remove();
		$(".overlay").remove();
		$("#captchaError").fadeIn("slow");
		}
	else if (str.search(/There was a problem/) != -1)
		{
		$("#loadimage").remove();
		$(".overlay").remove();
		$(".errorBox").html("<h4><span>&nbsp;</span></h4>" + str);
		$(".errorBox").show();
		}
	else
		{
		$(".ajaxForm").html(str);
		}
	}
