function get_district(val){
  pmp_clearSelect('district');
  pmp_clearSelect('city');
  if(val == 0) {
  	$("district").disabled = "disabled";
        $("city").disabled = "disabled";
  }else{
        $("load_img").show();
  	new Ajax.Request('/resp/get_district.php',
  	    {asynchronous:true,
  	     evalScripts:false,
  	     method: 'get',
  	     parameters: { id: val },
  	     onComplete:function(request, json){update_district(request, json);$("load_img").hide(); },
  	     onFailure:function(request, json){alert('Ошибка запроса к серверу');}
  	     }
  	     );
  }
}
function get_city(val){
  pmp_clearSelect('city');
  if(val == 0) {
  	$("city").disabled = "disabled";
  }else{
        $("load_img").show();
  	new Ajax.Request('/resp/get_city.php',
  	    {asynchronous:true,
  	     evalScripts:false,
  	     method: 'get',
  	     parameters: { id: val },
  	     onComplete:function(request, json){update_city(request, json);$("load_img").hide();},
  	     onFailure:function(request, json){alert ('Ошибка запроса к серверу');}
  	     }
  	     );
  }
}
function update_district(request, json){
    if (request.responseText.length > 0) {
        result = request.responseText.split("\n");
		for (var i=0; i<result.length; i++) {
		  var temp = result[i];
  			if (temp.length > 0) {
     			pmp_fillSelect('district', temp);
        	} else {
        		pmp_clearSelect('district');
                $("district").disabled = "disabled";
            }
		}
	}else{
	  pmp_clearSelect('district');
	}
}
function update_city(request, json){
    if (request.responseText.length > 0) {
        result = request.responseText.split("\n");
		for (var i=0; i<result.length; i++) {
		  var temp = result[i];
  			if (temp.length > 0) {
     			pmp_fillSelect('city', temp);
        	} else {
        		pmp_clearSelect('city');
                $("city").disabled = "disabled";
            }
		}
	}else{
	  pmp_clearSelect('city');
	}
}
function pmp_clearSelect(sName) {

	var obj = $(sName);
	if (obj && obj.options) {
		while (obj.options.length) {
			obj.options[0] = null;
		}
		obj.options[0] = new Option('Выбрать', '0');
		obj.disabled = true;
		obj.value = '';
		obj.selectedIndex = 0;
	}
}
function pmp_fillSelect(name, source) {

	var obj = $(name);
	pmp_clearSelect(name);

	if (source.length > 0) {
		var items = source.split(';');
		for (var i=0; i<items.length; i++) {
                    if(items[i] != "") {
			var item = items[i].split(':');
			obj.options[i+1] = new Option(item[1], item[0]);
                    }
		}
	}

	obj.disabled = obj.options.length <= 1;
}

function s_city_block() {

    $('zip_fields').hide();
    $('search_index').className = "search_index_b";
    $('index_fields').show();
    $('search_city').className = "search_city_b";


}

function s_index_block() {

    $('index_fields').hide();
    $('search_index').className = "search_index_b_y";
    $('zip_fields').show();
    $('search_city').className = "search_city_b_b";


}
