﻿//helper function to create the form
function getNewSubmitForm() {
    var submitForm = document.createElement("FORM");
    //document.body.appendChild(submitForm);
    submitForm.method = "POST";
    return submitForm;
}

//helper function to add elements to the form
function createNewFormElement(inputForm, elementName, elementValue) {
    var newElement = document.createElement("<input name='" + elementName + "' type='hidden'>");
    inputForm.appendChild(newElement);
    newElement.value = elementValue;
    return newElement;
}

function createComboBox(name, itemValue) {
    var newCboBox = document.createElement("select");
    newCboBox.name = name;
    var choice = document.createElement('option');
    choice.value = itemValue;
    choice.appendChild(document.createTextNode(itemValue));
    newCboBox.appendChild(choice);
    return newCboBox;
}

function submitCart(itemNumber, cboBox) {
    var submitForm = getNewSubmitForm();

    if (cboBox != null) {
        var comboValue
        var selIndex = cboBox.selectedIndex;
        comboValue = cboBox.options[selIndex].value;

        var newCboBox = createComboBox("o1", comboValue);
        submitForm.appendChild(newCboBox);
    }

    submitForm.action = "https://www.e-junkie.com/ecom/gb.php?c=cart&i=" + itemNumber + "&cl=10249&ejc=2&return=http://www.jackyl.com&cancel_return=http://www.jackyl.com";
    submitForm.target = "ej_ejc";

    return (EJEJC_lc(submitForm));

    //document.body.removeChild(submitForm);
}

function submitCart(itemNumber) {
    var submitForm = getNewSubmitForm();

    for (var i = 0; i < OptionComboBoxes.length; i++) {
        var selIndex = OptionComboBoxes[i].selectedIndex;
        var comboValue = OptionComboBoxes[i].options[selIndex].value;

        var newCboBox = createComboBox(OptionNames[i], comboValue);
        submitForm.appendChild(newCboBox);    
    }

    submitForm.action = "https://www.e-junkie.com/ecom/gb.php?c=cart&i=" + itemNumber + "&cl=10249&ejc=2&return=http://www.jackyl.com&cancel_return=http://www.jackyl.com";
    submitForm.target = "ej_ejc";

    return (EJEJC_lc(submitForm));
}

var OptionComboBoxes = [];
var OptionNames = [];
