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

function SelectRandom()
-- flags.HintCount=flags.HintCount-1;
	if flags.loc1 then
		selectrandomobject(1.5,65);
	return;end;
	if flags.all then
		if not flags.minicomplete1 then
			if not flags.wardrobe then
			selectrandomobject(1.5,46);
			return;end;
			selectrandomobject(1.5,44);
		return;end;	
	return;end;	
    idObject=GetRandomObject();	
	if idObject==28 then
		selectrandomobject(1.5,16);
	return;end	
	selectrandomobject(1.5,idObject);
end;

function SelectRandomRadar(idObject)

	if idObject==28 then
		selectrandomobject(1.5,16);
	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 flags.loc1 then
		if not flags.whole_darkness then
		if not flags.allobject1 then
		    flags.allobject1=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==35 then
		if obj_id==101 then
		   StartAnimation(101,0,8)
		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
		   if flags.levelcomplete then		        
				speciale_action(2,500,true,2);
				speciale_action(4,500);
				BlockCursor(true);
			--	flags.whole_darkness=true;
			return;end;
			BlockCursor(false);
		return;end;
		if obj_id==4 then
			CreateWindow(100,100,"198");
			BlockCursor(false);
		return;end;									
	return;end;
	
	if sender==15 then
		if obj_id==501 then
			BlockCursor(false);
			flags.whole_darkness=false;
			
			if flags.minitext1 then
				flags.minitext1=false;
				CreateWindow(100,100,"206")
				savegame(SaveLevel())
			end;
			if flags.minitext2 then
				flags.minitext2=false;
				savegame(SaveLevel())				
			if flags.loc1 then
				if not flags.allobject1 then
				flags.allobject1=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 obj_id==503 then
			ShowMenu(true);
			BlockCursor(false);
			AddParticleToObject(43,"Plank1",0,0);
			StartEmiter("Plank1");
			MoveEmiter("Plank1",925,126);	
			AddParticleToObject(42,"Plank2",0,0);
			StartEmiter("Plank2");
			MoveEmiter("Plank2",923,334);
			AddParticleToObject(41,"Plank3",0,0);
			StartEmiter("Plank3");
			MoveEmiter("Plank3",924,492);			
			AddParticleToObject(16,"Env",0,0);
			StartEmiter("Env");
			MoveEmiter("Env",639,423)	
			AddParticleToObject(46,"Wkaf1",0,0);
			StartEmiter("Wkaf1");
			MoveEmiter("Wkaf1",870,130)	
			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==41 then
				if attachedID==233 then    
					Set_Cursor(41,3);
					speciale_action(2,41,true);
					playeffect("attach");
					flags.board1=true;
					StopEmiter("Plank1");
					if flags.board2 and flags.board3 then
						RemoveFromMouse(attachedID);
						DeleteElement("gr",attachedID);
						Set_Cursor(46,2);

						--AddParticleToObject(46,"./particles/particle2.psi");
					return; end;	
				return; end;
				if attachedID~=233 and attachedID>-1 then
					CreateWindow(100,100,"200");     
				return; end;
				if attachedID ==-1 then		
					CreateWindow(100,100,"201");
				return; end;
			return;end;

			if obj_id==42 then
				if attachedID==233 then    
					Set_Cursor(42,3);
					speciale_action(2,42,true);
					playeffect("attach");
					flags.board2=true;
					StopEmiter("Plank2");
					if flags.board1 and flags.board3 then
						RemoveFromMouse(attachedID);
						DeleteElement("gr",attachedID);
						Set_Cursor(46,2);
					
						--AddParticleToObject(46,"./particles/particle2.psi");						
					return; end;	
				return; end;
				if attachedID~=233 and attachedID>-1 then
					CreateWindow(100,100,"200");     
				return; end;
				if attachedID ==-1 then		
					CreateWindow(100,100,"201");
				return; end;
			return;end;

			if obj_id==43 then
				if attachedID==233 then    
					Set_Cursor(43,3);
					speciale_action(2,43,true);
					playeffect("attach");
					flags.board3=true;
					StopEmiter("Plank3");
					if flags.board2 and flags.board1 then
						RemoveFromMouse(attachedID);
						DeleteElement("gr",attachedID);
						Set_Cursor(46,2);
				
						--AddParticleToObject(46,"./particles/particle2.psi");						
					return; end;	
				return; end;
				if attachedID~=233 and attachedID>-1 then
					CreateWindow(100,100,"200");     
				return; end;
				if attachedID ==-1 then		
					CreateWindow(100,100,"201");
				return; end;
			return;end;
	
	
		if attachedID==-1 then	
		
		if obj_id==102 then
			StartAnimation(102,0,16)
		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==65 then
				if flags.firstloc2==true then
				    flags.firstloc2=false
					BlockCursor(true)
					setcurentleaf("wash_room",19,1);
					
					SwitchToSheet("re");
					flags.firstloc2 = false;
					DarkScreen(true);
					speciale_action(2,503,true);
					speciale_action(4,503)
				return; end;
				setcurentleaf("wash_room",19,1);
				savegame(SaveLevel())
				SwitchToSheet("re");
			return; end;
			
			if obj_id==16 then -- стопка писем
			if not flags.minicomplete then
				DarkScreen(true);
				playeffect("mini");	
				add_free_leaf("Root","mini",19,11);
				dofile("./data/19/11/res.lua");
				set_satelite_leaf("arend_room");
				dofile("data\\19\\11\\level.lua");
				mini_create();
				for i=1000,1016,1 do
					speciale_action(2,i,true)
				end;
				speciale_action(2,1035,true)
			return; end;	
			return; end;			

			if obj_id==46 then --закрытый гардероб
			if not flags.wardrobe then	
			if flags.board1 and flags.board2 and flags.board3 then
				speciale_action(2,44);
				flags.wardrobe=true;
				Set_Cursor(46,3);
				Set_Cursor(44,2);
				playeffect("door");	
				StopEmiter("Wkaf1");

						AddParticleToObject(44,"Wkaf",879,503);
						StartEmiter("Wkaf");
						MoveEmiter("Wkaf",879,503)				
				--AddParticleToObject(44,"./particles/particle2.psi");
			return;end;	
				CreateWindow(100,100,"201");
			return;end;	
			return;end;

			if obj_id==44 then --закрытый гардероб
			if not flags.minicomplete1 then	
			if flags.board1 and flags.board2 and flags.board3 then
			        DarkScreen(true);
					playeffect("mini");	
					add_free_leaf("Root","mini1",19,12);
					dofile("./data/19/12/res.lua");
					set_satelite_leaf("arend_room");
					dofile("data\\19\\12\\level.lua");
					mini_create();
					speciale_action(2,1000,true);
					for i=1019,1028,1 do
						speciale_action(2,i,true);
					end;
			return;end;	
				CreateWindow(100,100,"201");
			return;end;	
			return;end;			
			
			
			if obj_id==233 then 
				playeffect("collaps");
				collaps_obj(obj_id,0,0,10,1);
				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 < 300 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.all=true;
		if flags.minicomplete1 then
		flags.loc1=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;		
	return; end;	
end
