/*
Block multiple form submission script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact for use
*/

function checksubmit(submitbtn)
    {
    submitbtn.form.submit()
    checksubmit = blocksubmit
    return false
    }

function blocksubmit()
    {
    return false
    }

function getDesc(idField)
    {
    var tdID = idField.id;//get the name of the ID of the TD field (part) that has the data
    var idName = document.getElementById(tdID);
    var idValue = idName.value;//get the value from the input field
    var idNum = tdID.substr(3);//get the number of the ID field so we can assign it to the desc id
    var descID = "des" + idNum;
    newId = document.getElementById(descID);
    newId.style.display = "";//begin the Ajax request
    var ajaxRequest; // The variable that makes Ajax possible!

    try
        {
        // Opera 8.0+, Firefox, Safari
        ajaxRequest = new XMLHttpRequest();
        }
    catch (e)
        {
        // Internet Explorer Browsers
        try
            {
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
            }
        catch (e)
            {
            try
                {
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                }
            catch (e)
                {
                // Something went wrong
                alert("Your browser broke!");
                return false;
                }
            }
        }
    // Create a function that will receive data sent from the server
    ajaxRequest.onreadystatechange = function()
        {
        if (ajaxRequest.readyState == 4)
            {
            var ajaxDisplay = document.getElementById(descID);
            ajaxDisplay.value = ajaxRequest.responseText;
            }
        }
    var part = idValue;
    var queryString = "?part=" + part;
    ajaxRequest.open("GET", "getDesc.php" + queryString, true);
    ajaxRequest.send(null);

    if (part == "")//if the value is taken out of the field, hide the input field
        {
        newId.style.display = "none";
        }
    return true;
    }

//this will format the Amount field to display correctly
function CurrencyFormatted(amount)
    {
    var i = parseFloat(amount);

    if (isNaN(i))
        {
        i = 0.00;
        }
    var minus = '';

    if (i < 0)
        {
        minus = '-';
        }
    i = Math.abs(i);
    i = parseInt((i + .005) * 100);
    i = i / 100;
    s = new String(i);

    if (s.indexOf('.') < 0)
        {
        s += '.00';
        }

    if (s.indexOf('.') == (s.length - 2))
        {
        s += '0';
        }
    s = minus + s;
    return s;
    }

function showTotal(idField)
    {
    var tdID = idField.id;//get the name of the ID of the TD field (part) that has the data
    var idName = document.getElementById(tdID);
    var idNum = tdID.substr(3);//get the number of the ID field so we can assign it to the amou id
    var idQty = "qty" + idNum;
    idQty = document.getElementById(idQty);
    var idSku = "sku" + idNum;
    idSku = document.getElementById(idSku);
    var idPri = "pri" + idNum;
    idPri = document.getElementById(idPri);
    var idPriVal = idPri.value.substr(1);
    var idAmo = "amo" + idNum;
    idAmo = document.getElementById(idAmo);

    if ((idQty.value == "") || (idSku.value == "") || (idPri.value == ""))
        {
        idAmo.style.display = "none";
        }

    else
        {
        idAmo.style.display = "";
        var amoVal = Math.round((idQty.value * idPriVal) * 100) / 100;
        var s = CurrencyFormatted(amoVal);
        idAmo.value = "$" + s;
        }
    }

function getPrice(idField)
    {
    var tdID = idField.id;//get the name of the ID of the TD field (part) that has the data
    var idName = document.getElementById(tdID);
    var idValue = idName.value;//get the value from the input field
    var idNum = tdID.substr(3);//get the number of the ID field so we can assign it to the pric id
    var quanID = "qty" + idNum;
    quanID = document.getElementById(quanID);
    var quanVal = quanID.value;//get the value from the Quantity field
    var priceID = "pri" + idNum;
    newId = document.getElementById(priceID);
    newId.style.display = "";//begin the Ajax request
    var ajaxRequest; // The variable that makes Ajax possible!

    try
        {
        // Opera 8.0+, Firefox, Safari
        ajaxRequest = new XMLHttpRequest();
        }
    catch (e)
        {
        // Internet Explorer Browsers
        try
            {
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
            }
        catch (e)
            {
            try
                {
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                }
            catch (e)
                {
                // Something went wrong
                alert("Your browser broke!");
                return false;
                }
            }
        }

    // Create a function that will receive data sent from the server
    ajaxRequest.onreadystatechange = function()
        {
        if (ajaxRequest.readyState == 4)
            {
            var ajaxDisplay = document.getElementById(priceID);
            ajaxDisplay.value = ajaxRequest.responseText;

            if (ajaxDisplay.value == "")
                {
                newId.style.display = "none";
                }

            else
                {
                showTotal(idName);
                }
            }
        }
    var part = idValue;
    var quantity = quanVal;
    var queryString = "?part=" + part;
    ajaxRequest.open("GET", "getPrice.php" + queryString, true);
    ajaxRequest.send(null);
    return true;
    }

function addNote(text)
        {
        myoutput = "<label for=" + text + ">" + document.getElementById(text + 1).innerHTML
            + "</label><textarea rows=5 name=" + text + " id=" + text + " cols=30";

        if (text == 'noteshipping')
            {
            myoutput = myoutput + ' onkeyup="this.value=Left(this.value,50);"';
            }
        myoutput = myoutput + "></textarea>";
        document.getElementById(text).innerHTML = myoutput;
        return false;
        }