	
	// Инициализируем таблицу перевода
	var trans = [];
	for (var i = 0x410; i <= 0x44F; i++)
	  trans[i] = i - 0x350; // А-Яа-я
	trans[0x401] = 0xA8;    // Ё
	trans[0x451] = 0xB8;    // ё

	// Сохраняем стандартную функцию escape()
	var escapeOrig = window.escape;

	// Переопределяем функцию escape()
	window.escape = function(str)
	{
	  var ret = [];
	  // Составляем массив кодов символов, попутно переводим кириллицу
	  for (var i = 0; i < str.length; i++)
	  {
	    var n = str.charCodeAt(i);
	    if (typeof trans[n] != 'undefined')
	      n = trans[n];
	    if (n <= 0xFF)
	      ret.push(n);
	  }
	  return escapeOrig(String.fromCharCode.apply(null, ret));
	}



	var city='';
	var area='';
	var street='';
	var house='';
	var count=1000;
	
	function getcnt(url)
	{
		count = 1001;
		$.ajax({
			type:'get',
			dataType:'text',
			url:'/exec/suik_cnt?'+url,
			success:function(data)
			{
//				alert(data);
//				count=data;
				if (data==1)
				{
//					$("#searchform").innerHTML = "Подождите. Идет поиск.";
					window.location='/searchuik/&'+url;
					
				}
			}
		});
		return 1;
	}

	function mycleardiv(id)
	{
		var obj = $(id).parent().parent();
		var inp = $(id).parent();
		inp.find('div').remove();
		var inp_html = inp.html();
		obj.find('div').remove();
		obj.append(inp_html);

//		var obj = $(id).parent();
//		var inp = $(id).parent();
//		inp.find('div').remove();
//		var inp_html = inp.html();
//		obj.find('div').remove();
//		obj.append(inp_html);
		
	}
	

	
jQuery().ready( function($) {

	
	$("#autocomplete1").autocomplete( {
		url :'/exec/suik',
		onSuggest:function(){
			this.ac.css({'background-image': 'url("/src/img/progress.gif")'});
		},
		onDisplay:function(list){
			this.ac.css({'background-image':'none'});
		},
		onSelect : function() {
			mycleardiv("#autocomplete2");
			city=escape(this.ac.val());
			getcnt('city='+city);

			$("#autocomplete2").autocomplete( {
				url :'/exec/suik?city='+city,
				onSuggest:function(){
					this.ac.css({'background-image': 'url("/src/img/progress.gif")'});
				},
				onDisplay:function(list){
					this.ac.css({'background-image':'none'});
				},
				onSelect : function()
				{
					mycleardiv("#autocomplete3");
					area=escape(this.ac.val());
					getcnt('city='+city+'&area='+area);
					
					$("#autocomplete3").autocomplete( {
						url :'/exec/suik?city='+city+'&area='+area,
						onSuggest:function(){
							this.ac.css({'background-image': 'url("/src/img/progress.gif")'});
						},
						onDisplay:function(list){
							this.ac.css({'background-image':'none'});
						},
						onSelect : function()
						{
							mycleardiv("#autocomplete4");
							street=escape(this.ac.val());
							getcnt('city='+city+'&area='+area+'&street='+street);
							
							$("#autocomplete4").autocomplete( {
								url :'/exec/suik?city='+city+'&area='+area+'&street='+street,
								onSuggest:function(){
									this.ac.css({'background-image': 'url("/src/img/progress.gif")'});
								},
								onDisplay:function(list){
									this.ac.css({'background-image':'none'});
								},
								onSelect : function()
								{
									mycleardiv("#autocomplete5");
									house=escape(this.ac.val());
									getcnt('city='+city+'&area='+area+'&street='+street+'&house='+house);
									
									$("#autocomplete5").autocomplete( {
										url :'/exec/suik?city='+city+'&area='+area+'&street='+street+'&house='+house,
										onSuggest:function(){
											this.ac.css({'background-image': 'url("/src/img/progress.gif")'});
										},
										onDisplay:function(list){
											this.ac.css({'background-image':'none'});
										},
										onSelect : function()
										{

											flat=escape(this.ac.val());
											getcnt('city='+city+'&area='+area+'&street='+street+'&house='+house+'&flat=flat');
											
										},
										fillin:true,
										mask:'',
										type :'xml'
									});
									
									
								},
								fillin:true,
								mask:'',
								type :'xml'
							});
							
						},
						fillin:true,
						mask:'',
						type :'xml'
					});
					
					
				},
				fillin:true,
				mask:'',
				type :'xml'
			});
		
		

	
	
		},
		fillin:true,
		mask:'',
		type :'xml'
	});
	
	
	
})
