function OnNavigateComplete(Object)

  m_simpleTV.Dialog.AddEventHandler(Object,'OnClick','LocalCheckButton','OnClickLocalCheckButton')
 m_simpleTV.Dialog.AddEventHandler(Object,'OnClick','LocalUncheckButton','OnClickLocalUncheckButton')
  m_simpleTV.Dialog.AddEventHandler(Object,'OnClick','LocalLoadButton','OnClickLocalLoadButton')

  m_simpleTV.Dialog.AddEventHandler(Object,'OnClick','MiscCheckButton','OnClickMiscCheckButton')
m_simpleTV.Dialog.AddEventHandler(Object,'OnClick','MiscUncheckButton','OnClickMiscUncheckButton')
  m_simpleTV.Dialog.AddEventHandler(Object,'OnClick','MisclLoadButton','OnClickMiscLoadButton')
 
  local conf = m_simpleTV.MainScriptDir .. "user/SmartTv/tvmenu.ini"
  local fhandle = io.open (conf , "r")
  if fhandle == nil then return end
  local str = fhandle:read('*all')
  fhandle:close()

  local value
  if str == nil or str == '' then value=0 end

  m_simpleTV.Dialog.SetElementValueString(Object,'LocalAltechnoe','Altechnoe')
  m_simpleTV.Dialog.SetElementValueString(Object,'LocalCastellano','Castellano')
  m_simpleTV.Dialog.SetElementValueString(Object,'LocalChulio46','Chulio46')
  m_simpleTV.Dialog.SetElementValueString(Object,'LocalEldan','Eldan')
  m_simpleTV.Dialog.SetElementValueString(Object,'LocalEspanol3','Espanol3')
  m_simpleTV.Dialog.SetElementValueString(Object,'LocalGonzalox','Gonzalox')


  m_simpleTV.Dialog.SetElementValueString(Object,'MiscIPTV-Latino','IPTV-Latino')
  m_simpleTV.Dialog.SetElementValueString(Object,'MiscLista13','Lista13')
  m_simpleTV.Dialog.SetElementValueString(Object,'MiscMegaIPTV','MegaIPTV')
  m_simpleTV.Dialog.SetElementValueString(Object,'MiscMikel','Mikel')
  m_simpleTV.Dialog.SetElementValueString(Object,'MiscPastebin','Pastebin')
  m_simpleTV.Dialog.SetElementValueString(Object,'MiscPlaylist','Playlist')

end
------------------------------------------------------------------
function OnClickLocalCheckButton(Object)

  local value=1
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'LocalAltechnoe',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'LocalCastellano',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'LocalChulio46',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'LocalEldan',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'LocalEspanol3',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'LocalGonzalox',value)

end

function OnClickTrashUncheckButton(Object)

  local value=0
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'LocalAltechnoe',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'LocalCastellano',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'LocalChulio46',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'LocalEldan',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'LocalEspanol3',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'LocalGonzalox',value)

end

function OnClickMiscCheckButton(Object)

  local value=1
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'MiscIPTV-Latino',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'MiscLista13',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'MiscMegaIPTV',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'MiscMikel',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'MiscPastebin',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'MiscPlaylist',value)

end

function OnClickMiscUncheckButton(Object)

  local value=0
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'MiscIPTV-Latino',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'MiscLista13',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'MiscMegaIPTV',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'MiscMikel',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'MiscPastebin',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'MiscPlaylist',value)

end
---------------------------------------------------------------
function OnClickLocalLoadButton(Object)

  local alt = ''
  local cst = ''
  local chl = ''
  local ldn = ''
  local enl = ''
  local nzl = ''


  local altvalue = m_simpleTV.Dialog.GetCheckBoxValue(Object,'LocalAltechnoe')
  if altvalue~=nil and altvalue~=0 then
    alt = m_simpleTV.Dialog.GetElementValueString(Object,'LocalAltechnoe') 
    alt =  alt .. ', '
    dofile(m_simpleTV.MainScriptDir .. 'user/ListasTv/Altechnoe/Altechnoe.lua')
  end

  local cstvalue = m_simpleTV.Dialog.GetCheckBoxValue(Object,'LocalCastellano')
  if cstvalue~=nil and cstvalue~=0 then
    cst = m_simpleTV.Dialog.GetElementValueString(Object,'LocalCastellano') 
    cst =  cst .. ', '
    dofile(m_simpleTV.MainScriptDir .. 'user/ListasTv/Castellano/Castellano.lua')
  end

  local chlvalue = m_simpleTV.Dialog.GetCheckBoxValue(Object,'LocalChulio46')
  if chlvalue~=nil and chlvalue~=0 then
    chl = m_simpleTV.Dialog.GetElementValueString(Object,'LocalChulio46') 
    chl =  chl .. ', '
   dofile(m_simpleTV.MainScriptDir .. 'user/ListasTv/Chulip46/Chulio46.lua')
   m_simpleTV.Common.Wait(5000)
  dofile(m_simpleTV.MainScriptDir .. 'user/ListasTv/Chulio46/Chulio460.lua')
  end

  local ldnvalue = m_simpleTV.Dialog.GetCheckBoxValue(Object,'LocalEldan')
  if ldnvalue~=nil and ldnvalue~=0 then
    ldn = m_simpleTV.Dialog.GetElementValueString(Object,'LocalEldan') 
    ldn =  ldn .. ', '
    dofile(m_simpleTV.MainScriptDir .. 'user/ListasTv/Eldan/Eldan.lua')
  end

  local enlvalue = m_simpleTV.Dialog.GetCheckBoxValue(Object,'LocalEspanol3')
  if enlvalue~=nil and enlvalue~=0 then
    enl = m_simpleTV.Dialog.GetElementValueString(Object,'LocalEspanol3') 
    enl =  enl .. ', '
    dofile(m_simpleTV.MainScriptDir .. 'user/ListasTv/Espanol3/Espanol3.lua')
  end

  local nzlvalue = m_simpleTV.Dialog.GetCheckBoxValue(Object,'LocalGonzalox')
  if nzlvalue~=nil and nzlvalue~=0 then
    nzl = m_simpleTV.Dialog.GetElementValueString(Object,'LocalGonzalox') 
    nzl =  nzl .. ', '
   dofile(m_simpleTV.MainScriptDir .. 'user/ListasTv/Gonzalox/Gonzalox.lua')
  end 

    if altvalue ~= 0 or cstvalue ~= 0 or chlvalue ~= 0 or ldnvalue ~= 0 or enlvalue ~= 0 or nzlvalue ~= 0 then
      m_simpleTV.Interface.MessageBox('Menu: ' .. alt .. cst .. chl .. ldn .. enl .. nzl .. '\nLista Completada.','Leyendo ListaTv',0,Object)
    end
end

function OnClickMiscLoadButton(Object)

  local ipt = ''
  local lst = ''
  local mgi = ''
  local kel = ''
  local pst = ''
  local llt = ''


  local iptvalue = m_simpleTV.Dialog.GetCheckBoxValue(Object,'IPTV-Latino')
  if iptvalue~=nil and iptvalue~=0 then
    ipt = m_simpleTV.Dialog.GetElementValueString(Object,'IPTV-Latino') 
    ipt =  ipt .. ', '
    dofile(m_simpleTV.MainScriptDir .. 'user/ListasTv/IPTV-Latino/IPTV-Latino.lua')
  end 

  local lstvalue = m_simpleTV.Dialog.GetCheckBoxValue(Object,'Lista13')
  if lstvalue~=nil and lstvalue~=0 then
    lst = m_simpleTV.Dialog.GetElementValueString(Object,'Lista13') 
    lst =  lst .. ', '
    dofile(m_simpleTV.MainScriptDir .. 'user/ListasTv/Lista13/Lista13.lua')
  end 

  local mgivalue = m_simpleTV.Dialog.GetCheckBoxValue(Object,'MegaIPTV')
  if mgivalue~=nil and mgivalue~=0 then
    mgi = m_simpleTV.Dialog.GetElementValueString(Object,'MegaIPTV') 
    mgi =  mgi .. ', '
    dofile(m_simpleTV.MainScriptDir .. 'user/ListasTv/MegaIPTV/MegaIPTV1.lua')
   m_simpleTV.Common.Wait(5000)
   dofile(m_simpleTV.MainScriptDir .. 'user/ListasTv/MegaIPTV/MegaIPTV2.lua')	
  end 

  local kelvalue = m_simpleTV.Dialog.GetCheckBoxValue(Object,'Mikel')
  if kelvalue~=nil and kelvalue~=0 then
    kel = m_simpleTV.Dialog.GetElementValueString(Object,'Mikel') 
    kel =  kel .. ', '
    dofile(m_simpleTV.MainScriptDir .. 'user/ListasTv/Mikel/Mikel.lua')
  end 

  local pstvalue = m_simpleTV.Dialog.GetCheckBoxValue(Object,'Pastebin')
  if pstvalue~=nil and pstvalue~=0 then
    pst = m_simpleTV.Dialog.GetElementValueString(Object,'Pastebin') 
    pst =  pst .. ', '
    dofile(m_simpleTV.MainScriptDir .. 'user/ListasTv/Pastebin/Pastebin1.lua')
   m_simpleTV.Common.Wait(5000)
   dofile(m_simpleTV.MainScriptDir .. 'user/ListasTv/Pastebin/Pastebin2.lua')
   m_simpleTV.Common.Wait(5000)
   dofile(m_simpleTV.MainScriptDir .. 'user/ListasTv/Pastebin/Pastebin3.lua')
   m_simpleTV.Common.Wait(5000)	 
   dofile(m_simpleTV.MainScriptDir .. 'user/ListasTv/Pastebin/Pastebin4.lua')
   m_simpleTV.Common.Wait(5000)	 
   dofile(m_simpleTV.MainScriptDir .. 'user/ListasTv/Pastebin/Pastebin5.lua')
  end 

  local lltvalue = m_simpleTV.Dialog.GetCheckBoxValue(Object,'Playlist')
  if lltvalue~=nil and lltvalue~=0 then
    llt = m_simpleTV.Dialog.GetElementValueString(Object,'Playlist') 
    llt =  llt .. ', '
    dofile(m_simpleTV.MainScriptDir .. 'user/ListasTv/Playlist/Playlist.lua')
  end 

    if iptvalue ~= 0 or lstvalue ~= 0 or mgivalue ~= 0 or kelvalue ~= 0 or pstvalue ~= 0 or lltvalue~=0 then
      m_simpleTV.Interface.MessageBox('Preset playlists: ' .. ipt .. lst .. mgi .. kel .. pst .. llt .. '\nLista Completada.','Leyendo ListaTv',0,Object)
    end
end

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

 local conf = m_simpleTV.MainScriptDir .. "user/ListasTv/tvmenu.ini"
 local fhandle = io.open (conf , "w+")
 if fhandle == nil then return end
 fhandle:write('')
 fhandle:close()

  local value
   value = m_simpleTV.Dialog.GetCheckBoxValue(Object,'Altechnoe') 
  if value~=nil and value~=0 then 
        value = '<"Altechnoe","user/ListasTv/Altechnoe/Altechnoe.lua">'
  	fhandle = io.open (conf , "a+")
        fhandle:write(value)
        fhandle:close()
   end		

   value = m_simpleTV.Dialog.GetCheckBoxValue(Object,'Castellano') 
  if value~=nil and value~=0 then 
        value = '<"Castellano","user/ListasTv/Castellano/Castellano.lua">'
  	fhandle = io.open (conf , "a+")
        fhandle:write(value)
        fhandle:close()
   end	

   value = m_simpleTV.Dialog.GetCheckBoxValue(Object,'Chulio46') 
  if value~=nil and value~=0 then 
        value = '<"Chulio46","user/ListasTv/Chulio46/Chulio46.lua">'
  	fhandle = io.open (conf , "a+")
        fhandle:write(value)
        fhandle:close()
   end

   value = m_simpleTV.Dialog.GetCheckBoxValue(Object,'Chulio460') 
  if value~=nil and value~=0 then 
        value = '<"Chulio460","user/ListasTv/Chulio46/Chulio460.lua">'
  	fhandle = io.open (conf , "a+")
        fhandle:write(value)
        fhandle:close()
   end

   value = m_simpleTV.Dialog.GetCheckBoxValue(Object,'Eldan') 
  if value~=nil and value~=0 then 
        value = '<"Eldan","user/ListasTv/Eldan/Eldan.lua">'
  	fhandle = io.open (conf , "a+")
        fhandle:write(value)
        fhandle:close()
   end

   value = m_simpleTV.Dialog.GetCheckBoxValue(Object,'Espanol3') 
  if value~=nil and value~=0 then 
        value = '<"Espanol3","user/ListasTv/Esapnol3/Espanol3.lua">'
  	fhandle = io.open (conf , "a+")
        fhandle:write(value)
        fhandle:close()
   end	

   value = m_simpleTV.Dialog.GetCheckBoxValue(Object,'Gonzalox') 
  if value~=nil and value~=0 then 
        value = '<"Gonzalox","user/ListasTv/Gonxalox/Gonzalox.lua">'
  	fhandle = io.open (conf , "a+")
        fhandle:write(value)
        fhandle:close()
   end	

   value = m_simpleTV.Dialog.GetCheckBoxValue(Object,'IPTV-Latino') 
  if value~=nil and value~=0 then 
        value = '<"IPTV-XBMC","user/ListasTv/IPTV-Latino/IPTV-Latino.lua">'
  	fhandle = io.open (conf , "a+")
        fhandle:write(value)
        fhandle:close()
   end	

   value = m_simpleTV.Dialog.GetCheckBoxValue(Object,'Lista13') 
  if value~=nil and value~=0 then 
        value = '<"Lista13","user/ListasTv/Lista13/Lista13.lua">'
  	fhandle = io.open (conf , "a+")
        fhandle:write(value)
        fhandle:close()
   end	

   value = m_simpleTV.Dialog.GetCheckBoxValue(Object,'MegaIPTV1') 
  if value~=nil and value~=0 then 
        value = '<"MegaIPTV1","user/ListasTv/MegaIPTV/MegaIPTV1.lua">'
  	fhandle = io.open (conf , "a+")
        fhandle:write(value)
        fhandle:close()
   end	

   value = m_simpleTV.Dialog.GetCheckBoxValue(Object,'MegaIPTV2') 
  if value~=nil and value~=0 then 
        value = '<"MegaIPTV2","user/ListasTv/MegaIPTV/MegaIPTV2.lua">'
  	fhandle = io.open (conf , "a+")
        fhandle:write(value)
        fhandle:close()
   end	

   value = m_simpleTV.Dialog.GetCheckBoxValue(Object,'Mikel') 
  if value~=nil and value~=0 then 
        value = '<"Mikel","user/ListasTv/Mikel/Mikel.lua">'
  	fhandle = io.open (conf , "a+")
        fhandle:write(value)
        fhandle:close()
   end	

   value = m_simpleTV.Dialog.GetCheckBoxValue(Object,'Pastebin1') 
  if value~=nil and value~=0 then 
        value = '<"Pastebin1","user/ListasTv/Pastebin/Pastebin1.lua">'
  	fhandle = io.open (conf , "a+")
        fhandle:write(value)
        fhandle:close()
   end	

   value = m_simpleTV.Dialog.GetCheckBoxValue(Object,'Pastebin2') 
  if value~=nil and value~=0 then 
        value = '<"Pastebin2","user/ListasTv/Pastebin/Pastebin2.lua">'
  	fhandle = io.open (conf , "a+")
        fhandle:write(value)
        fhandle:close()
   end	

   value = m_simpleTV.Dialog.GetCheckBoxValue(Object,'Pastebin3') 
  if value~=nil and value~=0 then 
        value = '<"Pastebin3","user/ListasTv/Pastebin/Pastebin3.lua">'
  	fhandle = io.open (conf , "a+")
        fhandle:write(value)
        fhandle:close()
   end	

   value = m_simpleTV.Dialog.GetCheckBoxValue(Object,'Pastebin4') 
  if value~=nil and value~=0 then 
        value = '<"Pastebin4","user/ListasTv/Pastebin/Pastebin4.lua">'
  	fhandle = io.open (conf , "a+")
        fhandle:write(value)
        fhandle:close()
   end

   value = m_simpleTV.Dialog.GetCheckBoxValue(Object,'Pastebin5') 
  if value~=nil and value~=0 then 
        value = '<"Pastebin5","user/ListasTv/Pastebin/Pastebin5.lua">'
  	fhandle = io.open (conf , "a+")
        fhandle:write(value)
        fhandle:close()
   end

   value = m_simpleTV.Dialog.GetCheckBoxValue(Object,'Playlist') 
  if value~=nil and value~=0 then 
        value = '<"Playlist","user/ListasTv/Playlist/Playlist.lua">'
  	fhandle = io.open (conf , "a+")
        fhandle:write(value)
        fhandle:close()
   end				

 local fhandle = io.open (conf , "r")
 if fhandle == nil then return end
 value = fhandle:read('*all')
 fhandle:close()

 if value == '' then 
        value = '<"Not available","">'
  	fhandle = io.open (conf , "a+")
        fhandle:write(value)
        fhandle:close()
 end
   
end
------------------------------------------------------------------
