Subversion Repositories munaweb

Rev

Rev 6 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

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

<head>
    <title>eBay Quick Listing</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">

    <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato">
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="css/chosen.min.css">
    <script src="js/XMLWriter.js"></script>
    <script src="js/vkbeautify.js"></script>
    <script src="js/lodash.min.js"></script>
    <script src="js/XMLparse.js"></script>
    <script src="js/chart.js"></script>
    <script src="js/muna-tools.js"></script>
</head>

<body onload="return initConfig();" onbeforeunload="return confirmUnload();">
    <div class="w3-main">
        <div class="w3-container w3-padding w3-margin w3-card-4">
            <div class="w3-container w3-gray" style="height:100px">
                <img class="w3-image" src="images/MUNA%20-%20Logo%20100x100.png" alt="MUNA Trading Logo" style="height:100px">
                <p id="connected" class="w3-xxlarge w3-right">eBay Quick Listing
                    <input id="login" type="button" class="w3-btn w3-large w3-green w3-margin w3-round-large w3-ripple w3-right w3-hide" onclick="eBayLogin();" value="Login" />
                </p>
            </div>

            <div class="w3-row">
                <div class="w3-container w3-padding w3-half">
                    <div class="w3-container w3-card-2 w3-padding">
                        <form id="searchForm" class="w3-container w3-light-grey w3-padding w3-small" onsubmit="return findOneBay();">
                            <label for="keyword">Item:</label>
                            <select id="keyword" name="keyword" data-placeholder="Select Item..." class="chosen-select" style="height:3em;width:95%;" autofocus="autofocus" onchange="findOneBay();">
                                                        <option disabled="disabled"> </option>
                            </select>
                        </form>
                    </div>
                    <div class="w3-container w3-card-2 w3-padding">
                        <form id="listForm" class="w3-container w3-light-grey w3-padding w3-small" onchange="return requireNewVerify();">
                            <div>
                                <label for="category" class="keepTogether">Category:</label>
                                    <select id="category" name="category" data-placeholder="Select Category..." class="chosen-select" style="height:3em;width:25%;" onchange="return categoryValues();" onload="return categoryValues();">
                                                                        <option />
                                    <option value="29792">Audiobooks</option>
                                    <option value="29223">Books Antiquarian &amp; Collectible</option>
                                    <option value="182882">Books Children Young Adults</option>
                                    <option value="171228">Books Fiction Literature</option>
                                    <option value="171243">Books Nonfiction</option>
                                    <option value="268">Books Other</option>
                                    <option value="2228">Books Textbooks, Education</option>
                                    <option selected="selected" value="176984">CDs</option>
                                    <option value="617">DVDs Blu-ray Discs</option>
                                    <!--option value="666">Trading Cards Auto Racing</option-->
                                    <option value="213">Trading Cards Baseball</option>
                                    <option value="214">Trading Cards Basketball</option>
                                    <!--option value="133072">Trading Cards College</option-->
                                    <option value="215">Trading Cards Football</option>
                                    <!--option value="4240">Trading Cards Golf</option-->
                                    <option value="216">Trading Cards Ice Hockey</option>
                                    <!--option value="183444">Trading Cards Soccer</option-->
                                </select>
                                <label for="format" class="keepTogether">Format:</label>
                                    <select id="format" name="format" data-placeholder="Select Format..." class="chosen-select-no-single" style="height:3em;width:15%;" onchange="return categoryValues();" onload="return categoryValues();">
                                                                        <option />
                                    <option value="Chinese">Auction</option>
                                    <option value="FixedPriceItem">Fixed Price</option>
                                </select>
                                <table class="w3-right">
                                    <tr>
                                        <td><a id="image1anchor" href="" target="_blank"><img id="image1" src="" alt="(Front Image Missing)" style="max-height:80px;" onload="return pictureLoad(true);" onerror="return pictureLoad(false);" crossorigin="anonymous" /></a></td>
                                        <td><a id="image2anchor" href="" target="_blank"><img id="image2" src="" alt="(Back Image Missing)" style="max-height:80px;" onload="return pictureLoad(true);" onerror="return pictureLoad(false);" crossorigin="anonymous" /></a> </td>
                                        <td><img id="descriptionImage" src="" alt="(Front/Back Image Missing)" style="max-height:50px;display:inline-block;" onload="return pictureLoad(true);" onerror="return pictureLoad(false); " crossorigin="anonymous" /> </td>
                                        <td><a id="image3anchor" class="w3-hide" href="" target="_blank"><img id="image3" src="" alt="(Optional Image 3)" style="max-height:80px;" crossorigin="anonymous" /></a> </td>
                                        <td><a id="image4anchor" class="w3-hide" href="" target="_blank"><img id="image4" src="" alt="(Optional Image 4)" style="max-height:80px;" crossorigin="anonymous" /></a> </td>
                                        <td><a id="image5anchor" class="w3-hide" href="" target="_blank"><img id="image5" src="" alt="(Optional Image 5)" style="max-height:80px;" crossorigin="anonymous" /></a> </td>
                                        <td><a id="image6anchor" class="w3-hide" href="" target="_blank"><img id="image6" src="" alt="(Optional Image 6)" style="max-height:80px;" crossorigin="anonymous" /></a> </td>
                                        <td><a id="image7anchor" class="w3-hide" href="" target="_blank"><img id="image7" src="" alt="(Optional Image 7)" style="max-height:80px;" crossorigin="anonymous" /></a> </td>
                                    </tr>
                                </table>
                            </div>
                            <div class="w3-clear">
                                <label for="title" class="keepTogether">Title:</label>
                                <input id="title" name="title" class="w3-input-2 w3-border-0" style="height:3em;width:80%;" type="text" maxlength="80" onblur="return extractFromTitle();" onKeyPress="printTitleLength()" onKeyUp="printTitleLength()" required>
                                <span id="titleLength" class="w3-tiny"> </span>
                            </div>
                            <div>
                                <label for="price" class="keepTogether">Price:</label>
                                <input id="price" name="price" class="w3-input-2 w3-border-0" style="height:3em;width:8%;" type="text" required>
                                <span class="no-label-wrap">
                                            <label for="bestoffer" style="display:inline-block;vertical-align:middle;">Best Offer<br/>Enabled</label>
                                            <input id="bestoffer" name="bestoffer" class="w3-check" style="height:1em;" type="checkbox">
                                                                </span>
                                <label for="quantity" class="keepTogether">Quantity:</label>
                                <input id="quantity" name="quantity" class="w3-input-2 w3-border-0" style="height:3em;;width:10%" type="text" value="1"  maxlength="4" required>
                                <label for="sku" class="keepTogether">SKU:</label>
                                <input id="sku" name="sku" class="w3-input-2 w3-border-0" style="height:3em;width:12%;" type="text" value="Batch X"  maxlength="20" required>
                                <label for="conditionId" class="keepTogether">Condition:</label>
                                    <select id="conditionId" name="conditionId" data-placeholder="Select Condition..." class="chosen-select" style="height:3em;width:25%;">
                                                                        <option />
                                    <option value="1000">New</option>
                                    <option value="1500">New other (see details)</option>
                                    <option value="1750">New with defects</option>
                                    <option value="2000">Manufacturer refurbished</option>
                                    <option value="2500">Seller refurbished</option>
                                    <option value="2750">Like New</option>
                                    <option value="3000">Used / Pre-owned</option>
                                    <option value="4000">Very Good</option>
                                    <option value="5000">Good</option>
                                    <option value="6000">Acceptable</option>
                                    <option value="7000">For parts or not working</option>
                                </select>
                            </div>
                            <div>
                                <label for="condition">Condition Description:</label>
                                <input id="CdConditionDescriptionSingular" type="button" class="w3-button w3-circle w3-black w3-tiny w3-ripple w3-hide" onclick="return setCdConditionDescription('S');" value="S" />
                                <input id="CdConditionDescriptionPlural" type="button" class="w3-button w3-circle w3-black w3-tiny w3-ripple w3-hide" onclick="return setCdConditionDescription('P');" value="P" />
                                <input id="CdConditionDescriptionDigipak" type="button" class="w3-button w3-circle w3-black w3-tiny w3-ripple w3-hide" onclick="return setCdConditionDescription('D');" value="D" />
                                <input id="CdConditionDescriptionNewCase" type="button" class="w3-button w3-circle w3-black w3-tiny w3-ripple w3-hide" onclick="return setCdConditionDescription('N');" value="N" />
                                <textarea id="condition" name="condition" class="w3-input w3-border-0" style="height:6em;" maxlength="1000" required></textarea>
                            </div>
                        </form>
                        <div id="bookDetails" class="w3-container w3-padding w3-card-2">
                            <form id="bookForm" class="w3-container w3-light-grey w3-small" onchange="return requireNewVerify();">
                                <div>
                                    <label for="bookISBN" class="keepTogether">ISBN:</label>
                                    <input id="bookISBN" name="bookISBN" class="w3-input-2 w3-border-0" style="height:3em;width:15%;" type="text" disabled>
                                    <label for="bookFormat" class="keepTogether">Format:</label>
                                            <select id="bookFormat" name="bookFormat" data-placeholder="Select Format..." class="chosen-select-no-single10" style="height:3em;width:18%;">
                                                                                <option />
                                        <option value="Hardcover">Hardcover</option>
                                        <option value="Paperback">Paperback</option>
                                        <option value="CD-ROM (Non-Audio)">CD-ROM (Non-Audio)</option>
                                        <option value="Mixed Lot">Mixed Lot</option>
                                        <option value="Board Book">Board Book</option>
                                        <option value="Loose-Leaf">Loose-Leaf</option>
                                        <option value="Postcard Book">Postcard Book</option>
                                        <option value="Shrink-Wrapped Pack">Shrink-Wrapped Pack</option>
                                    </select>
                                    <label for="bookAuthor" class="keepTogether">Author:</label>
                                    <input id="bookAuthor" name="bookAuthor" class="w3-input-2 w3-border-0" style="height:3em;width:30%;" type="text" maxlength="40">
                                    <label for="bookPublicationYear" class="keepTogether">Year:</label>
                                    <input id="bookPublicationYear" name="bookPublicationYear" class="w3-input-2 w3-border-0" style="height:3em;width:7%;" type="text" maxlength="4">
                                </div>
                                <div>
                                    <label for="bookSubject" class="keepTogether">Subject:</label>
                                            <select id="bookSubject" name="bookSubject" data-placeholder="Select Subject..." class="chosen-select-deselect" style="height:3em;width:27%;>
                                                                                <option />
                                        <option value="Activity &amp; Coloring Books">Activity & Coloring Books</option>
                                        <option value="Architecture &amp; Design">Architecture & Design</option>
                                        <option value="Art &amp; Photography">Art & Photography</option>
                                        <option value="Biography &amp; Autobiography">Biography & Autobiography</option>
                                        <option value="Books on Collecting">Books on Collecting</option>
                                        <option value="Business &amp; Economics">Business & Economics</option>
                                        <option value="Computers &amp; Internet">Computers & Internet</option>
                                        <option value="Cooking, Food &amp; Wine">Cooking, Food & Wine</option>
                                        <option value="Erotica">Erotica</option>
                                        <option value="Family &amp; Relationships">Family & Relationships</option>
                                        <option value="Games &amp; Puzzles">Games & Puzzles</option>
                                        <option value="Health &amp; Fitness">Health & Fitness</option>
                                        <option value="History">History</option>
                                        <option value="Hobbies &amp; Crafts">Hobbies & Crafts</option>
                                        <option value="Home &amp; Garden">Home & Garden</option>
                                        <option value="Humor">Humor</option>
                                        <option value="Law &amp; Government">Law & Government</option>
                                        <option value="Library &amp; Information Science">Library & Information Science</option>
                                        <option value="Literary Criticism">Literary Criticism</option>
                                        <option value="Literature">Literature</option>
                                        <option value="Medical">Medical</option>
                                        <option value="Military &amp; War">Military & War</option>
                                        <option value="Novel">Novel</option>
                                        <option value="Outdoor &amp; Nature">Outdoor & Nature</option>
                                        <option value="Paranormal &amp; Metaphysical">Paranormal & Metaphysical</option>
                                        <option value="Performing Arts">Performing Arts</option>
                                        <option value="Pets &amp; Animal Care">Pets & Animal Care</option>
                                        <option value="Philosophy">Philosophy</option>
                                        <option value="Psychology">Psychology</option>
                                        <option value="Reference">Reference</option>
                                        <option value="Religion &amp; Spirituality">Religion & Spirituality</option>
                                        <option value="Science &amp; Technology">Science & Technology</option>
                                        <option value="Self-Help">Self-Help</option>
                                        <option value="Sexuality">Sexuality</option>
                                        <option value="Social Sciences">Social Sciences</option>
                                        <option value="Sports &amp; Recreation">Sports & Recreation</option>
                                        <option value="Teaching &amp; Education">Teaching & Education</option>
                                        <option value="Transportation">Transportation</option>
                                        <option value="Travel, Geography &amp; Exploration">Travel, Geography & Exploration</option>
                                        <option value="True Crime">True Crime</option>
                                        <option value="Vintage Paperbacks">Vintage Paperbacks</option>
                                    </select>
                                    <label for="bookLanguage" class="keepTogether">Language:</label>
                                <input id="bookLanguage" name="bookLanguage" class="w3-input-2 w3-border-0" style="height:3em;width:12%;" type="text">
                                    <label for="bookCountry" class="keepTogether">Country:</label>
                                <input id="bookCountry" name="bookCountry" class="w3-input-2 w3-border-0" style="height:3em;width:20%;" type="text" maxlength="65">
                                </div>
                                <p>Special Attributes:</p>
                                <div>
                                    <span class="no-label-wrap">
                                    <input id="bookDustJacket" name="bookDustJacket" class="w3-check" style="height:1em" type="checkbox">
                                    <label for="bookDustJacket">Dust Jacket</label>
                                </span>
                                    <span class="no-label-wrap">
                                    <input id="bookIllustrated" name="bookIllustrated" class="w3-check" style="height:1em" type="checkbox">
                                    <label for="bookIllustrated">Illustrated</label>
                                </span>
                                    <span class="no-label-wrap">
                                    <input id="bookLargePrint" name="bookLargePrint" class="w3-check" style="height:1em" type="checkbox">
                                    <label for="bookLargePrint">Large Print</label>
                                </span>
                                    <span class="no-label-wrap">
                                    <input id="bookSigned" name="bookSigned" class="w3-check" style="height:1em" type="checkbox">
                                    <label for="bookSigned">Signed</label>
                                </span>
                                </div>
                            </form>
                        </div>
                        <div id="cdDetails" class="w3-container w3-padding w3-card-2">
                            <form id="cdForm" class="w3-container w3-light-grey w3-small" onchange="return requireNewVerify();">
                                <div>
                                    <label for="cdUPC" class="keepTogether w3-hide">UPC:</label>
                                    <input id="cdUPC" name="cdUPC" class="w3-input-2 w3-border-0 w3-hide" style="height:3em;width:10%;" type="text" disabled>
                                    <label for="cdArtist" class="keepTogether">Artist:</label>
                                    <input id="cdArtist" name="cdArtist" class="w3-input-2 w3-border-0" style="height:3em;width:31%;" type="text" maxlength="40">
                                    <label for="cdTitle" class="keepTogether">Title:</label>
                                    <input id="cdTitle" name="cdTitle" class="w3-input-2 w3-border-0" style="height:3em;width:31%;" type="text" maxlength="65">
                                    <label for="cdRecordLabel" class="keepTogether">Label:</label>
                                    <input id="cdRecordLabel" name="cdRecordLabel" class="w3-input-2 w3-border-0" style="height:3em;width:16%;" type="text" maxlength="40">
                                </div>
                                <div>
                                    <label for="cdReleaseYear" class="keepTogether">Year:</label>
                                    <input id="cdReleaseYear" name="cdReleaseYear" class="w3-input-2 w3-border-0" style="height:3em;width:6%;" type="text" maxlength="4">
                                    <label for="cdDuration" class="keepTogether">Duration:</label>
                                            <select id="cdDuration" name="cdDuration" data-placeholder="Select Duration..." class="chosen-select-no-single10" style="height:3em;width:15%;">
                                                                                <option />
                                        <option value="Album" selected>Album</option>
                                        <option value="Mini Album">Mini Album</option>
                                        <option value="Box Set">Box Set</option>
                                        <option value="EP">EP</option>
                                        <option value="Single">Single</option>
                                        <option value="Maxi-Single">Maxi-Single</option>
                                    </select>
                                    <label for="cdGenre" class="keepTogether">Genre:</label>
                                            <select id="cdGenre" name="cdGenre" data-placeholder="Select Genre..." class="chosen-select-deselect" style="height:3em;width:25%;">
                                                                                <option />
                                        <option value="Blues">Blues</option>
                                        <option value="Children&apos;s">Children's</option>
                                        <option value="Classical">Classical</option>
                                        <option value="Comedy &amp; Spoken Word">Comedy & Spoken Word</option>
                                        <option value="Country">Country</option>
                                        <option value="Dance &amp; Electronica">Dance & Electronica</option>
                                        <option value="Folk">Folk</option>
                                        <option value="Holiday">Holiday</option>
                                        <option value="Jazz">Jazz</option>
                                        <option value="Latin">Latin</option>
                                        <option value="Metal">Metal</option>
                                        <option value="Military">Military</option>
                                        <option value="New Age &amp; Easy Listening">New Age & Easy Listening</option>
                                        <option value="Pop">Pop</option>
                                        <option value="R&amp;B &amp; Soul">R&B & Soul</option>
                                        <option value="Rap &amp; Hip-Hop">Rap & Hip-Hop</option>
                                        <option value="Reggae, Ska &amp; Dub">Reggae, Ska & Dub</option>
                                        <option value="Religious &amp; Devotional">Religious & Devotional</option>
                                        <option value="Rock">Rock</option>
                                        <option value="Soundtracks &amp; Musicals">Soundtracks & Musicals</option>
                                        <option value="Sound Effects &amp; Nature">Sound Effects & Nature</option>
                                        <option value="World Music">World Music</option>
                                    </select>
                                    <label for="cdCountry" class="keepTogether">Country:</label>
                                <input id="cdCountry" name="cdCountry" class="w3-input-2 w3-border-0" style="height:3em;width:24%;" type="text" maxlength="65">
                                </div>
                                <div>
                                    <p>Special Attributes:</p>
                                    <span class="no-label-wrap">
                                    <input id="cdCompilation" name="cdCompilation" class="w3-check" style="height:1em" type="checkbox">
                                    <label for="cdCompilation">Compilation</label>
                                </span>
                                    <span class="no-label-wrap">
                                    <input id="cdDigipak" name="cdDigipak" class="w3-check" style="height:1em" type="checkbox">
                                    <label for="cdDigipak">Digipak</label>
                                </span>
                                    <span class="no-label-wrap">
                                    <input id="cdDualDisc" name="cdDualDisc" class="w3-check" style="height:1em" type="checkbox">
                                    <label for="cdDualDisc">DualDisc</label>
                                </span>
                                    <span class="no-label-wrap">
                                    <input id="cdEnhanced" name="cdEnhanced" class="w3-check" style="height:1em" type="checkbox">
                                    <label for="cdEnhanced">Enhanced</label>
                                </span>
                                    <span class="no-label-wrap">
                                    <input id="cdLiveRecording" name="cdLiveRecording" class="w3-check" style="height:1em" type="checkbox">
                                    <label for="cdLiveRecording">Live</label>
                                </span>
                                    <span class="no-label-wrap">
                                    <input id="cdPromo" name="cdPromo" class="w3-check" style="height:1em" type="checkbox">
                                    <label for="cdPromo">Promo</label>
                                </span>
                                    <span class="no-label-wrap">
                                    <input id="cdReissue" name="cdReissue" class="w3-check" style="height:1em" type="checkbox">
                                    <label for="cdReissue">Reissue</label>
                                </span>
                                    <span class="no-label-wrap">
                                    <input id="cdRemastered" name="cdRemastered" class="w3-check" style="height:1em" type="checkbox">
                                    <label for="cdRemastered">Remastered</label>
                                </span>
                                    <span class="no-label-wrap">
                                    <input id="cdHDCD" name="cdHDCD" class="w3-check" style="height:1em" type="checkbox">
                                    <label for="cdHDCD">HDCD</label>
                                </span>
                                    <span class="no-label-wrap">
                                    <input id="cdGreatestHits" name="cdGreatestHits" class="w3-check" style="height:1em" type="checkbox">
                                    <label for="cdGreatestHits">Greatest Hits</label>
                                </span>
                                </div>
                                <div>
                                    <p></p>
                                    <label for="cdTracksFormat">Track List (optional):</label>
                                                    <input id="cdTracksFormat" type="button" class="w3-button w3-circle w3-margin w3-black w3-tiny w3-ripple" onclick="return formatTrackList();" value="Format" />
                                    <span class="no-label-wrap">
                                                    <input id="cdUnorderedTrackList" name="cdUnorderedTrackList" class="w3-check" style="height:1em" type="checkbox">
                                                <label for="cdUnorderedTrackList">Unordered</label>
                                            </span>
                                    <textarea id="cdTracks" name="cdTracks" class="w3-input w3-border-0" style="height:15em"></textarea>
                                </div>
                            </form>
                        </div>
                        <div id="dvdDetails" class="w3-container w3-padding w3-card-2">
                            <form id="dvdForm" class="w3-container w3-light-grey w3-small" onchange="return requireNewVerify();">
                                <div>
                                    <label for="dvdUPC" class="keepTogether">UPC:</label>
                                    <input id="dvdUPC" name="dvdUPC" class="w3-input-2 w3-border-0" style="height:3em;width:15%;" type="text" disabled>
                                    <label for="dvdFormat" class="keepTogether">Format:</label>
                                            <select id="dvdFormat" name="dvdFormat" data-placeholder="Select Format..." class="chosen-select-no-single10" style="height:3em;width:20%;">
                                                                                <option />
                                        <option value="Blu-ray Disc">Blu-ray Disc</option>
                                        <option value="DVD" selected>DVD</option>
                                        <option value="HD DVD">HD DVD</option>
                                        <option value="UltraViolet Code">UltraViolet Code</option>
                                    </select>
                                    <label for="dvdTitle" class="keepTogether">Title:</label>
                                    <input id="dvdTitle" name="dvdTitle" class="w3-input-2 w3-border-0" style="height:3em;width:45%;" type="text" maxlength="65">
                                </div>
                                <div>
                                    <label for="dvdActor" class="keepTogether">Actor:</label>
                                    <input id="dvdActor" name="dvdActor" class="w3-input-2 w3-border-0" style="height:3em;width:21%;" type="text" maxlength="65">
                                    <label for="dvdLeadingRole" class="keepTogether">Lead:</label>
                                    <input id="dvdLeadingRole" name="dvdLeadingRole" class="w3-input-2 w3-border-0" style="height:3em;width:28%;" type="text" maxlength="65">
                                    <label for="dvdDirector" class="keepTogether">Director:</label>
                                    <input id="dvdDirector" name="dvdDirector" class="w3-input-2 w3-border-0" style="height:3em;width:21%;" type="text" maxlength="65">
                                </div>
                                <div>
                                    <label for="dvdReleaseYear" class="keepTogether">Movie Year:</label>
                                    <input id="dvdReleaseYear" name="dvdReleaseYear" class="w3-input-2 w3-border-0" style="height:3em;width:6%;" type="text" maxlength="4">
                                    <label for="dvdDVDEditionYear" class="keepTogether">DVD Year:</label>
                                    <input id="dvdDVDEditionYear" name="dvdDVDEditionYear" class="w3-input-2 w3-border-0" style="height:3em;width:6%;" type="text" maxlength="4">
                                    <label for="dvdGenre" class="keepTogether">Genre:</label>
                                            <select id="dvdGenre" name="dvdGenre" data-placeholder="Select Genre..." class="chosen-select-deselect" style="height:3em;width:25%;">
                                                                                <option />
                                        <option value="Action &amp; Adventure">Action & Adventure</option>
                                        <option value="Animation &amp; Anime">Animation & Anime</option>
                                        <option value="Children&apos;s &amp; Family">Children's & Family</option>
                                        <option value="Comedy">Comedy</option>
                                        <option value="Documentary">Documentary</option>
                                        <option value="Drama">Drama</option>
                                        <option value="Educational">Educational</option>
                                        <option value="Exercise &amp; Fitness">Exercise & Fitness</option>
                                        <option value="Foreign Language">Foreign Language</option>
                                        <option value="Horror">Horror</option>
                                        <option value="Music &amp; Concerts">Music & Concerts</option>
                                        <option value="Musicals &amp; Broadway">Musicals & Broadway</option>
                                        <option value="Romance">Romance</option>
                                        <option value="Sci-Fi &amp; Fantasy">Sci-Fi & Fantasy</option>
                                        <option value="Sports">Sports</option>
                                        <option value="Thriller &amp; Mystery">Thriller & Mystery</option>
                                        <option value="TV Shows">TV Shows</option>
                                        <option value="Westerns">Westerns</option>
                                    </select>
                                    <label for="dvdRating" class="keepTogether">Rating:</label>
                                            <select id="dvdRating" name="dvdRating" data-placeholder="Select Rating..." class="chosen-select-no-single10 chosen-select-deselect" style="height:3em;width:14%;">
                                                                                <option />
                                        <option value="G">G</option>
                                        <option value="PG">PG</option>
                                        <option value="PG-13">PG-13</option>
                                        <option value="R">R</option>
                                        <option value="NR">NR</option>
                                        <option value="NC-17">NC-17</option>
                                        <option value="TV-Y">TV-Y</option>
                                        <option value="TV-Y7">TV-Y7</option>
                                        <option value="TV-G">TV-G</option>
                                        <option value="TV-PG">TV-PG</option>
                                        <option value="TV-14">TV-14</option>
                                        <option value="TV-MA">TV-MA</option>
                                    </select>
                                </div>
                                <div>
                                    <label for="dvdRegionCode" class="keepTogether">Region:</label>
                                            <select id="dvdRegionCode" name="dvdRegionCode" data-placeholder="Select Region..." class="chosen-select-no-single10 chosen-select-deselect" style="height:3em;width:22%;">
                                                                                <option />
                                        <option value="Blu-ray: Region Free">Blu-ray: Region Free</option>
                                        <option value="Blu-ray: A (Americas, Southeast Asia...)">Blu-ray: A</option>
                                        <option value="Blu-ray: B (Europe, AU, NZ, Africa...)">Blu-ray: B</option>
                                        <option value="Blu-ray: C (China, Russia, India...)">Blu-ray: C</option>
                                        <option value="DVD: 0/All (Region Free/Worldwide)">DVD: 0/All</option>
                                        <option value="DVD: 1 (US, Canada...)" selected>DVD: 1</option>
                                        <option value="DVD: 2 (Europe, Japan, Middle East...)">DVD: 2</option>
                                        <option value="DVD: 3 (Southeast Asia, Taiwan, HK...)">DVD: 3</option>
                                        <option value="DVD: 4 (AU, NZ, Latin America...)">DVD: 4</option>
                                        <option value="DVD: 5 (Russia, India, Africa...)">DVD: 5</option>
                                        <option value="DVD: 6 (China)">DVD: 6 (China)</option>
                                    </select>
                                    <label for="dvdRental" class="keepTogether">Rental:</label>
                                            <select id="dvdRental" name="dvdRental" class="chosen-select-no-single10" style="height:3em;width:8%;">
                                        <option value="No" selected>No</option>
                                        <option value="Yes">Yes</option>
                                    </select>
                                    <label for="dvdSeason" class="keepTogether">Season:</label>
                                            <select id="dvdSeason" name="dvdSeason" data-placeholder="Select Season..." class="chosen-select chosen-select-deselect" style="height:3em;width:24%;">
                                                                                <option />
                                        <option value="Complete Series Box Set">Complete Series Box Set</option>
                                        <option value="1">1</option>
                                        <option value="2">2</option>
                                        <option value="3">3</option>
                                        <option value="4">4</option>
                                        <option value="5">5</option>
                                        <option value="6">6</option>
                                        <option value="7">7</option>
                                        <option value="8">8</option>
                                        <option value="9">9</option>
                                        <option value="10">10</option>
                                        <option value="11">11</option>
                                        <option value="12">12</option>
                                        <option value="13">13</option>
                                        <option value="14">14</option>
                                        <option value="15">15</option>
                                        <option value="16">16</option>
                                        <option value="17">17</option>
                                        <option value="18">18</option>
                                        <option value="19">19</option>
                                        <option value="20">20</option>
                                        <option value="21">21</option>
                                        <option value="22">22</option>
                                        <option value="23">23</option>
                                        <option value="24">24</option>
                                    </select>
                                    <label for="dvdCountry" class="keepTogether">Country:</label>
                                    <input id="dvdCountry" name="dvdCountry" class="w3-input-2 w3-border-0" style="height:3em;width:18%;" type="text" maxlength="65">
                                </div>
                                <div>
                                    <p>Edition:</p>
                                    <span class="no-label-wrap">
                                    <input id="dvd3D" name="dvd3D" class="w3-check" style="height:1em" type="checkbox">
                                    <label for="dvd3D">3D</label>
                                </span>
                                    <span class="no-label-wrap">
                                    <input id="dvdAnniversaryEdition" name="dvdAnniversaryEdition" class="w3-check" style="height:1em" type="checkbox">
                                    <label for="dvdAnniversaryEdition">Anniversary Edition</label>
                                </span>
                                    <span class="no-label-wrap">
                                    <input id="dvdBoxSet" name="dvdBoxSet" class="w3-check" style="height:1em" type="checkbox">
                                    <label for="dvdBoxSet">Box Set</label>
                                </span>
                                    <span class="no-label-wrap">
                                    <input id="dvdCollectorsEdition" name="dvdCollectorsEdition" class="w3-check" style="height:1em" type="checkbox">
                                    <label for="dvdCollectorsEdition">Collector's Edition</label>
                                </span>
                                    <span class="no-label-wrap">
                                    <input id="dvdDeluxeEdition" name="dvdDeluxeEdition" class="w3-check" style="height:1em" type="checkbox">
                                    <label for="dvdDeluxeEdition">Deluxe Edition</label>
                                </span>
                                    <span class="no-label-wrap">
                                    <input id="dvdDirectorsCut" name="dvdDirectorsCut" class="w3-check" style="height:1em" type="checkbox">
                                    <label for="dvdDirectorsCut">Director's Cut</label>
                                </span>
                                    <span class="no-label-wrap">
                                    <input id="dvdExtendedEdition" name="dvdExtendedEdition" class="w3-check" style="height:1em" type="checkbox">
                                    <label for="dvdExtendedEdition">Extended Edition</label>
                                </span>
                                    <span class="no-label-wrap">
                                    <input id="dvdFullScreen" name="dvdFullScreen" class="w3-check" style="height:1em" type="checkbox">
                                    <label for="dvdFullScreen">Full Screen</label>
                                </span>
                                    <span class="no-label-wrap">
                                    <input id="dvdLimitedEdition" name="dvdLimitedEdition" class="w3-check" style="height:1em" type="checkbox">
                                    <label for="dvdLimitedEdition">Limited Edition</label>
                                </span>
                                    <span class="no-label-wrap">
                                    <input id="dvdPromo" name="dvdPromo" class="w3-check" style="height:1em" type="checkbox">
                                    <label for="dvdPromo">Promo</label>
                                </span>
                                    <span class="no-label-wrap">
                                    <input id="dvdSignatureCollection" name="dvdSignatureCollection" class="w3-check" style="height:1em" type="checkbox">
                                    <label for="dvdSignatureCollection">Signature Collection</label>
                                </span>
                                    <span class="no-label-wrap">
                                    <input id="dvdSpecialEdition" name="dvdSpecialEdition" class="w3-check" style="height:1em" type="checkbox">
                                    <label for="dvdSpecialEdition">Special Edition</label>
                                </span>
                                    <span class="no-label-wrap">
                                    <input id="dvdSteelbook" name="dvdSteelbook" class="w3-check" style="height:1em" type="checkbox">
                                    <label for="dvdSteelbook">Steelbook</label>
                                </span>
                                    <span class="no-label-wrap">
                                    <input id="dvdUnratedEdition" name="dvdUnratedEdition" class="w3-check" style="height:1em" type="checkbox">
                                    <label for="dvdUnratedEdition">Unrated Edition</label>
                                </span>
                                    <span class="no-label-wrap">
                                    <input id="dvdWidescreen" name="dvdWidescreen" class="w3-check" style="height:1em" type="checkbox">
                                    <label for="dvdWidescreen">Widescreen</label>
                                </span>
                                </div>
                            </form>
                        </div>
                        <div id="tradingCardDetails" class="w3-container w3-padding w3-card-2 w3-hide">
                            <form id="tradingCardForm" class="w3-container w3-light-grey w3-small" onchange="return requireNewVerify();">
                                <div>
                                    <label for="tcPlayer" class="keepTogether">Player:</label>
                                    <input id="tcPlayer" name="tcPlayer" class="w3-input-2 w3-border-0" style="height:3em;width:20%;" type="text">
                                    <label for="tcPosition" class="keepTogether">Position:</label>
                                    <input id="tcPosition" name="tcPosition" class="w3-input-2 w3-border-0" style="height:3em;width:8%;" type="text">
                                    <label for="tcTeam" class="keepTogether">Team:</label>
                                    <input id="tcTeam" name="tcTeam" class="w3-input-2 w3-border-0" style="height:3em;width:20%;" type="text">
                                    <label for="tcSeason" class="keepTogether">Season:</label>
                                    <input id="tcSeason" name="tcSeason" class="w3-input-2 w3-border-0" style="height:3em;width:8%;" type="text">
                                </div>
                                <div>
                                    <label for="tcManufacturer" class="keepTogether">Manufacturer:</label>
                                    <input id="tcManufacturer" name="tcManufacturer" class="w3-input-2 w3-border-0" style="height:3em;width:20%;" type="text">
                                    <label for="tcNumber" class="keepTogether">Number:</label>
                                    <input id="tcNumber" name="tcNumber" class="w3-input-2 w3-border-0" style="height:3em;width:8%;" type="text">
                                    <label for="tcSeries" class="keepTogether">Series:</label>
                                    <input id="tcSeries" name="tcSeries" class="w3-input-2 w3-border-0" style="height:3em;width:20%;" type="text">
                                </div>
                                <div>
                                    <span class="no-label-wrap">
                            <input id="tcPoA" name="tcPoA" class="w3-check" style="height:1em" type="checkbox">
                            <label for="tcPoA">Piece of Authentic</label>
                                                        </span>
                                    <span class="no-label-wrap">
                            <input id="tcRookie" name="tcRookie" class="w3-check" style="height:1em" type="checkbox">
                            <label for="tcRookie">Rookie</label>
                                                        </span>
                                    <span class="no-label-wrap">
                            <input id="tcSerial" name="tcSerial" class="w3-check" style="height:1em" type="checkbox">
                            <label for="tcSerial">Serialized</label>
                                                        </span>
                                </div>
                            </form>
                        </div>
                        <div id="results" class="w3-container w3-padding w3-card-4 w3-hide"></div>
                    </div>

                    <input id="verify" type="submit" class="w3-btn w3-red w3-margin w3-round-large w3-ripple" onclick="verifyListingImage();" value="Verify" />
                    <input id="list" type="button" class="w3-btn w3-red w3-margin w3-round-large w3-ripple" onclick="submitListing(0);" value="List" />
                    <input id="savexml" type="button" class="w3-btn w3-red w3-margin w3-round-large w3-ripple" onclick="submitListing(1);" value="XML" />
                    <input type="button" class="w3-btn w3-black w3-margin w3-round-large w3-ripple w3-right" onclick="resetForm()" value="Reset form" />

                </div>

                <div class="w3-container w3-padding w3-half">
                    <div id="productinfo" class="w3-container w3-card-2 w3-padding">
                        <p>Product Info</p>
                    </div>
                    <div id="discogsReleases" class="w3-container w3-padding w3-card-2 w3-hide"></div>
                    <div id="prices" class="w3-container w3-padding w3-card-2 w3-hide"></div>
                </div>
            </div>

        </div>

        <div id="query" class="w3-container w3-padding w3-margin w3-card-4 w3-hide"></div>

        <footer class="w3-container w3-center w3-border-top w3-margin">
            Copyright &#169; 2018 MUNA Trading. All rights reserved.
        </footer>

    </div>

    <script>

// Globals
var originalUserAgent;

var picturesAreLoaded = false;
var xml = '';
var category = '';
var catalogTitle = '';
var catalogActorNames = '';
var listItems = [];
var additionalPictures = [];
var isManualMode = false;
var isDuplicate = false;
var eBayProductId = '';

var CC = -1; /* 0=Book, 1=CD, 2=DVD, 3=Trading Card */
var ShippingProfileIdList = ['146987753023', '146987646023', '146987753023', '125181485023'];
var ShippingProfileNameList = ['Free Economy Shipping', 'Free Standard Shipping', 'Free Economy Shipping', 'Trading Card without Tracking Number'];
var MinPriceList = ['5.98', '5.48', '5.48', '0.99'];
var ProductListingDetailsNameList = ['ISBN', 'UPC', 'UPC', 'UPC'];
var StoreCategoryList = ['30460217018', '30432075018', '30606323018', '1'];
var movieFormats = ["DVD", "Blu-ray Disc", "HD DVD"];
var auctionFormat = ['FixedPriceItem', 'FixedPriceItem', 'FixedPriceItem', 'Chinese'];
var discogsQty = 0;

var ConditionIdList = ['2750', '4000', '4000', '4000'];
var ConditionDescriptionList = ['The book is in mint condition and shows only slight cover wear due to shelf storage. The cover and binding are undamaged and the pages have no markings or writing. Please view all images of the actual book.',
        'The disc is in near mint/mint condition and has been tested by us. The jewel case is in good shape, the inside tray is intact. Please view all actual images.',
        'The case is in good shape, the disc in near mint/mint condition. Please view all actual images.',
        'The card is in near mint/mint condition and will be mailed out in a sleeve within 1 business day after payment cleared. Expedited service with tracking number and top loader is available at an extra charge.'
];

var ConditionDescriptionCdPlural = 'The discs are in near mint/mint condition and have been tested by us. The jewel case is in good shape, the inside trays are intact. Please view all actual images.';
var ConditionDescriptionCdNewCase = 'The disc is in near mint/mint condition and comes in a new jewel case. Please view all actual images.';
var ConditionDescriptionCdDigipak = 'The disc is in near mint/mint condition and has been tested by us. The digipak is in good shape, the inside tray intact. Please view all actual images.';

var Description1 = '<meta name="viewport" content="width=device-width, initial-scale=1.0"><style>.w3-ol{list-style-type:1}.w3-ol li{padding:8px 16px;border-bottom:1px solid #ddd}.w3-ol li:last-child{border-bottom:none} img {max-width:100%}.tabs {max-width:90%;float:none;list-style: none;margin: 0 auto;}.tabs:after {content:"";display:table;clear: both;}.tabs input[type=radio] {display:none;}.tabs label {opacity:0.5;display:block;font-size:30px;font-weight:normal;text-decoration:none;text-align:center;line-height:2;cursor:pointer;-webkit-transition:all 0.5s;transition:all 0.5s;}.tabs label span {display:inline-block;float:left;}.tabs label:hover {opacity:1;}.tab-content {display:none;width:100%;float:left;padding:8px 16px;box-shadow:0 2px 5px 0 rgba(0,0,0,0.16),0 2px 10px 0 rgba(0,0,0,0.12);border-radius:8px;background-color:#ffffff;}.tab-content * {-webkit-animation:scale 0.7s ease-in-out;-moz-animation:scale 0.7s ease-in-out;animation:scale 0.7s ease-in-out;}@keyframes scale {0% {transform:scale(0.9);opacity:0;}50% {transform:scale(1.01);opacity:0.5;}100% {transform:scale(1);opacity:1;}}.tabs [id^="tab"]:checked + label { opacity:1; }#tab1:checked ~ #tab-content1, #tab2:checked ~ #tab-content2, #tab3:checked ~ #tab-content3 {display:block;}.header-logo { max-height:100px!important; }.header-company-name { font-size:64px!important; }.header-button-1, .header-button-2, .header-button-3, .header-button-4, .header-button-5 {  }.header-icon-text { font-size:30px!important; }.header-icon { width:50px!important; height:50px!important;}.paypal-logo { max-height:100px!important; }.tab-alternate-header { display:none!important; }@media only screen and (max-width:780px) {.header-logo { max-height:80px!important; }.header-company-name { font-size:48px!important; }.header-button-2, .header-button-3, .header-button-5 { display:none!important; }.header-icon-text { font-size:24px!important; }.header-icon { width:45px!important; height:45px!important;}.paypal-logo { max-height:80px!important; }.tabs {max-width:100%!important;}.tab-button { display:none!important; }.tab-alternate-header { display:block!important; }#tab-content1, #tab-content2, #tab-content3 { display:block!important; }}@media only screen and (max-width:500px) {.header-logo { max-height:60px!important; }.header-company-name { font-size:32px!important; }.header-button-2, .header-button-3, .header-button-4, .header-button-5 { display:none!important; }.header-icon-text { font-size:20px!important; }.header-icon { width:40px!important; height:40px!important;}.paypal-logo { max-height:60px!important; }.tabs {max-width:100%!important;}.tab-button { display:none!important; }.tab-alternate-header { display:block!important; }#tab-content1, #tab-content2, #tab-content3 { display:block!important; }}</style><link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"><div class="w3-main"><div class="w3-container w3-margin w3-light-grey w3-text-black w3-card-4 w3-round-large" style="background-color:hsla(200, 100%, 25%, .8);"><div class="w3-center w3-text-white w3-round-large w3-border-white w3-topbar w3-bottombar w3-rightbar w3-leftbar w3-card-4" style="background-color:hsla(200, 100%, 25%, .8);"><h2 class="header-icon-text"><img class="header-icon" alt="Clipboard" src="https://cdn.shopify.com/s/files/1/0018/0273/1609/files/if_clipboard_1055091.png"> Product Description</h2></div><div class="w3-row w3-padding"><!-- *************** Place description here ****************** --><div class="w3-container w3-padding w3-twothird">';
var Description2 = '</div><div class="w3-container w3-padding w3-third"><img class="w3-image w3-border w3-right" alt="';
var Description2a = '" src="';
var DescImage;
var Description3 = '"></div><!-- *************** Place description here ****************** --></div></div><div class="w3-container w3-margin w3-light-grey w3-text-black w3-card-4 w3-round-large" style="background-color:hsla(200, 100%, 25%, .8);"><div class="tabs w3-padding"><!-- Radio button and label for #tab-content1 --><input name="tabs" id="tab1" checked="" type="radio"><label for="tab1"><span class="tab-button header-icon-text w3-padding w3-center w3-text-white w3-round-large w3-border-white w3-topbar w3-bottombar w3-rightbar w3-leftbar w3-card-4" style="background-color:hsla(200, 100%, 25%, .8);"><img class="header-icon" alt="Credit Card" src="https://cdn.shopify.com/s/files/1/0018/0273/1609/files/if_creditcard_1055079.png"> Payments</span></label><!-- Radio button and label for #tab-content2 --><input class="tab-button" name="tabs" id="tab2" type="radio"><label for="tab2"><span class="tab-button header-icon-text w3-padding w3-center w3-text-white w3-round-large w3-border-white w3-topbar w3-bottombar w3-rightbar w3-leftbar w3-card-4" style="background-color:hsla(200, 100%, 25%, .8);"><img class="header-icon" alt="Dolly" src="https://cdn.shopify.com/s/files/1/0018/0273/1609/files/if_dolly_1055070.png"> Shipping</span></label><!-- Radio button and label for #tab-content3 --><input class="tab-button" name="tabs" id="tab3" type="radio"><label for="tab3"><span class="tab-button header-icon-text w3-padding w3-center w3-text-white w3-round-large w3-border-white w3-topbar w3-bottombar w3-rightbar w3-leftbar w3-card-4" style="background-color:hsla(200, 100%, 25%, .8);"><img class="header-icon" alt="Delivery Truck" src="https://cdn.shopify.com/s/files/1/0018/0273/1609/files/if_truck_1054949.png"> Return</span> </label><div id="tab-content1" class="tab-content"><div class="tab-alternate-header w3-center w3-text-white w3-round-large w3-border-white w3-topbar w3-bottombar w3-rightbar w3-leftbar w3-card-4" style="background-color:hsla(200, 100%, 25%, .8);"><h2 class="header-icon-text"><img class="header-icon" alt="Credit Card" src="https://cdn.shopify.com/s/files/1/0018/0273/1609/files/if_creditcard_1055079.png"> Payments</h2></div><img class="paypal-logo w3-image w3-border-0 w3-right w3-padding" alt="PayPal Seal" src="https://cdn.shopify.com/s/files/1/0018/0273/1609/files/paypal-verified.png"><p>We accept PayPal and all major credit cards through secure payment processor PayPal.</p><ul><li>We charge 6% sales tax for items shipped to the state of Virginia.</li><li>Payment must be received in full within 3 days from the date of purchase.</li><li>We leave positive eBay feedback as soon as the payment clears.</li></ul></div><!-- #tab-content1 --><div id="tab-content2" class="tab-content"><div class="tab-alternate-header w3-center w3-text-white w3-round-large w3-border-white w3-topbar w3-bottombar w3-rightbar w3-leftbar w3-card-4" style="background-color:hsla(200, 100%, 25%, .8);"><h2 class="header-icon-text"><img class="header-icon" alt="Dolly" src="https://cdn.shopify.com/s/files/1/0018/0273/1609/files/if_dolly_1055070.png"> Shipping</h2></div>';
var DescriptionFreeShipping = '<p>We offer free USPS Economy or Media Mail, expedited service is available at an additional cost.</p>';
var DescriptionTradingCardShipping = '<p>Standard USPS shipping without Tracking Number. Expedited service with tracking number and top loader available at an extra cost.</p>';
var Description4 = '<ul><li>All items will be shipped from the United States.</li><li>We will only ship to the confirmed PayPal address. Please make sure it matches your shipping address.</li><li>Shipping Monday through Saturday, excluding federal holidays, within 24 hours after payment is received.</li><li>If a tracking number is provided by the shipping carrier, we will update your order with the tracking information.</li><li>Shipping Outside of the United States incurs additional shipping charges.</li></ul></div><!-- #tab-content2 --><div id="tab-content3" class="tab-content"><div class="tab-alternate-header w3-center w3-text-white w3-round-large w3-border-white w3-topbar w3-bottombar w3-rightbar w3-leftbar w3-card-4" style="background-color:hsla(200, 100%, 25%, .8);"><h2 class="header-icon-text"><img class="header-icon" alt="Delivery Truck" src="https://cdn.shopify.com/s/files/1/0018/0273/1609/files/if_truck_1054949.png"> Return</h2></div><p>Please <a href="https://contact.ebay.com/ws/eBayISAPI.dll?ContactUserNextGen&amp;recipient=muna_trading" target="_blank">contact us</a> before returning an item or leaving negative feedback. We will get back to you immediately and work with you to make your purchase right. </p></div><!-- #tab-content3 --></div></div><footer class="w3-container w3-center"><div class="w3-container w3-center w3-padding"><a class="header-button-1 w3-button w3-round-xlarge w3-border w3-border-black w3-white" href="https://stores.ebay.com/munatrading" target="_blank"><img alt="Sales Tag" src="https://cdn.shopify.com/s/files/1/0018/0273/1609/files/if_shop_1054978.png" width="35px" height="35px"> Other Items</a><a class="header-button-2 w3-button w3-round-xlarge w3-border w3-border-black w3-white" href="https://feedback.ebay.com/ws/eBayISAPI.dll?ViewFeedback2&amp;userid=muna_trading&amp;ftab=AllFeedback" target="_blank"><img alt="Paper and pencil" src="https://cdn.shopify.com/s/files/1/0018/0273/1609/files/if_compose_1055085.png" width="35px" height="35px"> Feedbacks</a><a class="header-button-3 w3-button w3-round-xlarge w3-border w3-border-black w3-white" href="https://www.ebay.com/usr/muna_trading" target="_blank"><img alt="Contacts" src="https://cdn.shopify.com/s/files/1/0018/0273/1609/files/if_contacts_1055082.png" width="35px" height="35px"> About Us</a><a class="header-button-4 w3-button w3-round-xlarge w3-border w3-border-black w3-white" href="https://contact.ebay.com/ws/eBayISAPI.dll?ContactUserNextGen&amp;recipient=muna_trading" target="_blank"><img alt="Envelope" src="https://cdn.shopify.com/s/files/1/0018/0273/1609/files/if_mail_1055030.png" width="35px" height="35px"> Contact Us</a><a class="header-button-5 w3-button w3-round-xlarge w3-border w3-border-black w3-white" href="https://my.ebay.com/ws/eBayISAPI.dll?AcceptSavedSeller&amp;mode=0&amp;preference=0&amp;ssPageName=STRK:MEFS:ADDMP&amp;sellerid=muna_trading" target="_blank"><img alt="Heart" src="https://cdn.shopify.com/s/files/1/0018/0273/1609/files/if_heart_1055045.png" width="35px" height="35px"> Add To Favorites</a></div><div class="w3-container w3-center w3-padding"><img class="header-logo w3-image" src="https://cdn.shopify.com/s/files/1/0018/0273/1609/files/MUNA_-_Logo_100x100.png" alt="MUNA Logo"></div><p>Thanks so much for looking at our auction and please do not hesitate to <a href="https://contact.ebay.com/ws/eBayISAPI.dll?ContactUserNextGen&amp;recipient=muna_trading" target="_blank">contact us</a> should you have any questions!</p></footer></div>';
var DescCore = '';
var ImageURLs = [];
var imagesToUpload = 0;
var imageUploadError = false;
var titlesToRead = 0;
var upc = '';


// Initialize Configuration Variables
function initConfig() {
        var i;
        var j;

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

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

        categoryValues();
        requireNewVerify();

        //document.getElementById('title').addEventListener('paste', reformatPastedTitle);

        makePropertyWritable(window, "navigator", "userAgent");
        originalUserAgent = window.navigator.userAgent;

        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function() {
                if (this.readyState == 4 && this.status == 200) {
                        //window.alert(this.responseText);

                        var parser = new DOMParser();
                        var htmlDoc = parser.parseFromString(this.responseText, "text/html");
                        var x = htmlDoc.getElementsByTagName("a");

                        listItems = [];
                        additionalPictures = [];
                        titlesToRead = 0;

                        for (i = 0, j = 0; i < x.length; i++) {
                                if (htmlDoc.getElementsByTagName("a")[i].innerHTML.endsWith(configImage1Extension)) {
                                        var n = htmlDoc.getElementsByTagName("a")[i].innerHTML.lastIndexOf(configImage1Extension);
                                        listItems[j] = htmlDoc.getElementsByTagName("a")[i].innerHTML.substr(0, n);
                                        ++titlesToRead;
                                        getTitleFromeBay(listItems[j], j);
                                        j++;
                                }
                        }

                        for (i = 0; i < x.length; i++) {
                                if (htmlDoc.getElementsByTagName("a")[i].innerHTML.endsWith(configImage1Extension) ||
                                        htmlDoc.getElementsByTagName("a")[i].innerHTML.endsWith(configImage2Extension) ||
                                        htmlDoc.getElementsByTagName("a")[i].innerHTML.endsWith(configdescriptionImageExtension)) {
                                        continue;
                                }

                                if (htmlDoc.getElementsByTagName("a")[i].innerHTML.endsWith(".jpg")) {
                                        for (j = 0; j < listItems.length; j++) {
                                                if (htmlDoc.getElementsByTagName("a")[i].innerHTML.startsWith(listItems[j]) && !htmlDoc.getElementsByTagName("a")[i].innerHTML.endsWith(" - small.jpg")) {
                                                        if (additionalPictures[j] === undefined) {
                                                                additionalPictures[j] = [];
                                                        }
                                                        additionalPictures[j].push(htmlDoc.getElementsByTagName("a")[i].innerHTML);
                                                }
                                        }
                                }
                        }

                        function checkTitlesToRead() {
                                if (titlesToRead > 0) {
                                        window.setTimeout(checkTitlesToRead, 100); // wait 100 milliseconds
                                } else {
                                        sortList(document.getElementById("keyword"));
                                        document.getElementById("keyword").selectedIndex = 0;
                                        $(document.getElementById("keyword")).trigger("chosen:updated");
                                        document.getElementById("bookDetails").className += " w3-hide";
                                        document.getElementById("cdDetails").className += " w3-hide";
                                        document.getElementById("dvdDetails").className += " w3-hide";
                                }
                        }

                        checkTitlesToRead();
                }
        };
        xhttp.open("GET", configListingUrl + '?t=' + Math.random(), true);
        xhttp.send();
}

function sortList(lb) {
        var arrTexts = new Array();
        var res;
        var i;

        for (i = 1; i < lb.length; i++) {
                arrTexts[i - 1] = lb.options[i].style.color + '|' + lb.options[i].id + '|' + lb.options[i].text;
        }

        arrTexts.sort();

        for (i = 0; i < arrTexts.length; i++) {
                res = arrTexts[i].split('|');
                lb.options[i + 1].style.color = res[0];
                lb.options[i + 1].id = res[1];
                lb.options[i + 1].value = res[1];
                lb.options[i + 1].text = res[2];
        }
}

function getTitleFromeBay(identifier, index) {
        // Construct the request
        url = configeBayShopping + "?";
        url += "callname=FindProducts";
        url += "&version=" + configeBayShoppingVersion;
        url += "&appid=" + configAppid;
        url += "&responseencoding=JSON";
        url += "&siteid=0";
        url += "&AvailableItemsOnly=true";
        url += "&MaxEntries=1";
        url += "&MessageID=";
        url += index;
        url += "&QueryKeywords=";
        url += encodeURIComponent(identifier.trim().replace(/ /g, "+"));

        var xhttp = new XMLHttpRequest();

        xhttp.onreadystatechange = function() {
                if (this.readyState == 4) {
                        _cb_getTitleFromeBay(JSON.parse(this.responseText));
                }
        };

        xhttp.open("GET", configProxyUrl, true);
        xhttp.setRequestHeader("X-Proxy-Url", encodeURI(url));
        xhttp.send();

        return false;
}

// Create new page for single item
function _cb_getTitleFromeBay(root) {
        var optionsAsString;
        var JsonObj;
        var color;

        if (root.Ack != 'Success') {
                color = 'purple';
                if (isNumeric((listItems[root.CorrelationID]))) {
                        if (listItems[root.CorrelationID].substr(0, 3) == '978' || listItems[root.CorrelationID].substr(0, 3) == '979') {
                                if (!isValidISBNCode(listItems[root.CorrelationID])) {
                                        color = 'red';
                                }
                        } else {
                                if (!isValidUpcOrEanCode(listItems[root.CorrelationID])) {
                                        color = 'red';
                                }
                        }
                }

                optionsAsString = "<option id='" + escapeHtml(listItems[root.CorrelationID]) + "' " + "value='" + escapeHtml(listItems[root.CorrelationID]) + "'>" + listItems[root.CorrelationID] + "</option>";
                document.getElementById("keyword").innerHTML += optionsAsString;
                document.getElementById(listItems[root.CorrelationID]).style.color = color;
        } else {
                JsonObj = typeof root.Product[0] != 'object' ? JSON.parse(root.Product[0]) : root.Product[0];
                optionsAsString = "<option id='" + escapeHtml(listItems[root.CorrelationID]) + "' " + "value='" + escapeHtml(listItems[root.CorrelationID]) + "'>" + listItems[root.CorrelationID] + " - " + JsonObj.Title + "</option>";
                document.getElementById("keyword").innerHTML += optionsAsString;
        }

        --titlesToRead;
}

// Create new page for single item
function _cb_FindProducts(root) {
        var j;
        var x;
        var ack = root.Ack;
        var MoreResults = root.MoreResults;

        if (ack != 'Success' || MoreResults) {
                x = document.getElementById("productinfo");
                if (root.Errors !== undefined && root.Errors[0].ShortMessage != 'No match found.') {
                        x.innerHTML = "<h2>eBay API Error<h2>";
                        x.innerHTML += "<p>Id: " + root.Errors[0].ErrorCode + "<br/>";
                        x.innerHTML += "Domain: " + root.Errors[0].ErrorClassification + "<br/>";
                        x.innerHTML += "Severity: " + root.Errors[0].SeverityCode + "<br/>";
                        x.innerHTML += "Category: " + root.Errors[0].category + "<br/>";
                        x.innerHTML += "Short Message: " + root.Errors[0].ShortMessage + "<br/>";
                        x.innerHTML += "Long Message: " + root.Errors[0].LongMessage + "<br/>";
                        x.innerHTML += "Build/Version: " + root.Build + '/' + root.Version + "</p>";
                        x.innerHTML += "<p>URL: " + "<a href=\"" + url + "\" target=\"_blank\">" + url + "</a>" + "</p>";
                } else {
                        x.innerHTML = '<h2 class="w3-red">Manual Mode</h3>';
                        x.innerHTML += "<h3>" + document.getElementById("keyword").value + "</h3>";
                        catalogTitle = document.getElementById("keyword").value;
                        if (isNumeric(catalogTitle)) {
                                if (catalogTitle.startsWith('978') || catalogTitle.startsWith('979')) {
                                        x.innerHTML += '<p>Search on <a href="https://isbnsearch.org/isbn/' + catalogTitle + '" target="blank">isbnsearch.com</a></p>';
                                        x.innerHTML += '<p>Search on <a href="https://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Dpopular&field-keywords=' + catalogTitle + '" target="blank">amazon.com</a></p>';
                                        x.innerHTML += '<p>Search on <a href="https://ujsoftware.linkpc.net/ebay/search.html?keyword=' + encodeURIComponent(catalogTitle.trim()) + '&listingType=All&hideDuplicateItems=on&locatedIn=WorldWide&sortOrder=PricePlusShippingLowest&results=100" target="blank">eBay</a></p>';
                                } else {
                                        x.innerHTML += '<p>Search on <a href="https://dvdlist.kazart.com/queryDVDList.php3?search=' + catalogTitle + '&select=UPC&Submit=Search&since=All&genre=All&date=All&status=All&sort1=title&sort1by=ASC&sort2=year&sort2by=ASC&sort3=genre&sort3by=ASC" target="blank">kazart.com</a></p>';
                                        x.innerHTML += '<p>Search on <a href="https://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords=' + catalogTitle + '" target="blank">amazon.com</a></p>';
                                        x.innerHTML += '<p>Search on <a href="https://ujsoftware.linkpc.net/ebay/search.html?keyword=' + encodeURIComponent(catalogTitle.trim()) + '&listingType=All&hideDuplicateItems=on&locatedIn=WorldWide&sortOrder=PricePlusShippingLowest&results=100" target="blank">eBay</a></p>';
                                }
                        } else {
                                catalogTitle = document.getElementById("keyword").value.trim();
                                splitTradingCardElements();
                                fillForm();

                                x.innerHTML += '<p>Search on <a href="https://ujsoftware.linkpc.net/ebay/search.html?keyword=' + encodeURIComponent(catalogTitle.trim()) + '&listingType=All&hideDuplicateItems=on&locatedIn=WorldWide&sortOrder=PricePlusShippingLowest&results=100" target="blank">eBay</a></p>';
                        }

                        printManualButtons();
                }

                unsetAdditionalImages();

                for (i = 0; i < additionalPictures.length; i++) {
                        if (additionalPictures[i] !== undefined && additionalPictures[i][0].startsWith(document.getElementById("keyword").value.trim())) {
                                if (additionalPictures[i].length > 5) {
                                        document.getElementById("productinfo").innerHTML += '<p class="w3-red"><strong>Too many additional images.</a></strong></p>';
                                } else {
                                        for (j = 0; j < additionalPictures[i].length; j++) {
                                                setAdditionalImage(j + 3, additionalPictures[i][j]);
                                        }
                                }
                        }
                }

                document.getElementById("image1").src = configListingUrl + document.getElementById("keyword").value.trim() + configImage1Extension;
                document.getElementById("image2").src = configListingUrl + document.getElementById("keyword").value.trim() + configImage2Extension;
                document.getElementById("descriptionImage").src = configListingUrl + document.getElementById("keyword").value.trim() + configdescriptionImageExtension;
                document.getElementById("image1anchor").href = document.getElementById("image1").src;
                document.getElementById("image2anchor").href = document.getElementById("image2").src;

                isManualMode = true;
                catalogActorNames = '';

                isDuplicate = false;
                findDuplicateListing();
                findPotentialDuplicateListing();
                findShopifyDuplicateListing();

                upc = catalogTitle;

                return;
        }

        isManualMode = false;

        var str = "";
        var i = 0;
        var JsonObj = typeof root.Product[0] != 'object' ? JSON.parse(root.Product[0]) : root.Product[0];

        var DetailsURL = JsonObj.DetailsURL;
        var ItemSpecifics = JsonObj.ItemSpecifics;
        var StockPhotoURL = JsonObj.StockPhotoURL;
        var ProductID = JsonObj.ProductID;
        var TotalProducts = Number(root.TotalProducts);
        var searchStr = '';
        var munaSearchStr = '';

        catalogTitle = JsonObj.Title;
        catalogActorNames = '';

        str = '';
        DescCore = '';

        if (StockPhotoURL && StockPhotoURL.length > 1) {
                if (DetailsURL && DetailsURL.length > 1) {
                        str += '<a href="' + DetailsURL + '" target="_blank">';
                }
                str += '<img class="w3-image w3-right w3-margin" src="' + StockPhotoURL + '" alt="Gallery Image" style="max-height:100px;max-width:100px;">';
                if (DetailsURL && DetailsURL.length > 1) {
                        str += '</a>';
                }
        }

        str += '<h3>' + catalogTitle + '</h3>';

        str += '<p>';

        eBayProductId = '';
        upc = catalogTitle;
        if (ProductID) {
                for (i = 0; i < ProductID.length; i++) {
                        if (ProductID[i].Type == 'Reference') {
                                str += ProductID[i].Type + ': ' + ProductID[i].Value + '<br/>';
                                munaSearchStr = 'ReferenceID%3A' + ProductID[i].Value;
                                eBayProductId = ProductID[i].Value;
                        } else {
                                str += ProductID[i].Type + ': ' + ProductID[i].Value + '<br/>';
                                searchStr = ProductID[i].Value;
                                if (ProductID[i].Type == 'UPC') {
                                        upc = ProductID[i].Value;
                                }
                        }
                }
        }

        if (ItemSpecifics) {
                for (i = 0; i < ItemSpecifics.NameValueList.length; i++) {
                        str += ItemSpecifics.NameValueList[i].Name + ': ' + ItemSpecifics.NameValueList[i].Value + '<br/>';

                        if (ItemSpecifics.NameValueList[i].Name == 'Leading Role') {
                                catalogActorNames = ItemSpecifics.NameValueList[i].Value;
                        }
                }
        }

        str += '</p>';

        if (MoreResults) {
                str += '<p class="w3-right w3-red">' + TotalProducts + ' Products found</p>';
        }

        if (catalogTitle.includes(movieFormats[0]) || catalogTitle.includes(movieFormats[1]) || catalogTitle.includes(movieFormats[2])) {
                str += '<p>Search on <a href="https://dvdlist.kazart.com/queryDVDList.php3?search=' + searchStr + '&select=UPC&Submit=Search&since=All&genre=All&date=All&status=All&sort1=title&sort1by=ASC&sort2=year&sort2by=ASC&sort3=genre&sort3by=ASC" target="blank">kazart.com</a></p>';
        } else if (catalogTitle.includes('Paperback') || catalogTitle.includes('Hardcover')) {
                str += '<p>Search on <a href="https://isbnsearch.org/isbn/' + searchStr + '" target="blank">isbnsearch.com</a></p>';
        }

        str += '<p>Search on <a href="https://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords=' + searchStr + '" target="blank">amazon.com</a></p>';
        str += '<p>Search on <a href="https://ujsoftware.linkpc.net/ebay/search.html?keyword=' + (munaSearchStr.length > 0 ? munaSearchStr : encodeURIComponent(searchStr.trim())) + '&listingType=All&hideDuplicateItems=on&locatedIn=WorldWide&sortOrder=PricePlusShippingLowest&results=100" target="blank">eBay</a></p>';

        x = document.getElementById("productinfo");
        x.innerHTML = str;


        isDuplicate = false;
        findDuplicateListing();
        findPotentialDuplicateListing();
        findShopifyDuplicateListing();

        fillForm(ItemSpecifics);
}

function printManualButtons() {
        var x = document.getElementById("productinfo");
        if (!x.innerHTML.includes('fillManualForm0')) {
                x.innerHTML += '<p><br/></p>';
                x.innerHTML += '<a href="javascript:void(0)" id="fillManualForm0" class="w3-btn-2 w3-black w3-margin w3-round-large w3-ripple" onclick="fillManualForm(0)">Fill Book Form</a>';
                x.innerHTML += '<a href="javascript:void(0)" id="fillManualForm1" class="w3-btn-2 w3-black w3-margin w3-round-large w3-ripple" onclick="fillManualForm(1)">Fill CD Form</a>';
                x.innerHTML += '<a href="javascript:void(0)" id="fillManualForm2" class="w3-btn-2 w3-black w3-margin w3-round-large w3-ripple" onclick="fillManualForm(2)">Fill DVD Form</a>';
                x.innerHTML += '<a href="javascript:void(0)" id="fillManualForm3" class="w3-btn-2 w3-black w3-margin w3-round-large w3-ripple" onclick="fillManualForm(3)">Fill Trading Card Form</a>';
        }
}

function setAdditionalImage(imageNumber, imageName) {
        if (imageName !== undefined) {
                document.getElementById("image" + imageNumber).src = configListingUrl + imageName.trim();
                document.getElementById("image" + imageNumber + "anchor").className += " w3-show";
                document.getElementById("image" + imageNumber + "anchor").href = document.getElementById("image" + imageNumber).src;
        }
}

function unsetAdditionalImages() {
        for (var i = 3; i <= 7; i++) {
                document.getElementById("image" + i).src = '';
                document.getElementById("image" + i + "anchor").className = document.getElementById("image" + i + "anchor").className.replace(" w3-show", "");
                document.getElementById("image" + i + "anchor").href = '';
        }
}

function requireNewVerify() {
        listButtonHot(false);
}

function requireNewLogin() {
        // dummy
}

function hideDetailWindows() {
        var x, y;

        x = document.getElementById("bookDetails");
        x.className = x.className.replace(" w3-show", "");
        document.getElementById("bookForm").reset();
        x = document.getElementById("cdDetails");
        x.className = x.className.replace(" w3-show", "");
        document.getElementById("cdForm").reset();
        x = document.getElementById("dvdDetails");
        x.className = x.className.replace(" w3-show", "");
        document.getElementById("dvdForm").reset();
        x = document.getElementById("tradingCardDetails");
        x.className = x.className.replace(" w3-show", "");
        document.getElementById("tradingCardForm").reset();
        document.getElementById("cdTracks").innerHTML = "";
        document.getElementById("cdUnorderedTrackList").checked = false;

        for (var imageNumber = 0; imageNumber < 5; imageNumber++) {
                x = document.getElementById("image" + (imageNumber + 3) + "anchor");
                y = document.getElementById("image" + (imageNumber + 3));

                if (x.className.includes("w3-show")) {
                        x.className = x.className.replace(" w3-show", "");
                        x.href = '';
                        y.src = '';
                }
        }
}

var url = "";

function findOneBay() {
        var n;
        var keyword;

        if (document.getElementById("list").className.includes("w3-green")) {
                alert("Listing verified but not yet submitted");
                return;
        }

        requireNewVerify();

        hideDetailWindows();

        ImageURLs = [];

        if (!document.getElementById("keyword").value) {
                return false;
        }

        if (document.getElementById("keyword").value.endsWith(" Front")) {
                n = document.getElementById("keyword").value.lastIndexOf(" Front");
                document.getElementById("keyword").value = document.getElementById("keyword").value.substr(0, n);
        } else if (document.getElementById("keyword").value.endsWith(" Rear")) {
                n = document.getElementById("keyword").value.lastIndexOf(" Rear");
                document.getElementById("keyword").value = document.getElementById("keyword").value.substr(0, n);
        }

        keyword = document.getElementById('keyword').value;

        // Clear results outputs button
        clearStatusWindows();

        discogsQty = 1;

        // Construct the request
        url = configeBayShopping + "?";
        url += "callname=FindProducts";
        url += "&version=" + configeBayShoppingVersion;
        url += "&appid=" + configAppid;
        url += "&responseencoding=JSON";
        url += "&siteid=0";
        url += "&AvailableItemsOnly=true";
        url += "&MaxEntries=1";
        url += "&QueryKeywords=";
        url += encodeURIComponent(keyword.trim().replace(/ /g, "+"));

        var xhttp = new XMLHttpRequest();

        xhttp.onreadystatechange = function() {
                if (this.readyState == 4) {
                        _cb_FindProducts(JSON.parse(this.responseText));
                }
        };

        xhttp.open("GET", configProxyUrl, true);
        xhttp.setRequestHeader("X-Proxy-Url", encodeURI(url));
        xhttp.send();

        getPricing();

        return false;
}

function fillForm(ItemSpecifics) {
        var eBayTitle;
        var fieldName;
        var field;
        var n;
        var i;
        var j;
        var x;
        var movieIndex = 0;
        var titleField = document.getElementById("title");

        eBayTitle = catalogTitle;
        if (catalogActorNames.length > 0) {
                eBayTitle += ' ' + catalogActorNames.join(', ');
        }

        document.getElementById("title").value = eBayTitle;
        printTitleLength();

        if (catalogTitle.includes("(CD")) {
                findDiscogsReleases(document.getElementById("keyword").value);

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

                if (!isManualMode) {
                        titleField.value = reformatCdTitle(catalogTitle);
                        printTitleLength();
                }

                if (titleField.value.endsWith(' (Label))')) {
                        titleField.value = titleField.value.substr(0, titleField.value.indexOf(' (Label))')) + ')';
                        printTitleLength();
                }

                if (titleField.value.endsWith(' (USA))')) {
                        titleField.value = titleField.value.substr(0, titleField.value.indexOf(' (USA))')) + ')';
                        printTitleLength();
                }

                document.getElementById("cdCountry").value = configDefaultCountry;

                if (ItemSpecifics) {
                        for (i = 0; i < ItemSpecifics.NameValueList.length; i++) {
                                fieldName = 'cd' + ItemSpecifics.NameValueList[i].Name.replace(/ /g, '');
                                field = document.getElementById(fieldName);
                                if (field) {
                                        field.value = ItemSpecifics.NameValueList[i].Value;
                                }
                        }
                }
                $('#cdGenre').prop('disabled', false).trigger("chosen:updated");

                if (titleField.value.indexOf('[EP]') > 0) {
                        document.getElementById("cdDuration").value = 'EP';
                } else if (titleField.value.indexOf('[Maxi-Single]') > 0 || titleField.value.indexOf('[Maxi Single]') > 0) {
                        document.getElementById("cdDuration").value = 'Maxi-Single';
                } else if (titleField.value.indexOf('[Single]') > 0) {
                        document.getElementById("cdDuration").value = 'Single';
                }
                $('#cdDuration').prop('disabled', false).trigger("chosen:updated");

                if (titleField.value.indexOf('[Digipak]') > 0) {
                        document.getElementById("cdDigipak").checked = true;
                }

                if (document.getElementById("cdArtist").value.length < 1) {
                        if (titleField.value.substr(0, titleField.value.includes('Various Artists'))) {
                                document.getElementById("cdArtist").value = 'Various';
                        } else {
                                document.getElementById("cdArtist").value = titleField.value.substr(0, titleField.value.indexOf(' - '));
                        }
                }

                if (document.getElementById("cdRecordLabel").value.length < 1) {
                        n = titleField.value.indexOf('(CD');
                        document.getElementById("cdRecordLabel").value = titleField.value.substr(n).substr(titleField.value.substr(n).lastIndexOf(',') + 2);
                        document.getElementById("cdRecordLabel").value = document.getElementById("cdRecordLabel").value.substr(0, document.getElementById("cdRecordLabel").value.lastIndexOf(')'));
                }

                if (document.getElementById("cdReleaseYear").value.length < 1) {
                        n = titleField.value.indexOf('(CD');
                        document.getElementById("cdReleaseYear").value = getYear(titleField.value.substr(n));
                }

                document.getElementById("category").value = "176984";
                $(document.getElementById("category")).trigger("chosen:updated");
                categoryValues();
        } else if (catalogTitle.includes(movieFormats[0]) || catalogTitle.includes(movieFormats[1]) || catalogTitle.includes(movieFormats[2])) {
                x = document.getElementById("dvdDetails");
                if (x.className.indexOf("w3-show") == -1) {
                        x.className += " w3-show";
                }

                document.getElementById("dvdCountry").value = configDefaultCountry;

                if (ItemSpecifics) {
                        for (i = 0; i < ItemSpecifics.NameValueList.length; i++) {
                                fieldName = 'dvd' + ItemSpecifics.NameValueList[i].Name.replace(/ /g, '');
                                field = document.getElementById(fieldName);
                                if (field) {
                                        field.value = ItemSpecifics.NameValueList[i].Value;
                                }
                        }
                }
                $('#dvdGenre').prop('disabled', false).trigger("chosen:updated");
                $('#dvdRating').prop('disabled', false).trigger("chosen:updated");
                $('#dvdRegionCode').prop('disabled', false).trigger("chosen:updated");
                $('#dvdRental').prop('disabled', false).trigger("chosen:updated");
                $('#dvdSeason').prop('disabled', false).trigger("chosen:updated");

                for (i = 0; i < movieFormats.length; i++) {
                        if (catalogTitle.includes('(' + movieFormats[i])) {
                                document.getElementById("dvdFormat").value = movieFormats[i];
                                movieIndex = i;
                        } else if (catalogTitle.includes('(HD-DVD')) {
                                document.getElementById("dvdFormat").value = 'HD DVD';
                                movieIndex = i;
                        }
                }
                $('#dvdFormat').prop('disabled', false).trigger("chosen:updated");

                if (document.getElementById("dvdReleaseYear").value.length < 1) {
                        n = titleField.value.indexOf('(' + movieFormats[movieIndex]);
                        document.getElementById("dvdReleaseYear").value = getYear(titleField.value.substr(n));
                }

                if (document.getElementById("dvdDVDEditionYear").value.length < 1) {
                        n = titleField.value.indexOf('(' + movieFormats[movieIndex]);
                        document.getElementById("dvdDVDEditionYear").value = getYear(titleField.value.substr(n));
                }

                if (document.getElementById("dvdTitle").value.length < 1) {
                        n = titleField.value.lastIndexOf('(' + movieFormats[movieIndex]);
                        document.getElementById("dvdTitle").value = titleField.value.substr(0, n);
                }

                if (titleField.value.indexOf("3D") > 0) {
                        document.getElementById("dvd3D").checked = true;
                }

                if (titleField.value.indexOf("Anniversary") > 0) {
                        document.getElementById("dvdAnniversaryEdition").checked = true;
                }

                if (titleField.value.indexOf("Collector") > 0) {
                        document.getElementById("dvdCollectorsEdition").checked = true;
                }

                if (titleField.value.indexOf("Deluxe") > 0) {
                        document.getElementById("dvdDeluxeEdition").checked = true;
                }

                if (titleField.value.indexOf("Director") > 0) {
                        document.getElementById("dvdDirectorsCut").checked = true;
                }

                if (titleField.value.indexOf("Extended") > 0) {
                        document.getElementById("dvdExtendedEdition").checked = true;
                }

                if (titleField.value.indexOf("Full Screen") > 0 || titleField.value.indexOf("Fullscreen") > 0 ||
                        titleField.value.indexOf("Full Frame") > 0 || titleField.value.indexOf("Fullframe") > 0) {
                        document.getElementById("dvdFullScreen").checked = true;
                }

                if (titleField.value.indexOf("Limited") > 0) {
                        document.getElementById("dvdLimitedEdition").checked = true;
                }

                if (titleField.value.indexOf("Promo") > 0) {
                        document.getElementById("dvdPromo").checked = true;
                }

                if (titleField.value.indexOf("Signature") > 0) {
                        document.getElementById("dvdSignatureCollection").checked = true;
                }

                if (titleField.value.indexOf("Special") > 0) {
                        document.getElementById("dvdSpecialEdition").checked = true;
                }

                if (titleField.value.indexOf("Steelbook") > 0) {
                        document.getElementById("dvdSteelbook").checked = true;
                }

                if (titleField.value.indexOf("Unrated") > 0) {
                        document.getElementById("dvdUnratedEdition").checked = true;
                }

                if (titleField.value.indexOf("Wide Screen") > 0 || titleField.value.indexOf("Widescreen") > 0) {
                        document.getElementById("dvdWidescreen").checked = true;
                }

                document.getElementById("category").value = "617";
                $(document.getElementById("category")).trigger("chosen:updated");
                categoryValues();
        } else if (catalogTitle.includes("Paperback") || catalogTitle.includes("Hardcover")) {
                x = document.getElementById("bookDetails");
                if (x.className.indexOf("w3-show") == -1) {
                        x.className += " w3-show";
                }

                document.getElementById("bookLanguage").value = configDefaultLanguage;
                document.getElementById("bookCountry").value = configDefaultCountry;
                document.getElementById("bookSubject").value = "";

                if (ItemSpecifics) {
                        for (i = 0; i < ItemSpecifics.NameValueList.length; i++) {
                                fieldName = 'book' + ItemSpecifics.NameValueList[i].Name.replace(/ /g, '');
                                field = document.getElementById(fieldName);
                                if (field) {
                                        field.value = ItemSpecifics.NameValueList[i].Value;
                                }
                        }
                }

                $('#bookFormat').prop('disabled', false).trigger("chosen:updated");
                $('#bookSubject').prop('disabled', false).trigger("chosen:updated");

                document.getElementById("category").value = "171243";
                $(document.getElementById("category")).trigger("chosen:updated");
                categoryValues();
        } else {
                printManualButtons();
        }

        function toDataURL(url) {
                var xhr = new XMLHttpRequest();
                xhr.onload = function() {
                        var reader = new FileReader();
                        reader.onloadend = function() {
                                DescImage = reader.result;
                        };
                        reader.readAsDataURL(xhr.response);
                };
                xhr.open('GET', url);
                xhr.responseType = 'blob';
                xhr.send();
        }

        toDataURL(configListingUrl + document.getElementById("keyword").value.trim() + configdescriptionImageExtension);
        document.getElementById("image1").src = configListingUrl + document.getElementById("keyword").value.trim() + configImage1Extension;
        document.getElementById("image2").src = configListingUrl + document.getElementById("keyword").value.trim() + configImage2Extension;
        document.getElementById("descriptionImage").src = configListingUrl + document.getElementById("keyword").value.trim() + configdescriptionImageExtension;
        document.getElementById("image1anchor").href = document.getElementById("image1").src;
        document.getElementById("image2anchor").href = document.getElementById("image2").src;
        unsetAdditionalImages();

        for (i = 0; i < additionalPictures.length; i++) {
                if (additionalPictures[i] !== undefined && additionalPictures[i][0].startsWith(document.getElementById("keyword").value.trim())) {
                        if (additionalPictures[i].length > 5) {
                                document.getElementById("productinfo").innerHTML += '<p class="w3-red"><strong>Too many additional images.</a></strong></p>';
                        } else {
                                for (j = 0; j < additionalPictures[i].length + 4; j++) {
                                        setAdditionalImage(j + 3, additionalPictures[i][j]);
                                }
                        }
                }
        }
}

function getYear(str) {
        return str.match(/[12][0-9][0-9][0-9]/);
}

function fillManualForm(type) {
        var n;
        var x;

        hideDetailWindows();

        if (document.getElementById("format").value.length <= 1) {
                document.getElementById("format").value = auctionFormat[type];
                $(document.getElementById("format")).trigger("chosen:updated");
        }

        if (type === 0) {
                document.getElementById("category").value = "171243";
                $(document.getElementById("category")).trigger("chosen:updated");
                if (isNumeric(catalogTitle)) {
                        document.getElementById("bookISBN").value = catalogTitle;
                } else {
                        document.getElementById("bookISBN").value = configDoesNotApply;
                }
                document.getElementById("bookLanguage").value = configDefaultLanguage;
                document.getElementById("bookCountry").value = configDefaultCountry;
                categoryValues();
                x = document.getElementById("bookDetails");
                if (x.className.indexOf("w3-show") == -1) {
                        x.className += " w3-show";
                }

                document.getElementById("bookFormat").selectedIndex = 0;
                $('#bookFormat').prop('disabled', false).trigger("chosen:updated");
                document.getElementById("bookSubject").value = "";
                $('#bookSubject').prop('disabled', false).trigger("chosen:updated");
        } else if (type == 1) {
                document.getElementById("category").value = "176984";
                $(document.getElementById("category")).trigger("chosen:updated");
                if (isNumeric(catalogTitle)) {
                        document.getElementById("cdUPC").value = catalogTitle;
                } else {
                        document.getElementById("cdUPC").value = configDoesNotApply;
                        if ((n = catalogTitle.indexOf(" - ")) > 0) {
                                document.getElementById("cdArtist").value = catalogTitle.substr(0, n);
                        }
                }
                document.getElementById("cdCountry").value = configDefaultCountry;
                categoryValues();

                document.getElementById("cdDuration").selectedIndex = 1;
                document.getElementById("cdGenre").selectedIndex = 0;
                $('#cdDuration').prop('disabled', false).trigger("chosen:updated");
                $('#cdGenre').prop('disabled', false).trigger("chosen:updated");

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

                findDiscogsReleases(document.getElementById("keyword").value);
        } else if (type == 2) {
                document.getElementById("category").value = "617";
                $(document.getElementById("category")).trigger("chosen:updated");
                if (isNumeric(catalogTitle)) {
                        document.getElementById("dvdUPC").value = catalogTitle;
                } else {
                        document.getElementById("dvdUPC").value = configDoesNotApply;
                }
                document.getElementById("dvdCountry").value = configDefaultCountry;
                categoryValues();
                x = document.getElementById("dvdDetails");
                if (x.className.indexOf("w3-show") == -1) {
                        x.className += " w3-show";
                }

                document.getElementById("dvdFormat").value = 'DVD';
                document.getElementById("dvdGenre").selectedIndex = 0;
                document.getElementById("dvdRating").selectedIndex = 0;
                document.getElementById("dvdRegionCode").value = 'DVD: 1 (US, Canada...)';
                document.getElementById("dvdRental").value = 'No';
                document.getElementById("dvdSeason").selectedIndex = 0;
                $('#dvdFormat').prop('disabled', false).trigger("chosen:updated");
                $('#dvdGenre').prop('disabled', false).trigger("chosen:updated");
                $('#dvdRating').prop('disabled', false).trigger("chosen:updated");
                $('#dvdRegionCode').prop('disabled', false).trigger("chosen:updated");
                $('#dvdRental').prop('disabled', false).trigger("chosen:updated");
                $('#dvdSeason').prop('disabled', false).trigger("chosen:updated");
        } else if (type == 3) {
                catalogTitle = document.getElementById("keyword").value.trim();
                splitTradingCardElements();
        }

        fillForm();
}

function resetForm() {
        var i;

        document.getElementById("searchForm").reset();
        document.getElementById("listForm").reset();
        document.getElementById("productinfo").innerHTML = "<p>Product Info</p>";
        initConfig();
        clearStatusWindows();
        for (i = 1; i <= 7; i++) {
                document.getElementById("image" + i).src = "";
        }
        document.getElementById("descriptionImage").src = "";
        hideDetailWindows();
}

function verifyListingImage() {
        if (eBayAuthTokenFlag === false) {
                return;
        }
        if (isDuplicate) {
                window.alert("This is a duplicate.");
                return;
        }

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

        if (ImageURLs.length === 0) {
                uploadSiteHostedPictures();
        } else {
                verifyListing();
        }
}

function verifyListing() {
        var i;
        var authErrorFlag = false;

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

        if (!createAddXML(xw, xhr, 'VerifyAddItemRequest', 'VerifyAddItem', false)) {
                return;
        }

        xml = xw.flush();
        xw.close();
        //window.alert(vkbeautify.xml(xml));

        xhr.onload = function() {
                var obj = XMLparse(xhr.responseXML);
                //window.alert(JSON.stringify(obj));
                //window.alert(vkbeautify.xml(xhr.responseText));

                var returnCode = obj.Ack;
                var x = document.getElementById("results");

                if (returnCode == 'Success' ||
                        (returnCode == 'Warning' && (obj.Errors.ErrorCode == '21917108' || obj.Errors.ErrorCode == '21920205' || obj.Errors.ErrorCode == '21917164'))) {
                        listButtonHot(true);

                        x.innerHTML += '<p><strong>' + returnCode + '</strong></p>';

                        if (returnCode == 'Warning') {
                                x.innerHTML += "<p>" + obj.Errors.SeverityCode + " (" + obj.Errors.ErrorCode + "): " + escapeHtml(obj.Errors.LongMessage) + "</p>";
                        }
                        var fees = obj.Fees;
                        x.innerHTML += "<p>";
                        for (i = 0; i < fees.length; i++) {
                                if (fees[i].Fee.text !== "0.0") {
                                        x.innerHTML += fees[i].Name + ": $" + Number(fees[i].Fee.text).toFixed(2) + "<br/>";
                                }
                        }
                        x.innerHTML += "</p>";

                        if (obj.DiscountReason) {
                                x.innerHTML += "<p>Discount Reason: " + obj.DiscountReason + "</p>";
                        }

                        var recommendations = obj.ListingRecommendations;
                        if (recommendations) {
                                if (recommendations.length > 0) {
                                        for (i = 0; i < recommendations.length; i++) {
                                                x.innerHTML += decode(recommendations[i]);
                                        }
                                } else {
                                        x.innerHTML += decode(recommendations);
                                }
                        }
                } else {
                        requireNewVerify();
                        x.innerHTML += "<p><strong>" + returnCode + ":</strong></p>";

                        var errors = obj.Errors;
                        x.innerHTML += "<p>";
                        if (errors.length > 0) {
                                for (i = 0; i < errors.length; i++) {
                                        x.innerHTML += errors[i].SeverityCode + " (" + errors[i].ErrorCode + "): " + escapeHtml(errors[i].LongMessage) + "<br/>";
                                        if (errors[i].LongMessage.includes('Auth')) {
                                                authErrorFlag = true;
                                        }
                                }
                        } else {
                                x.innerHTML += obj.Errors.SeverityCode + " (" + obj.Errors.ErrorCode + "): " + escapeHtml(obj.Errors.LongMessage) + "<br/>";
                                if (errors.LongMessage.includes('Auth')) {
                                        authErrorFlag = true;
                                }
                        }

                        x.innerHTML += "</p>";

                        if (obj.DuplicateInvocationDetails) {
                                x.innerHTML += '<p>Duplicate Invocation Id ' + obj.DuplicateInvocationDetails.DuplicateInvocationID + ' Tracking Id' + obj.DuplicateInvocationDetails.InvocationTrackingID + ' Status ' + obj.DuplicateInvocationDetails.Status + '</p>';
                        }

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

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

        xhr.send(xml);
}

function decode(recommendation) {
        var str = "<p>";
        var i;

        str += recommendation.Code + " (" + recommendation.Type + "/" + recommendation.Group + ") for '" + recommendation.FieldName;
        if (recommendation.Value) {
                str += "': " + recommendation.Value;
        }

        if (recommendation.Message) {
                str += "<br/>" + recommendation.Message;
        }

        var metadata = recommendation.Metadata;
        if (metadata) {
                if (metadata.length > 0) {
                        for (i = 0; i < metadata.length; i++) {
                                if (metadata[i].Name != "correlationId" &&
                                        metadata[i].Name != "currency" &&
                                        metadata[i].Name != "similarItems") {
                                        str += "<br/>" + metadata[i].Name + " = " + metadata[i].Value;
                                }
                        }
                } else {
                        if (metadata.Name != "correlationId" &&
                                metadata.Name != "currency" &&
                                metadata.Name != "similarItems") {
                                str += "<br/>" + metadata.Name + " = " + metadata.Value;
                        }
                }
        }

        str += "</p>";

        return str;
}

function submitListing(saveFlag) {
        var i;
        var authErrorFlag = false;

        if (document.getElementById("list").className.indexOf("w3-green") == -1) {
                return;
        }

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

        createAddXML(xw, xhr, 'AddItemRequest', 'AddItem', saveFlag);

        xml = xw.flush();
        xw.close();
        //window.alert(vkbeautify.xml(xml));

        xhr.onload = function() {
                var obj = XMLparse(xhr.responseXML);
                //window.alert(JSON.stringify(obj));
                //window.alert(vkbeautify.xml(xhr.responseText));

                var returnCode = obj.Ack;

                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' || obj.Errors.ErrorCode == '21920205' || obj.Errors.ErrorCode == '21917164'))) {
                        listButtonHot(false);
                        ImageURLs = [];
                        document.getElementById("title").value = "";
                        printTitleLength();
                        deleteSubmittedEntry();

                        x.innerHTML = '<p><strong>' + returnCode + '</strong>, Item Id <a href="https://www.ebay.com/itm/' + obj.ItemID + '" target="_blank">' + obj.ItemID + '</a></p>';

                        if (returnCode == 'Warning') {
                                x.innerHTML += "<p>" + obj.Errors.SeverityCode + " (" + obj.Errors.ErrorCode + "): " + escapeHtml(obj.Errors.LongMessage) + "</p>";
                        }

                        var fees = obj.Fees;
                        x.innerHTML += "<p>";
                        for (i = 0; i < fees.length; i++) {
                                if (fees[i].Fee.text !== "0.0") {
                                        x.innerHTML += fees[i].Name + ": $" + Number(fees[i].Fee.text).toFixed(2) + "<br/>";
                                }
                        }
                        x.innerHTML += "</p>";

                        if (obj.DiscountReason) {
                                x.innerHTML += "<p>Discount Reason: " + obj.DiscountReason + "</p>";
                        }
                } else {
                        requireNewVerify();
                        x.innerHTML = "<p><strong>" + returnCode + ":</strong></p>";

                        var errors = obj.Errors;
                        x.innerHTML += "<p>";
                        if (errors.length > 0) {
                                for (i = 0; i < errors.length; i++) {
                                        x.innerHTML += errors[i].SeverityCode + " (" + errors[i].ErrorCode + "): " + escapeHtml(errors[i].LongMessage) + "<br/>";
                                        if (errors[i].LongMessage.includes('Auth')) {
                                                authErrorFlag = true;
                                        }
                                }
                        } else {
                                x.innerHTML += obj.Errors.SeverityCode + " (" + obj.Errors.ErrorCode + "): " + escapeHtml(obj.Errors.LongMessage) + "<br/>";
                                if (errors.LongMessage.includes('Auth')) {
                                        authErrorFlag = true;
                                }
                        }

                        x.innerHTML += "</p>";

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

                unsetAdditionalImages();
        };

        if (saveFlag) {
                var sPos = xml.indexOf('<Item>');
                var ePos = xml.indexOf('</Item>');
                var textToSave = xml.substr(sPos, ePos - sPos + 7);
                var textToSaveAsBlob = new Blob([String(textToSave)], {
                        type: "text/xml"
                });
                var textToSaveAsURL = window.URL.createObjectURL(textToSaveAsBlob);
                var fileNameToSaveAs = document.getElementById('keyword').value + ".xml";

                var downloadLink = document.createElement("a");
                downloadLink.download = fileNameToSaveAs;
                downloadLink.innerHTML = "Download File";
                downloadLink.href = textToSaveAsURL;
                downloadLink.onclick = destroyClickedElement;
                downloadLink.style.display = "none";
                document.body.appendChild(downloadLink);

                document.getElementById("results").innerHTML = '<p><strong>XML Saved</strong>, Filename ' + fileNameToSaveAs;

                downloadLink.click();
                listButtonHot(false);
                ImageURLs = [];
                unsetAdditionalImages();
                deleteSubmittedEntry();
        } else {
                xhr.send(xml);
        }
}

function destroyClickedElement(event) {
        document.body.removeChild(event.target);
}

function deleteSubmittedEntry() {
        //      document.getElementById(document.getElementById('keyword').value).style.color = "green";
        var x = document.getElementById("keyword");
        x.remove(x.selectedIndex);
        x.selectedIndex = -1;
        $(document.getElementById("keyword")).trigger("chosen:updated");
}

function createAddXML(xw, xhr, xmlrequest, callname, saveFlag) {
        var errorText = "";
        var ShippingProfileName;
        var ShippingProfileId;
        var si, opt;
        var weightInOz;

        if (picturesAreLoaded === false) {
                errorText += "<li>Images not yet uploaded!</li>";
        }

        if (document.getElementById("format").value <= 1) {
                errorText += "<li>Select Auction Format!</li>";
        }

        if (document.getElementById("sku").value == 'Batch X') {
                errorText += "<li>Wrong Batch Number!</li>";
        }

        if (document.getElementById("category").value == '0') {
                errorText += "<li>Wrong Category!</li>";
        }

        if (document.getElementById("sku").value.length < 1) {
                errorText += "<li>Batch Number Empty!</li>";
        }

        if (document.getElementById("condition").value === "") {
                errorText += "<li>Condition Description Empty!</li>";
        }

        if (document.getElementById("quantity").value === "") {
                errorText += "<li>Quantity Empty!</li>";
        }

        if (document.getElementById("price").value === "") {
                errorText += "<li>Price Empty!</li>";
        }

        if (document.getElementById("title").value === "") {
                errorText += "<li>Title Empty!</li>";
        }

        if (errorText.length > 0) {
                var x = document.getElementById("results");
                x.innerHTML = '<h2>Form Errors</h2><ul class="w3-ul">' + errorText + '</ul>';
                if (x.className.indexOf("w3-show") == -1) {
                        x.className += " w3-show";
                }

                return;
        }

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

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

        xw.writeStartElement('Item');

        if (CC == 3 || saveFlag) {
                xw.writeElementString('UUID', document.getElementById('keyword').value.hashCode().pad(32));
        }

        xw.writeElementString('Site', 'US');
        xw.writeElementString('Country', 'US');
        xw.writeElementString('PostalCode', configZip);
        xw.writeElementString('Currency', 'USD');
        xw.writeElementString('HitCounter', 'HiddenStyle');

        var format = document.getElementById('format').value;
        xw.writeElementString('ListingType', format);
        if (format == 'Chinese') {
                xw.writeElementString('ListingDuration', 'Days_7');
        } else if (format == 'FixedPriceItem') {
                xw.writeElementString('ListingDuration', 'Days_30');
        }

        xw.writeStartElement('PrimaryCategory');
        xw.writeElementString('CategoryID', category);
        xw.writeEndElement(); /* PrimaryCategory */

        if (document.getElementById("category").value != '29223') {
                xw.writeElementString('ConditionID', document.getElementById('conditionId').value);
        }
        if (document.getElementById('conditionId').value != '1000') {
                xw.writeElementString('ConditionDescription', escapeXml(document.getElementById('condition').value));
        }

        xw.writeStartElement('StartPrice');
        xw.writeAttributeString('currencyID', 'USD');
        xw.writeString(document.getElementById('price').value);
        xw.writeEndElement(); /* StartPrice */

        xw.writeElementString('PayPalEmailAddress', configLinkedPayPal);
        xw.writeElementString('PaymentMethods', 'PayPal');
        xw.writeElementString('Quantity', document.getElementById('quantity').value);
        xw.writeElementString('Title', escapeXml(document.getElementById('title').value));
        if (!isManualMode) {
                xw.writeElementString('SKU', escapeXml(document.getElementById('sku').value));
        } else {
                if (isNumeric(document.getElementById('keyword').value.trim())) {
                        xw.writeElementString('SKU', escapeXml(document.getElementById('sku').value + ' - ' + ProductListingDetailsNameList[CC] + ' ' + document.getElementById('keyword').value.trim()));
                } else {
                        xw.writeElementString('SKU', escapeXml(document.getElementById('sku').value));
                }
        }

        xw.writeStartElement('SellerProfiles');
        xw.writeStartElement('SellerPaymentProfile');
        xw.writeElementString('PaymentProfileID', '116958658023');
        xw.writeElementString('PaymentProfileName', 'PayPal');
        xw.writeEndElement(); /* SellerPaymentProfile */
        xw.writeStartElement('SellerReturnProfile');
        xw.writeElementString('ReturnProfileID', '123043332023');
        xw.writeElementString('ReturnProfileName', 'Returns Accepted,Buyer,30 Days,Money Back');
        xw.writeEndElement(); /* SellerReturnProfile */

        xw.writeStartElement('SellerShippingProfile');
        ShippingProfileId = ShippingProfileIdList[CC];
        ShippingProfileName = ShippingProfileNameList[CC];
        if (CC == 1) {
                if (document.getElementById('title').value.includes('Discs') || discogsQty > 1) {
                        ShippingProfileId = ShippingProfileIdList[2];
                        ShippingProfileName = ShippingProfileNameList[2];
                }
        }
        xw.writeElementString('ShippingProfileID', ShippingProfileId);
        xw.writeElementString('ShippingProfileName', ShippingProfileName);
        xw.writeEndElement(); /* SellerShippingProfile */

        xw.writeEndElement(); /* SellerProfiles */

        if (CC == 1) {
                weightInOz = 4;

                if (discogsQty > 0) {
                        weightInOz = discogsQty * 4;
                }

                if (document.getElementById('title').value.includes('Discs')) {
                        var pos = document.getElementById('title').value.indexOf('Discs');
                        var discNo = Number(document.getElementById('title').value.substr(pos - 2, 1));
                        if (discNo > 1) {
                                weightInOz = discNo * 4;
                        }
                }

                xw.writeStartElement('ShippingPackageDetails');
                xw.writeElementString('ShippingPackage', 'PackageThickEnvelope');
                xw.writeElementString('ShippingIrregular', 'false');
                xw.writeElementString('MeasurementUnit', 'English');
                xw.writeElementString('WeightMajor', '0');
                xw.writeElementString('WeightMinor', weightInOz.toString());
                xw.writeEndElement(); /* ShippingPackageDetails> */
        } else if (CC == 2) {
                xw.writeStartElement('ShippingPackageDetails');
                xw.writeElementString('ShippingPackage', 'PackageThickEnvelope');
                xw.writeElementString('ShippingIrregular', 'false');
                xw.writeElementString('MeasurementUnit', 'English');
                xw.writeElementString('WeightMajor', '0');
                xw.writeElementString('WeightMinor', '6');
                xw.writeEndElement(); /* ShippingPackageDetails> */
        } else if (CC == 3) {
                xw.writeStartElement('ShippingPackageDetails');
                xw.writeElementString('ShippingPackage', 'Letter');
                xw.writeElementString('ShippingIrregular', 'false');
                xw.writeElementString('MeasurementUnit', 'English');
                xw.writeElementString('WeightMajor', '0');
                xw.writeElementString('WeightMinor', '1');
                xw.writeEndElement(); /* ShippingPackageDetails> */
        }

        xw.writeStartElement('ProductListingDetails');
        if (CC == 3) {
                xw.writeElementString(ProductListingDetailsNameList[CC], configDoesNotApply);
        } else {
                si = document.getElementById("keyword").selectedIndex;
                opt = document.getElementById("keyword").options;
                if (!isManualMode) {
                        if (eBayProductId.length > 0) {
                                xw.writeElementString('ProductReferenceID', eBayProductId);
                        } else {
                                if (isNumeric(document.getElementById('keyword').value.trim())) {
                                        if (opt[si].style.color != 'red') {
                                                xw.writeElementString(ProductListingDetailsNameList[CC], document.getElementById('keyword').value.trim());
                                        } else {
                                                xw.writeElementString(ProductListingDetailsNameList[CC], configDoesNotApply);
                                        }
                                } else {
                                        xw.writeElementString(ProductListingDetailsNameList[CC], configDoesNotApply);
                                }
                        }
                } else {
                        if (opt[si].style.color == 'red') {
                                xw.writeElementString(ProductListingDetailsNameList[CC], configDoesNotApply);
                        } else if (CC === 0) {
                                xw.writeElementString(ProductListingDetailsNameList[CC], document.getElementById('bookISBN').value.trim());
                        } else if (CC == 1) {
                                xw.writeElementString(ProductListingDetailsNameList[CC], document.getElementById('cdUPC').value.trim());
                        } else if (CC == 2) {
                                xw.writeElementString(ProductListingDetailsNameList[CC], document.getElementById('dvdUPC').value.trim());
                        }
                }
        }
        xw.writeEndElement(); /* ProductListingDetails */

        xw.writeStartElement('Storefront');
        if (CC != 3) {
                xw.writeElementString('StoreCategoryID', StoreCategoryList[CC]);
        } else {
                if (category == "666") {
                        xw.writeElementString('StoreCategoryID', "30431905018");
                } else if (category == "213") {
                        xw.writeElementString('StoreCategoryID', "30431901018");
                } else if (category == "214") {
                        xw.writeElementString('StoreCategoryID', "30431902018");
                } else if (category == "215") {
                        xw.writeElementString('StoreCategoryID', "30431903018");
                } else if (category == "216") {
                        xw.writeElementString('StoreCategoryID', "30431904018");
                } else {
                        xw.writeElementString('StoreCategoryID', "");
                }
        }
        xw.writeEndElement(); /* Storefront */

        xw.writeStartElement('PictureDetails');
        for (var imageNumber = 0; imageNumber < ImageURLs.length; imageNumber++) {
                xw.writeElementString('PictureURL', ImageURLs[imageNumber]);
        }
        xw.writeEndElement(); /* PictureDetails */

        // Use Tax Table
        //      xw.writeStartElement('ShippingDetails');
        //      xw.writeStartElement('SalesTax');
        //      xw.writeElementString('SalesTaxPercent', configTaxRate);
        //      xw.writeElementString('SalesTaxState', configTaxStateId);
        //      xw.writeElementString('ShippingIncludedInTax', 'false');
        //      xw.writeEndElement(); /* SalesTax */
        //      xw.writeEndElement(); /* ShippingDetails */
        xw.writeElementString('UseTaxTable', 'true');

        if (document.getElementById('bestoffer').checked) {
                var autoAcceptPrice = Number(document.getElementById('price').value) * configAutoAcceptPrice;
                var minBestOfferPrice = Number(document.getElementById('price').value) * configMinBestOfferPrice;

                xw.writeStartElement('BestOfferDetails');
                xw.writeElementString('BestOfferEnabled', 'true');
                xw.writeEndElement(); /* BestOfferDetails */
                xw.writeStartElement('ListingDetails');
                xw.writeStartElement('BestOfferAutoAcceptPrice');
                xw.writeAttributeString('currencyID', 'USD');
                xw.writeString(autoAcceptPrice.toFixed(2));
                xw.writeEndElement(); /* BestOfferAutoAcceptPrice */
                xw.writeStartElement('MinimumBestOfferPrice');
                xw.writeAttributeString('currencyID', 'USD');
                xw.writeString(minBestOfferPrice.toFixed(2));
                xw.writeEndElement(); /* MinimumBestOfferPrice */
                xw.writeEndElement(); /* ListingDetails */
        }

        var Desc = Description1;
        Desc += '<h3>' + document.getElementById('title').value + '</h3>';
        generateDescCore();
        Desc += DescCore;
        if (document.getElementById('conditionId').value != '1000') {
                Desc += '<p>' + document.getElementById('condition').value + '</p>';
        }
        Desc += Description2;
        Desc += document.getElementById('title').value.replace(/['"]+/g, '');
        Desc += Description2a;
        Desc += DescImage;
        Desc += Description3;
        if (CC !== 3) {
                Desc += DescriptionFreeShipping;
        } else {
                Desc += DescriptionTradingCardShipping;
        }
        Desc += Description4;
        xw.writeElementString('Description', escapeXml(Desc));

        if (callname.includes('Verify') && configGetRecommendations === true) {
                xw.writeElementString('IncludeRecommendations', 'true');

                // Debug
                //var x = document.getElementById("query");
                //if (x.className.indexOf("w3-show") == -1) {
                //      x.className += " w3-show";
                //}
                //x.innerHTML = "<p>" + Desc.length + "</p>" + Desc;
        }

        generateItemSpecifics(xw);

        xw.writeEndElement(); /* Item */

        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 categoryValues() {
        category = document.getElementById("category").value;
        $(document.getElementById("category")).trigger("chosen:updated");

        if (category == 182882 || category == 171228 || category == 171243 || category == 2228 || category == 268) {
                /* Books */
                CC = 0;
                conditionDescriptionButtons(0);
        } else if (category == 176984 || category == 29792) {
                /* CDs */
                CC = 1;
                conditionDescriptionButtons(1);
        } else if (category == 617) {
                /* DVDs */
                CC = 2;
                conditionDescriptionButtons(0);
        } else if (category == 666 || category == 213 || category == 214 || category == 133072 || category == 215 || category == 4240 || category == 216 || category == 183444) {
                /* Trading Cards */
                CC = 3;
                conditionDescriptionButtons(0);
        } else {
                conditionDescriptionButtons(0);
                return;
        }

        if (document.getElementById("format").value <= 1) {
                document.getElementById("format").value = auctionFormat[CC];
                $(document.getElementById("format")).trigger("chosen:updated");
        }

        if (document.getElementById("price").value.length < 4) {
                document.getElementById("price").value = MinPriceList[CC];
        }

        document.getElementById("condition").value = ConditionDescriptionList[CC];
        document.getElementById("conditionId").value = ConditionIdList[CC];
        $(document.getElementById("conditionId")).trigger("chosen:updated");
        document.getElementById("quantity").value = 1;
        document.getElementById("bestoffer").checked = false;
}

function conditionDescriptionButtons(flag) {
        var x = [];
        x[0] = document.getElementById("CdConditionDescriptionSingular");
        x[1] = document.getElementById("CdConditionDescriptionPlural");
        x[2] = document.getElementById("CdConditionDescriptionDigipak");
        x[3] = document.getElementById("CdConditionDescriptionNewCase");

        for (var i = 0; i < x.length; i++) {
                if (flag) {
                        if (x[i].className.indexOf("w3-show-inline-block") == -1) {
                                x[i].className += " w3-show-inline-block";
                        }
                } else {
                        x[i].className = x[i].className.replace(" w3-show-inline-block", "");
                }
        }
}

function setCdConditionDescription(flag) {
        if (flag == 'S') {
                document.getElementById("condition").value = ConditionDescriptionList[1];
        } else if (flag == 'P') {
                document.getElementById("condition").value = ConditionDescriptionCdPlural;
                discogsQty = 2;
        } else if (flag == 'D') {
                document.getElementById("condition").value = ConditionDescriptionCdDigipak;
                document.getElementById("cdDigipak").checked = true;
        } else if (flag == 'N') {
                document.getElementById("condition").value = ConditionDescriptionCdNewCase;
        }
}

var minActive = [0.0, 0.0, 0.0];
var maxActive = [0.0, 0.0, 0.0];
var avgActive = [0.0, 0.0, 0.0];
var noActive = [0, 0, 0];
var minSold = [0.0, 0.0, 0.0];
var maxSold = [0.0, 0.0, 0.0];
var avgSold = [0.0, 0.0, 0.0];
var noSold = [0, 0, 0];
var minUnsold = [0.0, 0.0, 0.0];
var maxUnsold = [0.0, 0.0, 0.0];
var avgUnsold = [0.0, 0.0, 0.0];
var noUnsold = [0, 0, 0];
var maxPricingPages = [-1, -1];
var totalPricingEntries = [0, 0];
var newActiveBreakdown = [];
var usedActiveBreakdown = [];
var newSoldBreakdown = [];
var usedSoldBreakdown = [];
var maxPriceByNumber = [0.0, 0.0];
var listingNumberPercentage = 0.25;


function getPricing() {
        minActive = [0.0, 0.0, 0.0];
        maxActive = [0.0, 0.0, 0.0];
        avgActive = [0.0, 0.0, 0.0];
        noActive = [0, 0, 0];
        minSold = [0.0, 0.0, 0.0];
        maxSold = [0.0, 0.0, 0.0];
        avgSold = [0.0, 0.0, 0.0];
        noSold = [0, 0, 0];
        minUnsold = [0.0, 0.0, 0.0];
        maxUnsold = [0.0, 0.0, 0.0];
        avgUnsold = [0.0, 0.0, 0.0];
        noUnsold = [0, 0, 0];
        maxPricingPages = [-1, -1];
        totalPricingEntries = [0, 0];
        newActiveBreakdown = [];
        usedActiveBreakdown = [];
        newSoldBreakdown = [];
        usedSoldBreakdown = [];

        getPricingData(0);
        getPricingData(1);
}

function getPricingData(searchIndex) {
        var index = 0;
        var keyword;
        var keywordURL;

        keyword = document.getElementById('keyword').value;

        // Construct the request
        var url = configeBayFinding + "?";
        if (searchIndex === 0) {
                url += "OPERATION-NAME=findItemsAdvanced";
        } else {
                url += "OPERATION-NAME=findCompletedItems";
        }
        url += "&SECURITY-APPNAME=" + configAppid;
        url += "&GLOBAL-ID=EBAY-US";
        url += "&RESPONSE-DATA-FORMAT=JSON";
        url += "&SERVICE-VERSION=" + configeBayFindingVersion;
        url += "&REST-PAYLOAD";
        url += "&keywords=";
        url += encodeURIComponent(keyword.trim().replace(/ /g, "+"));

        url += "&paginationInput.entriesPerPage=100";
        url += "&paginationInput.pageNumber=";
        url += (index + 1);
        url += "&buyerPostalCode=";
        url += configZip;

        var xhttp = new XMLHttpRequest();

        xhttp.onreadystatechange = function() {
                if (this.readyState == 4) {
                        if (searchIndex === 0) {
                                _cb_PriceActiveItems(JSON.parse(this.responseText));
                        } else {
                                _cb_PriceCompletedItems(JSON.parse(this.responseText));
                        }
                }
        };

        xhttp.open("GET", configProxyUrl, true);
        xhttp.setRequestHeader("X-Proxy-Url", encodeURI(url));
        xhttp.send();

        function waitForMaxPricingPages(i) {
                if (maxPricingPages[i] < 0) {
                        window.setTimeout(waitForMaxPricingPages, 500, i); // wait 500 milliseconds
                } else {
                        for (index = 1; index < maxPricingPages[searchIndex]; index++) {
                                // Construct the request
                                var url = configeBayFinding + "?";
                                if (searchIndex === 0) {
                                        url += "OPERATION-NAME=findItemsAdvanced";
                                } else {
                                        url += "OPERATION-NAME=findCompletedItems";
                                }
                                url += "&SECURITY-APPNAME=" + configAppid;
                                url += "&GLOBAL-ID=EBAY-US";
                                url += "&RESPONSE-DATA-FORMAT=JSON";
                                url += "&SERVICE-VERSION=" + configeBayFindingVersion;
                                url += "&REST-PAYLOAD";
                                url += "&keywords=";
                                url += encodeURIComponent(keyword.trim().replace(/ /g, "+"));

                                url += "&paginationInput.entriesPerPage=100";
                                url += "&paginationInput.pageNumber=";
                                url += (index + 1);

                                var xhttp = new XMLHttpRequest();

                                xhttp.onreadystatechange = function() {
                                        if (this.readyState == 4) {
                                                if (searchIndex === 0) {
                                                        _cb_PriceActiveItems(JSON.parse(this.responseText));
                                                } else {
                                                        _cb_PriceCompletedItems(JSON.parse(this.responseText));
                                                }
                                        }
                                };

                                xhttp.open("GET", configProxyUrl, true);
                                xhttp.setRequestHeader("X-Proxy-Url", encodeURI(url));
                                xhttp.send();
                        }
                }
        }

        waitForMaxPricingPages(searchIndex);
}

function _cb_PriceActiveItems(objArray) {
        var array = typeof objArray.findItemsAdvancedResponse[0] != 'object' ? JSON.parse(objArray.findItemsAdvancedResponse[0]) : objArray.findItemsAdvancedResponse[0].searchResult[0].item;
        totalPricingEntries[0] = Number(objArray.findItemsAdvancedResponse[0].paginationOutput[0].totalEntries);
        if (totalPricingEntries[0] > 0) {
                priceItem(array, 0);
        }
}

function _cb_PriceCompletedItems(objArray) {
        var array = typeof objArray.findCompletedItemsResponse[0] != 'object' ? JSON.parse(objArray.findCompletedItemsResponse[0]) : objArray.findCompletedItemsResponse[0].searchResult[0].item;
        totalPricingEntries[1] = Number(objArray.findCompletedItemsResponse[0].paginationOutput[0].totalEntries);
        if (totalPricingEntries[1] > 0) {
                priceItem(array, 1);
        }
}

function priceItem(array, index) {
        var i;
        var Title;
        var shippingCost = 0.0;
        var itemCost = 0.0;
        var totalCost = 0.0;
        var totalCostInt = 0;
        var sellingStatus;
        var sellingState;
        var bidCount;
        var condInd;
        var condition;
        var conditionId;
        var shippingInfo;
        var shippingServiceCost;
        var convertedCurrentPrice;
        var listingInfo;
        var convertedBuyItNowPrice;
        var JsonObj;

        if (array === undefined) {
                return;
        }

        if (totalPricingEntries[index] < 1) {
                maxPricingPages[index] = 0;
        } else {
                maxPricingPages[index] = (totalPricingEntries[index] / 100) > 100 ? 100 : Math.trunc(totalPricingEntries[index] / 100.0) + 1;
        }

        for (i = 0; i < array.length; i++) {
                JsonObj = array[i];

                Title = JsonObj.title[0].toLowerCase();
                if (Title.includes("disc only") > 0 ||
                        Title.includes("disk only") > 0 ||
                        Title.includes("only disc") > 0 ||
                        Title.includes("only disk") > 0 ||
                        Title.search(/dis[ck].*only/) > 0) {
                        continue; // exclude "disc only listing
                }

                condition = JsonObj.condition;
                if (condition) {
                        conditionId = condition[0].conditionId;
                        if (conditionId == 1000 || conditionId == 1500 || conditionId == 2750) {
                                condInd = 1;
                        } else if (conditionId <= 4000) {
                                condInd = 2;
                        } else {
                                continue; // Only 'Very Good' and better
                        }
                } else {
                        condInd = 2;
                }

                shippingInfo = JsonObj.shippingInfo;
                shippingServiceCost = shippingInfo[0].shippingServiceCost;
                if (shippingServiceCost) {
                        shippingCost = Number(shippingServiceCost[0].__value__);
                } else {
                        shippingCost = 0.0;
                }

                sellingStatus = JsonObj.sellingStatus;
                sellingState = sellingStatus[0].sellingState;
                bidCount = sellingStatus[0].bidCount;
                convertedCurrentPrice = sellingStatus[0].convertedCurrentPrice;
                itemCost = Number(convertedCurrentPrice[0].__value__);

                listingInfo = JsonObj.listingInfo;
                convertedBuyItNowPrice = listingInfo[0].convertedBuyItNowPrice;
                if (bidCount === 0 && convertedBuyItNowPrice) {
                        itemCost = Number(convertedBuyItNowPrice[0].__value__);
                }

                if (condition) {
                        conditionId = condition[0].conditionId;
                        if (conditionId == 1000 || conditionId == 1500 || conditionId == 2750) {
                                condInd = 1;
                        } else {
                                condInd = 2;
                        }
                } else {
                        condInd = 2;
                }

                totalCost = itemCost + shippingCost;
                totalCostInt = Math.ceil(totalCost);

                if (sellingState == "Active") {
                        if (totalCost < minActive[0] || !minActive[0]) {
                                minActive[0] = totalCost;
                        }
                        if (totalCost > maxActive[0]) {
                                maxActive[0] = totalCost;
                        }
                        avgActive[0] += totalCost;
                        ++noActive[0];

                        if (totalCost < minActive[condInd] || !minActive[condInd]) {
                                minActive[condInd] = totalCost;
                        }
                        if (totalCost > maxActive[condInd]) {
                                maxActive[condInd] = totalCost;
                        }
                        avgActive[condInd] += totalCost;
                        ++noActive[condInd];

                        if (condInd == 1) {
                                if (newActiveBreakdown[totalCostInt] === undefined) {
                                        newActiveBreakdown[totalCostInt] = 0;
                                }
                                ++newActiveBreakdown[totalCostInt];
                        } else {
                                if (usedActiveBreakdown[totalCostInt] === undefined) {
                                        usedActiveBreakdown[totalCostInt] = 0;
                                }
                                ++usedActiveBreakdown[totalCostInt];
                        }
                } else if (sellingState == "EndedWithSales") {
                        if (totalCost < minSold[0] || !minSold[0]) {
                                minSold[0] = totalCost;
                        }
                        if (totalCost > maxSold[0]) {
                                maxSold[0] = totalCost;
                        }
                        avgSold[0] += totalCost;
                        ++noSold[0];

                        if (totalCost < minSold[condInd] || !minSold[condInd]) {
                                minSold[condInd] = totalCost;
                        }
                        if (totalCost > maxSold[condInd]) {
                                maxSold[condInd] = totalCost;
                        }
                        avgSold[condInd] += totalCost;
                        ++noSold[condInd];

                        if (condInd == 1) {
                                if (newSoldBreakdown[totalCostInt] === undefined) {
                                        newSoldBreakdown[totalCostInt] = 0;
                                }
                                ++newSoldBreakdown[totalCostInt];
                        } else {
                                if (usedSoldBreakdown[totalCostInt] === undefined) {
                                        usedSoldBreakdown[totalCostInt] = 0;
                                }
                                ++usedSoldBreakdown[totalCostInt];
                        }
                } else /* Unsold */ {
                        if (totalCost < minUnsold[0] || !minUnsold[0]) {
                                minUnsold[0] = totalCost;
                        }
                        if (totalCost > maxUnsold[0]) {
                                maxUnsold[0] = totalCost;
                        }
                        avgUnsold[0] += totalCost;
                        ++noUnsold[0];

                        if (totalCost < minUnsold[condInd] || !minUnsold[condInd]) {
                                minUnsold[condInd] = totalCost;
                        }
                        if (totalCost > maxUnsold[condInd]) {
                                maxUnsold[condInd] = totalCost;
                        }
                        avgUnsold[condInd] += totalCost;
                        ++noUnsold[condInd];
                }
        }

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

        var str = '<h3>Pricing Information (Shipping included)</h3>';
        str += '<table class="w3-table-all">';
        str += '        <tr>';
        str += '                <th></th>';
        str += '                <th>Number</th>';
        str += '        <th>Minimum</th>';
        str += '        <th>Maximum</th>';
        str += '        <th>Average</th>';
        str += '        </tr>';
        str += '        <tr>';
        str += '                <td>Active</td>';
        str += '                <td>' + noActive[0] + '<br/>' + noActive[1] + ' / ' + noActive[2] + '</td>';
        str += '                <td>$' + Number(minActive[0]).toFixed(2) + '<br/>$' + Number(minActive[1]).toFixed(2) + ' / $' + Number(minActive[2]).toFixed(2) + '</td>';
        str += '                <td>$' + Number(maxActive[0]).toFixed(2) + '<br/>$' + Number(maxActive[1]).toFixed(2) + ' / $' + Number(maxActive[2]).toFixed(2) + '</td>';
        str += '                <td>';
        if (noActive[0]) {
                str += '$' + Number(avgActive[0] / noActive[0]).toFixed(2);
                str += '<br/>$' + (noActive[1] > 0 ? Number(avgActive[1] / noActive[1]).toFixed(2) : 0.00);
                str += ' / $' + (noActive[2] > 0 ? Number(avgActive[2] / noActive[2]).toFixed(2) : 0.00);
        }
        str += '</td>';
        str += '        </tr>';

        str += '<tr><td colspan="5">';
        str += '<canvas id="activeChart"></canvas>';
        str += '</td></tr>';

        str += '        <tr>';
        str += '                <td>Sold</td>';
        str += '                <td>' + noSold[0] + '<br/>' + noSold[1] + ' / ' + noSold[2] + '</td>';
        str += '                <td>$' + Number(minSold[0]).toFixed(2) + '<br/>$' + Number(minSold[1]).toFixed(2) + ' / $' + Number(minSold[2]).toFixed(2) + '</td>';
        str += '                <td>$' + Number(maxSold[0]).toFixed(2) + '<br/>$' + Number(maxSold[1]).toFixed(2) + ' / $' + Number(maxSold[2]).toFixed(2) + '</td>';
        str += '                <td>';
        if (noSold[0]) {
                str += '$' + Number(avgSold[0] / noSold[0]).toFixed(2);
                str += '<br/>$' + (noSold[1] > 0 ? Number(avgSold[1] / noSold[1]).toFixed(2) : 0.00);
                str += ' / $' + (noSold[2] > 0 ? Number(avgSold[2] / noSold[2]).toFixed(2) : 0.00);
        }
        str += '</td>';
        str += '        </tr>';

        str += '<tr><td colspan="5">';
        str += '<canvas id="soldChart"></canvas>';
        str += '</td></tr>';

        str += '        <tr>';
        str += '                <td>Unsold</td>';
        str += '                <td>' + noUnsold[0] + '<br/>' + noUnsold[1] + ' / ' + noUnsold[2] + '</td>';
        str += '                <td>$' + Number(minUnsold[0]).toFixed(2) + '<br/>$' + Number(minUnsold[1]).toFixed(2) + ' / $' + Number(minUnsold[2]).toFixed(2) + '</td>';
        str += '                <td>$' + Number(maxUnsold[0]).toFixed(2) + '<br/>$' + Number(maxUnsold[1]).toFixed(2) + ' / $' + Number(maxUnsold[2]).toFixed(2) + '</td>';
        str += '                <td>';
        if (noUnsold[0]) {
                str += '$' + Number(avgUnsold[0] / noUnsold[0]).toFixed(2);
                str += '<br/>$' + (noUnsold[1] > 0 ? Number(avgUnsold[1] / noUnsold[1]).toFixed(2) : 0.00);
                str += ' / $' + (noUnsold[2] > 0 ? Number(avgUnsold[2] / noUnsold[2]).toFixed(2) : 0.00);
        }
        str += '</td>';
        str += '        </tr>';
        str += '</table>';

        x.innerHTML = str;

        pricingGraphs(0, usedActiveBreakdown, newActiveBreakdown);
        pricingGraphs(1, usedSoldBreakdown, newSoldBreakdown);
}

function pricingGraphs(index, usedBreakdown, newBreakdown) {
        var i;
        var newData = [];
        var usedData = [];
        var labelData = [];
        var ctx = document.getElementById(index === 0 ? 'activeChart' : 'soldChart').getContext('2d');
        var min = findMin(usedBreakdown, newBreakdown);
        var max = findMax(usedBreakdown, newBreakdown);

        for (i = min; i < max; i++) {
                labelData.push('<$' + i);

                if (usedBreakdown[i] === undefined) {
                        usedData.push(0);
                } else {
                        usedData.push(usedBreakdown[i]);
                }

                if (newBreakdown[i] === undefined) {
                        newData.push(0);
                } else {
                        newData.push(newBreakdown[i]);
                }
        }

        var myChart = new Chart(ctx, {
                type: 'bar',
                options: {
                        scales: {
                                yAxes: [{
                                        ticks: {
                                                fixedStepSize: 1
                                        }
                                }],
                        },
                },
                data: {
                        labels: labelData,
                        datasets: [{
                                label: 'Used',
                                data: usedData,
                                backgroundColor: "rgba(0,102,0,1)"
                        }, {
                                label: 'New',
                                data: newData,
                                backgroundColor: "rgba(204,0,0,1)"
                        }]
                }
        });
}

function findMin(Used, New) {
        var i;
        var minUsed = 0,
                minNew = 0;
        var min = 0;

        for (i = 0; i < Used.length; i++) {
                if (Used[i] !== undefined) {
                        minUsed = i;
                        break;
                }
        }

        for (i = 0; i < New.length; i++) {
                if (New[i] !== undefined) {
                        minNew = i;
                        break;
                }
        }

        if (minUsed > 0 && minNew > 0) {
                min = Math.min(minUsed, minNew);
        } else if (minUsed > 0) {
                min = minUsed;
        } else if (minNew > 0) {
                min = minNew;
        }

        return min;
}

function findMax(Used, New) {
        var max = 0;

        if (Used.length >= New.length) {
                max = Used.length;
        } else if (New.length >= Used.length) {
                max = New.length;
        }

        return max;
}

function listButtonHot(flag) {
        var i;
        var x = [];

        x[0] = document.getElementById("list");
        x[1] = document.getElementById("savexml");

        for (i = 0; i < 2; i++) {
                if (flag === true) {
                        x[i].className = x[i].className.replace(" w3-red", " w3-green");
                } else {
                        x[i].className = x[i].className.replace(" w3-green", " w3-red");
                }
        }
}

function clearStatusWindows() {
        var x = document.getElementById("results");
        x.innerHTML = "";
        x.className = x.className.replace(" w3-show", "");
        x = document.getElementById("prices");
        x.innerHTML = "";
        x.className = x.className.replace(" w3-show", "");
        x = document.getElementById("discogsReleases");
        x.innerHTML = "";
        x.className = x.className.replace(" w3-show", "");
}

function pictureLoad(flag) {
        picturesAreLoaded = flag;
}

function reformatCdTitle(str) {
        if (str.includes("Various Artists")) {
                return str;
        }

        var n = str.lastIndexOf(" by ");

        if (n > 0) {
                var title = str.substr(0, n);
                var rest = str.substr(n + 4);
                n = rest.indexOf("(");
                var artist = rest.substr(0, n).trim();
                var info = rest.substr(n);
                return (artist + " - " + title + " " + info);
        }

        return str;
}

function extractFromTitle() {
        var titleField = document.getElementById("title");
        var n;

        titleField.value = titleField.value.trim().replace(/[\u2012\u2013\u2014\u2015]/, '-').replace(/\u200E/, '').replace(/  +/g, ' ');
        printTitleLength();

        if (CC == 1) {
                if (titleField.value.indexOf(', EP,') > 0) {
                        document.getElementById("cdDuration").value = 'EP';
                } else if (titleField.value.indexOf('[Maxi-Single]') > 0 || titleField.value.indexOf('[Maxi Single]') > 0) {
                        document.getElementById("cdDuration").value = 'Maxi-Single';
                } else if (titleField.value.indexOf(', Single,') > 0) {
                        document.getElementById("cdDuration").value = 'Single';
                }
                $('#cdDuration').prop('disabled', false).trigger("chosen:updated");

                if (titleField.value.indexOf(', Digipak,') > 0) {
                        document.getElementById("cdDigipak").checked = true;
                } else {
                        document.getElementById("cdDigipak").checked = false;
                }

                if (titleField.value.includes('Various Artists')) {
                        document.getElementById("cdArtist").value = 'Various';
                } else {
                        document.getElementById("cdArtist").value = titleField.value.substr(0, titleField.value.indexOf(" - "));
                }

                n = titleField.value.indexOf('(CD');
                document.getElementById("cdRecordLabel").value = titleField.value.substr(n).substr(titleField.value.substr(n).lastIndexOf(',') + 2);
                document.getElementById("cdRecordLabel").value = document.getElementById("cdRecordLabel").value.substr(0, document.getElementById("cdRecordLabel").value.lastIndexOf(')'));

                n = titleField.value.indexOf('(CD');
                document.getElementById("cdReleaseYear").value = getYear(titleField.value.substr(n));
        }
}

function reformatPastedTitle(e) {
        var clipboardData, pastedData;
        var x = document.getElementById("title");

        // Stop data actually being pasted
        e.stopPropagation();
        e.preventDefault();

        // Get pasted data via clipboard API
        clipboardData = e.clipboardData || window.clipboardData;
        pastedData = clipboardData.getData('Text');

        x.value = pastedData.trim().replace(/[\u2012\u2013\u2014\u2015]/, '-').replace(/\u200E/, '');
        printTitleLength();
}

function formatTrackList() {
        var i;
        var lines = [];
        var x = document.getElementById("cdTracks");

        if (x.value.length < 1) {
                return;
        }

        lines = x.value.split('\n');

        for (i = 0; i < lines.length; i++) {
                lines[i] = lines[i].trim();
                lines[i] = lines[i].replace(/^\d+ /, '');
                lines[i] = lines[i].replace(/^\d+. /, '');
                lines[i] = lines[i].replace(/^\t/g, '');
                lines[i] = lines[i].replace(/\t(\d+[:.]\d{2})$/, "\[$1\]");
                lines[i] = lines[i].replace(/^\u0096/, '');
                lines[i] = lines[i].replace(/ \t/, ' - ');
                lines[i] = lines[i].replace(/[\u2012\u2013\u2014\u2015]/, '');
                lines[i] = lines[i].replace(/@/g, '*');
                lines[i] = lines[i].replace(/\*/g, '');
        }

        x.value = lines.join('\n');
}

function splitTradingCardElements() {
        // [Year] [First Last], [Position] at [Club] - [Card Manufacturer] [Series] -P-[Card Number] [Rookie] [S####] [other]
        var elem;
        var stop1 = 0,
                stop2 = 0,
                stop3 = 0;
        var str;
        var title;
        var cardYear = '';
        var cardPlayer = '';
        var cardPosition = '';
        var cardTeam = '';
        var cardManufacturer = '';
        var cardSeries = '';
        var cardNumber = '';
        var isRookie = false;
        var isSerialized = false;
        var isPoA = false;

        title = document.getElementById('keyword').value.replace('-P-', '#');
        catalogTitle = title;
        var res = title.split(' ');
        for (elem = 0; elem < res.length; elem++) {
                if (res[elem].endsWith(',')) {
                        stop1 = elem;
                }

                if (res[elem] == '-') {
                        stop2 = elem - 1;
                }

                if (res[elem].startsWith('#')) {
                        stop3 = elem;
                }
        }

        if (!stop1 || !stop2 || !stop3) {
                return;
        }

        cardYear = res[0];
        for (elem = 1; elem <= stop1; elem++) {
                cardPlayer += res[elem] + ' ';
        }
        cardPlayer = cardPlayer.substr(0, cardPlayer.length - 2);

        cardPosition = res[elem];
        elem += 2;

        for (; elem <= stop2; elem++) {
                cardTeam += res[elem] + ' ';
        }
        cardTeam = cardTeam.trim();
        elem++;

        cardManufacturer = res[elem];

        if (cardManufacturer == "UpperDeck") {
                catalogTitle = catalogTitle.replace("UpperDeck", "Upper Deck");
                cardManufacturer = "Upper Deck";
        } else if (cardManufacturer == "AceAuthentic") {
                catalogTitle = catalogTitle.replace("AceAuthentic", "Ace Authentic");
                cardManufacturer = "Ace Authentic";
        } else if (cardManufacturer == "BeAPlayer") {
                catalogTitle = catalogTitle.replace("BeAPlayer", "Be A Player");
                cardManufacturer = "Be A Player";
        } else if (cardManufacturer == "CollectorsEdge") {
                catalogTitle = catalogTitle.replace("CollectorsEdge", "Collector's Edge");
                cardManufacturer = "Collector's Edge";
        } else if (cardManufacturer == "GoalLine") {
                catalogTitle = catalogTitle.replace("GoalLine", "Goal Line");
                cardManufacturer = "Goal Line";
        } else if (cardManufacturer == "InTheGame") {
                catalogTitle = catalogTitle.replace("InTheGame", "In the Game");
                cardManufacturer = "In the Game";
        } else if (cardManufacturer == "OnyxAuthenticated") {
                catalogTitle = catalogTitle.replace("OnyxAuthenticated", "Onyx Authenticated");
                cardManufacturer = "Onyx Authenticated";
        } else if (cardManufacturer == "PressPass") {
                catalogTitle = catalogTitle.replace("PressPass", "Press Pass");
                cardManufacturer = "Press Pass";
        } else if (cardManufacturer == "ProSet") {
                catalogTitle = catalogTitle.replace("ProSet", "Pro Set");
                cardManufacturer = "Pro Set";
        }
        elem++;

        for (; elem < stop3; elem++) {
                cardSeries += res[elem] + ' ';
        }
        cardSeries = cardSeries.trim();
        cardNumber = res[elem];
        elem++;

        for (; elem < res.length; elem++) {
                if (res[elem] == "Gameworn") {
                        isPoA = true;
                }

                if (res[elem] == "Rookie") {
                        isRookie = true;
                }

                if (res[elem].startsWith("S") && isNumeric(res[elem].substr(1))) {
                        catalogTitle = catalogTitle.replace(res[elem], "/" + res[elem].substr(1));
                        isSerialized = true;
                }
        }

        str = '<h3>' + title + '</h3>';
        str += '<p>';
        str += 'Season: ' + cardYear + '<br/>';
        str += 'Player: ' + cardPlayer + '<br/>';
        str += 'Position: ' + cardPosition + '<br/>';
        str += 'Team: ' + cardTeam + '<br/>';
        str += 'Card Manufacturer: ' + cardManufacturer + '<br/>';
        if (cardSeries.length > 0) {
                str += 'Card Series: ' + cardSeries + '<br/>';
        }
        str += 'Card Number: ' + cardNumber + '<br/>';
        if (isRookie) {
                str += 'Rookie<br/>';
        }
        if (isSerialized) {
                str += 'Serialized<br/>';
        }
        if (isPoA) {
                str += 'Piece of Authentic<br/>';
        }
        str += '</p>';

        var x = document.getElementById("productinfo");
        x.innerHTML = str;

        document.getElementById("tcPlayer").value = cardPlayer;
        document.getElementById("tcPosition").value = cardPosition;
        document.getElementById("tcTeam").value = cardTeam;
        document.getElementById("tcSeason").value = cardYear;
        document.getElementById("tcManufacturer").value = cardManufacturer;
        document.getElementById("tcNumber").value = cardNumber;
        document.getElementById("tcSeries").value = cardSeries;
        document.getElementById("tcRookie").checked = false;
        document.getElementById("tcPoA").checked = false;
        document.getElementById("tcSerial").checked = false;

        if (isRookie) {
                document.getElementById("tcRookie").checked = true;
        }

        if (isPoA) {
                document.getElementById("tcPoA").checked = true;
        }

        if (isSerialized) {
                document.getElementById("tcSerial").checked = true;
        }

        var currentCategory = document.getElementById("category").value;
        if (currentCategory != "213" && currentCategory != "214" && currentCategory != "215" && currentCategory != "216") {
                document.getElementById("category").value = '0';
                $(document.getElementById("category")).trigger("chosen:updated");
        }

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

function generateDescCore() {
        var listType = 'ol';
        DescCore = '';

        if (CC === 0) {
                DescCore = '<p>';
                DescCore += 'Format: ' + document.getElementById("bookFormat").value + '<br/>';
                if (document.getElementById("bookAuthor").value.length > 0) {
                        DescCore += 'Author: ' + document.getElementById("bookAuthor").value.toString().replace(/,/g, ', ') + '<br/>';
                }
                if (document.getElementById("bookPublicationYear").value.length > 0) {
                        DescCore += 'Publication Year: ' + document.getElementById("bookPublicationYear").value + '<br/>';
                }
                if (document.getElementById("bookSubject").value.length > 0) {
                        DescCore += 'Subject: ' + document.getElementById("bookSubject").value + '<br/>';
                }
                if (document.getElementById("bookLanguage").value.length > 0) {
                        DescCore += 'Language: ' + document.getElementById("bookLanguage").value + '<br/>';
                }
                if (document.getElementById("bookCountry").value.length > 0) {
                        DescCore += 'Country: ' + document.getElementById("bookCountry").value + '<br/>';
                }
                if (document.getElementById("bookDustJacket").checked) {
                        DescCore += 'Dust Jacket<br/>';
                }
                if (document.getElementById("bookIllustrated").checked) {
                        DescCore += 'Illustrated<br/>';
                }
                if (document.getElementById("bookLargePrint").checked) {
                        DescCore += 'Large Print<br/>';
                }
                if (document.getElementById("bookSigned").checked) {
                        DescCore += 'Signed<br/>';
                }
                DescCore += '</p>';
        } else if (CC == 1) {
                if (document.getElementById("cdTracks").value.length > 0) {
                        if (document.getElementById("cdUnorderedTrackList").checked) {
                                listType = 'ul';
                        }

                        DescCore += '<p>Tracklist:</p><' + listType + ' class="w3-' + listType + '">';
                        var lines = document.getElementById("cdTracks").value.split('\n');
                        for (var i = 0; i < lines.length; i++) {
                                DescCore += '<li>' + lines[i] + '</li>';
                        }
                        DescCore += '</' + listType + '>';
                }
        } else if (CC == 2) {
                DescCore = '<p>';
                DescCore += 'Format: ' + document.getElementById("dvdFormat").value + '<br/>';
                if (document.getElementById("dvdActor").value.length > 0) {
                        DescCore += 'Actors: ' + document.getElementById("dvdActor").value.toString().replace(/,/g, ', ') + '<br/>';
                }
                if (document.getElementById("dvdLeadingRole").value.length > 0) {
                        DescCore += 'Leading Role: ' + document.getElementById("dvdLeadingRole").value.toString().replace(/,/g, ', ') + '<br/>';
                }
                if (document.getElementById("dvdDirector").value.length > 0) {
                        DescCore += 'Director: ' + document.getElementById("dvdDirector").value.toString().replace(/,/g, ', ') + '<br/>';
                }
                if (document.getElementById("dvdDVDEditionYear").value.length > 0) {
                        DescCore += 'DVD Edition Year: ' + document.getElementById("dvdDVDEditionYear").value + '<br/>';
                }
                if (document.getElementById("dvdReleaseYear").value.length > 0) {
                        DescCore += 'Movie Release Year: ' + document.getElementById("dvdReleaseYear").value + '<br/>';
                }
                if (document.getElementById("dvdGenre").value.length > 1) {
                        DescCore += 'Genre: ' + document.getElementById("dvdGenre").value + '<br/>';
                }
                if (document.getElementById("dvdRating").value.length > 1) {
                        DescCore += 'Rating: ' + document.getElementById("dvdRating").value + '<br/>';
                }
                if (document.getElementById("dvdRegionCode").value.length > 1) {
                        DescCore += 'Region Code: ' + document.getElementById("dvdRegionCode").value + '<br/>';
                }
                if (document.getElementById("dvdSeason").value.length > 0 && document.getElementById("dvdSeason").value != ' ') {
                        DescCore += 'Season: ' + document.getElementById("dvdSeason").value + '<br/>';
                }
                if (document.getElementById("dvdCountry").value.length > 0) {
                        DescCore += 'Country/Region of Manufacture: ' + document.getElementById("dvdCountry").value + '<br/>';
                }
                if (document.getElementById("dvd3D").checked) {
                        DescCore += '3D<br/>';
                }
                if (document.getElementById("dvdAnniversaryEdition").checked) {
                        DescCore += 'Anniversary Edition<br/>';
                }
                if (document.getElementById("dvdBoxSet").checked) {
                        DescCore += 'Box Set<br/>';
                }
                if (document.getElementById("dvdCollectorsEdition").checked) {
                        DescCore += 'Collector\'s Edition<br/>';
                }
                if (document.getElementById("dvdDeluxeEdition").checked) {
                        DescCore += 'Deluxe Edition<br/>';
                }
                if (document.getElementById("dvdDirectorsCut").checked) {
                        DescCore += 'Director\'s Cut<br/>';
                }
                if (document.getElementById("dvdExtendedEdition").checked) {
                        DescCore += 'Extended Edition<br/>';
                }
                if (document.getElementById("dvdFullScreen").checked) {
                        DescCore += 'Full Screen<br/>';
                }
                if (document.getElementById("dvdLimitedEdition").checked) {
                        DescCore += 'Limited Edition<br/>';
                }
                if (document.getElementById("dvdPromo").checked) {
                        DescCore += 'Promo<br/>';
                }
                if (document.getElementById("dvdSignatureCollection").checked) {
                        DescCore += 'Signature Collection<br/>';
                }
                if (document.getElementById("dvdSpecialEdition").checked) {
                        DescCore += 'Special Edition<br/>';
                }
                if (document.getElementById("dvdSteelbook").checked) {
                        DescCore += 'Steelbook<br/>';
                }
                if (document.getElementById("dvdUnratedEdition").checked) {
                        DescCore += 'Unrated Edition<br/>';
                }
                if (document.getElementById("dvdWidescreen").checked) {
                        DescCore += 'Widescreen<br/>';
                }
                DescCore += '</p>';
        } else if (CC == 3) {
                DescCore = '<p>';
                DescCore += 'Season: ' + document.getElementById("tcSeason").value + '<br/>';
                DescCore += 'Player: ' + document.getElementById("tcPlayer").value + '<br/>';
                DescCore += 'Position: ' + document.getElementById("tcPosition").value + '<br/>';
                DescCore += 'Team: ' + document.getElementById("tcTeam").value + '<br/>';
                DescCore += 'Card Manufacturer: ' + document.getElementById("tcManufacturer").value + '<br/>';
                if (document.getElementById("tcSeries").value.length > 0) {
                        DescCore += 'Card Series: ' + document.getElementById("tcSeries").value + '<br/>';
                }
                DescCore += 'Card Number: ' + document.getElementById("tcNumber").value + '<br/>';
                if (document.getElementById("tcRookie").checked) {
                        DescCore += 'Rookie<br/>';
                }
                if (document.getElementById("tcSerial").checked) {
                        DescCore += 'Serialized<br/>';
                }
                if (document.getElementById("tcPoA").checked) {
                        DescCore += 'Piece of Authentic<br/>';
                }
                DescCore += '</p>';
        }
}

function generateItemSpecifics(xw) {
        xw.writeStartElement('ItemSpecifics');

        if (CC === 0) {
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Author');
                xw.writeElementString('Value', escapeXml(document.getElementById("bookAuthor").value));
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Format');
                xw.writeElementString('Value', escapeXml(document.getElementById("bookFormat").value));
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Publication Year');
                xw.writeElementString('Value', escapeXml(document.getElementById("bookPublicationYear").value));
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Subject');
                xw.writeElementString('Value', escapeXml(document.getElementById("bookSubject").value));
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Language');
                xw.writeElementString('Value', escapeXml(document.getElementById("bookLanguage").value));
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Country/Region of Manufacture');
                xw.writeElementString('Value', escapeXml(document.getElementById("bookCountry").value));
                xw.writeEndElement(); /* NameValueList */

                if (document.getElementById("bookDustJacket").checked ||
                        document.getElementById("bookIllustrated").checked ||
                        document.getElementById("bookLargePrint").checked ||
                        document.getElementById("bookSigned").checked) {
                        xw.writeStartElement('NameValueList');
                        xw.writeElementString('Name', 'Special Attributes');
                        itemSpecificCheckbox(xw, "bookDustJacket", 'Dust Jacket');
                        itemSpecificCheckbox(xw, "bookIllustrated", 'Illustrated');
                        itemSpecificCheckbox(xw, "bookLargePrint", 'Large Print');
                        itemSpecificCheckbox(xw, "bookSigned", 'Signed');
                        xw.writeEndElement(); /* NameValueList */
                }
        } else if (CC == 1) {
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Genre');
                xw.writeElementString('Value', escapeXml(document.getElementById("cdGenre").value));
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Duration');
                xw.writeElementString('Value', escapeXml(document.getElementById("cdDuration").value));
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Record Label');
                xw.writeElementString('Value', escapeXml(document.getElementById("cdRecordLabel").value));
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Release Year');
                xw.writeElementString('Value', escapeXml(document.getElementById("cdReleaseYear").value));
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Artist');
                xw.writeElementString('Value', escapeXml(document.getElementById("cdArtist").value));
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Title');
                xw.writeElementString('Value', escapeXml(document.getElementById("cdTitle").value));
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Country/Region of Manufacture');
                xw.writeElementString('Value', escapeXml(document.getElementById("cdCountry").value));
                xw.writeEndElement(); /* NameValueList */

                if (document.getElementById("cdCompilation").checked ||
                        document.getElementById("cdDigipak").checked ||
                        document.getElementById("cdDualDisc").checked ||
                        document.getElementById("cdEnhanced").checked ||
                        document.getElementById("cdHDCD").checked) {
                        xw.writeStartElement('NameValueList');
                        xw.writeElementString('Name', 'Special Attributes');
                        itemSpecificCheckbox(xw, "cdCompilation", 'Compilation');
                        itemSpecificCheckbox(xw, "cdDigipak", 'Digipak');
                        itemSpecificCheckbox(xw, "cdDualDisc", 'DualDisc');
                        itemSpecificCheckbox(xw, "cdEnhanced", 'Enhanced');
                        itemSpecificCheckbox(xw, "cdHDCD", 'HDCD');
                        xw.writeEndElement(); /* NameValueList */
                }

                if (document.getElementById("cdLiveRecording").checked ||
                        document.getElementById("cdPromo").checked ||
                        document.getElementById("cdReissue").checked ||
                        document.getElementById("cdRemastered").checked ||
                        document.getElementById("cdGreatestHits").checked) {
                        xw.writeStartElement('NameValueList');
                        xw.writeElementString('Name', 'Edition');
                        itemSpecificCheckbox(xw, "cdCompilation", 'Compilation');
                        itemSpecificCheckbox(xw, "cdDigipak", 'Digipak');
                        itemSpecificCheckbox(xw, "cdDualDisc", 'DualDisc');
                        itemSpecificCheckbox(xw, "cdEnhanced", 'Enhanced');
                        itemSpecificCheckbox(xw, "cdLiveRecording", 'Live Recording');
                        itemSpecificCheckbox(xw, "cdPromo", 'Promo');
                        itemSpecificCheckbox(xw, "cdReissue", 'Reissue');
                        itemSpecificCheckbox(xw, "cdRemastered", 'Remastered');
                        itemSpecificCheckbox(xw, "cdHDCD", 'HDCD');
                        itemSpecificCheckbox(xw, "cdGreatestHits", 'Greatest Hits');
                        xw.writeEndElement(); /* NameValueList */
                }
        } else if (CC == 2) {
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Format');
                xw.writeElementString('Value', escapeXml(document.getElementById("dvdFormat").value));
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Movie/TV Title');
                xw.writeElementString('Value', escapeXml(document.getElementById("dvdTitle").value));
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Actor');
                xw.writeElementString('Value', escapeXml(document.getElementById("dvdActor").value));
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Leading Role');
                xw.writeElementString('Value', escapeXml(document.getElementById("dvdLeadingRole").value));
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Release Year');
                xw.writeElementString('Value', escapeXml(document.getElementById("dvdReleaseYear").value));
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'DVD Edition Year');
                xw.writeElementString('Value', escapeXml(document.getElementById("dvdDVDEditionYear").value));
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Director');
                xw.writeElementString('Value', escapeXml(document.getElementById("dvdDirector").value));
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Genre');
                xw.writeElementString('Value', escapeXml(document.getElementById("dvdGenre").value));
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Rating');
                xw.writeElementString('Value', escapeXml(document.getElementById("dvdRating").value));
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Region Code');
                xw.writeElementString('Value', escapeXml(document.getElementById("dvdRegionCode").value));
                xw.writeEndElement(); /* NameValueList */

                if (document.getElementById("dvd3D").checked ||
                        document.getElementById("dvdAnniversaryEdition").checked ||
                        document.getElementById("dvdBoxSet").checked ||
                        document.getElementById("dvdCollectorsEdition").checked ||
                        document.getElementById("dvdDeluxeEdition").checked ||
                        document.getElementById("dvdDirectorsCut").checked ||
                        document.getElementById("dvdExtendedEdition").checked ||
                        document.getElementById("dvdFullScreen").checked ||
                        document.getElementById("dvdLimitedEdition").checked ||
                        document.getElementById("dvdPromo").checked ||
                        document.getElementById("dvdSignatureCollection").checked ||
                        document.getElementById("dvdSpecialEdition").checked ||
                        document.getElementById("dvdSteelbook").checked ||
                        document.getElementById("dvdUnratedEdition").checked ||
                        document.getElementById("dvdWidescreen").checked) {
                        xw.writeStartElement('NameValueList');
                        xw.writeElementString('Name', 'Edition');
                        itemSpecificCheckbox(xw, "dvd3D", '3D');
                        itemSpecificCheckbox(xw, "dvdAnniversaryEdition", 'Anniversary Edition');
                        itemSpecificCheckbox(xw, "dvdBoxSet", 'Box Set');
                        itemSpecificCheckbox(xw, "dvdCollectorsEdition", 'Collector&apos;s Edition');
                        itemSpecificCheckbox(xw, "dvdDeluxeEdition", 'Deluxe Edition');
                        itemSpecificCheckbox(xw, "dvdDirectorsCut", 'Director&apos;s Cut');
                        itemSpecificCheckbox(xw, "dvdExtendedEdition", 'Extended Edition');
                        itemSpecificCheckbox(xw, "dvdFullScreen", 'Full Screen');
                        itemSpecificCheckbox(xw, "dvdLimitedEdition", 'Limited Edition');
                        itemSpecificCheckbox(xw, "dvdPromo", 'Promo');
                        itemSpecificCheckbox(xw, "dvdSignatureCollection", 'Signature Collection');
                        itemSpecificCheckbox(xw, "dvdSpecialEdition", 'Special Edition');
                        itemSpecificCheckbox(xw, "dvdSteelbook", 'Steelbook');
                        itemSpecificCheckbox(xw, "dvdUnratedEdition", 'UnratedEdition');
                        itemSpecificCheckbox(xw, "dvdWidescreen", 'Widescreen');
                        xw.writeEndElement(); /* NameValueList */
                }

                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Former Rental');
                xw.writeElementString('Value', escapeXml(document.getElementById("dvdRental").value));
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Season');
                xw.writeElementString('Value', escapeXml(document.getElementById("dvdSeason").value));
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Country/Region of Manufacture');
                xw.writeElementString('Value', escapeXml(document.getElementById("dvdCountry").value));
                xw.writeEndElement(); /* NameValueList */
        } else if (CC == 3) {
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Card Manufacturer');
                xw.writeElementString('Value', escapeXml(document.getElementById("tcManufacturer").value));
                xw.writeEndElement(); /* NameValueList */

                if (document.getElementById("tcRookie").checked ||
                        document.getElementById("tcSerial").checked ||
                        document.getElementById("tcPoA").checked) {
                        xw.writeStartElement('NameValueList');
                        xw.writeElementString('Name', 'Card Attributes');
                        if (document.getElementById("tcRookie").checked) {
                                itemSpecificCheckbox(xw, "tcRookie", 'Rookie');
                        }
                        if (document.getElementById("tcSerial").checked) {
                                itemSpecificCheckbox(xw, "tcSerial", 'Serial Numbered');
                        }
                        if (document.getElementById("tcPoA").checked) {
                                itemSpecificCheckbox(xw, "tcPoA", 'Piece of Authentic');
                        }
                        xw.writeEndElement(); /* NameValueList */
                }

                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Product');
                xw.writeElementString('Value', 'Single');
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Professional Grader');
                xw.writeElementString('Value', 'Not Professionally Graded');
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Grade');
                xw.writeElementString('Value', 'Ungraded');
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Original/Reprint');
                xw.writeElementString('Value', 'Original');
                xw.writeEndElement(); /* NameValueList */
                //              xw.writeStartElement('NameValueList');
                //              xw.writeElementString('Name', 'Autograph Authentication');
                //              xw.writeElementString('Value', 'Not Authenticated');
                //              xw.writeEndElement(); /* NameValueList */
                //              xw.writeStartElement('NameValueList');
                //              xw.writeElementString('Name', 'Autograph Format');
                //              xw.writeElementString('Value', 'Not Autographed');
                //              xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Modified Item');
                xw.writeElementString('Value', 'No');
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Player');
                xw.writeElementString('Value', escapeXml(document.getElementById("tcPlayer").value));
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Team');
                xw.writeElementString('Value', escapeXml(document.getElementById("tcTeam").value));
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Season');
                xw.writeElementString('Value', escapeXml(document.getElementById("tcSeason").value));
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Year');
                xw.writeElementString('Value', escapeXml(document.getElementById("tcSeason").value));
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Era');
                if (category == '213') {
                        xw.writeElementString('Value', 'Modern (1981-Now)');
                } else {
                        xw.writeElementString('Value', 'Modern (1970-Now)');
                }
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'League');
                if (category == "215") {
                        xw.writeElementString('Value', 'NFL');
                } else if (category == "213") {
                        xw.writeElementString('Value', 'Major League');
                } else if (category == "214") {
                        xw.writeElementString('Value', 'NBA');
                } else if (category == "216") {
                        xw.writeElementString('Value', 'NHL');
                } else {
                        xw.writeElementString('Value', '');
                }
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Card Number');
                xw.writeElementString('Value', escapeXml(document.getElementById("tcNumber").value));
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Series');
                xw.writeElementString('Value', escapeXml(document.getElementById("tcSeries").value));
                xw.writeEndElement(); /* NameValueList */
                xw.writeStartElement('NameValueList');
                xw.writeElementString('Name', 'Country/Region of Manufacture');
                xw.writeElementString('Value', 'United States');
                xw.writeEndElement(); /* NameValueList */
        }

        xw.writeEndElement(); /* ItemSpecifics */
}

function itemSpecificCheckbox(xw, id, val) {
        if (document.getElementById(id).checked) {
                xw.writeElementString('Value', val);
        }
}

function _cb_findDuplicateListing(root) {
        var x;
        var response = root.findItemsAdvancedResponse[0];
        var ack = response.ack;
        if (ack != 'Success') {
                x = document.getElementById("productinfo").innerHTML += 'Duplicate Check Failed';

                if (ack == 'Failure' || ack == 'PartialFailure') {
                        return;
                }
        }

        var items = response.searchResult[0].item || [];

        if (Number(response.paginationOutput[0].totalEntries) > 0) {
                document.getElementById("productinfo").innerHTML += '<p class="w3-red"><strong>Duplicate, see Item Id <a href="https://www.ebay.com/itm/' + items[0].itemId + '" target="_blank">' + items[0].itemId + '</a></strong></p>';
                isDuplicate = true;
        }
}

function findDuplicateListing() {
        var keywordURL;
        var keyword = document.getElementById('keyword').value;

        // Construct the request
        url = configeBayFinding + "?";
        url += "OPERATION-NAME=findItemsAdvanced";
        url += "&SERVICE-VERSION=" + configeBayFindingVersion;
        url += "&SECURITY-APPNAME=" + configAppid;
        url += "&GLOBAL-ID=EBAY-US";
        url += "&RESPONSE-DATA-FORMAT=JSON";
        url += "&REST-PAYLOAD";
        url += "&keywords=";
        url += encodeURIComponent(keyword.trim().replace(/ /g, "+"));
        url += "&paginationInput.entriesPerPage=1";
        url += "&paginationInput.pageNumber=1";
        url += "&itemFilter(0).name=Seller";
        url += "&itemFilter(0).value=";
        url += configeBaySellerName;
        url += "&outputSelector=SellerInfo";

        // Submit the request
        var xhttp = new XMLHttpRequest();

        xhttp.onreadystatechange = function() {
                if (this.readyState == 4) {
                        _cb_findDuplicateListing(JSON.parse(this.responseText));
                }
        };

        xhttp.open("GET", configProxyUrl, true);
        xhttp.setRequestHeader("X-Proxy-Url", encodeURI(url));
        xhttp.send();

        return false;
}

function _cb_findPotentialDuplicateListing(root) {
        var x;
        var response = root.findCompletedItemsResponse[0];
        var ack = response.ack;
        if (ack != 'Success') {
                x = document.getElementById("productinfo").innerHTML += 'Duplicate Check Failed';

                if (ack == 'Failure' || ack == 'PartialFailure') {
                        return;
                }
        }

        var items = response.searchResult[0].item || [];

        if (Number(response.paginationOutput[0].totalEntries) > 0) {
                document.getElementById("productinfo").innerHTML += '<p class="w3-orange"><strong>Potential Duplicate, see Item Id <a href="https://www.ebay.com/itm/' + items[0].itemId + '" target="_blank">' + items[0].itemId + '</a></strong></p>';
        }
}

function findPotentialDuplicateListing() {
        var keywordURL;
        var keyword = document.getElementById('keyword').value;

        // Construct the request
        url = configeBayFinding + "?";
        url += "OPERATION-NAME=findCompletedItems";
        url += "&SERVICE-VERSION=" + configeBayFindingVersion;
        url += "&SECURITY-APPNAME=" + configAppid;
        url += "&GLOBAL-ID=EBAY-US";
        url += "&RESPONSE-DATA-FORMAT=JSON";
        url += "&REST-PAYLOAD";
        url += "&keywords=";
        url += encodeURIComponent(keyword.trim().replace(/ /g, "+"));
        url += "&paginationInput.entriesPerPage=1";
        url += "&paginationInput.pageNumber=1";
        url += "&itemFilter(0).name=Seller";
        url += "&itemFilter(0).value=";
        url += configeBaySellerName;
        url += "&outputSelector=SellerInfo";

        var xhttp = new XMLHttpRequest();

        xhttp.onreadystatechange = function() {
                if (this.readyState == 4) {
                        _cb_findPotentialDuplicateListing(JSON.parse(this.responseText));
                }
        };

        xhttp.open("GET", configProxyUrl, true);
        xhttp.setRequestHeader("X-Proxy-Url", encodeURI(url));
        xhttp.send();

        return false;
}

function findShopifyDuplicateListing() {
        var handle;
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function() {
                if (this.readyState == 4 && this.status == 200) {
                        //window.alert(this.responseText);
                        var json = JSON.parse(this.responseText);
                        if (json.products[0] !== undefined) {
                                document.getElementById("productinfo").innerHTML += '<p class="w3-orange"><strong>Potential Duplicate, see Shopify Item Id <a href="https://munatrading.com/products/' + handle + '" target="_blank">' + handle + '</a></strong></p>';
                        }
                }
        };

        handle = parseInt(document.getElementById('keyword').value, 10);

        xhttp.open("GET", configProxyUrl, true);
        xhttp.setRequestHeader("X-Proxy-Url", encodeURI(configShopifyUrl + configShopifyProductsUrl + '?handle=' + handle + '&fields=id'));
        xhttp.send();
}

function connected() {
        var x;

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

        x = document.getElementById("verify");
        x.className = x.className.replace(" w3-red", " w3-black");

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

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

function confirmUnload() {
        return "Do you really want to leave the quick listing tool?";
}

function uploadSiteHostedPictures() {
        imagesToUpload = 0;
        imageUploadError = false;

        ++imagesToUpload;
        uploadSiteHostedPicture('image1', 0);
        ++imagesToUpload;
        uploadSiteHostedPicture('image2', 1);
        for (var imageNumber = 0; imageNumber < 5; imageNumber++) {
                if (document.getElementById("image" + (imageNumber + 3) + "anchor").className.includes("w3-show")) {
                        ++imagesToUpload;
                        uploadSiteHostedPicture('image' + (imageNumber + 3), (imageNumber + 2));
                }
        }

        function checkImagesToUpload() {
                if (imagesToUpload > 0) {
                        window.setTimeout(checkImagesToUpload, 100); // wait 100 milliseconds
                } else {
                        if (!imageUploadError) {
                                verifyListing();
                        } else {
                                ImageURLs = [];
                                imagesToUpload = 0;
                        }
                }
        }

        checkImagesToUpload();
}

function uploadSiteHostedPicture(imageId, index) {
        var x;
        var i;
        var response;
        var str = '';
        var imageBasename = document.getElementById(imageId).src.substr(document.getElementById(imageId).src.lastIndexOf('/') + 1);
        var imageName = imageBasename.substr(0, imageBasename.indexOf('.jpg'));

        str += '<?xml version="1.0" encoding="utf-8"?>';
        str += '<UploadSiteHostedPicturesRequest xmlns="urn:ebay:apis:eBLBaseComponents">';
        str += '    <RequesterCredentials>';
        str += '        <eBayAuthToken>' + eBayAuthToken + '</eBayAuthToken>';
        str += '    </RequesterCredentials>';
        str += '        <ExtensionInDays>' + 30 + '</ExtensionInDays>';
        str += '    <PictureSet>Supersize</PictureSet>';
        str += '        <PictureName>' + imageBasename + '</PictureName>';
        str += '    <ExternalPictureURL>' + document.getElementById(imageId).src + '</ExternalPictureURL>';
        str += '</UploadSiteHostedPicturesRequest>';

        var xhr = new XMLHttpRequest();
        xhr.open("POST", configProxyUrl, true);
        xhr.setRequestHeader('X-EBAY-API-APP-NAME', configAppid);
        xhr.setRequestHeader('X-EBAY-API-DEV-NAME', configDevid);
        xhr.setRequestHeader('X-EBAY-API-CERT-NAME', configCertid);
        xhr.setRequestHeader('X-EBAY-API-COMPATIBILITY-LEVEL', configeBayTradingVersion);
        xhr.setRequestHeader('X-EBAY-API-CALL-NAME', 'UploadSiteHostedPictures');
        xhr.setRequestHeader('X-EBAY-API-SITEID', '0');
        xhr.setRequestHeader('X-Proxy-URL', configServiceEndpoint);

        xhr.onload = function() {
                var obj = XMLparse(xhr.responseXML);
                //window.alert(JSON.stringify(obj));
                //window.alert(vkbeautify.xml(xhr.responseText));

                var returnCode = obj.Ack;
                var x = document.getElementById("results");

                if (returnCode == 'Success') {
                        x.innerHTML += "<p>Image " + (index + 1) + " Upload: <strong>" + returnCode + "</strong></p>";
                        ImageURLs[index] = obj.SiteHostedPictureDetails.FullURL;
                } else {
                        ImageURLs = [];
                        imageUploadError = true;

                        x.innerHTML += "<p>Image " + (index + 1) + " Upload: <strong>" + returnCode + "</strong></p>";

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

                --imagesToUpload;
        };

        xhr.send(str);
}

function findDiscogsReleases(str) {
        if (str.length < 1) {
                return;
        }

        // Construct the request
        url = configDiscogsApiUrl + "?";
        url += "token=";
        url += configDiscogsToken;
        url += "&type=release";
        url += "&format=CD";
        if (isNumeric(str)) {
                url += "&barcode=";
        } else {
                url += "&q=";
        }
        url += str;

        var xhttp = new XMLHttpRequest();

        xhttp.onreadystatechange = function() {
                if (this.readyState == 4) {
                        var response = this.responseText;
                        if (this.status != 200) { // discogs returns HTML instead JSON
                                response = '{"pagination": {"per_page": 50, "items": 0, "page": 1, "urls": {}, "pages": 1}, "results": []}';
                        }
                        _cb_findDiscogsReleases(JSON.parse(response));
                }
        };

        xhttp.open("GET", configProxyUrl, true);
        xhttp.setRequestHeader("X-Proxy-Url", encodeURI(url));
        xhttp.setRequestHeader("User-Agent", configDiscogsUserAgent);
        xhttp.send();
}

function _cb_findDiscogsReleases(root) {
        var tableStr = '';
        var i, j;
        var x;

        tableStr = '<h3>Discogs Releases</h3>';
        tableStr += '<div class="w3-responsive">';
        tableStr += '<table id="discogsTable" class="w3-table-all w3-tiny w3-hoverable">';
        tableStr += '<thead>';
        tableStr += '<tr>';
        tableStr += tableHeader('Title');
        tableStr += tableHeader('Label');
        tableStr += tableHeader('Catalog #');
        tableStr += tableHeader('Format');
        tableStr += tableHeader('Year');
        tableStr += tableHeader('Country');
        tableStr += tableHeader('Genre');
        tableStr += '</tr>';
        tableStr += '</thead>';

        for (i = 0; i < root.results.length; i++) {
                tableStr += '<tr>';

                tableStr += tableCellLink(root.results[i].title, configDiscogsBaseUrl + root.results[i].uri);

                str = [];
                for (j = 0; j < root.results[i].label.length && j < 2; j++) {
                        str.push(root.results[i].label[j]);
                }
                tableStr += tableCell(str.join(', '));

                tableStr += tableCell(root.results[i].catno);

                str = [];
                for (j = 0; j < root.results[i].format.length; j++) {
                        str.push(root.results[i].format[j]);
                }
                tableStr += tableCell(str.join(', '));

                tableStr += tableCell(root.results[i].year);
                tableStr += tableCell(root.results[i].country);

                tableStr += tableCell(root.results[i].genre.join(', '));

                tableStr += tableCellButton(root.results[i].resource_url);

                tableStr += '</tr>';
        }

        tableStr += '</table>';

        if (root.results.length === 0) {
                tableStr += '<div class="w3-container">';
                tableStr += '<form id="searchFormDiscogs" class="w3-container w3-light-grey w3-padding w3-small" onsubmit="return specialDiscogsSearch();">';
                tableStr += '<label for="discogsRelease" class="keepTogether">Discogs Release #:</label>';
                tableStr += '<input id="discogsRelease" name="discogsRelease" class="w3-input-2 w3-border" style="width:20%;" type="text" maxlength="10">';
                tableStr += '<input type="button" class="w3-button w3-circle w3-margin w3-black w3-tiny w3-ripple" onclick="return specialDiscogsSearch();" value="Find" />';
                tableStr += '</form>';
                tableStr += '</div>';
        }


        x = document.getElementById("discogsReleases");
        x.innerHTML = tableStr;
        if (x.className.indexOf("w3-show") == -1) {
                x.className += " w3-show";
        }

        x = document.getElementById("productinfo");
        x.innerHTML += '<p>Get <a href="https://www.getcdprices.com/upc/' + upc + '" target="blank">CD Price</a></p>';
}

function specialDiscogsSearch() {
        if (document.getElementById("discogsRelease").value.length > 0) {
                findDiscogsReleases("r" + document.getElementById("discogsRelease").value);
        }
}

function tableHeader(str) {
        return ('<th>' + (str === undefined ? '' : str) + '</th>');
}

function tableCell(str) {
        return ('<td>' + (str === undefined ? '' : str) + '</td>');
}

function tableCellLink(text, link) {
        var str = "<a href=\"" + link + "\" target=\"_blank\">" + text + "</a>";
        return ('<td>' + str + '</td>');
}

function tableCellButton(link) {
        var str = "<button class=\"w3-button w3-small w3-circle w3-black\" onclick='getDiscogsRelease(\"" + link + "\");'>+</button>";
        return ('<td>' + str + '</td>');
}

function getDiscogsRelease(url) {
        var xhttp = new XMLHttpRequest();

        xhttp.onreadystatechange = function() {
                if (this.readyState == 4) {
                        _cb_getDiscogsRelease(JSON.parse(this.responseText));
                }
        };

        xhttp.open("GET", configProxyUrl, true);
        xhttp.setRequestHeader("X-Proxy-Url", encodeURI(url));
        xhttp.setRequestHeader("User-Agent", configDiscogsUserAgent);
        xhttp.send();
}

function _cb_getDiscogsRelease(root) {
        var str;
        var titleStr = '';
        var trackStr;
        var artist;
        var label;
        var year;
        var position;
        var promo = '';
        var digipak = '';
        var duration = '';
        var quantity = '';
        var i, j;
        var x;
        var temp;

        // Tracklist
        trackStr = [];
        allNumbers = true;

        for (i = 0; i < root.tracklist.length; i++) {
                str = '';
                if (root.tracklist[i].position.length > 0) {
                        str += root.tracklist[i].position + '. ';

                        position = Number(root.tracklist[i].position);
                        if (position === NaN || position != (i + 1)) {
                                allNumbers = false;
                        }
                }

                if (root.tracklist[i].artists !== undefined) {
                        for (j = 0; j < root.tracklist[i].artists.length; j++) {
                                temp = root.tracklist[i].artists[j].name.replace(/\([0-9]+\)$/, "");
                                str += temp + " " + root.tracklist[i].artists[j].join + " ";
                        }
                        str += " - ";
                }

                str += root.tracklist[i].title;

                if (root.tracklist[i].duration.length > 0) {
                        str += " [" + root.tracklist[i].duration + "]";
                }

                trackStr.push(str);
        }

        str = str.replace(/  +/g, ' ');
        if (allNumbers) {
                for (i = 0; i < trackStr.length; i++) {
                        trackStr[i] = trackStr[i].replace(/^\d+. /g, '');
                }
        } else {
                document.getElementById("cdUnorderedTrackList").checked = true;
        }

        $("#cdTracks").val(trackStr.join('\n'));

        // Title
        titleStr = '';
        artist = '';
        label = '';
        year = '';
        catno = ''
        if (root.artists !== undefined) {
                for (i = 0; i < root.artists.length; i++) {
                        temp = root.artists[i].name.replace(/\([0-9]+\)$/, "");
                        artist += temp + " " + root.artists[i].join + " ";
                }
        }

        artist = artist.trim();
        if (artist != 'Various') {
                titleStr += artist + " - " + root.title;
        } else {
                titleStr += root.title + " by Various Artists";
        }
        titleStr += " (CD";

        document.getElementById("cdTitle").value = root.title;

        // formats
        promo = '';
        duration = '';
        quantity = '';
        digipak = '';
        for (i = 0; i < root.formats.length; i++) {
                if (root.formats[i].name.startsWith("CD")) {
                        for (j = 0; j < root.formats[i].descriptions.length; j++) {
                                if (root.formats[i].descriptions[j] == "Enhanced") {
                                        document.getElementById("cdEnhanced").checked = true;
                                } else if (root.formats[i].descriptions[j] == "Compilation") {
                                        document.getElementById("cdCompilation").checked = true;
                                } else if (root.formats[i].descriptions[j] == "Digipak") {
                                        document.getElementById("cdDigipak").checked = true;
                                        digipak = root.formats[i].descriptions[j];
                                        setCdConditionDescription('D');
                                } else if (root.formats[i].descriptions[j] == "Promo") {
                                        document.getElementById("cdPromo").checked = true;
                                        promo = 'PROMO';
                                } else if (root.formats[i].descriptions[j] == "Reissue") {
                                        document.getElementById("cdReissue").checked = true;
                                } else if (root.formats[i].descriptions[j] == "Remastered") {
                                        document.getElementById("cdRemastered").checked = true;
                                } else if (root.formats[i].descriptions[j] == "HDCD") {
                                        document.getElementById("cdHDCD").checked = true;
                                } else if (root.title.includes('Greatest Hits')) {
                                        document.getElementById("cdGreatestHits").checked = true;
                                } else if (root.formats[i].descriptions[j] == "Album" ||
                                        root.formats[i].descriptions[j] == "Mini-Album" ||
                                        root.formats[i].descriptions[j] == "EP" ||
                                        root.formats[i].descriptions[j] == "Maxi-Single" ||
                                        root.formats[i].descriptions[j] == "Single") {
                                        document.getElementById("cdDuration").value = root.formats[i].descriptions[j];
                                        $('#cdDuration').prop('disabled', false).trigger("chosen:updated");
                                        if (!root.formats[i].descriptions[j].includes("Album")) {
                                                duration = root.formats[i].descriptions[j];
                                        }
                                }

                                discogsQty = Number(root.formats[i].qty);
                                if (discogsQty > 1) {
                                        setCdConditionDescription('P');
                                        quantity = Number(root.formats[i].qty) + ' Discs';
                                }
                        }
                }
        }

        // genres
        if (document.getElementById("cdGenre").value.length <= 1) {
                for (i = 0; i < root.genres.length; i++) {
                        if (isInSelectList("cdGenre", root.genres[i])) {
                                $('#cdGenre').prop('disabled', false).trigger("chosen:updated");
                                break;
                        }
                }
        }

        // country
        if (root.country != 'US' && !root.country.includes('Europe')) {
                if (root.country == 'UK') {
                        document.getElementById("cdCountry").value = 'United Kingdom';
                } else {
                        document.getElementById("cdCountry").value = root.country;
                }
        } else {
                document.getElementById("cdCountry").value = "United States";
        }

        // title remainder
        if (duration.length > 0) {
                titleStr += ", " + duration;
        }

        if (digipak.length > 0) {
                titleStr += ", " + digipak;
        }

        if (quantity.length > 0) {
                titleStr += ", " + quantity;
        }

        if (root.released !== undefined) {
                year = root.released.substr(0, 4);
                titleStr += ", " + year;
        }

        if (root.labels !== undefined) {
                label = root.labels[0].name;
                titleStr += ", " + label;
        }

        titleStr += ")";

        if (promo.length > 0) {
                titleStr += " " + promo + ' ' + root.labels[0].catno;
        }

        titleStr = titleStr.trim();
        titleStr = titleStr.replace(/  +/g, ' ');
        titleStr - titleStr.replace('<br>', '');

        if (isNumeric(document.getElementById("title").value) || document.getElementById("title").value.length === 0) {
                document.getElementById("title").value = titleStr;
                printTitleLength();
                document.getElementById("cdArtist").value = artist;
                document.getElementById("cdRecordLabel").value = label;
                document.getElementById("cdReleaseYear").value = year;
        }
}

function isInSelectList(list, value) {
        var i;
        var opts = document.getElementById(list).options;

        for (var i = 0; i < opts.length; ++i)
                if (opts[i].value.includes(value)) {
                        document.getElementById(list).value = opts[i].value;
                        return true;
                }

        return false;
}

function printTitleLength() {
        var len = document.getElementById("title").value.length;

        color = (len > 80 ? 'red' : 'black');

        document.getElementById("titleLength").innerHTML = '(' + len + ')';
        document.getElementById("titleLength").style.color = color;
}

/**
 * Creates a read/writable property which returns a function set for write/set (assignment)
 * and read/get access on a variable
 *
 * @param {Any} value initial value of the property
 */
function createProperty(value) {
        var _value = value;

        /**
         * Overwrite getter.
         *
         * @returns {Any} The Value.
         * @private
         */
        function _get() {
                return _value;
        }

        /**
         * Overwrite setter.
         *
         * @param {Any} v   Sets the value.
         * @private
         */
        function _set(v) {
                _value = v;
        }

        return {
                "get": _get,
                "set": _set
        };
};

/**
 * Creates or replaces a read-write-property in a given scope object, especially for non-writable properties.
 * This also works for built-in host objects (non-DOM objects), e.g. navigator.
 * Optional an initial value can be passed, otherwise the current value of the object-property will be set.
 *
 * @param {Object} objBase  e.g. window
 * @param {String} objScopeName    e.g. "navigator"
 * @param {String} propName    e.g. "userAgent"
 * @param {Any} initValue (optional)   e.g. window.navigator.userAgent
 */
function makePropertyWritable(objBase, objScopeName, propName, initValue) {
        var newProp,
                initObj;

        if (objBase && objScopeName in objBase && propName in objBase[objScopeName]) {
                if (typeof initValue === "undefined") {
                        initValue = objBase[objScopeName][propName];
                }

                newProp = createProperty(initValue);

                try {
                        Object.defineProperty(objBase[objScopeName], propName, newProp);
                } catch (e) {
                        initObj = {};
                        initObj[propName] = newProp;
                        try {
                                objBase[objScopeName] = Object.create(objBase[objScopeName], initObj);
                        } catch (e) {
                                // Workaround, but necessary to overwrite native host objects
                        }
                }
        }
};

    </script>

    <script src="js/jquery.js"></script>
    <script src="js/chosen.jquery.min.js"></script>
    <script src="js/chosen.init.list.js"></script>

</body>
</html>