var mycity = null;		// флэш объект
var mc_menu = [[]];		// ссылки на меню и табы
var isIE    = navigator.appVersion.indexOf("MSIE") != -1;
var isOpera = navigator.userAgent.indexOf("Opera") != -1;
var isGecko = navigator.userAgent.indexOf("Gecko") != -1;
var emailExpr = /^[a-z0-9][a-z0-9_.-]*@[a-z0-9_.-]+\.[a-z]{2,7}$/i;
var quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/;
var data_status = {alpha:"Статус α-тестирования",beta: "Статус β-тестирования",news: "Новинка!",soon: "Скоро...",none: "Недоступен"};

String.prototype.trim = function(){return this.replace(/^\s+|\s+$/g,'');};
window.$ = function(id) {var match = quickExpr.exec(id);return document.getElementById(match[3]);};
var opening = function(obj) {
	var target = obj.parentNode.childNodes[1];
		target.style.display = target.style.display == 'none' ? 'block' : 'none';
}
// -------------------------------------------------------------------------------------------------------------------
function Class() {};
Class.prototype.construct = function() {};
Class.extend = function(def) {
	var classDef = function() {
		if (arguments[0] !== Class) {
			this.construct.apply(this, arguments);
		}
	};
	var proto = new this(Class);
	var superClass = this.prototype;
	for (var n in def) {
		var item = def[n];
		if (item instanceof Function) item.$ = superClass;
		else classDef[n] = item;
		proto[n] = item;
	}
	classDef.prototype = proto;
	classDef.extend = this.extend;
	return classDef;
};
// -------------------------------------------------------------------------------------------------------------------
var UI = {
	Icon: function(className, title) {
		var icon = document.createElement("div");
			icon.className = className;
			icon.title = title;
			icon.onmouseover = function() {
				this.style.backgroundPosition = '-15px 0px';
			};
			icon.onmouseout = function() {
				this.style.backgroundPosition = '0px 0px';
			};
		return icon;
	},
	Div: function(className, innerHTML) {
		var div = document.createElement("div");
			div.className = className;
			div.innerHTML = innerHTML;
		return div;
	}
};
var MC = {
	Load: {
		isLoad: false,
		onLoadBody: function() {
			this.isLoad = true;
		},
		onLoadFlash: function() {
			
		},
		getValue: function() {
			return this.isLoad;
		}
	},
	Event: {
		add: function(target, type, handler) {
			if (target.addEventListener) {
				target.addEventListener(type, handler, false);
			} else if (target.attachEvent) {
				target.attachEvent("on" + type, handler);
			} else {
				// Событие не подписано
			}
		},
		remove: function(target, type, handler) {
			if (target.removeEventListener) {
				target.removeEventListener(type, handler, false);
			} else if (target.detachEvent) {
				target.detachEvent("on" + type, handler);
			} else {
				// Событие не отписанно
			}
		}
	},
	Item: {
		Tab:		Class.extend({
			_div: null,		// Слой контейнер элементов, прокладка между основным табом. Нужен для удобной очистки.
			construct: function(id, name, title, status) {
				this._id = id;
				this._name = name;
				this._title = title;
				this._status = status;
			},
			show: function() {
				this._menu._stab.hide();
				this._menu._stab = this;
				this._dt.className = "on";
				this._cnt.style.display = "block";
			},
			hide: function() {
				this._dt.className = "off";
				this._cnt.style.display = "none";
			},
			clear: function() {
				this._cnt.removeChild(this._div);
				this._div = document.createElement("div");
				this._cnt.appendChild(this._div);
			},
			enabled: function() {
				// переключение на предыдущй или следующий таб, отключение таба
			},
			disabled: function() {
				// включение таба
			},
			addItem: function(item) {
				this._div.appendChild(item.getItem());
			},
			addHtml: function(html) {
				this._div.innerHTML = html;
			},
			setTab: function(menu) {
				this._menu = menu;
				
				var b = document.createElement("b");
					b.innerHTML = this._name;
				if (this._status != "no") {
					if (this._status == "on") {
						menu._stab = this;
					}
					b.style.color = menu._color;
					b.style.borderColor = menu._color;
				}
				this._b = b;
				var span = document.createElement("span");
					span.appendChild(b);
				var div = document.createElement("div");
				this._div = div;
				var cnt = document.createElement("div");
					cnt.className = "places";
				//	cnt.id = "list_"+this._id;
				//	cnt.style.height = document.body.clientHeight - 148;
					cnt.style.height = menu._div5.style.height;
					cnt.style.display = this._status == "on" ? "block" : "none";
					cnt.appendChild(div);
				this._cnt = cnt;
				
				var dt = document.createElement("div");
					dt.target = this;
					dt.id = this._id;					// !! возможно не нужно
					dt.className = this._status;
					dt.title = this._title;
					dt.onclick = function() {
						if (this.className == "off") {
							this.target.show();
						}
					};
					dt.appendChild(span);
				this._dt = dt;
				// подписка дивов на ресайз
				MC.Event.add(window, "resize", function() {cnt.style.height = menu._div5.style.height;});
				
				menu._div4.appendChild(this._dt);
				menu._div5.appendChild(this._cnt);
			}
		}),
		Menu:		Class.extend({
			_stab: null,	// выбранный таб
			_color: null,	// цвет меню
			_ico: null,		// ссылка на слой с иконкой
			_div:null,		// 
			construct: function(id, name, color) {
				this._color = color;
				var h = document.body.clientHeight - 148;
				//
				var gif = document.createElement("img");
					gif.width = "32";
					gif.height = "31";
					gif.src = "./res/menu/"+id+".gif";
					gif.title = name;
				var ico = document.createElement("div");
					ico.target = this;
					ico.onclick = function() {
						this.target.show();
					};
					ico.appendChild(gif);
				this._ico = ico;
				var mic = $("#menu_icons");
					mic.appendChild(ico);
				//
				var img = document.createElement("img");
				var line = document.createElement("div");
					line.className = "menu_cline";
					line.style.backgroundColor = this._color;
					line.appendChild(img);
				var h1 = document.createElement("h1");
					h1.innerHTML = name;
				var div3 = document.createElement("div");
					div3.className = "menu_title background";
					div3.appendChild(h1);
				var div4 = document.createElement("div");
					div4.className = "tabs";
				var div5 = document.createElement("div");
					div5.className = "div_list";
					div5.style.height = h;
				// подписка дивов на ресайз
				MC.Event.add(window, "resize", function() {div5.style.height = document.body.clientHeight - 148;});
				
				var div = document.createElement("div");
					div.style.height = "100%";
					div.style.display = "none";
					div.appendChild(line);
					div.appendChild(div3);
					div.appendChild(div4);
					div.appendChild(div5);
				
				this._div = div;
				this._div4 = div4;
				this._div5 = div5;
			},
			show: function() {
				var temp = MC.Panel.Right.temp;
				if (temp != this) {
					this._div.style.display = "block";
					this._ico.style.backgroundColor = this._color;
					if (temp != null && temp != this) {
						temp.hide();
					}
					MC.Panel.Right.temp = this;
				}
			},
			hide: function() {
				this._div.style.display = "none";
				this._ico.style.backgroundColor = "#000";
			},
			getItem: function() {
				return this._div;
			}
		}),
		MenuLeft:	Class.extend({
			_stab: null,	// выбранный таб
			_color: null,	// цвет меню
			_div:null,		// 
			construct: function(id, name, color) {
				this._color = color;
				var h = document.body.clientHeight - 110;
			/*	var gif = document.createElement("img");
					gif.width = "32";
					gif.height = "31";
					gif.src = "./res/menu/"+id+".gif";
					gif.title = name;
				var ico = document.createElement("div");
					ico.target = this;
					ico.onclick = function() {
						this.target.show();
					};
					ico.appendChild(gif);
				this._ico = ico;
				var mic = $("#menu_icons");
					mic.appendChild(ico);
				var img = document.createElement("img");
				var line = document.createElement("div");
					line.className = "menu_cline";
					line.style.backgroundColor = this._color;
					line.appendChild(img);
			*/
				var h1 = document.createElement("h1");
					h1.innerHTML = name;
				var div3 = document.createElement("div");
					div3.className = "menu_title";
					div3.appendChild(h1);
				var div4 = document.createElement("div");
					div4.className = "tabs";
				var div5 = document.createElement("div");
					div5.className = "div_list";
					div5.style.height = h;
				// подписка дивов на ресайз
				MC.Event.add(window, "resize", function() {div5.style.height = document.body.clientHeight - 110;});
				
				var div = document.createElement("div");
					div.style.height = "100%";
					div.style.display = "none";
				//	div.appendChild(line);
					div.appendChild(div3);
					div.appendChild(div4);
					div.appendChild(div5);
				
				this._div = div;
				this._div4 = div4;
				this._div5 = div5;
			},
			show: function() {
				this._div.style.display = "block";
			},
			hide: function() {
				this._div.style.display = "none";
			},
			getItem: function() {
				return this._div;
			}
		}),
		Tool:		Class.extend({
			construct: function(value) {this._title  = value;},
			setTitle:  function(value) {this._title  = value;},
			setStatus: function(value) {this._status = value;},
			setIcon:   function(value) {this._icon   = value;},
			setLink:   function(value) {this._link   = value;},
			setNote:   function(value) {this._note   = value;},
			setHtml:   function(value) {this._html   = value;},
			setFocus:  function(value) {this._focus  = value;},
			mouseOver: function() {
				if (this._eContent.style.display == 'none') {
					this._eIcons.style.display = 'block';
					this._eTitle.style.color = '#3378ff';
					this._eTool.style.background = '#000 url(img/design/v_line_bg_item.gif) repeat-x';
				}
			},
			mouseOut: function() {
				if (this._eContent.style.display == 'none') {
					this._eIcons.style.display = 'none';
					this._eTitle.style.color = '#cbcbcb';
					this._eTool.style.background = '#292929';
				}
			},
			openItem:  function() {
				this.mouseOver();
				this._eContent.style.display = 'block';
				// установка фокуса
				if (this._focus != undefined && this._html != undefined) {
					var e = eval("this._eSubi." + this._focus);
					if (e.select != undefined) e.select();
					if (e.focus  != undefined) e.focus();
				}
			},
			closeItem: function() {
				this._eContent.style.display = 'none';
				this.mouseOut();
			},
			removeItem: function() {
				
			},
			show: function() {
				this._eTool.style.display = "block";
			},
			hide: function() {
				this._eTool.style.display = "none";
			},
			getItem:   function() {
				//	Icons
				var iconHelp = new UI.Icon("help", "Справка по инструменту");
					iconHelp.onclick = function() {
						alert('# Переход на справку этого инструмента\n' + this._link);
					};
				var icons = document.createElement("div");
					icons.className = "icons";
					icons.style.display = "none";
					icons.appendChild(iconHelp);
				this._eIcons = icons;
				//
				var isIcon = this._icon != undefined;
				
				var icon = document.createElement("div");
					icon.className = "icon";
					icon.style.backgroundImage = 'url('+this._icon+')';
					icon.style.backgroundRepeat = 'no-repeat';
				//
				var stat = this._status == undefined ? "" : "status " + this._status;
				var status = document.createElement("span");
					status.className = stat;
					status.title = data_status[this._status];
				var title = document.createElement("div");
					title.className = "title";
					title.innerHTML = this._title;
					title.target = this;
					title.onclick = function() {
						var value = this.target._eContent.style.display;
						if (value == 'none') {
							this.target.openItem();
						} else if (value == 'block') {
							this.target.closeItem();
						}
					};
					title.appendChild(status);
				this._eTitle = title;
				var note = document.createElement("div");
					note.className = "note";
					note.innerHTML = this._note;
				var content = document.createElement("div");
					content.className = "content";
					content.style.display = "none";
					content.appendChild(note);
				
				if (this._html != undefined) {
					var line = document.createElement("div");
						line.className = "line";
					var subi = document.createElement("div");
						subi.className = "subinfo";
						subi.innerHTML = this._html;
					this._eSubi = subi;
					var info = document.createElement("div");
						info.className = "info";
						info.style.MozBorderRadius = "4px";
						info.style.WebkitBorderRadius = "4px";
						info.style.BorderRadius = "4px";
						info.appendChild(subi);
					content.appendChild(line);
					content.appendChild(info);
				}
				
				this._eContent = content;
				var tool = document.createElement("div");
					tool.className = "tool";
					tool.isIcon = isIcon;
					tool.target = this;
					tool.onmouseover = function() {this.target.mouseOver();};
					tool.onmouseout = function() {this.target.mouseOut();};
				if (isIcon) {
					tool.appendChild(icon);
				}
					tool.appendChild(icons);
					tool.appendChild(title);
					tool.appendChild(content);
				this._eTool = tool;
				return tool;
			}
		}),
		Place:		Class.extend({
			construct: function(list) { this._list  = list; },
			del: function() {
				if (confirm("Вы уверены, что хотите удалить метку \""+this._list.name+"\"?")) {
					back.temp.del = this;
					mycity.delPlace(this._list.id);
				}
			},
			delResult: function() {
				this._eItem.parentNode.removeChild(this._eItem);
				delete this;
			},
			edit: function() {
				var id_place = this._list.id;
				var old_name = this._list.name;
				var old_note = this._list.note;
				var new_name = this._text_name;
				var new_note = this._text_note;
				/*
				if (new_name.value == old_name && new_note.value == old_note) {
					alert("Данные не были изменены! Будь внимательней! ;)");
					new_name.select();
					new_name.focus();
					return;
				}*/
				if (new_name.value == "") {
					alert("Название метки не может быть пустым!");
					new_name.focus();
					return;
				}
				/*
				if (new_note.value == "") {
					alert("Вы не ввели комментарий к метке!");
					new_note.focus();
					return;
				}*/
			//	back.temp.rename = obj.parentNode.parentNode.parentNode;
				back.temp.edit = this;
				mycity.editPlace({id:id_place, name:new_name.value, note:new_note.value});
			},
			editResult: function(result) {
				this._list.name = this._name.innerHTML = result.name;
				this._list.note = this._note.innerHTML = result.note;
				this.closeItem();
			},
			openItem: function() {
				this.mouseOver();
				if (MC.Place.temp != this && MC.Place.temp != null) {
					MC.Place.temp.closeItem();
					MC.Place.temp.mouseOut();
				}
				MC.Place.temp = this;
				this._change.style.display = 'block';			// отобразить панель редактирования
				this._text_name.select();						// выделить название метки
				this._text_name.focus();						// фокусировать поле названия
				mycity.moveToPosition("Place", this._list.id);	// быстро цетрировать метку
			},
			closeItem: function() {
				this._change.style.display = 'none';			// скрыть панель редактирования
				this._text_name.value = this._list.name;		// восстановить оригинальное название
				this._text_note.value = this._list.note;		// восстановить оригинальную заметку
				mycity.restorePosition("Place", this._list.id);	// восстановить оригинальную позицию
			},
			mouseOver: function() {
				if (this._change == null || this._change.style.display == 'none') {
					this._icons.style.display = 'block';
					this._note.style.display = 'block';
					this._name.style.color = '#fe6732';
					this._eItem.style.background = '#000 url(img/design/v_line_bg_item.gif) repeat-x';
					if (!isOpera) mycity.mouseOver("Place", this._list.id);
				}
			},
			mouseOut: function() {
				if (this._change == null || this._change.style.display == 'none') {
					this._icons.style.display = 'none';
					this._note.style.display = 'none';
					this._name.style.color = '#cbcbcb';
					this._eItem.style.background = '#292929';
					if (!isOpera) mycity.mouseOut("Place", this._list.id);
				}
			},
			getItem: function() {
				//	Change Panel
				var change = document.createElement("div");
					change.className = "change";
					change.style.display = "none";
				this._change = change;
				var line = document.createElement("div");
					line.className = "line";
				//	Text Fields
				var text_name = document.createElement("input");
					text_name.type = "text";
					text_name.title = "Новое название метки";
					text_name.className = "name";
					text_name.maxLength = "50";
					text_name.value = this._list.name;
				this._text_name = text_name;
				var text_note = document.createElement("textarea");	
					text_note.rows = "3";
					text_note.title = "Новый комментарий к метке";
					text_note.maxLength = "255";
					text_note.value = this._list.note;
				this._text_note = text_note;
				var tfields = document.createElement("div");
					tfields.className = "tfields";
					tfields.appendChild(text_name);
					tfields.appendChild(text_note);
				//	Button Save
				var bs = document.createElement("input");
					bs.type = "button";
					bs.value = "Сохранить";
					bs.target = this;
					bs.onclick = function() {
						this.target.edit();
					};
				var ds = document.createElement("div");
					ds.className = "button";
					ds.style.textAlign = "left";
					ds.appendChild(bs);
				//	Button Cancel
				var bc = document.createElement("input");
					bc.type = "button";
					bc.value = "Отмена";
					bc.target = this;
					bc.onclick = function() {
						this.target.closeItem();
						this.target.mouseOut();
					};
				var dc = document.createElement("div");
					dc.className = "button";
					dc.style.textAlign = "right";
					dc.appendChild(bc);
				//	Div Buttons
				var buttons = document.createElement("div");
					buttons.className = "buttons";
					buttons.appendChild(ds);
					buttons.appendChild(dc);
			//	var descrip = document.createElement("div");
			//		descrip.className = "description";
			//		descrip.innerHTML = "Для изменения положения точки, перетяните её, измените машстаб или угол поворота карты. Измените описание и сохраните.";
				var subi = document.createElement("div");
					subi.className = "subinfo";
			//		subi.appendChild(descrip);
					subi.appendChild(tfields);
					subi.appendChild(buttons);
				var info = document.createElement("div");
					info.className = "info";
					info.style.MozBorderRadius = "4px";
					info.style.WebkitBorderRadius = "4px";
					info.style.BorderRadius = "4px";
					info.appendChild(subi);
					
					change.appendChild(line);
					change.appendChild(info);
				//	Icons
				var iconDelete = new UI.Icon("delete", "Удалить метку");
					iconDelete.target = this;
					iconDelete.onclick = function() {this.target.del();};
				var iconChange = new UI.Icon("change", "Редактировать метку");
					iconChange.target = this;
					iconChange.onclick = function() {
						var value = this.target._change.style.display;
						if (value == 'none') {
							this.target.openItem();
						} else {
							this.target.closeItem();
						}
					};
				var icons = document.createElement("div");
					icons.className = "icons";
					icons.style.display = "none";
					icons.appendChild(iconDelete);
					icons.appendChild(iconChange);
				this._icons = icons;
				//	Info
				this._name = new UI.Div('name', this._list.name);
				this._note = new UI.Div('note', this._list.note);
				var info = document.createElement("div");
					info.className = "title";
					info.target = this;
					info.appendChild(this._name);
					info.appendChild(this._note);
					info.onclick = function() {
						mycity.flyToPosition("Place", this.target._list.id);
					};
				this._info = info;
				//	Item
				var item = document.createElement("div");
					item.target = this;
					item.className = "place";
					item.onmouseover = function() {this.target.mouseOver();};
					item.onmouseout = function() {this.target.mouseOut();};
					item.appendChild(this._icons);
					item.appendChild(this._info);
					item.appendChild(this._change);
				this._eItem = item;
				return item;
			}
		}),
		Point:		Class.extend({
			construct: function(list) {this._list  = list;},
			del: function() {
				if (confirm("Вы уверены, что хотите удалить точку \""+this._list.name+"\"?")) {
					back.temp.del = this;
					MC.Panel.Left.hide();	// Закрывается панель
					mycity.delPoint(this._list.id);
				}
			},
			delResult: function() {
				this._eItem.parentNode.removeChild(this._eItem);
				delete this;
			},
			info: function() {
				back.temp.view = this;
				mycity.infoPoint(this._list.id);
			},
			edit: function() {
				back.temp.edit = this;
				mycity.editPoint(this._list.id);
			},
			editResult: function() {
				
			},
			addFavor: function() {
				mycity.addFavor(this._list.id);
			},
			mouseOver: function() {
				this._eIcons.style.display = 'block';
				this._eTitle.style.color = '#ffcc33';
				this._eContent.style.display = 'block';
				this._eItem.style.background = '#000 url(img/design/v_line_bg_item.gif) repeat-x';
				if (!isOpera) mycity.mouseOver("Point", this._list.id);
			},
			mouseOut: function() {
				this._eIcons.style.display = 'none';
				this._eTitle.style.color = '#cbcbcb';
				this._eContent.style.display = 'none';
				this._eItem.style.background = '#292929';
				if (!isOpera) mycity.mouseOut("Point", this._list.id);
			},
			getItem: function() {
			//	var iconDelete = new UI.Icon("delete", "Удалить объект");
			//		iconDelete.target = this;
			//		iconDelete.onclick = function() {this.target.del();};
				var iconDetail = new UI.Icon("detail", "Подробнее");
					iconDetail.target = this;
					iconDetail.onclick = function() {this.target.info();};
				var iconAddFav = new UI.Icon("favor", "Добавить в избранное");
					iconAddFav.target = this;
					iconAddFav.onclick = function() {this.target.addFavor();};
				var icons = document.createElement("div");
					icons.className = "icons";
					icons.style.display = "none";
			//		icons.appendChild(iconDelete);
					icons.appendChild(iconDetail);
					icons.appendChild(iconAddFav);
				this._eIcons = icons;
				
				var title = document.createElement("div");
					title.target = this;
					title.className = "title";
					title.innerHTML = this._list.name;
					title.onclick = function() {mycity.flyToPosition("Point", this.target._list.id);};
				this._eTitle = title;
				
				var tags = new UI.Div('tags', this._list.tags);
				var note = new UI.Div('note', this._list.note);
				var line = document.createElement("div");
					line.className = "line";
				var content = document.createElement("div");
					content.className = "content";
					content.style.display = "none";
					content.appendChild(tags);
					content.appendChild(line);
					content.appendChild(note);
				this._eContent = content;
				
				var item = document.createElement("div");
					item.target = this;
					item.className = "place";
					item.onmouseover = function() {this.target.mouseOver();};
					item.onmouseout  = function() {this.target.mouseOut();};
					item.appendChild(icons);
					item.appendChild(title);
					item.appendChild(content);
				this._eItem = item;
				
				return item;
			}
		}),
		Favor:		Class.extend({
			construct: function(list) {this._list  = list;},
			del: function() {
				if (confirm("Вы уверены, что хотите удалить из избранного \""+this._list.name+"\"?")) {
					back.temp.del = this;
					mycity.delFavor(this._list.id);
				}
			},
			delResult: function() {
				this._eItem.parentNode.removeChild(this._eItem);
				delete this;
			},
			info: function() {
			//	MC.Panel.Left.show();
			//	alert("id: "+this._list.id+"\nname: "+this._list.name+"\nnote: "+this._list.note);
			},
			mouseOver: function() {
				this._eIcons.style.display = 'block';
				this._eTitle.style.color = '#fe6732';
				this._eContent.style.display = 'block';
				this._eItem.style.background = '#000 url(img/design/v_line_bg_item.gif) repeat-x';
				if (!isOpera) mycity.mouseOver("Favor", this._list.id);
			},
			mouseOut: function() {
				this._eIcons.style.display = 'none';
				this._eTitle.style.color = '#cbcbcb';
				this._eContent.style.display = 'none';
				this._eItem.style.background = '#292929';
				if (!isOpera) mycity.mouseOut("Favor", this._list.id);
			},
			getItem: function() {
				var iconDelete = new UI.Icon("delete", "Удалить из избранного");
					iconDelete.target = this;
					iconDelete.onclick = function() {this.target.del();};
			//	var iconDetail = new UI.Icon("detail", "Подробнее");
			//		iconDetail.target = this;
			//		iconDetail.onclick = function() {this.target.info();};
				var icons = document.createElement("div");
					icons.className = "icons";
					icons.style.display = "none";
					icons.appendChild(iconDelete);
			//		icons.appendChild(iconDetail);
				this._eIcons = icons;
				
				var title = document.createElement("div");
					title.target = this;
					title.className = "title";
					title.innerHTML = this._list.name;
					title.onclick = function() {mycity.flyToPosition("Favor", this.target._list.id);};
				this._eTitle = title;
				
				var tags = new UI.Div('tags', this._list.tags);
				var note = new UI.Div('note', this._list.note);
				var line = document.createElement("div");
					line.className = "line";
				var content = document.createElement("div");
					content.className = "content";
					content.style.display = "none";
					content.appendChild(tags);
					content.appendChild(line);
					content.appendChild(note);
				this._eContent = content;
				
				var item = document.createElement("div");
					item.target = this;
					item.className = "place";
					item.onmouseover = function() {this.target.mouseOver();};
					item.onmouseout  = function() {this.target.mouseOut();};
					item.appendChild(icons);
					item.appendChild(title);
					item.appendChild(content);
				this._eItem = item;
				
				return item;
			}
		})
	},
	Panel: {
		Top: {
			show: function() {
				$("#panel_top").style.display = isGecko ? null : "block";
			},
			hide: function() {
				$("#panel_top").style.display = "none";
			}
		},
		Left: {
			show: function() {
				this.removeDiv();
				$("#panel_left").style.display = isGecko ? null : "block";
			},
			hide: function() {
				this.removeVar();
				this.removeDiv();
				$("#panel_left").style.display = "none";
			},
			removeVar: function() {
				if (back.temp.edit != null) {
					mycity.restorePosition("Point", back.temp.edit._list.id);
					mycity.mouseOut("Point", back.temp.edit._list.id);
					back.temp.edit = null;
				}
			},
			removeDiv: function() {
				var con = $("#panel_left_container");
				var div = con.firstChild;
				div != null ? con.removeChild(div) : "";
			}
		},
		Right: {
			show: function() {
				$("#panel_right").style.display = isGecko ? null : "block";
			},
			hide: function() {
				$("#panel_right").style.display = "none";
				MC.Panel.Left.hide();
			},
			temp: null
		}
	}
};
var back = {
	temp: {},
	// SET
	setPoints: function(list) { this.setObjects(list, 'Point', 1,2);},
	setPlaces: function(list) { this.setObjects(list, 'Place', 2,1);},
	setFavors: function(list) { this.setObjects(list, 'Favor', 2,2);},
	// CLEAR
	clearPoints: function(list) { mc_menu[1][2].clear();},
	clearPlaces: function(list) { mc_menu[2][1].clear(); mc_menu[2][1].addItem(toolAuthPlace);},
	clearFavors: function(list) { mc_menu[2][2].clear(); mc_menu[2][2].addItem(toolAuthFavor);},
	// ADD
	addPoint:  function(list) { mc_menu[1][2].addItem(new MC.Item.Point(list[0]));},
	addPlace:  function(list) { mc_menu[2][1].addItem(new MC.Item.Place(list[0]));},
	addFavor:  function(list) { mc_menu[2][2].addItem(new MC.Item.Favor(list[0]));},
	// Common
	setObjects: function(list, type, m, n) {
		mc_menu[m][n].clear();
		mc_menu[m][n].addItem(eval("toolAdd" + type));
		var i = 0, ilen = list.length;
		while (i < ilen) {
			mc_menu[m][n].addItem(new MC.Item[type](list[i]));
			i++;
		}
		// открытие таба
		mycity.toolMenuHide();
		MC.Panel.Right.show();
		mc_menu[m][0].show();
		mc_menu[m][n].show();
	}
};
var createPanelRight = function() {
	var menu1 = new MC.Item.Menu("catalog", "Каталог", "#ffcc33");
	var tab11 = new MC.Item.Tab("rubricator", "Рубрикатор", "Рубрикатор каталога", "on");
		tab11.setTab(menu1);
		tab11.addHtml(
			'<div style="font:12px Tahoma; color:#fff; cursor:pointer; cursor:hand;">'+
				'<div style="padding:5px;" onclick="mycity.getPoints(5)">Автозаправки</div>'+
				'<div style="padding:5px;" onclick="mycity.getPoints(28)">Автомойки</div>'+
				'<div style="padding:5px;" onclick="mycity.getPoints(6)">Аптеки</div>'+
				'<div style="padding:5px;"><div onclick="opening(this)">Банки</div>'+
					'<div style="padding:5px 0 0 5px; display:none">'+
						'<div style="padding:5px"><div onclick="opening(this)">Нурбанк</div>'+
							'<div style="padding:5px 0 0 5px; display:none">'+
								'<div style="padding:5px;" onclick="mycity.getPoints(19)">· Филиалы</div>'+
								'<div style="padding:5px;" onclick="mycity.getPoints(20)">· Банкоматы</div>'+
							'</div>'+
						'</div>'+
						'<div style="padding:5px"><div onclick="opening(this)">Альфа-Банк</div>'+
							'<div style="padding:5px 0 0 5px; display:none">'+
								'<div style="padding:5px;" onclick="mycity.getPoints(21)">· Отделения</div>'+
								'<div style="padding:5px;" onclick="mycity.getPoints(22)">· Банкоматы</div>'+
							'</div>'+
						'</div>'+
					'</div>'+
				'</div>'+
				'<div style="padding:5px;" onclick="mycity.getPoints(25)">Бытовая техника</div>'+
				'<div style="padding:5px;" onclick="mycity.getPoints(4)">Гостиницы</div>'+
				'<div style="padding:5px;" onclick="mycity.getPoints(26)">Ж/д кассы</div>'+
				'<div style="padding:5px;" onclick="mycity.getPoints(27)">Канцтовары</div>'+
				'<div style="padding:5px;" onclick="mycity.getPoints(1)">Кинотеатры</div>'+
				'<div style="padding:5px;"><div onclick="opening(this)">Культура и искусство</div>'+
					'<div style="padding:5px 0 0 5px; display:none">'+
						'<div style="padding:5px;" onclick="mycity.getPoints(2)">Музеи</div>'+
						'<div style="padding:5px;" onclick="mycity.getPoints(32)">Театры</div>'+
						'<div style="padding:5px;" onclick="mycity.getPoints(34)">Выставки и галереи</div>'+
						'<div style="padding:5px;" onclick="mycity.getPoints(37)">Концертные залы</div>'+
					'</div>'+
				'</div>'+
				'<div style="padding:5px;" onclick="mycity.getPoints(30)">Ночные клубы</div>'+
				'<div style="padding:5px;" onclick="mycity.getPoints(29)">Общепит</div>'+
				'<div style="padding:5px;" onclick="mycity.getPoints(9)">Почтовые отделения</div>'+
				'<div style="padding:5px;" onclick="mycity.getPoints(24)">Салоны связи</div>'+
				'<div style="padding:5px;" onclick="mycity.getPoints(35)">Торговые комплексы</div>'+
				'<div style="padding:5px;" onclick="mycity.getPoints(31)">ЦОНы</div>'+
				'<div style="padding:5px;" onclick="mycity.getPoints(39)">Бутики</div>'+
				'<div style="padding:5px;" onclick="mycity.getPoints(40)">Мебель</div>'+
				'<br>'+
			'</div>'
		);
	var tab12 = new MC.Item.Tab("objects", "Объекты", "Объекты выбранной категории", "off");
		tab12.setTab(menu1);
		tab12.addItem(toolAddPoint);
	var tab13 = new MC.Item.Tab("section", "Разделы", "Разделы каталога", "no");
		tab13.setTab(menu1);
	// -------------------------------------------------------------------------------------------------------------------
	var menu2 = new MC.Item.Menu("points", "Метки", "#fe6732");
	var tab21 = new MC.Item.Tab("places", "Личные", "Ваши личные метки", "on");
		tab21.setTab(menu2);
		tab21.addItem(user.id == "" ? toolAuthPlace : toolAddPlace);
	var tab22 = new MC.Item.Tab("favors", "Избранное", "Ваши избранные точки из каталога", "off");
		tab22.setTab(menu2);
		tab22.addItem(user.id == "" ? toolAuthFavor : toolAddFavor);
	var tab23 = new MC.Item.Tab("public", "Друзей", "Публичные метки Ваших друзей", "no");
		tab23.setTab(menu2);
	// -------------------------------------------------------------------------------------------------------------------
	var menu3 = new MC.Item.Menu("tools", "Инструменты", "#3378ff");
		menu3.show();
	var tab31 = new MC.Item.Tab("tools_1", "Основные", "Основные инструменты", "on");
		tab31.setTab(menu3);
		tab31.addItem(tool7);
		tab31.addItem(tool8);
		tab31.addItem(tool2);
		tab31.addItem(tool1);
		tab31.addItem(tool3);
		tab31.addItem(tool4);
	//	tab31.addItem(tool5);
	//	tab31.addItem(tool6);
	//	tab31.addItem(tool9);
		tab31.show();
	var tab32 = new MC.Item.Tab("tools_3", "Интерфейс", "Настройка интерфейса", "no");
		tab32.setTab(menu3);
	// -------------------------------------------------------------------------------------------------------------------
	var menu4 = new MC.Item.Menu("party", "Тусовки", "#a533ff");
	var tab41 = new MC.Item.Tab("calendar", "Календарь", "Календарь", "on");
		tab41.setTab(menu4);
	var tab42 = new MC.Item.Tab("friends", "Друзья", "Друзья и тусовки друзей", "off");
		tab42.setTab(menu4);
	var tab43 = new MC.Item.Tab("afisha", "Афиша", "Афиша тусовок и мероприятий в городе", "off");
		tab43.setTab(menu4);
	// -------------------------------------------------------------------------------------------------------------------
	var menu5 = new MC.Item.Menu("news", "Новости", "#8ad72b");
	var tab51 = new MC.Item.Tab("allnew", "Все", "Все новости по дате", "on");
		tab51.setTab(menu5);
	var tab52 = new MC.Item.Tab("rating", "Популярные", "Популярные новости по мнению читателей", "off");
		tab52.setTab(menu5);
	var tab53 = new MC.Item.Tab("radius", "В радиусе", "Ближайшие новости в радиусе", "off");
		tab53.setTab(menu5);
	// -------------------------------------------------------------------------------------------------------------------
	var menu6 = new MC.Item.Menu("settings", "Настройки", "#d72e2b");
	var tab61 = new MC.Item.Tab("personal", "Персональное", "Персональное", "on");
		tab61.setTab(menu6);
		tab61.addItem(toolAuthorization);
		tab61.addItem(toolRegistration);
		tab61.addItem(toolRemainPassword);
	var tab62 = new MC.Item.Tab("private", "Личное", "Личное", "no");
		tab62.setTab(menu6);
	var tab63 = new MC.Item.Tab("preferences", "Настройки", "Настройки", "no");
		tab63.setTab(menu6);
	// -------------------------------------------------------------------------------------------------------------------
	var menus = $("#panel_right_container");	// Главное меню
		menus.appendChild(menu1.getItem());
		menus.appendChild(menu2.getItem());
		menus.appendChild(menu3.getItem());
		menus.appendChild(menu4.getItem());
		menus.appendChild(menu5.getItem());
		menus.appendChild(menu6.getItem());
	// -------------------------------------------------------------------------------------------------------------------
		mc_menu.push([menu1, tab11, tab12, tab13]);
		mc_menu.push([menu2, tab21, tab22, tab23]);
		mc_menu.push([menu3, tab31, tab32]);
		mc_menu.push([menu4, tab41, tab42, tab43]);
		mc_menu.push([menu5, tab51, tab52, tab53]);
		mc_menu.push([menu6, tab61, tab62, tab63]);
}

var createAddObject = function() {
	MC.Panel.Left.show();
	
	var menuAddObject = new MC.Item.MenuLeft("add_object", "Добавление нового объекта", "#ffcc33");
		menuAddObject.show();
	
	var tabInfoObject = new MC.Item.Tab("add_object_info", "Информация", "Основная информация об объекте", "on");
		tabInfoObject.setTab(menuAddObject);
		tabInfoObject.addHtml(
			'<div style="padding:10px;">'+
				'<div class="notes"><p>Перед добавлением объекта, рекомендуем ознакомиться с <a title="Как добавить новый объект в каталог" target="_blank" href="http://mycity.kz">некоторыми моментами</a>.</p></div>'+
				htmlFieldsObject +
				'<div class="notes" style="margin-top:10px;"><p>Выставите центр карты в местоположение объекта, установите оптимальный масштаб и угол поворота.</p><p>Перед добавлением, внимательно проверьте всю&nbsp;информацию и местоположение объекта.</p></div>'+
				'<div class="buttons" style="margin:5px 0 8px 0;"><div class="button" style="width:100%; text-align:center;"><input type="button" value="Добавить" onclick="MC.Point.Add.OK(this)"/></div></div>'+
			'</div>'
		);
		tabInfoObject.show();
	var tabDescObject = new MC.Item.Tab("add_object_desc", "Описание", "Подробное текстовое описание", "off");
		tabDescObject.setTab(menuAddObject);
		tabDescObject.addHtml('<textarea id="add_point_desc" style="width:100%; height:100%; margin:0;" title="Введите подробное описание объекта. Ограничение в 4000 символов (этого будет пока вполне достаточно :)"></textarea>');
	var tabModeObject = new MC.Item.Tab("add_object_mode", "Режим работы", "Режим работы объекта (компании)", "no");
		tabModeObject.setTab(menuAddObject);
//	var tabGalleryObject = new MC.Item.Tab("add_object_gallery", "Галерея", "Фотогалерея", "no");
//		tabGalleryObject.setTab(menuAddObject);
	
	var panelLeft = $("#panel_left_container");
		panelLeft.appendChild(menuAddObject.getItem());
	
	mycity.setTerritory("add_point_mkrn", "");
	
}
var createEditObject = function(point) {
	MC.Panel.Left.show();
	
	var menuAddObject = new MC.Item.MenuLeft("add_object", "Редактирование объекта", "#ffcc33");
		menuAddObject.show();
	
	var tabInfoObject = new MC.Item.Tab("add_object_info", "Информация", "Основная информация об объекте", "on");
		tabInfoObject.setTab(menuAddObject);
		tabInfoObject.addHtml(
			'<div style="padding:10px;">'+
				'<div class="notes"><p>Перед редактированием объекта, рекомендуем ознакомиться с <a title="Как изменить данные и положение объекта" target="_blank" href="http://mycity.kz">некоторыми моментами</a>.</p></div>'+
				htmlFieldsObject +
				'<div class="notes" style="margin-top:10px;"><p>Так же возможно изменить положение точки.</p><p>Для этого перетяните точку мышкой в новое положение, измените масштаб и угол поворота, если это необходимо.</p></div>'+
				'<div class="buttons" style="margin:5px 0 8px 0;"><div class="button" style="width:100%; text-align:center;"><input type="button" value="Сохранить" onclick="MC.Point.Edit.OK(this)"/></div></div>'+
			'</div>'
		);
		tabInfoObject.show();
	var tabOpinionObject = new MC.Item.Tab("add_object_opinion", "Отзывы", "Отзывы пользователей", "no");
		tabOpinionObject.setTab(menuAddObject);
	
	var panelLeft = $("#panel_left_container");
		panelLeft.appendChild(menuAddObject.getItem());
		
	mycity.setTerritory("add_point_mkrn", "", point.m == null ? -1 : point.m);
	
	$("#add_point_name").value = point.name;
	$("#add_point_home_1").value = point.h1;
	$("#add_point_home_2").value = point.h2;
	$("#add_point_korpus_1").value = point.k1;
	$("#add_point_korpus_2").value = point.k2;
	$("#inputCrossing_2_1").value = point.s1_name;
	$("#inputCrossing_2_2").value = point.s2_name;
	$("#add_point_office").value = point.office;
	$("#add_point_phone").value = point.phone;
	$("#add_point_fax").value = point.fax;
	$("#add_point_email").value = point.email;
	$("#add_point_web").value = point.web;
	$("#add_point_note").value = point.note;
	$("#add_point_otype").options[point.otype == null ? 0 : point.otype - 1].selected = true;
}
var createInfoObject = function(point) {
	MC.Panel.Left.show();
	
	var menuAddObject = new MC.Item.MenuLeft("add_object", point.name, "#ffcc33");
		menuAddObject.show();
	
	var tabInfoObject = new MC.Item.Tab("add_object_info", "Информация", "Основная информация об объекте", "on");
		tabInfoObject.setTab(menuAddObject);
		tabInfoObject.addHtml('<div style="padding:10px;"><div class="info_tab">'+point.info+'</div><br><div style="width: 50%; text-align: center; float:left;"><span onclick="back.temp.view.edit()" style="border-bottom:1px dashed #ffcc33; font:18px Tahoma,Arial,Verdana; color:#ffcc33; cursor:pointer; cursor:hand;">Изменить<span></div><div style="width: 50%; text-align: center; float: left;"><span style="border-bottom:1px dashed red; font:18px Tahoma,Arial,Verdana; color:red; cursor:pointer; cursor:hand;" onclick="back.temp.view.del()">Удалить</span></div></div>');
		tabInfoObject.show();
	var tabOpinionObject = new MC.Item.Tab("add_object_opinion", "Отзывы", "Отзывы пользователей", "no");
		tabOpinionObject.setTab(menuAddObject);
	
	var panelLeft = $("#panel_left_container");
		panelLeft.appendChild(menuAddObject.getItem());
}

MC.Load.onLoadFlash = function() {
//	swfmacmousewheel.registerObject("mycity");
	mycity = $("#mycity");
	if (isIE) {
		mycity.height = document.body.clientHeight - 24;
		MC.Event.add(window, "resize", function() {mycity.height = document.body.clientHeight - 24;});
	} else {
		mycity.height = document.body.clientHeight - 28;
		MC.Event.add(window, "resize", function() {mycity.height = document.body.clientHeight - 28;});
	}
	//
	MC.Tool = {
		Reminder: {
			temp: {},
			ok: function(o) {
			},
			cancel: function(o) {
				var node = o.parentNode.parentNode.parentNode;
					node.firstChild.childNodes[1].firstChild.value = "";
					node.firstChild.childNodes[3].firstChild.value = "";
					node.parentNode.parentNode.style.display = "none";
			}
		},
		Registration: {
			temp: {},
			ok: function(o) {
				var node = o.parentNode.parentNode.parentNode.firstChild.childNodes;
				this.temp = {
					login: node[1].firstChild,
					email: node[3].firstChild,
					pass1: node[5].firstChild,
					pass2: node[7].firstChild
				};
				var info = {
					login: this.temp.login.value,
					email: this.temp.email.value,
					pass1: this.temp.pass1.value,
					pass2: this.temp.pass2.value
				};
				mycity.registration(info);
			},
			cancel: function(o) {
				var node = o.parentNode.parentNode.parentNode;
					node.firstChild.childNodes[1].firstChild.value = "";
					node.firstChild.childNodes[3].firstChild.value = "";
					node.firstChild.childNodes[5].firstChild.value = "";
					node.firstChild.childNodes[7].firstChild.value = "";
					node.parentNode.parentNode.style.display = "none";
			}
		},
		Auth: {
			temp: {},		// объект входа
			onLogin: function(o, device) {
				var node = o.parentNode.parentNode.parentNode.firstChild.childNodes;
				var info = {
					login: node[1].firstChild.value,
					password: node[3].firstChild.value,
					memory: node[4].firstChild.checked,
					device: device
				};
				this.temp = {
					input_username: node[1].firstChild,
					input_password: node[3].firstChild
				};
				if (info.login.length == 0) {
					alert("Вы не ввели логин!");
					this.temp.input_username.focus();
					return;
				}
				if (info.password.length == 0) {
					alert("Вы не ввели пароль!");
					this.temp.input_password.focus();
					return;
				}
				mycity.logLogin(info);
			},
			loginOk: function() {
				toolAuthorization.hide();
				toolRegistration.hide();
				toolRemainPassword.hide();
			},
			onLogout: function() {
				mycity.logLogout();
				MC.Panel.Left.hide();
				toolAuthorization.show();
				toolRegistration.show();
				toolRemainPassword.show();
			},
			onKeyDown: function(o, event) {
				var keyCode = event.which == undefined ? event.keyCode : event.which;
				if (keyCode == 13) {		// Enter
					this.onLogin(o, false);
				}
			},
			onErrorLogin: function() {
				alert("Неверное сочетание логина и пароля.\nПопробуйте еще раз.");
				this.temp.input_username.value = "";
				this.temp.input_password.value = "";
				this.temp.input_username.focus();
			},
			onErrorLogout: function() {
				alert("Не удалось завершить сеанс!\nВозможно, сеанс еще не был открыт ;)");
			},
			onCancel: function(o) {
				var node = o.parentNode.parentNode.parentNode;
					node.childNodes[0].childNodes[1].firstChild.value = "";
					node.childNodes[0].childNodes[3].firstChild.value = "";
					node.childNodes[0].childNodes[4].firstChild.checked = false;
					node.parentNode.parentNode.style.display = "none";
			}
		},
		Snapshot: {
			setLink: function(link, tagret) {
				var a = $("#tool_snapshot_"+tagret+"_link");
					a.href = "img/snapshot/" + link + ".png";
					a.parentNode.style.display = "block";
			},
			setSize: function(value) {
				$("#tool_snapshot_size").innerHTML = value;
			},
			Save: {
				clickCancel: function(o) {
					o.parentNode.parentNode.parentNode.parentNode.parentNode.style.display = "none";
				},
				clickSave: function(o) {
					mycity.toolSnapshotSave();
					this.clickCancel(o);
				}
			},
			Send: {
				clickCancel: function(o) {
					o.parentNode.parentNode.parentNode.parentNode.parentNode.style.display = "none";
					$("#tool_send_mail").value = "Почта";
					$("#tool_send_note").value = "Комментарий к снимку";
				},
				clickSend: function(o) {
					var mail = $("#tool_send_mail");
					var note = $("#tool_send_note");
					// TODO: Проверить поля на валидность
					if (!emailExpr.test(mail.value)) {
						alert("Неверный формат электронной почты!");
						mail.select();
 						mail.focus();
						return;
					}
					mycity.toolSnapshotSend(mail.value, note.value);
					this.clickCancel(o);
				}
			}
		},
		Cursor: {
			click: function(o) {
				if (o.checked) {
					mycity.toolCursorCheck(o.value);
				}
			},
			check: function(n) {
				var cursor = $("#tool_cursor_radio_" + n);
					cursor.checked = true;
			}
		},
		Control: {
			click: function(o) {
				if (o.checked) {
					mycity.toolControlCheck(o.value);
				}
			},
			check: function(n) {
				var control = $("#tool_control_radio_" + n);
					control.checked = true;
			}
		},
		Crossing: {
			// _1_ — Для инструмента "Поиск перекрёстка"
			temp_1_1:"", select_1_1:null, id_1_1:null,
			temp_1_2:"", select_1_2:null, id_1_2:null,
			// _2_ — Для опции "Добавиление нового объекта"
			temp_2_1:"", select_2_1:null, id_2_1:null,
			temp_2_2:"", select_2_2:null, id_2_2:null,
			// functions
			onFocus: function(o, m, n) {
				o.value = o.value.replace(/\s[^ ]+\.$/g, "");	// отбрасывает в конце префикс с точкой " ул."
				$("#div_crossing_"+m+"_"+n).style.display = "block";
				$("#inputCrossing_"+m+"_"+n).className = "street normal";
				var select = this["select_"+m+"_"+n];
				var lenght = select != null ? select.parentNode.lenght : 0;
				if (o.value == "" && lenght == 0) {
					this.message(m, n, "Введите название улицы");
				}
				this.onKeyUp(o, m, n);
			},
			onBlur: function(o, m, n) {
				var div = $("#div_crossing_"+m+"_"+n);
				if (div.style.display == 'block') {
					div.style.display = 'none';
					if (o.value.trim() == "") {
						mycity.removeCrossing2();	//отчистка второй линии и значений
						this["select_"+m+"_"+n] = null;
					} else {
						var select = MC.Tool.Crossing["select_"+m+"_"+n];
						if (select != null) {
							var d = select.data;
							var v = d.name.replace(/<\/?em>/gi ,"");
							var input = $("#inputCrossing_"+m+"_"+n);
								input.className = "street select";
								input.value = v;
							var value = o.value;
							if (value != this["temp_"+m+"_"+n] || d.id != this["id_"+m+"_"+n]) {
								this["temp_"+m+"_"+n] = value;
								this["id_"+m+"_"+n] = d.id;
								mycity["viewCrossroad"+n](m, d.id);
							}
						}
					}
				}
			},
			onKeyUp: function(o, m, n) {
				var value = o.value;
				if (value != this["temp_"+m+"_"+n]) {
					this["temp_"+m+"_"+n] = value;
					mycity.toolCrossingSearch(value, m, n);
				}
			},
			onKeyDown: function(o, m, n, event) {
				var div = $("#div_crossing_"+m+"_"+n);
				var keyCode = event.which == undefined ? event.keyCode : event.which;
				if (keyCode == 9) {
					return;
				}
				this.onFocus(o, m, n);
				if (keyCode == 13) {		// Enter
					this.onBlur(o, m, n);
				} else if (keyCode == 27) {	// Esc
					div.style.display = 'none';
				} else if (keyCode == 38 || keyCode == 40) {
				//	this.onFocus(o, n);
					var select = MC.Tool.Crossing["select_"+m+"_"+n];
					var count = select.count;
					var lenght= select.parentNode.lenght;
					var bool = keyCode == 38 ? count > 0 : count < lenght-1;
					if (bool) {
						var znak = keyCode == 38 ? -1 : 1;
						select.className = "typeahead_suggestion";
						var item = $("#crossing_item_"+m+"_"+n+"_"+(count+znak));
							item.className = "typeahead_suggestion typeahead_selected";
						MC.Tool.Crossing["select_"+m+"_"+n] = item;
					}
				}
			},
			call: function(m, n, a) {
				if (a.length != 0) {
					var div = document.createElement("div");
						div.style.height = "auto";
						div.style.width = "auto";
						div.lenght = a.length;
					for (var i = 0; i < a.length; i++) {
						var name = document.createElement("div");
							name.innerHTML = "<div>"+a[i].name+"</div>";
						var note = document.createElement("div");
							note.innerHTML = "<div><small>"+a[i].note+" </small></div>";
						var item = document.createElement("div");
							item.count = i;
							item.id = "crossing_item_"+m+"_"+n+"_"+i;
							item.data = a[i];
							item.className = "typeahead_suggestion" + (i == 0 ? "  typeahead_selected" : "");
							item.onmouseover = function() {
								MC.Tool.Crossing["select_"+m+"_"+n].className = "typeahead_suggestion";
								MC.Tool.Crossing["select_"+m+"_"+n] = this;
								this.className = "typeahead_suggestion typeahead_selected";
							};
							item.appendChild(name);
							item.appendChild(note);
						if (i == 0) {
							MC.Tool.Crossing["select_"+m+"_"+n] = item;
						}
						div.appendChild(item);
					}
					var sub = document.createElement("div");
						sub.appendChild(div);
					var crossing = $("#div_crossing_"+m+"_"+n);
						crossing.removeChild(crossing.firstChild);
						crossing.appendChild(sub);
				} else {
					this.message(n, "Совпадений не найдено");
				}
			},
			message: function(m, n, msg) {
				var div = document.createElement("div");
					div.className = "typeahead_message";
					div.innerHTML = msg;
				var sub = document.createElement("div");
					sub.appendChild(div);
				var crossing = $("#div_crossing_"+m+"_"+n);
					crossing.removeChild(crossing.firstChild);
					crossing.appendChild(sub);
			}
		},
		Address: {
			one: function(o) {
				
			},
			two: function(o) {
				
			}
		}
	};
	MC.Point = {
		temp: null,
		Add: {
			OK: function(o) {
				var eName = $("#add_point_name");
				var vName = eName.value.trim();
				if (vName == "") {
					alert("Вы не ввели наименование объекта!");
					eName.value = "";
 					eName.focus();
					return;
				}
				var data = {
					name: vName,
					mkrn: $("#add_point_mkrn").value.trim(),
					home1: $("#add_point_home_1").value.trim(),
					korpus1: $("#add_point_korpus_1").value.trim(),
					office: $("#add_point_office").value.trim(),
					otype: $("#add_point_otype").value.trim(),
					home2: $("#add_point_home_2").value.trim(),
					korpus2: $("#add_point_korpus_2").value.trim(),
					phone: $("#add_point_phone").value.trim(),
					fax: $("#add_point_fax").value.trim(),
					email: $("#add_point_email").value.trim(),
					web: $("#add_point_web").value.trim(),
					note: $("#add_point_note").value.trim()
				};
				mycity.addPoint(data);
			}
		},
		Edit: {
			OK: function(o) {
				var eName = $("#add_point_name");
				var vName = eName.value.trim();
				if (vName == "") {
					alert("Вы не ввели наименование объекта!");
					eName.value = "";
 					eName.focus();
					return;
				}
				var data = {
					name: vName,
					mkrn: $("#add_point_mkrn").value.trim(),
					home1: $("#add_point_home_1").value.trim(),
					korpus1: $("#add_point_korpus_1").value.trim(),
					office: $("#add_point_office").value.trim(),
					otype: $("#add_point_otype").value.trim(),
					home2: $("#add_point_home_2").value.trim(),
					korpus2: $("#add_point_korpus_2").value.trim(),
					phone: $("#add_point_phone").value.trim(),
					fax: $("#add_point_fax").value.trim(),
					email: $("#add_point_email").value.trim(),
					web: $("#add_point_web").value.trim(),
					note: $("#add_point_note").value.trim(),
					id: back.temp.edit._list.id
				};
				mycity.updatePoint(data);
			}
		}
	};
	MC.Place = {
		temp: null,
		Add: {
			clickCancel: function(o) {
				o.parentNode.parentNode.parentNode.parentNode.parentNode.style.display = "none";
				$("#add_place_name").value = "";
				$("#add_place_note").value = "";
			},
			clickAdd: function(o) {
				var name = $("#add_place_name");
				var note = $("#add_place_note");
				// TODO: Проверить поля на валидность
				if (name.value == "") {
					alert("Вы не ввели название метки!");
 					name.focus();
					return;
				}
				if (note.value == "") {
					alert("Вы не ввели комментарий к метке!");
 					note.focus();
					return;
				}
				mycity.addPlace(name.value, note.value);
				this.clickCancel(o);
			}
		}
	};
	MC.Open = {
		tabAuthorization: function() {
			mycity.toolMenuHide();
			MC.Panel.Right.show();
			mc_menu[6][0].show();
			mc_menu[6][1].show();
			toolAuthorization.openItem();
			toolRegistration.closeItem();
			toolRemainPassword.closeItem();
		},
		tabRegistration: function() {
			mycity.toolMenuHide();
			MC.Panel.Right.show();
			mc_menu[6][0].show();
			mc_menu[6][1].show();
			toolAuthorization.closeItem();
			toolRegistration.openItem();
			toolRemainPassword.closeItem();
		},
		tabRemainPassword: function() {
			mycity.toolMenuHide();
			MC.Panel.Right.show();
			mc_menu[6][0].show();
			mc_menu[6][1].show();
			toolAuthorization.closeItem();
			toolRegistration.closeItem();
			toolRemainPassword.openItem();
		},
		authTabPlaces: function() {
			mycity.toolMenuHide();
			MC.Panel.Right.show();
			mc_menu[2][0].show();
			mc_menu[2][1].show();
			toolAuthPlace.openItem();
		},
		authTabFavors: function() {
			mycity.toolMenuHide();
			MC.Panel.Right.show();
			mc_menu[2][0].show();
			mc_menu[2][2].show();
			toolAuthFavor.openItem();
		},
		tabPlaces: function() {
			mycity.toolMenuHide();
			MC.Panel.Right.show();
			mc_menu[2][0].show();
			mc_menu[2][1].show();
		},
		tabFavors: function() {
			mycity.toolMenuHide();
			MC.Panel.Right.show();
			mc_menu[2][0].show();
			mc_menu[2][2].show();
		},
		tabPoints: function() {
			mycity.toolMenuHide();
			MC.Panel.Right.show();
			mc_menu[1][0].show();
			mc_menu[1][2].show();
		}
	};
	
	createPanelRight();
//	createAddObject();
	
	MC.Panel.Top.show();
	MC.Panel.Right.show();
	
	mycity.setTerritory("selectTerritory", "Выберите микрорайон...");
	mycity.setDistrict("selectDistrict", "Выберите адм. район...");
//	mycity.getPoints(4);
	
	if (user.id != "") {
		MC.Tool.Auth.loginOk();
	}
};
MC.Event.add(window, "load", function(){MC.Load.onLoadBody();});
// -------------------------------------------------------------------------------------------------------------------
// TOOLS
// -------------------------------------------------------------------------------------------------------------------
var tool1 = new MC.Item.Tool('Элементы навигации');
	tool1.setLink('http://mycity.kz/help/#tool1');
	tool1.setNote('Настройте режим отображение элементов навигации карты');
	tool1.setFocus("childNodes[0].firstChild");
	tool1.setHtml(
		'<div style="float:left;"><input type="radio" name="tool_control" value="1" id="tool_control_radio_1" onclick="MC.Tool.Control.click(this)" style="margin-right:6px;"/></div>'+
		'<div style="padding-top:3px;"><label for="tool_control_radio_1">Скрывать автоматически</label></div>'+
		'<div style="float:left;"><input type="radio" name="tool_control" value="2" id="tool_control_radio_2" onclick="MC.Tool.Control.click(this)" style="margin-right:6px;"/></div>'+
		'<div style="padding-top:3px;"><label for="tool_control_radio_2">Всегда скрывать</label></div>'+
		'<div style="float:left;"><input type="radio" name="tool_control" value="3" id="tool_control_radio_3" onclick="MC.Tool.Control.click(this)" style="margin-right:6px;"/></div>'+
		'<div style="padding-top:3px;"><label for="tool_control_radio_3">Всегда отображать</label></div>'
	);
var tool2 = new MC.Item.Tool('Указатель');
	tool2.setLink('http://mycity.kz/help/#tool2');
	tool2.setNote('Веберите удобный для вас указатель центра карты');
	tool2.setFocus("firstChild.childNodes[1].childNodes[2]");
	tool2.setHtml(
		'<div style="height:45px">'+
			'<div style="float:left; width:2%;">&nbsp;</div>'+
			'<div style="float:left; width:16%; height:30px; text-align:center;"><label for="tool_cursor_radio_1"><img style="padding-bottom:15px; width:14px; height:14px;" src="./res/cursor/1.gif" title="Крест"/></label>		<br/><input style="margin-left:1px" type="radio" onclick="MC.Tool.Cursor.click(this)" id="tool_cursor_radio_1" value="1" title="Крест"/></div>'+
			'<div style="float:left; width:16%; height:30px; text-align:center;"><label for="tool_cursor_radio_2"><img style="padding-bottom:15px; width:14px; height:14px;" src="./res/cursor/2.gif" title="Кольцо"/></label>		<br/><input style="margin-left:1px" type="radio" onclick="MC.Tool.Cursor.click(this)" id="tool_cursor_radio_2" value="2" title="Кольцо"/></div>'+
			'<div style="float:left; width:16%; height:30px; text-align:center;"><label for="tool_cursor_radio_3"><img style="padding-bottom:15px; width:14px; height:14px;" src="./res/cursor/3.gif" title="Квадрат"/></label>		<br/><input style="margin-left:1px" type="radio" onclick="MC.Tool.Cursor.click(this)" id="tool_cursor_radio_3" value="3" title="Квадрат"/></div>'+
			'<div style="float:left; width:16%; height:30px; text-align:center;"><label for="tool_cursor_radio_4"><img style="padding-bottom:15px; width:14px; height:14px;" src="./res/cursor/4.gif" title="Ромб"/></label>		<br/><input style="margin-left:1px" type="radio" onclick="MC.Tool.Cursor.click(this)" id="tool_cursor_radio_4" value="4" title="Ромб"/></div>'+
			'<div style="float:left; width:16%; height:30px; text-align:center;"><label for="tool_cursor_radio_5"><img style="padding-bottom:15px; width:14px; height:14px;" src="./res/cursor/5.gif" title="Точка"/></label>		<br/><input style="margin-left:1px" type="radio" onclick="MC.Tool.Cursor.click(this)" id="tool_cursor_radio_5" value="5" title="Точка"/></div>'+
			'<div style="float:left; width:16%; height:30px; text-align:center;"><label for="tool_cursor_radio_0"><img style="padding-bottom:15px; width:14px; height:14px;" src="./res/cursor/0.gif" title="Отсутствует"/></label>	<br/><input style="margin-left:1px" type="radio" onclick="MC.Tool.Cursor.click(this)" id="tool_cursor_radio_0" value="0" title="Отсутствует"/></div>'+
			'<div style="float:left; width:2%;">&nbsp;</div>'+
		'</div>'
	);
var tool3 = new MC.Item.Tool('Сохранить снимок');
	tool3.setStatus('news');
	tool3.setLink('http://mycity.kz/help/#tool3');
	tool3.setNote('Сохраните снимок фрагмента карты в растровом формате <a href="http://ru.wikipedia.org/wiki/PNG" target="_blank" title="Материал из Википедии">PNG</a> себе на ПК или на наш сервер и получите ссылку.');
	tool3.setFocus("childNodes[1].firstChild.firstChild");
	tool3.setHtml(
		'<div class="labels">'+
			'<div class="label_l">Текущие размеры:</div>'+
			'<div class="label_r" id="tool_snapshot_size">&nbsp;&nbsp;</div>'+
		'</div>'+
		'<div class="buttons">'+
			'<div class="button" style="text-align: left"><input type="button" value="Сохранить" onclick="MC.Tool.Snapshot.Save.clickSave(this)"/></div>'+
			'<div class="button" style="text-align:right"><input type="button" value="Отмена" onclick="MC.Tool.Snapshot.Save.clickCancel(this)"/></div>'+
		'</div>'+
		'<div class="links" style="display:none">'+
			'<a title="Время жизни - 10 дней" href="#" target="_blank" id="tool_snapshot_save_link">Ссылка на последний<br>сохранённый вами снимок</a>'+
		'</div>'
	);
var tool4 = new MC.Item.Tool('Отправить снимок');
	tool4.setStatus('beta');
	tool4.setLink('http://mycity.kz/help/#tool4');
	tool4.setNote('Сохраните снимок у себя на почте или отправьте другу c комментарием.');
	tool4.setFocus("firstChild.firstChild");
	tool4.setHtml(
		'<div class="tfields">'+
			'<input class="name" type="text" maxlength="50" value="Почта" title="Электронная почта" id="tool_send_mail"/>'+
			'<textarea rows="3" title="Комментарий к снимку" id="tool_send_note"></textarea>'+
		'</div>'+
		'<div class="buttons">'+
			'<div class="button" style="text-align: left"><input type="button" value="Отправить" onclick="MC.Tool.Snapshot.Send.clickSend(this)"/></div>'+
			'<div class="button" style="text-align:right"><input type="button" value="Отмена" onclick="MC.Tool.Snapshot.Send.clickCancel(this)"/></div>'+
		'</div>'+
		'<div class="links" style="display:none">'+
			'<a title="Время жизни - 10 дней" href="#" target="_blank" id="tool_snapshot_send_link">Ссылка на последний<br>отправленный вами снимок</a>'+
		'</div>'
	);
var tool7 = new MC.Item.Tool('Поиск перекрестка');
	tool7.setStatus('beta');
	tool7.setLink('http://mycity.kz/help/#tool7');
	tool7.setNote('Выберите две пересекающиеся улицы...');
	tool7.setHtml(
		'<div class="tfields">'+
			'<div><input type="text" id="inputCrossing_1_1" class="street" autocomplete="off" maxlength="30" title="Введите первые буквы улицы"'+
				'onfocus = "MC.Tool.Crossing.onFocus(this,1,1)" '+
				'onblur  = "MC.Tool.Crossing.onBlur (this,1,1)" '+
				'onkeyup = "MC.Tool.Crossing.onKeyUp(this,1,1)" '+
				'onkeydown="MC.Tool.Crossing.onKeyDown(this,1,1,event)"/></div>'+
			'<div id="div_crossing_1_1" class="typeahead_list" style="height:auto; width:100%; max-width:178px; display:none;"><div></div></div>'+
			'<div><input type="text" id="inputCrossing_1_2" class="street" autocomplete="off" maxlength="30" title="Выберите или введите нужный перекрёсток" style="margin-top:10px"'+
				'onfocus = "MC.Tool.Crossing.onFocus(this,1,2)" '+
				'onblur  = "MC.Tool.Crossing.onBlur (this,1,2)" '+
				'onkeyup = "MC.Tool.Crossing.onKeyUp(this,1,2)" '+
				'onkeydown="MC.Tool.Crossing.onKeyDown(this,1,2,event)"/></div>'+
			'<div id="div_crossing_1_2" class="typeahead_list" style="height:auto; width:100%; max-width:178px; display:none;"><div></div></div>'+
		'</div>'
	);
var tool8 = new MC.Item.Tool('Поиск районов');
	tool8.setLink('http://mycity.kz/help/#tool8');
	tool8.setNote('Выберите из списка искомый район, микрорайон, посёлок или территорию');
	tool8.setHtml(
		'<div class="tfields">'+
			'<div style="margin-bottom:10px">'+
				'<select type="combobox" id="selectDistrict"  onchange="mycity.viewDistrict(this.value)"  title="Выберите из списка административный район"></select></div>'+
			'<div>'+
				'<select type="combobox" id="selectTerritory" onchange="mycity.viewTerritory(this.value)" title="Выберите из списка микрорайон или посёлок"></select></div>'+
		'</div>'
	);
var toolAddPoint = new MC.Item.Tool('Добавить новую точку');
	toolAddPoint.setIcon('res/icons/add.gif');
	toolAddPoint.setLink('http://mycity.kz/help/#add-new-point');
	toolAddPoint.setNote('Для добавления новой точки в эту категорию, заполните базовую форму.');
	toolAddPoint.setFocus("firstChild.firstChild");
	toolAddPoint.setHtml(
		'<div class="buttons" style="margin:0;">'+
			'<div class="button" style="text-align:center; width:100%;"><input type="button" value="Перейти к форме" onclick="createAddObject()"/></div>'+
		'</div>'
	);
var toolAddPlace = new MC.Item.Tool('Добавить новую метку');
	toolAddPlace.setIcon('res/icons/add.gif');
	toolAddPlace.setLink('http://mycity.kz/help/#add-new-place');
	toolAddPlace.setNote('Выставите цетр карты в нужное вам положение. Введите название и комментарий к метке.');
	toolAddPlace.setFocus("firstChild.firstChild");
	toolAddPlace.setHtml(
		'<div class="tfields">'+
			'<input class="name" type="text" maxlength="50" value="" title="Название метки" id="add_place_name"/>'+
			'<textarea rows="3" title="Комментарий к метке" id="add_place_note"></textarea>'+
		'</div>'+
		'<div class="buttons">'+
			'<div class="button" style="text-align: left"><input type="button" value="Добавить" onclick="MC.Place.Add.clickAdd(this)"/></div>'+
			'<div class="button" style="text-align:right"><input type="button" value="Отмена" onclick="MC.Place.Add.clickCancel(this)"/></div>'+
		'</div>'
	);
var toolAddFavor = new MC.Item.Tool('Добавить в избранное');
	toolAddFavor.setIcon('res/icons/add.gif');
	toolAddFavor.setLink('http://mycity.kz/help/#add-to-favorites');
	toolAddFavor.setNote('Чтобы добавить объект в избранное, нажмите на "Добавить в избранное" в объектах добавяемой точки (иконка звёздочки).');
// -------------------------------------------------------------------------------------------------------------------
var htmlAuthorization = 
	'<div class="tfields">'+
		'<div style="padding-top:4; float:left; width:50"><label for="inputAuthUsername">Логин:</label></div>'+
		'<div style="padding-left:50;"><input type="text" value="demo" id="inputAuthUsername" maxlength="50" class="street" onkeydown="MC.Tool.Auth.onKeyDown(this, event)"/></div>'+
		'<div style="padding-top:14; float:left; width:50"><label for="inputAuthPassword">Пароль:</label></div>'+
		'<div style="padding:10 0 0 50;"><input type="password" value="demo" id="inputAuthPassword" maxlength="50" class="street" onkeydown="MC.Tool.Auth.onKeyDown(this, event)"/></div>'+
		'<div style="padding:10 5 0 50; float:left;"><input disabled type="checkbox" id="checkboxAuthSave" onkeydown="MC.Tool.Auth.onKeyDown(this, event)"/></div>'+
		'<div style="padding-top:13;"><label for="checkboxAuthSave">Запомнить меня</label></div>'+
	'</div>'+
	'<div class="buttons">'+
		'<div class="button" style="text-align: left"><input type="button" value="Вход" onclick="MC.Tool.Auth.onLogin(this, true)"/></div>'+
		'<div class="button" style="text-align:right"><input type="button" value="Отмена" onclick="MC.Tool.Auth.onCancel(this)"/></div>'+
	'</div>'+
	'<div class="links"><a onclick="MC.Open.tabRegistration()">Регистрация</a><span class="sprt"> | </span><a onclick="MC.Open.tabRemainPassword()">Забыли пароль</a></div>';
var toolAuthPlace = new MC.Item.Tool('Авторизация');
	toolAuthPlace.setLink('http://mycity.kz/help/#authorization');
	toolAuthPlace.setNote('Для доступа к личным меткам Вам необходимо авторизироваться.');
	toolAuthPlace.setHtml(htmlAuthorization);
	toolAuthPlace.setFocus("firstChild.childNodes[1].firstChild");
var toolAuthFavor = new MC.Item.Tool('Авторизация');
	toolAuthFavor.setLink('http://mycity.kz/help/#authorization');
	toolAuthFavor.setNote('Для доступа к избранным точкам Вам необходимо авторизироваться.');
	toolAuthFavor.setHtml(htmlAuthorization);
	toolAuthFavor.setFocus("firstChild.childNodes[1].firstChild");
var toolAuthorization = new MC.Item.Tool('Авторизация');
	toolAuthorization.setLink('http://mycity.kz/help/#authorization');
	toolAuthorization.setNote('Чтобы получить доступ к личным настройкам и к другим функциям проекта, вам необходимо авторизироваться.');
	toolAuthorization.setHtml(htmlAuthorization);
	toolAuthorization.setFocus("firstChild.childNodes[1].firstChild");
var toolRegistration = new MC.Item.Tool('Регистрация');
	toolRegistration.setStatus('soon');
	toolRegistration.setLink('http://mycity.kz/help/#registration');
	toolRegistration.setNote('Если вы еще не зарегистрированы, сделайте это, и у вас будет гораздо больше удобств и привилегий.');
	toolRegistration.setFocus("firstChild.childNodes[1].firstChild");
	toolRegistration.setHtml(
		'<div class="tfields">'+
			'<div style="padding-top:4; float:left; width:50"><label for="loginRegistration">Логин:</label></div>'+
			'<div style="padding-left:50;"><input type="text" id="loginRegistration" maxlength="50" class="street" disabled/></div>'+
			'<div style="padding-top:14; float:left; width:50"><label for="emailRegistration">E-mail:</label></div>'+
			'<div style="padding:10 0 0 50;"><input type="text" id="emailRegistration" maxlength="90" class="street" disabled title="Для уведомлений и восстановления пароля"/></div>'+
			'<div style="padding-top:14; float:left; width:50"><label for="passwordRegistration">Пароль:</label></div>'+
			'<div style="padding:10 0 0 50;"><input type="password" id="passwordRegistration" maxlength="50" class="street" disabledtitle="Рекомендуем использовать пароль не менее чем из 6 символов"/></div>'+
			'<div style="padding-top:14; float:left; width:50"><label for="repeatRegistration">Повтор:</label></div>'+
			'<div style="padding:10 0 0 50;"><input type="password" id="repeatRegistration" maxlength="50" class="street" disabledtitle="Повторите пароль"/></div>'+
		'</div>'+
		'<div class="buttons">'+
			'<div class="button" style="text-align: left"><input type="button" value="OK" onclick="MC.Tool.Registration.ok(this)" disabled/></div>'+
			'<div class="button" style="text-align:right"><input type="button" value="Отмена" onclick="MC.Tool.Registration.cancel(this)"/></div>'+
		'</div>'+
		'<div class="links"><a onclick="MC.Open.tabAuthorization()">Авторизация</a><span class="sprt"> | </span><a onclick="MC.Open.tabRemainPassword()">Забыли пароль</a></div>'
	);
var toolRemainPassword = new MC.Item.Tool('Забыли пароль');
	toolRemainPassword.setStatus('soon');
	toolRemainPassword.setLink('http://mycity.kz/help/#remain-password');
	toolRemainPassword.setNote('Введите логин и E-mail указанный в настройках вашего профиля, и мы пришлём инструкцию для создания нового пароля.');
	toolRemainPassword.setFocus("firstChild.childNodes[1].firstChild");
	toolRemainPassword.setHtml(
		'<div class="tfields">'+
			'<div style="padding-top:4; float:left; width:50px"><label for="usernameRemainPassword">Логин:</label></div>'+
			'<div style="padding-left:50;"><input type="text" id="usernameRemainPassword" maxlength="50" class="street" disabled/></div>'+
			'<div style="padding-top:14; float:left; width:50px"><label for="emailRemainPassword">E-mail:</label></div>'+
			'<div style="padding:10px 0 0 50px;"><input type="password" id="emailRemainPassword" maxlength="50" class="street" disabled/></div>'+
		'</div>'+
		'<div class="buttons"><div class="button" style="text-align:left"><input type="button" value="OK" onclick="" disabled/></div><div class="button" style="text-align:right"><input type="button" value="Отмена" onclick="MC.Tool.Reminder.cancel(this)"/></div></div>'+
		'<div class="links"><a onclick="MC.Open.tabAuthorization()">Авторизация</a><span class="sprt"> | </span><a onclick="MC.Open.tabRegistration()">Регистрация</a></div>'
	);
var htmlFieldsObject = 
'<div class="editing">'+
	'<div class="label"><label for="add_point_name">Наименование</label></div>'+
	'<div class="input"><input id ="add_point_name" type="text" title="Введите наименование объекта" maxlength="100"/></div>'+
	'<div class="label"><label for="add_point_mkrn">Микрорайон</label></div>'+
	'<div class="input"><select id="add_point_mkrn" type="combobox" title="Выберите из списка микрорайон или посёлок" onchange="mycity.viewTerritory(this.value)"></select></div>'+
	// Улица, дом, корпус, офис
	'<div class="label"><label for="inputCrossing_2_1">Улица</label></div>'+
	'<div class="input">'+
		'<div><input type="text" id="inputCrossing_2_1" class="street" autocomplete="off" maxlength="30" title="Введите первые буквы улицы"'+
			'onfocus = "MC.Tool.Crossing.onFocus(this,2,1)" '+
			'onblur  = "MC.Tool.Crossing.onBlur (this,2,1)" '+
			'onkeyup = "MC.Tool.Crossing.onKeyUp(this,2,1)" '+
			'onkeydown="MC.Tool.Crossing.onKeyDown(this,2,1,event)"/></div>'+
		'<div id="div_crossing_2_1" class="typeahead_list" style="height:auto; width:100%; max-width:178px; display:none;"><div></div></div>'+
	'</div>'+
	'<div class="label"><label for="add_point_home_1">Дом</label></div>'+
	'<div class="input">'+
		'<div style="width:35%; float:left;"><input id ="add_point_home_1" type="text" maxlength="5" class="name"/></div>'+
		'<div style="width:30%; float:left; text-align:center;" class="label"><label for="add_point_korpus_1"> , корпус </label></div>'+
		'<div style="width:35%; float:left;"><input type="text" id="add_point_korpus_1" maxlength="5" class="name"/></div>'+
	'</div>'+
	'<div class="label"><label for="add_point_office">Апартаменты</label></div>'+
	'<div class="input"><div style="width:35%; float:left;"><input id ="add_point_office" type="text" maxlength="5" class="name"/></div><div style="width:5%; float:left;">&#160</div><div style="width:60%; float:left;"><select id="add_point_otype" type="combobox" style="padding:2px 0 0 2px"><option value="0"></option><option value="1">офис</option><option value="2">кабинет</option><option value="3">квартира</option><option value="4">этаж</option><option value="5">подвал</option><option value="6">здание</option></select></div></div>'+
	// Перекрёсток, дом, корпус
	'<div class="label"><label for="inputCrossing_2_2">Перекрёсток</label></div>'+
	'<div class="input">'+
		'<div><input type="text" id="inputCrossing_2_2" class="street" autocomplete="off" maxlength="30" title="Выберите или введите нужный перекрёсток" '+
			'onfocus = "MC.Tool.Crossing.onFocus(this,2,2)" '+
			'onblur  = "MC.Tool.Crossing.onBlur (this,2,2)" '+
			'onkeyup = "MC.Tool.Crossing.onKeyUp(this,2,2)" '+
			'onkeydown="MC.Tool.Crossing.onKeyDown(this,2,2,event)"/></div>'+
		'<div id="div_crossing_2_2" class="typeahead_list" style="height:auto; width:100%; max-width:178px; display:none;"><div></div></div>'+
	'</div>'+
	'<div class="label"><label for="add_point_home_2">Дом</label></div>'+
	'<div class="input">'+
		'<div style="width:35%; float:left;"><input id ="add_point_home_2" type="text" maxlength="5" class="name"/></div>'+
		'<div style="width:30%; float:left; text-align:center;" class="label"><label for="add_point_korpus_2"> , корпус </label></div>'+
		'<div style="width:35%; float:left;"><input type="text" id="add_point_korpus_2" maxlength="5" class="name"/></div>'+
	'</div>'+
	// Телефон, факс, емаил, веб
	'<div class="label"><label for="add_point_phone">Телефон</label></div>'+
	'<div class="input"><input id ="add_point_phone" type="text" maxlength="100" title="Телефоны в формате: 8-ХХХ-ХХХХХХХ, ХХХ-ХХ-ХХ"/></div>'+
	'<div class="label"><label for="add_point_fax">Факс</label></div>'+
	'<div class="input"><input id ="add_point_fax" type="text" maxlength="100" title="Номер вашего факс"/></div>'+
	'<div class="label"><label for="add_point_email">E-mail</label></div>'+
	'<div class="input"><input id ="add_point_email" type="text" maxlength="100" title="Электронная почта"/></div>'+
	'<div class="label"><label for="add_point_web">Web</label></div>'+
	'<div class="input"><input id ="add_point_web" type="text" maxlength="100" title="Адрес сайта или страницы в интернете"/></div>'+
	'<div class="label"><label for="add_point_note">Комментарий</label><br/><span>255 символов</span></div>'+
	'<div class="input"><textarea id ="add_point_note" rows="3" title="Любой текстовый комментарий (например: режим работы, как пройти, здание …)"></textarea></div>'+
'</div>';
