$(document).ready(function()
{
	$('#comment_form').form_validation(
	{
		before_validation: function()
		{
			/* clear data if the default value is the current value */
			$('.form_field').each(function()
			{
				($(this).val() == $(this).data('default_value') ? $(this).val('') : $(this).val($(this).val()));
			});
		},
		error: function()
		{
			/* populate default values is empty and form validation failed */
			$('.form_field').each(function()
			{
				($(this).val() == '' ? $(this).val($(this).data('default_value')) : $(this).val($(this).val()));
			});

		}
	});
	
	/* store default values for form fields*/
	$('.form_field').each(function()
	{
		$(this).data('default_value', $(this).val());
	});
	
	/* clear/populate default value of focus/blur */
	$('.form_field').focus(function()
	{
		($(this).val() == $(this).data('default_value') ? $(this).val('') : $(this).val($(this).val()));
		check_form_value($(this).attr('id'));
	}).blur(function()
	{
		($(this).val() == '' ? $(this).val($(this).data('default_value')) : $(this).val($(this).val()));
		check_form_value($(this).attr('id'));
	});
	
	/* changing color of form fields when value does and does not equal the default */
	$('.form_field').keyup(function()
	{
		check_form_value($(this).attr('id'));
	});
	
	/* form submission */
	$('#submit_comment_form').click(function()
	{	
		$('#comment_form').submit();
	});
});

function check_form_value(id)
{
	var $selector = $('#' + id);
	var new_css_value = ($selector.val() != $selector.data('default_value') ? 'rgb(0, 0, 0)' : 'rgb(100, 100, 100)');
	$selector.css('color', new_css_value);
}
