local spellLeft = nil
local spellMiddle = nil
local spellRight = nil
local spellButton4 = nil
local spellButton5 = nil
local hlth, maxhlth, linenum = 1,2,1
local templeft=nil
local id=nil
local lspell=nil
local lspellrank=nil
local r=nil
local g=nil
local b=nil
local a=nil
local br=nil
local bg=nil
local bb=nil
local text=nil
local Heals=nil
local ri=nil
local DebuffType=nil
local uName=nil
local uBuff=nil
local spellLeftRecInstant=nil
local spellMiddleRecInstant=nil
local spellRightRecInstant=nil
local spellButton4RecInstant=nil
local spellButton5RecInstant=nil
local hlthdelta, tmpnum=0,0
local spellLeftTxt=nil
local spellLeftHeal=nil
local spellMiddleTxt=nil
local spellMiddleHeal=nil
local spellRightTxt=nil
local spellRightHeal=nil
local spellButton4Txt=nil
local spellButton4Heal=nil
local spellButton5Txt=nil
local spellButton5Heal=nil
local height = 20 
local width = 0
local txtL = nil
local txtR = nil
local ret_val, ret_heal = "  ", 0;
local tonumber=tonumber
local combo=nil
local linenum=1
local ModKey=""
local spell4 = nil
local spell5 = nil
local ManaLeft = 0;
local ManaMiddle = 0;
local ManaRight = 0;
local Mana4 = 0;
local Mana5 = 0;
local raidID=nil
local zone=nil;
local Instant_check=false
local top = nil
local x, y, z = nil,nil,nil
local format=format
local strsub=strsub
local strlen=strlen
local strlower=strlower
local HealBot_CheckBuffs = {}
local HealBot_Tooltip_DirtyLines={}
local mins,secs=0,0
  
function HealBot_Tooltip_Clear_CheckBuffs()
  for x,_ in pairs(HealBot_CheckBuffs) do
    HealBot_CheckBuffs[x]=nil;
  end
  HealBot_Clear_CheckBuffs()
end

function HealBot_Tooltip_CheckBuffs(buff)
  HealBot_CheckBuffs[buff]=buff;
  HealBot_Set_CheckBuffs(buff)
  z=HealBot_AltBuffNames(buff)
  if z then 
    HealBot_CheckBuffs[z]=buff; 
    HealBot_Set_CheckBuffs(z)
  end
end

function HealBot_Tooltip_ReturnMinsSecs(s)
  mins=floor(s/60)
  secs=floor(s-(mins*60))
  if secs<10 then secs="0"..secs end
  return mins,secs
end

local UnitOffline=nil
function HealBot_Action_RefreshTooltip(unit)
  if HealBot_Config.ShowTooltip==0 then return end
  if not unit then return end;
  
  uName=UnitName(unit);
  if (not uName) then return end;

  if unit=="target" then
    HealBot_Action_RefreshTargetTooltip(uName, unit)
	return
  end
  
  hlth,maxhlth=HealBot_UnitHealth(unit, uName)

  if hlth>maxhlth then
    maxhlth=HealBot_CorrectPetHealth(unit,hlth,maxhlth,uName)
  end
  
  UnitOffline=HealBot_Action_GetTimeOffline(uName); --added by Diacono
  uBuff=HealBot_UnitBuff[uName]
  DebuffType=HealBot_UnitDebuff[uName];

  spellLeft = HealBot_Action_SpellPattern("Left");
  spellMiddle = HealBot_Action_SpellPattern("Middle");
  spellRight = HealBot_Action_SpellPattern("Right");
  spellButton4 = HealBot_Action_SpellPattern("Button4");
  spellButton5 = HealBot_Action_SpellPattern("Button5");
  linenum = 1
  
  if not IsModifierKeyDown() and not HealBot_IsFighting and HealBot_Config.SmartCast==1 then 
    templeft=spellLeft;
    spellLeft=nil;
    spellLeft=HealBot_Action_SmartCast(unit);
    if not spellLeft then spellLeft=templeft; end;
  end
  if spellLeft and strlower(spellLeft)~=strlower(HEALBOT_DISABLED_TARGET) and strlower(spellLeft)~=strlower(HEALBOT_ASSIST) and strlower(spellLeft)~=strlower(HEALBOT_FOCUS) then
    
    if spellLeft then
      id=nil
      if not HealBot_Spells[spellLeft] then
        id = HealBot_GetSpellId(spellLeft);
      elseif HealBot_Spells[spellLeft].id then
        id = HealBot_Spells[spellLeft].id
      else
        id = HealBot_GetSpellId(spellLeft);
      end
	  if id then
        lspell, lspellrank = HealBot_GetSpellName(id)
        if lspellrank then
          spellLeft=lspell .. "(" .. lspellrank .. ")";
        else
          spellLeft=lspell;
        end
	  else
	    x=GetMacroIndexByName(spellLeft)
		if x==0 then spellLeft="" end
	  end
    else 
      spellLeft = HealBot_GetHealSpell(unit,HealBot_Action_SpellPattern("Left"));
    end
  end
  if spellMiddle and strlower(spellMiddle)~=strlower(HEALBOT_DISABLED_TARGET) and strlower(spellMiddle)~=strlower(HEALBOT_ASSIST) and strlower(spellMiddle)~=strlower(HEALBOT_FOCUS) then
    x=GetMacroIndexByName(spellMiddle)
	if x==0 then spellMiddle = HealBot_GetHealSpell(unit,spellMiddle) end
  end
  if spellRight and strlower(spellRight)~=strlower(HEALBOT_DISABLED_TARGET) and strlower(spellRight)~=strlower(HEALBOT_ASSIST) and strlower(spellRight)~=strlower(HEALBOT_FOCUS) then
    x=GetMacroIndexByName(spellRight)
    if x==0 then spellRight = HealBot_GetHealSpell(unit,spellRight) end
  end
  if spellButton4 and strlower(spellButton4)~=strlower(HEALBOT_DISABLED_TARGET) and strlower(spellButton4)~=strlower(HEALBOT_ASSIST) and strlower(spellButton4)~=strlower(HEALBOT_FOCUS) then
    x=GetMacroIndexByName(spellButton4)
    if x==0 then spellButton4 = HealBot_GetHealSpell(unit,spellButton4) end
  end
  if spellButton5 and strlower(spellButton5)~=strlower(HEALBOT_DISABLED_TARGET) and strlower(spellButton5)~=strlower(HEALBOT_ASSIST) and strlower(spellButton5)~=strlower(HEALBOT_FOCUS) then
    x=GetMacroIndexByName(spellButton5)
    if x==0 then spellButton5 = HealBot_GetHealSpell(unit,spellButton5) end
  end
  
  HealBot_Tooltip_ClearLines();
    
  if HealBot_Config.Tooltip_ShowTarget==1 then
    if uName then
      if UnitClass(unit) then
	    if UnitName("target") and UnitName("target")==uName and HealBot_UnitSpec[uName]==" " and UnitInRange("target") == 1 then
		  NotifyInspect("target")
		end
		text = HealBot_UnitSpec[uName] or " "
	    r,g,b=HealBot_Action_RetHealBot_ClassCol(uName)
        HealBot_Tooltip_SetLineLeft(uName,r,g,b,linenum,1)
        HealBot_Tooltip_SetLineRight("Level "..UnitLevel(unit)..text..UnitClass(unit),r,g,b,linenum,1) 		
      else 
        HealBot_Tooltip_SetLineLeft(uName,1,1,1,linenum,1)   
      end      
      if hlth and maxhlth then
	    linenum=linenum+1
        r,g,b,a=HealBot_HealthColor(unit,hlth,maxhlth,true,uName,false,uBuff,DebuffType,HealBot_RetHealsIn(uName));
        HealBot_Tooltip_SetLineRight(hlth.."/"..maxhlth.." (-"..maxhlth-hlth..")",r,g,b,linenum,1)
      else
        linenum=linenum+1
      end
      if UnitOffline then -- added by Diacono
    	HealBot_Tooltip_SetLineLeft(HB_TOOLTIP_OFFLINE..": "..UnitOffline,1,1,1,linenum,1)
		linenum=linenum+1
      end
      if DebuffType then
        linenum=linenum+1
        HealBot_Tooltip_SetLineLeft(uName.." suffers from "..HealBot_UnitDebuff[uName.."_debuff_name"],
                                           HealBot_Config.CDCBarColour[DebuffType].R+0.2,
                                           HealBot_Config.CDCBarColour[DebuffType].G+0.2,
                                           HealBot_Config.CDCBarColour[DebuffType].B+0.2,
                                           linenum,1)
        HealBot_Tooltip_SetLineRight(" ",0,0,0,linenum,0)
      end
      if uBuff then
        linenum=linenum+1
		br,bg,bb=HealBot_Options_RetBuffRGB(uBuff)
        HealBot_Tooltip_SetLineLeft(" Requires "..uBuff,br,bg,bb,linenum,1)
		HealBot_Tooltip_SetLineRight(" ",0,0,0,linenum,0)
      end
	  linenum=linenum+1
	  if HealBot_Config.Tooltip_ShowTarget==1 and HealBot_Config.Tooltip_ShowMyBuffs==1 then
	    d=false
        for x,y in pairs(HealBot_CheckBuffs) do
		  z=HealBot_RetMyBuffTime(uName,x)
          if z then
		    d=true
			z=z-GetTime()
			mins,secs=HealBot_Tooltip_ReturnMinsSecs(z)
            linenum=linenum+1
		    br,bg,bb=HealBot_Options_RetBuffRGB(y)
			if mins>0 then 
              HealBot_Tooltip_SetLineLeft("  "..x.."  "..mins..":"..secs.." mins",br,bg,bb,linenum,1)
			  HealBot_Tooltip_SetLineRight(" ",0,0,0,linenum,0)
			elseif tonumber(secs)>=0 and mins==0 then
			  HealBot_Tooltip_SetLineLeft("  "..x.."  "..secs.." secs",br,bg,bb,linenum,1)
			  HealBot_Tooltip_SetLineRight(" ",0,0,0,linenum,0)
			else
			  linenum=linenum-1
			  HealBot_Queue_MyBuffsCheck(uName,unit)
			  HealBot_AddDebug("Tooltip - Found debuff <1 buff="..x)
			end
		  end
        end
	  end
      if d then linenum=linenum+1 end
      if HealBot_Config.ProtectPvP==1 and UnitIsPVP(unit) and not UnitIsPVP("player") then 
        HealBot_Tooltip_SetLineLeft("    ----- PVP -----",1,0.5,0.5,linenum,1);
        HealBot_Tooltip_SetLineRight("----- PVP -----    ",1,0.5,0.5,linenum,1);
		linenum=linenum+1;
	  end
    end
  else
    HealBot_Tooltip_SetLineLeft(HEALBOT_OPTIONS_TAB_SPELLS,1,1,1,linenum,1)
	HealBot_Tooltip_SetLineRight(" ",0,0,0,linenum,0)
  end
  
  spellLeftRecInstant=false;
  spellMiddleRecInstant=false;
  spellRightRecInstant=false;
  spellButton4RecInstant=false;
  spellButton5RecInstant=false;
  
  if spellLeft=="" then spellLeft=nil; end
  if spellMiddle=="" then spellMiddle=nil; end
  if spellRight=="" then spellRight=nil; end
  if spellButton4=="" then spellButton4=nil; end
  if spellButton5=="" then spellButton5=nil; end
    
    if HealBot_Config.Tooltip_ShowSpellDetail==1 then

      if spellLeft then
        linenum=linenum+1
        HealBot_Tooltip_SetLineLeft(HEALBOT_OPTIONS_BUTTONLEFT.." "..HEALBOT_OPTIONS_COMBOBUTTON..": "..spellLeft,1,1,0,linenum,1) 
        HealBot_Tooltip_SpellInfo(spellLeft);
        spellLeftRecInstant=HealBot_Tooltip_CheckForInstant(unit,spellLeft)
        linenum=linenum+1;
      end
      if spellMiddle then
        linenum=linenum+1;
        HealBot_Tooltip_SetLineLeft(HEALBOT_OPTIONS_BUTTONMIDDLE.." "..HEALBOT_OPTIONS_COMBOBUTTON..": "..spellMiddle,1,1,0,linenum,1) 
        HealBot_Tooltip_SpellInfo(spellMiddle);
        spellMiddleRecInstant=HealBot_Tooltip_CheckForInstant(unit,spellMiddle)
        linenum=linenum+1;
      end
      if spellRight then
        linenum=linenum+1;
        HealBot_Tooltip_SetLineLeft(HEALBOT_OPTIONS_BUTTONRIGHT.." "..HEALBOT_OPTIONS_COMBOBUTTON..": "..spellRight,1,1,0,linenum,1) 
        HealBot_Tooltip_SpellInfo(spellRight);
        spellRightRecInstant=HealBot_Tooltip_CheckForInstant(unit,spellRight)
        linenum=linenum+1;
      end
      if spellButton4 then
        linenum=linenum+1;
        HealBot_Tooltip_SetLineLeft(HEALBOT_OPTIONS_BUTTON4.." "..HEALBOT_OPTIONS_COMBOBUTTON..": "..spellButton4,1,1,0,linenum,1) 
        HealBot_Tooltip_SpellInfo(spellButton4);
        spellButton4RecInstant=HealBot_Tooltip_CheckForInstant(unit,spellButton4)
        linenum=linenum+1;
      end
      if spellButton5 then
        linenum=linenum+1;
        HealBot_Tooltip_SetLineLeft(HEALBOT_OPTIONS_BUTTON5.." "..HEALBOT_OPTIONS_COMBOBUTTON..": "..spellButton5,1,1,0,linenum,1) 
        HealBot_Tooltip_SpellInfo(spellButton5);
        spellButton5RecInstant=HealBot_Tooltip_CheckForInstant(unit,spellButton5);
        linenum=linenum+1;
      end
    else
      hlthdelta=maxhlth-hlth;
      spellLeftTxt, spellLeftHeal="",0
      spellMiddleTxt, spellMiddleHeal="",0
      spellRightTxt, spellRightHeal="",0
      spellButton4Txt, spellButton4Heal="",0
      spellButton5Txt, spellButton5Heal="",0
      tmpnum=0;
      if spellLeft then 
        spellLeftTxt, spellLeftHeal=HealBot_Tooltip_SpellSummary(spellLeft);
        r,g,b,a,spellLeftRecInstant,spellLeftHeal=HealBot_Tooltip_SetQuickTipsColours(spellLeftHeal,hlthdelta,unit,spellLeft)
        linenum=linenum+1
        HealBot_Tooltip_SetLineRight(spellLeftTxt,r,g,b,linenum,a) 
        HealBot_Tooltip_SetLineLeft(HEALBOT_OPTIONS_BUTTONLEFT..": "..spellLeft,1,1,0,linenum,a) 
      end
      if spellMiddle then
        spellMiddleTxt, spellMiddleHeal=HealBot_Tooltip_SpellSummary(spellMiddle);
        r,g,b,a,spellMiddleRecInstant,spellMiddleHeal=HealBot_Tooltip_SetQuickTipsColours(spellMiddleHeal,hlthdelta,unit,spellMiddle)
        linenum=linenum+1
        HealBot_Tooltip_SetLineRight(HealBot_Tooltip_SpellSummary(spellMiddle),r,g,b,linenum,a) 
        HealBot_Tooltip_SetLineLeft(HEALBOT_OPTIONS_BUTTONMIDDLE..": "..spellMiddle,1,1,0,linenum,a) 
      end
      if spellRight then
        spellRightTxt, spellRightHeal=HealBot_Tooltip_SpellSummary(spellRight);
        r,g,b,a,spellRightRecInstant,spellRightHeal=HealBot_Tooltip_SetQuickTipsColours(spellRightHeal,hlthdelta,unit,spellRight)
        linenum=linenum+1
        HealBot_Tooltip_SetLineRight(HealBot_Tooltip_SpellSummary(spellRight),r,g,b,linenum,a) 
        HealBot_Tooltip_SetLineLeft(HEALBOT_OPTIONS_BUTTONRIGHT..": "..spellRight,1,1,0,linenum,a) 
      end
      if spellButton4 then
        spellButton4Txt, spellButton4Heal=HealBot_Tooltip_SpellSummary(spellButton4);
        r,g,b,a,spellButton4RecInstant,spellButton4Heal=HealBot_Tooltip_SetQuickTipsColours(spellButton4Heal,hlthdelta,unit,spellButton4)
        linenum=linenum+1
        HealBot_Tooltip_SetLineRight(HealBot_Tooltip_SpellSummary(spellButton4),r,g,b,linenum,a) 
        HealBot_Tooltip_SetLineLeft(HEALBOT_OPTIONS_BUTTON4..": "..spellButton4,1,1,0,linenum,a) 
      end
      if spellButton5 then
        spellButton5Txt, spellButton5Heal=HealBot_Tooltip_SpellSummary(spellButton5);
        r,g,b,a,spellButton5RecInstant,spellButton5Heal=HealBot_Tooltip_SetQuickTipsColours(spellButton5Heal,hlthdelta,unit,spellButton5)
        linenum=linenum+1
        HealBot_Tooltip_SetLineRight(HealBot_Tooltip_SpellSummary(spellButton5),r,g,b,linenum,a) 
        HealBot_Tooltip_SetLineLeft(HEALBOT_OPTIONS_BUTTON5..": "..spellButton5,1,1,0,linenum,a) 
      end
    end      
    if HealBot_Config.Tooltip_Recommend==1 then
      Instant_check=false;
      if HealBot_Config.Tooltip_ShowSpellDetail==0 then linenum=linenum+1; end
      linenum=linenum+1
      HealBot_Tooltip_SetLineLeft(HEALBOT_TOOLTIP_RECOMMENDTEXT,0.8,0.8,0,linenum,1) 
      if spellLeftRecInstant then
        linenum=linenum+1;
        HealBot_Tooltip_SetLineLeft("   "..HEALBOT_OPTIONS_BUTTONLEFT..":",1,1,0.2,linenum,1);
        HealBot_Tooltip_SetLineRight(spellLeft.."    ",1,1,1,linenum,1);
        Instant_check=true;
      end
      if spellMiddleRecInstant then
        linenum=linenum+1;
        HealBot_Tooltip_SetLineLeft("   "..HEALBOT_OPTIONS_BUTTONMIDDLE..":",1,1,0.2,linenum,1);
        HealBot_Tooltip_SetLineRight(spellMiddle.."    ",1,1,1,linenum,1);
        Instant_check=true;
      end
      if spellRightRecInstant then
        linenum=linenum+1;
        HealBot_Tooltip_SetLineLeft("   "..HEALBOT_OPTIONS_BUTTONRIGHT..":",1,1,0.2,linenum,1);
        HealBot_Tooltip_SetLineRight(spellRight.."    ",1,1,1,linenum,1);
        Instant_check=true;
      end
      if spellButton4RecInstant then
        linenum=linenum+1;
        HealBot_Tooltip_SetLineLeft("   "..HEALBOT_OPTIONS_BUTTON4..":",1,1,0.2,linenum,1);
        HealBot_Tooltip_SetLineRight(spellButton4.."    ",1,1,1,linenum,1);
        Instant_check=true;
      end
      if spellButton5RecInstant then
        linenum=linenum+1;
        HealBot_Tooltip_SetLineLeft("   "..HEALBOT_OPTIONS_BUTTON5..":",1,1,0.2,linenum,1);
        HealBot_Tooltip_SetLineRight(spellButton5.."    ",1,1,1,linenum,1);
        Instant_check=true;
      end
      if not Instant_check then
        linenum=linenum+1
        HealBot_Tooltip_SetLineLeft("  None",0.4,0.4,0.4,linenum,1) 
      end
    else
      if HealBot_Config.Tooltip_ShowSpellDetail==1 then linenum=linenum-1; end
    end
  
    HealBot_ToolTip_PreDefined(uName)
  
    height = 20 
    width = 0
    for x = 1, linenum do
      txtL = getglobal("HealBot_TooltipTextL" .. x)
      txtR = getglobal("HealBot_TooltipTextR" .. x)
      height = height + txtL:GetHeight() + 2
      if (txtL:GetWidth() + txtR:GetWidth() + 25 > width) then
        width = txtL:GetWidth() + txtR:GetWidth() + 25
      end
    end
    HealBot_ToolTip_SetTooltipPos();
    HealBot_Tooltip:SetWidth(width)
    HealBot_Tooltip:SetHeight(height)
    HealBot_Tooltip:Show();
end

local innerFocus
function HealBot_Tooltip_SpellInfo(spellName)
  text=nil
  innerFocus=HealBot_retInnerFocus()
  if HealBot_Spells[spellName] then
    if HealBot_Spells[spellName].HealsDur>0 then
      linenum=linenum+1
      HealBot_Tooltip_SetLineLeft(HEALBOT_WORDS_CAST..": "..HealBot_Spells[spellName].CastTime.." "..HEALBOT_WORDS_SEC..".",0.8,0.8,0.8,linenum,1)
      if innerFocus then
        HealBot_Tooltip_SetLineRight("Mana: 0",0.5,0.5,1,linenum,1) 
      else
        HealBot_Tooltip_SetLineRight("Mana: "..HealBot_Spells[spellName].Mana,0.5,0.5,1,linenum,1) 
      end
      if HealBot_Spells[spellName].HealsMax>0 then
        Heals = HEALBOT_HEAL.." "
        if HealBot_Spells[spellName].Shield then
          Heals = HEALBOT_TOOLTIP_SHIELD.." "
          text=Heals..format("%d", HealBot_Spells[spellName].HealsMax)
        else
          if HealBot_Spells[spellName].HealsMin<HealBot_Spells[spellName].HealsMax then
            text=Heals..format("%d", HealBot_Spells[spellName].HealsMin + HealBot_Spells[spellName].RealHealing) .." "..HEALBOT_WORDS_TO.." "..format("%d",HealBot_Spells[spellName].HealsMax + HealBot_Spells[spellName].RealHealing)
          else
            text=Heals..format("%d", HealBot_Spells[spellName].HealsMax + HealBot_Spells[spellName].RealHealing)
          end
        end
        linenum=linenum+1
        HealBot_Tooltip_SetLineLeft(text,1,1,1,linenum,1)
      end
      if HealBot_Spells[spellName].HealsExt>0 then
        text=HEALBOT_HEAL.." "..HealBot_Spells[spellName].HealsDur.." "..HEALBOT_WORDS_OVER.." "..HealBot_Spells[spellName].Duration-HealBot_Spells[spellName].CastTime.." sec."
        linenum=linenum+1
        HealBot_Tooltip_SetLineLeft(text,1,1,1,linenum,1)
      end
      if not HealBot_Spells[spellName].Shield then
        text=HEALBOT_TOOLTIP_ITEMBONUS.." +"..GetSpellBonusHealing().." | "..HEALBOT_TOOLTIP_ACTUALBONUS.." +"..HealBot_Spells[spellName].RealHealing.." "
        linenum=linenum+1
        HealBot_Tooltip_SetLineLeft(text,0.8,0.8,0.8,linenum,1)
      end
    end
  elseif HealBot_OtherSpells[spellName] then
    linenum=linenum+1
    HealBot_Tooltip_SetLineLeft(HEALBOT_WORDS_CAST..": "..HealBot_OtherSpells[spellName].CastTime.." "..HEALBOT_WORDS_SEC..".",0.8,0.8,0.8,linenum,1) 
    HealBot_Tooltip_SetLineRight("Mana: "..HealBot_OtherSpells[spellName].Mana,0.5,0.5,1,linenum,1)    
  end
end

function HealBot_Tooltip_SpellSummary(spellName)
  ret_val, ret_heal = "  ", 0
  if HealBot_Spells[spellName] then
    if HealBot_Spells[spellName].HealsDur>0 then
      if HealBot_Spells[spellName].HealsMax>0 then
        Heals = " "..HEALBOT_HEAL.." "
        if HealBot_Spells[spellName].Shield then
          Heals = " "..HEALBOT_TOOLTIP_SHIELD.." "
          ret_heal=HealBot_Spells[spellName].HealsMax
          ret_val=ret_val..Heals..format("%d", ret_heal)
          ret_heal=0-ret_heal
        else
          if HealBot_Spells[spellName].HealsMin<HealBot_Spells[spellName].HealsMax then
            ret_heal=((HealBot_Spells[spellName].HealsMin+HealBot_Spells[spellName].HealsMax)/2) + HealBot_Spells[spellName].RealHealing
          else
            ret_heal=HealBot_Spells[spellName].HealsMax + HealBot_Spells[spellName].RealHealing
          end
          ret_val=ret_val..Heals..format("%d", ret_heal)
        end
      end
      if HealBot_Spells[spellName].HealsExt>0 then
        ret_heal=HealBot_Spells[spellName].HealsDur;
        ret_val=ret_val.." HoT "..format("%d", ret_heal);
        ret_heal=0-ret_heal;
      end
--      ret_val=ret_val.." "..HEALBOT_WORDS_FOR.." "..HealBot_Spells[spellName].Mana.." Mana";
    end
  elseif HealBot_OtherSpells[spellName] then
    innerFocus=HealBot_retInnerFocus()
    if innerFocus then
      ret_val = " -   0 Mana"
    else
      ret_val = " -  "..HealBot_OtherSpells[spellName].Mana.." Mana"
    end
  else
    ret_heal=-1;
  end
  if strlen(ret_val)<5 then ret_val = " - "..spellName; end
  return ret_val,ret_heal;
end

function HealBot_Tooltip_CheckForInstant(unit,spellName)
  if HealBot_Spells[spellName] then
    if HealBot_Spells[spellName].Buff then
      if HealBot_HasMyBuff(HealBot_Spells[spellName].Buff,unit) then return false end;  
      return true;
    end
  end
  return false;
end

function HealBot_Tooltip_SetQuickTipsColours(healval,hlthdelta,unit,spellName)
  r,g,b,a,ri=0.5,0.5,1,1,false;
  ri=HealBot_Tooltip_CheckForInstant(unit,spellName)
  if healval==-1 then
--    r, g, b=0.58,0.58,1;
  elseif healval>0 then
    if healval>hlthdelta then
      tmpnum=(healval-hlthdelta);
      a=(hlthdelta-tmpnum)/(hlthdelta+1);
    else
      a=((healval)/(hlthdelta+1))*1.35;
    end
  elseif healval==0 then
--    r, g, b=0.8,1,0.2;
  else
    healval=0-healval;
    if (healval*.72)>hlthdelta then
      tmpnum=((healval)-hlthdelta);
      a=((hlthdelta-tmpnum)/(hlthdelta+1))*1.35;
    else
      A=(healval/(hlthdelta+1))*1.5;
    end
    if not ri then
      a=0.2
    end
  end
  if a<0.2 then 
    a=0.2;
  elseif a>1 then 
    a=1;
  end
  return r,g,b,a,ri,healval;
end

function HealBot_Tooltip_RefreshDisabledTooltip(unit)
  if HealBot_Config.ShowTooltip==0 then return end
  if not unit then return end;
  
  uName=UnitName(unit);

  if (not uName) then return end;
  
  if unit=="target" then
    HealBot_Action_RefreshTargetTooltip(uName, unit)
	return
  end

  combo=HealBot_Config.DisabledKeyCombo
  linenum=1;
  ModKey="";
  if IsAltKeyDown() then ModKey="Alt"; end
  if IsControlKeyDown() then ModKey="Ctrl"..ModKey; end
  if IsShiftKeyDown() then ModKey="Shift"..ModKey; end

  innerFocus=HealBot_retInnerFocus()
  spellLeft=nil
  spellMiddle = combo[ModKey.."Middle"];
  spellRight = combo[ModKey.."Right"];
  spell4 = combo[ModKey.."Button4"];
  spell5 = combo[ModKey.."Button5"];
  
  spellLeftRecInstant=false;
  spellMiddleRecInstant=false;
  spellRightRecInstant=false;
  spellButton4RecInstant=false;
  spellButton5RecInstant=false;
  
  if ModKey=="" and not HealBot_IsFighting and HealBot_Config.SmartCast==1 then 
    spellLeft=HealBot_Action_SmartCast(unit);
  end
  if not spellLeft then
    spellLeft = combo[ModKey.."Left"];
    if spellLeft and strlower(spellLeft)~=strlower(HEALBOT_DISABLED_TARGET) and strlower(spellLeft)~=strlower(HEALBOT_ASSIST) and strlower(spellLeft)~=strlower(HEALBOT_FOCUS) then
	  x=GetMacroIndexByName(spellLeft)
      if x==0 then spellLeft = HealBot_GetHealSpell(unit,spellLeft) end 
    end
  end
  if spellMiddle and strlower(spellMiddle)~=strlower(HEALBOT_DISABLED_TARGET) and strlower(spellMiddle)~=strlower(HEALBOT_ASSIST) and strlower(spellMiddle)~=strlower(HEALBOT_FOCUS) then
    x=GetMacroIndexByName(spellMiddle)
	if x==0 then spellMiddle = HealBot_GetHealSpell(unit,spellMiddle) end
  end
  if spellRight and strlower(spellRight)~=strlower(HEALBOT_DISABLED_TARGET) and strlower(spellRight)~=strlower(HEALBOT_ASSIST) and strlower(spellRight)~=strlower(HEALBOT_FOCUS) then
    x=GetMacroIndexByName(spellRight)
    if x==0 then spellRight = HealBot_GetHealSpell(unit,spellRight) end
  end
  if spell4 and strlower(spell4)~=strlower(HEALBOT_DISABLED_TARGET) and strlower(spell4)~=strlower(HEALBOT_ASSIST) and strlower(spell4)~=strlower(HEALBOT_FOCUS) then
    x=GetMacroIndexByName(spell4)
    if x==0 then spell4 = HealBot_GetHealSpell(unit,spell4) end
  end
  if spell5 and strlower(spell5)~=strlower(HEALBOT_DISABLED_TARGET) and strlower(spell5)~=strlower(HEALBOT_ASSIST) and strlower(spell5)~=strlower(HEALBOT_FOCUS) then
    x=GetMacroIndexByName(spell5)
    if x==0 then spell5 = HealBot_GetHealSpell(unit,spell5) end
  end
  
  ManaLeft = 0;
  ManaMiddle = 0;
  ManaRight = 0;
  Mana4 = 0;
  Mana5 = 0;
  
  if HealBot_Spells[spellLeft] then
    ManaLeft = HealBot_Spells[spellLeft].Mana
  elseif HealBot_OtherSpells[spellLeft] then
    ManaLeft = HealBot_OtherSpells[spellLeft].Mana
  elseif spellLeft=="" then
    spellLeft=nil;
  end
    
  if HealBot_Spells[spellMiddle] then
    ManaMiddle = HealBot_Spells[spellMiddle].Mana
  elseif HealBot_OtherSpells[spellMiddle] then
    ManaMiddle = HealBot_OtherSpells[spellMiddle].Mana
  elseif spellMiddle=="" then
    spellMiddle=nil;
  end

  if HealBot_Spells[spellRight] then
    ManaRight = HealBot_Spells[spellRight].Mana
  elseif HealBot_OtherSpells[spellRight] then
    ManaRight = HealBot_OtherSpells[spellRight].Mana
  elseif spellRight=="" then
    spellRight=nil;
  end

  if HealBot_Spells[spell4] then
    ManaRight = HealBot_Spells[spell4].Mana
  elseif HealBot_OtherSpells[spell4] then
    ManaRight = HealBot_OtherSpells[spell4].Mana
  elseif spell4=="" then
    spell4=nil;
  end

  if HealBot_Spells[spell5] then
    ManaRight = HealBot_Spells[spell5].Mana
  elseif HealBot_OtherSpells[spell5] then
    ManaRight = HealBot_OtherSpells[spell5].Mana
  elseif spell5=="" then
    spell5=nil;
  end
    
  HealBot_Tooltip_ClearLines();
  
  if HealBot_Config.Tooltip_ShowTarget==1 then
    raidID=nil
    zone=nil;
    if HealBot_PlayerName==uName then
      zone=GetRealZoneText();
    elseif GetNumRaidMembers()>0 then
      if strsub(unit,1,4)~="raid" then
        if UnitInRaid(unit) then
          for r=1,40 do
            if UnitName("raid"..r)==uName then
              raidID=r
              _, _, _, _, _, _, zone, _, _ = GetRaidRosterInfo(raidID);
              do break end;
            end
          end
        end
      elseif strsub(unit,1,7)~="raidpet" then
        raidID=tonumber(strsub(unit,5))
        _, _, _, _, _, _, zone, _, _ = GetRaidRosterInfo(raidID);
      end
    else
      HealBot_TooltipInit();
      HealBot_ScanTooltip:SetUnit(unit)
      zone = HealBot_ScanTooltipTextLeft3:GetText()
      if zone == "PvP" then
        zone = HealBot_ScanTooltipTextLeft4:GetText()
      end
    end
    if uName then
	  if UnitName("target") and UnitName("target")==uName and HealBot_UnitSpec[uName]==" " and UnitInRange("target") == 1 then
		NotifyInspect("target")
      end
	  r,g,b=HealBot_Action_RetHealBot_ClassCol(uName)
      HealBot_Tooltip_SetLineLeft(uName,r,g,b,linenum,1)
      if UnitClass(unit) then
	    text = HealBot_UnitSpec[uName] or " "
        HealBot_Tooltip_SetLineRight(" Level "..UnitLevel(unit)..text..UnitClass(unit),r,g,b,linenum,1);
      end
	  UnitOffline=HealBot_Action_GetTimeOffline(uName); --added by Diacono
      if zone and not strfind(zone,"Level") then
        linenum=linenum+1
        HealBot_Tooltip_SetLineLeft(HEALBOT_TOOLTIP_LOCATION..":",1,1,0.5,linenum,1);
        if UnitOffline then -- added by Diacono
    	  HealBot_Tooltip_SetLineRight(HB_TOOLTIP_OFFLINE..": "..UnitOffline,1,1,1,linenum,1)
        else
		  if zone==HB_TOOLTIP_OFFLINE then HealBot_Action_UnitIsOffline(unit,uName,time()) end
		  HealBot_Tooltip_SetLineRight(zone,1,1,1,linenum,1);
        end
	  elseif UnitOffline then
	    linenum=linenum+1
		HealBot_Tooltip_SetLineLeft(HB_TOOLTIP_OFFLINE..": "..UnitOffline,1,1,1,linenum,1)
      end
      if HealBot_Config.ProtectPvP==1 and UnitIsPVP(unit) and not UnitIsPVP("player") then 
        HealBot_Tooltip_SetLineLeft("    ----- PVP -----",1,0.5,0.5,linenum,1);
        HealBot_Tooltip_SetLineRight("----- PVP -----    ",1,0.5,0.5,linenum,1);
	  end
      DebuffType=HealBot_UnitDebuff[uName];
      if DebuffType then
        linenum=linenum+1
        HealBot_Tooltip_SetLineLeft(uName.." suffers from "..HealBot_UnitDebuff[uName.."_debuff_name"],
                                           HealBot_Config.CDCBarColour[DebuffType].R+0.2,
                                           HealBot_Config.CDCBarColour[DebuffType].G+0.2,
                                           HealBot_Config.CDCBarColour[DebuffType].B+0.2,
                                           linenum,1)
		HealBot_Tooltip_SetLineRight(" ",0,0,0,linenum,0)
      end
      uBuff=HealBot_UnitBuff[uName];
      if uBuff then
        linenum=linenum+1
		br,bg,bb=HealBot_Options_RetBuffRGB(uBuff);
        HealBot_Tooltip_SetLineLeft(" Requires "..uBuff,br,bg,bb,linenum,1)
		HealBot_Tooltip_SetLineRight(" ",0,0,0,linenum,0)
      end
	  linenum=linenum+1
	  if HealBot_Config.Tooltip_ShowTarget==1 and HealBot_Config.Tooltip_ShowMyBuffs==1 then
	    d=false
        for x,y in pairs(HealBot_CheckBuffs) do
		  z=HealBot_RetMyBuffTime(uName,x)
          if z then
		    d=true
			z=z-GetTime()
			mins,secs=HealBot_Tooltip_ReturnMinsSecs(z)
            linenum=linenum+1
		    br,bg,bb=HealBot_Options_RetBuffRGB(y)
			if mins>0 then 
              HealBot_Tooltip_SetLineLeft("  "..x.."  "..mins..":"..secs.." mins",br,bg,bb,linenum,1)
			  HealBot_Tooltip_SetLineRight(" ",0,0,0,linenum,0)
			elseif tonumber(secs)>=0 and mins==0 then
			  HealBot_Tooltip_SetLineLeft("  "..x.."  "..secs.." secs",br,bg,bb,linenum,1)
			  HealBot_Tooltip_SetLineRight(" ",0,0,0,linenum,0)
			else
			  linenum=linenum-1
			  HealBot_Queue_MyBuffsCheck(uName,unit)
			  HealBot_AddDebug("Tooltip - Found debuff <1 buff="..x.."  z="..z)
			end
		  end
        end
	  end
      if d then linenum=linenum+1 end
    end
  else
    HealBot_Tooltip_SetLineLeft(HEALBOT_OPTIONS_TAB_SPELLS,1,1,1,linenum,1)
	HealBot_Tooltip_SetLineRight(" ",0,0,0,linenum,0)
  end
  
  if spellLeft then
    linenum=linenum+1
    HealBot_Tooltip_SetLineLeft(HEALBOT_OPTIONS_BUTTONLEFT..": "..spellLeft,1,1,0,linenum,1) 
    if ManaLeft>0 then 
      if innerFocus then ManaLeft=0; end
      HealBot_Tooltip_SetLineRight("  "..ManaLeft.." Mana",0.5,0.5,1,linenum,1); 
    end
    spellLeftRecInstant=HealBot_Tooltip_CheckForInstant(unit,spellLeft)
  end
  if spellMiddle then
    linenum=linenum+1
    HealBot_Tooltip_SetLineLeft(HEALBOT_OPTIONS_BUTTONMIDDLE..": "..spellMiddle,1,1,0,linenum,1) 
    if ManaMiddle>0 then
      if innerFocus then ManaMiddle=0; end
      HealBot_Tooltip_SetLineRight("  "..ManaMiddle.." Mana",0.5,0.5,1,linenum,1); 
    end
    spellMiddleRecInstant=HealBot_Tooltip_CheckForInstant(unit,spellMiddle)
  end
  if spellRight then
    linenum=linenum+1
    HealBot_Tooltip_SetLineLeft(HEALBOT_OPTIONS_BUTTONRIGHT..": "..spellRight,1,1,0,linenum,1) 
    if ManaRight>0 then 
      if innerFocus then ManaRight=0; end
      HealBot_Tooltip_SetLineRight("  "..ManaRight.." Mana",0.5,0.5,1,linenum,1); 
    end
    spellRightRecInstant=HealBot_Tooltip_CheckForInstant(unit,spellRight)
  end
  if spell4 then
    linenum=linenum+1
    HealBot_Tooltip_SetLineLeft(HEALBOT_OPTIONS_BUTTON4..": "..spell4,1,1,0,linenum,1) 
    if Mana4>0 then 
      if innerFocus then Mana4=0; end
      HealBot_Tooltip_SetLineRight("  "..Mana4.." Mana",0.5,0.5,1,linenum,1); 
    end
    spellButton4RecInstant=HealBot_Tooltip_CheckForInstant(unit,spell4)
  end
  if spell5 then
    linenum=linenum+1
    HealBot_Tooltip_SetLineLeft(HEALBOT_OPTIONS_BUTTON5..": "..spell5,1,1,0,linenum,1) 
    if Mana5>0 then 
      if innerFocus then Mana5=0; end
      HealBot_Tooltip_SetLineRight("  "..Mana5.." Mana",0.5,0.5,1,linenum,1); 
    end
    spellButton5RecInstant=HealBot_Tooltip_CheckForInstant(unit,spell5);
  end

  if HealBot_Config.Tooltip_Recommend==1 then
    Instant_check=false;
    linenum=linenum+2
    HealBot_Tooltip_SetLineLeft(HEALBOT_TOOLTIP_RECOMMENDTEXT,0.8,0.8,0,linenum,1) 
      if spellLeftRecInstant then
        linenum=linenum+1;
        HealBot_Tooltip_SetLineLeft("   "..HEALBOT_OPTIONS_BUTTONLEFT..":",1,1,0.2,linenum,1);
        HealBot_Tooltip_SetLineRight(spellLeft.."    ",1,1,1,linenum,1);
        Instant_check=true;
      end
      if spellMiddleRecInstant then
        linenum=linenum+1;
        HealBot_Tooltip_SetLineLeft("   "..HEALBOT_OPTIONS_BUTTONMIDDLE..":",1,1,0.2,linenum,1);
        HealBot_Tooltip_SetLineRight(spellMiddle.."    ",1,1,1,linenum,1);
        Instant_check=true;
      end
      if spellRightRecInstant then
        linenum=linenum+1;
        HealBot_Tooltip_SetLineLeft("   "..HEALBOT_OPTIONS_BUTTONRIGHT..":",1,1,0.2,linenum,1);
        HealBot_Tooltip_SetLineRight(spellRight.."    ",1,1,1,linenum,1);
        Instant_check=true;
      end
      if spellButton4RecInstant then
        linenum=linenum+1;
        HealBot_Tooltip_SetLineLeft("   "..HEALBOT_OPTIONS_BUTTON4..":",1,1,0.2,linenum,1);
        HealBot_Tooltip_SetLineRight(spell4.."    ",1,1,1,linenum,1);
        Instant_check=true;
      end
      if spellButton5RecInstant then
        linenum=linenum+1;
        HealBot_Tooltip_SetLineLeft("   "..HEALBOT_OPTIONS_BUTTON5..":",1,1,0.2,linenum,1);
        HealBot_Tooltip_SetLineRight(spell5.."    ",1,1,1,linenum,1);
        Instant_check=true;
      end
    if not Instant_check then
      linenum=linenum+1
      HealBot_Tooltip_SetLineLeft("  None",0.4,0.4,0.4,linenum,1) 
    end
  end
  
  HealBot_ToolTip_PreDefined(uName) 

    height = 20 
    width = 0
    for i = 1, linenum do
      txtL = getglobal("HealBot_TooltipTextL" .. i)
      txtR = getglobal("HealBot_TooltipTextR" .. i)
      height = height + txtL:GetHeight() + 2
      if (txtL:GetWidth() + txtR:GetWidth() + 25 > width) then
        width = txtL:GetWidth() + txtR:GetWidth() + 25
      end
    end
    HealBot_ToolTip_SetTooltipPos();
    HealBot_Tooltip:SetWidth(width)
    HealBot_Tooltip:SetHeight(height)
    HealBot_Tooltip:Show();
end

function HealBot_Action_RefreshTargetTooltip(unitName, unit)
  HealBot_TooltipInit();
  HealBot_Tooltip_ClearLines();
  linenum=1
  r,g,b=HealBot_Action_RetHealBot_ClassCol(unitName)
  HealBot_Tooltip_SetLineLeft(unitName,r,g,b,linenum,1)
  if UnitClass(unit) then
    text = HealBot_UnitSpec[unitName] or " "
    HealBot_Tooltip_SetLineRight(" Level "..UnitLevel(unit)..text..UnitClass(unit),r,g,b,linenum,1);
  end
  linenum=linenum+1
  HealBot_Tooltip_SetLineLeft(HEALBOT_TOOLTIP_TARGETBAR,1,1,0.5,linenum,1);
  HealBot_Tooltip_SetLineRight(HEALBOT_OPTIONS_TAB_SPELLS.." "..HEALBOT_SKIN_DISTEXT,1,1,0.5,linenum,1);
  linenum=linenum+2
  
  if HealBot_Config.SmartCast==1 then
    HealBot_Tooltip_SetLineLeft(" "..HEALBOT_OPTIONS_BUTTONLEFT..":",1,1,0.2,linenum,1)
    HealBot_Tooltip_SetLineRight(HEALBOT_TITAN_SMARTCAST.." ",1,1,1,linenum,1);
  end
  if HealBot_UnitID[unitName] then
    linenum=linenum+1
    HealBot_Tooltip_SetLineLeft(" "..HEALBOT_OPTIONS_BUTTONRIGHT..":",1,1,0.2,linenum,1)
    if HealBot_Panel_RetMyHealTarget(unitName) then
      HealBot_Tooltip_SetLineRight(HEALBOT_WORDS_REMOVEFROM.." "..HEALBOT_OPTIONS_TARGETHEALS.." ",1,1,1,linenum,1);
    else
      HealBot_Tooltip_SetLineRight(HEALBOT_WORDS_ADDTO.." "..HEALBOT_OPTIONS_TARGETHEALS.." ",1,1,1,linenum,1);
    end
  end
  
    height = 20 
    width = 0
    for x = 1, linenum do
      txtL = getglobal("HealBot_TooltipTextL" .. x)
      txtR = getglobal("HealBot_TooltipTextR" .. x)
      height = height + txtL:GetHeight() + 2
      if (txtL:GetWidth() + txtR:GetWidth() + 25 > width) then
        width = txtL:GetWidth() + txtR:GetWidth() + 25
      end
    end
    HealBot_ToolTip_SetTooltipPos();
    HealBot_Tooltip:SetWidth(width)
    HealBot_Tooltip:SetHeight(height)
    HealBot_Tooltip:Show();
end

function HealBot_ToolTip_PreDefined(unitName)
  if HealBot_Config.Tooltip_PreDefined==1 then
    linenum=linenum+2
    HealBot_Tooltip_SetLineLeft("   "..HEALBOT_OPTIONS_CTRL.."+"..HEALBOT_OPTIONS_ALT.."+"..HEALBOT_OPTIONS_BUTTONLEFT..":",1,1,0.2,linenum,1)
    if HealBot_Action_RetMyTarget(unitName) then
      HealBot_Tooltip_SetLineRight(HEALBOT_SKIN_DISTEXT.."    ",1,1,1,linenum,1)
    else
      HealBot_Tooltip_SetLineRight(HEALBOT_SKIN_ENTEXT.."    ",1,1,1,linenum,1)
    end
  
    linenum=linenum+1
    HealBot_Tooltip_SetLineLeft("   "..HEALBOT_OPTIONS_CTRL.."+"..HEALBOT_OPTIONS_ALT.."+"..HEALBOT_OPTIONS_BUTTONMIDDLE..":",1,1,0.2,linenum,1)
    HealBot_Tooltip_SetLineRight(HEALBOT_PANEL_BLACKLIST.."    ",1,1,1,linenum,1)

    linenum=linenum+1
    HealBot_Tooltip_SetLineLeft("   "..HEALBOT_OPTIONS_CTRL.."+"..HEALBOT_OPTIONS_ALT.."+"..HEALBOT_OPTIONS_BUTTONRIGHT..":",1,1,0.2,linenum,1)
    if HealBot_Panel_RetMyHealTarget(unitName) then
      HealBot_Tooltip_SetLineRight(HEALBOT_WORDS_REMOVEFROM.." "..HEALBOT_OPTIONS_TARGETHEALS.."    ",1,1,1,linenum,1)
    else
      HealBot_Tooltip_SetLineRight(HEALBOT_WORDS_ADDTO.." "..HEALBOT_OPTIONS_TARGETHEALS.."    ",1,1,1,linenum,1)
    end
  end

end

function HealBot_ToolTip_SetTooltipPos()
    HealBot_Tooltip:ClearAllPoints();
    if HealBot_Config.TooltipPos>1 then
      top = HealBot_Action:GetTop();
      x, y = GetCursorPosition();
      x=x/UIParent:GetScale();
      y=y/UIParent:GetScale();
      if HealBot_Config.TooltipPos==2 then
        HealBot_Tooltip:SetPoint("TOPRIGHT","HealBot_Action","TOPLEFT",0,0-(top-(y+35)));
      elseif HealBot_Config.TooltipPos==3 then
        HealBot_Tooltip:SetPoint("TOPLEFT","HealBot_Action","TOPRIGHT",0,0-(top-(y+35)));
      elseif HealBot_Config.TooltipPos==4 then
        HealBot_Tooltip:SetPoint("BOTTOM","HealBot_Action","TOP",0,0);
      elseif HealBot_Config.TooltipPos==5 then
        HealBot_Tooltip:SetPoint("TOP","HealBot_Action","BOTTOM",0,0);
      else
        HealBot_Tooltip:SetPoint("TOPLEFT","WorldFrame","BOTTOMLEFT",x+25,y-20);
      end
    else
      HealBot_Tooltip:SetPoint("BOTTOMRIGHT","WorldFrame","BOTTOMRIGHT",-105,105);
    end
end

function HealBot_Tooltip_SetLineLeft(Text,R,G,B,lNo,a)
  if lNo>40 then return end
  txtL = getglobal("HealBot_TooltipTextL" .. lNo)
  txtL:SetTextColor(R,G,B,a)
  txtL:SetText(Text)
  txtL:Show()
  HealBot_Tooltip_DirtyLines[lNo]=true
end

function HealBot_Tooltip_SetLineRight(Text,R,G,B,lNo,a)
  if lNo>40 then return end
  txtR = getglobal("HealBot_TooltipTextR" .. lNo)
  txtR:SetTextColor(R,G,B,a)
  txtR:SetText(Text)
  txtR:Show()
  HealBot_Tooltip_DirtyLines[lNo]=true
end

function HealBot_Tooltip_ClearLines()
  for x,_ in pairs(HealBot_Tooltip_DirtyLines) do
    txtR = getglobal("HealBot_TooltipTextR" .. x)
    txtR:SetText(" ")
    txtL = getglobal("HealBot_TooltipTextL" .. x)
    txtL:SetText(" ")
	HealBot_Tooltip_DirtyLines[x]=nil
  end
end

local timeOffline,uOffline = nil,nil
local hours, minutes, seconds
function HealBot_Action_GetTimeOffline(unitName)
  uOffline=HealBot_Action_retUnitOffline(unitName)
  timeOffline=nil
  if uOffline then
  	timeOffline = time() - uOffline;
  	seconds = timeOffline % 60;
		minutes = math.floor(timeOffline / 60) % 60
		hours = math.floor(timeOffline / 3600)
		timeOffline = "";
		if hours > 0 then
			if hours == 1 then
				timeOffline = hours.." hour ";
			else
				timeOffline = hours.." hours ";
			end
		end
		if minutes > 0 then
			if minutes == 1 then
				timeOffline = timeOffline..minutes.." min ";
			else
				timeOffline = timeOffline..minutes.." mins ";
			end
		end
		if seconds > 0 then
			if seconds == 1 then
				timeOffline = timeOffline..seconds.." sec";
			else
				timeOffline = timeOffline..seconds.." secs";
			end
		end						
	end  	
  return timeOffline;
end