﻿//

function PopulateRecentSales()
{
    document.getElementById("RecentSalesList").innerHTML = "<li><img src=\"" + ControlPath() + "images/busy.gif\" alt=\"Loading...\" /></li>";
    jQuery.getJSON(baseWSurl() + "?o=recent", DisplayRecentSales);
}

function DisplayRecentSales(jsonPlates, status)
{
if (status == 'success')
    {  
    var plates = eval(jsonPlates);
    var RecentHTML = "";
    var plate;
    
    for (i = 0; i < plates.length; i++) {
        plate = plates[i];
        
        RecentHTML += "<div style='height:65px; text-align:center;'>";
        RecentHTML += "<a href='#' style='text-decoration:none;' onclick='selectRecentSaleDesign(" + plate.BackgroundId + "," + plate.ForegroundId + "," + plate.CategoryId + "); return false;'>";
        RecentHTML += "<img alt='" + plate.Description + "' src='";
        RecentHTML += plateImageURL('', plate.BackgroundId, plate.ForegroundId, plate.CategoryId, plate.PlateSizeId, true);
        RecentHTML += "'><br>"
        RecentHTML += "<span style='font-style: italic; font-size: 11px; display: block; height: 15px; overflow: hidden;'>" + plate.Description + "</span>";
        RecentHTML += "</div>";
        }

    document.getElementById("RecentSalesList").innerHTML = RecentHTML;
    }
}
 
function selectRecentSaleDesign(backgroundid, foregroundid, categoryid)
{
    jQuery.getJSON(baseWSurl() + "?o=di&category=" + categoryid + "&bi=" + backgroundid + "&fi=" + foregroundid, WorkedOutCode);
}

function WorkedOutCode(jsonCodes, status)
{
if (status == 'success')
    {
    var Code = eval(jsonCodes);
    var OkToProceed = false;
        
    if (currentCombination == '')
        OkToProceed = true;

    // check if current combo then it checks suitability
    if ((currentCombination != '') && !ComboFormatCompatible(Code.SuitsFormat, currentCombination)) {
        var Answer = confirm(msgConfirmOverwriteCombination);
        
        if (Answer == true) {
            OkToProceed = true;
            currentCombination = "";
            SetCombo("");
            WhatHotUpdateCombination("");
            }
        }
    else
        OkToProceed = true;
        
    if (Code.DesignName != "" && OkToProceed) {
        DontOverwritebackground = true;
        selectedTab='design';
        ShowTabsBar();
        panelMode_PlateDesign();
        selectedCategoryId = Code.SelectedCategoryId;
        SelectPlateCategory(Code.PlateCategoryId, this, Code.SuitsFormat, Code.Msg);
        SelectDesign(Code.BackgroundId, Code.ForegroundId, Code.DesignCategoryId, Code.HasSeparator, Code.Name, Code.PriceName, Code.Sizes, Code.SizesWith, Code.SizesWithout);

        ShowBusy();
        jQuery.getJSON(baseWSurl() + "?o=tabs&c=" + currentCombination, DisplayTabs);
        }
    }
}
