var total_entries = 0;
var total_ccost = 0;
var total_kcost = 0;
var total_bcost = 0;
var total_rcost = 0;
var total_wcost = 0;
var total_cars = 0;
var total_cars_kits = 0;
var total_racers = 0;
var total_wheels = 0;
var total_books = 0;
var total_cars_dsply = 0;
var total_cars_kits_dsply = 0;
var total_racers_dsply = 0;
var total_wheels_dsply = 0;
var total_books_dsply = 0;
var total_ship = 0;
var curAcc = 0;
var chsprice = 10;
var fullname = "";
var fulladdress = "";
var emailaddr = "";
var cartext = new Array(200);
var cartype = new Array(200);
var carid = new Array(200);
var slctn = new Array(100);
var prop1 = new Array(100);
var cnt = new Array(100);
var cost = new Array(100);
var chs = new Array(100);
var rcr = new Array(100);
var prcof = new Array(100);
var compactform = new String();
var mailtoindex = -1;
var cksw = false;
var skipcoloradj = "false";
var Mcardesc = "";
var Mcarprep = "";


function LoadCarTable() {
    for (i = 1; i < document.order.cars.length-1; i++) {
        cartext[i] = document.order.cars.options[i].text;
        cartype[i] = document.order.cars.options[i].text.substring(1, 4);
        carid[i] = document.order.cars.options[i].value;
    }
}

function LoadCarSubTable() {
    carcnt = 0;
    selindx = document.order.type.selectedIndex;
    for (i = 0; i < cartext.length - 1; i++) {
        if (cartype[i] == document.order.type.options[selindx].value) {
            carcnt = carcnt + 1;
        }
    }
    document.order.cars.options.length = carcnt;
    
    carcnt = 0;
    for (i = 0; i < cartext.length - 1; i++) {
        if (cartype[i] == document.order.type.options[selindx].value) {
            if (carcnt == 0) {
                document.order.cars.options[0] = new Option(cartext[i], carid[i], false, false);
            }
            else {
                document.order.cars.options[carcnt].text = cartext[i];
                document.order.cars.options[carcnt].value = carid[i];
            }
            carcnt = carcnt + 1;
        }
    }
    document.order.cars.options[0].selected = "selected";
}

function ConfirmEmail() {
    if (document.order.emailtxt.value <= ">") {
        alert("Email address required to e-mail form.");
        return false;
    }
    return true;
}

function SetScreenAsp(cardesc) {
    StartOffRemote(cardesc);
    AdjustPropsRemote();
    cartext = GetCarText(cardesc);
    document.order.namex.value = cartext.substring(5, cartext.length);
}

function SetScreenAspSpec(cardesc) {
    StartOffRemote(cardesc);
    AdjustPropsRemote();
}

function AdJustSubButtonType(sw) {
    document.order.subswitch.value = sw;
}

function AdjustImage() {
    selindx = document.order.cars.selectedIndex;
    seltype = document.order.type.selectedIndex;
    selaccs = document.order.accsry.selectedIndex;
    if (document.order.type.options[seltype].value == "Whl")
     {
       bld = document.order.accsry.options[selaccs].value;
     }
     else
     {
       bld = document.order.cars.options[selindx].value;
     }
    document.images[0].src = "images/GrayedOut/tbgmv" + bld + ".gif";
}

function SetScreen_not_used(sw) {
    param = unescape(window.location.href);
    chkchar = 0;
    while ((param.substring(chkchar, chkchar + 1) != "?") && (chkchar <= param.length)) {
        chkchar++;
    }
    chkchar++;
    comma = 0;
    atcomma = false;
    selpic = "";
    if (chkchar <= param.length) {
        bld = param.substring(chkchar, chkchar + 1);
    }
    // car#,wheelbase,TO clearance,
    while (chkchar <= param.length) {
        if ((comma == 1) && (atcomma == true)) {
            if (sw == '2') {
                document.images[0].src = "images/Cars/mv" + bld + "f.jpg";
                document.images[1].src = "images/Cars/mv" + bld + "b.jpg";
            }
            else {
                document.images[0].src = "images/Cars/mv" + bld + ".jpg";
            }
            selpic = bld;
            atcomma = false;
            bld = "";
        }
        if ((comma == 2) && (atcomma == true)) {
            if (bld == "L") {
                document.order.whlbsx.value = "LONG";
            }
            else {
                document.order.whlbsx.value = "SHORT";
            }
            atcomma = false;
            bld = "";
        }
        chkchar++
        if (param.substring(chkchar, chkchar + 1) == ",") {
            comma++;
            atcomma = true;
        }
        else {
            if (chkchar <= param.length) {
                bld += param.substring(chkchar, chkchar + 1);
            }
        }

    }

    if ((bld == "N") || (bld == "n")) {
        document.order.tuffx.value = "NO";
    }
    if ((bld == "Y") || (bld == "y")) {
        document.order.tuffx.value = "YES";
    }
    if (selpic > " ") {
        if ((selpic == '20a') || (selpic == '20c')) {
            selpic = '20y';
        }
        StartOffRemote(selpic);
        cartext = GetCarText(selpic);
        document.order.namex.value = cartext.substring(5, cartext.length);
        AdjustProps();
        AdjustColors();
        UpdatePrice();
    }
}

function UpdatePrice() {
    chsaddon = 0;
    carprice = 0;
    rcraddon = 0;
    selindxch = document.order.accsry.selectedIndex;
    selectionch = document.order.accsry.options[selindxch].text.substring(0, 1);
    checkcartext = document.order.cars.options[document.order.cars.selectedIndex].text;
    if ((selectionch == "A") && ((checkcartext.substring(1, 2) == "C") || (checkcartext.substring(1, 2) == "R"))) {
        chsaddon = chsprice;
    }
    if ((selectionch != "C") && (checkcartext.substring(1, 2) == "R") && (checkcartext.substring(1, 4) != "XXX")) {
        rcraddon = 3;
    }
    selindx = document.order.cars.selectedIndex;
    carprice = 3;
    if (checkcartext.substring(1, 4) == "XXX") {
        carprice = 0;
    }
    if (checkcartext.substring(1, 4) == "Rcr") {
        carprice = 15;
    }
    if (checkcartext.substring(1, 4) == "Bok") {
        carprice = 16;
    }
    if (((checkcartext.substring(1, 4) == "Cpu") || (checkcartext.substring(1, 4) == "Cwg") ||
  (checkcartext.substring(1, 4) == "Ca5") || (checkcartext.substring(1, 4) == "Ca6") ||
  (checkcartext.substring(1, 4) == "Cmu")) && (selectionch == "C")) {
        carprice = 15;
    }
    if (((checkcartext.substring(1, 4) == "Cst") || (checkcartext.substring(1, 4) == "Cdr")) && (selectionch == "C")) {
        carprice = 20;
    }
    if (((checkcartext.substring(1, 4) == "Cpu") || (checkcartext.substring(1, 4) == "Cwg") ||
  (checkcartext.substring(1, 4) == "Ca5") || (checkcartext.substring(1, 4) == "Ca6") ||
  (checkcartext.substring(1, 4) == "Cmu")) && ((selectionch == "A") || (selectionch == "B"))) {
        carprice = 44;
    }
    if ((checkcartext.substring(1, 4) == "Cyk") || (checkcartext.substring(1, 4) == "Cus")) {
        carprice = 54;
    }
    if (((checkcartext.substring(1, 4) == "Cst") || (checkcartext.substring(1, 4) == "Cdr") ||
  (checkcartext.substring(1, 4) == "Ctt") || (checkcartext.substring(1, 4) == "Cem")) &&
  ((selectionch == "A") || (selectionch == "B"))) {
        carprice = 56;
    }
    carprice += chsaddon + rcraddon;
    document.order.price.value = "$" + carprice;
}

function AdjustTypeRemote() {
    LoadCarSubTable();
    AdjustPropsRemote();
}

function AdjustPropsRemote() {
    AdjStandard();
    AdjustProps();
    AdjustColors();
    AdjustImage();
    UpdatePrice();
}

function AdjustColorsRemote() {
    AdjustColors();
    AdjustImage();
    UpdatePrice();
}

function UpdatePriceRemote() {
    AdjustColors();
    AdjustImage();
    UpdatePrice();

}

function StartOffRemote(selcar) {
    ClearArray();
    Initialize(false);
    PreSetSelection(selcar);
    PreSetPaint(selcar);
    PreSetOption();
    FindEmailLink();
    ReadCookie();
    UnCompressform();
    AdjustTotals();
    UpdatePrice();
}

function ClearArray() {
    for (i = 1; i <= 100; i++) {
        slctn[i] = "";
        prop1[i] = "";
        cnt[i] = 0;
        cost[i] = 0;
        chs[i] = 0;
        rcr[i] = 0;
        prcof[i] = 0;
    }
    total_entries = 0;
}

function FindEmailLink() {
    for (i = 0; i < document.links.length; i++) {
        if (document.links[i].href.substring(0, 6) == "mailto") {
            mailtoindex = i;
        }
    }
}

function PrepareToMailThisForm() {
    bodyout = "";
    if (total_entries == 0) {
        gcount = 0;
        document.order.bodyemail.value = unescape('No items ordered');
        document.order.bodycount.value = unescape(gcount);
    }
    else {
        for (i = 1; i <= total_entries; i++) {
            bodyout += "** " + slctn[i] + ", ";
            bodyout += "C: " + prop1[i] + ", "; //unescape('%0D')+unescape('%0A');
            bodyout += "Total: " + cnt[i] + "-$" + cost[i] + "<br>";
        }
        gtotal = total_ccost + total_kcost + total_rcost + total_wcost + total_bcost + total_dcost;
        gcount = total_cars + total_cars_kits + total_racers + total_wheels + total_books + total_decals;
        bodyout += " <br>";
        bodyout += " **** TOTAL American Cars/Amount " + total_cars + "/$" + total_ccost + " <br>";
        bodyout += " **** TOTAL American Kits/Amount " + total_cars_kits + "/$" + total_kcost + " <br>";
        bodyout += " **** TOTAL GT Racers/Amount " + total_racers + "/$" + total_rcost + " <br>";
        bodyout += " **** TOTAL Wheels/Amount " + total_wheels + "/$" + total_wcost + " <br>";
        bodyout += " **** TOTAL Decals/Amount " + total_decals + "/$" + total_dcost + " <br>";
        bodyout += " **** TOTAL Books/Amount " + total_books + "/$" + total_bcost + " <br>";
        bodyout += " ****** GRAND TOTAL  $" + gtotal + " <br> <br>";
        bodyout += 'Email: ' + '<a href="mailto:' + emailaddr + '">' + emailaddr + '</a><br><br>';
        bodyout += "Name: " + fullname + " <br> <br>";
        bodyout += "Address:  <br>" + EscapeVal(fulladdress, "<br>"); +" <br> <br>";
        // bodyout += "To reply .. use: "+"mev@tjets.com"+" <br> <br>";
        document.order.bodycount.value = unescape(gcount);
        document.order.bodyemail.value = unescape(bodyout);

    }
}


function StartOff() {
    LoadCarTable();
    AdjustTypeRemote();
    ClearArray();
    PreSetSelection();
    //PreSetPaint('X');
    Initialize(false);
    FindEmailLink();
    ReadCookie();
    UnCompressform();
    AdjustTotals();
    PrepareToMailThisForm();
    OutToGrid();
}

function ResetList() {
    ClearArray();
    AdjustTotals();
    OutToGrid();
    Compressform();
    PrepareToMailThisForm();
    WriteCookie();
    Initialize(false);
}

function Initialize(skip) {
    document.order.cars.focus();
    document.order.count.value = "1";
}

function ReadCookie() {
    compactform = unescape(document.cookie);
}

function WriteCookie() {

    var expirex = new Date();
    expirex.setTime(expirex.getTime() + (1000 * 60 * 60 * 24 * 30));
    if (cksw != true) {
        document.cookie = "MEV=" + escape(compactform) + "; expires=" + expirex.toGMTString();
    }
}

function Compressform() {
    if (fullname <= " ") {
        fullname = ">";
    }
    if (fulladdress <= " ") {
        fulladdress = ">";
    }
    if (emailaddr <= " ") {
        emailaddr = ">";
    }
    compactform = "vv" + AdjustText(fullname) + "!" + AdjustText(fulladdress) + "!" + AdjustText(emailaddr) + "!";
    for (i = 1; i <= total_entries; i++) {
        compactform += slctn[i] + "~" + prop1[i] + "~" + cnt[i] + "~" + cost[i] + "~" + chs[i] + "~" + rcr[i] + "~" + prcof[i] + "~$";
    }
    compactform += "^^";
    compactform += total_ship + "!<<";
}

function AdjustShipping() {
    
    total_ship = 0;
    if (document.order.USShip[1].checked == true) 
        {
        total_ship = 4;
        }
    AdjustTotals();
    DisplayTot();
    Compressform();
    PrepareToMailThisForm();
    WriteCookie();

}

function AdjustText(str) {
    var newstring = "";
    if (str > "") {
        for (i = 0; i < str.length; i++) {
            if (str.substring(i, i + 1) == "!") {
                newstring = newstring + " ";
            }
            else {
                newstring = newstring + str.substring(i, i + 1);
            }
        }
    }
    str = newstring;
    return str;
}

function AdjustCookieSW() {

    if (document.order.ckechk.checked == true) {
        cksw = false;
    }
    else {
        cksw = true;
    }
}

function UnCompressform() {
    var somethingwrong = 10000;
    var sameform = true;
    var sameline = true;
    var element = 1;
    var sliver = "";
    var ci = 0;
    total_entries = 0;
    if (compactform > " ") {
        while ((compactform.substring(ci, ci + 2) != "vv") && (ci < compactform.length - 2)) {
            ci++;
        }
        ci++;
        ci++;
        saveci = ci;
        while ((compactform.substring(ci, ci + 1) != "!") && (ci < compactform.length - 2)) {
            sliver += compactform.substring(ci, ci + 1);
            ci++;
        }
        fullname = sliver;
        if (fullname == ">") {
            fullname = "";
        }
        sliver = "";
        ci++;
        while ((compactform.substring(ci, ci + 1) != "!") && (ci < compactform.length - 2)) {
            sliver += compactform.substring(ci, ci + 1);
            ci++;
        }
        fulladdress = sliver;
        if (fulladdress == ">") {
            fulladdress = "";
        }
        sliver = "";
        ci++;
        while ((compactform.substring(ci, ci + 1) != "!") && (ci < compactform.length - 2)) {
            sliver += compactform.substring(ci, ci + 1);
            ci++;
        }
        emailaddr = sliver;
        if (emailaddr == ">") {
            emailaddr = "";
        }
        sliver = "";
        ci++;
        if (ci >= compactform.length - 2) {
            sameform = false;
        }
        while ((sameform == true) && (ci <= somethingwrong)) {
            element = 1;
            sliver = "";
            sameline = true;
            while ((sameline == true) && (ci <= somethingwrong)) {
                if (compactform.substring(ci, ci + 1) == "~") {
                    if (element == 1) {
                        total_entries++;
                        slctn[total_entries] = sliver;
                    }
                    if (element == 2) {
                        prop1[total_entries] = sliver;
                    }
                    if (element == 3) {
                        cnt[total_entries] = sliver;
                    }
                    if (element == 4) {
                        cost[total_entries] = sliver * 1;
                    }
                    if (element == 5) {
                        chs[total_entries] = sliver * 1;
                    }
                    if (element == 6) {
                        rcr[total_entries] = sliver * 1;
                    }
                    if (element == 7) {
                        prcof[total_entries] = sliver * 1;
                    }
                    element++;
                    sliver = "";
                }
                if ((compactform.substring(ci, ci + 1) == "$") || (compactform.substring(ci, ci + 1) == "^")) {
                    sameline = false;
                }
                if (compactform.substring(ci, ci + 1) == "^") {
                    sameform = false;
                }
                if ((compactform.substring(ci, ci + 1) != "~") && (compactform.substring(ci, ci + 1) != "$") && (compactform.substring(ci, ci + 1) != "^")) {
                    sliver += compactform.substring(ci, ci + 1);
                }
                ci++;
                if (ci > compactform.length) {
                    sameline = false;
                    sameform = false;
                }
            }
        }
       ci++;
       while ((compactform.substring(ci, ci + 1) != "!") && (ci < compactform.length - 2)) {
            sliver += compactform.substring(ci, ci + 1);
            ci++;
        }
        if (sliver == '4') 
             {
             total_ship = 4;
             }
          else
             {
             total_ship = 0;
             }
                
    }
}

function AdjWheelsMEVDesc() {
    document.order.accsry.options.length = 3;

    document.order.accsry.options[0] = new Option("5 Lug Style (4std)", "0", false, false);
    document.order.accsry.options[0].selected = "selected";
    document.order.accsry.options[0].value = "Lug";
    document.order.accsry.options[1].text = "5 Lug Style (4tuf)";
    document.order.accsry.options[1].value = "Lug";
    document.order.accsry.options[2].text = "5 Lug Style (2std/2tuf)";
    document.order.accsry.options[2].value = "Lug";
}

function AdjWheelsVinDesc() {
    document.order.accsry.options.length = 25;

    document.order.accsry.options[0] = new Option("Alpina 4A Chr", "0", false, false);
    document.order.accsry.options[0].value = "Alp";
    document.order.accsry.options[0].selected = "selected";
    document.order.accsry.options[1].text = "Alpina 2A/2E Chr";
    document.order.accsry.options[1].value = "Alp";
    document.order.accsry.options[2].text = "Alufelge 4A Alum";
    document.order.accsry.options[2].value = "Alu";
    document.order.accsry.options[3].text = "Alufelge 2A/2E Alum";
    document.order.accsry.options[3].value = "Alu";
    document.order.accsry.options[4].text = "ATS 4B Alum";
    document.order.accsry.options[4].value = "ATS";
    document.order.accsry.options[5].text = "ATS 2B/2E Alum";
    document.order.accsry.options[5].value = "ATS";
    document.order.accsry.options[6].text = "BBS 2B Alum/Silver";
    document.order.accsry.options[6].value = "BBS";
    document.order.accsry.options[7].text = "BBS 2E Alum/Silver";
    document.order.accsry.options[7].value = "BBS";
    document.order.accsry.options[8].text = "BBS 2B Alum/Gold";
    document.order.accsry.options[8].value = "BBS";
    document.order.accsry.options[9].text = "BBS 2E Alum/Gold";
    document.order.accsry.options[9].value = "BBS";
    document.order.accsry.options[10].text = "Corvette 4A Chr";
    document.order.accsry.options[10].value = "Cor";
    document.order.accsry.options[11].text = "Corvette 2A/2E Chr";
    document.order.accsry.options[11].value = "Cor";
    document.order.accsry.options[12].text = "Cromoda 4B Alum";
    document.order.accsry.options[12].value = "Cro";
    document.order.accsry.options[13].text = "Cromoda 2B/2E Alum";
    document.order.accsry.options[13].value = "Cro";
    document.order.accsry.options[14].text = "Fuchsfelge 4A Chr";
    document.order.accsry.options[14].value = "Fuc";
    document.order.accsry.options[15].text = "Fuchsfelge 2A/2E Chr";
    document.order.accsry.options[15].value = "Fuc";
    document.order.accsry.options[16].text = "L. Stahl 4A Chr";
    document.order.accsry.options[16].value = "Loc";
    document.order.accsry.options[17].text = "L. Stahl 4A Black";
    document.order.accsry.options[17].value = "Loc";
    document.order.accsry.options[18].text = "L. Stahl 2A/2E Chr";
    document.order.accsry.options[18].value = "Loc";
    document.order.accsry.options[19].text = "Lotus 4A Chr";
    document.order.accsry.options[19].value = "Lot";
    document.order.accsry.options[20].text = "Lotus 2A/2E Chr";
    document.order.accsry.options[20].value = "Lot";
    document.order.accsry.options[21].text = "Halibrand 4B Alum";
    document.order.accsry.options[21].value = "Hal";
    document.order.accsry.options[22].text = "Halibrand 2B/2E Alum";
    document.order.accsry.options[22].value = "Hal";
    document.order.accsry.options[23].text = "Porsche 4B Chr";
    document.order.accsry.options[23].value = "Por";
    document.order.accsry.options[24].text = "4 A/B Tires";
    document.order.accsry.options[24].value = "Tir";
}


function AdjAccsry0() {
    document.order.accsry.options.length = 1;
    document.order.accsry.options[0] = new Option("D) Decals only", "D", false, false);
    document.order.accsry.options[0].selected = "selected";
}

function AdjAccsry1() {
    document.order.accsry.options.length = 2;
//    document.order.accsry.options[0] = new Option("A) Finished Body w/chs", "A", false, false);
    document.order.accsry.options[0] = new Option("B) Finished Body only", "B", false, false);
//    document.order.accsry.options[1].text = "B) Finished Body only";
//    document.order.accsry.options[1].value = "B";
    document.order.accsry.options[1].text = "C) -ColoredKit- Body only";
    document.order.accsry.options[1].value = "C";
    document.order.accsry.options[0].selected = "selected";
}

function AdjAccsry2() {
    document.order.accsry.options.length = 2;
    //    document.order.accsry.options[0] = new Option("A) Finished Body w/chs", "A", false, false);
    document.order.accsry.options[0] = new Option("B) Finished Body only", "B", false, false);
    //    document.order.accsry.options[1].text = "B) Finished Body only";
    //    document.order.accsry.options[1].value = "B";
    document.order.accsry.options[1].text="C) -Kit- Body only";
    document.order.accsry.options[1].value="C";
    document.order.accsry.options[0].selected = "selected";
}

function AdjAccsry3() {
    document.order.accsry.options.length = 2;
//    document.order.accsry.options[0] = new Option("A) Finished Body w/chs", "A", false, false);
    document.order.accsry.options[0] = new Option("B) Finished Body only", "B", false, false);
//    document.order.accsry.options[1].text = "B) Finished Body only";
//    document.order.accsry.options[1].value = "B";
    document.order.accsry.options[1].text = "D) Decals only";
    document.order.accsry.options[1].value = "D";
    document.order.accsry.options[0].selected = "selected";
}

function AdjAccsry4() {
    document.order.accsry.options.length = 1;
    //    document.order.accsry.options[0] = new Option("A) Finished Body w/chs", "A", false, false);
    document.order.accsry.options[0] = new Option("B) Finished Body only", "B", false, false);
    document.order.accsry.options[0].selected = "selected";
}

function AdjKit() {
    document.order.colors.options.length = 1;
    document.order.colors.options[0] = new Option("-Trans White-", "FFFFFF", false, false);
    document.order.colors.options[0].selected = "selected";
    document.order.colors.options[0].className = "MEVoptNone";
}

function AdjCorvair() {
    document.order.colors.options.length = 4;

    document.order.colors.options[0].selected = "selected";
    document.order.colors.options[0].text = "-1st Avail-";
    document.order.colors.options[0].value = "FFFFFF";
    document.order.colors.options[0].className = "MEVoptNone";
    document.order.colors.options[1].text = "White w/blue";
    document.order.colors.options[1].value = "FFF7FF";
    document.order.colors.options[1].className = "MEVoptWhite";
    document.order.colors.options[2].text = "Red w/black";
    document.order.colors.options[2].value = "FF0000";
    document.order.colors.options[2].className = "MEVoptRed";
    document.order.colors.options[3].text = "Drk Blue w/white";
    document.order.colors.options[3].value = "0800FB";
    document.order.colors.options[3].className = "MEVoptDkBlue";
}

function AdjFairlane() {
    document.order.colors.options.length = 5;

    document.order.colors.options[0].selected = "selected";
    document.order.colors.options[0].text = "-1st Avail-";
    document.order.colors.options[0].value = "FFFFFF";
    document.order.colors.options[0].className = "MEVoptNone";
    document.order.colors.options[1].text = "Black w/white";
    document.order.colors.options[1].value = "000000";
    document.order.colors.options[1].className = "MEVoptBlack";
    document.order.colors.options[2].text = "White w/black";
    document.order.colors.options[2].value = "FFF7FF";
    document.order.colors.options[2].className = "MEVoptWhite";
    document.order.colors.options[3].text = "Drk Blue w/white";
    document.order.colors.options[3].value = "0800FB";
    document.order.colors.options[3].className = "MEVoptDkBlue";
    document.order.colors.options[4].text = "Red w/white (fire)";
    document.order.colors.options[4].value = "FF0000";
    document.order.colors.options[4].className = "MEVoptRed";
}

function AdjPaddy() {
    document.order.colors.options.length = 4;

    document.order.colors.options[0].text = "-1st Avail-";
    document.order.colors.options[0].value = "FFFFFF";
    document.order.colors.options[0].selected = "selected";
    document.order.colors.options[0].className = "MEVoptNone";
    document.order.colors.options[1].text = "Black w/white";
    document.order.colors.options[1].value = "000000";
    document.order.colors.options[1].className = "MEVoptBlack";
    document.order.colors.options[2].text = "White w/black";
    document.order.colors.options[2].value = "FFF7FF";
    document.order.colors.options[2].className = "MEVoptWhite";
    document.order.colors.options[3].text = "Drk Blue w/white";
    document.order.colors.options[3].value = "0800FB";
    document.order.colors.options[3].className = "MEVoptDkBlue";
}

function AdjTaxi() {
    document.order.colors.options.length = 1;

    document.order.colors.options[0].selected = "selected";
    document.order.colors.options[0].text = "Lemon";
    document.order.colors.options[0].value = "FFEF10";
    document.order.colors.options[0].className = "MEVoptLemon";
}

function AdjCaddy() {
    document.order.colors.options.length = 4;

    document.order.colors.options[0].text = "-1st Avail-";
    document.order.colors.options[0].value = "FFFFFF";
    document.order.colors.options[0].selected = "selected";
    document.order.colors.options[0].className = "MEVoptNone";
    document.order.colors.options[1].text = "Black Hearse";
    document.order.colors.options[1].value = "000000";
    document.order.colors.options[1].className = "MEVoptBlack";
    document.order.colors.options[2].text = "White Ambulance";
    document.order.colors.options[2].value = "FFF7FF";
    document.order.colors.options[2].className = "MEVoptWhite";
    document.order.colors.options[3].text = "Red Rescue";
    document.order.colors.options[3].value = "FF0000";
    document.order.colors.options[3].className = "MEVoptRed";
}

function AdjChevelle() {
    document.order.colors.options.length = 4;

    document.order.colors.options[0].text = "-1st Avail-";
    document.order.colors.options[0].value = "FFFFFF";
    document.order.colors.options[0].selected = "selected";
    document.order.colors.options[0].className = "MEVoptNone";
    document.order.colors.options[1].text = "White w/black";
    document.order.colors.options[1].value = "FFF7FF";
    document.order.colors.options[1].className = "MEVoptWhite";
    document.order.colors.options[2].text = "Red w/white";
    document.order.colors.options[2].value = "FF0000";
    document.order.colors.options[2].className = "MEVoptRed";
    document.order.colors.options[3].text = "Gold w/black";
    document.order.colors.options[3].value = "9C7B4E";
    document.order.colors.options[3].className = "MEVoptGold";

}

function AdjStandard() {
    document.order.colors.options.length = 21;

    document.order.colors.options[0] = new Option("-1st Avail-", "FFFFFF", false, false);
    document.order.colors.options[0].selected = "selected";
    document.order.colors.options[0].className = "MEVoptNone";
    document.order.colors.options[1].text = "White(tjet)";
    document.order.colors.options[1].value = "FFF7FF";
    document.order.colors.options[1].className = "MEVoptWhite";
    document.order.colors.options[2].text = "Lemon(tjet)";
    document.order.colors.options[2].value = "FFEF10";
    document.order.colors.options[2].className = "MEVoptLemon";
    document.order.colors.options[3].text = "Btr-stch(tjet)";
    document.order.colors.options[3].value = "EEAF26";
    document.order.colors.options[3].className = "MEVoptBtrStch";
    document.order.colors.options[4].text = "Lt Org(tjet)";
    document.order.colors.options[4].value = "FF7B42";
    document.order.colors.options[4].className = "MEVoptLtOrg";
    document.order.colors.options[5].text = "Pink(tjet)";
    document.order.colors.options[5].value = "F96F9C";
    document.order.colors.options[5].className = "MEVoptPink";
    document.order.colors.options[6].text = "Red(tjet)";
    document.order.colors.options[6].value = "FF0000";
    document.order.colors.options[6].className = "MEVoptRed";
    document.order.colors.options[7].text = "Drk Mrn(tjet)";
    document.order.colors.options[7].value = "763003";
    document.order.colors.options[7].className = "MEVoptDkMrn";
    document.order.colors.options[8].text = "Purple(tjet)";
    document.order.colors.options[8].value = "8C008C";
    document.order.colors.options[8].className = "MEVoptPurple";
    document.order.colors.options[9].text = "Drk Blue(tjet)";
    document.order.colors.options[9].value = "0800FB";
    document.order.colors.options[9].className = "MEVoptDkBlue";
    document.order.colors.options[10].text = "Lime(tjet)";
    document.order.colors.options[10].value = "18F708";
    document.order.colors.options[10].className = "MEVoptLime";
    document.order.colors.options[11].text = "Drk Grn(tjet)";
    document.order.colors.options[11].value = "057E0F";
    document.order.colors.options[11].className = "MEVoptDkGrn";
    document.order.colors.options[12].text = "Gray(tjet)";
    document.order.colors.options[12].value = "ADADC6";
    document.order.colors.options[12].className = "MEVoptGray";
    document.order.colors.options[13].text = "Black(tjet)";
    document.order.colors.options[13].value = "000000";
    document.order.colors.options[13].className = "MEVoptBlack";
    document.order.colors.options[14].text = "Pale Yellow";
    document.order.colors.options[14].value = "F8FF9B";
    document.order.colors.options[14].className = "MEVoptPaleYel";
    document.order.colors.options[15].text = "Sandstone";
    document.order.colors.options[15].value = "D7BF9C";
    document.order.colors.options[15].className = "MEVoptSandStn";
    document.order.colors.options[16].text = "Lavender";
    document.order.colors.options[16].value = "D3BDDD";
    document.order.colors.options[16].className = "MEVoptLav";
    document.order.colors.options[17].text = "Carmine";
    document.order.colors.options[17].value = "940610";
    document.order.colors.options[17].className = "MEVoptCarmine";
    document.order.colors.options[18].text = "Dyn Green";
    document.order.colors.options[18].value = "56FCBE";
    document.order.colors.options[18].className = "MEVoptDyGrn";
    document.order.colors.options[19].text = "Sky Blue";
    document.order.colors.options[19].value = "00CCFF";
    document.order.colors.options[19].className = "MEVoptSkyBlue";
    document.order.colors.options[20].text = "Teal";
    document.order.colors.options[20].value = "057870";
    document.order.colors.options[20].className = "MEVoptTeal";
}

function AdjWheels() {
    document.order.colors.options.length = 23;

    document.order.colors.options[0] = new Option("-1st Avail-", "FFFFFF", false, false);
    document.order.colors.options[0].selected = "selected";
    document.order.colors.options[0].className = "MEVoptNone";
    document.order.colors.options[1].text = "White(tjet)";
    document.order.colors.options[1].value = "FFF7FF";
    document.order.colors.options[1].className = "MEVoptWhite";
    document.order.colors.options[2].text = "Lemon(tjet)";
    document.order.colors.options[2].value = "FFEF10";
    document.order.colors.options[2].className = "MEVoptLemon";
    document.order.colors.options[3].text = "Btr-stch(tjet)";
    document.order.colors.options[3].value = "EEAF26";
    document.order.colors.options[3].className = "MEVoptBtrStch";
    document.order.colors.options[4].text = "Lt Org(tjet)";
    document.order.colors.options[4].value = "FF7B42";
    document.order.colors.options[4].className = "MEVoptLtOrg";
    document.order.colors.options[5].text = "Pink(tjet)";
    document.order.colors.options[5].value = "F96F9C";
    document.order.colors.options[5].className = "MEVoptPink";
    document.order.colors.options[6].text = "Red(tjet)";
    document.order.colors.options[6].value = "FF0000";
    document.order.colors.options[6].className = "MEVoptRed";
    document.order.colors.options[7].text = "Drk Mrn(tjet)";
    document.order.colors.options[7].value = "763003";
    document.order.colors.options[7].className = "MEVoptDkMrn";
    document.order.colors.options[8].text = "Purple(tjet)";
    document.order.colors.options[8].value = "8C008C";
    document.order.colors.options[8].className = "MEVoptPurple";
    document.order.colors.options[9].text = "Drk Blue(tjet)";
    document.order.colors.options[9].value = "0800FB";
    document.order.colors.options[9].className = "MEVoptDkBlue";
    document.order.colors.options[10].text = "Lime(tjet)";
    document.order.colors.options[10].value = "18F708";
    document.order.colors.options[10].className = "MEVoptLime";
    document.order.colors.options[11].text = "Drk Grn(tjet)";
    document.order.colors.options[11].value = "057E0F";
    document.order.colors.options[11].className = "MEVoptDkGrn";
    document.order.colors.options[12].text = "Gray(tjet)";
    document.order.colors.options[12].value = "ADADC6";
    document.order.colors.options[12].className = "MEVoptGray";
    document.order.colors.options[13].text = "Black(tjet)";
    document.order.colors.options[13].value = "000000";
    document.order.colors.options[13].className = "MEVoptBlack";
    document.order.colors.options[14].text = "Pale Yellow";
    document.order.colors.options[14].value = "F8FF9B";
    document.order.colors.options[14].className = "MEVoptPaleYel";
    document.order.colors.options[15].text = "Sandstone";
    document.order.colors.options[15].value = "D7BF9C";
    document.order.colors.options[15].className = "MEVoptSandStn";
    document.order.colors.options[16].text = "Lavender";
    document.order.colors.options[16].value = "D3BDDD";
    document.order.colors.options[16].className = "MEVoptLav";
    document.order.colors.options[17].text = "Carmine";
    document.order.colors.options[17].value = "940610";
    document.order.colors.options[17].className = "MEVoptCarmine";
    document.order.colors.options[18].text = "Dyn Green";
    document.order.colors.options[18].value = "56FCBE";
    document.order.colors.options[18].className = "MEVoptDyGrn";
    document.order.colors.options[19].text = "Sky Blue";
    document.order.colors.options[19].value = "00CCFF";
    document.order.colors.options[19].className = "MEVoptSkyBlue";
    document.order.colors.options[20].text = "Teal";
    document.order.colors.options[20].value = "057870";
    document.order.colors.options[20].className = "MEVoptTeal";
    document.order.colors.options[21].text = "Gold Flake";
    document.order.colors.options[21].value = "9C7B4E";
    document.order.colors.options[21].className = "MEVoptGold";
    document.order.colors.options[22].text = "Chrome";
    document.order.colors.options[22].value = "C0C0C0";
    document.order.colors.options[22].className = "MEVoptChrome";

}

function EmptyPaint() {
    document.order.paintcolors.options.length = 1;
    document.order.paintcolors.options[0] = new Option("-Skip-", "0", false, false);
    document.order.paintcolors.options[0].selected = "selected";
}

function PreSetPaint(selpp) {
    if (selpp != 'W3') {
        document.order.paintcolors.options.length = 8;
        document.order.paintcolors.options[0].className = "MEVoptNone";
        document.order.paintcolors.options[1].text = "Black";
        document.order.paintcolors.options[1].value = "1";
        document.order.paintcolors.options[1].className = "MEVoptBlack";
        document.order.paintcolors.options[2].text = "White";
        document.order.paintcolors.options[2].value = "2";
        document.order.paintcolors.options[2].className = "MEVoptWhite";
        document.order.paintcolors.options[3].text = "Red";
        document.order.paintcolors.options[3].value = "3";
        document.order.paintcolors.options[3].className = "MEVoptRed";
        document.order.paintcolors.options[4].text = "Blue";
        document.order.paintcolors.options[4].value = "4";
        document.order.paintcolors.options[4].className = "MEVoptDkBlue";
        document.order.paintcolors.options[5].text = "Silver";
        document.order.paintcolors.options[5].value = "5";
        document.order.paintcolors.options[5].className = "MEVoptChrome";
        document.order.paintcolors.options[6].text = "Gold";
        document.order.paintcolors.options[6].value = "6";
        document.order.paintcolors.options[6].className = "MEVoptGold";
        document.order.paintcolors.options[7].text = "-none-";
        document.order.paintcolors.options[7].value = "7";
        document.order.paintcolors.options[7].className = "MEVoptNone";

    }
}


function PreSetSelection(sele) {

    carcount = document.order.cars.options.length;

    if (sele > ' ') {
        for (i = 0; i < carcount; i++) {
            if (document.order.cars.options[i].value == sele) {
                document.order.cars.options[i].selected = "selected";
            }
        }

    }
}

function PreSetOption() {
    AdjAccsry3();
}


function GetCarText(selee) {
    varout = "";
    carcountx = document.order.cars.options.length;
    if (selee > " ") {
        for (i = 0; i < carcountx; i++) {
            if (document.order.cars.options[i].value == selee) {
                varout = document.order.cars.options[i].text;
            }
        }

    }
    return varout
}

function AdjustColorSpot() {
    clrindx = document.order.colors.selectedIndex;
    colorspot = document.order.colors.options[clrindx].value;
    window.onerror = error_handler;

    if (skipcoloradj != true) {

       if (colorspot.length != 6) {
            document.order.clrspot.style.background = "#FFFFFF";
        }
        else {
            document.order.clrspot.style.background = "#" + colorspot;
        }
    }
}

function error_handler() {
    skipcoloradj = "true";
}

function AdjustProps() {

    selindx = document.order.cars.selectedIndex;
    selmade = "No";
    selection1 = document.order.cars.options[selindx].text.substring(1, 4);
    selection2 = document.order.cars.options[selindx].text.substring(6, 9);
    if ((selection1 == "Whl") && (selmade == "No")) {
        document.order.colors.options.length = 1;
        if ((selection1 == "Whl") && (selection2 == "MEV")) {
            AdjWheelsMEVDesc();
            AdjWheels();
            curAcc = 1;
        }
        else {
            AdjWheelsVinDesc();
            document.order.colors.options[0] = new Option("-Skip-", "0", false, false);
            curAcc = 2;
        }
        selmade = "Yes";
    }
    if ((selection1 == "Dcl") && (selmade == "No")) {
        document.order.colors.options.length = 1;
        document.order.colors.options[0] = new Option("Authentic coloring", "0", false, false);
        AdjAccsry0();
        curAcc = 3;
        selmade = "Yes";
    }
    if (((selection1 == "Cyk") || (selection1 == "Cem") || (selection1 == "Cus") || (selection1 == "Ctt")) && (selmade == "No")) {
        if (curAcc != 4) {
            AdjAccsry4();
        }
        curAcc = 4;
        selmade = "Yes";
    }
    if (((selection1 == "Cpu") || (selection1 == "Cwg") || (selection1 == "Ca5") ||
         (selection1 == "Ca6") || (selection1 == "Cmu")) && (selmade == "No")) {
        if (curAcc != 5) {
            AdjAccsry2();
        }
        curAcc = 5;
        selmade = "Yes";
    }
    if (((selection1 == "Cst") || (selection1 == "Cdr")) && (selmade == "No")) {
        document.order.colors.options.length = 1;
        document.order.colors.options[0] = new Option("Authentic coloring", "0", false, false);
        if (curAcc != 6) {
            AdjAccsry3();
        }
        curAcc = 6;
        selmade = "Yes";
    }
    if ((selection1 == "Rcr") && (selmade == "No")) {
        if (curAcc != 7) {
            AdjAccsry1();
        }
        curAcc = 7;
        selmade = "Yes";

    }
    if (selmade == "No") {
        document.order.accsry.options[0] = new Option("-Skip-", "0", false, false);
        document.order.accsry.options.length = 1;
        curAcc = 0;
    }
}

function AdjustColors() {

    selindx = document.order.cars.selectedIndex;
    selection1 = document.order.cars.options[selindx].text.substring(1, 4);
    selection2 = document.order.cars.options[selindx].text.substring(12, 17);
    selection3 = document.order.cars.options[selindx].text.substring(1, 2);
    selection4 = document.order.cars.options[selindx].text.substring(20, 23);
    selection5 = document.order.cars.options[selindx].text.substring(9, 12);
    selindxch = document.order.accsry.selectedIndex;
    selectionch = document.order.accsry.options[selindxch].text.substring(0, 1);
    EmptyPaint();
    if (selection1 != "Whl") {

        //  if ((selection1 != "Cst") && (selection1 != "Cdr") && (selection1 != "Dcl")) {
        //        AdjStandard();
        //        }

        if ((selectionch != "C") || (selection1 == "Rcr")) {

            if ((selection2 == "Corva") && (selection1 == "Cyk")) {
                AdjCorvair();
            }
            if ((selection2 == "Cheve") && (selection1 == "Cyk")) {
                AdjChevelle();
            }
            if ((selection2 == "Mercu") && (selection1 == "Ca5")) {
                document.order.colors.options[0] = new Option("-1st Avail Body-", "0", false, false);
                document.order.colors.options[0].selected = "selected";
                document.order.paintcolors.options[0] = new Option("-1st Avail Cove-", "0", false, false);
                document.order.paintcolors.options[0].selected = "selected";
                PreSetPaint("X");
            }
            if ((selection2 == "Edsel") && (selection1 == "Ca5")) {
                document.order.colors.options[0] = new Option("-1st Avail Body-", "0", false, false);
                document.order.colors.options[0].selected = "selected";
                document.order.paintcolors.options[0] = new Option("-1st Avail Cove-", "0", false, false);
                document.order.paintcolors.options[0].selected = "selected";
                PreSetPaint("X");
            }
            if (selection2 == "Marli") {
                document.order.colors.options[0] = new Option("-1st Avail Body-", "0", false, false);
                document.order.colors.options[0].selected = "selected";
                document.order.paintcolors.options[0] = new Option("-1st Avail Two Tone-", "0", false, false);
                document.order.paintcolors.options[0].selected = "selected";
                PreSetPaint("X");
            }
            if (selection2 == "Roadr") {
                document.order.colors.options[0] = new Option("-1st Avail Body-", "0", false, false);
                document.order.colors.options[0].selected = "selected";
                document.order.paintcolors.options[0] = new Option("-1st Avail Stripe-", "0", false, false);
                document.order.paintcolors.options[0].selected = "selected";
                PreSetPaint("X");
            }
            if ((selection2 == "Fairl") && (selection4 == "500")) {
                document.order.colors.options[0] = new Option("-1st Avail Body-", "0", false, false);
                document.order.colors.options[0].selected = "selected";
                document.order.paintcolors.options[0] = new Option("-1st Avail Cove-", "0", false, false);
                document.order.paintcolors.options[0].selected = "selected";
                PreSetPaint("X");
            }
            if (selection2.substring(0, 4) == "Fury") {
                document.order.colors.options[0] = new Option("-1st Avail Body-", "0", false, false);
                document.order.colors.options[0].selected = "selected";
                document.order.paintcolors.options[0] = new Option("-1st Avail Moulding-", "0", false, false);
                document.order.paintcolors.options[0].selected = "selected";
                PreSetPaint("X");
            }
            if (selection2.substring(0, 4) == "Cuda") {
                document.order.colors.options[0] = new Option("-1st Avail Body-", "0", false, false);
                document.order.colors.options[0].selected = "selected";
                document.order.paintcolors.options[0] = new Option("-1st Avail Top-", "0", false, false);
                document.order.paintcolors.options[0].selected = "selected";
                PreSetPaint("X");
            }
            if ((selection2 == "Olds4") && (selection1 == "Cmu")) {
                document.order.colors.options[0] = new Option("-1st Avail Body-", "0", false, false);
                document.order.colors.options[0].selected = "selected";
                document.order.paintcolors.options[0] = new Option("-1st Avail BA Strip-", "0", false, false);
                document.order.paintcolors.options[0].selected = "selected";
                PreSetPaint("X");
            }
            if ((selection2 == "Cheve") && (selection1 == "Cus")) {
                document.order.colors.options[0] = new Option("-1st Avail Body-", "0", false, false);
                document.order.colors.options[0].selected = "selected";
                document.order.paintcolors.options[0] = new Option("-1st Avail Strip-", "0", false, false);
                document.order.paintcolors.options[0].selected = "selected";
                PreSetPaint("X");
            }
            if ((selection2 == "Hurst") && (selection1 == "Cus")) {
                document.order.colors.options.length = 1;
                document.order.colors.options[0] = new Option("Silver w/black", "0", false, false);
                document.order.colors.options[0].className = "MEVoptChrome";                
            }
            if (selection1 == "Bok") {
                document.order.colors.options.length = 1;
                document.order.colors.options[0] = new Option("-Skip-", "0", false, false);
            }
            if ((selection2 == "Coron") && (selection1 == "Cmu")) {
                document.order.colors.options[0] = new Option("-1st Avail Body-", "0", false, false);
                document.order.colors.options[0].selected = "selected";
                document.order.paintcolors.options[0] = new Option("-1st Avail BB Strip-", "0", false, false);
                document.order.paintcolors.options[0].selected = "selected";
                PreSetPaint("X");
            }
            if (selection1 == "Ctt") {
                document.order.colors.options[0] = new Option("-1st Avail Body-", "0", false, false);
                document.order.colors.options[0].selected = "selected";
                document.order.paintcolors.options[0] = new Option("-1st Avail Two Tone-", "0", false, false);
                document.order.paintcolors.options[0].selected = "selected";
                PreSetPaint("X");
            }
            if ((selection5 == "Pol") && (selection1 == "Cem")) {
                AdjFairlane();
            }
            if ((selection5 == "Pad") && (selection1 == "Cem")) {
                AdjPaddy();
            }
            if ((selection5 == "Amb") && (selection1 == "Cem")) {
                AdjCaddy();
            }
            if ((selection5 == "Che") && (selection1 == "Cem")) {
                AdjTaxi();
            }
            if ((selection2 == "Coron") && (selection1 == "Cus")) {
                document.order.colors.options[0] = new Option("-1st Avail Body-", "0", false, false);
                document.order.colors.options[0].selected = "selected";
                document.order.paintcolors.options[0] = new Option("-1st Avail C Strip-", "0", false, false);
                document.order.paintcolors.options[0].selected = "selected";
                PreSetPaint("X");
            }
            if ((selection2 == "Dart ") && (selection1 == "Cus")) {
                document.order.colors.options[0] = new Option("-1st Avail Body-", "0", false, false);
                document.order.colors.options[0].selected = "selected";
                document.order.paintcolors.options[0] = new Option("-1st Avail BB Strip-", "0", false, false);
                document.order.paintcolors.options[0].selected = "selected";
                PreSetPaint("X");
            }
            if ((selection2 == "Musta") && (selection1 == "Cus")) {
                document.order.colors.options[0] = new Option("-1st Avail Body-", "0", false, false);
                document.order.colors.options[0].selected = "selected";
                document.order.paintcolors.options[0] = new Option("-1st Avail Strip-", "0", false, false);
                document.order.paintcolors.options[0].selected = "selected";
                PreSetPaint("X");
            }
        }
        else {
            AdjKit();
        }    
    }

    window.onerror = error_handler;
    if (skipcoloradj != true) {
        document.order.clrspot.style.background = "#FFFFFF";
    }
}

function DeleteFromArray(loc) {
    slctn[loc] = slctn[loc + 1];
    prop1[loc] = prop1[loc + 1];
    cnt[loc] = cnt[loc + 1];
    cost[loc] = cost[loc + 1];
    chs[loc] = chs[loc + 1];
    rcr[loc] = rcr[loc + 1];
    prcof[loc] = prcof[loc + 1];
}

function DeleteFromList() {
    buttn = document.order.dellist.selectedIndex;
    if ((buttn > 0) && (total_entries>0)) {
        for (i = buttn; i <= total_entries; i++) {
            if (i < total_entries) {
                DeleteFromArray(i);
            }
            // use this for the last one
            else {
                slctn[i] = "";
                prop1[i] = "";
                cnt[i] = 0;
                cost[i] = 0;
                chs[i] = 0;
                rcr[i] = 0;
                prcof[i] = 0;
            }
        }
        total_entries--;
        AdjustTotals();
        OutToGrid();
        Compressform();
        PrepareToMailThisForm();
        WriteCookie();
    }
}

function DisplayTot() 
{
    hold_tot = total_ccost + total_kcost + total_wcost + total_bcost + total_rcost + total_dcost + (total_ship*1);
    hold_cnt = total_cars + total_cars_kits + total_racers + total_books + total_wheels + total_decals;
    document.order.tot.value = "$" + hold_tot;
    document.order.bodycount.value = hold_cnt;
    document.order.totalorder.value = hold_tot;
}

function OutToGrid() {
    var displaycount = 2;
    offset = 1;
    if (total_cars == 1) {
        total_cars_dsply = total_cars + " Amer. Car";
    }
    else {
        total_cars_dsply = total_cars + " Amer. Cars";
    }
    if (total_cars_kits == 1) {
        total_cars_kits_dsply = total_cars_kits + " Amer. Kit";
    }
    else {
        total_cars_kits_dsply = total_cars_kits + " Amer. Kits";
    }
    if (total_wheels == 1) {
        total_wheels_dsply = total_wheels + " Wheels";
    }
    else {
        total_wheels_dsply = total_wheels + " Wheels";
    }
    if (total_racers == 1) {
        total_racers_dsply = total_racers + " GT Racer";
    }
    else {
        total_racers_dsply = total_racers + " GT Racers";
    }
    if (total_decals == 1) {
        total_decals_dsply = total_decals + " Decal";
    }
    else {
        total_decals_dsply = total_decals + " Decals";
    }
    if (total_books == 1) {
        total_books_dsply = total_books + " Book";
    }
    else {
        total_books_dsply = total_books + " Books";
    }

    document.order.dsply.value = total_cars_dsply +
            unescape("%0D%0A") + total_cars_kits_dsply +
            unescape("%0D%0A") + total_racers_dsply +
            unescape("%0D%0A") + total_wheels_dsply +
            unescape("%0D%0A") + total_decals_dsply;
    //      +  unescape("%0D%0A") + total_books_dsply;

    DisplayTot();     
    document.order.fname.value = fullname;
    document.order.addr.value = fulladdress;
    document.order.emailtxt.value = emailaddr;

    //deal with ship
    if (total_ship == 4) {
        document.order.USShip[1].checked = true;
    } 
    else{

        document.order.USShip[1].checked = false;
    }


    document.order.cart.value = "";
    
    if (total_entries < 1) {
        offset = 2;
        document.order.dellist.options[0].text = "";
    }
    document.order.dellist.length = total_entries + offset;

    for (i = 1; i <= total_entries; i++) {
        document.order.dellist.options[i].value = i.toString();
        document.order.dellist.options[i].text = i.toString()+")";
        if (i == 1) {
            document.order.cart.value = i.toString() + ") " + slctn[i] + " " + prop1[i] + " " + cnt[i] + " $" + cost[i];
        }
        else {
            document.order.cart.value = document.order.cart.value + unescape("%0D%0A") +
            i.toString() + ") " + slctn[i] + " " + prop1[i] + " " + cnt[i] + " $" + cost[i];
        }

    }

    if (total_entries > 0) {
        displaycount = total_entries + 1
    }

}

function Validate() {
    var valid = true;
//    if (document.order.cars.selectedIndex <= 0) {
//        alert("Please choose a -selection-");
//        document.order.cars.focus();
//        valid = false;
//    }
    if (document.order.count.value.substring(0, 1) == "O") {
        document.order.count.value = "0" + document.order.count.value.substring(1, 2);
    }
    if (document.order.count.value.substring(1, 2) == "O") {
        document.order.count.value = document.order.count.value.substring(0, 1) + "0";
    }
    if ((document.order.count.value.substring(0, 1) <= "0") ||
      (document.order.count.value.substring(0, 1) > "9")) {
        document.order.count.value = "1" + document.order.count.value.substring(1, 2);
    }
    if ((document.order.count.value.substring(1, 2) <= "0") ||
      (document.order.count.value.substring(1, 2) > "9")) {
        document.order.count.value = document.order.count.value.substring(0, 1);
    }

    return valid;

}

function NeedToAdd() {
    var nadd = true;
    i = 1;
    Mcardesc = "";
    Mcarprep = "";
    selindx = document.order.cars.selectedIndex;
    AddToIndArray(0, selindx, true); // sets Mcardesc, Mcarprep
    if (total_entries > 0)
    {
        while (i <= total_entries)
        {
            if ((Mcardesc==slctn[i]) && (Mcarprep==prop1[i])) 
            {
                nadd = false;
                // alter count here
                cnt[i] = (cnt[i]*1) + (document.order.count.value * 1);
                i = total_entries+1; 
            }     
            i++
        }
    }
        
    return nadd;
}

function EscapeVal(textarea,replaceWith){
    textarea = escape(textarea);
    for(i=0; i<textarea.length; i++){ 

        if(textarea.indexOf("%0D%0A") > -1){
            textarea = textarea.replace("%0D%0A", replaceWith);
        }
        else if(textarea.indexOf("%0A") > -1){
            textarea = textarea.replace("%0A", replaceWith);
        }
        else if(textarea.indexOf("%0D") > -1){
            textarea = textarea.replace("%0D", replaceWith);
        }
     }
     textarea = unescape(textarea);
     return textarea;
}


function UpdateNameAddress() {
    fullname = document.order.fname.value;
    fulladdress = document.order.addr.value;
    emailaddr = document.order.emailtxt.value;
    Compressform();
    PrepareToMailThisForm();
    WriteCookie();
}

function AddToIndArray(pos, indx, chkdup) {

    accsindx = document.order.accsry.selectedIndex;
    accsval = document.order.accsry.options[accsindx].value;
    accstext = document.order.accsry.options[accsindx].text;

    slctnhld = "";
    prop1hld = "";
    cnthld = 0;
    costhld = 0;
    chshld = 0;
    rcrhld = 0;
    prcofhld = 0;

    slctnhld = document.order.cars.options[indx].text;
    propindx = document.order.colors.selectedIndex;
    prop1hld = document.order.colors.options[propindx].text;
    paintindx = document.order.paintcolors.selectedIndex;
    painttext = document.order.paintcolors.options[paintindx].text;
    cnthld = document.order.count.value;
    if ((accsval == "A") && ((slctnhld.substring(1, 2) == "C") || (slctnhld.substring(1, 2) == "R"))) {
        slctnhld += " w/chs";
        chshld = chsprice;
    }
    if (slctnhld.substring(1, 2) == "W") {
        slctnhld += " " + accstext;
    }
    if (accsval == "D") {
        slctnhld = "[Decals]" + slctnhld;
    }
    if ((accsval == "A") && (slctnhld.substring(1, 2) == "R")) {
        slctnhld += " (fin)";
        rcrhld = 18;
    }
    if ((accsval == "B") && (slctnhld.substring(1, 2) == "R")) {
        slctnhld += " (fin)";
        rcrhld = 18;
    }
    if ((accsval == "C") && (slctnhld.substring(1, 2) == "R")) {
        slctnhld += " (unf)";
        rcrhld = 15;
    }
    if ((accsval == "B") && (slctnhld.substring(1, 2) == "C")) {
        slctnhld += " (fin)";
    }
    if ((accsval == "C") && (slctnhld.substring(1, 2) == "C")) {
        slctnhld = "[Kit]" + slctnhld;
    }
    if ((painttext > " ") && (painttext != "-Skip-")) {
        prop1hld += " w/" + painttext;
    }
    if ((slctnhld.substring(2, 4) == "yk") || (slctnhld.substring(2, 4) == "us")) {
        prcofhld = 10;
    }
    if ((slctnhld.substring(2, 4) == "em") || (slctnhld.substring(2, 4) == "st") || (slctnhld.substring(2, 4) == "dr")
                || (slctnhld.substring(2, 4) == "tt")) {
        prcofhld = 12;
    }
    if (chkdup==true)
    {
        Mcardesc = slctnhld;
        Mcarprep = prop1hld;
    }
    else 
    {
        slctn[pos] = slctnhld;
        prop1[pos] = prop1hld;
        cnt[pos] = cnthld;
        cost[pos] = costhld;
        chs[pos] = chshld;
        rcr[pos] = rcrhld;
        prcof[pos] = prcofhld;
    }
}

function AddToArray() {
    if (Validate() == true) {
        catmatch = false;
        selindx = document.order.cars.selectedIndex;
        sel3cmpr = document.order.cars.options[selindx].text.substring(1, 4);
        seltext = document.order.cars.options[selindx].text;
        hit = false;
        if (NeedToAdd() == true) {
            if (total_entries == 0) {
                AddToIndArray(1, selindx, false);
            }
            i = 1;
            while (i <= total_entries) {
                slc3cmpr = slctn[i].substring(1, 4);
                if ((slctn[i] > seltext) && (hit == false)) {
                    h_slctn = slctn[i];
                    h_prop1 = prop1[i];
                    h_cnt = cnt[i];
                    h_cost = cost[i];
                    h_chs = chs[i];
                    h_rcr = rcr[i];
                    h_prcof = prcof[i];

                    AddToIndArray(i, selindx, false);

                    hit = true;
                 }   

                if ((i + 1 <= total_entries) && (hit == true)) {
                    n_slctn = slctn[i + 1];
                    n_prop1 = prop1[i + 1];
                    n_cnt = cnt[i + 1];
                    n_cost = cost[i + 1];
                    n_chs = chs[i + 1];
                    n_rcr = rcr[i + 1];
                    n_prcof = prcof[i + 1];
                    slctn[i + 1] = h_slctn;
                    prop1[i + 1] = h_prop1;
                    cnt[i + 1] = h_cnt;
                    cost[i + 1] = h_cost;
                    chs[i + 1] = h_chs;
                    rcr[i + 1] = h_rcr;
                    prcof[i + 1] = h_prcof;
                    h_slctn = n_slctn;
                    h_prop1 = n_prop1;
                    h_cnt = n_cnt;
                    h_cost = n_cost;
                    h_chs = n_chs;
                    h_rcr = n_rcr;
                    h_prcof = n_prcof;
                }
                if ((i + 1 > total_entries) && (hit == true)) {
                    slctn[i + 1] = h_slctn;
                    prop1[i + 1] = h_prop1;
                    cnt[i + 1] = h_cnt;
                    cost[i + 1] = h_cost;
                    chs[i + 1] = h_chs;
                    rcr[i + 1] = h_rcr;
                    prcof[i + 1] = h_prcof;
                } // if      
               
                
            i++;    
            } // while
            if (hit == false) {
                AddToIndArray(total_entries + 1, selindx, false);
            }
            total_entries++;
        } // if need to add
    } // if valid
}


function AddToList() {
    selindx = document.order.cars.selectedIndex;
    selection1 = document.order.cars.options[selindx].text.substring(1, 4);
    if (selection1 == "XXX") {
        alert("Vehicle Discontinued");
    }
    else {
        AddToArray();
        AdjustTotals();
        OutToGrid();
        Compressform();
        PrepareToMailThisForm();
        WriteCookie();
        Initialize(false);
    }
}

function AddToListRemote() {
    selindx = document.order.cars.selectedIndex;
    selection1 = document.order.cars.options[selindx].text.substring(1, 4);
    if (selection1 == "XXX") {
        alert("Vehicle Discontinued");
    }
    else {
        AddToArray();
        AdjustTotals();
        Compressform();
        WriteCookie();
        Initialize(true);
    }
}

function AdjustTotals() {
    cursel = new String();
    priceoffset = 0;
    price = 44;
    total_ccost = 0;
    total_kcost = 0;
    total_bcost = 0;
    total_rcost = 0;
    total_wcost = 0;
    total_dcost = 0;
    total_cars = 0;
    total_cars_kits = 0;
    total_racers = 0;
    total_books = 0;
    total_wheels = 0;
    total_decals = 0;
    for (i = 1; i <= total_entries; i++) {
        cursel = slctn[i];
        if (cursel != null) {
            if (cursel.substring(1, 2) == "C") {
                total_cars += cnt[i] * 1;
            }
            if (cursel.substring(1, 2) == "K") {
                total_cars_kits += cnt[i] * 1;
            }
            if (cursel.substring(1, 2) == "W") {
                total_wheels += cnt[i] * 1;
            }
            if (cursel.substring(1, 2) == "R") {
                total_racers += cnt[i] * 1;
            }
            if (cursel.substring(1, 2) == "B") {
                total_books += cnt[i] * 1;
            }
            if (cursel.substring(1, 2) == "D") {
                total_decals += cnt[i] * 1;
            }
        }
    }
    if (total_cars >= 10) {
        price = 28;
    }
    if (total_cars >= 20) {
        price = 25;
    }
    if (total_cars >= 50) {
        price = 22;
    }
    if (total_cars >= 100) {
        price = 20;
    }


    for (i = 1; i <= total_entries; i++) {
        if (cnt[i] > 0) {
            cursel = slctn[i];
            if ((total_cars >= 10) && (prcof[i] > 0)) {
                priceoffset = prcof[i] - 4;
            }
            else {
                priceoffset = prcof[i];
            }
            if (cursel.substring(1, 2) == "R") {
                cost[i] = cnt[i] * (rcr[i] + chs[i]);
                total_rcost += cost[i];
            }
            if (cursel.substring(1, 2) == "C") {
                cost[i] = cnt[i] * (price + priceoffset + chs[i]);
                total_ccost += cost[i];
            }
            if (cursel.substring(1, 2) == "K") {
                cost[i] = cnt[i] * 15;
                total_kcost += cost[i];
            }
            if (cursel.substring(1, 2) == "W") {
                cost[i] = cnt[i] * 3;
                total_wcost += cost[i];
            }
            if (cursel.substring(1, 2) == "D") {
                cost[i] = cnt[i] * 3;
                total_dcost += cost[i];
            }
            if (cursel.substring(1, 2) == "B") {
                if (total_cars + total_racers + total_wheels == 0) {
                    cost[i] = (cnt[i] * 12) + 4;
                    total_bcost += cost[i];
                }
                else {
                    cost[i] = cnt[i] * 12;
                    total_bcost += cost[i];
                }
            }
        }
    }
}
 
 