function SheetSwitched (ncount)
	StopSheet=true;
return;end;


function SelectRandom()
-- flags.HintCount=flags.HintCount-1;
	if flags.loc2 then
		selectrandomobject(1.5,341);
	return;end;
    idObject=GetRandomObject();	
	if idObject==23 then
			if GetActivCount()>1 then
				flags.HintCount=flags.HintCount+1;
				SelectRandom()		
			return;end;				
	
		if not flags.minicomplete2 then

				selectrandomobject(1.5,160);

		return;end;
		if flags.isopen then
		    if flags.handle then		
			selectrandomobject(1.5,63);
			return;end;
			if not flags.box then
				selectrandomobject(1.5,35);
			return;end;
			selectrandomobject(1.5,115);			
		return;end	
		selectrandomobject(1.5,39);		
	return;end	
	if idObject==115 and not flags.box then		
	
		if not flags.minicomplete2 then
			selectrandomobject(1.5,160);
		return;end;	
			selectrandomobject(1.5,35);
	return;end		
	if idObject==325 then
		selectrandomobject(1.5,160);
	return;end		
	selectrandomobject(1.5,idObject);
end;

function SelectRandomRadar(idObject)

	if idObject==23 then
			
	
		if not flags.minicomplete2 then
				selectrandomobject(1.5,160);
		return;end;
		if flags.isopen then
		    if flags.handle then		
			selectrandomobject(1.5,63);
			return;end;
			if not flags.box then
				selectrandomobject(1.5,35);
			return;end;
			selectrandomobject(1.5,115);			
		return;end	
		selectrandomobject(1.5,39);		
	return;end	
	if idObject==115 and not flags.box then		
		if not flags.minicomplete2 then
			selectrandomobject(1.5,160);
		return;end;	
			selectrandomobject(1.5,35);
	return;end		
	if idObject==325 then
		selectrandomobject(1.5,160);
	return;end		
	selectrandomobject(1.5,idObject);
end;

function MessageFromMenu(nCount,Param1)
if Param1==2000029 then
	ScrollLeft();
return;end;
if Param1==2000030 then
	ScrollRight();
return;end;
showoptons(0);
return;end;

function gameinput (sender,obj_id,attachedID)
	if sender == 2 then
		MessageProc(sender,obj_id);
	return;end;
	if sender==12 or sender==26 then
		--if obj_id==325 then
	--		speciale_action(2,325)
	--	end;
		if flags.loc2 then
		if not flags.whole_darkness then
		if not flags.allobject2 then
		    flags.allobject2=true;
			if flags.loc1 and flags.loc2 then
				flags.levelcomplete=true;
				DarkScreen(true);
				ShowMenu(false);
			return; end;		
			CreateWindow(100,100,"199");
		return;end;	
		return;end;
		return;end;	
	return;end;
	
	if sender==16 then
		if obj_id==503 or obj_id==500 then
		   BlockCursor(false);
		return;end;
		if obj_id==501 then
		--	flags.whole_darkness=true;
		   if flags.levelcomplete then		        
				speciale_action(2,500,true,2);
				speciale_action(4,500);
				BlockCursor(true);
			return;end;
			BlockCursor(false);
		return;end;
		if obj_id==2 then
			BlockCursor(false);
		return;end;									
	return;end;
	
	if sender==15 then
		if obj_id==501 then
			BlockCursor(false);
			flags.whole_darkness=false;
			if flags.loc2 then
			if not flags.allobject2 then
				flags.allobject2=true;
				if flags.loc1 and flags.loc2 then
					flags.levelcomplete=true;
					DarkScreen(true);
					ShowMenu(false);
				return; end;		
				CreateWindow(100,100,"199");
			return;end;	
			return;end;			
		return;end;		
		if obj_id==503 then
			ShowMenu(true);
			BlockCursor(false);
			AddParticleToObject(160,"Bath",0,0);
			StartEmiter("Bath");
			MoveEmiter("Bath",241,396);	
			AddParticleToObject(60,"Bath1",0,0);
			StartEmiter("Bath1");
			MoveEmiter("Bath1",211,378);				
			AddParticleToObject(39,"Bak",0,0);
			StartEmiter("Bak");
			MoveEmiter("Bak",48,331);
			AddParticleToObject(35,"Box",0,0);
			StartEmiter("Box");
			MoveEmiter("Box",903,109);	
			savegame(SaveLevel())
		return;end;
	return;end;	
	if pause_state then
		if sender==1 or sender==6 or sender==14 then
			pause_state=false;
			set_visible_object(11111,false);
		end;	
	return;end;		
	if sender == 1 then --кликнули левой кнопкой мыши на активный объект

			if obj_id==35 then --закрытый гардероб
			if not flags.box then
				if attachedID==325 then    
					RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);
					playeffect("door");
					Set_Cursor(35,3);
				---	speciale_action(2,30);
					speciale_action(2,35,true);
					speciale_action(2,28,true);
					setcolor(115,0,0,0,1,1);
					flags.box=true;
					StopEmiter("Box")
				return; end;
				if attachedID~=325 and attachedID>-1 then
					CreateWindow(100,100,"200");     
				return; end;
				if attachedID ==-1 then		
					CreateWindow(100,100,"202");   
				return; end;
			return;end;
			return;end;
			
			if obj_id==39 then -- бачок унитаза
				if attachedID==302 then    
					RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);
					playeffect("openbak");
					Set_Cursor(39,3);
					speciale_action(2,39,true);
					--speciale_action(2,32);
					Set_Cursor(63,4);
					--AddParticleToObject(63,"./particles/particle2.psi");
					flags.isopen =true;
					StopEmiter("Bak")
					AddParticleToObject(1,"OpenBak",0,0);
					StartEmiter("OpenBak");
					MoveEmiter("OpenBak",40,354)
				return; end;
				if attachedID~=302 and attachedID>-1 then
					CreateWindow(100,100,"200");     
				return; end;
				if attachedID ==-1 then		
					CreateWindow(100,100,"203");   
				return; end;
			return;end;	

			if obj_id==63  then
			if not flags.bottle then
				if flags.isopen then
				if attachedID==115 then    
					RemoveFromMouse(attachedID);
					DeleteElement("gr",attachedID);
					flags.openbak=true;
					
					speciale_action(2,363,true)
					speciale_action(2,365,true)					
					playeffect("sliv");
				return; end;
				if attachedID~=115 and attachedID>-1 then
					CreateWindow(100,100,"200");     
				return; end;
				if attachedID ==-1 then		
					flags.bak=true;
					speciale_action(2,364,true)
					speciale_action(2,365,true)
				return; end;	
				return; end;		
			return; end;
			return;end;	
	if attachedID==-1 then	
		if obj_id==363 then
			speciale_action(2,363,true);
			speciale_action(2,365,true);			
			Set_Cursor(31,3);
			speciale_action(2,41,true);
			collaps_obj(23,0,0,10,1);
			CreateWindow(100,100,"207");   
			setcolor(23,0,0,0,0.5,1);
			flags.bottle=true;
			StopEmiter("OpenBak")
			Set_Cursor(63,3);	
			flags.openbak=false;			
		return;end
	
		if obj_id==365 then
			if flags.bak then
				speciale_action(2,364,true);
				speciale_action(2,365,true);
				flags.bak=false;
			return;end;
			if flags.openbak then
				speciale_action(2,363,true);
				speciale_action(2,365,true);	
				Set_Cursor(31,3);
				speciale_action(2,41,true);
				collaps_obj(23,0,0,0,0);
				CreateWindow(100,100,"207");   
				setcolor(23,0,0,0,0.5,1);
				flags.bottle=true;
				StopEmiter("OpenBak")
				Set_Cursor(63,3);					
				flags.openbak=false;				
			return;end;
		return;end;
		if obj_id==364 then
			CreateWindow(100,100,"204");
		return;end;
		if obj_id==501 then
			if flags.levelcomplete then
				delete_tree_leaf("Root","arend_room");
				delete_tree_leaf("Root","wash_room");
				delete_tree_leaf("Root","box");
				delete_tree_leaf("Root","mini1");
				delete_tree_leaf("Root","mini2");
				delete_tree_leaf("Root","mini");
				setnextlavel(20);
				loadlavel();
			return;end;	
			DarkScreen(false);
			speciale_action(2,503,true);
		return;end;		

			if obj_id==341 then
				setcurentleaf("arend_room",19,0);
				savegame(SaveLevel())
				SwitchToSheet("re");
			return; end;			
			
			if obj_id==115 then
				flags.handle=true;
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");
				AddElement("gr",obj_id);
				setcolor(obj_id,0,0,0,0.5,1);
				MoveObjectToTree(obj_id); 
			return; end;
			
			if obj_id==160 then -- ванная с мутнйо водой
			if not flags.minicomplete2 then
				DarkScreen(true);
				playeffect("mini");	
				add_free_leaf("Root","mini2",19,13);
				dofile("./data/19/13/res.lua");
				set_satelite_leaf("wash_room");
				dofile("data\\19\\13\\level.lua");
				mini_create();
				for i=1000,1068,1 do
					if i~=1065 then
						speciale_action(2,i,true)
					end;
				end;
			return; end;	
			return; end;			
		
			if obj_id==302 then 
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");
				AddElement("gr",obj_id);
				setcolor(obj_id,0,0,0,0.5,1);
				MoveObjectToTree(obj_id); 
			return; end;				




			if obj_id > 0 and obj_id < 57 then --кликаем на активный объект
				playeffect("collaps");
		        collaps_obj(obj_id,0,0,10,1);
	        return 0; end
	return; end;					
	return; end;

	if sender==14 then
		if obj_id>0 then
			addObjectToMouse(obj_id);
		return; end;
	return; end;
	
	if sender==4 then
	if SLevel==1.0 then return;end;
	flags.loc2=true;
	-- CreateWindow(100,100,"199");
	-- if flags.loc1 and flags.loc2 then
		-- flags.levelcomplete=true;
		-- speciale_action(2,501,true,2);
	-- return; end;			
	return; end;	
end
