function Timer(ncount, Param1)
	if not StopSheet then
		AlfingSheet();
		StopSheet=false;
	return;end;
return;end;

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

function PhoneSound()
	playeffect("phone");
end;

function SelectRandom()
	if flags.loc1 then
		selectrandomobject(1.5,51);
	return;end;
    idObject=GetRandomObject();    
	if idObject>=110 and idObject<=113 then
	    selectrandomobject(1.5,58);
	return;end;
	if idObject==100 and not flags.minicomplete1 then
		if GetActivCount()>1 then
			flags.HintCount=flags.HintCount+1;
			SelectRandom()		
		return;end;
		if not flags.box then
			selectrandomobject(1.5,49);
		return;end;
		selectrandomobject(1.5,45);
	return;end;
	selectrandomobject(1.5,idObject);
end;

function SelectRandomRadar(idObject)  
	if idObject>=110 and idObject<=113 then
	    selectrandomobject(1.5,58);
	return;end;
	if idObject==100 and not flags.minicomplete1 then
		if not flags.box then
			selectrandomobject(1.5,49);
		return;end;
		selectrandomobject(1.5,45);
	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 and flags.loc3 and flags.loc4 and flags.loc5 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
			   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
				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.loc1 then
			if not flags.allobject1 then
		    flags.allobject1=true;
			if flags.loc1 and flags.loc2 and flags.loc3 and flags.loc4 and flags.loc5 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
		    BlockCursor(false);
		    ShowMenu(true);
		   	AddParticleToObject(4,"can",0,0);
			StartEmiter("can");
			AddParticleToObject(49,"Letter1",0,0);
			StartEmiter("Letter1");
			MoveEmiter("Letter1",390,230);			   
			AddParticleToObject(58,"Table",0,0);
			StartEmiter("Table");
			MoveEmiter("Table",587,403);	
			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 attachedID==-1 then	
	
			if obj_id==501 then
				if flags.levelcomplete then
					delete_tree_leaf("Root","kab_direktor");
					delete_tree_leaf("Root","azart_room");
					delete_tree_leaf("Root","private_room");
					delete_tree_leaf("Root","grimerka");
					delete_tree_leaf("Root","kulisi");
					delete_tree_leaf("Root","mini1");
					delete_tree_leaf("Root","mini2");
					delete_tree_leaf("Root","mini3");
					delete_tree_leaf("Root","mini");
					delete_tree_leaf("Root","mini4");
					delete_tree_leaf("Root","mini5");
					delete_tree_leaf("Root","mini6");		
					delete_tree_leaf("Root","mini7");
					setnextlavel(4);
					loadlavel();
				return;end;	
				DarkScreen(false);
				speciale_action(2,503,true);
				speciale_action(4,503);
			return;end;
			
			if obj_id==51 then
				if flags.firstloc2==true then
					BlockCursor(true)
					setcurentleaf("azart_room",3,1);
					
					AddParticleToObject(43,"room",0,0);
					StartEmiter("room");
					SwitchToSheet("re");
					flags.firstloc2 = false;
					DarkScreen(true);
					speciale_action(2,503,true,3);	
					speciale_action(4,503)
				return; end;	
				setcurentleaf("azart_room",3,1);
				savegame(SaveLevel())
				SwitchToSheet("re");
			return; end;		
			
			if obj_id==58 then
			if not flags.minicomplete then
				playeffect("mini");	
			    DarkScreen(true);
				add_free_leaf("Root","mini",3,11);
				dofile("./data/3/11/res.lua");
				set_satelite_leaf("kab_direktor");
				dofile("data\\3\\11\\level.lua");
				mini_create();	
			return; end;	
			return; end;
			
			if obj_id==49 then
			if not flags.box then			
				Set_Cursor(49,3)
				speciale_action(2,45,true);
				Set_Cursor(45,2)
				playeffect("door");	
				StopEmiter("Letter1")
				AddParticleToObject(45,"Letter",350,300);
				StartEmiter("Letter");
				MoveEmiter("Letter",350,300);						
				flags.box=true;
			return;end;				
			return;end;

			if obj_id==45 then
			if not flags.minicomplete1 then
			        DarkScreen(true);
					playeffect("mini");	
					add_free_leaf("Root","mini1",3,12);
					dofile("./data/3/12/res.lua");
					set_satelite_leaf("kab_direktor");
					dofile("data\\3\\12\\level.lua");
					mini_create();		
					for i=1000,1019,1 do
						speciale_action(2,i,true)
					end;					
			return; end;	
			return; end;			

			if obj_id==102 then 
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");	
				AddElement("gr",obj_id);
				SetAlfaSheet(2.5)
				setcolor(obj_id,0,0,0,0.5,1);
				MoveObjectToTree(obj_id); 
			return; end;

			if obj_id==14 then 
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");	
				setcolor(obj_id,0,0,0,0.5,1);
				CreateWindow(100,100,"202");   
			return; end;

			if obj_id==55 then 
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");	
				setcolor(obj_id,0,0,0,0.5,1);				
			return; end;

			if obj_id==110 then 
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");	
				AddElement("gr",obj_id);
				SetAlfaSheet(2.5)
				setcolor(obj_id,0,0,0,0.5,1);
				MoveObjectToTree(obj_id); 		
			return; end;		

			if obj_id==100 then 
				collaps_obj(obj_id,0,0,10,1);
				playeffect("collaps");	
				AddElement("gr",obj_id);
				SetAlfaSheet(2.5)
				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
	StopSheet=true;
		if obj_id>0 then
			addObjectToMouse(obj_id);
		return; end;
	return; end;
	
	if sender==4 then
		if SLevel==1.0 then return;end;
		flags.loc1 = true;		
	return; end;	
	
	
end
