
prices = {    BoxedVintageDolls : 30.99,    CardedNineteenEightyOnwards : 20.99,    LooseFigures : 12.99,    GaloobVintageLargeCardedFigures : 27.99,    GaloobLargeLooseFigures : 17.99,    ThreeAndThreeQtrBoxedVehicles : 'POA',    VintageNineteenEightiesCardedFigures : 24.99,    VintageNineteenEightiesLoose : 15.99,    RHINO : 55.99,    Firefly : 35.99,    Condor : 30.99,    TwoPackFigures : 22.99,    Piranha : 35.99,    VintageCardedFigures : 20.99,    VintageCardedFiguresUVCases : 25.99,    ModernCardedNineteenNinetyOnwards : 22.99,    VintageLooseFiguresIncludingNineteenNinetyOnwards : 12.99,    VintageLooseFiguresAmanamanHanSoloCarboniteGraded : 14.99,    LooseFiguresCoinCustomCase : 19.99,    LooseFiguresCoinCustomCaseUGraded : 21.99,    BoxedATAT : 75.99,    BoxedVintageTwelveInchDolls : 45.99,    VintageModernFiguresUGraded : 14.99,    VintageHothWampa : 35.99,    VintageMiniRigs : 30.99,    VintageEndorForrestRangerFlapVersion : 30.99,    VintageEndorForrestTriLogoBox : 35.99,    VintageEwokCombatGlider : 33.99,    VintageEwokVillage : 75.99,    VintageVehicleMaintenanceEnergizerTripodLaserCannon : 25.99,    VintageSlaveOne : 50.99,    VintageSySnootlesReboBandTriLogoBox : 33.99,    VintageSySnootlesReboBandBubblePack : 35.99,    VintageSySnootlesReboBandLoose : 35.99,    VintageJabbaHuttPlaysetSearsBox : 50.99,    VintageTieInterceptor : 60.99,    VintageTieFighter : 50.99,    VintageXWing : 57.99,    VintageMilleniumFalcon : 75.99,    TFVintageCardedFigures : 27.99,    TFVintageLooseFigures : 17.99,    TFAstralMoat : 45.99,    DependantBoxCard : 'POA'};
        
function setOptions(categoryDropDown, selbox) {    
    category = categoryDropDown.options[categoryDropDown.selectedIndex].value;
    strId = categoryDropDown.name;
    document.getElementById('Quantity' + strId.substring(16)).value = '';
    document.getElementById('Price' + strId.substring(16)).value = '';
    selbox.options.length = 0;
    
    if (category == "") {
      selbox.options[selbox.options.length] = new Option('Please select a category first.','');
    }
    if (category == "Action Force") {
      selbox.options[selbox.options.length] = new Option('Please select...','');//new Option(text, value, defaultSelected, selected)
      selbox.options[selbox.options.length] = new Option("Boxed Vintage Dolls",'BoxedVintageDolls');//'30');//
      selbox.options[selbox.options.length] = new Option("Carded 1980 Onwards",'CardedNineteenEightyOnwards');
      selbox.options[selbox.options.length] = new Option("Loose Figures",'LooseFigures');
    }
    if (category == "A-Team") {
      selbox.options[selbox.options.length] = new Option('Please select...','');
      selbox.options[selbox.options.length] = new Option('Galoob Vintage Large Carded Figures','GaloobVintageLargeCardedFigures');
      selbox.options[selbox.options.length] = new Option('Galoob Large Loose Figures','GaloobLargeLooseFigures');
      selbox.options[selbox.options.length] = new Option('3 3/4 Boxed Vehicles','ThreeAndThreeQtrBoxedVehicles');
    }
    if (category == "He-Man") {
      selbox.options[selbox.options.length] = new Option('Please select...','');
      selbox.options[selbox.options.length] = new Option("Vintage 1980's Carded Figures",'VintageNineteenEightiesCardedFigures');
      selbox.options[selbox.options.length] = new Option("Vintage 1980's Loose",'VintageNineteenEightiesLoose');
    }
    if (category == "MASK") {
      selbox.options[selbox.options.length] = new Option('Please select...','');
      selbox.options[selbox.options.length] = new Option("RHINO",'RHINO');
      selbox.options[selbox.options.length] = new Option("Firefly",'Firefly');
      selbox.options[selbox.options.length] = new Option("Condor",'Condor');
      selbox.options[selbox.options.length] = new Option("2 Pack Figures",'TwoPackFigures');
      selbox.options[selbox.options.length] = new Option("Piranha",'Piranha');
    }
    if (category == "Star Wars") {
      selbox.options[selbox.options.length] = new Option('Please select...','');
      selbox.options[selbox.options.length] = new Option('Vintage Carded Figures','VintageCardedFigures');
      selbox.options[selbox.options.length] = new Option('Vintage Carded Figures - UV Protective Cases','VintageCardedFiguresUVCases');
      selbox.options[selbox.options.length] = new Option('Carded Modern 1990 Onwards','ModernCardedNineteenNinetyOnwards');
      selbox.options[selbox.options.length] = new Option('Vintage Loose Figures Including 1990 Onwards','VintageLooseFiguresIncludingNineteenNinetyOnwards');
      selbox.options[selbox.options.length] = new Option('Vintage Loose Figures Amanaman & Han Solo Carbonite Graded (larger case)','VintageLooseFiguresAmanamanHanSoloCarboniteGraded');
      selbox.options[selbox.options.length] = new Option('Loose Figures with coin in a custom case','LooseFiguresCoinCustomCase');
      selbox.options[selbox.options.length] = new Option('Loose Figures with coin in a custom case U graded (Uncirculated)','LooseFiguresCoinCustomCaseUGraded');
      selbox.options[selbox.options.length] = new Option('Boxed ATAT','BoxedATAT');
      selbox.options[selbox.options.length] = new Option('Boxed Vintage 12" Dolls','BoxedVintageTwelveInchDolls');
      selbox.options[selbox.options.length] = new Option('Vintage\\Modern Figures U Graded (Uncirculated)','VintageModernFiguresUGraded');
      selbox.options[selbox.options.length] = new Option('Vintage Hoth Wampa','VintageHothWampa');
      selbox.options[selbox.options.length] = new Option('Vintage Mini Rigs ISP-6, INT-4, CAP-2, MLC-3, PDT-8','VintageMiniRigs');
      selbox.options[selbox.options.length] = new Option('Vintage Endor Forrest Ranger Flap Version','VintageEndorForrestRangerFlapVersion');
      selbox.options[selbox.options.length] = new Option('Vintage Endor Forrest Tri Logo Box','VintageEndorForrestTriLogoBox');
      selbox.options[selbox.options.length] = new Option('Vintage Ewok Combat Glider','VintageEwokCombatGlider');
      selbox.options[selbox.options.length] = new Option('Vintage Ewok Village','VintageEwokVillage');
      selbox.options[selbox.options.length] = new Option('Vintage Vehicle Maintenance Energizer & Tripod Laser Cannon','VintageVehicleMaintenanceEnergizerTripodLaserCannon');
      selbox.options[selbox.options.length] = new Option('Vintage Slave 1','VintageSlaveOne');
      selbox.options[selbox.options.length] = new Option('Vintage Sy Snootles and the Rebo Band Tri Logo Box','VintageSySnootlesReboBandTriLogoBox');
      selbox.options[selbox.options.length] = new Option('Vintage Sy Snootles and the Rebo Band Bubble Pack','VintageSySnootlesReboBandBubblePack');
      selbox.options[selbox.options.length] = new Option('Vintage Sy Snootles and the Rebo Band Loose','VintageSySnootlesReboBandLoose');
      selbox.options[selbox.options.length] = new Option('Vintage Jabba and the Hutt Playset (includes the sears exclusive box)','VintageJabbaHuttPlaysetSearsBox');
      selbox.options[selbox.options.length] = new Option('Vintage Tie Interceptor','VintageTieInterceptor');
      selbox.options[selbox.options.length] = new Option('Vintage Tie Fighter','VintageTieFighter');
      selbox.options[selbox.options.length] = new Option('Vintage X-Wing','VintageXWing');
      selbox.options[selbox.options.length] = new Option('Vintage Millenium Falcon','VintageMilleniumFalcon');
    }
    if (category == "ThunderCats") {
      selbox.options[selbox.options.length] = new Option('Please select...','');
      selbox.options[selbox.options.length] = new Option('Vintage Carded Figures','TFVintageCardedFigures');
      selbox.options[selbox.options.length] = new Option('Vintage Loose Figures','TFVintageLooseFigures');
      selbox.options[selbox.options.length] = new Option('Astral Moat','TFAstralMoat');
    }
    if (category == "Transformers") {
      selbox.options[selbox.options.length] = new Option('Please select...','');
      selbox.options[selbox.options.length] = new Option('Dependant on BoxCard','DependantBoxCard');
    }
}function prepareRecord(itemDropDown) {    strId = itemDropDown.name;    if (itemDropDown.value == '') {        document.getElementById('Quantity' + strId.substring(12)).value = '';        document.getElementById('Price' + strId.substring(12)).value = '';    }    else {        document.getElementById('Quantity' + strId.substring(12)).value = 1;        document.getElementById('Price' + strId.substring(12)).value = prices[itemDropDown.value];        //document.getElementById('Price' + strId.substring(12)).value = itemDropDown.value;    }}function isNumeric(number) {
    return (number!=null && !isNaN(number));
}function calcPrice(qty) {    if (qty.value != '') {        if (!isNumeric(qty.value) || qty.value=='0') {            document.getElementById('Quantity'+strId.substring(8)).value = '1';        }        strId = qty.name;                var price = prices[document.getElementById('itemDropDown'+strId.substring(8)).value];                document.getElementById('Price'+strId.substring(8)).value = price * (document.getElementById('Quantity'+strId.substring(8)).value);        //document.getElementById('Price'+strId.substring(8)).value = (document.getElementById('itemDropDown'+strId.substring(8)).value) * (document.getElementById('Quantity'+strId.substring(8)).value);            }}function validateRecord(buttonName) {    strId = buttonName;    if (document.getElementById('categoryDropDown'+strId.substring(6)).value == "")        return false;    else if (document.getElementById('itemDropDown'+strId.substring(6)).value == "")        return false;    else if (!isNumeric(document.getElementById('Quantity'+strId.substring(6)).value))        return false;    //else if (document.getElementById('Price'+strId.substring(6)).value != (document.getElementById('itemDropDown'+strId.substring(6)).value * document.getElementById('Quantity'+strId.substring(6)).value))    else if (document.getElementById('Price'+strId.substring(6)).value != 'POA')            if (document.getElementById('Price'+strId.substring(6)).value != (prices[document.getElementById('itemDropDown'+strId.substring(6)).value] * document.getElementById('Quantity'+strId.substring(6)).value)) {                return false;            }    return true;}function addToBasket(button) {
    var tbl = document.getElementById('Orders');
    if (button.value == "Add") {
        if (validateRecord(button.name)) {
            var lastRow = tbl.rows.length;
            var row = tbl.insertRow(lastRow);
            controlId++;
            //document.getElementById('categoryDropDown' + (controlId - 1)).disabled = true;
            var strName = 'categoryDropDown' + controlId; 
            
            var cellName = row.insertCell(0);
            cellName.innerHTML = "<select id=" + strName + " name=" + strName + " size=\"1\" onchange=\"setOptions(this, document.orderForm.itemDropDown" + controlId + ");\">"
                + "<option value=\"\" selected=\"selected\">Select...</option>"
                + "<option value=\"Action Force\">Action Force\\GI Joe</option>"
                + "<option value=\"A-Team\">A-Team</option>"
                + "<option value=\"He-Man\">He-Man\\Masters Of The Universe</option>"
                + "<option value=\"MASK\">M.A.S.K.</option>"
                + "<option value=\"Star Wars\">Star Wars</option>"
                + "<option value=\"ThunderCats\">ThunderCats</option>"
                + "<option value=\"Transformers\">Transformers</option>"
                + "</select>";
            
            IEHack(controlId);
            document.getElementById('itemDropDown' + (controlId - 1)).readonly;
            strName = 'itemDropDown' + controlId;
            cellName = row.insertCell(1);
            cellName.innerHTML = "<span class=\"select-box\"><select id=" + strName + " name=" + strName + " size=\"1\" onchange=\"prepareRecord(this);\"><option value=\"\" selected=\"selected\">Please select a Category first.</option></select></span>";
            
//            strName = 'ProductName' + controlId;
//            cellName = row.insertCell(2);
//            cellName.innerHTML = "<input id=" + strName + " name=" + strName + " type=\"text\" size=\"35\" />";
            
            document.getElementById('Quantity' + (controlId - 1)).readOnly = true;
            strName = 'Quantity' + controlId;
            cellName = row.insertCell(2);
            cellName.align = "center";
            cellName.innerHTML = "<input id=" + strName + " name=" + strName + " type=\"text\" size=\"1\" onchange=\"calcPrice(this)\" />";
            
            strName = 'Price' + controlId;
            cellName = row.insertCell(3);
            cellName.align = "center";
            cellName.innerHTML = "<input id=" + strName + " name=" + strName + " type=\"text\" size=\"3\" readonly=\"readonly\" />";
            
            strName = 'Button' + controlId;
            cellName = row.insertCell(4);
            cellName.innerHTML = "<input id=" + strName + " name=" + strName + " type=\"button\" value=\"Add\" onclick=\"addToBasket(this);\" />";
            
            button.value = 'Remove';
            var strId = button.name;
            
            if (document.getElementById('Price'+strId.substring(6)).value != 'POA') {
                //Calculate new total
                var Total = document.getElementById('totalTextBox').value                document.getElementById('totalTextBox').value = '£' + (+Total.substring(1) + +document.getElementById('Price'+strId.substring(6)).value);
            }
        }
    }
    else {
        var strId = button.name;
        if (document.getElementById('Price'+strId.substring(6)).value != 'POA') {
            var Total = document.getElementById('totalTextBox').value
            document.getElementById('totalTextBox').value = '£' + (+Total.substring(1) - +document.getElementById('Price'+strId.substring(6)).value);
        }
        tbl.deleteRow(button.parentNode.parentNode.rowIndex);
    }
}