// load town/cities

function load_towncities(county_id, towncity_sel, lang_id, first_val, only_existing)
{
	$.getJSON('/ajax_towncities?county_id=' + county_id + '&lang_id=' + lang_id + (only_existing ? '&only_existing=true' : ''), function(json)
	{
		$('#' + towncity_sel).html('');
		$('#' + towncity_sel).append('<option value="0">' + first_val + '</option>');
		$.each(json.items, function(i, item)
		{
        	$('#' + towncity_sel).append('<option value="' + item[0] + '">' + item[1] + '</option>');
		});		
	});
}



// calctotal

function calctotal()
{
	var s = 0;
	$('.corder:checked').each(function(i){s+=parseInt(this.alt);});
	$('#total_price').html(s+'');
}

function userchecked(e,id)
{
	$.get('/ajax_userchecked/'+id, function(data){
		if (data=='ok')
		{
			$('#'+e).remove();
		}
	});
}

function questionchecked(e,id)
{
	$.get('/ajax_questionchecked/'+id, function(data){
		if (data=='ok')
		{
			$('#'+e).remove();
		}
	});
}



// search form cleanup

function search_form_cleanup()
{
	if($('#search_query').attr('class') == 'text_ex')
	{
		$('#search_query').val('');
	}
	if ($('#search_lang').val() == '0')
	{
		$('#search_lang').removeAttr('name');
	}
	if ($('#search_county_id').val() == '0')
	{
		$('#search_county_id').removeAttr('name');
	}
	if ($('#search_towncity_id').val() == '0')
	{
		$('#search_towncity_id').removeAttr('name');
	}
	$('#search_jurists').not(':checked').removeAttr('name');
	$('#search_lawyers').not(':checked').removeAttr('name');
	$('#search_notaries').not(':checked').removeAttr('name');
	$('#search_executors').not(':checked').removeAttr('name');
	$('#search').removeAttr('name');
}



// ie button fix

function ie_button_fix()
{
	$('button').click(function()
	{
		$('button').not(this).removeAttr('name');
	});
}



// document ready

$(document).ready(function()
{
	$(".autofocus:last").focus();
	if ($.browser.msie) ie_button_fix();
});