function load_person_jur_type_add_form(jur_type_id)
{
	show_progress_bar("person_add_form");
	$.post("/cgi-bin/dsp.pl", { cl: "register", event: "get_person_jur_type_add_form", jur_type: jur_type_id, rnd: Math.random(), utf8: 1 }, 
	function(data) { $('#person_add_form').show().html(data); });
}
function add_person()
{
	$('#person_add_form').hide();
	var form_params = get_form_params("#add_new_person");
	$.post("/cgi-bin/dsp.pl", form_params, 
	function(data) 
	{ 
		if(data.match(/^ok$/))
		{
			var div_id = 'person_list';
			reload_person_list(div_id);
		}
		else if (data.match(/^error~/))
		{
			$('#person_add_form').show();
			data = data.replace(/^error~/, '');
			alert(data);
		}
	});
}

function show_progress_bar(div_id)
{
	// $("div[id="+div_id+"]").html("<img width='200px' id='load_img' src='/images/loading_file.gif'>");
	$("div[id="+div_id+"]").html("<font class='load_wait'>Подождите, идет загрузка...</font>");
}

function get_form_params(form)
{
	var form_params={};	
	$('input, textarea, select', form).each(function() {
			if($(this).attr('name'))
			{
				var value = $(this).attr('value');
				if( $(this).is(':radio') ) 
				{ 
					value = $("input[name='"+$(this).attr('name')+"']:checked").val();
				}
				else if ( $(this).is(':checkbox') )
				{
					value = $(this).attr('checked') ? 1 : 0;
				}
				form_params[$(this).attr('name')] = value;
			}
		})
	form_params['rnd'] = Math.random();
	form_params['utf8'] = 1;		
	return form_params;
}

function load_auth(div_id)
{
	$.post("/cgi-bin/dsp_ajax.pl", { cl: "register_ajax", event: "get_auth_form", rnd: Math.random(), utf8: 1 }, 
	function(data) { $("#auth_form_div").html(data); });
}

function open_div(show_div, hide_div) 
{
	document.getElementById(show_div).style.display ='block';
	document.getElementById(hide_div).style.display = 'none';
}

function perform_unit_ask(form_id, id, cl, ev, msg, mode)
{
	if(confirm(msg)==true)
	{
		perform_unit(form_id, id, cl, ev, mode);
	}
}

function perform_unit(form_id, id, cl, ev, mode)
{
	myForm = document.getElementById(form_id);
	myForm.unit_id.value=id;
	myForm.event.value=ev;
	myForm.cl.value=cl;
	myForm.submit();
}

$(document).ready( function(){
	$('div#open_sub a').click(function(){
		var catalog_id = $(this).parent().attr('catalog_id');
		if( $(this).parent().attr('class') != 'level0' && $(this).parent().attr('class') != 'level0cur') 
			$(this).parent().siblings('div[id^=sub][id!=sub'+catalog_id+']:visible').hide(); // закрываем открытые того же уровня
		$('div#sub'+catalog_id).toggle(); 
		return false;
	});
	
	$('.toogle_address').live('click', function () {
		if($(this).attr('checked')) $('div[id^=hide_address]').hide();
		else $('div[id^=hide_address]').show();
	});
});
