	function test(input_id, li_id, type, optional, error_text)
	{
		$(input_id).blur(function(){
			 $.getJSON(  
		            'http://'+site_url+'/debt-help/json-test.php',  
		            {value: this.value, type: type},  
		            function(json) {
		                if (optional)
		                {
	                		if ($(input_id).val() == '')
	                		{
                				remove_error(li_id);
							}
						}
						
                		if (json.result == 'true')
                		{
							mark_successful(li_id);
						}
						else
						{
                			if ($(li_id).hasClass('success'))
							{
                				$(li_id).removeClass('success');
							}
							
							if ((($(input_id).val() != '') && optional) || !optional)
							{
								if (error_text == '')
								{
									error_text = 'You have entered invalid data';
								}
								
								add_error(li_id, error_text);
							}
						}
		            }  
		        );  
		});
	}
	
	function not_blank(input_id, li_id)
	{
		$(input_id).blur(function(){
	        if ($(input_id).val() != '')
	        {
				mark_successful(li_id);
			}
			else
			{
				add_error(li_id, 'This field is required');
			}
		});
	}
	
	function not_blank_select(input_id, li_id)
	{
		$(input_id).change(function(){
	        if ($(input_id).val() != '')
	        {
				mark_successful(li_id);
			}
			else
			{
				add_error(li_id, 'This field is required');
			}
		});
		
		$(input_id).blur(function(){
	        if ($(input_id).val() != '')
	        {
				mark_successful(li_id);
			}
			else
			{
				add_error(li_id, 'This field is required');
			}
		});
	}
    
	function mark_success_radio(ol_id, li_id)
	{
		$(ol_id + " li label input:radio").change(function(){
				mark_successful(li_id);
		});
	}
    
	function mark_success_check(ol_id, li_id)
	{
		$(ol_id + " li label input:checkbox").change(function(){
			
			if ($(ol_id + " li label input:checked").length > 0)
			{
				mark_successful(li_id);
			}
			else
			{
				add_error(li_id, 'This field is required');
			}
		});
	}
	
	function mark_success_check_single(input_id, li_id)
	{
		$(input_id).change(function(){
			if ($(input_id + ':checked').length > 0)
			{
				mark_successful(li_id);
			}
			else
			{
				add_error(li_id, 'This field is required');
			}
		});
	}
	
	function hint(input_id, li_id, hint_text)
	{
		$(input_id).focus(function(){
			$(li_id).prepend('<div class="hint"><div class="arrow"></div><p>'+hint_text+'</p></div>');
			$(li_id + ' div.hint').hide();
			$(li_id + ' div.hint').fadeIn('slow');
		});
		
		$(input_id).blur(function(){
			$(li_id + ' div.hint').fadeOut('slow', function(){$(li_id + ' div.hint').remove();});
		});
	}
	
	function add_error(li_id, error_text)
	{
		if ($(li_id).hasClass('success'))
		{
            $(li_id).removeClass('success');
		}
		
		if (!$(li_id).hasClass('error'))
		{
	        $(li_id).addClass('error');
	        if (error_text != '')
	        {
		        $(li_id).append('<span class="error">' + error_text + '</span>');
		        $(li_id + ' span.error').hide();
		        $(li_id + ' span.error').fadeIn('slow');
			}
		}
	}
	
	function mark_successful(li_id)
	{
		remove_error(li_id);
		$(li_id).addClass('success');
	}
	
	function remove_error(li_id)
	{
		if ($(li_id).hasClass('error'))
		{
			$(li_id + ' span.error').fadeOut(function(){ $(li_id + ' span.error').remove();$(li_id).removeClass('error');});
		}
	}
	
	function attach_show_hide_if_checked(id_to_show_hide, id_if_checked)
	{
		$(id_if_checked).change(function(){show_hide_if_checked(id_to_show_hide, id_if_checked, true)});
		show_hide_if_checked(id_to_show_hide, id_if_checked, false);
	}
	
	function show_hide_if_checked(id_to_show_hide, id_if_checked, animate)
	{
		if ($(id_if_checked).is(':checked'))
		{
			if (animate)
			{
				$(id_to_show_hide).fadeIn('slow');
			}
			else
			{
				$(id_to_show_hide).css('display', 'block');
			}
		}
		else
		{
			if (animate)
			{
				$(id_to_show_hide).fadeOut('slow');
			}
			else
			{
				$(id_to_show_hide).css('display', 'none');
			}
			$(id_to_show_hide + ' input').val('');
			
			if ($(id_to_show_hide).hasClass('success'))
			{
				$(id_to_show_hide).removeClass('success');
			}
			
			if ($(id_to_show_hide).hasClass('error'))
			{
				$(id_to_show_hide + ' span').remove();
				$(id_to_show_hide).removeClass('error');
			}
		}
	}
