function OnNavigateComplete(Object)

  m_simpleTV.Dialog.AddEventHandler(Object,'OnClick','TrashCheckButton','OnClickTrashCheckButton')
m_simpleTV.Dialog.AddEventHandler(Object,'OnClick','TrashUncheckButton','OnClickTrashUncheckButton')
  m_simpleTV.Dialog.AddEventHandler(Object,'OnClick','TrashlLoadButton','OnClickTrashLoadButton')
 
  local conf = m_simpleTV.MainScriptDir .. "user/Kodi/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,'TrashAlemania','Alemania')
  m_simpleTV.Dialog.SetElementValueString(Object,'TrashCastellano','Castellano')
  m_simpleTV.Dialog.SetElementValueString(Object,'TrashDeportes','Deportes')
  m_simpleTV.Dialog.SetElementValueString(Object,'TrashFilmon','Filmon')
  m_simpleTV.Dialog.SetElementValueString(Object,'TrashFrancia','Francia')
  m_simpleTV.Dialog.SetElementValueString(Object,'TrashHdCanales','HdCanales')
  m_simpleTV.Dialog.SetElementValueString(Object,'TrashItalia','Italia')
  m_simpleTV.Dialog.SetElementValueString(Object,'TrashMusica','Musica')
  m_simpleTV.Dialog.SetElementValueString(Object,'TrashPortugal','Portugal')
  m_simpleTV.Dialog.SetElementValueString(Object,'TrashRusia','Rusia')
  m_simpleTV.Dialog.SetElementValueString(Object,'TrashUkrania','Ukrania')

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

  local value=1
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'TrashAlemania',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'TrashCastellano',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'TrashDeportes',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'TrashFilmon',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'TrashFrancia',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'TrashHdCanales',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'TrashItalia',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'TrashMusica',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'TrashPortugal',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'TrashRusia',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'TrashMUkrania',value)

end

function OnClickTrashUncheckButton(Object)

  local value=0
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'TrashAlemania',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'TrashCastellano',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'TrashDeportes',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'TrashFilmon',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'TrashFrancia',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'TrashHdCanales',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'TrashItalia',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'TrashMusica',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'TrashPortugal',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'TrashRusia',value)
  m_simpleTV.Dialog.SetCheckBoxValue(Object,'TrashMUkrania',value)



end
---------------------------------------------------------------
function OnClickTrashLoadButton(Object)

  local alm = ''
  local cst = ''
  local dpt = ''
  local flm = ''
  local frc = ''
  local hdc = ''
  local itl = ''
  local mia = ''
  local prt = ''
  local rsa = ''
  local krn = ''


  local almvalue = m_simpleTV.Dialog.GetCheckBoxValue(Object,'TrashAlemania')
  if almvalue~=nil and almvalue~=0 then
    alm = m_simpleTV.Dialog.GetElementValueString(Object,'TrashAmericaLatina') 
    alm =  alm .. ', '
    dofile(m_simpleTV.MainScriptDir .. 'user/Hasbahcatv/Alemania/Alemania.lua')
  end

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

  local dptvalue = m_simpleTV.Dialog.GetCheckBoxValue(Object,'TrashDeportes')
  if dptvalue~=nil and dptvalue~=0 then
    dpt = m_simpleTV.Dialog.GetElementValueString(Object,'TrashDesportes') 
    dpt =  dpt .. ', '
    dofile(m_simpleTV.MainScriptDir .. 'user/Hasbahcatv/Deportes/Deportes.lua')  
  end 

  local flmvalue = m_simpleTV.Dialog.GetCheckBoxValue(Object,'TrashFilmon')
  if flmvalue~=nil and flmvalue~=0 then
    flm = m_simpleTV.Dialog.GetElementValueString(Object,'TrashFilmon') 
    flm =  flm .. ', '
    dofile(m_simpleTV.MainScriptDir .. 'user/Hasbahcatv/Filmon/Filmon.lua')  
  end 

  local frcvalue = m_simpleTV.Dialog.GetCheckBoxValue(Object,'TrashFrancia')
  if frcvalue~=nil and frcvalue~=0 then
    frc = m_simpleTV.Dialog.GetElementValueString(Object,'TrashFrancia') 
    frc =  frc .. ', '
    dofile(m_simpleTV.MainScriptDir .. 'user/Hasbahcatv/Francia/Francia.lua')
  end

  local hdcvalue = m_simpleTV.Dialog.GetCheckBoxValue(Object,'TrashHdCanales')
  if hdcvalue~=nil and hdcvalue~=0 then
    hdc = m_simpleTV.Dialog.GetElementValueString(Object,'TrashHdCanales') 
    hdc =  hdc .. ', '
    dofile(m_simpleTV.MainScriptDir .. 'user/Hasbahcatv/HdCanales/HdCanales.lua')  
  end 

  local itlvalue = m_simpleTV.Dialog.GetCheckBoxValue(Object,'TrashItalia')
  if itlvalue~=nil and itlvalue~=0 then
    itl = m_simpleTV.Dialog.GetElementValueString(Object,'TrashItalia') 
    itl =  itl .. ', '
    dofile(m_simpleTV.MainScriptDir .. 'user/Hasbahcatv/Italia/Italia.lua')
  end

  local miavalue = m_simpleTV.Dialog.GetCheckBoxValue(Object,'LocalMusica')
  if miavalue~=nil and miavalue~=0 then
    mia = m_simpleTV.Dialog.GetElementValueString(Object,'LocalMusica') 
    mia =  mia .. ', '
    dofile(m_simpleTV.MainScriptDir .. 'user/Hasbahcatv/Musica/Musica.lua')
  end

  local prtvalue = m_simpleTV.Dialog.GetCheckBoxValue(Object,'TrashPortugal')
  if prtvalue~=nil and prtvalue~=0 then
    prt = m_simpleTV.Dialog.GetElementValueString(Object,'TrashPortugal') 
    prt =  prt .. ', '
    dofile(m_simpleTV.MainScriptDir .. 'user/Hasbahcatv/Portugal/Portugal.lua')
  end

  local rsavalue = m_simpleTV.Dialog.GetCheckBoxValue(Object,'TrashRusia')
  if rsavalue~=nil and rsavalue~=0 then
    rsa = m_simpleTV.Dialog.GetElementValueString(Object,'TrashRusia') 
    rsa =  rsa .. ', '
    dofile(m_simpleTV.MainScriptDir .. 'user/Hasbahcatv/Rusia/Rusia.lua')  
  end

  local krnvalue = m_simpleTV.Dialog.GetCheckBoxValue(Object,'TrashUkrania')
  if krnvalue~=nil and krnvalue~=0 then
    krn = m_simpleTV.Dialog.GetElementValueString(Object,'TrashUkrania') 
    krn =  krn .. ', '
    dofile(m_simpleTV.MainScriptDir .. 'user/Hasbahcatv/Ukrania/Ukrania.lua')  
  end

    if almvalue ~= 0 or cstvalue ~= 0 or dptvalue ~= 0 or flmvalue ~= 0 or frcvalue ~=0 or hdcvalue ~=0 or itlvalue ~=0 or miavalue ~=0 or prtvalue ~=0 or rsavalue ~=0 or krnvalue ~=0 then
      m_simpleTV.Interface.MessageBox('Menu: ' .. alm .. cst .. dpt .. flm .. frc .. hdc .. itl .. mia .. prt .. rsa .. krn .. '\nLista Cpmpletada.','Leyendo Kodi',0,Object)
    end
end

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

 local conf = m_simpleTV.MainScriptDir .. "user/Hasbahcatv/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,'Alemania') 
  if value~=nil and value~=0 then 
        value = '<"Alemania","user/Hasbahcatv/Alemania/Alemania.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 = '<"Csatellano","user/Hasbahcatv/Castellano/Castellano.lua">'
  	fhandle = io.open (conf , "a+")
        fhandle:write(value)
        fhandle:close()
   end	

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

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

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

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

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

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

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

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

  value = m_simpleTV.Dialog.GetCheckBoxValue(Object,'Ukrania') 
  if value~=nil and value~=0 then 
        value = '<"Ukrania","user/Hasbahcatv/Ukrania/Ukrania.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
------------------------------------------------------------------
