﻿var img_loaded = 0;
var copy_x;
var copy_y;
var change_pic_buffer = new Array();
var gnus_info_opened=1;
var panel_position;
var opened_plan_sh_elem = new Array();
var currentModal = new Object ();
var user_position_text = '';

Draggables.addObserver({onStart: function (v, drag, ev)
											{
												if (Element.hasClassName(drag.element, 'win_passive_window'))
												{
													Wins.activate (drag.element.id);
												};
												if (Element.hasClassName(drag.element, 'default_win'))
												{
													$(drag.element.id+'_content').style.visibility='hidden';
													drag.element.style.opacity='0.6';
												};

												if (Element.hasClassName(drag.element, 'chulan_class'))
												{
													if (!window.allow_drop && !window.return_item)
														Draggables.endDrag ();
													else
													{
														drag.element.style.top = '5000px';
														document.body.appendChild(drag.element);
														els = $('chulan').getElementsByClassName ('chulan_class');
														if (!els.length)
															$('chulan_empty_text').style.display = '';
													};
												};

												if (Element.hasClassName(drag.element, 'copy_class'))
												{
													if ($('plan_view'))
														ob = $('ppi'+drag.element.id.substr(3));
													else
														ob = $('pic'+drag.element.id.substr(3));
													imgcopy=document.createElement('IMG');
													imgcopy.id="cpi"+ob.id.substr(3);
													imgcopy.src=ob.src;
													imgcopy.width=drag.element.width;
													imgcopy.height=drag.element.height;
													imgcopy.style.position="absolute";
													imgcopy.style.left=drag.element.style.left;
													imgcopy.style.top=drag.element.style.top;
													imgcopy.style.zIndex=parseInt(ob.style.zIndex)-1;
													drag.element.parentNode.appendChild(imgcopy);
													copy_x = drag.element.style.left;
													copy_y = drag.element.style.top;

													drag.element.style.zIndex=parseInt(drag.element.style.zIndex)+600;
													$('cpi' + drag.element.id.substr(3)).style.zIndex=parseInt($('cpi' + drag.element.id.substr(3)).style.zIndex)+600;
													if (!$('chulan_win'))
														openWin($('open_chulan'), {no_update: true, win_options: {width: 300, title: 'Портфель'}});
												}
												else if (Element.hasClassName(drag.element, 'movable_class'))
												{
													$('ppi' + drag.element.id.substr(3)).style.zIndex=parseInt($('ppi' + drag.element.id.substr(3)).style.zIndex)+600;
													drag.element.style.zIndex=parseInt(drag.element.style.zIndex)+600;
													if (Element.hasClassName (drag.element, 'user_sell'))
													{
														window.reverse_position_left = $('ppi' + drag.element.id.substr(3)).style.left;
														window.reverse_position_top = $('ppi' + drag.element.id.substr(3)).style.top;
														if (!$('chulan_win'))
															openWin($('open_chulan'), {no_update: true, win_options: {width: 300, title: 'Портфель'}});
													};
												};

												if (Element.hasClassName(drag.element, 'musor_class'))
												{
													$('pic' + drag.element.id.substr(3)).style.zIndex=parseInt($('pic' + drag.element.id.substr(3)).style.zIndex)+600;
													drag.element.style.zIndex=parseInt(drag.element.style.zIndex)+600;

													if (!$('chulan_win'))
														openWin($('open_chulan'), {no_update: true, win_options: {width: 300, title: 'Портфель'}});
												};

											},
						onDrag: function (v, drag, ev)
											{

												if (Element.hasClassName(drag.element, 'copy_class'))
												{
													$('cpi' + drag.element.id.substr(3)).style.left=drag.element.style.left;
													$('cpi' + drag.element.id.substr(3)).style.top=drag.element.style.top;
												}
												else if (Element.hasClassName(drag.element, 'movable_class'))
												{
													if ($('ppi' + drag.element.id.substr(3)))
													{
														$('ppi' + drag.element.id.substr(3)).style.left=drag.element.style.left;
														$('ppi' + drag.element.id.substr(3)).style.top=drag.element.style.top;
													};
												};
												
												if (Element.hasClassName(drag.element, 'musor_class'))
												{
													if ($('pic' + drag.element.id.substr(3)))
													{
														$('pic' + drag.element.id.substr(3)).style.left=drag.element.style.left;
														$('pic' + drag.element.id.substr(3)).style.top=drag.element.style.top;
													};
												};
											},
						onEnd: function(v, drag, ev)
											{
												if (Element.hasClassName(drag.element, 'default_win'))
												{
												 	$(drag.element.id+'_content').style.visibility='';
												 	drag.element.style.opacity='';
												};
												if (Element.hasClassName(drag.element, 'copy_class'))
												{
													drag.element.style.zIndex=parseInt(drag.element.style.zIndex)-600;
													drag.element.style.left = copy_x;
													drag.element.style.top = copy_y;
													$('cpi' + drag.element.id.substr(3)).remove();
												}
												else if (Element.hasClassName(drag.element, 'movable_class'))
												{
													$('ppi' + drag.element.id.substr(3)).style.zIndex=parseInt($('ppi' + drag.element.id.substr(3)).style.zIndex)-600;
													drag.element.style.left=$('ppi' + drag.element.id.substr(3)).style.left;
													drag.element.style.top=$('ppi' + drag.element.id.substr(3)).style.top;
													drag.element.style.zIndex=parseInt(drag.element.style.zIndex)-600;
													if (Element.hasClassName (drag.element, 'user_sell'))
													{
														$('ppi' + drag.element.id.substr(3)).style.left = window.reverse_position_left;
														$('ppi' + drag.element.id.substr(3)).style.top = window.reverse_position_top;
														$('pli' + drag.element.id.substr(3)).style.left = window.reverse_position_left;
														$('pli' + drag.element.id.substr(3)).style.top = window.reverse_position_top;
													}
													else
														save_drags ();
												};
												
												if (Element.hasClassName(drag.element, 'musor_class'))
												{
													$('pic' + drag.element.id.substr(3)).style.zIndex=parseInt($('pic' + drag.element.id.substr(3)).style.zIndex)-600;
													drag.element.style.left=$('pic' + drag.element.id.substr(3)).style.left;
													drag.element.style.top=$('pic' + drag.element.id.substr(3)).style.top;
													drag.element.style.zIndex=parseInt(drag.element.style.zIndex)-600;
													save_drags_musor (drag.element.id.substr(3));
												};


												if (Element.hasClassName(drag.element, 'chulan_class'))
												{
													if (window.allow_drop || window.return_item)
													{
														off = Position.cumulativeOffset ($('chulan_win_main_div'));
														if ((Event.pointerX(ev) >= off[0])&&(Event.pointerX(ev)<=(off[0]+$('chulan_win_main_div').offsetWidth))&&(Event.pointerY(ev)>=off[1])&&(Event.pointerY(ev)<=(off[1]+$('chulan_win_main_div').offsetHeight)))
														{
														   $('dpc' + drag.element.id.substr(6)).appendChild(drag.element);
														   drag.element.style.removeProperty('left');
														   drag.element.style.removeProperty('top');
														   $('chulan_empty_text').style.display = 'none';
														}
														else
														{
															ob = drag.element;

															if ($('plan_view'))
															{
																getstr = 'elem='+drag.element.id+'&x='+(Event.pointerX(ev)-$('plan_view').offsetLeft)+'&y='+(Event.pointerY(ev)-$('workarea').offsetTop);
																if (!$(drag.element.id) || window.return_item)
																{
																	getstr += '&noset=1';
																	if (!confirm ('Вы действительно собираетесь сдать предмет (вам вернётся только 90% цены)?'))
																	{
																		$('dpc' + drag.element.id.substr(6)).appendChild (drag.element);
																		drag.element.style.removeProperty('left');
																		drag.element.style.removeProperty('top');
																		drag.element.style.removeProperty('opacity');
																		drag.element.style.zIndex=0;
																		return false;
																	}
																	else
																	{
																		new Ajax.Updater('plan_view', '/ajax/remove_from_chulan.php?' + getstr, {method: 'get', evalScripts: true, insertion: Insertion.Bottom, onComplete: function ()
																	{
																		$('dpc' + drag.element.id.substr(6)).remove();
																		drag.element.remove();
																		unclock();
																	}});
																	};
																}
																else if(window.plan_owner)
																{
																	new Ajax.Updater('plan_view', '/ajax/remove_from_chulan.php?' + getstr, {method: 'get', evalScripts: true, insertion: Insertion.Bottom, onComplete: function ()
																	{
																		//$('dpc' + drag.element.id.substr(6)).remove();
																		drag.element.remove();
																		unclock();
																	}});
																}
																else
																{
																	$('dpc' + drag.element.id.substr(6)).appendChild (drag.element);
																	drag.element.style.removeProperty('left');
																	drag.element.style.removeProperty('top');
																	drag.element.style.removeProperty('opacity');
																	drag.element.style.zIndex=0;
																	return false;
																};
																
															}
															else
															{
/*																getstr = 'elem='+drag.element.id+'&x='+(Event.pointerX(ev)-$('workarea').offsetLeft)+'&y='+(Event.pointerY(ev)-$('workarea').offsetTop);
																new Ajax.Updater ('workarea', '/ajax/remove_from_chulan_street.php?' + getstr, {method: 'get', evalScripts: true, insertion: Insertion.Bottom, onComplete: function ()
																	{
																		ob.remove();
																		unclock();
																	}});*/
																getstr = 'elem='+drag.element.id+'&x='+(Event.pointerX(ev)-$('workarea').offsetLeft)+'&y='+(Event.pointerY(ev)-$('workarea').offsetTop);
																new Ajax.Updater('workarea', '/ajax/place_musor_object.php?' + getstr, {method: 'get', evalScripts: true, insertion: Insertion.Bottom, onComplete: function ()
																	{
																		$('dpc' + drag.element.id.substr(6)).remove();
																		drag.element.remove();
																		unclock();
																	}});
																drag.element.style.top = '';
																drag.element.style.left = '';
																drag.element.style.zIndex = '';
																$('dpc' + drag.element.id.substr(6)).appendChild (ob);
																unclock ();
															};
														};
													};
												};
											}
										});



var ModalRequest = Class.create();

ModalRequest.prototype = 
{
	initialize: function ()
	{
		obj = new Object ();
		if (arguments[0] && typeof arguments[0] == 'object')
			obj = arguments[0];
		Object.extend (this, obj);
		modal_extend = new Object ({overlayCloseOnClick: false});
		currentModal = new Control.Modal.open (this.collect (), modal_extend);
		Event.observe ('modal_request_ok', 'click', this.ok_func.bindAsEventListener (this), true);
		Event.observe ('modal_request_cancel', 'click', this.cancel_func.bindAsEventListener (this), true);
		if ($(this.prompt_id))
			Event.observe (this.prompt_id, 'keydown', this.check_key_down.bindAsEventListener (this), true);
	},
	onOK: function ()
	{
	},
	onCancel: function ()
	{
	},
	ok_func: function ()
	{
		this.onOK ();
		this.remove_observers ();
		Control.Modal.close ();
	},
	cancel_func: function ()
	{
		this.onCancel ();
		this.remove_observers ();
		Control.Modal.close ();
	},
	remove_observers: function ()
	{
		Event.stopObserving ('modal_request_ok', 'click');
		Event.stopObserving ('modal_request_cancel', 'click');
	},
	collect: function ()
	{
		switch (this.type)
		{
			case 'prompt':
				return this.modal_text + '<br/><input id="' + this.prompt_id + '" class="' + this.prompt_class + '" value="' +
					this.prompt_default + '" /><br/><img id="modal_request_ok" class="' + this.ok_class + '" src="' +
					'/img/inv.gif"/><img id="modal_request_cancel" class="' + this.cancel_class + '" src="/img/inv.gif"/>';
				break;
			default:
				return this.modal_text + '<br/><img id="modal_request_ok" class="' + this.ok_class + '" src="/img/inv.gif"/>' +
					'<img id="modal_request_cancel" class="' + this.cancel_class + '" src="/img/inv.gif"/>';
		};
	},
	check_key_down: function (ev)
	{
		if (ev.keyCode == 13)
			this.ok_func ();
	},
	type: 'confirm',
	ok_class: 'win_ok',
	cancel_class: 'win_cancel',
	prompt_class: 'default_input',
	prompt_id: 'modal_request_input',
	prompt_default: '',
	modal_text: 'Вы уверены?'
};


var house_numbers = new Array();
var primitives_drag=new Object();
var images = new Array();

var myWins = new Object();


function showportrait(e, id)
{
	$('portrait_' + id).style.zIndex='999999';
	$('portrait_' + id).style.display='';
	if (Event.findElement(e, 'TD').id=='people_count_users_content')
	{
		$('portrait_' + id).style.left=parseInt(Event.pointerX(e)+15-Position.cumulativeOffset($('open_people_count_users'))[0])+'px';
		$('portrait_' + id).style.top=parseInt(Event.pointerY(e)+15-Position.cumulativeOffset($('open_people_count_users'))[1])+'px';
	}
	else if ($('get_users_win'))
	{
		$('portrait_' + id).style.left=parseInt(Event.pointerX(e)+15-$('get_users_win').offsetLeft)+'px';
		$('portrait_' + id).style.top=parseInt(Event.pointerY(e)+15-$('get_users_win').offsetTop)+'px';
	};
};

function set_teleport (id_user, place_type, place_id)
{
	new Ajax.Request ('modules/user_summoning/ajax/set_teleport.php?id_user=' + id_user + '&place_type=' + place_type + '&place_id=' + place_id);
};

function show_info (e, id)
{
	if ($('user_info_' + id))
		$('user_info_' + id).remove ();
	divelement = document.createElement ('DIV');
	divelement.id = 'user_info_' + id;
	divelement.style.left = parseInt(Event.pointerX(e) + 2)+'px';
	divelement.style.bottom = parseInt($('workarea').offsetTop + $('workarea').offsetHeight - Event.pointerY(e) + 2)+'px';
	divelement.style.position = 'absolute';
//	divelement.className = 'tooltip';
	divelement.style.zIndex = 900;
//	divelement.innerHTML = '<div id="sub_user_info" style="left:0px; top:0px; height:20px; width:20px; position:absolute;"></div>';
	$('workarea').appendChild (divelement);

	divelement = document.createElement ('DIV');
	divelement.id = 'sub_user_info_' + id;
	divelement.style.left = '0px';
	divelement.style.top = '0px';
	divelement.style.height = '20px';
	divelement.style.width = '20px';
	divelement.style.position = 'absolute';
	$('user_info_' + id).appendChild (divelement);

	Protoload.startWaiting ($('sub_user_info_' + id));
	new Ajax.Updater ('user_info_' + id, '/ajax/user_info.php?id=' + id, {method: 'get', evalScripts: true, insertion: Insertion.Bottom, onComplete:
		function ()
		{
			Protoload.stopWaiting ($('sub_user_info_' + id));
		}});
};

function move_user_info (e, id)
{
	if ($('user_info_' + id))
	{
		$('user_info_' + id).style.left = parseInt(Event.pointerX(e) + 2)+'px';
		$('user_info_' + id).style.bottom = parseInt($('workarea').offsetTop + $('workarea').offsetHeight - Event.pointerY(e) + 2)+'px';
	};
};

function hide_user_info (id)
{
	if ($('user_info_' + id))
	{
		Protoload.stopWaiting ($('sub_user_info_' + id));
		$('user_info_' + id).remove ();
	};
};

function updt()
{
	$('user_info_win_content').style.overflow='hidden';
	myWins["user_info_obj"].updateHeight();
	myWins["user_info_obj"].updateWidth();
	$('user_info_win_content').style.overflow='auto';
};
function resiz(ob)
{
	accordeons=document.getElementsByClassName('info_page');
	for (i=0;i<accordeons.length; i++)
	{
		//alert(accordeons[i].id);
		if (accordeons[i].id!=ob)
		{
			if (Element.visible(accordeons[i].id)) Effect.BlindUp(accordeons[i].id, {duration:0.2, afterUpdate: updt});
		}
		else
		{
			if (!Element.visible(accordeons[i].id)) Effect.BlindDown(accordeons[i].id, {duration:0.2, afterUpdate: updt});
			else if (Element.visible(accordeons[i].id)) Effect.BlindUp(accordeons[i].id, {duration:0.2, afterUpdate: updt});
		};
	};
};


var Cookie = {
  set: function(name, value, daysToExpire) {
    var expire = '';
    if (daysToExpire != undefined) {
      var d = new Date();
      d.setTime(d.getTime() + (86400000 * parseFloat(daysToExpire)));
      expire = '; expires=' + d.toGMTString();
    };
    return (document.cookie = escape(name) + '=' + escape(value || '') + expire);
  },
  get: function(name) {
    var cookie = document.cookie.match(new RegExp('(^|;)\\s*' + escape(name) + '=([^;\\s]*)'));
    return (cookie ? unescape(cookie[2]) : null);
  },
  erase: function(name) {
    var cookie = Cookie.get(name) || true;
    Cookie.set(name, '', -1);
    return cookie;
  },
  accept: function() {
    if (typeof navigator.cookieEnabled == 'boolean') {
      return navigator.cookieEnabled;
    };
    Cookie.set('_test', '1');
    return (Cookie.erase('_test') == '1');
  }
};




function onclos(e)
	{

	$('open_'+e.element.id.substr(0, e.element.id.length-4)).style.display='';
	};
	


/*function openNav(ob)
{
	ob.style.display='none';
	if (!$(ob.id.substr(5)+'_win'))
	{
	var index= 0;
	var contentWin = null;
	win = new Window(ob.id.substr(5)+'_win', {overflow:"hidden", className: "alphacube", width:300, height:200, top: 300, left: 500, zIndex: 900, resizable: true, title: $(ob).innerHTML, minimizable: false, maximizable: false, closable:true, opacity:1, draggable:false})
//	Object.extend(win.options.hideEffectOptions, {afterFinish:  onclos});
	
	
	divelement= document.createElement('DIV');
	divelement.id=ob.id.substr(5);
	divelement.style.display='none';
	document.body.appendChild(divelement);

	Object.extend(win.options.showEffectOptions, {duration: 0.3, from: 0.0, to: 1.0, afterFinish:function () {myWins[ob.id.substr(5)+'_obj'].updateWidth();myWins[ob.id.substr(5)+'_obj'].updateHeight();} })
	Object.extend(win.options.hideEffectOptions, {duration: 0.3, from: 1.0, to: 0.0, afterFinish:function () {myWins[ob.id.substr(5)+'_obj'].draghand.destroy(); Element.remove($(ob.id.substr(5)+'_win')); ob.style.display='';	delete myWins[ob.id.substr(5)+'_obj']; } })

	
	myWins[ob.id.substr(5)+"_obj"]=win;
	new Ajax.Updater( ob.id.substr(5), '/'+ob.id.substr(5)+'/', 
						{	method: 'get', evalScripts: true, 
							onComplete: function()
												{
													myWins[ob.id.substr(5)+"_obj"].setContent(ob.id.substr(5), true, false);
													myWins[ob.id.substr(5)+"_obj"].show();
													$(ob.id.substr(5)+"_win_top").style.cursor="move";
													myWins[ob.id.substr(5)+"_obj"].draghand=new Draggable(ob.id.substr(5)+"_win", {handle: ob.id.substr(5)+"_win_top",starteffect: '', endeffect: ''});
												};
						});

	};
	else
	{
		myWins[ob.id.substr(5)+"_obj"].show();
	};
	return false;
};
*/
function open_reg (position, teleport)
{
	if ($('registration'))
		return false;
	clock ();
	divelement = document.createElement('DIV');
	divelement.id='shadower';
	divelement.style.position='absolute';
	divelement.style.zIndex=499;
	divelement.style.left='0px';
	divelement.style.top='0px';
	divelement.style.width='100%';
//	divelement.style.height='640px';
	divelement.style.height='100%';
	divelement.style.background="#000000";
	divelement.style.opacity='0.6';
	divelement.style.filter='alpha(opacity=60, style=0)';
//	$('workarea').appendChild(divelement);
	document.body.appendChild(divelement);

	divelement = document.createElement('DIV');
	divelement.id='registration';
	divelement.style.position='absolute';
	divelement.style.zIndex=500;
/*	divelement.style.left='300px';
	divelement.style.bottom='0px';
	divelement.style.width='800px';
	divelement.style.height='640px';
	$('workarea').appendChild(divelement);*/
	document.body.appendChild(divelement);

//	new Ajax.Updater('registration', '/registration/', {method: 'get', evalScripts: true, onComplete: function(){ unclock();} });
	new Ajax.Updater('registration', '/ajax/personal/reg/index.php?teleport='+teleport+'&position='+position, {method: 'get', evalScripts: true, onComplete: function(){
			$('registration').style.left = (parseInt (document.body.offsetWidth / 2) - parseInt ($('registration').offsetWidth / 2)) + 'px';
			$('registration').style.top = (parseInt (document.body.offsetHeight / 2) - parseInt ($('registration').offsetHeight / 2)) + 'px';
			unclock();} });
};

function open_user_info ()
{
	if ($('user_info'))
		return false;
	clock ();
	divelement = document.createElement('DIV');
	divelement.id='shadower_user_info';
	divelement.style.position='absolute';
	divelement.style.zIndex=1000;
	divelement.style.left='0px';
	divelement.style.top='0px';
	divelement.style.width='100%';
//	divelement.style.height='640px';
	divelement.style.height='100%';
	divelement.style.background="#000000";
	divelement.style.opacity='0.6';
	divelement.style.filter='alpha(opacity=60, style=0)';
//	$('workarea').appendChild(divelement);
	document.body.appendChild(divelement);

	divelement = document.createElement('DIV');
	divelement.id='user_info';
	divelement.style.position='absolute';
	divelement.style.zIndex=1500;
	divelement.style.backgroundColor = '#FFFFFF';
	divelement.style.height='370px';
/*	divelement.style.left='300px';
	divelement.style.bottom='0px';
	divelement.style.width='800px';
	$('workarea').appendChild(divelement);*/
	document.body.appendChild(divelement);

//	new Ajax.Updater('registration', '/registration/', {method: 'get', evalScripts: true, onComplete: function(){ unclock();} });
	new Ajax.Updater('user_info', '/ajax/personal/reg/user_info.php', {method: 'get', evalScripts: true, onComplete: function(){
			$('user_info').style.left = (parseInt (document.body.offsetWidth / 2) - parseInt ($('user_info').offsetWidth / 2)) + 'px';
			$('user_info').style.top = (parseInt (document.body.offsetHeight / 2) - parseInt ($('user_info').offsetHeight / 2)) + 'px';
			unclock();} });
};

function goto_reg ()
{
	new Ajax.Updater ('workarea', '/ajax/goto_reg.php', {method: 'get', evalScripts: true});
};

function cancel_reg ()
{
	$('shadower').remove();
	$('registration').remove();
};

function start_chat(ob)
{
	if (window.allow_chat)
	{
		if (arguments[1])
			Chat.start_session(ob, arguments[1]);
		else
			Chat.start_session(ob);
	}
	else
		matug ('В этом месте чат недоступен');
};

function common_chat(ev)
{
	if (!$(Event.element(ev).id.substr(5)+'_win'))
	{
		obj = new Object ({url: '/modules/chat/ajax/start_session.php', external_param: Event.element(ev).id.substr (5)});
		openWin(Event.element(ev), obj);
	};
};

function clock()
{
	$('clock_div').style.height=document.body.offsetHeight+'px';
	$('clock_div').style.display='';
	document.body.style.cursor='wait';
};
function unclock()
{
	$('clock_div').style.display='none';
	document.body.style.cursor='auto';
};


function enter_district(id)
{
	clock();
	new Ajax.Updater ('workarea', '/ajax/walk.php?id='+id, {method: 'get', evalScripts: true, onComplete: function (){unclock();} });
};


function sortObservers1 (a, b)
{
	if (a[0]&&b[0])
	{
		if ((a[0].id>'')&&(b[0].id>''))
		{
			if (a[0].id>b[0].id)
			{
				return 1;
			}
			else
			{
				return -1;
			};
		}
		else
		{
			return -1;
		};
	}
	else
	{
		return -1;
	};
};

function sortObservers2 (a, b)
{
	if (a[1]&&b[1])
	{
			if (a[1]>b[1])
			{
				return 1;
			}
			else
			{
				return -1;
			};
	}
	else
	{
		return -1;
	};
};


//Функция обновления окружения
function get_env ()
{
/*	if (Event.observers)
	{
		Event.observers.sort(sortObservers1);
		Event.observers.sort(sortObservers2);
		for (var i = 0; i < Event.observers.length; i++) 
		{
			if (Event.observers[i][0])
				if (Event.observers[i][0].id>'')
				{
					if (Event.observers[i+1])
						if (Event.observers[i+1][0])
							if (Event.observers[i+1][0].id>'')
								if ((Event.observers[i][0].id==Event.observers[i+1][0].id)&&(Event.observers[i][1]==Event.observers[i+1][1])&&(Event.observers[i][2]==Event.observers[i+1][2]))
								{
									Event.stopObserving(Event.observers[i][0], Event.observers[i][1], Event.observers[i][2], Event.observers[i][3]);
									Event.observers.splice(i,1);
									i--;
								};
				};
		};
	};
*/
	if (myWins['map_obj'])
	{
		get_map_pos();
	};
	get_footer_menu();
	get_position();
	
};

function get_map_pos()
{
	new Ajax.Updater ('map', '/ajax/get_map_pos.php', {method: 'get', evalScripts: true, insertion:Insertion.Bottom, onComplete: function(){ }});
};

function get_nav_buttons()
{
	//clock();

	new Ajax.Updater ('nav_buttons', '/ajax/get_nav_buttons.php', {method: 'get', evalScripts: true, onComplete: function(){ if ($('temp_area')) slide_workarea(); else clearRandomPics();}});
};

function get_nav_buttons_plan()
{
	//clock();

	new Ajax.Updater ('nav_buttons', '/ajax/get_nav_buttons_plan.php', {method: 'get', evalScripts: true, onComplete: function(){ if ($('temp_area')) slide_workarea(); else clearRandomPics();}});
};

function get_footer_menu()
{
	//clock();
	new Ajax.Updater ('menuitems_foot', '/ajax/get_footer_menu.php', {method: 'get', evalScripts: true, onComplete: function(){ }});
};

function get_position()
{
	new Ajax.Updater ('footer_position', '/ajax/get_footer_position.php', {method: 'get', evalScripts: true, onComplete: function(){  }});
};

//КОНЕЦ Функция обновления окружения

function walk (ob)
{
	$('history_iframe').title = document.title;
//	document.title = user_position_text;
	var time = new Date();
	$('history_iframe').src = '/ajax/history_iframe.php?typ=street&coord='+ob.id+'&x='+window.session_x+'&street='+window.session_street+'&side='+window.session_side+'&user='+window.id_user+'&time='+time.getTime();
};

function walkstreet(id)
{
	clock();

	divelement = document.createElement('DIV');
	divelement.id='temp_area';
	divelement.style.position='absolute';
	if (document.body.offsetHeight<=730)
		divelement.style.top=(parseInt(document.body.offsetHeight/2)-320)+'px';
	else
		divelement.style.top=(document.body.offsetHeight-680)+'px';

	divelement.style.height=env['height']+"px";
	divelement.style.width=env['width']+"px";
	divelement.style.left=(document.body.offsetWidth*10)+'px';
	document.body.insertBefore(divelement, $('footer'));

	new Ajax.Updater('temp_area', '/ajax/walk.php?type='+id, {method: 'get', evalScripts: true, onComplete: function(){ } });
};

var slideX=0;

function slide_workarea()
{
	$('temp_area').style.left=(-1*slideX)+'px';

	new Effect.Parallel(
	[new Effect.Move( $('temp_area'), {x:slideX , sync: true}),
	new Effect.Move( $('workarea'), {x:slideX , sync: true})],
	{duration: 0.5, afterFinish: end_slide_workarea});
};

function end_slide_workarea()
{
	document.body.removeChild($('workarea'));
	$('temp_area').id='workarea';
	clearRandomPics();
	MainObject.fireAct();
	AnnounObject.fireActs();
	unclock();
};


function show_picdescr (ev)
{
	id='picdescr'+Event.element(ev).id.substr(3);
	$(id).style.left=(Event.pointerX(ev)-Position.cumulativeOffset (Event.element (ev).parentNode)[0]+8)+'px';
	$(id).style.top=(Event.pointerY(ev)-Position.cumulativeOffset (Event.element (ev).parentNode)[1]+8)+'px';
	$(id).style.display='';
};

function hide_picdescr (ev)
{
	id='picdescr'+(arguments[1]>''?arguments[1]:Event.element(ev).id.substr(3));
	$(id).style.display='none';
};

function ch_side (ob)
{
	$('history_iframe').title = document.title;
//	document.title = user_position_text;
	var time = new Date();
	$('history_iframe').src = '/ajax/history_iframe.php?typ=street&also=side&coord='+ob+'&x='+window.session_x+'&street='+window.session_street+'&side='+window.session_side+'&user='+window.id_user+'&time='+time.getTime();
};

function ch_side_perehod(ob)
{
	clock();
	new Ajax.Updater('workarea', '/ajax/walk.php?side='+ob, {method: 'get', evalScripts: true, onComplete: function(){ unclock();} });
};

function go_to_plan(ev)
{
	$('history_iframe').title = document.title;
//	document.title = user_position_text;
	var time = new Date();
	$('history_iframe').src = '/ajax/history_iframe.php?typ=gotoplan&coord='+Event.element(ev).id.substr(3)+'&user='+window.id_user+'&time='+time.getTime();
};

function go_to_plan_perehod(id)
{
	clock();
/*	if (myWins['map_obj'])
	{
		Wins.hide('map_win');
	};
*/
	new Ajax.Updater('workarea', '/ajax/go_to_plan.php?elem='+id, {method: 'get', evalScripts: true, onComplete: function(){$('plan_view').style.left = (parseInt(document.body.offsetWidth-960)/2)+'px'; unclock();} });
};


function go_extlink(ev, ob)
{
	clock();
	new Ajax.Updater('workarea', '/ajax/go_extlink.php?url='+ob, {method: 'get', evalScripts: true, onComplete: function(){ unclock();} });
};


function walkplan (ev)
{
	$('history_iframe').title = document.title;
//	document.title = user_position_text;
	var time = new Date();
	$('history_iframe').src = '/ajax/history_iframe.php?typ=walkplan&coord='+Event.element(ev).id.substr(3)+'&user='+window.id_user+'&time='+time.getTime();
};

function walkplan_perehod (id)
{
	clock();
	//alert(id.substr(3));
//	alert(Event.element(ev).id.substr(3));
	new Ajax.Updater('workarea', '/ajax/go_to_plan.php?elem='+id, {method: 'get', evalScripts: true, onComplete: function(){$('plan_view').style.left = (parseInt(document.body.offsetWidth-960)/2)+'px'; unclock();} })
};

function show_picdescr_nw (ev)
{
	id=Event.element(ev).id.substr(3);

	if (!myWins['picdescr_'+id+'_obj'])
	{
		myWins['picdescr_'+id+'_obj'] = new Win('picdescr_'+id+'_win', {overflow:"hidden", className: "alphacube", width:300, height:200, top: Event.pointerY(ev)+8, left: Event.pointerX(ev)+8, zIndex: 999, resizable: false, title: '&nbsp;', minimizable: false, maximizable: false, closable:true,  opacity:1.0, draggable:false});
		Object.extend(myWins['picdescr_'+id+'_obj'].options.showEffectOptions, {duration: 0.3, from: 0.0, to: 1.0});
		Object.extend(myWins['picdescr_'+id+'_obj'].options.hideEffectOptions, {duration: 0.3, from: 1.0, to: 0.0});
		myWins['picdescr_'+id+'_obj'].setContent('picdescr'+id, true, false);
		myWins['picdescr_'+id+'_obj'].show();
		$('picdescr_'+id+"_win_top").style.cursor="move";
		myWins['picdescr_'+id+"_obj"].draghand=new Draggable('picdescr_'+id+"_win", {handle: 'picdescr_'+id+"_win_top",starteffect: '', endeffect: ''});
	}
	else
	{
		if($('picdescr_'+id+'_win').style.display=='none')
		{
			$('picdescr_'+id+'_win').style.left=(Event.pointerX(ev)+8)+'px';
			$('picdescr_'+id+'_win').style.top=(Event.pointerY(ev)+8)+'px';
			myWins['picdescr_'+id+'_obj'].show();
		};
	};
};


function add_announcement (ev)
{
	id=Event.element(ev).id.substr(3);

	x=Event.pointerX(ev)-Position.cumulativeOffset (Event.element (ev).parentNode)[0];
	y=Event.pointerY(ev)-Position.cumulativeOffset (Event.element (ev).parentNode)[1];

	currentModal = new Control.Modal.open ('<div style="margin:10px 20px" id="announcement_div"><p>Добавление объявления</p></div>');
//	Control.Modal.open('<p>Добавление объявления</p>');

		formelement = document.createElement('FORM');
		formelement.action = '';
		formelement.method = 'post';
		formelement.id= 'add_announcement_'+id;
//		formelement.style.display='none';

		textelement = document.createElement('TEXTAREA');
		textelement.id='add_announcement_text'+id;
		textelement.name='add_announcement_text'+id;
		textelement.style.width='300px';
		textelement.style.height='200px';
		textelement.style.overflowY='scroll';
		textelement.wrap='hard';
		textelement.className = 'defaultinput restrict_move_input';
		formelement.appendChild(textelement);

		formelement.innerHTML+='<br><br><img src="/img/inv.gif" class="win_save" id="add_announcement_but'+id+'" onclick="save_announcement(event)">&nbsp;<img src="/img/inv.gif" class="win_cancel" onclick="Control.Modal.close();">';
//		butelement = document.createElement('INPUT');
//		butelement.type='button';
//		butelement.value='Сохранить';
//		butelement.id='add_announcement_but'+id;
//		butelement.name='add_announcement_but'+id;
//		Event.observe(butelement, 'click', save_announcement, true);
//		formelement.appendChild(butelement);
//
//		butelement = document.createElement('INPUT');
//		butelement.type='button';
//		butelement.value='Отменить';
//		butelement.id='close_announcement_but'+id;
//		butelement.name='close_announcement_but'+id;
//		Event.observe(butelement, 'click',Control.Modal.close, true);
//		formelement.appendChild(butelement);

		inputelement = document.createElement('input');
		inputelement.type='hidden';
		inputelement.id='add_announcement_x'+id;
		inputelement.name='add_announcement_x'+id;
		inputelement.value=x;
		formelement.appendChild(inputelement);

		inputelement = document.createElement('input');
		inputelement.type='hidden';
		inputelement.id='add_announcement_y'+id;
		inputelement.name='add_announcement_y'+id;
		inputelement.value=y;
		formelement.appendChild(inputelement);

		inputelement = document.createElement('input');
		inputelement.type='hidden';
		inputelement.id='add_announcement_layer'+id;
		inputelement.name='add_announcement_layer'+id;
		inputelement.value=Event.element(ev).style.zIndex;
		formelement.appendChild(inputelement);

		hidelement = document.createElement('input');
		hidelement.type='hidden';
		hidelement.id='add_announcement_hid1'+id;
		hidelement.name='id_street';
		hidelement.value=window.session_street;
		formelement.appendChild(hidelement);

		hidelement = document.createElement('input');
		hidelement.type='hidden';
		hidelement.id='add_announcement_hid2'+id;
		hidelement.name='x';
		hidelement.value=window.session_x;
		formelement.appendChild(hidelement);

		hidelement = document.createElement('input');
		hidelement.type='hidden';
		hidelement.id='add_announcement_hid3'+id;
		hidelement.name='side';
		hidelement.value=window.session_side;
		formelement.appendChild(hidelement);
		$('announcement_div').appendChild(formelement);


		$('add_announcement_text'+id).focus();

//		$('modal_container').style.top=parseInt(Event.pointerY(ev)-$('modal_container').offsetHeight/2)+'px';
//		$('modal_container').style.left=parseInt(Event.pointerX(ev)-$('modal_container').offsetWidth/2)+'px';

Control.Modal.center($('modal_container'));

/*	if (!myWins['add_announcement_'+id+'_obj'])
	{
		myWins['add_announcement_'+id+'_obj'] = new Win('add_announcement_'+id+'_win', {overflow:"hidden", className: "alphacube", width:300, height:200, top: Event.pointerY(ev)+8, left: Event.pointerX(ev)+8, zIndex: 999, resizable: false, title: 'Объявление', minimizable: false, maximizable: false, closable:true,  opacity:1.0, draggable:false});
		Object.extend(myWins['add_announcement_'+id+'_obj'].options.showEffectOptions, {duration: 0.3, from: 0.0, to: 1.0, afterFinish:function ()
							{
								myWins['add_announcement_'+id+'_obj'].updateDimensions();
								if ($('add_announcement_text'+id))
									$('add_announcement_text'+id).addClassName ('restrict_move_input');
							}})
		Object.extend(myWins['add_announcement_'+id+'_obj'].options.hideEffectOptions, {duration: 0.3, from: 1.0, to: 0.0, afterFinish:function ()
							{
								$('add_announcement_text'+id.substr (8)).removeClassName ('restrict_move_input');
							}})
		formelement = document.createElement('FORM');
		formelement.action = '';
		formelement.method = 'post';
		formelement.id= 'add_announcement_'+id;
		formelement.style.display='none';

		textelement = document.createElement('TEXTAREA');
		textelement.id='add_announcement_text'+id;
		textelement.name='add_announcement_text'+id;
		textelement.style.width='100%';
		textelement.style.height='100px';
		textelement.style.overflowY='scroll';
		textelement.wrap='hard';
		textelement.className = 'restrict_move_input';
		formelement.appendChild(textelement);

		formelement.innerHTML+='<br>';

		butelement = document.createElement('INPUT');
		butelement.type='button';
		butelement.value='Сохранить';
		butelement.id='add_announcement_but'+id;
		butelement.name='add_announcement_but'+id;
		Event.observe(butelement, 'click', save_announcement, true);
		formelement.appendChild(butelement);

		inputelement = document.createElement('input');
		inputelement.type='hidden';
		inputelement.id='add_announcement_x'+id;
		inputelement.name='add_announcement_x'+id;
		inputelement.value=x;
		formelement.appendChild(inputelement);

		inputelement = document.createElement('input');
		inputelement.type='hidden';
		inputelement.id='add_announcement_y'+id;
		inputelement.name='add_announcement_y'+id;
		inputelement.value=y;
		formelement.appendChild(inputelement);

		inputelement = document.createElement('input');
		inputelement.type='hidden';
		inputelement.id='add_announcement_layer'+id;
		inputelement.name='add_announcement_layer'+id;
		inputelement.value=Event.element(ev).style.zIndex;
		formelement.appendChild(inputelement);

		hidelement = document.createElement('input');
		hidelement.type='hidden';
		hidelement.id='add_announcement_hid1'+id;
		hidelement.name='id_street';
		hidelement.value=window.session_street;
		formelement.appendChild(hidelement);

		hidelement = document.createElement('input');
		hidelement.type='hidden';
		hidelement.id='add_announcement_hid2'+id;
		hidelement.name='x';
		hidelement.value=window.session_x;
		formelement.appendChild(hidelement);

		hidelement = document.createElement('input');
		hidelement.type='hidden';
		hidelement.id='add_announcement_hid3'+id;
		hidelement.name='side';
		hidelement.value=window.session_side;
		formelement.appendChild(hidelement);

		document.body.appendChild(formelement);
		myWins['add_announcement_'+id+'_obj'].setContent('add_announcement_'+id, true, false);

		myWins['add_announcement_'+id+'_obj'].show();

		$('add_announcement_text'+id).focus();
		$('add_announcement_'+id+"_win_top").style.cursor="move";
		myWins['add_announcement_'+id+"_obj"].draghand=new Draggable('add_announcement_'+id+"_win", {handle: 'add_announcement_'+id+"_win_top",starteffect: '', endeffect: ''});
	};
	else
	{
		if ($('add_announcement_text'+id))
			$('add_announcement_text'+id).addClassName ('restrict_move_input');
		if ($('add_announcement_'+id+'_win').style.display == 'none')
		{
			$('add_announcement_'+id+'_win').style.left=(Event.pointerX(ev)+8)+'px';
			$('add_announcement_'+id+'_win').style.top=(Event.pointerY(ev)+8)+'px';
			myWins['add_announcement_'+id+'_obj'].show();
		};
	};
*/
};


function save_announcement(ev)
{
	id=Event.element(ev).id.substr(20);
	if (!$('add_announcement_text'+id).value)
		return false;
	clock();
	if ($('add_announcement_text'+id).value>'')
	{
		poststring=$('add_announcement_text'+id).id+'='+encodeURIComponent($('add_announcement_text'+id).value);
		poststring+='&'+$('add_announcement_x'+id).name+'='+encodeURIComponent($('add_announcement_x'+id).value);
		poststring+='&'+$('add_announcement_y'+id).name+'='+encodeURIComponent($('add_announcement_y'+id).value);
		poststring+='&'+$('add_announcement_layer'+id).name+'='+encodeURIComponent($('add_announcement_layer'+id).value);
		poststring+='&'+$('add_announcement_hid1'+id).name+'='+encodeURIComponent($('add_announcement_hid1'+id).value);
		poststring+='&'+$('add_announcement_hid2'+id).name+'='+encodeURIComponent($('add_announcement_hid2'+id).value);
		poststring+='&'+$('add_announcement_hid3'+id).name+'='+encodeURIComponent($('add_announcement_hid3'+id).value);
		if ($('plan_view'))
		{
		};
		new Ajax.Updater(($('plan_view')?$('plan_view'):$('workarea')), '/ajax/save_announcement.php', { method: 'post', insertion:Insertion.Bottom, evalScripts: true, postBody: poststring, onComplete: function()
			{
				Control.Modal.close();
				unclock();
			}});
	};
};


function show_announcement (ev)
{
	id='anntip'+Event.element(ev).id.substr(4);
	$(id).style.left=(Event.pointerX(ev)-Event.element(ev).parentNode.offsetLeft+8)+'px';
	if (Event.element(ev).parentNode.id == 'plan_view')
		$(id).style.top = (Event.pointerY(ev) - Position.cumulativeOffset (Event.element(ev).parentNode)[0]) + 'px';
	else
		$(id).style.top=(Event.pointerY(ev)-Event.element(ev).parentNode.offsetTop+8)+'px';
	$(id).style.display='';
};

function hide_announcement (ev)
{
	id='anntip'+Event.element(ev).id.substr(4);
	$(id).style.display='none';
};


function click_announcement (ev)
{
	id=Event.element(ev).id.substr(4);

	//$('anntip'+id).style.display='none';

	if (!myWins['announcement_'+id+'_obj'])
	{
		myWins['announcement_'+id+'_obj'] = new Win('announcement_'+id+'_win', {overflow:"hidden", className: "alphacube", top: Event.pointerY(ev)-10, left: Event.pointerX(ev)-10, zIndex: 999, resizable: false, title: 'Объявление', minimizable: false, maximizable: false, closable:true,  opacity:1.0, draggable:false});
		Object.extend(myWins['announcement_'+id+'_obj'].options.showEffectOptions, {duration: 0.3, from: 0.0, to: 1.0});
		Object.extend(myWins['announcement_'+id+'_obj'].options.hideEffectOptions, {duration: 0.3, from: 1.0, to: 0.0, afterFinish: function() {
											id=arguments[0].element.id.substr(arguments[0].element.id.indexOf('_')+1, arguments[0].element.id.lastIndexOf('_')-arguments[0].element.id.indexOf('_')-1);
										 	if ($('corrector_value'))
												$('announcement_'+id).innerHTML = $('corrector_value').value.replace (/\n/g, '<br>');
											$('announcement_'+id).style.display='none';
											$('workarea').appendChild($('announcement_'+id));
											myWins['announcement_'+id+'_obj'].draghand.destroy();
											$('announcement_'+id+'_win').remove();
											myWins['announcement_'+id+'_obj']=null;
											}});
		myWins['announcement_'+id+'_obj'].setContent('announcement_'+id, true, false);
		myWins['announcement_'+id+'_obj'].show();
		$('announcement_'+id+"_win_top").style.cursor="move";
		myWins['announcement_'+id+"_obj"].draghand=new Draggable('announcement_'+id+"_win", {handle: 'announcement_'+id+"_win_top",starteffect: '', endeffect: ''});
	}
	else
	{
		if ($('announcement_'+id+'_win').style.display=='none')
		{
			$('announcement_'+id+'_win').style.left=(Event.pointerX(ev)-Event.element(ev).parentNode.offsetLeft-10)+'px';
			$('announcement_'+id+'_win').style.top=(Event.pointerY(ev)-Event.element(ev).parentNode.offsetTop-10)+'px';
			myWins['announcement_'+id+'_obj'].show();
		};
	};

	if ($('corrector_div'))
	{
		$('corrector_div').remove ();
	};

	if (window.corrector)
	{
		$('announcement_'+id+'_win_content').innerHTML += '<div id="corrector_div"><input type=submit value="Редактировать" onclick="edit_announcement(' + id + '); return false"><input type=submit value="Удалить" onclick="delete_announcement(' + id + '); return false"></div>';
	};
	
	clock();
	new Ajax.Updater('announcement_'+id, '/ajax/view_announcement.php?id='+id, {method: 'get', evalScripts: true, onComplete: function() {unclock();} });
};

function to_street(ev)
{
	$('history_iframe').title = document.title;
//	document.title = user_position_text;
	var time = new Date();
	$('history_iframe').src = '/ajax/history_iframe.php?typ=to_street&coord='+Event.element(ev).id+'&user='+window.id_user+'&time='+time.getTime();
};

function to_street_perehod(id)
{
	clock();
	new Ajax.Updater('workarea', '/ajax/walk.php?coord='+id, {method: 'get', evalScripts: true, onComplete: function() {unclock();} });
};

function to_street_pause(event, act)
{
	$('history_iframe').title = document.title;
//	document.title = user_position_text;
	var time = new Date();
	$('history_iframe').src = '/ajax/history_iframe.php?typ=to_street_pause&act='+act+'&coord='+Event.element(event).id+'&user='+window.id_user+'&time='+time.getTime();
};

function to_street_pause_perehod(id, act)
{
	Element.hide($('workarea'));
	Element.hide($('nav_buttons'));
	Element.hide($('footer_position'));
	Element.hide($('menuitems_foot'));

	divelement = document.createElement ('div');
	divelement.id = "drive_" + id.substr(3);
	divelement.style.position = 'absolute';
	divelement.style.left = $('workarea').style.left;
	divelement.style.top = $('workarea').style.top;
	divelement.style.width = document.body.offsetWidth+'px';
	divelement.style.height = '640px';
	divelement.style.zIndex = 500;
	divelement.className = 'restrict_move_input';
	if (!flash)
		divelement.style.background = 'url(' + pic_host + '/img/metro.jpg) top center no-repeat';
	document.body.appendChild (divelement);

	if (flash)
	{
		drive_flash = new SWFObject("/swf/metrodrive.swf", "drive_flash_"+id.substr(3), "100%", "100%", "8");
		drive_flash.addParam('wmode', 'opaque');
		drive_flash.addParam("scale","noScale");
		drive_flash.addParam("salign", "t");
		drive_flash.addVariable('drivetime', act.substr(act.lastIndexOf('_')+1));
		drive_flash.addVariable('drivelink', '/ajax/walk.php?coord='+id);
		drive_flash.addVariable('divtodel', 'drive_'+id.substr(3));
		drive_flash.write('drive_'+id.substr(3));
	}
	else
	{
		currentModal = new Control.Modal.open ('<b>Время в пути: <span id="drive_flash_time">' + act.substr(act.lastIndexOf('_')+1) + '</span> сек.</b><br/>'+
			'Для правильного отображения этой страницы необходим flash-плеер не ниже 8-й версии.<br/>'+
			'Ваша версия flash-плеера устарела (или flash-плеер отсутствует).<br/>' + 
			'Скачать свежий flash-плеер можно здесь: <a target="_blank" href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash">Adobe.com</a>',
			{
				overlayCloseOnClick: false,
				afterOpen: function ()
				{
					setTimeout ('update_drive_timer (' + act.substr(act.lastIndexOf('_')+1) + ');', 1000);
					setTimeout ("to_street_pause_doit ('/ajax/walk.php?coord=" + id + "', 'drive_" + id.substr(3) + "');", parseInt (act.substr(act.lastIndexOf('_')+1)) * 1000);
				}
			});
	};
};

function update_drive_timer (sec)
{
	if ($('drive_flash_time'))
		$('drive_flash_time').innerHTML = (sec - 1);
	if (sec > 0)
		setTimeout ('update_drive_timer (' + (sec - 1) + ');', 1000);
};

function to_street_pause_doit (drivelink, divtodel)
{
	Element.remove($(divtodel));
	clock();
	Element.show($('workarea'));
	Element.show($('nav_buttons'));
//	Element.show($('menuitems_div'));
	Element.show($('footer_position'));
	Element.show($('menuitems_foot'));
	new Ajax.Updater('workarea', drivelink, {method: 'get', evalScripts: true, onComplete: function() {Control.Modal.close ();unclock();}});
};

function to_street_from_plan (ev)
{
	$('history_iframe').title = document.title;
//	document.title = user_position_text;
	var time = new Date();
	$('history_iframe').src = '/ajax/history_iframe.php?typ=to_street_from_plan&coord='+Event.element(ev).id+'&user='+window.id_user+'&time='+time.getTime();
};


function to_street_from_plan_perehod (id)
{
	clock();
	new Ajax.Updater('workarea', '/ajax/to_street_from_plan.php?coord='+id, {method: 'get', evalScripts: true, onComplete: function() {unclock();} });
};


function go_to_plan_sh(ev)
{
	clock();
	MainObject.endMouseMove(ev);
	if ($('plan_sh')) $('plan_sh').remove();
	if ($('shadower')) $('shadower').remove();
	if (!$('plan_sh'))
	{
		invs=$('workarea').getElementsByClassName('action_inv');
		for (i=0; i<invs.length; i++)
		{
			invs[i].style.display='none';
		};
		
		
		divelement = document.createElement('DIV');
		divelement.id='shadower';
		divelement.style.position='absolute';
		divelement.style.zIndex=502;
		divelement.style.left='0px';

		divelement.style.top='0px';
		divelement.style.width='100%';
		divelement.style.height='100%';
		divelement.style.background="#000000";
		divelement.style.opacity='0.6';
		divelement.style.filter='alpha(opacity=60, style=0)';
		document.body.appendChild(divelement);

		divelement = document.createElement('DIV');
		divelement.id='plan_sh';
		divelement.style.position='absolute';
		divelement.style.zIndex=503;
		divelement.style.left=(parseInt(document.body.offsetWidth-960)/2)+'px';
		divelement.style.bottom='0px';
		divelement.style.width='960px';
		divelement.style.height='640px';
		$('workarea').appendChild(divelement);
		$('plan_sh').innerHTML='<img src="/img/x2.gif" id="close_plan_sh_img" onclick="close_plan_sh();" style="cursor:pointer; position:absolute; top:0px; right:0px; z-index:500">';
		/*
		currentModal = new Control.Modal.open('<img src="/img/progress2.gif"><div id="plan_sh" style="display:none"></div>');
		clock();
		new Ajax.Updater('plan_sh', '/ajax/go_to_plan_sh.php?elem='+Event.element(ev).id.substr(3), {method: 'get', evalScripts: true, onComplete: function ()
			{
				currentModal = new Control.Modal.open('<div style="width:960px;height:640px">'+$('plan_sh').innerHTML+'<img width=22 height=20 src="/img/x2.gif" id="close_plan_sh_img" onclick="close_plan_sh();" style="cursor:pointer; position:absolute; top:0px; right:0px; z-index:500"></div>',
					{
						overlayCloseOnClick:false,
						containerClassName:'',
						beforeOpen: function ()
						{
							$('modal_container').style.visibility='hidden'
						},
						afterOpen: function ()
						{
							$('modal_container').style.visibility='';
							$('modal_overlay').style.backgroundColor='#000000';
							$('modal_overlay').style.opacity='0.6';
							$('modal_overlay').style.filter='alpha(opacity=60, style=0)';
							$('modal_container').style.backgroundColor='';
						},
						afterClose: function ()
						{
							$('modal_overlay').style.backgroundColor='';
							$('modal_overlay').style.opacity='1.0';
							$('modal_overlay').style.filter='alpha(opacity=100, style=0)';
						};
					});
				unclock();
			}});*/
	};
	new Ajax.Updater('plan_sh', '/ajax/go_to_plan_sh.php?elem='+Event.element(ev).id.substr(3), {method: 'get', evalScripts: true, insertion:Insertion.Bottom, onComplete: function(){ unclock();} });
};

function go_to_plan_sh_id(id)
{
//	if ($('plan_sh')) $('plan_sh').remove();
//	if ($('shadower')) $('shadower').remove();
	if (!$('plan_sh'))
	{
		clock();
		invs=$('workarea').getElementsByClassName('action_inv');
		for (i=0; i<invs.length; i++)
		{
			invs[i].style.display='none';
		};
		
		
/*		divelement = document.createElement('DIV');
		divelement.id='shadower';
		divelement.style.position='absolute';
		divelement.style.zIndex=299;
		divelement.style.left='0px';
		divelement.style.top='0px';
		divelement.style.width='100%';
		divelement.style.height='640px';
		divelement.style.background="#000000";
		divelement.style.opacity='0.6';
		divelement.style.filter='alpha(opacity=60, style=0)';
		$('workarea').appendChild(divelement);

		divelement = document.createElement('DIV');
		divelement.id='plan_sh';
		divelement.style.position='absolute';
		divelement.style.zIndex=300;
		divelement.style.left=(parseInt(document.body.offsetWidth-960)/2)+'px';
		divelement.style.bottom='0px';
		divelement.style.width='960px';
		divelement.style.height='640px';
		$('workarea').appendChild(divelement);
*/
/*		$('plan_sh').innerHTML='<img src="/img/x2.gif" id="close_plan_sh_img" onclick="close_plan_sh();" style="cursor:pointer; position:absolute; top:0px; right:0px; z-index:500">';
		
		
		
		new Ajax.Updater('plan_sh', '/ajax/go_to_plan_sh.php?plan='+id, {method: 'get', evalScripts: true, insertion:Insertion.Bottom, onComplete: function(){ unclock();} });
*/
		currentModal = new Control.Modal.open('<img src="/img/progress2.gif"><div id="plan_sh" style="display:none"></div>');
		clock();
		new Ajax.Updater('plan_sh', '/ajax/go_to_plan_sh.php?plan='+id, {method: 'get', evalScripts: true, onComplete: function ()
			{
				currentModal = new Control.Modal.open('<div style="width:960px;height:640px">'+$('plan_sh').innerHTML+'<img src="/img/x2.gif" id="close_plan_sh_img" onclick="close_plan_sh();" style="cursor:pointer; position:absolute; top:0px; right:0px; z-index:500"></div>',
					{
						overlayCloseOnClick:false,
						beforeOpen: function ()
						{
							$('modal_container').style.visibility='hidden';
						},
						afterOpen: function ()
						{
							$('modal_container').style.visibility='';
							$('modal_overlay').style.backgroundColor='#000000';
							$('modal_overlay').style.opacity='0.6';
							$('modal_overlay').style.filter='alpha(opacity=60, style=0)';
						},
						afterClose: function ()
						{
							$('modal_overlay').style.backgroundColor='';
							$('modal_overlay').style.opacity='1.0';
							$('modal_overlay').style.filter='alpha(opacity=100, style=0)';
						}
					});
				unclock();
			}});
	}
	else
	{
//		if ($('plan_sh')) $('plan_sh').remove();
//		if ($('shadower')) $('shadower').remove();
	};
};

function close_plan_sh()
{
	if ($('shadower'))
	{
		$('shadower').remove();
		if ($('plan_sh'))
			$('plan_sh').remove();
	}
	else
		Control.Modal.close();
	
	invs=$('workarea').getElementsByClassName('action_inv');
	for (i=0; i<invs.length; i++)
	{
		invs[i].style.display='';
	};
	
	new Ajax.Updater('workarea','/ajax/close_plan_sh.php', {method: 'get', evalScripts:true, insertion:Insertion.Bottom});
};

function openWin(ob)
{
	ob_extend = false;
	win_options = false;
	mod_rewrite = false;
	ext_param = '';
	exec_on_show = '';
	exec_on_finish = '';
	alt_url='';
	update_dimensions = true;
	modal_mode = false;
	close_on_click = false;
	title = '';
	modal_options = new Object ();
	modal_after_open = '';

	if (arguments[1])
		if (typeof arguments[1] == 'object')
		{
			ob_extend = arguments[1];
			if (ob_extend['external_param'])
				ext_param = ob_extend['external_param'];
			if (ob_extend['exec_on_show'])
				exec_on_show = ob_extend['exec_on_show'];
			if (ob_extend['exec_on_finish'])
				exec_on_finish = ob_extend['exec_on_finish'];
			if (ob_extend['win_options'])
				win_options = ob_extend['win_options'];
			if (ob_extend['mod_rewrite'])
				mod_rewrite = true;
			if (ob_extend['url'])
				alt_url = ob_extend['url'];
			if (ob_extend['no_update'])
				update_dimensions = false;
			if (ob_extend['modal'])
			{
				modal_mode = true;
				modal_finish = '';
				if (ob_extend['close_on_click'])
					close_on_click = true;
				if (ob_extend['modal_finish'])
					modal_finish = ob_extend['modal_finish'];
				if (ob_extend['modal_after_open'])
					modal_after_open = ob_extend['modal_after_open'];
			};
			if (ob_extend['hide_elem'])
				ob.style.display='none';
			if (ob_extend['win_options'])
			{
				if (ob_extend['win_options']['title'])
				{
					title = ob_extend['win_options']['title'];
				};
			};
			if (ob_extend['modal_options'])
				modal_options = ob_extend['modal_options'];
		};

	if (modal_mode)
	{
		currentModal = new Control.Modal.open ('<img src="/img/progress2.gif">', Object.extend ({
						beforeOpen: function ()
						{
							if ($('modal_container'))
								$('modal_container').style.visibility = 'hidden';
						},
						afterOpen: function ()
						{
							$('modal_container').style.visibility = '';
							if (modal_after_open)
								eval (modal_after_open);
						},
						beforeClose: function ()
						{
						},
						afterClose: function ()
						{
							if (modal_finish)
								eval (modal_finish);
						},
						overlayCloseOnClick:close_on_click
					}, modal_options));
		clock ();
		new Ajax.Request ((alt_url>'')?alt_url+'?'+ext_param:((mod_rewrite==true)?'/'+ob.id.substr(5)+'/'+ext_param:'/ajax/'+ob.id.substr(5)+'.php?'+ext_param), {method: 'get', evalScripts: true, onComplete: function (request)
			{
				$('modal_container').style.visibility = 'hidden';
				currentModal.update ('<div id="modal_content">' + request.responseText + '</div>');
				$('modal_container').style.visibility = '';
				unclock ();
			}});

		return false;
	};

	if (!$(ob.id.substr(5)+'_win'))
	{
		var index= 0;
		var contentWin = null;
		var myTitle = '';
		obs = $(ob).getElementsByTagName ('IMG');
		if (obs.length)
			myTitle = obs[0].title;
		else
			myTitle = $(ob).innerHTML;
		win = new Win(
				ob.id.substr(5)+'_win', 
				Object.extend(
							{
								overflow:"hidden", 
								className: "alphacube", 
								width:100, 
								height:100, 
								top: 300, 
								left: 500, 
								zIndex: 510, 
								resizable: false, 
								title: myTitle, 
								minimizable: false, 
								maximizable: false, 
								closable:true, 
								opacity:1, 
								draggable:false
							}, 
					win_options || {})
				);

		divelement= document.createElement('DIV');
		divelement.id=ob.id.substr(5);	
		document.body.appendChild(divelement);
		Object.extend(win.options.showEffectOptions, {duration: 0.1, from: 0.0, to: 1.0, afterFinish: function () {
																	if (update_dimensions)
																		myWins[ob.id.substr(5)+"_obj"].updateDimensions ();
																	if (exec_on_show)
																		eval (exec_on_show);
																}});
		Object.extend(win.options.hideEffectOptions, {duration: 0.3, from: 1.0, to: 0.0, afterFinish: function () {
																	ob.style.display = '';
																	myWins[ob.id.substr(5)+'_obj'].draghand.destroy();
																	Element.remove($(ob.id.substr(5)+'_win'));
																	delete myWins[ob.id.substr(5)+'_obj'];
																	if (exec_on_finish)
																		eval (exec_on_finish);
																	Wins.onCloseWin (ob.id.substr (5) + '_win');
																}});

		myWins[ob.id.substr(5)+"_obj"]=win;

		new Ajax.Updater( ob.id.substr(5), (alt_url>'')?alt_url+'?'+ext_param:((mod_rewrite==true)?'/'+ob.id.substr(5)+'/'+ext_param:'/ajax/'+ob.id.substr(5)+'.php?'+ext_param), 
						{	method: 'get', evalScripts: true, 
							onComplete: function()
												{
													myWins[ob.id.substr(5)+"_obj"].setContent(ob.id.substr(5), true, false);
													myWins[ob.id.substr(5)+"_obj"].show();
													//myWins[ob.id.substr(5)+"_obj"].updateDimensions();
													$(ob.id.substr(5)+"_win_top").style.cursor="move";
													myWins[ob.id.substr(5)+"_obj"].draghand=new Draggable(ob.id.substr(5)+"_win", {handle: ob.id.substr(5)+"_win_top",starteffect: '', endeffect: ''});
												}
						});
	}
	else
	{
		new Ajax.Updater( ob.id.substr(5), (alt_url>'')?alt_url+'?'+ext_param:((mod_rewrite==true)?'/'+ob.id.substr(5)+'/'+ext_param:'/ajax/'+ob.id.substr(5)+'.php?'+ext_param), 
							{	method: 'get', evalScripts: true, 
								onComplete: function()
													{
														Wins.activate(ob.id.substr(5) + '_win');
														if (update_dimensions)
															myWins[ob.id.substr(5)+"_obj"].updateDimensions();
														if (exec_on_show)
															eval (exec_on_show);
													}
							});
	};
	return false;
};

function drawDraggableDiv(ob,id)
{
	if (!ob)
	{
		obid='rc';
	}
	else
	{
		obid=ob.id.substr(5);
	};
	if (!$(obid))
	{
		divelement = document.createElement('DIV');
		divelement.id = obid;
		divelement.style.position = 'absolute';
		divelement.style.cursor = 'move';
		divelement.style.zIndex = 500;
		divelement.style.left = (parseInt(document.body.offsetWidth)/2)+'px';
		divelement.style.top = (parseInt(document.body.offsetHeight)/2)+'px';
		document.body.appendChild(divelement);
		new Ajax.Updater( obid, '/ajax/'+obid+'.php?id='+id, {method: 'get', evalScripts: true});
		divelement.dragPip=new Draggable($(obid));
	}
	else
		$(obid).remove();
	return false;
};

function show_ppidescr_nw (ev)
{
	id=Event.element(ev).id.substr(3);

	if (!myWins['ppidescr_nw_'+id+'_obj'])
	{
		this_win_id = id;
		myWins['ppidescr_nw_'+id+'_obj'] = new Win('ppidescr_nw_'+id+'_win', {overflow:"hidden", className: "alphacube", width:300, height:200, top: Event.pointerY(ev)+8, left: Event.pointerX(ev)+8, zIndex: 999, resizable: false, title: '', minimizable: false, maximizable: false, closable:true,  opacity:1.0, draggable:false});
		Object.extend(myWins['ppidescr_nw_'+id+'_obj'].options.showEffectOptions, {duration: 0.3, from: 0.0, to: 1.0, afterFinish: function () {myWins['ppidescr_nw_'+this_win_id+'_obj'].updateDimensions();}});
		Object.extend(myWins['ppidescr_nw_'+id+'_obj'].options.hideEffectOptions, {duration: 0.3, from: 1.0, to: 0.0});
//		myWins['ppidescr_nw_'+id+'_obj'].setContent('ppidescr_nw'+id, true, false);
		$('ppidescr_nw_'+id+'_win_content').appendChild ($('ppidescr_nw'+id));
		$('ppidescr_nw'+id).style.minWidth = '300px';
		$('ppidescr_nw'+id).style.display = '';
		myWins['ppidescr_nw_'+id+'_obj'].show();
		$('ppidescr_nw_'+id+"_win_top").style.cursor="move";
		myWins['ppidescr_nw_'+id+"_obj"].draghand=new Draggable('ppidescr_nw_'+id+"_win", {handle: 'ppidescr_nw_'+id+"_win_top",starteffect: '', endeffect: ''});
	}
	else
	{
		if($('ppidescr_nw_'+id+'_win').style.display=='none')
		{
			$('ppidescr_nw_'+id+'_win').style.left=(Event.pointerX(ev)+8)+'px';
			$('ppidescr_nw_'+id+'_win').style.top=(Event.pointerY(ev)+8)+'px';
			myWins['ppidescr_nw_'+id+'_obj'].show();
		};
	};
};

function show_tv_panel (ev)
{
	id='ppitv'+Event.element(ev).id.substr(3);
	$(id).style.display='';
};

function hide_tv_panel (ev)
{
	id='ppitv'+(arguments[1]>''?arguments[1]:Event.element(ev).id.substr(3));
	if (Event.element(ev).id!='ppitv'+arguments[1])
		$(id).style.display='none';
};


function show_ppidescr (ev)
{
	id='ppidescr'+Event.element(ev).id.substr(3);
	$(id).style.left=(Event.pointerX(ev)-Position.cumulativeOffset (Event.element (ev).parentNode)[0]+8)+'px';
	$(id).style.top=(Event.pointerY(ev)-Position.cumulativeOffset (Event.element (ev).parentNode)[1]+8)+'px';
	$(id).style.display='';
};

function hide_ppidescr (ev)
{
	id='ppidescr'+(arguments[1]>''?arguments[1]:Event.element(ev).id.substr(3));
	$(id).style.display='none';
};

function show_picnumber (ev)
{
	id='picnumber'+Event.element(ev).id.substr(3);
	$(id).style.left=(Event.pointerX(ev)-Position.cumulativeOffset (Event.element (ev).parentNode)[0]+8)+'px';
	$(id).style.top=(Event.pointerY(ev)-Position.cumulativeOffset (Event.element (ev).parentNode)[1]+8)+'px';
	$(id).style.display='';
};

function hide_picnumber (ev)
{
	id='picnumber'+(arguments[1]>''?arguments[1]:Event.element(ev).id.substr(3));
	$(id).style.display='none';
};



//Движения
var moves_timer=0;
function moves()
{
/*	if($('open_moves').innerHTML=='Прекратить движение')
	{
		stop_moves();
	};
	else
	{
*/		start_moves();
//	};

};

function start_moves ()
{
	$('moves').style.display='';
//	$('open_moves').innerHTML='Прекратить движение';
	moves_num=parseInt(Math.random()*3+1);
	for(i=0; i<moves_num; i++)
	{
		imgelement = document.createElement('IMG');
		move_typ=(parseInt(Math.random()*2)==1)? 'l':'r';
		imgelement.src='/img/avto/car'+(parseInt(Math.random()*3)+1)+'_'+move_typ+'.gif';
		imgelement.id='car1_'+(parseInt(Math.random()*5)+1);
		imgelement.style.position='absolute';
		imgelement.style.left=((move_typ=='l')? parseInt(document.body.offsetWidth):-265)+'px';
		imgelement.style.top=(parseInt(Math.random()*100)+50)+'px';
		imgelement.style.zIndex=(201+i);
		imgelement.className='m_'+((move_typ=='l')? 'left':'right');
		$('moves').appendChild(imgelement);

		new Effect.MoveBy(imgelement, 0, ((move_typ=='l')? (-parseInt(document.body.offsetWidth)-265):(265+parseInt(document.body.offsetWidth))),  {duration: (Math.random()*5), transition:Effect.Transitions.linear, afterFinish: function() {Element.remove(arguments[0].element);} });
	};
//	moves_timer=setInterval('update_moves();', 1);
};

function stop_moves()
{
//	clearInterval(moves_timer);
	$('open_moves').innerHTML='Начать движение';
	$('moves').innerHTML='';
	$('moves').style.display='none';
};

function update_moves()
{
//	clearTimeout(moves_timer);
	lefts=$('moves').getElementsByClassName('m_left');
	if (lefts.length>0)
	{
		for(i=0; i<lefts.length; i++)
		{
			lefts[i].style.left=parseInt(parseInt(lefts[i].style.left)-parseInt(lefts[i].id.substr(lefts[i].id.indexOf('_')+1)))+'px';
		};
	};

	rights=$('moves').getElementsByClassName('m_right');
	if (rights.length>0)
	{
		for(i=0; i<rights.length; i++)
		{
			rights[i].style.left=parseInt(parseInt(rights[i].style.left)+parseInt(rights[i].id.substr(rights[i].id.indexOf('_')+1)))+'px';
		};
	};

//	moves_timer=setTimeout('update_moves();', 1);
};

//Конец Движения




function click_plan_map_coord (ev)
{
	$('history_iframe').title = document.title;
//	document.title = user_position_text;
	var time = new Date();
	$('history_iframe').src = '/ajax/history_iframe.php?typ=clickplanmapcoord&coord='+Event.element(ev).id.substr(10)+'&user='+window.id_user+'&time='+time.getTime();
};

function click_plan_map_coord_perehod (id)
{
	clock();
	new Ajax.Updater('workarea', '/ajax/go_to_plan.php?coord='+id, {method: 'get', evalScripts: true, onComplete: function(){$('plan_view').style.left = (parseInt(document.body.offsetWidth-960)/2)+'px'; unclock();} })
};

function save_drags ()
{
	drags = document.getElementsByClassName ('movable_class');
	if (drags.length)
	{
		clock ();
		get_string = '';
		for (i = 0; i < drags.length; i++)
			get_string += '&id[' + i + '][0]=' + drags[i].id.substr(3) + '&id[' + i + '][1]=' + drags[i].style.left + '&id[' + i + '][2]=' + drags[i].style.top;
		get_string = get_string.substr(1);
		new Ajax.Request('/ajax/save_drags.php', {method: 'post', postBody:get_string, onComplete: function () {unclock ();}});
	};
};

function save_drags_musor (id)
{
	clock ();
	get_string = 'id='+id+'&left='+parseInt($('pic'+id).style.left)+'&top='+parseInt($('pic'+id).style.top);
	new Ajax.Request('/ajax/save_drags.php?'+get_string, {method: 'get', onComplete: function () {unclock ();}});
};

function ping ()
{
	new Ajax.Updater ('musorka', '/ajax/ping.php', {method: 'get', evalScripts: true, onComplete: function () {window.setTimeout ('ping ();', 10000);} });
};

var refresh_user_win_timer = 0;
var refresh_user_win_protoload_timer = 0;
var refresh_user_win_protoload_time = 0;
var refresh_user_win_user_li_div_last = '';

function refresh_user_win ()
{
	clearTimeout(refresh_user_win_protoload_timer);
	clearTimeout(refresh_user_win_timer);
	window.refresh_user_win_protoload_time=parseInt((new Date()).getTime());
	if (!(/MSIE ((5\.5)|[6789])/.test(navigator.userAgent))) Protoload.startWaiting($('get_users_win_content_users'));
	if (Element.hasClassName($('user_li_div').parentNode,'user_list_li'))
	{
		refresh_user_win_user_li_div_last=$('user_li_div').parentNode.firstChild.id;
		$('user_li_div').style.display='none';
	}
	else
	{
		refresh_user_win_protoload_user_li_div_last='';
	};
	$('get_users_win_content_users').appendChild($('user_li_div'));
	if ($('get_people_count_users_content_refresher'))
	{
		new Ajax.Updater ($('get_people_count_users_content_refresher'), '/ajax/refresh_user_win.php', {method: 'get', evalScripts: true, onComplete: function () {} });
	};
};

function add_user_to_users_list_in_users_win (user)
{

	if (user.typ=='user')
	{
		uls = $('near_citizens').getElementsByTagName('ul');
		ul = uls[0];
		new_li=document.createElement('LI');
		new_li.style.paddingLeft="5px";
		new_li.className='user_list_li';
		new_li.innerHTML = '<a href="" id="user_li'+user.id_user+'" onclick="get_people_count_users_act('+user.id_user+','+user.id+', \'user\'); return false">'+user.name+' '+user.lastName+(window.allow_see_ip?' '+user.ip:'')+'</a>&nbsp;&nbsp;<img src="/img/users/info.gif" style="cursor:pointer" onclick="show_user_info('+user.id_user+')">';
		if (user.fullInfo)
			new_li.innerHTML +='&nbsp;&nbsp;<img src="/img/users/full_info.gif" style="cursor:pointer" onclick="full_user_info('+user.id_user+')">';
		
//		if (window.NoteBook)
//			new_li.innerHTML += '&nbsp;&nbsp;<img src="/img/win/addnotebook.gif" onclick="NoteBook.add_user(\''+user.name+'\', \''+user.lastName+'\');" alt="Добавить в записную книжку" title="Добавить в записную книжку" style="cursor:pointer">';
	}
	else
	{
		uls = $('near_men').getElementsByTagName('ul');
		ul = uls[0];
		new_li=document.createElement('LI');
		new_li.style.listStyleImage="url(/img/people/tourist.gif)";
		new_li.style.paddingLeft="5px";
		new_li.innerHTML = '<a href="" id="user_li'+user.id+'" onclick="start_chat('+user.id+');return false" class="defaultspan">Турист №'+user.id+(window.allow_see_ip?' '+user.ip:'')+'</a>';
		if (user.fullInfo)
			new_li.innerHTML +='&nbsp;&nbsp;<img src="/img/users/full_info.gif" style="cursor:pointer" onclick="full_user_info(0, '+user.id+')">';
	};
	ul.appendChild(new_li);
};

function get_people_count_users_act(id, sid, user)
{
	if (user=='user')
	{
		if ($('user_li'+id).parentNode.lastChild==$('user_li_div'))
		{
			$('user_li_div').innerHTML='';
			$('get_users_win_content_users').appendChild($('user_li_div'));
		}
		else
		{
			$('user_li_div').innerHTML='';
			$('user_li'+id).parentNode.appendChild($('user_li_div'));
			new Ajax.Updater($('user_li_div'), '/ajax/get_people_count_users_act.php?id='+id+'&sid='+sid, {evalScripts:true, method:'get'});
		};
	};
};

function open_people_count_users ()
{
	if ($('open_people_count_users').style.display=='')
	{
		clearTimeout(refresh_user_win_protoload_timer);
		clearTimeout(refresh_user_win_timer);
		Protoload.stopWaiting($('get_users_win_content_users'));
		$('people_count_users_content').innerHTML='';
		$('open_people_count_users').style.display='none';
		
	}
	else
	{
		$('open_people_count_users').style.display='';
		clock();
		new Ajax.Updater('people_count_users_content', '/ajax/get_people_count_users.php', {method: 'get',evalScripts: true, onComplete: unclock});
	};
};

function show_paper(ev)
{
	clock();
	divelement=document.createElement('DIV');
	divelement.id='paper_descr'+Event.element(ev).id.substr(3);
	divelement.style.zIndex=502;
	divelement.className='paper';
	divelement.style.position='absolute';
//	divelement.style.left=(Event.element(ev).offsetLeft+parseInt(Event.element(ev).width/2))+'px';
//	divelement.style.top=(Event.pointerY(ev).offsetTop+parseInt(Event.element(ev).height/2))+'px';
	divelement.style.left=(parseInt(document.body.offsetWidth/2))+'px';
	divelement.style.top=(parseInt((document.body.offsetHeight-$('header').offsetHeight-$('footer').offsetHeight)/2))+'px';
	divelement.style.display='none';
	Event.element(ev).parentNode.appendChild(divelement);
	new Ajax.Updater('paper_descr'+Event.element(ev).id.substr(3), '/ajax/get_paper.php?id='+Event.element(ev).id.substr(3), {method: 'get', evalScripts:true, onComplete: function () {unclock();} });
};

function hide_paper()
{
	papers=$('workarea').getElementsByClassName('paper');
	for (i=0; i<papers.length; i++)
	{
		papers[i].remove();
	};
	Event.stopObserving(document, 'click', hide_paper, false);
};

function change_info (ob)
{
	new Ajax.Updater ('change_info_win', '/ajax/update_info.php', {method: 'post', evalScripts:true, parameters:Form.serialize(ob), insertion:Insertion.Bottom});
};

function change_settings (ob, keys)
{
	new Ajax.Updater ('modal_container', '/ajax/update_settings.php?keys='+keys, {method: 'post', evalScripts:true, parameters:Form.serialize(ob), insertion:Insertion.Bottom});
};

function show_change_settings_position(ob)
{
	cur=document.getElementsByClassName('current_panel_pos');
	if (cur.length)
	{
			cur[0].style.display='none';
	};
	ob.down().show();
};

function hide_change_settings_position(ob)
{
	$('tools_pos_no').hide();
	cur=document.getElementsByClassName('current_panel_pos');
	if (cur.length)
	{
			cur[0].style.display='';
	};
	if (cur.length)
	{
		if (cur[0]!=ob.down())
			ob.down().hide();
	}
	else
	{
		ob.down().hide();
	};
};

function change_settings_position (id)
{
	if (!$('panel_pos_'+id).hasClassName('current_panel_pos'))
	{
		ob=document.getElementsByClassName('current_panel_pos');
		if (ob.length)
		{
			ob[0].removeClassName('current_panel_pos');
		};
		$('panel_pos_'+id).addClassName('current_panel_pos');
		new Ajax.Updater ('modal_container', '/ajax/update_settings_position.php?panel_position='+id, {method: 'get', evalScripts:true, insertion:Insertion.Bottom});
	};
};

function change_pass (ob)
{
	new Ajax.Updater ('change_pass_win', '/ajax/update_pass.php', {method: 'post', evalScripts:true, parameters:Form.serialize(ob), insertion:Insertion.Bottom});
};

function validate_pass_info (ob)
{
	if ((ob.new_p1.value != ob.new_p2.value) || !ob.new_p1.value)
	{
		matug ('Введённые пароли не совпадают!');
		return false;
	};
	if (!ob.cur_pass.value)
	{
		matug ('Не указан текущий пароль!');
		return false;
	};
	change_pass (ob);
};

function validate_user_info (ob)
{
	if (isNaN (ob.birth_y.value) || (ob.birth_y.value.length != 4))
	{
		matug ('Некорректный год рождения. Должно быть значение из 4-х цифр!');
		return false;
	};
	if (isNaN(ob.birth_d.value)||(ob.birth_d.value.length<1)||(ob.birth_d.value < 1)||(ob.birth_d.value > 31))
	{
		matug ('Некорректный день рождения. Должно быть значение от 1 до 31!');
		return false;
	};
	if (!ob.name.value || !ob.last_name.value)
	{
		matug ('Не укзано по крайней мере одно из обязательных полей - "Имя", "Фамилия"');
		return false;
	}
	else
	{
		var last_name_pattern = new RegExp ('^[а-яА-Яa-zA-ZёЁ]*[-]?[а-яА-Яa-zA-ZёЁ]+$');
		var name_pattern = new RegExp ('^[а-яА-Яa-zA-ZёЁ]*[ -]?[а-яА-Яa-zA-ZёЁ]+$');
		if (!name_pattern.test (ob.name.value))
		{
			matug ('Не корректное Имя');
			return false;
		};
		if (!last_name_pattern.test (ob.last_name.value))
		{
			matug ('Не корректная Фамилия');
			return false;
		};
	};
	if (ob.email)
	{
		var pattern = new RegExp ('([_.0-9a-z-]+@([0-9a-z][0-9a-z-]+.)+[a-z]{2,5})');
		if (!pattern.test (ob.email.value))
		{
			matug ('Некорректный адрес эл. почты! Учтите, что пароль будет выслан Вам на е-mail.');
			return false;
		};
	};

	change_info (ob);
};



function show_gluk(event)
{
	ob=Event.element(event);
	id='gluk_'+ob.id.substr(3);
//	alert($(id).src);
	$(id).style.width='1px'; 
	$(id).style.height='1px';	
	$(id).style.display='';
	new Effect.Scale($(id),100, {duration:0.2, scaleFromCenter: true,scaleFrom:0, scaleMode: { originalHeight: $(id).title.substr($(id).title.indexOf('_')+1), originalWidth: $(id).title.substr(0, $(id).title.indexOf('_')) }, afterFinish: function (ob) { pulsate_gluk(ob.element.id); } });
};

function pulsate_gluk (id)
{
	new Effect.Pulsate(id, {duration:0.5, pulses: 5, from:0.1, afterFinish: function (ob) { setTimeout("hide_gluk('"+ob.element.id+"')", 1000); } });
};

function hide_gluk (id)
{
	new Effect.Puff(id, {duration: 0.5, from: 0, to: 1});
};

function show_user_info(id)
{
	if (!$('yupi').visible())
	{
		$('yupi').style.top=(document.body.offsetHeight-40-277)+'px';
		$('yupi').style.left=(document.body.offsetWidth)+'px';
		$('yupi').style.display='';

		new Effect.Move ($('yupi'),{ x: -423, y: 0, mode: 'relative', duration:0.2});
		new Ajax.Updater('yupi_user_info', '/ajax/get_user_info.php?id='+id, {method: 'get', evalScripts: true});
	}
	else if ($('yupi_user_info').innerHTML>'')
	{
		if (!$('yupi_user_info_pic_'+id))
		{
			new Effect.Move ($('yupi'),{ x: 423, y: 0, mode: 'relative', duration:0.2, afterFinish: function () {$('yupi').style.display='none';show_user_info(id);} });
		};
	};
};

function close_user_info ()
{
	new Effect.Move ($('yupi'),{ x: 423, y: 0, mode: 'relative', duration:0.2, afterFinish: function () {$('yupi').style.display='none';} });
};

function show_opros (event, opros)
{
	ob=Event.findElement(event, 'IMG');
	if (!$('opros_'+ob.id.substr(3)))
	{
		divelement=document.createElement("DIV");
		divelement.id='opros_'+ob.id.substr(3);
		divelement.style.position='absolute';
		divelement.style.left='0px';
		divelement.style.top='0px';
		divelement.style.visibility='hidden';
//		divelement.style.overflow='hidden';
//		divelement.style.overflowY='auto';
		divelement.style.zIndex=1000;
		$('workarea').appendChild(divelement);
		
		new Ajax.Updater('opros_'+ob.id.substr(3), '/ajax/get_opros.php?id='+'opros_'+ob.id.substr(3)+'&opros='+opros, {method:'get', evalScripts:true});
	};
	
};

function save_opros(id, opros)
{
	clock();
	$(id).style.display='none';
	ans='';
	k=0;
	answers=$(id).getElementsByTagName('INPUT');
	for (i=0; i<answers.length; i++)
	{
		if (answers[i].type=='radio')
		{
			if (answers[i].checked)
			{
				ans+='&ans['+k+'][0]='+encodeURIComponent(answers[i].id.substr(3));
				ans+='&ans['+k+'][1]='+encodeURIComponent(answers[i].value);
				k++;
			};
		}
		else if (answers[i].type=='checkbox')
		{
			if (answers[i].checked)
			{
				ans+='&ans['+k+'][0]='+encodeURIComponent(answers[i].id.substr(3));
				ans+='&ans['+k+'][1]='+encodeURIComponent(answers[i].value);
				k++;
			};
		}
		else if (answers[i].type=='text')
		{
			if (answers[i].value>'')
			{
				ans+='&ans['+k+'][0]='+encodeURIComponent(answers[i].id.substr(3));
				ans+='&ans['+k+'][1]='+encodeURIComponent(answers[i].value);
				k++;
			};
		};
	};
	new Ajax.Updater('workarea', '/ajax/save_opros.php?id='+id, {method:'post', postBody:'id='+opros+ans, evalScripts:true, insertion:Insertion.Bottom, onComplete: function () {} });
	
};

function show_apear_pic(event)
{
	ob=Event.element(event);
	id='apear_pic_'+ob.id.substr(3);
	$(id).style.width='1px'; 
	$(id).style.height='1px';
	tit=$(id).title;
	typ=tit.substr(0,1);
	if ((typ=='c')||(typ=='p'))
	{
		tit=tit.substr(1);
	}
	else
	{
		typ='c';
	};
	width=tit.substr(0,tit.indexOf('_'));
	height=tit.substr(tit.indexOf('_')+1);
	if (typ=='c')
	{
		$(id).style.left=Math.floor(($('workarea').offsetWidth-width)/2)+'px';
		$(id).style.top=Math.floor(($('workarea').offsetHeight-height)/2)+'px';
	}
	else
	{
		$(id).style.left=(parseInt(ob.style.left)+Math.floor(parseInt(ob.width)/2)-parseInt(parseInt(width)/2))+'px';
		$(id).style.top=(parseInt(ob.style.top)+Math.floor(parseInt(ob.height)/2)-parseInt(parseInt(height)/2))+'px';
	};
	$(id).style.display='';
	new Effect.Scale($(id),100, {duration:0.2, scaleFromCenter: true,scaleFrom:0, scaleMode: { originalHeight: height, originalWidth: width }, afterFinish: function (ob) { } });
};

function hide_apear_pic (event)
{
	new Effect.Puff(Event.findElement(event, 'IMG'), {duration: 0.5, from: 0, to: 1, afterFinish: function (ob) {} });
	Event.stop (event);
	return false;
};

window.too_small = false;

//function hide_headers ()
//{
//	if ($('header').style.display!='none')
//	{
//		new Effect.SwitchOff ('self_head',{duration:0.2, afterFinish:function()
//			{
//				new Effect.SwitchOff('mainlogo', {duration:0.2, afterFinish:function()
//					{new Effect.SlideUp ('header', {duration: 0.2});};
//					});
//			}});
//	};
//	else
//	{
//		new Effect.SlideDown('header', {duration: 0.2});
//	};
//};

function hide_headers ()
{
	if ($('header').style.display!='none')
	{
		$('header').innerHtml='';
		new Effect.SlideUp('header', {duration: 0.2});
	}
	else
	{
		new Effect.SlideDown('header', {duration: 0.2});
	}	
};
function menuitem_switcher ()
{
	if ($('menuitems_div_'+panel_position))
	{
		if ($('menuitems_div_'+panel_position).style.display!='none')
		{
			//$('menuitems_div_'+panel_position).innerHTML='';
			new Effect.Fade('menuitems_div_'+panel_position, {duration: 0.2});
		}
		else
		{
			new Effect.Appear('menuitems_div_'+panel_position, {duration: 0.2});
		};
	};
};


function show_header ()
{
	$('header').style.zIndex = 501;
	$('header').style.visibility = 'visible';
	$('h_show').style.display = 'none';
	$('h_hide').style.display = '';
};

function hide_header ()
{
	$('header').style.zIndex = 0;
	$('header').style.visibility = 'hidden';
	$('h_hide').style.display = 'none';
	$('h_show').style.display = '';
};

function show_footer ()
{
	$('footer').style.visibility = 'visible';
	$('footer').style.zIndex = 501;
	
//	Event.stopObserving ($('footer'), 'mouseout', hide_footer_temp, true);
	$('visible_users').style.bottom = $('footer').offsetHeight+'px';

	$('f_show').style.display = 'none';
	$('f_hide').style.display = '';
};

function show_footer_temp ()
{
	$('footer').style.visibility = 'visible';
	$('footer').style.zIndex = 501;
	$('visible_users').style.bottom = $('footer').offsetHeight+'px';
};

function hide_footer_temp ()
{
	$('footer').style.visibility = 'hidden';
	$('footer').style.zIndex = 0;
	$('visible_users').style.bottom = $('foot_hider').offsetHeight+'px';
};

function hide_footer ()
{
	$('f_hide').style.display = 'none';
	$('f_show').style.display = '';
	zind = $('footer').style.zIndex - 1;
//	Event.observe($('footer'), 'mouseout', hide_footer_temp, true);
	$('footer').style.visibility = 'hidden';
	$('footer').style.zIndex = 0;

	if (!$('foot_hider'))
	{
		hdiv = document.createElement ('DIV');
		hdiv.id = 'foot_hider';
		hdiv.style.position = 'absolute';
		hdiv.style.left = '0px';
		hdiv.style.top = document.body.offsetHeight - 10 + 'px';
		hdiv.style.width = '100%';
		hdiv.style.height = '2px';
		hdiv.style.zIndex = zind;
//		hdiv.innerHTML = '<img src=/img/inv.gif height="2px" width="100%" onmouseover="show_footer_temp ();">';
		document.body.appendChild (hdiv);
	};
	$('visible_users').style.bottom = $('foot_hider').offsetHeight+'px';
};

function bodyonload ()
{
	new Ajax.Updater('musorka', '/ajax/get_dimensions.php?width='+document.body.offsetWidth+'&height='+document.body.offsetHeight + '&flash=' + flash, {method:'get', evalScripts:true });
};

function change_pass_alert (login)
{
//	if (!login)
//	{
		currentModal = new Control.Modal.open ('<div style="margin:10px 20px"><span class="defaultspan" style="font-size:18px">Восстановление пароля</span><br><br clear="all"><table cellpadding="0" cellspacing="3"><tr><td class="defaultspan">Электропочта</td><td><input id="pr_mail" class="defaultinput" style="height:20px; padding:3px; font-size:14px;" /></td></tr><tr><td colspan="2" align="center"><table cellpadding="5"><tr><td><img src="/img/inv.gif" class="win_ok" onclick="pass_restore ();" ></td><td><img src="/img/inv.gif" class="win_cancel" onclick="Control.Modal.close();"></td></tr></table></td></tr></table></div>',
			{
				overlayClassName: 'black_overlay',
				afterOpen: function ()
				{
					if ((/MSIE ((5\.5)|[6])/.test(navigator.userAgent)))
					{
//						$('modal_overlay').style.backgroundColor = '#000';
//						$('modal_overlay').style.filter = 'alpha(opacity=60, style=0)';
					};
				}});
/*		$('err_login').style.display = '';
		if ($('err_msg_span'))
			$('err_msg_span').innerHTML = 'Введите логин, для которого надо восстановить пароль!';*/
//	};
//	else
//		new Ajax.Updater ('login_win', '/ajax/change_pass_alert.php?login=' + encodeURIComponent (login), {method: 'get', evalScripts: true, 
//						  insertion: Insertion.Bottom});
};

function pass_restore ()
{
	mail = encodeURIComponent ($('pr_mail').value);
	Control.Modal.close ();
	new Ajax.Updater ('login_win', '/ajax/change_pass_alert.php?mail=' + mail,
						{method: 'get', evalScripts: true, insertion: Insertion.Bottom});
};

function block_key (ev)
{
	allow_move = true;

	if (ev.keyCode == 109 || ev.keyCode == 107 || ev.keyCode == 61)
		if (ev.ctrlKey)
			Event.stop (ev);

	els = document.getElementsByClassName ('restrict_move_input');
	if (els.length)
		allow_move = false;

	if (ev.keyCode > 36 && ev.keyCode < 41)
		if (ev.target)
			if (!ev.target.id)
				Event.stop (ev);

	if (!$('clock_div').visible () && allow_move)
	{
		if (ev.keyCode == 37 && $('prev960') && !$('temp_area'))
		{
			if (ev.ctrlKey)
				walk ($('prev'));
			else
				walk ($('prev960'));
		}
		else if (ev.keyCode == 39 && $('next960') && !$('temp_area'))
		{
			if (ev.ctrlKey)
				walk ($('next'));
			else
				walk ($('next960'));
		}
		else if (ev.keyCode == 40)
		{
			if ($('turn2'))
				ch_side ('2');
		}
		else if (ev.keyCode == 38)
		{
			if ($('turn1'))
				ch_side ('1');
		};
	};
};


function rent_plan()
{
	clock();
	new Ajax.Updater('modal_container', '/ajax/rent_plan.php', {method:'get', evalScripts: true, onComplete: function () {$('open_map').onclick ();unclock();}});
};

function lock_plan()
{
	$('gnus_container').startWaiting();
	new Ajax.Updater('locking_container', '/ajax/lock_plan.php', {method:'get', evalScripts: true, onComplete: function () {$('gnus_container').stopWaiting();} });
};

function return_from_locked()
{
	clock();
	new Ajax.Updater ('workarea', '/ajax/teleport.php', {method: 'get', evalScripts: true, onComplete: function () {unclock();} });
};

function go_to_main_page()
{
	document.location.replace('http://'+document.location.host+'/main/');
};


function click_flash_action(id, url, wmode)
{

$('click_flash_div_'+id).show();
click_flash_action_flash = new SWFObject(url, "click_flash_"+id, parseInt($('click_flash_div_'+id).style.width), parseInt($('click_flash_div_'+id).style.height), "8");
click_flash_action_flash.addParam('wmode',wmode);
click_flash_action_flash.write("click_flash_div_"+id);

	Event.observe(document, 'mousedown', hide_click_flash_action, true);
};

function hide_click_flash_action ()
{
	Event.stopObserving (document, 'mousedown', hide_click_flash_action, true);
	ar=$('workarea').getElementsByClassName('click_flash_class');
	for (i=0; i<ar.length; i++)
	{
		ar[i].innerHTML='';
		ar[i].hide();
	};
};


function mouseover_flash_action(id, url, wmode)
{
	$('mouseover_flash_div_'+id).show();
	mouseover_flash_action_flash = new SWFObject(url, "mouseover_flash_"+id, parseInt($('mouseover_flash_div_'+id).style.width), parseInt($('mouseover_flash_div_'+id).style.height), "8");
	mouseover_flash_action_flash.addParam('wmode',wmode);
	mouseover_flash_action_flash.write("mouseover_flash_div_"+id);

	Event.observe($('mouseover_flash_'+id), 'mouseout', hide_mouseover_flash_action, true);
};

function hide_mouseover_flash_action (event)
{
	ob=Event.findElement(event,'DIV');

	Event.stopObserving($(Event.element(event).id), 'mouseout', hide_mouseover_flash_action, true);

	ob.innerHTML='';
	ob.hide();
};

function edit_announcement (id)
{
	$('corrector_div').remove ();
	ann_string = $('announcement_' + id + '_text').innerHTML;
	ann_string = ann_string.replace (/<br>/g, '\n');
	$('announcement_' + id + '_text').innerHTML = '<textarea id="corrector_value" class="restrict_move_input" style="height:100%; width:100%;">' + ann_string + '</textarea><br/><input type=submit value="Сохранить" onclick="save_edit_announcement(' + id + ');return false">';
};

function delete_announcement (id)
{
	clock ();
	new Ajax.Updater ($('workarea'), '/ajax/delete_announcement.php?id=' + id, {method: 'get', evalScripts: true, insertion: Insertion.Bottom,
				onComplete: function()
				{
					$('announcement_'+id+'_win').style.display = 'none';
					unclock ();
				}});
};

function save_edit_announcement (id)
{
	clock ();
	new Ajax.Updater ($('workarea'), '/ajax/edit_announcement.php?id=' + id, {method: 'post', postBody: 'val=' + encodeURIComponent($('corrector_value').value), evalScripts: true, insertion: Insertion.Bottom,
				onComplete: function()
				{
					$('announcement_'+id+'_win').style.display = 'none';
					unclock();
				}});
};

function delete_user_action (id, action)
{
	new Ajax.Updater ('workarea', '/ajax/delete_user_action.php?id=' + id + '&action=' + action, {method:'get', evalScripts: true, insertion: Insertion.Bottom});
};

function get_owner_menu (ev)
{
	if (ev.button == 2)
	{
		if ($('user_element_menu'))
			$('user_element_menu').remove ();
		divelement = document.createElement ('DIV');
		divelement.id = 'user_element_menu';
		divelement.className = 'tooltip';
		divelement.style.zIndex = 800;
		divelement.style.left = parseInt(Event.pointerX(ev) - $('plan_view').offsetLeft + 2)+'px';
		divelement.style.bottom = parseInt($('workarea').offsetTop + $('plan_view').offsetTop + $('plan_view').offsetHeight - Event.pointerY(ev) + 2)+'px';
		divelement.style.position = 'absolute';
		divelement.innerHTML = '';
		id = Event.element(ev).id.substr(3);
		if (!isNaN (id))
		{
			if ($('ppi' + id).style.zIndex > 199 && $('ppi' + id).style.zIndex < 300)
			{
				$('ppi' + id).parentNode.appendChild (divelement);
				new Ajax.Updater ('user_element_menu', '/ajax/user_element_menu.php?id=' + id, {method:'get', evalScripts:true});
			}
			else
			{
				$('plan_view').appendChild (divelement);
				new Ajax.Updater ('user_element_menu', '/ajax/user_element_menu.php', {method:'get', evalScripts:true});
			};
		}
		else
		{
			$('plan_view').appendChild (divelement);
			new Ajax.Updater ('user_element_menu', '/ajax/user_element_menu.php', {method:'get', evalScripts:true});
		};
		Event.observe (document, 'mousedown', function (ev) {if ($('user_element_menu')) $('user_element_menu').remove();}, false);
	};
};

function load_pic_menu (ev)
{
	if (!$('user_image_edit_win'))
	{
		if (!$('open_user_image_edit'))
		{
			divelement = document.createElement ('DIV');
			divelement.id = 'open_user_image_edit';
			divelement.style.zIndex = 800;
			divelement.style.left = parseInt (Event.pointerX (ev) - $('plan_view').offsetLeft) + 'px';
			divelement.style.top = parseInt (Event.pointerY (ev) - $('workarea').offsetTop) + 'px';
			divelement.style.position = 'absolute';
			$('plan_view').appendChild (divelement);
		};
		openWin ($('open_user_image_edit'), {win_options: {title: 'Управление картинками'}});
	};
};

function delete_user_pic (file)
{
	new ModalRequest ({modal_text: 'Внимание! Уже размещённые элементы с этим изображением будут удалены! Продолжить?', onOK: function ()
		{
			poststring = 'file=' + encodeURIComponent (file);
			new Ajax.Updater ('user_image_edit', '/ajax/delete_user_image.php', {method:'post', postBody: poststring, evalScripts:true});
		}});
};

function place_image (file)
{
	poststring = 'file=' + encodeURIComponent (file) + '&x=' + parseInt ($('user_image_edit_win').offsetLeft) + '&y=' + parseInt ($('user_image_edit_win').style.top);
	new Ajax.Updater ('plan_view', '/ajax/place_pic.php', {method:'post', insertion:Insertion.Bottom, postBody:poststring, evalScripts:true});
};

function remove_plan_element (id_plan_views)
{
	new ModalRequest ({modal_text: 'Удалить элемент?', onOK: function ()
		{
			new Ajax.Updater ('ppi' + id_plan_views, '/ajax/remove_plan_element.php?id=' + id_plan_views, {method:'get', evalScripts:true});
		}});
};

var morph_widthElements = new Array();
function morph_width (element, to)
{
	count=0;
	from=element.offsetWidth;
	
	delta=(to-from)/5;
	morph_widthElements.push(element);
	setTimeout('do_morph_width('+(morph_widthElements.length-1)+', '+delta+', '+count+', '+from+');', 2);
};

function do_morph_width(i, delta, count, from)
{
	if (count<=5)
	{
		morph_widthElements[i].style.width=(from+parseInt(delta*count))+'px';
		count++;
		setTimeout('do_morph_width('+i+', '+delta+', '+count+', '+from+');', 2);
	};
};

function check_form_key (ev, code)
{
	if (ev.keyCode == 13)
		eval (code);
	return false;
};

window.default_title = 'Проект "Азиопия" : 100лица"';
function change_title (title_mess)
{
	document.title = title_mess;
};

function show_magazin (param)
{
	arr = param.split ('_');
	pages = arr[3] ? '&pages=' + arr[3] : '';
	number = (arr[1] > 0) ? '&id_number=' + arr[1] : '';
	switch (parseInt (arr[2]))
	{
		case 1:
			window.open ('http://smi.aziopia.ru/magazin/view.php?id_magazin=' + arr[0] + number + pages);
			break;
		case 2:
			if (!$('open_magazin'))
			{
				divelement = document.createElement ('div');
				divelement.id = 'open_magazin';
				document.body.appendChild (divelement);
			};
			ext = 'magazin=' + arr[0] + '&number=' + arr[1];
			if (arr[3])
				ext += '&pages=' + arr[3];
			openWin ($('open_magazin'), {external_param: ext, win_options: {width: 500}});
			break;
		default:
			if (!$('magazin'))
			{
				$('workarea').style.display='none';
				divelement = document.createElement ('div');
				divelement.id = 'magazin';
				divelement.style.zIndex = 500;
				divelement.style.position='absolute';
				divelement.style.overflow = 'hidden';
				divelement.style.width=document.body.offsetWidth+'px';
				divelement.style.height=(document.body.offsetHeight-$('header').offsetHeight-$('footer').offsetHeight)+'px';
				divelement.style.left='0px';
				divelement.style.top=$('header').offsetHeight+'px';
				divelement.style.backgroundColor = 'ffffff';
				document.body.appendChild (divelement);
			};
			test = new Object();
			test.id=arr[0];
			test.number=arr[1];
			test.view_arrows=true;
			test.pages = arr[3] ? parseInt (arr[3]) : 0;
			myMagazin = new Magazin ('magazin', 'myMagazin', test);
			Object.extend (myMagazin,
				{
					close_win: function ()
					{
						$('magazin').remove ();
						$('workarea').style.display = '';
					}
				});
	};
};

var includeCaption = 1;
var zoomTime       = 5;
var zoomSteps      = 15;
var fade           = 1;
var minBorder      = 90;
var zoomImageURI   = '/img/zoom/'; 
var myWidth = 0, myHeight = 0, myScroll = 0; myScrollWidth = 0; myScrollHeight = 0;
var zoomOpen = false, preloadFrame = 1, preloadActive = false, preloadTime = 0, imgPreload = new Image();
var zoomActive = new Array(); var zoomTimer  = new Array(); 
var zoomOrigW  = new Array(); var zoomOrigH  = new Array();
var zoomOrigX  = new Array(); var zoomOrigY  = new Array();
var zoomID    = "ZoomBox";
var theID     = "ZoomImage";
var theCap    = "ZoomCaption";
var theCapDiv = "ZoomCapDiv";

function setupZoom() {
	zoomdiv = document.getElementById(zoomID);  
	zoomimg = document.getElementById(theID);
};

function prepZooms() {
	if (! document.getElementsByTagName) {
		return;
	};
	var links = document.getElementsByTagName("a");
	for (i = 0; i < links.length; i++) {
		if (links[i].getAttribute("href") && (links[i].getAttribute("rel"))) {
			if (links[i].getAttribute("rel").indexOf("zoom:") == 0) {
				links[i].onclick = function () { zoomClick(this); return false; };
				links[i].onmouseover = function () { zoomPreload(this); };
			};
		};
	};
};

function zoomPreload(from) {
	var theimage = from.getAttribute("href");
	if (imgPreload.src.indexOf(from.getAttribute("href").substr(from.getAttribute("href").lastIndexOf("/"))) == -1) {
		preloadActive = true;
		imgPreload = new Image();
		imgPreload.onload = function() {
			preloadActive = false;
		};
		imgPreload.src = theimage;
	};
};

function preloadAnimStart() {
	preloadTime = new Date();
	document.getElementById("ZoomSpin").style.left = (myWidth / 2) + 'px';
	document.getElementById("ZoomSpin").style.top = ((myHeight / 2) + myScroll) + 'px';
	document.getElementById("ZoomSpin").style.visibility = "visible";	
	preloadFrame = 1;
	document.getElementById("SpinImage").src = zoomImageURI+'zoom-spin-'+preloadFrame+'.png';  
	preloadAnimTimer = setInterval("preloadAnim()", 100);
};

function preloadAnim(from) {
	if (preloadActive != false) {
		document.getElementById("SpinImage").src = zoomImageURI+'zoom-spin-'+preloadFrame+'.png';
		preloadFrame++;
		if (preloadFrame > 12) preloadFrame = 1;
	} else {
		document.getElementById("ZoomSpin").style.visibility = "hidden";    
		clearInterval(preloadAnimTimer);
		zoomIn(preloadFrom);
	};
};

function zoomClick(from) {
	getSize();
	if (preloadActive == true) {
		preloadFrom = from;
		preloadAnimStart();
	} else {
		zoomIn(from);
	};
};

function zoomIn(from) {
	$('ZoomImage').src = from.getAttribute("href");
	if (from.childNodes[0].width) {
		startW = from.childNodes[0].width;
		startH = from.childNodes[0].height;
		startPos = findElementPos(from.childNodes[0]);
	} else {
		startW = 50;
		startH = 12;
		startPos = findElementPos(from);
	};
	hostX = startPos[0];
	hostY = startPos[1];
	if (document.getElementById('scroller')) {
		hostX = hostX - document.getElementById('scroller').scrollLeft;
	};
	endW = imgPreload.width;

	endH = imgPreload.height;
	if (zoomActive[theID] != true) {
		document.getElementById("ShadowBox").style.visibility = "hidden";
		document.getElementById("ZoomClose").style.visibility = "hidden";     
		if (includeCaption == 1) {
			zoomcap  = document.getElementById(theCap);
			zoomcapd = document.getElementById(theCapDiv);
       
			if (from.getAttribute('title') && includeCaption == 1) {
				zoomcapd.style.display = 'block';
				zoomcap.innerHTML = from.getAttribute('title');
			} else {
				zoomcapd.style.display = 'none';
			};
		}   
		zoomOrigW[theID] = startW;
		zoomOrigH[theID] = startH;
		zoomOrigX[theID] = hostX;
		zoomOrigY[theID] = hostY;
		zoomimg.style.width = startW + 'px';
		zoomimg.style.height = startH + 'px';
		zoomdiv.style.left = hostX + 'px';
		zoomdiv.style.top = hostY + 'px';
		if (fade == 1) {
			setOpacity(0, zoomID);
		};
		zoomdiv.style.visibility = "visible";
		sizeRatio = endW / endH;
		if (endW > myWidth - minBorder) {
			endW = myWidth - minBorder;
			endH = endW / sizeRatio;
		};
		if (endH > myHeight - minBorder) {
			endH = myHeight - minBorder;
			endW = endH * sizeRatio;
		};
		zoomChangeX = ((myWidth / 2) - (endW / 2) - hostX);
		zoomChangeY = (((myHeight / 2) - (endH / 2) - hostY) + myScroll);
		zoomChangeW = (endW - startW);
		zoomChangeH = (endH - startH);
		zoomCurrent = 0;
		if (fade == 1) {
			fadeCurrent = 0;
			fadeAmount = (0 - 100) / zoomSteps;
		} else {
			fadeAmount = 0;
		};
		zoomTimer[theID] = setInterval("zoomElement('"+zoomID+"', '"+theID+"', "+zoomCurrent+", "+startW+", "+zoomChangeW+", "+startH+", "+zoomChangeH+", "+hostX+", "+zoomChangeX+", "+hostY+", "+zoomChangeY+", "+zoomSteps+", "+fade+", "+fadeAmount+", 'zoomDoneIn(zoomID)')", zoomTime);		
		zoomActive[theID] = true; 
	};
};
function zoomOut() {
	if (zoomActive[theID] != true) {
		document.getElementById("ShadowBox").style.visibility = "hidden";
		document.getElementById("ZoomClose").style.visibility = "hidden";
		startX = parseInt(zoomdiv.style.left);
		startY = parseInt(zoomdiv.style.top);
		startW = zoomimg.width;
		startH = zoomimg.height;
		zoomChangeX = zoomOrigX[theID] - startX;
		zoomChangeY = zoomOrigY[theID] - startY;
		zoomChangeW = zoomOrigW[theID] - startW;
		zoomChangeH = zoomOrigH[theID] - startH;
		zoomCurrent = 0;
		if (fade == 1) {
			fadeCurrent = 0;
			fadeAmount = (100 - 0) / zoomSteps;
		} else {
			fadeAmount = 0;
		};
		zoomTimer[theID] = setInterval("zoomElement('"+zoomID+"', '"+theID+"', "+zoomCurrent+", "+startW+", "+zoomChangeW+", "+startH+", "+zoomChangeH+", "+startX+", "+zoomChangeX+", "+startY+", "+zoomChangeY+", "+zoomSteps+", "+fade+", "+fadeAmount+", 'zoomDone(zoomID, theID)')", zoomTime);	
		zoomActive[theID] = true;
   };
};
function zoomDoneIn(zoomdiv, theID) {
	zoomOpen = true;
	setOpacity(0, "ShadowBox");
	setOpacity(0, "ZoomClose");
	zoomdiv = document.getElementById(zoomdiv);
	shadowdiv = document.getElementById("ShadowBox");
	shadowLeft = parseInt(zoomdiv.style.left) - 13;
	shadowTop = parseInt(zoomdiv.style.top) - 8;
	shadowWidth = zoomdiv.offsetWidth + 26;
	shadowHeight = zoomdiv.offsetHeight + 26; 
	shadowdiv.style.width = shadowWidth + 'px';
	shadowdiv.style.height = shadowHeight + 'px';
	shadowdiv.style.left = shadowLeft + 'px';
	shadowdiv.style.top = shadowTop + 'px';
	document.getElementById("ShadowBox").style.visibility = "visible";
	fadeElementSetup("ShadowBox", 0, 100, 5);
	document.getElementById("ZoomClose").style.visibility = "visible";
	fadeElementSetup("ZoomClose", 0, 100, 5);
};
function zoomDone(zoomdiv, theID) {
	zoomOpen = false;
	zoomOrigH[theID] = "";
	zoomOrigW[theID] = "";
	document.getElementById(zoomdiv).style.visibility = "hidden";
	zoomActive[theID] == false;
};
function zoomElement(zoomdiv, theID, zoomCurrent, zoomStartW, zoomChangeW, zoomStartH, zoomChangeH, zoomStartX, zoomChangeX, zoomStartY, zoomChangeY, zoomSteps, fade, fadeAmount, execWhenDone) {
	if (zoomCurrent == (zoomSteps + 1)) {
		zoomActive[theID] = false;
		clearInterval(zoomTimer[theID]);
		if (execWhenDone != "") {
			eval(execWhenDone);
		};
	} else {
		if (fade != 0) {
			if (fadeAmount < 0) {
				setOpacity(Math.abs(zoomCurrent * fadeAmount), zoomdiv);
			} else {
				setOpacity(100 - (zoomCurrent * fadeAmount), zoomdiv);
			};
		};
		moveW = cubicInOut(zoomCurrent, zoomStartW, zoomChangeW, zoomSteps);
		moveH = cubicInOut(zoomCurrent, zoomStartH, zoomChangeH, zoomSteps);
		moveX = cubicInOut(zoomCurrent, zoomStartX, zoomChangeX, zoomSteps);
		moveY = cubicInOut(zoomCurrent, zoomStartY, zoomChangeY, zoomSteps);
		document.getElementById(zoomdiv).style.left = moveX + 'px';
		document.getElementById(zoomdiv).style.top = moveY + 'px';
		zoomimg.style.width = moveW + 'px';
		zoomimg.style.height = moveH + 'px';
		zoomCurrent++;
		clearInterval(zoomTimer[theID]);
		zoomTimer[theID] = setInterval("zoomElement('"+zoomdiv+"', '"+theID+"', "+zoomCurrent+", "+zoomStartW+", "+zoomChangeW+", "+zoomStartH+", "+zoomChangeH+", "+zoomStartX+", "+zoomChangeX+", "+zoomStartY+", "+zoomChangeY+", "+zoomSteps+", "+fade+", "+fadeAmount+", '"+execWhenDone+"')", zoomTime);
	};
};
function zoomMouseOver() {
};
function zoomMouseOut() {
};
function fadeOut(elem) {
	if (elem.id) {
		fadeElementSetup(elem.id, 100, 0, 10);
	};
};

function fadeIn(elem) {
	if (elem.id) {
		fadeElementSetup(elem.id, 0, 100, 10);	
	};
};
var fadeActive = new Array();
var fadeQueue  = new Array();
var fadeTimer  = new Array();
var fadeClose  = new Array();
function fadeElementSetup(theID, fdStart, fdEnd, fdSteps, fdClose) {
	if (fadeActive[theID] == true) {
		fadeQueue[theID] = new Array(theID, fdStart, fdEnd, fdSteps);
	} else {
		fadeSteps = fdSteps;
		fadeCurrent = 0;
		fadeAmount = (fdStart - fdEnd) / fadeSteps;
		fadeTimer[theID] = setInterval("fadeElement('"+theID+"', '"+fadeCurrent+"', '"+fadeAmount+"', '"+fadeSteps+"')", 15);
		fadeActive[theID] = true;
		if (fdClose == 1) {
			fadeClose[theID] = true;
		} else {
			fadeClose[theID] = false;
		};
	};
};
function fadeElement(theID, fadeCurrent, fadeAmount, fadeSteps) {
	if (fadeCurrent == fadeSteps) {
	    clearInterval(fadeTimer[theID]);
	    fadeActive[theID] = false;
	    if (fadeClose[theID] == true) {
	    	document.getElementById(theID).style.visibility = "hidden";
	    };
	    if (fadeQueue[theID] && fadeQueue[theID] != false) {
	    	fadeElementSetup(fadeQueue[theID][0], fadeQueue[theID][1], fadeQueue[theID][2], fadeQueue[theID][3]);
	    	fadeQueue[theID] = false;
	    }  
	} else {
		fadeCurrent++;
		if (fadeAmount < 0) {
			setOpacity(Math.abs(fadeCurrent * fadeAmount), theID);
		} else {
			setOpacity(100 - (fadeCurrent * fadeAmount), theID);
		};
		clearInterval(fadeTimer[theID]);
		fadeTimer[theID] = setInterval("fadeElement('"+theID+"', '"+fadeCurrent+"', '"+fadeAmount+"', '"+fadeSteps+"')", 15);
	};
};
function setOpacity(opacity, theID) {
	var object = document.getElementById(theID).style;
	if (navigator.userAgent.indexOf("Firefox") != -1) {
		if (opacity == 100) { opacity = 99.9999; } 
	};
	object.filter = "alpha(opacity=" + opacity + ")";
	object.opacity = (opacity / 100);  
};
function linear(t, b, c, d)
{
	return c*t/d + b;
};
function sineInOut(t, b, c, d)
{
	return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
};
function cubicIn(t, b, c, d) {
	return c*(t/=d)*t*t + b;
};
function cubicOut(t, b, c, d) {
	return c*((t=t/d-1)*t*t + 1) + b;
};
function cubicInOut(t, b, c, d)
{
	if ((t/=d/2) < 1) return c/2*t*t*t + b;
	return c/2*((t-=2)*t*t + 2) + b;
};
function bounceOut(t, b, c, d)
{
	if ((t/=d) < (1/2.75)){
		return c*(7.5625*t*t) + b;
	} else if (t < (2/2.75)){
		return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
	} else if (t < (2.5/2.75)){
		return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
	} else {
		return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
	};
};
function getSize() {
	if (document.all) {
		myWidth  = (document.documentElement.clientWidth) ? document.documentElement.clientWidth : document.body.clientWidth;
		myHeight = (document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.clientHeight;
		myScroll = (document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
	} else {
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
		myScroll = window.pageYOffset;
	};
    if (window.innerHeight && window.scrollMaxY) {	
        myScrollWidth = document.body.scrollWidth;
		myScrollHeight = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
		myScrollWidth = document.body.scrollWidth;
		myScrollHeight = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		myScrollWidth = document.body.offsetWidth;
		myScrollHeight = document.body.offsetHeight;
	};
};
function findElementPos(elemFind)
{
	var elemX = 0;
	var elemY = 0;
	do {
		elemX += elemFind.offsetLeft;
		elemY += elemFind.offsetTop;
	} while ( elemFind = elemFind.offsetParent )
	return Array(elemX, elemY);
};

function update_chulan ()
{
	if ($('chulan_win'))
		new Ajax.Updater ('chulan', '/ajax/chulan.php', {method:'get', evalScripts: true});
	else
		openWin ($('open_chulan'), {no_update: true, win_options: {width: 300, title: 'Портфель'}});
};

function get_chulan_menu (ev)
{
	if (ev.button == 2)
	{
		pos = Position.cumulativeOffset (Event.element(ev));
		id = Event.element(ev).id;
		if (id.substr (0, 3) == 'ch_')
		{
			id_chulan = id.substr (6);
			if (!$('set_own_price'))
			{
				divelement = document.createElement ('div');
				divelement.id = 'set_own_price';
				divelement.className = 'tooltip';
				divelement.style.position = 'absolute';
				$('chulan_win').appendChild (divelement);
			};
			$('set_own_price').innerHTML = '<a onclick="set_own_price (' + id_chulan + ');" style="cursor:pointer">Установить цену</a>';
			$('set_own_price').style.left = Event.element(ev).offsetLeft + 'px';
			$('set_own_price').style.top = Event.element(ev).offsetTop + 'px';
		};
	};
};

function set_own_price (id_chulan)
{
	divelement = document.createElement ('div');
	divelement.id = 'open_self_price';
	$('chulan').appendChild (divelement);
	openWin ($('open_self_price'), {external_param: 'id=' + id_chulan, win_options: {title: 'Установка цены', width: 200}});
	$('set_own_price').remove ();
};

function show_gnus_info()
{
	if ($('gnus_info').style.display=='')
	{
		window.gnus_info_opened=0; 
		new Effect.Fade('gnus_info',{duration:0.3,
					 				afterUpdate: function(){ myWins['map_obj'].updateDimensions(); },
									afterFinish: function(){ myWins['map_obj'].updateDimensions(); } 
									});
		$('show_gnus_info_img').style.backgroundImage='url(/img/right_switch.gif)';
	}
	else
	{
		window.gnus_info_opened=1;
		new Effect.Appear('gnus_info',{duration:0.3,
					   				afterUpdate: function(){ myWins['map_obj'].updateDimensions(); },
									afterFinish: function(){ myWins['map_obj'].updateDimensions(); }
									});
		$('show_gnus_info_img').style.backgroundImage='url(/img/left_switch.gif)';	 
	};
};

function save_self_price (id)
{
	poststr = '';
	if (parseInt ($('my_price').value))
		poststr += 'price=' + parseInt ($('my_price').value);
	if ($('my_name'))
		poststr += '&name=' + encodeURIComponent ($('my_name').value);
	new Ajax.Request ('/ajax/save_self_price.php?id=' + id, {method: 'post', postBody: poststr, onComplete: function ()
			{
				$('self_price_win').remove ();
				delete myWins['self_price_obj'];
			}});
};

function add_user_descr (id)
{
	if (!$('open_user_descr'))
	{
		divelement = document.createElement ('div');
		divelement.id = 'open_user_descr';
		$('plan_view').appendChild (divelement);
	};
	openWin ($('open_user_descr'), {external_param: 'id=' + id, win_options: {title: 'Установка описания'}});
};

function get_transactions (id_bablo, bill_id)
{
	clock();
	
	

	
/*	if (!$('open_get_transactions'))
	{
		divelement = document.createElement ('div');
		divelement.id = 'open_get_transactions';
		$('workarea').appendChild (divelement);
	};
	openWin ($('open_get_transactions'), {no_update: true, exec_on_show: "if ($('transaction_table')) if ($('transaction_table').offsetHeight>250) $('transaction_table').setStyle({height:'200px', overflow:'hidden', overflowY:'auto'});", external_param: 'id_bablo=' + id_bablo, win_options: {title: 'Детализация счёта №' + bill_id, top: 200}});
*/
	if ($('money_action' + id_bablo).style.display)
	{
		elems=document.getElementsByClassName('money_bill');
		for (i=0; i<elems.length;i++)
		{
			if (elems[i].id.substr(12)!=id_bablo)
			{
				elems[i].style.display='none';
				$('fin_collaps_'+elems[i].id.substr(12)).hide();
				$('fin_expand_'+elems[i].id.substr(12)).show();
			};
		};
		
//		$('modal_content').style.visibility='hidden';
		el = $('money_action' + id_bablo);
		new Ajax.Updater (el, '/ajax/get_transactions.php?id_bablo=' + id_bablo, {method: 'get', evalScripts: true, onComplete: function ()
			{
				if ($('transaction_table'))
					if ($('transaction_table').offsetHeight>250)
						$('transaction_table').setStyle({height:'200px', overflow:'hidden', overflowY:'auto'});
				$('money_action' + id_bablo).style.display = '';
//				resizeContainer(0,250);
	Control.Modal.center($('modal_container'));unclock();			
			}});
	}
	else {$('money_action' + id_bablo).style.display = 'none';Control.Modal.center($('modal_container')); unclock();};
};

function get_item_transaction (id)
{
	clock ();
	new Ajax.Updater ('item_area_' + id, '/ajax/item_transaction.php?id=' + id, {method: 'get', evalScripts: true, onComplete: function ()
		{
			if ($('item_area_' + id))
				$('item_area_' + id).style.display = '';
			unclock ();
			currentModal.position ();
		}});
};

function get_item_location (id)
{
	clock ();
	new Ajax.Updater ('item_area_' + id, '/ajax/item_location.php?id=' + id, {method: 'get', evalScripts: true, onComplete: function ()
		{
			if ($('item_area_' + id))
				$('item_area_' + id).style.display = '';
			unclock ();
			currentModal.position ();
		}});
};

function save_item (id)
{
	poststr = '';
	if ($('item_name_' + id))
		if ($('item_name_' + id).value)
			poststr = 'name=' + encodeURIComponent ($('item_name_' + id).value);

	if ($('item_price_' + id))
		if ($('item_price_' + id).value)
			poststr += '&price=' + $('item_price_' + id).value;

	new Ajax.Request ('/ajax/personal/save_item.php?id=' + id, {method: 'post', postBody: poststr, onComplete: function ()
			{
				if ($('item_name_' + id))
					$('item_name_td_' + id).innerHTML = $('item_name_' + id).value;

				if ($('item_price_' + id))
					$('item_price_td_' + id).innerHTML = $('item_price_' + id).value + ' руб.';
			}});
};


var MainObjectClass = Class.create();

MainObjectClass.prototype = {

	initialize: function (name)
	{
		this.name=name;
	},
	start: function ()
	{
		this.checkClickBind=this.checkClick.bindAsEventListener(this, this);
		Event.observe(document.body,'click', window[this.name].checkClickBind);

		this.checkDblClickBind=this.checkDblClick.bindAsEventListener(this, this);
		Event.observe(document.body,'dblclick', window[this.name].checkDblClickBind);

		this.checkMouseMoveBind=this.checkMouseMove.bindAsEventListener(this, this);
		Event.observe(document.body,'mousemove', window[this.name].checkMouseMoveBind);
	},
	Actions: new Object(),
	setActions:function (object)
	{
		this.Actions[object.name]=new Object ();
		this.Actions[object.name]=Object.extend(this.Actions[object.name],object);
	},
	name: '',
	clearActs: function ()
	{
		placeinfos=document.getElementsByClassName('placeinfo');
		for (i=0;i<placeinfos.length;i++)
		{
			placeinfos[i].innerHTML='';
		};
		this.MouseMoveElem = '';
		this.ActClick = new Object();
		this.ActClickFire = new Object();
		this.ActNone = new Object();
		this.ActNoneFire = new Object();
		this.ActDblClick = new Object();
		this.ActDblClickFire = new Object();
		this.ActMouseMove = new Object();
		this.ActMouseMoveFire = new Object();
		this.Acts = new Array();
	},
	clearActs_plan: function ()
	{
		placeinfos=document.getElementsByClassName('placeinfo');
		for (i=0; i<placeinfos.length;i++)
		{
			placeinfos[i].innerHTML='';
		};
		this.MouseMoveElem = '';
		this.ActClick = new Object();
		this.ActClickFire = new Object();
		this.ActNone = new Object();
		this.ActNoneFire = new Object();
		this.ActDblClick = new Object();
		this.ActDblClickFire = new Object();
		this.ActMouseMove = new Object();
		this.ActMouseMoveFire = new Object();
		this.Acts = new Array();
	},
	clearActs_plan_sh: function ()
	{
		this.buffer_Acts_sh = new Array();
		this.Acts_sh = new Array();
	},
	ActClick: new Object(),
	ActClickFire: new Object(),
	ActNone: new Object(),
	ActNoneFire: new Object(),
	ActDblClick: new Object(),
	ActDblClickFire: new Object(),
	ActMouseMove: new Object(),
	ActMouseMoveFire: new Object(),
	Acts: new Array(),
	buffer_Acts_sh: new Array(),
	setAct: function (id, typ, x, y, w, h, text)
	{
		workoffset=$('workarea').offsetTop;

		obj={typ:typ, id:id, leftx:x, y:y-workoffset, width:w, height:h, pic_host:pic_host, zIndex:$('pic'+id).style.zIndex, action:text};
		this.Acts.push(obj);
	},
	setAct_plan: function (id, typ, x, y, w, h, text)
	{
		workoffset=$('workarea').offsetTop;

		obj={typ:typ, id:id, leftx:x, y:y-workoffset, width:w, height:h, pic_host:pic_host, zIndex:$('ppi'+id).style.zIndex, action:text};
		this.Acts.push(obj);
	},
	setAct_plan_sh: function (id, typ, x, y, w, h, text)
	{
		workoffset=$('workarea').offsetTop;

		obj={typ:typ, id:id, leftx:x, y:y-workoffset, width:w, height:h, pic_host:pic_host, zIndex:$('ppi'+id).style.zIndex, action:text};
		this.Acts_sh.push(obj);
	},
	fireAct_plan: function ()
	{
		for(i=0; i<this.Acts.length; i++)
		{
			elem=this.Acts[i];	
			if (this.Actions[elem.typ])
			{
				if (this.Actions[elem.typ].eventname=='click')
				{
					this.ActClick['pli'+elem.id]=elem.id;
					templ=new Template(this.Actions[elem.typ].initscript_plan);
					eval(templ.evaluate(elem));

					if (!this.ActClickFire[elem.id]) {this.ActClickFire[elem.id] = new Array();};
					this.ActClickFire[elem.id].push(elem);
				}
				else if (this.Actions[elem.typ].eventname=='')
				{
					templ=new Template(this.Actions[elem.typ].initscript_plan);
					eval(templ.evaluate(elem));
				}
				else if (this.Actions[elem.typ].eventname=='mousemove')
				{
					this.ActMouseMove['pli'+elem.id]=elem.id;
					templ=new Template(this.Actions[elem.typ].initscript_plan);
					eval(templ.evaluate(elem));

					this.ActMouseMoveFire[elem.id]=elem;
				}
				else if (this.Actions[elem.typ].eventname=='dblclick')
				{
					this.ActDblClick['pli'+elem.id]=elem.id;
					templ=new Template(this.Actions[elem.typ].initscript_plan);
					eval(templ.evaluate(elem));

					this.ActDblClickFire[elem.id]=elem;
				};
			};
		};
		this.Acts = new Array();
	},
	fireAct_plan_sh: function ()
	{
		for(i=0; i<this.Acts_sh.length; i++)
		{
			if (this.ActClickFire[this.Acts_sh[i].id])
				this.ActClickFire[this.Acts_sh[i].id] = new Array();
			if (this.ActNoneFire[this.Acts_sh[i].id])
				this.ActNoneFire[this.Acts_sh[i].id] = new Array();
			if (this.ActDblClickFire[this.Acts_sh[i].id])
				this.ActDblClickFire[this.Acts_sh[i].id] = new Array();
			if (this.ActMouseMoveFire[this.Acts_sh[i].id])
				this.ActMouseMoveFire[this.Acts_sh[i].id] = new Array();
		};
		for(i=0; i<this.Acts_sh.length; i++)
		{
			elem=this.Acts_sh[i];	
			if (this.Actions[elem.typ])
			{
				if (this.Actions[elem.typ].eventname=='click')
				{
					this.ActClick['pli'+elem.id]=elem.id;
					templ=new Template(this.Actions[elem.typ].initscript_plan);
					eval(templ.evaluate(elem));
					
					if (!this.ActClickFire[elem.id]) {this.ActClickFire[elem.id] = new Array();};
					this.ActClickFire[elem.id].push(elem);
				}
				else if (this.Actions[elem.typ].eventname=='')
				{
					templ=new Template(this.Actions[elem.typ].initscript_plan);
					eval(templ.evaluate(elem));
				}
				else if (this.Actions[elem.typ].eventname=='mousemove')
				{
					this.ActMouseMove['pli'+elem.id]=elem.id;
					templ=new Template(this.Actions[elem.typ].initscript_plan);
					eval(templ.evaluate(elem));

					this.ActMouseMoveFire[elem.id]=elem;
				}
				else if (this.Actions[elem.typ].eventname=='dblclick')
				{
					this.ActDblClick['pli'+elem.id]=elem.id;
					templ=new Template(this.Actions[elem.typ].initscript_plan);
					eval(templ.evaluate(elem));

					this.ActDblClickFire[elem.id]=elem;
				};
			};
		};
		this.Acts_sh = new Array();
	},
	fireAct: function ()
	{

		for(i=0; i<this.Acts.length; i++)
		{
			elem=this.Acts[i];					 
			if (this.Actions[elem.typ])
			{
				if (this.Actions[elem.typ].eventname=='click')
				{
					this.ActClick['pli'+elem.id]=elem.id;
					templ=new Template(this.Actions[elem.typ].initscript);
					eval(templ.evaluate(elem));

					if (!this.ActClickFire[elem.id]) {this.ActClickFire[elem.id] = new Array();};
					this.ActClickFire[elem.id].push(elem);
				}
				else if (this.Actions[elem.typ].eventname=='')
				{
					templ=new Template(this.Actions[elem.typ].initscript);
					eval(templ.evaluate(elem));
				}
				else if (this.Actions[elem.typ].eventname=='mousemove')
				{
					this.ActMouseMove['pli'+elem.id]=elem.id;
					templ=new Template(this.Actions[elem.typ].initscript);
					eval(templ.evaluate(elem));

					this.ActMouseMoveFire[elem.id]=elem;
				}
				else if (this.Actions[elem.typ].eventname=='dblclick')
				{
					this.ActDblClick['pli'+elem.id]=elem.id;
					templ=new Template(this.Actions[elem.typ].initscript);
					eval(templ.evaluate(elem));

					this.ActDblClickFire[elem.id]=elem;
				};
			};
		};
		this.Acts = new Array();
	},
	checkClick: function (event, object)
	{
		if (event.element().hasClassName('action_inv'))
		{	
			x=event.pointerX();
			y=event.pointerY();
			if (id=object.ActClick[event.element().id])
			{
				str='';
				for (i=0; i<object.ActClickFire[id].length; i++)
				{
					if ($('plan_view'))
						templ = new Template(object.Actions[object.ActClickFire[id][i].typ].firescript_plan);
					else
						templ = new Template(object.Actions[object.ActClickFire[id][i].typ].firescript);

					str+=templ.evaluate(Object.extend({event:event}, object.ActClickFire[id][i]) );
				};
				eval(str);
			};
		};
	},
	checkDblClick: function (event, object)
	{
		if (event.element().hasClassName('action_inv'))
		{

			x=event.pointerX();
			y=event.pointerY();
			if (id=object.ActDblClick[event.element().id])
			{
					if ($('plan_view'))
						templ = new Template(object.Actions[object.ActDblClickFire[id].typ].firescript_plan);
					else
						templ = new Template(object.Actions[object.ActDblClickFire[id].typ].firescript);
	
	
					str=templ.evaluate(Object.extend({event:event}, object.ActDblClickFire[id]) );
					eval(str);
			};
		};
	},
	MouseMoveElem: '',
	checkMouseMove: function (event, object)
	{
		id=event.element().id;
		if (object.MouseMoveElem>'') if (object.MouseMoveElem!=id.substr(3))
		{
				if ($('plan_view'))
					templ = new Template(object.Actions[object.ActMouseMoveFire[object.MouseMoveElem].typ].endscript_plan);
				else
					templ = new Template(object.Actions[object.ActMouseMoveFire[object.MouseMoveElem].typ].endscript);
	
	
				str=templ.evaluate(Object.extend({event:event}, object.ActMouseMoveFire[object.MouseMoveElem]) );

				eval(str);
				object.MouseMoveElem='';
		};
		if (id=object.ActMouseMove[id])
		{
			if ((object.Actions[object.ActMouseMoveFire[id].typ].repeat>0)||(object.MouseMoveElem!=id) )
			{
				object.MouseMoveElem=id;
				
				x=event.pointerX();
				y=event.pointerY();

				if ($('plan_view'))
					templ = new Template(object.Actions[object.ActMouseMoveFire[id].typ].firescript_plan);
				else
					templ = new Template(object.Actions[object.ActMouseMoveFire[id].typ].firescript);
	
	
				str=templ.evaluate(Object.extend({event:event}, object.ActMouseMoveFire[id]) );

				eval(str);
			};
		};
	},
	setPlaceInfo: function (t)
	{
		placeinfos=document.getElementsByClassName('placeinfo');
		for (k=0;k<placeinfos.length;k++)
		{
			placeinfos[k].innerHTML+='<div>'+t+'</div>';
		};
//		$('placeinfo').innerHTML='<div>'+t+'</div>';
	},
	getPlaceInfo: function ()
	{
/*		if ($('placeinfo').innerHTML>'')
		{
			currentModal = new Control.Modal.open($('placeinfo').innerHTML);
		}*/
	},
	endMouseMove: function (event)
	{
		if (this.MouseMoveElem>'')
		{
				if (arguments[1])
					templ = new Template(this.Actions[this.ActMouseMoveFire[this.MouseMoveElem].typ].endscript_plan);
				else
					templ = new Template(this.Actions[this.ActMouseMoveFire[this.MouseMoveElem].typ].endscript);
	
	
				str=templ.evaluate(this.ActMouseMoveFire[this.MouseMoveElem]);

				//alert(str);
				//eval(str);
				this.MouseMoveElem='';
		};
	}
};

function check_gb_mess(id_plan)
{
	if ($('guest_message').value) 
		new Ajax.Updater ('guest_book_' + id_plan, '/ajax/post_guest_message.php', {evalScripts:true, method: 'post', postBody: 'mess=' + encodeURIComponent ($('guest_message').value)});
	else 
		currentModal = new Control.Modal.open('<div style="width:300px; padding:20px 20px 10px 20px;"><table width="100%" cellpadding="0" cellspacing="0"><tr><td class="defaultspan">Мы сожалеем, но отправить пустое сообщение нельзя. Телепатические способности человека всё ещё исследуются в лабораториях Смотрящего.</td></tr><tr><td align="center" style="padding-top:20px"><img src="/img/inv.gif" class="win_ok" onclick="Control.Modal.close();"></td></tr></div>');
};

function plan_stat_clear(id_plan)
{
	filter = 0;
	if (arguments[1])
		filter = arguments[1];
	currentModal = new Control.Modal.open('<div style="width:300px; padding:20px 20px 10px 20px;"><table cellpadding="0" cellspacing="0"><tr><td class="defaultspan">Данное действие уничтожит всю статистику посещений этого помещения. Совсем уничтожит. Насмерть.<br><br>Вы действительно хотите этого ?</td></tr><tr><td align="center" style="padding-top:20px"><table><tr><td><img src="/img/inv.gif" class="win_ok" onclick="new Ajax.Updater (\'plan_stat_' + id_plan + '\', \'/ajax/clear_plan_stat.php?filter=' + filter + '\', {method:\'get\'}); Control.Modal.close();"></td><td align="left" style="padding-left:5px"><img src="/img/inv.gif" class="win_cancel" onclick="Control.Modal.close();"></td></tr></table></td></tr></table></div>');
};

function gb_delete_message(id)
{
	currentModal = new Control.Modal.open('<div style="width:300px; padding:20px 20px 10px 20px;"><table cellpadding="0" cellspacing="0"><tr><td class="defaultspan">Вы собираетесь удалить сообщение из гостевой книги. <br><br>Вы действительно хотите этого ? &copy; Windows</td></tr><tr><td align="center" style="padding-top:20px"><table><tr><td><img src="/img/inv.gif" class="win_delete" onclick="new Ajax.Request (\'/ajax/delete_guest_message.php?id='+id+'\', {method: \'get\', onComplete: function () {$(\'gb_'+id+'\').remove ();}});Control.Modal.close();"></td><td align="left" style="padding-left:5px"><img src="/img/inv.gif" class="win_cancel" onclick="Control.Modal.close();"></td></tr></table></td></tr></table></div>');
};

function matug (message)
{
	if (arguments[1])
	{
		code_str = arguments[1];
	}
	else
		code_str = false;
	currentModal = new Control.Modal.open (false);
	currentModal = new Control.Modal.open ('<div style="width:300px; padding:20px 20px 10px 20px;"><table width="100%" cellpadding="0" cellspacing="0"><tr><td class="defaultspan" align="center">' + message + '</td></tr><tr><td align="center" style="padding-top:20px"><img src="/img/inv.gif" class="win_ok" onclick="Control.Modal.close();" /></td></tr></div>', {
						beforeOpen: function ()
						{
							$('modal_container').style.visibility='hidden';
						},
						afterOpen: function ()
						{
							$('modal_container').style.visibility='';
						},
						afterClose: function ()
						{
							if (code_str)
							{
								eval(code_str);
							};
						}});
};

function set_plan_enterprice (id)
{
	default_price = 0;
	if (arguments[1])
		default_price = arguments[1];
//	$('gnus_container').innerHTML+=''	
//new ModalRequest ({type: 'prompt', modal_text: 'Введите цену. 0 - вход бесплатный', prompt_default: default_price, onOK: function ()
//		{
			price = arguments[1];
			new Ajax.Updater ('gnus_price_descr', '/ajax/set_enterprice.php?id=' + id + '&price=' + parseInt (price), 
							{method: 'get', evalScripts:true, onComplete: function() {
																				 document.getElementsByClassName('gnus_price_active')[0].onclick();} });
																						  //				{
//					$('open_map').onclick();
//
//					matug ('Ну.. ваше право. Пожалуйста.');
//				}});
//		}});
};

function gt_check ()
{
	els = $('transaction_table').getElementsByClassName ('transaction_row');
	for (i = 0; i < els.length; i++)
		els[i].checked = $('gt_check_all').checked;
};

function transactions_delete (id_bablo)
{
	getstr = '';
	if (arguments[1])
		getstr = '&filter=' + arguments[1];
	els = $('transaction_table').getElementsByClassName ('transaction_row');
	poststr = '';
	for (i = 0; i < els.length; i++)
		if (els[i].checked)
			poststr += '&id[]=' + els[i].id.substr (5);
	if (poststr)
	{
		new ModalRequest ({onOK: function ()
			{
				clock ();
				new Ajax.Updater ('get_transactions', '/ajax/get_transactions.php?id_bablo=' + id_bablo + getstr, {method: 'post', postBody: poststr.substr (1), evalScripts: true, onComplete: function (){unclock ();}});
			}});
	}
	else
		matug ('Не выбрано ни одной транзакции!');
};

function mt_redraw ()
{
	if ($('items_div'))
	{
		els = $('items_div').getElementsByClassName ('moneytable');
		for (i = 0; i < els.length; i++)
		{
			if ((i / 2) != parseInt (i / 2))
			{
				if (Element.hasClassName (els[i], 'moneytable_row'))
				{
					Element.removeClassName (els[i], 'moneytable_row');
					Element.addClassName (els[i], 'moneytable_row2');
				};
			}
			else
			{
				if (Element.hasClassName (els[i], 'moneytable_row2'))
				{
					Element.removeClassName (els[i], 'moneytable_row2');
					Element.addClassName (els[i], 'moneytable_row');
				};
			};
		};
	};
};

function edit_pamyatnik (id)
{
	currentModal = new Control.Modal.open('<iframe class="edit_tombstone restrict_move_input" src="/ajax/edit_pamyatnik.php?id='+id+'" marginheight="0" marginwidth="0" hspace="0" vspace="0" frameborder="0" ></iframe>', {overlayCloseOnClick:false});
};

function del_pamyatnik (id)
{
	currentModal = new Control.Modal.open('<iframe class="edit_tombstone restrict_move_input" src="/ajax/del_pamyatnik.php?id='+id+'" width="400px" height="50px"></iframe>', {overlayCloseOnClick:false});
};

function add_pamyatnik (id)
{
	if (window.id_user) currentModal = new Control.Modal.open('<iframe marginheight="0" marginwidth="0" hspace="0" vspace="0" frameborder="0" class="add_tombstone restrict_move_input" src="/ajax/add_pamyatnik.php?id='+id+'"></iframe>', {overlayCloseOnClick:false});
};

function add_uploaded_info (id)
{
	if (window.id_user) currentModal = new Control.Modal.open('<iframe marginheight="0" marginwidth="0" hspace="0" vspace="0" frameborder="0" class="add_tombstone restrict_move_input" src="/ajax/add_uploaded_info.php?id='+id+'"></iframe>', {overlayCloseOnClick:false});
};

function edit_uploaded_info (id)
{
	currentModal = new Control.Modal.open('<iframe class="edit_tombstone restrict_move_input" src="/ajax/edit_uploaded_info.php?id='+id+'" marginheight="0" marginwidth="0" hspace="0" vspace="0" frameborder="0" ></iframe>', {overlayCloseOnClick:false});
};

function del_uploaded_info (id)
{
	currentModal = new Control.Modal.open('<iframe class="edit_tombstone restrict_move_input" src="/ajax/del_uploaded_info.php?id='+id+'" width="400px" height="50px"></iframe>', {overlayCloseOnClick:false});
};

function add_picture_place (id)
{
	if (window.id_user) currentModal = new Control.Modal.open('<iframe marginheight="0" marginwidth="0" hspace="0" vspace="0" frameborder="0" class="add_tombstone restrict_move_input" src="/ajax/add_picture_place.php?id='+id+'"></iframe>', {overlayCloseOnClick:false});
};

function edit_picture_place (id)
{
	currentModal = new Control.Modal.open('<iframe class="edit_tombstone restrict_move_input" src="/ajax/edit_picture_place.php?id='+id+'" marginheight="0" marginwidth="0" hspace="0" vspace="0" frameborder="0" ></iframe>', {overlayCloseOnClick:false});
};

function del_picture_place (id)
{
	currentModal = new Control.Modal.open('<iframe class="edit_tombstone restrict_move_input" src="/ajax/del_picture_place.php?id='+id+'" width="400px" height="50px"></iframe>', {overlayCloseOnClick:false});
};

function walk_tele(coord)
{
	$('history_iframe').title = document.title;
//	document.title = user_position_text;
	new Ajax.Updater ('workarea', '/ajax/walk.php?tele='+coord+'_start', {method:'get', evalScripts: true});
};

function walk_plan_tele (coord)
{
	$('history_iframe').title = document.title;
//	document.title = user_position_text;
	var time = new Date();
	$('history_iframe').src = '/ajax/history_iframe.php?typ=walkplantele&coord='+coord+'&user='+window.id_user+'&time='+time.getTime();
};

function walk_plan_tele_perehod (coord)
{
	new Ajax.Updater ('workarea', '/ajax/go_to_plan.php?tele='+coord, {method:'get', evalScripts: true, onComplete: function(){$('plan_view').style.left = (parseInt(document.body.offsetWidth-960)/2)+'px'; unclock(); Control.Modal.close();}});
};

function zatychko()
{
	currentModal = new Control.Modal.open('<div style="padding:20px 20px 10px 20px"><table style="width:500px"><tr><td>'+
					'<span class="defaultspan" style="font-size:18px">Поздравляем с принятием азиопского гражданства!</span>'+
					'<br><br><span class="defaultspan">     На Ваш азиопский счет начислено 100.000 азиопских рублей. На эти деньги Вы можете купить квартиру и начать ее обустраивать. Инструкции по выбору и покупке жилья Вы найдете на площади Трех вокзалов (точка входа в Азиопию) под вывеской "Рога и копыта".'+
'<br>Способы пополнения личного счета - на Бирже труда.'+
'<br>Со всем остальным разберетесь в процессе - это несложно.'+
'<br>По всем азиопским вопросам обращайтесь к Зёме Азиопской или Азиопу Азиопычу в чате или по пейджеру.'+
'<br>За более подробным хэлпом сюда: http://aziopia.ru'+
'<br>Не забудьте вклеить в документ фотографию (при помощи фоторобота).'+
'<br>Желаем успехов в освоении азиопских территорий.'+
'<br><br>До встречи на просторах Азиопии!</span><br><br></td></tr><tr><td align="center">'+
					'<img src="/img/inv.gif" class="win_ok" onclick="Control.Modal.close();"></td></tr></table></div>');
};

function save_subscribe ()
{
	post_string = '';
	els = $('subscribe').getElementsByClassName ('subscribe_class');
	for (i = 0; i < els.length; i++)
		if (els[i].checked)
			post_string += '&subscr[]=' + els[i].value;
	new Ajax.Updater ('subscribe', '/ajax/delete_subscribe.php', {method: 'post', postBody: post_string.substr(1), onComplete: function () {matug ('Подписка сохранена');}});
};

function open_item_tr (id, scroll_flag)
{
	els = $('items_div').getElementsByClassName ('item_act');
	disp = 'none';
	if ($('item_acts_' + id).style.display)
		disp = '';
	for (i = 0; i < els.length; i++)
		if (!els[i].style.display)
			els[i].style.display = 'none';
	if (!disp)
	{
		new Ajax.Updater ($('item_acts_' + id).childElements()[0], '/ajax/personal/item_act.php?id=' + id + '&scroll_flag=' + scroll_flag, {method: 'get', evalScripts: true, onComplete: function ()
			{
				els = $('item_acts_' + id).getElementsByTagName ('img');
				for (i = 0; i < els.length; i++)
				{
					tip_title = '';
					switch (els[i].className)
					{
						case 'item_name':
							tip_title = 'Редактирование названия предмета';
							break;
						case 'item_price':
							tip_title = 'Редактирование цены предмета';
							break;
						case 'item_transfer':
							tip_title = 'Просмотр протокола транзакций';
							break;
						case 'item_vote':
							tip_title = 'Участие предмета в конкурсах';
							break;
						case 'item_destroy':
							tip_title = 'Выбросить предмет';
							break;
						case 'item_location':
							tip_title = 'Где установлен?';
							break;
						case 'item_gift':
							tip_title = 'Подарить предмет';
							break;
						case 'item_sell':
							tip_title = 'Продать предмет';
							break;
					};
					if (tip_title)
						new Tip (els[i], tip_title, {delay:0});
				};
			}});
		$('item_acts_' + id).style.display = '';
	};
};

function set_item_act (act, id)
{
	if ($('item_area_' + id))
		$('item_area_' + id).style.display = '';
	switch (act)
	{
		case 'change_name':
			$('item_area_' + id).innerHTML = '<table cellpadding="0" cellspacing="0"><tr><td class="defaultspan">Изменение '+
				'названия предмета</td><td style="padding:0px 10px 0px 10px"><input class="restrict_move_input defaultinput" '+
				'id="item_name_' + id + '" value="' + $('item_name_td_' + id).innerHTML + '" style="font-size:14px; '+
				'vertical-align:text-top; padding:2px" /></td><td><img src="/img/inv.gif" class="win_ok" onclick="save_item ('+
				id + ');" /></td></tr></table>';
			break;
		case 'change_price':
			$('item_area_' + id).innerHTML = '<table cellpadding="0" cellspacing="0"><tr><td class="defaultspan">'+
				'Изменение цены предмета</td><td style="padding:0px 10px 0px 10px" class="defaultspan"><input class='+
				'"restrict_move_input defaultinput" id="item_price_' + id + '" value="' +
				parseInt ($('item_price_td_' + id).innerHTML) + '" style="font-size:14px; vertical-align:text-top; '+
				'padding:2px" /> руб.</td><td><img src="/img/inv.gif" class="win_ok" onclick="save_item (' + id +
				');" /></td></tr></table>';
			break;
		case 'delete':
			$('item_area_' + id).innerHTML = '<center>Вы действительно хотите удалить этот предмет?<br /><img class="win_ok" onclick="clock (); new Ajax.Updater (\'musorka\', \'/ajax/personal/drop_item.php?id=' + id + '\', {evalScripts: true, onComplete: function () {unclock ();}});" src="/img/inv.gif"/><img class="win_cancel" onclick="$(\'item_area_' + id + '\').style.display=\'none\'" src="/img/inv.gif"/></center>';
			break;
	};
};

function edit_plan_descr (descr)
{
	currentModal = new Control.Modal.open ('<div style="margin:10px 20px;"><span class="defaultspan"><b>Изменение описания</b></span><br><textarea id="plan_descr_area" class="defaultinput restrict_move_input" style="width: 300px; height: 200px; overflow-y: scroll;">' + descr + '</textarea><br/>'+
			'<br><center><img src="/img/inv.gif" class="win_save" onclick="new Ajax.Updater (\'musorka\', \'/ajax/edit_plan_descr.php\', '+

			'{method: \'post\', postBody: \'descr=\' + encodeURIComponent ($(\'plan_descr_area\').value), evalScripts: true, '+
			'onComplete: function () {Control.Modal.close (); gnus_about_but.onclick ();}});" />'+
			'<img src="/img/inv.gif" class="win_cancel" style="margin-left:10px" onClick="Control.Modal.close ();" /></center></div>');
};

function add_dog_settle (id)
{
	if (window.id_user)
		currentModal = new Control.Modal.open('<iframe marginheight="0" marginwidth="0" hspace="0" vspace="0" frameborder="0" class="restrict_move_input" src="/ajax/add_dog_settle.php?id='+id+'" style="width:750px;height:510px;"></iframe>', {overlayCloseOnClick:false});
};

function view_dog_settle (id)
{
	if (!$('open_dog_settle_view'))
	{
		divelement = document.createElement ('div');
		divelement.id = 'open_dog_settle_view';
		$('workarea').appendChild (divelement);
	};
	openWin ($('open_dog_settle_view'), {modal: true, external_param: 'id=' + id, modal_options: {containerClassName:''}, win_options: {title: 'Просмотр анкеты'}});
};

function edit_dog_settle (id)
{
	if (window.id_user)
		currentModal = new Control.Modal.open('<iframe marginheight="0" marginwidth="0" hspace="0" vspace="0" frameborder="0" class="restrict_move_input" src="/ajax/dog_settle_edit.php?id='+id+'" style="width:700px;height:500px;"></iframe>', {overlayCloseOnClick:false});
};

function delete_dog_settle (id)
{
	new Ajax.Request ('/ajax/delete_dog_settle.php?id=' + id, {method: 'get', onComplete: function ()
		{
			location.reload ();
		}});
};

function add_dog_sell (id)
{
	if (window.id_user)
		currentModal = new Control.Modal.open('<iframe marginheight="0" marginwidth="0" hspace="0" vspace="0" frameborder="0" class="restrict_move_input" src="/ajax/add_dog_sell.php?id='+id+'" style="width:750px;height:510px;"></iframe>', {overlayCloseOnClick:false});
};

function view_dog_sell (id)
{
	if (!$('open_dog_sell_view'))
	{
		divelement = document.createElement ('div');
		divelement.id = 'open_dog_sell_view';
		$('workarea').appendChild (divelement);
	};
	openWin ($('open_dog_sell_view'), {modal: true, external_param: 'id=' + id, modal_options: {containerClassName:''}, win_options: {title: 'Просмотр анкеты'}});
};

function edit_dog_sell (id)
{
	if (window.id_user)
		currentModal = new Control.Modal.open('<iframe marginheight="0" marginwidth="0" hspace="0" vspace="0" frameborder="0" class="restrict_move_input" src="/ajax/dog_sell_edit.php?id='+id+'" style="width:700px;height:500px;"></iframe>', {overlayCloseOnClick:false});
};

function delete_dog_sell (id)
{
	new Ajax.Request ('/ajax/delete_dog_sell.php?id=' + id, {method: 'get', onComplete: function ()
		{
			location.reload ();
		}});
};


function resize (ob)
{
	els = ob.getElementsByTagName ('img');
	tmp = els[0].src;
	els[0].src = ob.href;
	ob.href = tmp;
};

function rating_item_open()
{
	rating_param = '';
	if (arguments[0])
		rating_param += '?id=' + arguments[0];
	
	currentModal = new Control.Modal.open('<img src="/img/progress2.gif"><div id="preview_item_rates_tmp" style="display:none"></div>');

	new Ajax.Updater('preview_item_rates_tmp', '/ajax/rating_item_preview.php'+rating_param, {method:'get', evalScripts:true, onComplete: function () {currentModal = new Control.Modal.open($('preview_item_rates_tmp').innerHTML, {overlayCloseOnClick:false, beforeOpen: function () {$('modal_container').style.visibility='hidden';}, afterOpen: function () {$('modal_container').style.visibility='';} }); unclock();} })
};

function rating_global_collapse(type, id)
{
/*	if ($(type+'_'+id).style.display=='')
	{
		$(type+'_'+id).style.display='none';
		$('img_'+type+'_'+id).src="/img/folder.gif";
	};
	else
	{	
		$('img_'+type+'_'+id).src='/img/folder-open.gif';
		new Ajax.Updater(type+'_'+id, '/ajax/rating_'+type+'_action.php?id='+id, {method:'get', evalScripts:true, onComplete: function () {$(type+'_'+id).style.display='';}});
	};
*/
	if (type=='item')
	{
		if (!$('open_item_rating_list_action'+id))
		{
			 divelement = document.createElement ('div');
			 divelement.id = 'open_item_rating_list_action'+id;
			 $('workarea').appendChild (divelement);
		};
		openWin($('open_item_rating_list_action'+id), {url:'/ajax/rating_item_action.php', external_param: 'id='+id});
	};
	if (type=='plan')
	{
		if (!$('open_plan_rating_list_action'+id))
		{
			 divelement = document.createElement ('div');
			 divelement.id = 'open_plan_rating_list_action'+id;
			 $('workarea').appendChild (divelement);
		};
		openWin($('open_plan_rating_list_action'+id), {url:'/ajax/rating_plan_action.php', no_update:true, external_param: 'id='+id, exec_on_show: 	'if ($("plan_rating_list_'+id+'").offsetHeight>=500)'+
																																				'{'+
																																				'$("plan_rating_list_'+id+'").style.height="500px";'+
																																				'$("plan_rating_list_'+id+'").style.overflow="hidden";'+
																																				'$("plan_rating_list_'+id+'").style.overflowY="auto";'+
																																				'}'
																																				});
	};
	if (type=='item_ended')
	{
		if (!$('open_item_rating_list_action'+id))
		{
			 divelement = document.createElement ('div');
			 divelement.id = 'open_item_rating_list_action'+id;
			 $('workarea').appendChild (divelement);
		};
		openWin($('open_item_rating_list_action'+id), {url:'/ajax/rating_item_action.php', external_param: 'id='+id+'&ended=1'});
	};
	if (type=='plan_ended')
	{
		if (!$('open_plan_rating_list_action'+id))
		{
			 divelement = document.createElement ('div');
			 divelement.id = 'open_plan_rating_list_action'+id;
			 $('workarea').appendChild (divelement);
		};
		openWin($('open_plan_rating_list_action'+id), {url:'/ajax/rating_plan_action.php', external_param: 'id='+id+'&ended=1'});
	};
	if (type=='best')
	{
		if (!$('open_best_rating_list_action'+id))
		{
			 divelement = document.createElement ('div');
			 divelement.id = 'open_best_rating_list_action'+id;
			 $('workarea').appendChild (divelement);
		};
		openWin($('open_best_rating_list_action'+id), {url:'/ajax/rating_best_action.php', external_param: 'id='+id, win_options:{width:'400px'}});
	};
};

function rating_global_window (type)
{
	if (!$('open_global_rating_list_'+type))
	{
		divelement = document.createElement ('div');
		divelement.id = 'open_global_rating_list_'+type;
		$('workarea').appendChild (divelement);
	};
	openWin($('open_global_rating_list_'+type), {external_param: 'type=' + type, url:'/ajax/rating_global_action.php'});
};

function gnus_make_inactive ()
{
//	alert($$('img.gnus_active'));
	ob=$$('img.gnus_active')[0];
	ob.removeClassName('gnus_active');
	ob.className=ob.className.substr(0, ob.className.lastIndexOf('_active'));
	$('gnus_right_div').style.width='39px';
	$('dstrdscr').hide();
	myWins['map_obj'].updateDimensions();
};

function gnus_make_active(ob)
{
	old_ob=$$('img.gnus_active')[0];
	if (old_ob)
	{
		old_ob.removeClassName('gnus_active');
		old_ob.className=old_ob.className.substr(0, old_ob.className.lastIndexOf('_active'));
	};
	if (ob.className.indexOf(' ')>1)
		ob.className=ob.className.substr(0,ob.className.indexOf(' '));
	ob.className+='_active gnus_active';
	$('gnus_right_div').style.width='254px';
	$('dstrdscr').show();
	myWins['map_obj'].updateDimensions();
	$('gnus_container').style.height=($('gnus_right_div').offsetHeight-12)+'px';
};

function resizeContainer(deltaWidth, deltaHeight) {

        // get current width and height
        var widthCurrent  = $('modal_container').getWidth();
        var heightCurrent = $('modal_container').getHeight();

        // get new width and height
        var widthNew  = widthCurrent+deltaWidth;
        var heightNew = heightCurrent+deltaHeight;
		var topNew = parseInt($('modal_container').style.top)-parseInt(deltaHeight/2);
		var leftNew = parseInt($('modal_container').style.left)-parseInt(deltaWidth/2);

        // scalars based on change from old to new
        var xScale = (widthNew  / widthCurrent)  * 100;
        var yScale = (heightNew / heightCurrent) * 100;

        // calculate size difference between new and old image, and resize if necessary
        var wDiff = deltaWidth*-1;
        var hDiff = deltaHeight*-1;

//$('modal_content').style.display='none';
$('modal_content').style.visibility='';
		
		str='width:'+widthNew+'px;height:'+heightNew+'px;top:'+topNew+'px;left:'+leftNew+'px';

		$('modal_container').morph(str, {afterFinish: function () {$('modal_content').style.display='';}})
//		new Effect.Morph($('modal_container'), yScale, {scaleX: false, duration: 0.3, queue: 'front'}); 
//        new Effect.Morph($('modal_container'), xScale, {scaleY: false, duration: 0.3, delay: 0.3, afterFinish: function () {$('modal_content').style.display='';} }); 

        // if new and old image are same size and no scaling transition is necessary, 
        // do a quick pause to prevent image flicker.
/*        var timeout = 0;
        if ((hDiff == 0) && (wDiff == 0)){
            timeout = 100;
            if (Prototype.Browser.IE) timeout = 250;   
        };

        (function(){
            this.prevLink.setStyle({ height: imgHeight + 'px' });
            this.nextLink.setStyle({ height: imgHeight + 'px' });
            this.imageDataContainer.setStyle({ width: widthNew + 'px' });

            this.showImage();
        }).bind(this).delay(timeout / 1000);
*/   };

function move(id)
{
	if ($(id).next())
	{
		$('selected').value = $(id).next().id.substr(7);
		$(id).next().style.backgroundColor='#FFFF66';
	}
	else if ($(id).previous())
	{
		$('selected').value = $(id).previous().id.substr(7);
		$(id).previous().style.backgroundColor='#FFFF66';
	};
	if ($(id).parentNode.id == 'key_list')
	{
		$('add_button').disabled=true;
		$('button_left').disabled=true;
		$('button_del').disabled=true;
		$('button_right').disabled=true;
		if ($(id).next() || $(id).previous())
		{
			$('add_button').disabled=false;
		};
		divelement=$(id);
		$('selected_keys').appendChild(divelement);
		$(id).style.backgroundColor='';
	}
	else
	{
		$('add_button').disabled=true;
		$('button_left').disabled=true;
		$('button_del').disabled=true;
		$('button_right').disabled=true;
		if ($(id).next() || $(id).previous())
		{
			$('button_left').disabled=false;
			$('button_del').disabled=false;
			$('button_right').disabled=false;
		};
		divelement=$(id);
		$('key_list').appendChild(divelement);
		$(id).style.backgroundColor='';
	};
};

function get_info_plan_tree (str, id)
{
	if (id==0)
	{
		if (!$('open_info_plan_tree'))
		{
			divelement=document.createElement('DIV');
			divelement.id='open_info_plan_tree'
			divelement.style.display='none';
			$('workarea').appendChild(divelement);
		};
		openWin($('open_info_plan_tree'), {external_param:'id='+id+'&str='+str, no_update:true, win_options:{width:'470px'}})
	}
	else
	{
		if ($('info_container')) $('info_container').update('');
		new Ajax.Updater('tree_container', '/ajax/info_plan_tree.php?id='+id+'&str='+str, {method:'get', evalScripts:true});
	};
};
function get_info_plan_tree_right (str, id)
{
	new Ajax.Updater('info_container', '/ajax/info_plan_tree_right.php?id='+id+'&str='+str, {method:'get', evalScripts:true});
};

function get_info_plan_fast_tree_right (str, id)
{
	new Ajax.Updater('info_container', '/ajax/info_plan_tree_right.php?id='+id+'&str='+str, {method:'get', insertion: Insertion.Bottom, evalScripts:true});
};

function info_plan_tree_typ (id, typ)
{
		new Ajax.Updater('info_plan_tree_typ_temp', '/ajax/info_plan_tree_typ.php?id='+id+'&typ='+typ, {method:'get', evalScripts:true});
};

function add_guestbook_mess(id_plan, id)
{
	currentModal = new Control.Modal.open ('<div style="margin:10px 20px;"><span class="defaultspan"><b>Оставить сообщение</b></span><br><textarea id="guest_message" class="defaultinput restrict_move_input" style="width: 300px; height: 200px; overflow-y: scroll;"></textarea><br/>'+
			'<br><center><img src="/img/inv.gif" class="win_save" onclick="save_add_guestbook_mess('+id_plan+', \''+id+'\')" />'+
			'<img src="/img/inv.gif" class="win_cancel" style="margin-left:10px" onClick="Control.Modal.close ();" /></center></div>');
};

function gb_edit_message(id_mess)
{
	currentModal = new Control.Modal.open ('<div style="margin:10px 20px;"><span class="defaultspan"><b>Редактировать сообщение</b></span><br><textarea id="guest_message" class="defaultinput restrict_move_input" style="width: 300px; height: 200px; overflow-y: scroll;"></textarea><br/>'+
			'<br><center><img src="/img/inv.gif" class="win_save" onclick="save_edit_guestbook_mess('+id_mess+')" />'+
			'<img src="/img/inv.gif" class="win_cancel" style="margin-left:10px" onClick="Control.Modal.close ();" /></center></div>', {afterOpen: function (){new Ajax.Updater('guest_message', '/ajax/edit_guest_message.php?type=edit&id='+ id_mess, {evalScripts:true, method: 'get'});}});
};

function save_edit_guestbook_mess (id_mess)
{
var text_temp = $('guest_message').value;
var text = encodeURIComponent ($('guest_message').value);
new Ajax.Updater ('modal_container', '/ajax/edit_guest_message.php', {
				  evalScripts:true,
				  method: 'post',
				  postBody: 'type=save&id='+ id_mess +'&mess=' + text,
				  onComplete: function () 
				  	{
					$('message_text_'+id_mess).innerHTML=text_temp.replace(/\n/g, '<br />\n');
					Control.Modal.close();
					}
				  });
};

function save_add_guestbook_mess (id_plan, id)
{
new Ajax.Updater (id, '/ajax/post_guest_message.php', {evalScripts:true, method: 'post', postBody: 'mess=' + encodeURIComponent ($('guest_message').value)});
Control.Modal.close();
};

function return_toplan ()
{
	$('history_iframe').title = document.title;
//	document.title = user_position_text;
	var time = new Date();
	$('history_iframe').src = '/ajax/history_iframe.php?typ=returntoplan&user='+window.id_user+'&time='+time.getTime();
};

function return_toplan_perehod ()
{
new Ajax.Updater ('workarea', '/ajax/go_to_plan.php?return=1', {method:'get', evalScripts: true, onComplete: function(){$('plan_view').style.left = (parseInt(document.body.offsetWidth-960)/2)+'px'; unclock(); Control.Modal.close();}});
};

function grafity_paint (id)
{
	divelement = document.createElement ('div');
	divelement.id = 'block_div_'+id;
	divelement.style.position = 'absolute';
	divelement.style.left = 0;
	divelement.style.top = 0;
	divelement.style.width = '100%';
	divelement.style.height = '100%';
	divelement.style.zIndex = 649;
	document.body.appendChild (divelement);

	canvaselement = document.createElement ('canvas');
	canvaselement.id = 'canvas_'+id;
	canvaselement.style.position = 'absolute';
	canvaselement.style.width = $('pli'+id).width;
	canvaselement.style.height = $('pli'+id).height;
	canvaselement.width = $('pli'+id).width;
	canvaselement.height = $('pli'+id).height;
	canvaselement.style.left = $('pli'+id).style.left;
	canvaselement.style.top = $('pli'+id).style.top;
	canvaselement.style.zIndex = 650;
	if ($('plan_view'))
		$('plan_view').appendChild (canvaselement);
	else
		$('workarea').appendChild (canvaselement);

	panel = document.createElement ('div');
	panel.id = 'paint_panel_'+id;
	panel.style.position = 'absolute';
	panel.style.width = '580px';
	panel.style.height = '42px';
	panel.style.left = 100;
	panel.style.top = 100;
	panel.style.zIndex = 651;
	$('workarea').appendChild (panel);
	new Ajax.Updater ('paint_panel_'+id, '/modules/paint/ajax/paint.php?id='+id, {method:'get', evalScripts: true});
	panel.dragPip=new Draggable($('paint_panel_'+id));
};

function open_personal_config ()
{
	clock();
	currentModal = Control.Modal.open('');
	Control.Modal.open('<div id=\'settings_div\' style=\'width:500px\'></div>',
					{
						overlayCloseOnClick:true,
						overlayClassName: 'black_overlay',
						beforeOpen: function ()	{ $('modal_container').style.visibility='hidden'; },
						afterOpen: function ()
						{
							new Ajax.Updater('settings_div', '/ajax/personal/change_settings.php', {method: 'get', evalScripts: true, onComplete: function () {
								$('modal_overlay').style.filter='alpha(opacity=60, style=0)';
								Control.Modal.center($('modal_container'));
								unclock();}
								});
						},
						afterClose: function ()
						{
							$('modal_overlay').style.opacity='1.0';
							$('modal_overlay').style.filter='alpha(opacity=100, style=0)';
						}
					});
};

function grafity_log_open(id)
{
	clock();
	currentModal = Control.Modal.open('');
	Control.Modal.open('<div id=\'grafity_log_div\' style=\'width:800px; height:400px\'></div>',
					{
						overlayCloseOnClick:true,
						overlayClassName: 'black_overlay',
						beforeOpen: function ()	{ $('modal_container').style.visibility='hidden'; },
						afterOpen: function ()
						{
							new Ajax.Updater('grafity_log_div', '/modules/grafity_admin/ajax/grafity_list.php?id='+id, {method: 'get', evalScripts: true, onComplete: function () {
								$('modal_overlay').style.filter='alpha(opacity=60, style=0)';
								Control.Modal.center($('modal_container'));
								$('modal_container').style.visibility='';
								unclock();}
								});
						},
						afterClose: function ()
						{
							$('modal_overlay').style.opacity='1.0';
							$('modal_overlay').style.filter='alpha(opacity=100, style=0)';
						}
					});
};

function give_money(id)
{
	clock();
	new Ajax.Updater(document.body, '/ajax/give_money.php?elem='+id, {method: 'get', evalScripts: true, insertion: Insertion.Bottom, onComplete: function () { unclock();} });
};

function user_click_money(id)
{
	clock();
	new Ajax.Updater(document.body, '/ajax/user_click_money.php?elem='+id, {method: 'get', evalScripts: true, insertion: Insertion.Bottom, onComplete: function () { unclock();} });
};


randomPics = new Object();
tempRandomPics = new Object();

function random_pic(id, act)
{
	if (randomPics[id] && !$('plan_sh'))
	{
	}
	else
	{
		randomPics[id]=new Object();
		randomPics[id]['url']=act;
		randomPics[id]['show']=Math.round(Math.random());

	};

	if (randomPics[id]['show']==1)
	{
		imgelement = document.createElement('IMG');
		imgelement.id='rpi'+id.substr(3);
		imgelement.src=act;
		imgelement.style.position = 'absolute';
		imgelement.style.left=$(id).style.left;
		imgelement.style.top=$(id).style.top;
		imgelement.style.zIndex=$(id).style.zIndex;
		$(id).parentNode.appendChild(imgelement);
		
	};
};

function clearRandomPics()
{
	tempRandomPics = new Object();
	for (i in randomPics)
	{
		if ($(i)) tempRandomPics[i]=randomPics[i];
	};
	randomPics=Object.extend(tempRandomPics, {});
};



function night_plan()
{
	$('gnus_container').startWaiting();
	new Ajax.Updater('night_container', '/ajax/night_plan.php', {method:'get', evalScripts: true, onComplete: function () {$('gnus_container').stopWaiting();} });
};


function make_night_plan()
{
	if ($('night_plan'))
	{
		$('night_plan').remove();
	}
	else
	{
		divelement = document.createElement('DIV');
		divelement.id='night_plan';
		divelement.style.position='absolute';
		divelement.style.left='0px';
		divelement.style.top='0px';
		divelement.style.width=$('workarea').style.width;
		divelement.style.height=$('workarea').style.height;
		divelement.style.zIndex=299;
		divelement.style.background="#000000";
		divelement.style.opacity='0.75';
		divelement.style.filter='alpha(opacity=75, style=0)';
		$('workarea').appendChild(divelement);
	};
};

function light_plan(act)
{
	clock();
	new Ajax.Updater('workarea', '/ajax/light_plan.php', {method:'post', postBody:'act='+encodeURIComponent(act), evalScripts: true, insertion:Insertion.Bottom, onComplete: function () {unclock();} });
};

function make_light_plan(act)
{
		lwidth=0;
		lheight=0;
		lleft=1000;
		ltop=1000;

	lights=document.getElementsByClassName('light_plan_imgs');
	if (lights.length>0)
	{
		lwidth=lights[0].width;
		lheight=lights[0].height;
		lleft=parseInt(lights[0].style.left);
		ltop=parseInt(lights[0].style.top);
		for(i=0; i<lights.length; i++)
		{
//			alert(i);
			lights[i].remove();
		};
	}
	else
	{
		
		childs=$('plan_view').childElements();
		for (i=0; i<childs.length; i++)
		{
			if (lleft>parseInt(childs[i].style.left)) lleft=parseInt(childs[i].style.left);
			if (ltop>parseInt(childs[i].style.top)) ltop=parseInt(childs[i].style.top);
		};
		
		for (i=0; i<childs.length; i++)
		{
			dims=Element.getDimensions(childs[i]);
			if (lwidth<parseInt(childs[i].style.left)+dims.width-lleft)
				lwidth=parseInt(childs[i].style.left)+dims.width-lleft;

			if (lheight<parseInt(childs[i].style.top)+dims.height-ltop)
				lheight=parseInt(childs[i].style.top)+dims.height-ltop;
		};
		
		lleft+=parseInt($('plan_view').style.left);
		ltop+=parseInt($('plan_view').style.top);
	};

	if (act>'')
	{
		acts=act.split(',');
		for (i=0;i<acts.length;i++)
		{
			elem=new Element('IMG', {src:"/img/inv.gif", width:lwidth, height:lheight});
			elem.style.position='absolute';
			elem.style.left=lleft+'px';
			elem.style.top=ltop+'px';
			elem.style.backgroundColor='#'+acts[i].substr(0,acts[i].indexOf('_'));
			elem.style.opacity='0.'+acts[i].substr(acts[i].indexOf('_')+1);
			elem.style.filter='alpha(opacity='+acts[i].substr(acts[i].indexOf('_')+1)+', style=0)';
			elem.style.zIndex=201+i;
			elem.className='light_plan_imgs';
			$('workarea').appendChild(elem);
		};
	};
};



function pick_change_click (id, src)
{
	if ($('plan_view'))
		ob = $('ppi'+id);
	else
		ob = $('pic'+id);
	if (!change_pic_buffer[id])
		change_pic_buffer[id] = ob.src;
	if (change_pic_buffer[id]==ob.src)
		ob.src = src;
	else
		ob.src = change_pic_buffer[id];
};

function new_window_link (action)
{
	action = action.replace(/true/g, "yes");
	action = action.replace(/false/g, "no");
	var action_array = new Array();
	action_array = action.split(';');
	if (action_array[6] == 'no')
		window.open(action_array[0], '', 'toolbar = '+action_array[1]+', status = '+action_array[2]+', scrollbar = '+action_array[3]+', resizable = '+action_array[4]+', location = '+action_array[5]);
	else
		window.open(action_array[0]);
};

function item_comments (id)
{
	currentModal = new Control.Modal.open('<div id="comments_div" style="display:none"></div>');

	new Ajax.Updater('comments_div', '/ajax/rating_item_comments.php?elem='+id, {method:'get', evalScripts:true, onComplete: function () {currentModal = new Control.Modal.open($('comments_div').innerHTML, {overlayCloseOnClick:false, beforeOpen: function () {$('modal_container').style.visibility='hidden';}, afterOpen: function () {$('modal_container').style.visibility='';} }); unclock();} })
};

function plan_comments (id)
{
	currentModal = new Control.Modal.open('<div id="comments_div" style="display:none"></div>');

	new Ajax.Updater('comments_div', '/ajax/rating_plan_comments.php?elem='+id, {method:'get', evalScripts:true, onComplete: function () {currentModal = new Control.Modal.open($('comments_div').innerHTML, {overlayCloseOnClick:false, beforeOpen: function () {$('modal_container').style.visibility='hidden';}, afterOpen: function () {$('modal_container').style.visibility='';} }); unclock();} })
};

function post_rating_comment (id, type)
{
	var text = $('post_comment').value;
	poststring = 'text='+text+'&elem='+id ;
	new Ajax.Updater('modal_container', '/ajax/rating_'+type+'_comments.php', {method:'post', postBody: poststring, evalScripts: true, onComplete: function () {$('modal_container').style.visibility='hidden'; $('modal_container').style.visibility='';}});
};

function delete_rating_comment (id, type)
{
	$('gb_'+id).remove();
	new Ajax.Updater('modal_container', '/ajax/rating_'+type+'_comments_delete.php?id='+id, {method:'get', evalScripts: true, insertion:Insertion.Bottom});
};

function img_loaded_counter (total)
{
	img_loaded++;
	load_procent = (img_loaded/total*100)+100;
	$('load_progress_bar').style.width = load_procent+'px';
	if (img_loaded == total)
		$("total_preloader").style.display='none';
};

function full_user_info (id_user, sid)
{
	if (!id_user)
		openWin ($('workarea'), {external_param: 'sid=' + sid+ '&id_user=' + id_user, url: '/ajax/full_user_info.php', win_options: {title:'Информация о пользователе'}});
	else
		openWin ($('workarea'), {external_param: 'id_user=' + id_user, url: '/ajax/full_user_info.php', win_options: {title:'Информация о пользователе'}});
};

function IsNumeric(input){
    var RE = /^-{0,1}\d*\.{0,1}\d+$/;
    return (RE.test(input));
};



var AnnounObjectClass = Class.create();

AnnounObjectClass.prototype = {

	initialize: function (name)
	{
		this.name=name;
	},
	elem: new Array(),
	setActs: function (ob)
	{
		this.elem.push(ob);
		i=this.elem.length-1;
//		alert(this.elem[i].x);
		long = 0;
		temp = this.elem[i].act.indexOf('<br')>0?this.elem[i].act.indexOf('<br'):this.elem[i].act.length;
//		$temp = (strpos($this->_tpl_vars['elem']['act'], "<br")?strpos($this->_tpl_vars['elem']['act'], "<br"):strlen($this->_tpl_vars['elem']['act']));
		if (temp > 49) {temp = 49; long = 1;};
		this.elem[i].tip= this.elem[i].act.substr(0,temp)+(long>0?'...':'');
//		alert(this.elem[i].tip);
	},
	fireActs: function()
	{
		for (i=0; i<this.elem.length; i++)
		{
			imgcopy=document.createElement('IMG');
			imgcopy.id="upli"+this.elem[i].id;
			imgcopy.src="/img/inv.gif";
			imgcopy.width=this.elem[i].width;
			imgcopy.height=this.elem[i].height;
			imgcopy.style.position="absolute";
			imgcopy.style.left=this.elem[i].x+'px';
			imgcopy.style.top=this.elem[i].y+'px';
			imgcopy.style.zIndex=this.elem[i].layer + 300;
			imgcopy.style.cursor = 'pointer';
			imgcopy.className = 'action_inv';
			$('upic'+this.elem[i].id).parentNode.appendChild(imgcopy);
	
			/*announcement_tip{$elem.id_user_street_elements} = */
			new Tip('upli'+this.elem[i].id, this.elem[i].tip, {delay:0.1});
			
			Event.observe ('upli'+this.elem[i].id, 'click', click_announcement, true);
			divelement=document.createElement('DIV');
			divelement.id="announcement_"+this.elem[i].id;
			divelement.innerHTML='Автор: <img style="cursor: pointer;" src="/img/users/info.gif"/><br>'+this.elem[i].act;
			divelement.style.display='none';
			divelement.style.margin='10px';
			divelement.style.minWidth='250px';
			$('upic'+this.elem[i].id).parentNode.appendChild(divelement);
		};
	},
	clearActs: function ()
	{
/*		for (i=0; i<this.elem.length; i++)
		{
			Event.stopObserving('upli'+this.elem[i].id);
		};
		*/
		this.elem = new Array();
	}
	
	
};

AnnounObject = new AnnounObjectClass('AnnounObject');



function myitems_get ()
{
	
	new ModalRequest({modal_text:'<div style="padding:5px;" align="center">Вы уверены, что хотите забрать<br>все свои вещи из этого помещения?</div>', 
					 	onOK: function () {clock(); new Ajax.Updater('workarea', '/ajax/myitems_get.php', {method:'get', evalScripts:true, insertion:Insertion.Bottom });} });
};


function item_show_noshow (id)
{
	clock();
	$('item_acts_' + id).style.display='none';
	if ($('chulan_win')) Wins.hide('chulan_win');
	new Ajax.Updater ('musorka', '/ajax/personal/item_sns.php?id='+id, {method:'get', evalScripts:true});
};


function open_my_items ()
{
	url='/ajax/personal/my_items.php';
	openWin (this, {modal:true, url:url, external_param:(arguments[0]>''?'scroll_id='+arguments[0]:''), win_options:{parentWin: 'personal_win', title:'Мои предметы', width:300}})
};



function add_guestbook_action_mess(id_act, id)
{
	currentModal = new Control.Modal.open ('<div style="margin:10px 20px;"><span class="defaultspan"><b>Оставить сообщение</b></span><br><textarea id="guest_message_act_'+id_act+'" class="defaultinput restrict_move_input" style="width: 300px; height: 200px; overflow-y: scroll;"></textarea><br/>'+
			'<br><center><img src="/img/inv.gif" class="win_save" onclick="save_add_guestbook_action_mess('+id_act+', \''+id+'\')" />'+
			'<img src="/img/inv.gif" class="win_cancel" style="margin-left:10px" onClick="Control.Modal.close ();" /></center></div>');
};

function gba_edit_message(id_mess)
{
	currentModal = new Control.Modal.open ('<div style="margin:10px 20px;"><span class="defaultspan"><b>Редактировать сообщение</b></span><br><textarea id="guest_message_'+id_mess+'" class="defaultinput restrict_move_input" style="width: 300px; height: 200px; overflow-y: scroll;"></textarea><br/>'+
			'<br><center><img src="/img/inv.gif" class="win_save" onclick="save_edit_guestbook_action_mess('+id_mess+')" />'+
			'<img src="/img/inv.gif" class="win_cancel" style="margin-left:10px" onClick="Control.Modal.close ();" /></center></div>', {afterOpen: function (){new Ajax.Updater('guest_message_'+id_mess, '/ajax/guest_book_action_edit.php?type=edit&id='+ id_mess, {evalScripts:true, method: 'get'});}});
};

function save_edit_guestbook_action_mess (id_mess)
{
var text_temp = $('guest_message_'+id_mess).value;
var text = encodeURIComponent ($('guest_message_'+id_mess).value);
new Ajax.Updater ('modal_container', '/ajax/guest_book_action_edit.php', {
				  evalScripts:true,
				  method: 'post',
				  postBody: 'type=save&id='+ id_mess +'&mess=' + text,
				  onComplete: function () 
				  	{
					$('message_text_'+id_mess).innerHTML=text_temp.replace(/\n/g, '<br />\n');
					Control.Modal.close();
					}
				  });
};

function save_add_guestbook_action_mess (id_act, id)
{
new Ajax.Updater (id, '/ajax/guest_book_action_add.php?id='+id_act, {evalScripts:true, method: 'post', postBody: 'mess=' + encodeURIComponent ($('guest_message_act_'+id_act).value)});
Control.Modal.close();
};

function gba_delete_message(id)
{
	currentModal = new Control.Modal.open('<div style="width:300px; padding:20px 20px 10px 20px;"><table cellpadding="0" cellspacing="0"><tr><td class="defaultspan">Вы собираетесь удалить сообщение из гостевой книги. <br><br>Вы действительно хотите этого ? &copy; Windows</td></tr><tr><td align="center" style="padding-top:20px"><table><tr><td><img src="/img/inv.gif" class="win_delete" onclick="new Ajax.Request (\'/ajax/guest_book_action_delete.php?id='+id+'\', {method: \'get\', onComplete: function () {$(\'gba_'+id+'\').remove ();}});Control.Modal.close();"></td><td align="left" style="padding-left:5px"><img src="/img/inv.gif" class="win_cancel" onclick="Control.Modal.close();"></td></tr></table></td></tr></table></div>');
};

