--[[

	Scorpio's AddOns

	By Scorpio of <Sisu> http://sisuguild.fi

]]

-- Format Time to Text
function SAD_FormatTimeText(time, show_full_time)

	local d, h, m, s;
	local text = "";
	
	if(time <= 0) then
	
		text = "";

	else

		d, h, m, s = ChatFrame_TimeBreakDown(time);
		
		if(show_full_time) then
		
			text = format("%d:%02d:%02d:%02d", d, h, m, s);
		
		else
		
			if(time <= 3600) then
		
				text = format("%02d:%02d", m, s);
				
			else
			
				text = format("1h+");
				
			end
		
		end
	
	end
	
	return text;
	
end

function SAD_FindCurrentResolution(...)

	if(GetCurrentResolution() < 1 or GetCurrentResolution() > arg.n) then
		return;
	end
	
	local resolution = arg[GetCurrentResolution()];
	local xIndex = strfind(resolution, "x");
	local width = strsub(resolution, 1, xIndex-1);
	local height = strsub(resolution, xIndex+1, strlen(resolution));
	
	return width, height;
	
end

-- Debug trace
function SAD_Trace(msg, r, g, b, frame, id, unknown4th)

	if(SAD_DEBUG == false) then
	
		return;
		
	end
	
	if(unknown4th) then
		local temp = id;
		id = unknown4th;
		unknown4th = id;
	end
				
	if (not r) then r = 1.0; end
	if (not g) then g = 1.0; end
	if (not b) then b = 1.0; end

	if ( frame ) then 
		frame:AddMessage(msg,r,g,b,id,unknown4th);
	else
		if ( DEFAULT_CHAT_FRAME ) then 
			DEFAULT_CHAT_FRAME:AddMessage(msg, r, g, b,id,unknown4th);
		end
	end
		
end

-- Output to chat
function SAD_Output(msg, r, g, b, frame, id, unknown4th)

	if(unknown4th) then
		local temp = id;
		id = unknown4th;
		unknown4th = id;
	end
				
	if (not r) then r = 1.0; end
	if (not g) then g = 1.0; end
	if (not b) then b = 1.0; end

	if ( frame ) then 
		frame:AddMessage(msg,r,g,b,id,unknown4th);
	else
		if ( DEFAULT_CHAT_FRAME ) then 
			DEFAULT_CHAT_FRAME:AddMessage(msg, r, g, b,id,unknown4th);
		end
	end
		
end

-- TOOLTIP Fix toggle, apply both sides of own tooltip calls
local SAD_Saved_GameTooltip_ClearMoney = nil;

function SAD_GameTooltip_ClearMoney_Fix()

	if( SAD_Saved_GameTooltip_ClearMoney ~= nil ) then
	
		GameTooltip_ClearMoney = SAD_Saved_GameTooltip_ClearMoney;
		SAD_Saved_GameTooltip_ClearMoney = nil;
	
	else
	
		SAD_Saved_GameTooltip_ClearMoney = GameTooltip_ClearMoney;
		GameTooltip_ClearMoney = SAD_GameTooltip_ClearMoney;
	
	end

end

function SAD_GameTooltip_ClearMoney()

	-- left blank on purpose
	
end