Subversion Repositories munaweb

Rev

Rev 163 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<!DOCTYPE html>
<html lang="en">

<head>
    <title>Export eBay Listings to Shopify</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
    <link rel="icon" href="favicon.ico" type="image/x-icon">

    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
    <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <script src="js/XMLWriter.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/lodash@4.17.11/lodash.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.23.0/moment.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.23/moment-timezone-with-data-2012-2022.min.js"></script>
    <link rel="stylesheet" href="css/tablesorter.theme.blue.css">
    <script src="js/jquery.tablesorter.min.js"></script>
    <script src="js/jquery.tablesorter.widgets.js"></script>
    <script src="js/jquery.parser-input-select.js"></script>
    <link rel="stylesheet" href="css/style.css">
    <script src="js/muna-tools.js"></script>
    <script src="js/stopcock.js"></script>
</head>

<body onload="return initConfig();">
    <div>
        <div>
            <div class="container-fluid bg-secondary">
                <div class="clearfix">
                    <img class="img-fluid float-right" src="images/MUNA%20-%20Logo%20100x100.png" alt="MUNA Trading Logo" />
                    <h1 id="connected">Export eBay Listings to Shopify
                    <input id="login" type="button" class="btn bg-success mb-2 w3-hide" onclick="eBayLogin();" value="Login" /></h1>
                </div>
            </div>

            <div class="col border">
                <div>
                    <form id="searchForm" class="container-fluid bg-light" onsubmit="return getListings();">
                        <div id="form1div" class="w3-hide">
                            <div class="form-check">
                                <label for="completedList">
                                    <input id="completedList" class="form-check-input" type="radio" name="rptType" value="completedList" checked>Completed Listings
                                </label>
                            </div>
                            <div class="form-check">
                                <label for="liveList">
                                    <input id="liveList" class="form-check-input" type="radio" name="rptType" value="liveList" checked>Live Listings
                                </label>
                            </div>
                            <input id="startButton" type="button" class="btn btn-danger" onclick="getListings();" value="Start" />
                        </div>
                        <div id="form2div" class="w3-hide">
                            <input id="downloadButton" type="button" class="btn btn-dark" onclick="downloadListings()" value="Download CSV" />
                        </div>
                    </form>
                </div>
                <div class="modal" id="progressBarDiv">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h4 id="progressBarHeader"></h4>
                            </div>
                            <div class="modal-body">
                                <div class="progress">
                                    <div id="progressBar" class="progress-bar" style="width:0%">0%</div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div id="results" class="border bg-info w3-hide"></div>
                <div id="csv" class="w3-hide"></div>
                <div id="logging"></div>
            </div>
        </div>

        <footer class="container-fluid text-center border border-bottom-0 border-left-0 border-right-0">
            <div w3-include-html="php/footer.php"></div>
        </footer>

    </div>

    <script>

// Globals
var tableName = 'exportTable';
var tableSorterName = 'selectTable';
var liveListing;
var maxPagesToProcess = 0;
var pagesToProcess = 0;
var pagesProcessed = 0;
var maxNotesToAdd = 0;
var notesToAdd = 0;
var notesAdded = 0;
var listingsToFill = 0;
var maxListingsToFill = 0;
var listingsFilled = 0;
var listingsToFind = 0;
var maxListingsToFind = 0;
var listingsFound = 0;
var html = [];

// Initialize Configuration Variables
function initConfig() {
    var x = document.getElementById("form1div");
    if (x.className.indexOf("w3-show") == -1) {
        x.className += " w3-show";
    }

    eBayAuthToken = readCookie();
    if (eBayAuthToken.length > 0) {
        connected();
    }

    if (eBayAuthTokenFlag === false) {
        x = document.getElementById("login");
        if (x.className.indexOf("w3-show") == -1) {
            x.className += " w3-show";
        }
    }
}

function connected() {
    var x;

    eBayAuthTokenFlag = true;
    document.getElementById("connected").innerHTML += " (Connected)";

    x = document.getElementById("startButton");
    x.className = x.className.replace(" btn-danger", " btn-dark");

    x = document.getElementById("login");
    x.className = x.className.replace(" w3-show", "");

    x = document.getElementById("results");
    x.innerHTML = "";
    x.className = x.className.replace(" w3-show", "");
    x.className = x.className.replace(" process-errors", "");
}

function requireNewLogin() {
    var x = document.getElementById("startButton");
    x.className = x.className.replace(" btn-dark", " btn-danger ");
}

function downloadListings() {
    var noteList = [];
    var table = document.getElementById(tableSorterName);

    maxPagesToProcess = 0;
    pagesToProcess = 0;
    pagesProcessed = 0;

    initProgressBar("Downloading Selected Items");

    var x = document.getElementById("results");
    x.innerHTML = '';
    x.className = x.className.replace("process-errors", "");
    if (x.className.indexOf("w3-show") == -1) {
        x.className += " w3-show";
    }
    x.innerHTML = '<p><strong>Downloading Listings...</strong></p>';

    document.getElementById("csv").innerHTML = '';

    tableStart();
    for (var i = 2; i < table.rows.length; i++) {
        if (table.rows[i].cells[0].children[0].checked) {
            ++maxPagesToProcess;
            ++pagesToProcess;
            noteList.push(table.rows[i].cells[3].innerHTML);
            eBaySearch(table.rows[i].cells[3].innerHTML, (table.rows[i].cells[13].innerHTML == 'Yes' ? true : false));

            table.deleteRow(i--);
        }
    }

    function checkpagesToProcess() {
        if (pagesToProcess > 0) {
            window.setTimeout(checkpagesToProcess, 100); // wait 100 milliseconds
        } else {
            tableEnd();
            tableSorterUpdateCounters(tableSorterName);
            endProgressBar();
            exportTableToCSV(tableName, 'import.csv', true);
            addNotes(noteList);
        }
    }

    checkpagesToProcess();
}

function addNotes(noteList) {
    var i, x;

    maxNotesToAdd = 0;
    notesToAdd = 0;
    notesAdded = 0;

    if (!liveListing) {
        initProgressBar('Adding Notes to Ended Listings');

        for (i = 0; i < noteList.length; i++) {
            ++maxNotesToAdd;
            ++notesToAdd;
            addNote(noteList[i]);
        }
    }

    function checkNotesToAdd() {
        if (notesToAdd > 0) {
            window.setTimeout(checkNotesToAdd, 100); // wait 100 milliseconds
        } else {
            endProgressBar();

            x = document.getElementById("results");
            x.innerHTML += '<p><strong>Report Finished!</strong></p>';
            if (!x.className.includes("process-errors")) {
                setTimeout(function() {
                    x.className = x.className.replace(" w3-show", "");
                }, 3000);
            }
        }
    }

    checkNotesToAdd();
}

function tableStart() {
    document.getElementById("csv").innerHTML = '';
    html = [];

    html.push('<h3>Shopify Import</h3>');
    html.push('<div class="border table-responsive">');
    html.push('<table id="' + tableName + '">');
    html.push('<thead>');
    html.push('<tr>');

    html.push(tableHeader('Handle'));
    html.push(tableHeader('Title'));
    html.push(tableHeader('Body (HTML)'));
    html.push(tableHeader('Vendor'));
    html.push(tableHeader('Type'));
    html.push(tableHeader('Tags'));
    html.push(tableHeader('Published'));
    html.push(tableHeader('Option1 Name'));
    html.push(tableHeader('Option1 Value'));
    html.push(tableHeader('Option2 Name'));
    html.push(tableHeader('Option2 Value'));
    html.push(tableHeader('Option3 Name'));
    html.push(tableHeader('Option3 Value'));
    html.push(tableHeader('Variant SKU'));
    html.push(tableHeader('Variant Grams'));
    html.push(tableHeader('Variant Inventory Tracker'));
    html.push(tableHeader('Variant Inventory Qty'));
    html.push(tableHeader('Variant Inventory Policy'));
    html.push(tableHeader('Variant Fulfillment Service'));
    html.push(tableHeader('Variant Price'));
    html.push(tableHeader('Variant Compare At Price'));
    html.push(tableHeader('Variant Requires Shipping'));
    html.push(tableHeader('Variant Taxable'));
    html.push(tableHeader('Variant Barcode'));
    html.push(tableHeader('Image Src'));
    html.push(tableHeader('Image Position'));
    html.push(tableHeader('Image Alt Text'));
    html.push(tableHeader('Gift Card'));
    html.push(tableHeader('Google Shopping / MPN'));
    html.push(tableHeader('Google Shopping / Age Group'));
    html.push(tableHeader('Google Shopping / Gender'));
    html.push(tableHeader('Google Shopping / Google Product Category'));
    html.push(tableHeader('SEO Title'));
    html.push(tableHeader('SEO Description'));
    html.push(tableHeader('Google Shopping / AdWords Grouping'));
    html.push(tableHeader('Google Shopping / AdWords Labels'));
    html.push(tableHeader('Google Shopping / Condition'));
    html.push(tableHeader('Google Shopping / Custom Product'));
    html.push(tableHeader('Google Shopping / Custom Label 0'));
    html.push(tableHeader('Google Shopping / Custom Label 1'));
    html.push(tableHeader('Google Shopping / Custom Label 2'));
    html.push(tableHeader('Google Shopping / Custom Label 3'));
    html.push(tableHeader('Google Shopping / Custom Label 4'));
    html.push(tableHeader('Variant Image'));
    html.push(tableHeader('Variant Weight Unit'));
    html.push(tableHeader('Variant Tax Code'));
    html.push(tableHeader('Cost per item'));

    html.push('</tr>');
    html.push('</thead>');
    html.push('<tbody>');
}

function tableEntry(JsonObj, onShopify) {
    var i, n, barcode, handle;
    var tags = [];
    var ConditionDescription = JsonObj.ConditionDescription;
    var ConditionID = JsonObj.ConditionID;
    var CurrentPrice = JsonObj.SellingStatus.CurrentPrice;
    var CurrentPriceValue = CurrentPrice === undefined ? 0.00 : Number(CurrentPrice.text);
    var price = CurrentPriceValue;
    var Description = JsonObj.Description;
    var userDescription;
    var ItemID = JsonObj.ItemID;
    var ItemSpecifics = JsonObj.ItemSpecifics;
    var PictureURL = getJsonArray(JsonObj.PictureDetails.PictureURL);
    var PrimaryCategoryName = JsonObj.PrimaryCategory.CategoryName;
    var Quantity = Number(JsonObj.Quantity);
    var QuantitySold = Number(JsonObj.SellingStatus.QuantitySold);
    var SKU = JsonObj.SKU;
    var ProductListingDetails = JsonObj.ProductListingDetails;
    var weightInGrams = 0;
    var categoryName = PrimaryCategoryName;
    var Title = JsonObj.Title;

    if (Number(ConditionID) === 1000) {
        tags.push("Condition: Brand New");
    } else {
        tags.push("Condition: Preowned");
    }

    n = (SKU === undefined ? 0 : SKU.indexOf(" - "));
    if (n > 0) {
        barcode = SKU.substr(n + 3);
        barcode = barcode.substr(barcode.indexOf(" ") + 1);
        handle = 'B' + barcode;
        barcode = '\'' + barcode;
        SKU = SKU.substr(0, n);
    } else {
        if (categoryName.indexOf("Books") != -1 && ProductListingDetails && ProductListingDetails.ISBN && isNumeric(ProductListingDetails.ISBN)) {
            barcode = '\'' + ProductListingDetails.ISBN;
            handle = 'B' + ProductListingDetails.ISBN;
        } else if (ProductListingDetails && ProductListingDetails.UPC && isNumeric(ProductListingDetails.UPC)) {
            barcode = '\'' + ProductListingDetails.UPC;
            handle = 'B' + ProductListingDetails.UPC;
        } else if (ProductListingDetails && ProductListingDetails.ProductReferenceID && isNumeric(ProductListingDetails.ProductReferenceID)) {
            barcode = 'R' + ProductListingDetails.ProductReferenceID;
            handle = barcode;
        } else {
            barcode = 'H' + Title.hashCode();
            handle = barcode;
        }
    }

    userDescription = extractDescription(Description);
    if (ItemSpecifics && ItemSpecifics.NameValueList && PrimaryCategoryName.indexOf('DVD') < 0) {
        userDescription += '<table><tbody>';
        for (i = 0; i < ItemSpecifics.NameValueList.length; i++) {
            var itemSpecific = ItemSpecifics.NameValueList[i];
            if (itemSpecific.Name != 'All returns accepted' &&
                itemSpecific.Name != 'Item must be returned within' &&
                itemSpecific.Name != 'Refund will be given as' &&
                itemSpecific.Name != 'Return policy details' &&
                itemSpecific.Name != 'Restocking Fee' &&
                itemSpecific.Name != 'Return shipping will be paid by') {
                userDescription += '<tr><td style="padding: 0;">' + itemSpecific.Name + ':</td><td style="padding: 0;">' + itemSpecific.Value + '</td></tr>';
            }
        }
        userDescription += '</tbody></table>';
    }

    if (ConditionDescription &&
        (userDescription.indexOf('Please view all actual images.') < 0 && userDescription.indexOf('mint condition') < 0)) {
        userDescription += '<p>' + ConditionDescription + '</p>';
    }

    if (categoryName.indexOf("CDs") != -1) {
        categoryName = 'Music CDs';
        price = 5.45;
    } else if (categoryName.indexOf("Movies") != -1) {
        categoryName = 'Movies';
        price = 5.45;
    } else if (categoryName.indexOf("Books") != -1) {
        categoryName = 'Books';
        price = 5.95;
    } else if (categoryName.indexOf("Trading Cards") != -1) {
        if (categoryName.indexOf("Baseball") != -1) {
            tags.push('Trading Cards: Baseball');
        } else if (categoryName.indexOf("Football") != -1) {
            tags.push('Trading Cards: Football');
        } else if (categoryName.indexOf("Basketball") != -1) {
            tags.push('Trading Cards: Basketball');
        } else if (categoryName.indexOf("Soccer") != -1) {
            tags.push('Trading Cards: Soccer');
        } else if (categoryName.indexOf("Ice Hockey") != -1) {
            tags.push('Trading Cards: Ice Hockey');
        } else if (categoryName.indexOf("Auto Racing") != -1) {
            tags.push('Trading Cards: Auto Racing');
        }
        categoryName = 'Trading Cards';
        price = 1.99;
    }
    tags.push(categoryName);

    if (liveListing) {
        tags.push('_eBay Live');

        price = round((CurrentPriceValue * 0.90), 1) + 0.05; // always end with 5
        if (categoryName.indexOf("CDs") != -1 && price < 5.45) {
            price = 5.45;
        } else if (categoryName.indexOf("Movies") != -1 && price < 5.45) {
            price = 5.45;
        } else if (categoryName.indexOf("Books") != -1 && price < 5.95) {
            price = 5.95;
        } else if (categoryName.indexOf("Trading Cards") != -1 && price < 1.99) {
            price = 1.99;
        }
    }

    if (JsonObj.ShippingPackageDetails !== undefined) {
        if (JsonObj.ShippingPackageDetails.WeightMajor !== undefined) {
            weightInGrams += (Number(JsonObj.ShippingPackageDetails.WeightMajor.text) * 453.5);
        }

        if (JsonObj.ShippingPackageDetails.WeightMinor !== undefined) {
            weightInGrams += (Number(JsonObj.ShippingPackageDetails.WeightMinor.text) * 28.3);
        }
    }

    html.push('<tr>');

    html.push(tableCell(handle));
    html.push(tableCell(Title));
    html.push(tableCell(escapeHtml(userDescription)));
    html.push(tableCell("MUNA Trading"));
    html.push(tableCell(categoryName));
    html.push(tableCell(tags.join(',')));
    html.push(tableCell("TRUE"));
    html.push(tableCell("Title"));
    html.push(tableCell("Default Title"));
    html.push(tableCell(""));
    html.push(tableCell(""));
    html.push(tableCell(""));
    html.push(tableCell(""));
    html.push(tableCell((SKU !== undefined ? SKU : "")));
    html.push(tableCell(Math.floor(weightInGrams)));
    html.push(tableCell("shopify"));
    html.push(tableCell((Quantity - QuantitySold)));
    html.push(tableCell("deny"));
    html.push(tableCell("manual"));
    html.push(tableCell(price));
    html.push(tableCell(""));
    html.push(tableCell("TRUE"));
    html.push(tableCell("TRUE"));
    html.push(tableCell(barcode));
    if (onShopify) {
        html.push(tableCell(""));
        html.push(tableCell(""));
        html.push(tableCell(""));
    } else {
        html.push(tableCell(PictureURL[0].substr(0, PictureURL[0].lastIndexOf('/') + 1) + '$_57.JPG'));
        html.push(tableCell(1));
        html.push(tableCell(Title + " Image 1"));
    }
    html.push(tableCell("FALSE"));
    html.push(tableCell(""));
    html.push(tableCell(""));
    html.push(tableCell(""));
    html.push(tableCell(""));
    html.push(tableCell(""));
    html.push(tableCell(""));
    html.push(tableCell(""));
    html.push(tableCell(""));
    html.push(tableCell(""));
    html.push(tableCell(""));
    html.push(tableCell(""));
    html.push(tableCell(""));
    html.push(tableCell(""));
    html.push(tableCell(""));
    html.push(tableCell(""));
    html.push(tableCell(""));
    html.push(tableCell("oz"));
    html.push(tableCell(""));
    html.push(tableCell(""));

    html.push('</tr>');

    if (!onShopify) {
        for (i = 1; i < PictureURL.length; i++) {
            html.push('<tr>');

            html.push(tableCell(handle));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(PictureURL[i].substr(0, PictureURL[i].lastIndexOf('/') + 1) + '$_57.JPG'));
            html.push(tableCell(i + 1));
            html.push(tableCell(Title + " Image " + (i + 1)));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));
            html.push(tableCell(""));

            html.push('</tr>');
        }
    }
}

function extractDescription(str) {
    var startText = "<!-- *************** Place description here ****************** -->";
    var startPos = str.indexOf(startText) + startText.length;
    var endPos = str.lastIndexOf("<!-- *************** Place description here ****************** -->");
    var userDescription = str.substr(startPos, endPos - startPos);
    var parser = new DOMParser();
    var htmlDoc = parser.parseFromString(userDescription, "text/html");

    return ((htmlDoc.getElementsByTagName('div')[0] !== undefined ? htmlDoc.getElementsByTagName('div')[0].innerHTML : userDescription));
}

function tableEnd() {
    html.push('</tbody>');
    html.push('</table>');
    html.push('</div>');

    document.getElementById("csv").innerHTML = html.join('');
}

function addNote(itemId) {
    var i;
    var xml;

    var xw = new XMLWriter('UTF-8', '1.0');
    var xhr = new XMLHttpRequest();

    if (!createAddXMLNote(xw, xhr, 'SetUserNotesRequest', 'SetUserNotes', itemId)) {
        return;
    }

    xml = xw.flush();
    xw.close();

    xhr.onload = function() {
        var jsonObj = XMLparse(xhr.responseXML, false);
        var obj = jsonObj.SetUserNotesResponse;
        var returnCode = obj.Ack;
        var str;

        var x = document.getElementById("results");
        if (x.className.indexOf("w3-show") == -1) {
            x.className += " w3-show";
        }

        if (returnCode == 'Success' || (returnCode == 'Warning' && obj.Errors.ErrorCode == '21917108')) {
            str = '<p>' + itemId + ': <strong>' + returnCode + '</strong></p>';

            if (returnCode == 'Warning') {
                str += "<p>" + obj.Errors.SeverityCode + " (" + obj.Errors.ErrorCode + "): " + escapeHtml(obj.Errors.LongMessage) + "</p>";
            }
            
            x.innerHTML += str;
        } else {
            x.className += " process-errors";
            str = '<p class="text-danger">' + itemId + ': <strong>' + returnCode + ':</strong></p>';

            var errors = getJsonArray(obj.Errors);
            str += "<p>";
            for (i = 0; i < errors.length; i++) {
                str += errors[i].SeverityCode + " (" + errors[i].ErrorCode + "): " + escapeHtml(errors[i].LongMessage) + "<br/>";
            }
            str += "</p>";
            
            x.innerHTML += str;
        }

        if (obj.Message) {
            x.innerHTML += obj.Message;
        }

        --notesToAdd;
        ++notesAdded;

        updateProgressBar(maxNotesToAdd, notesAdded);
    };

    xhr.send(xml);
}

function createAddXMLNote(xw, xhr, xmlrequest, callname, itemId) {
    var today = new Date();
    var todayYYYYMMDD = today.toISOString().slice(0, 10);

    xw.writeStartDocument();
    xw.writeStartElement(xmlrequest);
    xw.writeAttributeString('xmlns', 'urn:ebay:apis:eBLBaseComponents');

    xw.writeStartElement('RequesterCredentials');
    xw.writeElementString('eBayAuthToken', eBayAuthToken);
    xw.writeEndElement(); /* RequesterCredentials */

    xw.writeElementString('ItemID', itemId);
    xw.writeElementString('Action', 'AddOrUpdate');
    xw.writeElementString('NoteText', 'Exported to Shopify on ' + todayYYYYMMDD);

    xw.writeElementString('ErrorLanguage', 'en_US');
    xw.writeElementString('Version', configeBayTradingVersion);
    xw.writeElementString('WarningLevel', configWarningLevel);

    xw.writeEndElement(); /* xmlrequest */
    xw.writeEndDocument();

    xhr.open('POST', configProxyUrl, true);
    xhr.setRequestHeader('Content-Type', 'text/xml');
    xhr.setRequestHeader('X-EBAY-API-APP-NAME', configAppid);
    xhr.setRequestHeader('X-EBAY-API-COMPATIBILITY-LEVEL', configeBayTradingVersion);
    xhr.setRequestHeader('X-EBAY-API-CALL-NAME', callname);
    xhr.setRequestHeader('X-EBAY-API-SITEID', '0');
    xhr.setRequestHeader('X-EBAY-API-DEV-NAME', '');
    xhr.setRequestHeader('X-EBAY-API-CERT-NAME', '');
    xhr.setRequestHeader('X-Proxy-URL', configServiceEndpoint);

    return true;
}

function eBaySearch(itemId, onShopify) {
    var i;
    var xml;

    var xw = new XMLWriter('UTF-8', '1.0');
    var xhr = new XMLHttpRequest();

    if (!createAddXMLSearch(xw, xhr, 'GetItemRequest', 'GetItem', itemId)) {
        return;
    }

    xml = xw.flush();
    xw.close();

    xhr.onload = function() {
        var returnCode;
        var str;
        var jsonObj = XMLparse(xhr.responseXML, false);
        var obj = jsonObj.GetItemResponse;

        if (obj === undefined) {
            returncode = 'Response undefined';
        } else {
            returnCode = obj.Ack;
        }

        var x = document.getElementById("results");
        if (x.className.indexOf("w3-show") == -1) {
            x.className += " w3-show";
        }

        if (returnCode == 'Success') {
            tableEntry(obj.Item, onShopify);
        } else {
            x.className += " process-errors";
            str = '<p class="text-danger">' + itemId + ': <strong>' + returnCode + ':</strong></p>';

            var errors = getJsonArray(obj.Errors);
            str += "<p>";
            for (i = 0; i < errors.length; i++) {
                str += errors[i].SeverityCode + " (" + errors[i].ErrorCode + "): " + escapeHtml(errors[i].LongMessage) + "<br/>";
            }
            str += "</p>";

            x.innerHTML += str;
        }

        --pagesToProcess;
        ++pagesProcessed;

        updateProgressBar(maxPagesToProcess, pagesProcessed);
    };

    xhr.send(xml);
}

function createAddXMLSearch(xw, xhr, xmlrequest, callname, itemId) {

    xw.writeStartDocument();
    xw.writeStartElement(xmlrequest);
    xw.writeAttributeString('xmlns', 'urn:ebay:apis:eBLBaseComponents');

    xw.writeStartElement('RequesterCredentials');
    xw.writeElementString('eBayAuthToken', eBayAuthToken);
    xw.writeEndElement(); /* RequesterCredentials */

    xw.writeElementString('ItemID', itemId);
    xw.writeElementString('IncludeItemSpecifics', 'true');
    xw.writeElementString('DetailLevel', 'ReturnAll');

    xw.writeElementString('ErrorLanguage', 'en_US');
    xw.writeElementString('Version', configeBayTradingVersion);
    xw.writeElementString('WarningLevel', configWarningLevel);

    xw.writeEndElement(); /* xmlrequest */
    xw.writeEndDocument();

    xhr.open('POST', configProxyUrl, true);
    xhr.setRequestHeader('Content-Type', 'text/xml');
    xhr.setRequestHeader('X-EBAY-API-APP-NAME', configAppid);
    xhr.setRequestHeader('X-EBAY-API-COMPATIBILITY-LEVEL', configeBayTradingVersion);
    xhr.setRequestHeader('X-EBAY-API-CALL-NAME', callname);
    xhr.setRequestHeader('X-EBAY-API-SITEID', '0');
    xhr.setRequestHeader('X-EBAY-API-DEV-NAME', '');
    xhr.setRequestHeader('X-EBAY-API-CERT-NAME', '');
    xhr.setRequestHeader('X-Proxy-URL', configServiceEndpoint);

    return true;
}

function getListings() {
    var x;

    if (eBayAuthTokenFlag === false) {
        return;
    }

    document.getElementById("logging").innerHTML = '';

    x = document.getElementById("results");
    if (x.className.indexOf("w3-show") == -1) {
        x.className += " w3-show";
    }
    x.className = x.className.replace("process-errors", "");
    x.innerHTML = '<p><strong>Retrieving Listings...</strong></p>';

    initProgressBar('Getting Items for Export (Step 1/3)');

    liveListing = (getRadioValue('rptType') == 'liveList');
    tableSorterStart();
    maxPagesToProcess = 1;
    pagesToProcess = 1;
    pagesProcessed = 0;
    eBaySorterSearch(1);

    function checkpagesToProcess() {
        if (pagesToProcess > 0) {
            window.setTimeout(checkpagesToProcess, 100); // wait 100 milliseconds
        } else {
            tableSorterEnd();
            endProgressBar();
            // fillSorterListings(); is now in tableSorterEnd()
        }
    }

    checkpagesToProcess();
}

function tableSorterStart() {
    document.getElementById("logging").innerHTML = '';
    html = [];

    html.push('<h3>Items for Export</h3>');
    html.push('<p>Showing <span id="filtered-rows">0</span> of <span id="total-rows">0</span> / <span id="selected-rows">0</span> selected.</p>');
    html.push('<div class="border table-responsive">');
    html.push('<table id="' + tableSorterName + '" class="tablesorter">');
    html.push('<thead>');
    html.push('<tr>');

    html.push(tableHeaderCheckbox());
    html.push(tableHeader('Image'));
    html.push(tableHeader('Title'));
    html.push(tableHeader('Item Id'));
    html.push(tableHeader('SKU'));
    html.push(tableHeader('Category'));
    html.push(tableHeader('Format'));
    html.push(tableHeader('Price'));
    html.push(tableHeader('Quantity'));
    html.push(tableHeader('Views'));
    html.push(tableHeader('Watchers'));
    html.push(tableHeader(liveListing ? 'Start Date' : 'End Date'));
    html.push(tableHeader('Note'));
    html.push(tableHeader('Shopify'));

    html.push('</tr>');
    html.push('</thead>');
    html.push('<tbody>');
}

function tableSorterEntry(JsonObj) {
    var i;
    var image;
    var title;
    var itemId;
    var sku;
    var format;
    var price;
    var quantity;
    var views;
    var watchers;
    var listingDate;
    var privateNote;
    var ebayNote;
    var relisted;
    var bidCount;

    for (i = 0; i < JsonObj.length; i++) {
        image = getJsonValue(JsonObj[i].PictureDetails.GalleryURL).replace('http:', 'https:');
        title = getJsonValue(JsonObj[i].Title);
        itemId = getJsonValue(JsonObj[i].ItemID);
        sku = getJsonValue(JsonObj[i].SKU);
        format = getJsonValue(JsonObj[i].ListingType);
        bidCount = (typeof(JsonObj[i].SellingStatus) === 'object' ? Number(getJsonValue(JsonObj[i].SellingStatus.BidCount)) : 0);
        if (format == 'Chinese') {
            format = 'Auction';
            price = getJsonValue(JsonObj[i].StartPrice.text);
        } else {
            format = 'Fixed Price';
            price = getJsonValue(JsonObj[i].BuyItNowPrice.text);
        }
        quantity = getJsonValue(JsonObj[i].QuantityAvailable);
        views = '';
        watchers = Number(getJsonValue(JsonObj[i].WatchCount));
        listingDate = getJsonValue((liveListing ? JsonObj[i].ListingDetails.StartTime : JsonObj[i].ListingDetails.EndTime)).substr(0, 10);
        privateNote = getJsonValue(JsonObj[i].PrivateNotes);
        ebayNote = getJsonValue(JsonObj[i].eBayNotes);
        relisted = getJsonValue(JsonObj[i].Relisted);

        if (!liveListing) {
            if (privateNote.startsWith("Exported to ") || relisted == 'true' || privateNote.startsWith("Sold via ") || privateNote.startsWith("Relisted As New Item")) {
                continue;
            }
        } else {
            if (bidCount > 0) {
                continue;
            }
        }
        
        if (Number(quantity) < 1) {
            continue;
        }

        html.push('<tr>');

        html.push(tableCellCheckbox());
        html.push(tableCell('<img class="img-fluid" src="' + image + '" alt="Gallery Image" style="max-height:100px;max-width:100px;">'));
        html.push(tableCell(title));
        html.push(tableCell(itemId));
        html.push(tableCell(sku));
        html.push(tableCellLabel('Category' + itemId));
        html.push(tableCell(format));
        html.push(tableCell('$' + price));
        html.push(tableCell(quantity));
        html.push(tableCellLabel('Views' + itemId));
        html.push(tableCell(watchers));
        html.push(tableCell(listingDate));
        html.push(tableCell(privateNote + ' ' + ebayNote));
        html.push(tableCellLabel('Shopify' + itemId));

        html.push('</tr>');
    }
}

function tableSorterEnd() {
    html.push('</tbody>');
    html.push('</table>');
    html.push('</div>');

    document.getElementById("logging").innerHTML = html.join('');

    $(function() {
        $("#" + tableSorterName).on('tablesorter-initialized', function() {

            // class name to add on tr when checkbox is checked
            var highlightClass = 'checked',
                // resort the table after the checkbox is modified?
                resort = true,
                $table = $(this),
                c = this.config,
                wo = c && c.widgetOptions,
                // include sticky header checkbox; if installed
                $sticky = c && wo.$sticky || '',
                doChecky = function(c, col) {
                    $table
                        .children('tbody')
                        .children('tr:visible')
                        .children('td:nth-child( ' + (parseInt(col, 10) + 1) + ' )')
                        .find('input[type=checkbox]')
                        .each(function() {
                            this.checked = c;
                            $(this).trigger('change');
                        });
                };

            $table
                .children('tbody')
                .on('change', 'input[type=checkbox]', function() {
                    // ignore change if updating all rows
                    if ($table[0].ignoreChange) {
                        return;
                    }
                    var $this = $(this);
                    $this.closest('tr').toggleClass(highlightClass, this.checked);
                    // resort will jump bqack to the top
                    // $this.trigger('updateCell', [$this.closest('td'), resort]);

                    // handle header
                    var rowCount = $('#' + tableSorterName + ' tbody tr').length;
                    var checkedCount = $('#' + tableSorterName + ' tbody .checked').length;
                    var ua = window.navigator.userAgent;
                    if (checkedCount === 0) {
                        $table.add($sticky).find('thead input[type=checkbox]').prop('checked', false);
                        $table.add($sticky).find('thead input[type=checkbox]').prop('indeterminate', false);
                    } else if (checkedCount === rowCount) {
                        $table.add($sticky).find('thead input[type=checkbox]').prop('checked', true);
                        $table.add($sticky).find('thead input[type=checkbox]').prop('indeterminate', false);
                    } else {
                        $table.add($sticky).find('thead input[type=checkbox]').prop('checked', !(ua.indexOf('Trident/') > -1 || ua.indexOf('Edge/') > -1));
                        $table.add($sticky).find('thead input[type=checkbox]').prop('indeterminate', true);
                    }
                    $('#selected-rows').html(checkedCount);
                })
                .end()
                .add($sticky)
                .find('thead input[type=checkbox]')
                // Click on checkbox in table header to toggle all inputs
                .on('change', function() {
                    // prevent updateCell for every cell
                    $table[0].ignoreChange = true;
                    var c = this.checked,
                        col = $(this).closest('th').attr('data-column');
                    doChecky(c, col);
                    // update main & sticky header

                    $table.children('tbody').children('tr:visible').toggleClass(highlightClass, c);
                    // update all at once
                    $table[0].ignoreChange = false;
                    $table.trigger('update', [resort]);

                    // handle header
                    var rowCount = $('#' + tableSorterName + ' tbody tr').length;
                    var checkedCount = $('#' + tableSorterName + ' tbody .checked').length;
                    var ua = window.navigator.userAgent;
                    if (checkedCount === 0) {
                        $table.add($sticky).find('th[data-column=' + col + '] input[type=checkbox]').prop('checked', false);
                        $table.add($sticky).find('th[data-column=' + col + '] input[type=checkbox]').prop('indeterminate', false);
                    } else if (checkedCount === rowCount) {
                        $table.add($sticky).find('th[data-column=' + col + '] input[type=checkbox]').prop('checked', true);
                        $table.add($sticky).find('th[data-column=' + col + '] input[type=checkbox]').prop('indeterminate', false);
                    } else {
                        $table.add($sticky).find('th[data-column=' + col + '] input[type=checkbox]').prop('checked', !(ua.indexOf('Trident/') > -1 || ua.indexOf('Edge/') > -1));
                        $table.add($sticky).find('th[data-column=' + col + '] input[type=checkbox]').prop('indeterminate', true);
                    }
                    $('#selected-rows').html(checkedCount);
                })
                .on('mouseup', function() {
                    return false;
                });

        });

        $("#" + tableSorterName).tablesorter({
            theme: "blue",
            widgets: ["zebra", "stickyHeaders", "filter"],
            headers: {
                0: {
                    sorter: "checkbox"
                },
                1: {
                    sorter: false,
                    filter: false
                }
            },
            initialized: function() {
                fillSorterListings();
            }
        });

        $("#" + tableSorterName).bind('filterInit filterEnd', function(event, data) {
            $('#filtered-rows').html(data.filteredRows);
            $('#total-rows').html(data.totalRows);
        });
    });
}

function eBaySorterSearch(pageNo) {
    var i;
    var xml;

    var xw = new XMLWriter('UTF-8', '1.0');
    var xhr = new XMLHttpRequest();

    if (!createSorterAddXMLSearch(xw, xhr, 'GetMyeBaySelling', pageNo)) {
        return;
    }

    xml = xw.flush();
    xw.close();

    xhr.onload = function() {
        var jsonObj = XMLparse(xhr.responseXML, false);
        var obj = jsonObj.GetMyeBaySellingResponse;
        var returnCode = obj.Ack;
        var str;

        var objArray = (liveListing ? obj.ActiveList : obj.UnsoldList);

        var x = document.getElementById("results");

        if (returnCode == 'Success') {
            tableSorterEntry(objArray.ItemArray.Item);

            if (Number(objArray.PaginationResult.TotalNumberOfPages) > pageNo) {
                maxPagesToProcess = Number(objArray.PaginationResult.TotalNumberOfPages);
                ++pagesToProcess;
                eBaySorterSearch(pageNo + 1);
            }

            updateProgressBar(maxPagesToProcess, pagesProcessed);
        } else {
            x.className += " process-errors";
            str = '<p class="text-danger">' + obj.CorrelationID + ': <strong>' + returnCode + ':</strong></p>';
            var errors = getJsonArray(obj.Errors);
            str += "<p>";
            for (i = 0; i < errors.length; i++) {
                str += errors[i].SeverityCode + " (" + errors[i].ErrorCode + "): " + escapeHtml(errors[i].LongMessage) + "<br/>";
            }
            str += "</p>";

            x.innerHTML += str;
        }

        --pagesToProcess;
        ++pagesProcessed;

        updateProgressBar(maxPagesToProcess, pagesProcessed);
    };

    xhr.send(xml);
}

function createSorterAddXMLSearch(xw, xhr, callname, pageNo) {
    var outputSelector;
    
    xw.writeStartDocument();
    xw.writeStartElement(callname + "Request");
    xw.writeAttributeString('xmlns', 'urn:ebay:apis:eBLBaseComponents');

    xw.writeStartElement('RequesterCredentials');
    xw.writeElementString('eBayAuthToken', eBayAuthToken);
    xw.writeEndElement(); /* RequesterCredentials */

    xw.writeElementString('DetailLevel', 'ReturnAll');
    xw.writeStartElement('DeletedFromSoldList');
    xw.writeElementString('Include', 'false');
    xw.writeEndElement(); /* DeletedFromSoldList */
    xw.writeStartElement('DeletedFromUnsoldList');
    xw.writeElementString('Include', 'false');
    xw.writeEndElement(); /* DeletedFromUnsoldList */
    xw.writeStartElement('ScheduledList');
    xw.writeElementString('Include', 'false');
    xw.writeEndElement(); /* ScheduledList */
    xw.writeStartElement('SellingSummary');
    xw.writeElementString('Include', 'false');
    xw.writeEndElement(); /* SellingSummary */
    xw.writeStartElement('SoldList');
    xw.writeElementString('Include', 'false');
    xw.writeEndElement(); /* SoldList */

    xw.writeStartElement(liveListing ? 'UnsoldList' : 'ActiveList');
    xw.writeElementString('Include', 'false');
    xw.writeEndElement(); /* ActiveList */

    xw.writeStartElement(liveListing ? 'ActiveList' : 'UnsoldList');
    xw.writeElementString('Include', 'true');
    xw.writeElementString('IncludeNotes', 'true');
    xw.writeStartElement('Pagination');
    xw.writeElementString('EntriesPerPage', '200');
    xw.writeElementString('PageNumber', '' + pageNo);
    xw.writeEndElement(); /* Pagination*/
    xw.writeEndElement(); /* UnsoldList> */

    outputSelector = liveListing ? 'ActiveList.' : 'UnsoldList.';

    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.SellingStatus.BidCount');
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.BuyItNowPrice');
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.eBayNotes');
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.ItemID');
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.ListingDetails.' + (liveListing ? 'StartTime' : 'EndTime'));
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.ListingType');
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.PrivateNotes');
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.QuantityAvailable');
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.PictureDetails');
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.Relisted');
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.SKU');
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.Title');
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.StartPrice');
    xw.writeElementString('OutputSelector', outputSelector + 'ItemArray.Item.WatchCount');
    xw.writeElementString('OutputSelector', outputSelector + 'PaginationResult');

    xw.writeElementString('ErrorLanguage', 'en_US');
    xw.writeElementString('Version', configeBayTradingVersion);
    xw.writeElementString('WarningLevel', configWarningLevel);

    xw.writeEndElement(); /* xmlrequest */
    xw.writeEndDocument();

    xhr.open('POST', configProxyUrl, true);
    xhr.setRequestHeader('Content-Type', 'text/xml');
    xhr.setRequestHeader('X-EBAY-API-APP-NAME', configAppid);
    xhr.setRequestHeader('X-EBAY-API-COMPATIBILITY-LEVEL', configeBayTradingVersion);
    xhr.setRequestHeader('X-EBAY-API-CALL-NAME', callname);
    xhr.setRequestHeader('X-EBAY-API-SITEID', '0');
    xhr.setRequestHeader('X-EBAY-API-DEV-NAME', '');
    xhr.setRequestHeader('X-EBAY-API-CERT-NAME', '');
    xhr.setRequestHeader('X-Proxy-URL', configServiceEndpoint);

    return true;
}

function fillSorterListings() {
    var i;
    var x = document.getElementById(tableSorterName);
    var fillList = [];
    var maxItems = 20;

    listingsToFill = 0;
    maxListingsToFill = 0;
    listingsFilled = 0;

    initProgressBar('Filling Listing Information (Step 2/3)');

    for (i = 2; i < x.rows.length; i++) {
        fillList.push(x.rows[i].cells[3].innerHTML);
    }

    for (i = 0; (i * maxItems) < fillList.length; i++) {
        ++listingsToFill;
        ++maxListingsToFill;
        fillSorterListing(fillList.slice(i * maxItems, (i + 1) * maxItems));
    }

    function checkListingsToFill() {
        if (listingsToFill > 0) {
            window.setTimeout(checkListingsToFill, 100); // wait 100 milliseconds
        } else {
            $("#" + tableSorterName).trigger("update");

            endProgressBar();
            findOnShopify();
        }
    }

    checkListingsToFill();
}

function findOnShopify() {
    var i;
    var x = document.getElementById(tableSorterName);

    listingsToFind = 0;
    maxListingsToFind = 0;
    listingsFound = 0;

    initProgressBar('Finding Listings already on Shopify (Step 3/3)');

    for (i = 2; i < x.rows.length; i++) {
        ++listingsToFind;
        ++maxListingsToFind;
        findShopifyListing(x.rows[i].cells[3].innerHTML, x.rows[i].cells[2].innerText).then(function(env) {
                    --listingsToFind;
            ++listingsFound;
            updateProgressBar(maxListingsToFind, listingsFound);
        }); 
    }

    function checkListingsToFind() {
        if (listingsToFind > 0) {
            window.setTimeout(checkListingsToFind, 100); // wait 100 milliseconds
        } else {
            $("#" + tableSorterName).trigger("update");

            endProgressBar();

            x = document.getElementById("form1div");
            x.className = x.className.replace(" w3-show", "");
            x = document.getElementById("form2div");
            x.className += " w3-show";

            x = document.getElementById("results");
            x.innerHTML += '<p><strong>Report Finished!</strong></p>';
            if (!x.className.includes("process-errors")) {
                setTimeout(function() {
                    x.className = x.className.replace(" w3-show", "");
                }, 3000);
            }
        }
    }

    checkListingsToFind();
}

const findShopifyListing = stopcock(function request(itemId, title) {
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function() {
                if (this.readyState == 4 && this.status == 200) {
                        var json = JSON.parse(this.responseText);
                        if (typeof(json.products) != 'undefined') {
                            var x = document.getElementById('Shopify' + itemId);
                            x.innerHTML = (json.products.length > 0 ? 'Yes' : 'No');
                        }
                        
            return Promise.resolve(true);
                }
        };

    title = cleanTitleForShopifySearch(title);
    
        xhttp.open("GET", configProxyUrl, true);
        xhttp.setRequestHeader("X-Proxy-Url", configShopifyUrl + configShopifyProductsUrl + '?limit=1&title=' + title);
        xhttp.setRequestHeader("X-LEAVE-ENCODED", "1");
        xhttp.send();
});

function fillSorterListing(itemIdList) {
    var i;
    var xml;

    var xw = new XMLWriter('UTF-8', '1.0');
    var xhr = new XMLHttpRequest();

    if (!createSorterFillXMLSearch(xw, xhr, 'GetMultipleItems', itemIdList)) {
        return;
    }

    xml = xw.flush();
    xw.close();

    xhr.onload = function() {
        var jsonObj = XMLparse(xhr.responseXML, false);
        var obj = jsonObj.GetMultipleItemsResponse;
        var returnCode;
        var str;
        var x = document.getElementById("results");

        if (obj === undefined) {
            fillSorterListing(itemIdList);
            return;
        } else {
            returnCode = obj.Ack;
        }

        if (returnCode == 'Success') {
            for (i = 0; i < obj.Item.length; i++) {
                var itemId = getJsonValue(obj.Item[i].ItemID);
                document.getElementById("Views" + itemId).innerHTML = getJsonValue(obj.Item[i].HitCount);
                document.getElementById("Category" + itemId).innerHTML = getJsonValue(obj.Item[i].PrimaryCategoryName);
            }
        } else {
            x.className += " process-errors";
            str = '<p class="text-danger"><strong>' + returnCode + ':</strong></p>';

            var errors = getJsonArray(obj.Errors);
            str += "<p>";
            for (i = 0; i < errors.length; i++) {
                str += errors[i].SeverityCode + " (" + errors[i].ErrorCode + "): " + escapeHtml(errors[i].LongMessage) + "<br/>";
            }
            x.innerHTML += "</p>";
            
            x.innerHTML += str;
        }

        --listingsToFill;
        ++listingsFilled;
        updateProgressBar(maxListingsToFill, listingsFilled);
    };

    xhr.send(xml);
}

function createSorterFillXMLSearch(xw, xhr, callname, itemIdList) {
    var i;

    xw.writeStartDocument();
    xw.writeStartElement(callname + "Request");
    xw.writeAttributeString('xmlns', 'urn:ebay:apis:eBLBaseComponents');

    for (i = 0; i < itemIdList.length; i++) {
        xw.writeElementString('ItemID', itemIdList[i]);
    }

    xw.writeElementString('ErrorLanguage', 'en_US');
    xw.writeElementString('Version', configeBayShoppingVersion);
    xw.writeElementString('WarningLevel', configWarningLevel);

    xw.writeEndElement(); /* xmlrequest */
    xw.writeEndDocument();

    xhr.open('POST', configProxyUrl, true);
    xhr.setRequestHeader('Content-Type', 'text/xml');
    xhr.setRequestHeader('X-EBAY-API-APP-NAME', configAppid);
    xhr.setRequestHeader('X-EBAY-API-VERSION', configeBayShoppingVersion);
    xhr.setRequestHeader('X-EBAY-API-CALL-NAME', callname);
    xhr.setRequestHeader('X-EBAY-API-SITEID', '0');
    xhr.setRequestHeader('X-EBAY-API-DEV-NAME', '');
    xhr.setRequestHeader('X-EBAY-API-CERT-NAME', '');
    xhr.setRequestHeader('X-EBAY-API-REQUEST-ENCODING', 'XML');
    xhr.setRequestHeader('X-Proxy-URL', configeBayShopping);

    return true;
}

    </script>
    <script>includeHTML();</script> 

</body>
</html>