

   $(document).ready( function(){
		
		$(":input").focus(function () { 
			$(this).parent().parent().not(".failed-validation").find(".help-column").css("color","#666");
			$(this).parent().parent().not(".failed-validation").animate({"backgroundColor": "#DDDDE7"}, 200);
		});
		
		$(":input").blur(function () { 
			$(this).parent().parent().not(".failed-validation").find(".help-column").css("color","#F6F6F6");
			$(this).parent().parent().not(".failed-validation").animate({"backgroundColor": "#F6F6F6"}, 400);
	   });
		
		$(".validate-me").blur(function () { 
			if ( $(this).attr("type") == "checkbox")
			{	if ( $(this).attr("checked") != false ) { $(this).parent().parent().removeClass("failed-validation"); } }
			else
			{	if ( $(this).val() != "" ) { $(this).parent().parent().removeClass("failed-validation"); } }
	   });
	});


// ================================================================================================================== //
	
	function validateForm()
	{
		var _ElementCounter = 0;
		var _FirstFailElement = "";

		// remove all falied validation classes
		$(".failed-validation").removeClass("failed-validation");

		// check for any validation classes 
		$(".validate-me").each(function(i){
			
			// checkboxes to be validated ( .val() returns "on" if null ? )
			if ( $(this).attr("type") == "checkbox" )
			{
				if ( $(this).attr("checked") == false )
				{
					$(this).parent().parent().addClass("failed-validation");
					
					if ( _ElementCounter == 0 ) { _FirstFailElement = $(this); }
					
					_ElementCounter++;
				}
			}
			// text boxes, textareas, and select boxes to be validated
			else
			{
				if ( $(this).val() == "" )
				{
					$(this).parent().parent().addClass("failed-validation");
					
					if ( _ElementCounter == 0 ) { _FirstFailElement = $(this); }
					
					_ElementCounter++;
				}
			}
			
 		});
		
		if ( _ElementCounter > 0 )
		{
			$(_FirstFailElement).focus();
			$("#dialog").html("<i style='color:#C44; font-weight:bold;'>We're sorry, but you are missing " + _ElementCounter + " pieces of information that we require to submit this form.<br><br>The information you have not supplied is highlighted in red and needs to be entered before you can resubmit this form.<br><br>Thank you</i>");
       	 	$("#dialog").dialog({ modal: true, overlay: { opacity: 0.7, background: "black" } });
			return false;
		}
		else
		{
			return true;
		}
		
	}
	
// ================================================================================================================== //

	// Global variable counter
	var _Counter = 2;

	// Add another textarea to the form
	function AddAnotherTD()
	{
		textAreaSnippet = "<tr><td class='left-column' valign='top'><label for='Disc" + _Counter + "'>Tracks On Disc " + _Counter + "</label></td><td class='right-column'><textarea id='Disc" + _Counter + "' name='Disc" + _Counter + "' cols='60' rows=10'></textarea><span class='help-column'>Please enter your disc's track names (required)</span></td></tr>"
									
		$("#AddAnotherTD").parent().parent().parent().parent().parent().parent().before(textAreaSnippet);
		$("#HiddenLink").css("display","inline");
		$("#RemovePriorTD").text("- Remove Disc " + _Counter);
		
		$("#Disc" + _Counter).focus();

		_Counter++;
		
		$("#DiscCount").val(_Counter-1);
		
		return false;
	}		
		
	// Remove the preceding textarea from the form
	function RemovePriorTD()
	{
		_Counter--;
		var tempCounter = _Counter-1;		
		$("#Disc" + _Counter).parent().parent().remove();
		
		if ( _Counter == 2 )
		{
			$("#HiddenLink").css("display","none");
		}
		else
		{
			$("#RemovePriorTD").text("- Remove Disc " + tempCounter);
		}

		$("#Disc" + tempCounter).focus();

		$("#DiscCount").val(_Counter-1);

		return false;
	}		
