function change_country(a, url) {
		var myAjax = new Ajax.Request(
			url,
			{method: 'get', parameters: "action=country&id="+a.value, onComplete: change_city.bindAsEventListener(this)}
		);
}

function change_city(response) {

	var data = response.responseText.evalJSON();
	list = $('city');
	if (!list) list = $('items_city');
	
	list.options.length=0;
	list.options[list.options.length] = new Option('Выберете город', key);
	for (var key in data)
		list.options[list.options.length] = new Option(data[key].replace('&#39;','\''), key);
}

function checkall(a, className) {
	var el = document.getElementsByClassName(className);
	
	for (var i=0;i<el.length;i++) el[i].checked=a.checked;
}

function getSelect(sel) {
	for (var i=0;i<sel.options.length;i++) {
		if (sel.options[i].selected) return sel.options[i].value;
	}
	return 0;
}

function format_num(num, len) {
	while (num.length<len) {
		num = '0'+num;
	}
	return num;
}

function search_ref(sel) {
	for (var i=0;i<sel.options.length;i++) {
		if (sel.options[i].selected) return sel.options[i].ref;
	}
	return '';
}

function remake_code() {
	var seller = getSelect($('items_seller'));
	var code = search_ref($('items_country'))+format_num(seller, 2)+format_num($('myid').value, 4);
	
	$('apcode').innerHTML = code;
}

function filtrReset() {
	$('country').value=0;
	$('city').value=0;
	$('price').value=0;
	$('badroom').value=0;
	$('aptype').value=0;
	$('country').value=0;
	$('apposition1').checked = false;
}
