
function OnNavigateComplete(Object)

local value
  --dsgsd.sdgdg
  value=m_simpleTV.Config.GetConfigString(m_simpleTV.Defines.ID_TORRENTSTREAM_PATH)
  if value==nil then value = '%APPDATA%\\AceStream\\engine' end
  m_simpleTV.Dialog.SetElementValueString(Object,'Path',value) 
  
  value=m_simpleTV.Config.GetConfigString(m_simpleTV.Defines.ID_TORRENTSTREAM_ADDRESS)
  if value==nil then  value ='127.0.0.1' end
  m_simpleTV.Dialog.SetElementValueString(Object,'Address',value)
  
  value=m_simpleTV.Config.GetConfigInt(m_simpleTV.Defines.ID_TORRENTSTREAM_PORT)
  if value==nil then  value = -1 end
  m_simpleTV.Dialog.SetElementValueString(Object,'Port','' .. value)
  
  value=m_simpleTV.Config.GetConfigInt(m_simpleTV.Defines.ID_TORRENTSTREAM_AUTOSTART)
  if value==nil then  value = 1 end
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'AutoStart',value) 
  
  value=m_simpleTV.Config.GetConfigInt(m_simpleTV.Defines.ID_TORRENTSTREAM_CLOSE_ON_EXIT)
  if value==nil then  value = 0 end
  m_simpleTV.Dialog.SelectComboIndex(Object,'AutoEnd',value) 
  
  
  value=m_simpleTV.Config.GetConfigInt(m_simpleTV.Defines.ID_TORRENTSTREAM_ALLOW_CHANGE_NAME)
  if value==nil then  value = 0 end
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'AllowChangeName',value) 
  
  value=m_simpleTV.Config.GetConfigInt(m_simpleTV.Defines.ID_TORRENTSTREAM_ALLOW_SHOW_NAME)
  if value==nil then  value = 1 end
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'AllowShowName',value) 
    
  value=m_simpleTV.Config.GetConfigInt(m_simpleTV.Defines.ID_TORRENTSTREAM_ALLOW_AD)
  if value==nil then  value = 1 end
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'CheckboxAD',value) 	
	    
 m_simpleTV.Dialog.AddEventHandler(Object,'OnClick','ButtonDef','OnClickButtonDef')
 m_simpleTV.Dialog.AddEventHandler(Object,'OnClick','ButtonFolderPicker','OnFolderPicker')

end
------------------------------------------------------------------
function OnOk(Object)

local value

  value = m_simpleTV.Dialog.GetElementValueString(Object,'Path') 
  if value~=nil then 
		m_simpleTV.Config.SetConfigString(m_simpleTV.Defines.ID_TORRENTSTREAM_PATH,value)
  end		
  
  value=m_simpleTV.Dialog.GetElementValueString(Object,'Address')
  if value~=nil then 
     m_simpleTV.Config.SetConfigString(m_simpleTV.Defines.ID_TORRENTSTREAM_ADDRESS,value)
  end
  
  value=m_simpleTV.Dialog.GetElementValueString(Object,'Port')
  value=tonumber(value)
  if value~=nil then 
    m_simpleTV.Config.SetConfigInt(m_simpleTV.Defines.ID_TORRENTSTREAM_PORT,value)
  end
    
  value=m_simpleTV.Dialog.GetCheckBoxValue(Object,'AutoStart') 
  if value~=nil then 	
      m_simpleTV.Config.SetConfigInt(m_simpleTV.Defines.ID_TORRENTSTREAM_AUTOSTART,value)
  end
  
  value=m_simpleTV.Dialog.GetComboValue(Object,'AutoEnd',true) 
  if value~=nil then 	
      value = tonumber(value)
	  if value~=nil then 	
			m_simpleTV.Config.SetConfigInt(m_simpleTV.Defines.ID_TORRENTSTREAM_CLOSE_ON_EXIT,value)
	  end
  end
    
  value=m_simpleTV.Dialog.GetCheckBoxValue(Object,'AllowChangeName') 
  if value~=nil then  
	m_simpleTV.Config.SetConfigInt(m_simpleTV.Defines.ID_TORRENTSTREAM_ALLOW_CHANGE_NAME,value)
  end  
  
  value=m_simpleTV.Dialog.GetCheckBoxValue(Object,'AllowShowName') 
  if value~=nil then  
	m_simpleTV.Config.SetConfigInt(m_simpleTV.Defines.ID_TORRENTSTREAM_ALLOW_SHOW_NAME,value)
  end  

  
  value=m_simpleTV.Dialog.GetCheckBoxValue(Object,'CheckboxAD') 
  if value~=nil then  
	m_simpleTV.Config.SetConfigInt(m_simpleTV.Defines.ID_TORRENTSTREAM_ALLOW_AD,value)
  end  
  
end
------------------------------------------------------------------
function OnClickButtonDef(Object)
  
  m_simpleTV.Dialog.SetElementText(Object,'Path','%APPDATA%\\AceStream\\engine') 
  m_simpleTV.Dialog.SetElementText(Object,'Address','127.0.0.1')
  m_simpleTV.Dialog.SetElementText(Object,'Port','-1')
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'AutoStart',1) 
  m_simpleTV.Dialog.SelectComboIndex(Object,'AutoEnd',0) 
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'AllowChangeName',0)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'AllowShowName',1) 
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'CheckboxAD',1) 	  
   
end
------------------------------------------------------------------
function OnFolderPicker(Object)

 local folder =  m_simpleTV.Common.FolderPicker('Выберите папку')
 
 if folder~=nil then 
    m_simpleTV.Dialog.SetElementValueString(Object,'Path',folder) 
 end	
 
end