function OnNavigateComplete(Object2) 
m_simpleTV.Dialog.SetWindowIcon(Object2,m_simpleTV.MainScriptDir .. 'user\\Tools\\css\\favicon.ico',false)
  m_simpleTV.Config.AddEventHandler(Object2,'OnClick','LoadButton','OnClickLoadButton')
  m_simpleTV.Config.AddEventHandler(Object2,'OnClick','CloseButton','OnClickCloseButton')
end
-----------------------------------------------------------------
function OnClickLoadButton(Object2)
local Object =  m_simpleTV.Dialog.FindWindowById( 'tools_window_1' )
local value = m_simpleTV.Config.GetElementValueString_UTF8(Object,'outText')
local ExtFilter = m_simpleTV.Config.GetElementValueString_UTF8(Object2,'ExtFilter')
local grp = m_simpleTV.Config.GetElementValueString_UTF8(Object2,'grp')
local borpas = m_simpleTV.Config.GetCheckBoxValue(Object2,'BorPas')

 if not string.match(value,'#EXTM3U') and not string.match(value,'#EXTINF') then 
  m_simpleTV.Config.SetElementText(Object2, 'Mess', 'Loading Error - Incorrect playlist')
  m_simpleTV.OSD.ShowMessage("Loading Error - Incorrect playlist" ,255,10)
  m_simpleTV.Common.Wait(2000)
  m_simpleTV.Dialog.Close(Object2)
      return 
 end
if ExtFilter ~= '' then
   value = string.gsub(value,'#EXTM3U','#EXTM3U $ExtFilter="'..ExtFilter..'"')
end
   if borpas == 0 then
	value = string.gsub(value,'#EXTINF:.-,','#EXTINF:-1,'..grp..':')
--debug_in_file(value..'\n')
   elseif borpas == 1 then
	borpas = 1
   end

local  tmpName = m_simpleTV.Common.GetTmpName()
if tmpName == nil then return end 

 local tfile = io.open(tmpName,'w+')
 if tfile == nil then 
     os.remove(tmpName)
     return
 end
 tfile:write(value)
 tfile:close()

local p={}
p.TypeSourse = 1
p.DeleteBeforeLoad = 0
p.TypeSkip   = 1
p.TypeFind =   0
p.AutoSearch = 1
p.NumberM3U =  0
p.Find_Group = 1
p.TypeCoding = 1  --  -1-auto  0 - plane text  1- UTF8  2- unicode
p.BorpasFileFormat= borpas
p.ExtFilter = ''
p.AutoNumber = 0

local err,add,ref,names = m_simpleTV.Common.LoadPlayList (tmpName,p,0,true,false)
os.remove(tmpName)

if err==true then
     local mess = "Channels added (" .. add .. ")"
	m_simpleTV.Interface.MessageBox('Playlist loaded successfully\n' ..mess,'Load playlist',0,Object2)
	 if add > 0 and add < 25 then 
	    names = string.gsub(names,'%$end','\n')
		mess = mess .. '\n' .. names
	 end
	 
	 m_simpleTV.OSD.ShowMessage(mess,0xFF00,5)
	 
end

  m_simpleTV.Dialog.Close(Object2)
 end

-----------------------------------------------------------------
function OnClickCloseButton(Object2)
  m_simpleTV.Dialog.Close(Object2)
end