MGDB = {}
if (MGDB['take_ah'] == nil) then
	MGDB['take_ah'] = false;
end
if (MGDB['pay_cod'] == nil) then
	MGDB['pay_cod'] = false;
end

--make new button

mailButton = CreateFrame("Button", "OpenMailTakeButton", OpenMail, "UIPanelButtonTemplate");
mailButton:Hide();
mailButton:SetWidth(OpenMailReplyButton:GetWidth()-5);
mailButton:SetHeight(OpenMailReplyButton:GetHeight());
mailButton:SetFrameStrata('DIALOG');
mailButton:SetPoint("right","OpenMailReplyButton","left");
mailButton:SetText('Take All');
mailButton:SetScript('OnClick', MG_GetMailItems);
mailButton:SetScript('OnEvent', MG_OnEvent);
mailButton:RegisterEvent('PLAYER_MONEY');
mailButton:RegisterEvent('CHAT_MSG_LOOT');
mailButton:SetScale(.75);

--some default variables

MG_MailIndex = 1;
MG_MailItemIndex = 0;
MG_MailQueue = {}
MG_MailIndexes = {}
MG_TakeIndex = 1;
MG_TakeMoney = false;

--set some scripts

MG_NextScript = InboxNextPageButton:GetScript('OnClick');
MG_PrevScript = InboxPrevPageButton:GetScript('OnClick');

InboxNextPageButton:SetScript('OnClick', MG_Next);
InboxPrevPageButton:SetScript('OnClick', MG_Prev);

for i=1,7 do 
	mailboxbutton = getglobal('MailItem' .. i .. 'Button');
	mailboxbutton.oldscript = mailboxbutton:GetScript('OnClick');
	mailboxbutton:SetScript('OnClick', MG_OpenMail);
end


if (OpenMailFrame:GetScript('OnShow')) then
	MG_OldShow = OpenMailFrame:GetScript('OnShow');
end

if (OpenMailFrame:GetScript('OnHide')) then
	MG_OldHide = OpenMailFrame:GetScript('OnHide');
end

OpenMailFrame:SetScript('OnShow', MG_Show);
OpenMailFrame:SetScript('OnHide', MG_Hide);

------------------------------------------------------------------------------------
-- master take all button 
------------------------------------------------------------------------------------

bigMailButton = CreateFrame("Button", "MailFrameTakeButton", InboxFrame, "UIPanelButtonTemplate");
bigMailButton:SetWidth(OpenMailReplyButton:GetWidth());
bigMailButton:SetHeight(OpenMailReplyButton:GetHeight());
bigMailButton:SetFrameStrata('DIALOG');
bigMailButton:SetPoint("BOTTOM","MailFrame","BOTTOM", -63, 104);
bigMailButton:SetText('Забрать все');
bigMailButton:SetScale(.9)
bigMailButton:SetScript('OnClick', MG_GetAllMailItems);

------------------------------------------------------------------------------------
-- loot history
------------------------------------------------------------------------------------

--lootHistoryWindow = CreateFrame("Frame", "MailGetHistory", UIParent);
--lootHistoryWindow:SetWidth

--OptionsCheckButtonTemplate
checkButton = CreateFrame("CheckButton", "OpenMailTakeAH", bigMailButton, "OptionsCheckButtonTemplate");
checkButton:SetPoint("left", bigMailButton, "right", 10, 10);
checkButton:SetFrameStrata('DIALOG');
OpenMailTakeAHText:SetText('Забрать АУК предметы');
OpenMailTakeAH:SetScript('OnClick', MG_ToggleAH);
OpenMailTakeAH:SetScript('OnShow', MG_ShowOMTA);
OpenMailTakeAH:SetScale(.75);

--OptionsCheckButtonTemplate
checkButton2 = CreateFrame("CheckButton", "OpenMailPayCOD", bigMailButton, "OptionsCheckButtonTemplate");
checkButton2:SetPoint("left", bigMailButton, "right", 10, -11);
checkButton2:SetFrameStrata('DIALOG');
OpenMailPayCODText:SetText('Pay CODs');
OpenMailPayCOD:SetScript('OnClick', MG_ToggleCOD);
OpenMailPayCOD:SetScript('OnShow', MG_ShowCOD);
OpenMailPayCOD:SetScale(.75);

