function OnNavigateComplete(ObjectSaveFilter) 
m_simpleTV.Dialog.SetWindowIcon(ObjectSaveFilter,m_simpleTV.MainScriptDir .. 'user\\Tools\\css\\favicon.ico',false)
  m_simpleTV.Config.AddEventHandler(ObjectSaveFilter,'OnClick','ButtonFolderPicker','OnFolderPicker')
  m_simpleTV.Config.AddEventHandler(ObjectSaveFilter,'OnClick','SaveButton','OnClickSaveButton')
  m_simpleTV.Config.AddEventHandler(ObjectSaveFilter,'OnClick','CloseButton','OnClickCloseButton')
  m_simpleTV.Config.AddEventHandler(ObjectSaveFilter,'OnClick','ButtonClearFilename','OnClickButtonClearFilename')

local disk = os.getenv('HOMEDRIVE')
local path = os.getenv('HOMEPATH')
m_simpleTV.Config.SetElementValueString(ObjectSaveFilter,'Path',disk..path..'\\Desktop\\')
local filename = 'new_filter.txt'
m_simpleTV.Config.SetElementValueString(ObjectSaveFilter,'Filename',filename)
end
-----------------------------------------------------------------
function OnFolderPicker(ObjectSaveFilter)
 local path =  m_simpleTV.Common.FolderPicker('Select directory')
 if path~=nil then 
    path = path .. '\\'
    m_simpleTV.Config.SetElementValueString(ObjectSaveFilter,'Path',path) 
 end	
 
end
-----------------------------------------------------------------
function OnClickSaveButton(ObjectSaveFilter)

 local Object =  m_simpleTV.Dialog.FindWindowById( 'tools_window_1' )
-- local channels = m_simpleTV.Dialog.GetElementHtml_UTF8(Object,'ChannelsTable')
 local path = m_simpleTV.Config.GetElementValueString(ObjectSaveFilter,'Path')
 local filename = m_simpleTV.Config.GetElementValueString(ObjectSaveFilter,'Filename')
 if filename == '' then return end
 path = path .. filename

local channels = m_simpleTV.User.ToolsAddon.NewFilter

 channels = m_simpleTV.Common.string_fromUTF8(channels)
 channels = string.gsub(channels,'&nbsp;','' )

 local out = ''
 for w in string.gmatch(channels,'<tr class="row">(.-)</tr>') do

  local CurrentName = string.match(w,'col="oldname">(.-)<')
  local NewName = string.match(w,'col="newname">(.-)<')
  local GroupName = string.match(w,'col="groupname">(.-)<')
  local Source = string.match(w,'col="sourcename">(.-)<')

    if CurrentName ~= nil and NewName ~= nil and GroupName ~= nil and Source ~= nil then

       if trim(NewName) ~= '' and trim(GroupName) ~= '!No Group' and trim(GroupName) ~= '' then
          out = out .. '"' .. String2Upper(CurrentName)  .. ',' .. trim(NewName) .. ',' .. trim(GroupName) .. ',' .. Source ..'"\n'
       end
    end

end
   out = m_simpleTV.Common.string_toUTF8(out)

local str = 
'--custom filter list utf-8  on ' .. m_simpleTV.User.ToolsAddon.Date .. '\n' .. 
'--current channel name allways in uppercase, new name, group name, epg source name\n\n'

  str = m_simpleTV.Common.string_toUTF8(str)

 local fhandle = io.open (path , "w+")
 if fhandle==nil then return end
 fhandle:write(str .. out)
 fhandle:close()

  if FileExists(path) then
     m_simpleTV.Dialog.SetElementText_UTF8(ObjectSaveFilter, 'Mess', 'File saved successfully')
     m_simpleTV.Common.Wait(2000) 
     m_simpleTV.Dialog.Close(ObjectSaveFilter)
   else
     m_simpleTV.Dialog.SetElementText_UTF8(ObjectSaveFilter, 'Mess', 'Error - File cannot be saved')
     m_simpleTV.Common.Wait(2000) 
     m_simpleTV.Dialog.SetElementText_UTF8(ObjectSaveFilter, 'Mess', '')
  end

 m_simpleTV.User.ToolsAddon.NewFilter = nil
end
-----------------------------------------------------------------
function OnClickButtonClearFilename(ObjectSaveFilter)
  m_simpleTV.Config.SetElementText(ObjectSaveFilter, 'Filename', '')
end

function OnClickCloseButton(ObjectSaveFilter)
  m_simpleTV.Dialog.Close(ObjectSaveFilter)
end