var server = "http://www.koncha-zaspa.net/";

function main(id)
{
	new Ajax.Updater('main', server+'scripts.php', {
		method : 'post',
		onComplete : function()
			{
			switch (id)
				{
				case 0: {document.getElementById('main_head1').innerHTML = "<a href='#' onclick='main(0);'>Главная</a>"; break;}
				case 1: {document.getElementById('main_head1').innerHTML = "<a href='#' onclick='main(1);'>О компании</a>"; break;}
				case 2: {document.getElementById('main_head1').innerHTML = "<a href='#' onclick='main(2);'>Услуги</a>"; break;}
				case 3: {document.getElementById('main_head1').innerHTML = "<a href='#' onclick='main(3);'>Сотрудничество</a>"; break;}
				case 4: {document.getElementById('main_head1').innerHTML = "<a href='#' onclick='main(4);'>Контакты</a>"; break;}
				}
			document.getElementById('main_head2').innerHTML = '';
			loading_ajax("off");
			},
		onLoading : function()
			{
			loading_ajax("on");
			},
		parameters: 
		{ 
		'query' : 'main',
		'id' : id
		}
	});
}

function loading_ajax(onoff)
{
$('loading_ajax').style.width = "100%";
$('loading_ajax').style.height = "100%"; 

if (onoff == 'on') $('loading_ajax').style.display='block';
else  $('loading_ajax').style.display='none';
}

function load_by_object(id){
	location.href = server+id+".html";
	/*new Ajax.Updater('main', server+'scripts.php', {
		method : 'post',
		onComplete : function()
			{
			loading_ajax("off");
			show_uploaded_files(id, 0);
			document.getElementById('main_head2').innerHTML = "Объект №"+id;
			},
		onLoading : function()
			{
			loading_ajax("on");
			},
		parameters: 
		{ 
		'query' : 'load_by_object',
		'id' : id
		}
	});*/
}

function load_place(type){
	var tablerow = true;
	if (navigator.appName == 'Microsoft Internet Explorer') 
		{
		var ua = navigator.userAgent;
		var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		if (re.exec(ua) != null)
			rv = parseFloat(RegExp.$1);
		if (rv<8) tablerow = false;
		}
	if (tablerow)
	for (var i=0;i<100;i++)
		{
		if($("menu_row_"+type+"_"+i) != null )
			if ($("menu_row_"+type+"_"+i).style.display == 'none')
				{
				$("menu_row_"+type+"_"+i).style.display = 'table-row';
				$("menu_row_"+type).bgColor = "#00713d";
				}
			else 
				{
				$("menu_row_"+type+"_"+i).style.display = 'none';
				$("menu_row_"+type).bgColor = "#ffffff";
				}
		else break;
		}
}

function close_all_menu(){
	var tablerow = true;
	if (navigator.appName == 'Microsoft Internet Explorer') 
		{
		var ua = navigator.userAgent;
		var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
		if (re.exec(ua) != null)
			rv = parseFloat(RegExp.$1);
		if (rv<8) tablerow = false;
		}
	if (tablerow)
	for (var i=0;i<20;i++)
	for (var j=0;j<20;j++)
		{
		if($("menu_row_"+i+"_"+j) != null )
			$("menu_row_"+i+"_"+j).style.display = 'none';
		//else break;
		}
}

function load_by_place(region,type,place){
	location.href = server+type+region+"/"+place+"/";
	/*new Ajax.Updater('main', server+'scripts.php', {
		method : 'post',
		onComplete : function() 
			{
			loading_ajax("off");
			document.getElementById('main_head1').innerHTML = "<a href='#' onclick='load_by_place("+'"'+region+'","'+type+'","'+place+'"'+");'>"+place+"</a>";
			document.getElementById('main_head2').innerHTML = "";
			},
		onLoading : function()
			{
			loading_ajax("on");
			},
		parameters: 
		{ 
		'query' : 'load_by_place',
		'region' : region,
		'type' : type,
		'place' : place
		}
	});*/
	return false;
}

function load_exclusive(){
	new Ajax.Updater('main', server+'scripts.php', {
		method : 'post',
		onComplete : function() 
			{
			loading_ajax("off");
			document.getElementById('main_head1').innerHTML = "<a href='#' onclick='load_exclusive();'>Эксклюзив</a>";
			document.getElementById('main_head2').innerHTML = "";
			},
		onLoading : function()
			{
			loading_ajax("on");
			},			
		parameters: 
		{ 
		'query' : 'load_exclusive'
		}
	});
	return false;
}

function startUpload(){
      document.getElementById('f1_upload_process').style.visibility = 'visible';
      document.getElementById('f1_upload_form').style.visibility = 'hidden';
      return true;
}

function stopUpload(success){
      var result = '';
      if (success == 1){
         result = '<span class="msg">Файл был успешно загружен!<\/span><br/>';
      }
      else {
         result = '<span class="emsg">Ошибка при загрузке файла!<\/span><br/>';
      }
      document.getElementById('f1_upload_process').style.visibility = 'hidden';
      document.getElementById('f1_upload_form').innerHTML = result + '<input name="myfile" type="file"><br><input type="submit" name="submitBtn" class = "button" value="Загрузить">';
      document.getElementById('f1_upload_form').style.visibility = 'visible'; 
	  show_uploaded_files($F('obj_id'), 1);
      return true;   
}

function show_uploaded_files(id, edit)
{
	new Ajax.Updater('filelist', server+'scripts.php', {
		method : 'post',
		onComplete : function()
			{
			$('filelist').style.display='block';
			},
		parameters: 
		{ 
		'query' : 'show_uploaded_files',
		'id' : id,
		'edit' : edit
		}
	});
}

function del_file(file,tb_file)
{
	new Ajax.Updater('', server+'scripts.php', {
		method : 'post',
		onComplete : function()
			{
			show_uploaded_files($F('obj_id'), 1);
			document.getElementById('f1_upload_form').innerHTML = '<input name="myfile" type="file"><br><input type="submit" name="submitBtn" class = "button" value="Загрузить">';
			},
		parameters: 
		{ 
		'query' : 'del_file',
		'file' : file,
		'tb_file' : tb_file
		}
	});
}

function admin_add()
{
	new Ajax.Updater('profile', server+'scripts.php', 
	{
	method : 'post',
	onComplete : function()
		{
		admin_profile_open();
		document.getElementById('all').style.display = 'none';
		document.getElementById('main_head1').innerHTML = "Добавление";
		},
	parameters: 
		{
		'query' : 'admin_add'
		}
	});
}

function admin_price()
{
	new Ajax.Updater('profile', server+'scripts.php', 
	{
	method : 'post',
	onComplete : function()
		{
		document.getElementById('all').style.display = 'none';
		document.getElementById('main_head1').innerHTML = "Прайс";
		},
	parameters: 
		{
		'query' : 'admin_price'
		}
	});
}

function admin_del(id)
{
	new Ajax.Updater('', server+'scripts.php', 
	{
	method : 'post',
	onComplete : function()
		{
		admin_view_all();
		},
	parameters: 
		{
		'query' : 'admin_del',
		'id' : id
		}
	});
}

function admin_edit(id)
{
	new Ajax.Updater('profile', server+'scripts.php', 
	{
	method : 'post',
	onComplete : function()
		{
		admin_profile_open();
		show_uploaded_files(id, 1);
		document.getElementById('main_head2').innerHTML = "Объект №"+id;
		},
	parameters: 
		{
		'query' : 'admin_edit',
		'id' : id
		}
	});
}

function admin_view_all()
{
	new Ajax.Updater('all', server+'scripts.php', 
	{
	method : 'post',
	onComplete : function()
		{
		document.getElementById('all').style.display = 'block';
		admin_profile_close();
		document.getElementById('main_head1').innerHTML = "Редактирование";
		},
	parameters: 
		{
		'query' : 'admin_view_all'
		}
	});
}

function admin_save()
{
	new Ajax.Updater('', server+'scripts.php', 
	{
	method : 'post',
	onComplete : function()
		{
		admin_profile_close();
		admin_view_all();
		},
	parameters: 
		{
		'query' : 'admin_save',
		'id' : $F('id1'),
		'region' : $F('region'),
		'place' : $F('place'),
		'type' : $F('type'),
		's_land' : $F('s_land'),
		'land_type' : $F('land_type'),
		's_house' : $F('s_house'),
		'ready_state' : $F('ready_state'),
		'addinfo' : $F('addinfo'),
		'price' : $F('price'),
		'exclusive' : $('exclusive').checked,
		'on_mainpage' : $('on_mainpage').checked
		}
	});
}

function admin_profile_close()
{
$('profile').style.display = 'none';
}

function admin_profile_open()
{
$('profile').style.display = 'block';
}

function search_text()
{
	new Ajax.Updater('main', server+'scripts.php', 
	{
	method : 'post',
	onComplete : function() 
		{
		loading_ajax("off");
		document.getElementById('main_head1').innerHTML = "<a href='#' onclick='search_text();'>Поиск: "+$F('search_text')+"</a>";
		document.getElementById('main_head2').innerHTML = "";
		},
	onLoading : function()
		{
		loading_ajax("on");
		},
	parameters: 
		{
		'query' : 'search_text',
		'search_text' : $F('search_text')
		}
	});
}

function filter()
{
	new Ajax.Updater('main', server+'scripts.php', 
	{
	method : 'post',
	onComplete : function() 
		{
		loading_ajax("off");
		document.getElementById('main_head1').innerHTML = "<a href='#' onclick='filter();'>Фильтр</a>";
		document.getElementById('main_head2').innerHTML = "";
		},
	onLoading : function()
		{
		loading_ajax("on");
		},
	parameters: 
		{
		'query' : 'filter',
		'region_s' : $F('region_s'),
		'type_s' : $F('type_s'),
		'price_s' : $F('price_s')
		}
	});
}