/* 
 * Arrays to handle adding blanks and their attachments on the page.
 * 
 * Dependencies:
 *      ./javascript/general.js
 */
var newBlankNumbersToAdd = new Array();

function addBorder($controlName, $borderColor){
    // Get the element to add a border to
    var theElement = document.getElementById($controlName);
    
    // set the border what color they chose
    theElement.style.border = '2px solid' + $borderColor;
}

function getNewMaxBlankNumber(){
    // Set the result to zero for now
    var result = 0;
    
   // Loop through the result numbers to get the highest
   for (var loopBlankNumber in newBlankNumbersToAdd){
       // Determine if the number is higher than the current number
       if (newBlankNumbersToAdd[loopBlankNumber]>result){
           // make this the new high
           result = newBlankNumbersToAdd[loopBlankNumber];
       }
   }
   
    // Return the highest result
    return result;
}

function createNewBlankNumberString(){
    // Set the result to zero for now
    var result = '';
    
   // Loop through the result numbers
   for (var loopBlankNumber in newBlankNumbersToAdd){
       // Add it to the string
       result = result+newBlankNumbersToAdd[loopBlankNumber].toString()+'|';
   }

    // Remove the last comma
    result=result.slice(0, (result.length-1));
    
    // Return the highest result
    return result;
}

function removeNewBlankNumber(blankNumberToRemove){
    // Set the removal item to zero for now
    var blankLocationToRemove = -1;
    
    // Loop through the result numbers to get the highest
    for (var loopBlankNumber in newBlankNumbersToAdd){
        // Determine if the number is higher than the current number
        if (newBlankNumbersToAdd[loopBlankNumber]===blankNumberToRemove){
            // set this as the one to remove
            blankLocationToRemove = loopBlankNumber;

            // Break out of the list
            break;
        }
    }

    // Remove it from the list
    newBlankNumbersToAdd.splice(blankLocationToRemove,1);
}

// Create a function to create a select list off of the comma delimited array provided
function createSelectHTMLFromList(selectName, list, style){
    // Create and init a return
    var returnHTML = '';
    
    // Determine if we have a list
    if (list !== ''){
        // Create  comma delimited list from the list passed in, hopefully
        var commaList = list.split(',');

        // Loop through the list
        for (var i = 0; i < commaList.length; i++) {
            // Add the option to the select
            returnHTML += commaList[i];
        }
        
        // Add the select tag
        returnHTML = '<select style="' + style + '" id="' + selectName + '" name="' + selectName + '">' + returnHTML + '</select>'
    }
    
    // Return what we created
    return returnHTML;
};

function addNewBlank() {
    console.log("in addNewNote");

    // Increment the amount that is currently in the array
    var newBlankAmountID=getNewMaxBlankNumber()+1;
    
    // Create the blank div
    var blankDiv = document.createElement("div");
    blankDiv.style = 'margin: 5px; width: 97%; border-bottom-style:dashed; border-width: 1px; display: inline-block; text-align: left; vertical-align: middle;';
    blankDiv.id = 'newBlank' + newBlankAmountID;
    blankDiv.name = 'newBlank' + newBlankAmountID;

    //!!!!!! Create the first table div. !!!!!!//
    var table1Div = document.createElement("div");
    table1Div.style = 'display: table; margin: 5px; width: 97%; border-width: 1px; display: inline-block; text-align: center; vertical-align: middle;';
    table1Div.id = 'table1' + newBlankAmountID;
    table1Div.name = 'table1' + newBlankAmountID;

    // Add the first table to the blank div
    blankDiv.appendChild(table1Div);

    // Start table 1 row 1
     
    // Create a div to hold the blank row
    var blankTable1Line1Div = document.createElement("div");
    blankTable1Line1Div.style = 'display: table-row; width: 100%; margin: 5px; vertical-align: right; text-align: center; vertical-align: middle;';

    // Add the first row to the table 1 div
    table1Div.appendChild(blankTable1Line1Div);
    
    // Start table 1 cell 1 line 1
     
    // Create the first cell of the first line of the first table
    var blankTable1Line1Cell1 = document.createElement("div");
    blankTable1Line1Cell1.style = ' display: table-cell; width: 25%; padding-left: 50px; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: center; vertical-align: right;';

    // Add the blank cell to the blank row div
    blankTable1Line1Div.appendChild(blankTable1Line1Cell1);

    // Create the blank submit label
    var blankSubmitLabel = document.createElement("label");
    blankSubmitLabel.textContent="Submit: ";

    // Add the blank submit label to the cell
    blankTable1Line1Cell1.appendChild(blankSubmitLabel);
    
    // Create the blank submit checkbox
    var blankSubmitCheck = document.createElement("input");
    blankSubmitCheck.type = "checkbox";
    blankSubmitCheck.id = 'newBlankSubmitted' + newBlankAmountID;    
    blankSubmitCheck.name = 'newBlankSubmitted' + newBlankAmountID;  

    // Add the blank submit checkbox to the blank submit checkbox div
    blankTable1Line1Cell1.appendChild(blankSubmitCheck);
    
    // Start table 1 cell 2 line 1
    
    // Create the second cell of the first line
    var blankTable1Line1Cell2 = document.createElement("div");
    blankTable1Line1Cell2.style = ' display: table-cell; width: 25%; padding-left: 1px; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: center; vertical-align: right;';

    // Add the cell to the table
    blankTable1Line1Div.appendChild(blankTable1Line1Cell2);
    
    // Create the blank rush label
    var blankRushLabel = document.createElement("label");
    blankRushLabel.textContent="Rush: ";

    // Add the blank rush label to the blank cell
    blankTable1Line1Cell2.appendChild(blankRushLabel);
    
    // Create the blank rush checkboxt
    var blankRushCheck = document.createElement("input");
    blankRushCheck.type = "checkbox";
    blankRushCheck.id = 'newBlankRush' + newBlankAmountID;    
    blankRushCheck.name = 'newBlankRush' + newBlankAmountID;  

    // Add the blank rush checkbox to the cell
    blankTable1Line1Cell2.appendChild(blankRushCheck);
    
    // Start table 1 cell 3 line 1
    
    // Create the third cell of the first line
    var blankTable1Line1Cell3 = document.createElement("div");
    blankTable1Line1Cell3.style = ' display: table-cell; width: 25%; padding-left: 1px; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: center; vertical-align: right;';

    // Add the cell to the row
    blankTable1Line1Div.appendChild(blankTable1Line1Cell3);
    
    // Create the blank ready label
    var blankReadyLabel = document.createElement("label");
    blankReadyLabel.textContent="Ready: ";

    // Add the blank ready label to the cell
    blankTable1Line1Cell3.appendChild(blankReadyLabel);
    
    // Create the blank ready checkbox
    var blankReadyCheck = document.createElement("input");
    blankReadyCheck.type = "checkbox";
    blankReadyCheck.id = 'newBlankReady' + newBlankAmountID;    
    blankReadyCheck.name = 'newBlankReady' + newBlankAmountID;  
    blankReadyCheck.onchange = function(a) {  
        return function() {
           checkPendingStockBoxesDependingOnOthers(this, a, true);
        };
    }(newBlankAmountID);

    // Add the blank ready checkbox to the cell
    blankTable1Line1Cell3.appendChild(blankReadyCheck);
    
    // Start table 1 cell 4 line 1
    
    // Create the third cell of the first line
    var blankTable1Line1Cell4 = document.createElement("div");
    blankTable1Line1Cell4.style = ' display: table-cell; width: 25%; padding-left: 1px; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: center; vertical-align: right;';

    // Add the cell to the row
    blankTable1Line1Div.appendChild(blankTable1Line1Cell4);
    
    // Create the blank waiting for stock label
    var blankWaitingForStockLabel = document.createElement("label");
    blankWaitingForStockLabel.textContent="Waiting For Stock: ";

    // Add the blank waiting for stock label to the cell
    blankTable1Line1Cell4.appendChild(blankWaitingForStockLabel);
    
    // Create the blank ready checkbox
    var blankWaitingForStockCheck = document.createElement("input");
    blankWaitingForStockCheck.type = "checkbox";
    blankWaitingForStockCheck.id = 'newIsPendingStock' + newBlankAmountID;    
    blankWaitingForStockCheck.name = 'newIsPendingStock' + newBlankAmountID;  
    blankWaitingForStockCheck.onchange = function(a) {  
        return function() {
           checkPendingStockBoxesDependingOnOthers(this, a, true);
        };
    }(newBlankAmountID);

    // Add the blank ready checkbox to the cell
    blankTable1Line1Cell4.appendChild(blankWaitingForStockCheck);
    
    //!!!!!! Create the second table div. !!!!!!//
    var table2Div = document.createElement("div");
    table2Div.style = 'display: table; margin: 5px; width: 97%; display: inline-block; text-align: center; vertical-align: middle;';
    table2Div.id = 'table2' + newBlankAmountID;
    table2Div.name = 'table2' + newBlankAmountID;

    // Add the first table to the blank div
    blankDiv.appendChild(table2Div);
    
    // Start table 2 row 1
     
    // Create a div to hold the blank row
    var blankTable2Line1Div = document.createElement("div");
    blankTable2Line1Div.style = 'vertical-align: center; display: table-row; width: 100%; margin: 5px; text-align: center; vertical-align: middle;';

    // Add the blank row to the blank div
    table2Div.appendChild(blankTable2Line1Div);
    
    // Start table 2 cell 1 line 1
     
    // Create the first cell of the first line
    var blankTable2Line1Cell1 = document.createElement("div");
    blankTable2Line1Cell1.style = ' display: table-cell; width: 25%; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: right; vertical-align: middle;';

    // Add the blank label to the blank label div
    blankTable2Line1Div.appendChild(blankTable2Line1Cell1);

    // Create the blank quantity label
    var blankQuantityLabel = document.createElement("label");
    blankQuantityLabel.textContent="Quantity: ";

    // Add the blank quantity label to the blank label div
    blankTable2Line1Cell1.appendChild(blankQuantityLabel);
    
    // Create the second cell of the first line
    var blankTable2Line1Cell2 = document.createElement("div");
    blankTable2Line1Cell2.style = ' display: table-cell; width: 25%; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: left; vertical-align: middle;';

    // Add the blank label to the blank label div
    blankTable2Line1Div.appendChild(blankTable2Line1Cell2);

    // Create the blank quantity textbox
    var blankQuantity = document.createElement("textarea");
    blankQuantity.rows = '1';
    blankQuantity.id = 'newBlankQuantity' + newBlankAmountID;    
    blankQuantity.name = 'newBlankQuantity' + newBlankAmountID;  
    blankQuantity.style = 'resize: none;';
    blankQuantity.maxLength = 11;

    // Add the quantity text to the cell
    blankTable2Line1Cell2.appendChild(blankQuantity);
    
    // Start table 2 cell 3 line 1
     
    // Create the first cell of the third line
    var blankTable2Line1Cell3 = document.createElement("div");
    blankTable2Line1Cell3.style = ' display: table-cell; width: 15%; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: right; vertical-align: middle;';

    // Add the cell to the row
    blankTable2Line1Div.appendChild(blankTable2Line1Cell3);

    // Create the Dimension 1 label
    var blankDimension1Label = document.createElement("label");
    blankDimension1Label.textContent="Dimension 1: ";

    // Add the Dimension 1 label to the cell
    blankTable2Line1Cell3.appendChild(blankDimension1Label);

    // Start table 2 cell 4 line 1
     
    // Create the second cell of the third line
    var blankTable2Line1Cell4 = document.createElement("div");
    blankTable2Line1Cell4.style = ' display: table-cell; width: 35%; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: left; vertical-align: middle;';

    // Add the cell to the row
    blankTable2Line1Div.appendChild(blankTable2Line1Cell4);

    // Create the dimension 1 text
    var blankDimension1 = document.createElement("textarea");
    blankDimension1.rows = '1';
    blankDimension1.id = 'newBlankDimension1' + newBlankAmountID;    
    blankDimension1.name = 'newBlankDimension1' + newBlankAmountID;  
    blankDimension1.style = 'resize: none; border-color: #00b33c; border-width: 2px; border-style: solid;';
    blankDimension1.maxLength = 15;

    // Add the dimension 1 text to the cell
    blankTable2Line1Cell4.appendChild(blankDimension1);
    
    // Create a div to hold the blank row
    var blankTable2Line4Div = document.createElement("div");
    blankTable2Line4Div.style = 'vertical-align: center; display: table-row; width: 100%; margin: 5px; vertical-align: middle; text-align: right; vertical-align: middle;';

    // Add the blank row to the table div
    table2Div.appendChild(blankTable2Line4Div);

    
    // Start table 2 row 2
     
    // Create a div to hold the blank row
    var blankTable2Line2Div = document.createElement("div");
    blankTable2Line2Div.style = 'vertical-align: center; display: table-row; width: 100%; margin: 5px; vertical-align: middle; text-align: right; vertical-align: middle;';

    // Add the blank row to the table div
    table2Div.appendChild(blankTable2Line2Div);
    
    // Start table 2 cell 1 line 2
     
    // Create the first cell of the second line
    var blankTable2Line2Cell1 = document.createElement("div");
    blankTable2Line2Cell1.style = ' display: table-cell; width: 25%; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: right; vertical-align: middle;';

    // Add the cell to the row
    blankTable2Line2Div.appendChild(blankTable2Line2Cell1);
    
        // Create the blank quantity label
    var blankQuantityDimensionLabel = document.createElement("label");
    blankQuantityDimensionLabel.textContent="Quantity Dimension: ";

    // Add the blank quantity Dimension label to the blank label div
    blankTable2Line2Cell1.appendChild(blankQuantityDimensionLabel);

    // Create the second cell of the second line
    var blankTable2Line2Cell2 = document.createElement("div");
    blankTable2Line2Cell2.style = ' display: table-cell; width: 25%; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: left; vertical-align: middle;';

    // Add the cell to the row
    blankTable2Line2Div.appendChild(blankTable2Line2Cell2);

    var blankQuantityDimension = document.createElement("div");
    blankQuantityDimension.innerHTML = createSelectHTMLFromList('newBlankQuantityDimension' + newBlankAmountID, "<option value='None' selected>None</option>,<option value='Dimension 1'>Dimension 1</option>,<option value='Dimension 2'>Dimension 2</option>,<option value='Dimension 3'>Dimension 3</option>", "");

    // Add the quantity text to the cell
    blankTable2Line2Cell2.appendChild(blankQuantityDimension);
    
    // Start table 2 cell 3 line 2
     
    // Create the third cell of the second line
    var blankTable2Line2Cell3 = document.createElement("div");
    blankTable2Line2Cell3.style = ' display: table-cell; width: 10%; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: right; vertical-align: middle;';

    // Add the cell to the row
    blankTable2Line2Div.appendChild(blankTable2Line2Cell3);

    // Start table 2 cell 4 line 2
     
    // Create the forth cell of the second line
    var blankTable2Line2Cell4 = document.createElement("div");
    blankTable2Line2Cell4.style = ' display: table-cell; width: 40%; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: left; vertical-align: middle;';

    // Add the cell to the row
    blankTable2Line2Div.appendChild(blankTable2Line2Cell4);

    // Deep Copy the Radio Div
    var radioToCopy1 = (' ' + genericDimensionRadio).slice(1);;
    
    // Replace appropriate names of the new string
    var radioCopy1 = '';
    radioCopy1 = radioToCopy1.replace(/genericDimension1Radio/g, ('newBlankDimension1Radio' + newBlankAmountID));
    var radioCopy2 = '';
    radioCopy2 = radioCopy1.replace(/genericDimension1/g, ('newBlankDimension1' + newBlankAmountID));
    
    // Create a paragraph to hold the radio html and the add the html
    var div1 = document.createElement("div");
    div1.innerHTML = radioCopy2;            

    // Add the paragraph to the cell
    blankTable2Line2Cell4.appendChild(div1);
    
    // Start table 2 row 3
     
    // Create a div to hold the blank row
    var blankTable2Line3Div = document.createElement("div");
    blankTable2Line3Div.style = 'vertical-align: center; display: table-row; width: 100%; margin: 5px; vertical-align: middle; text-align: right; vertical-align: middle;';

    // Add the blank row to the table div
    table2Div.appendChild(blankTable2Line3Div);
    
    // Start table 2 cell 1 line 3
     
    // Create the first cell of the second line
    var blankTable2Line3Cell1 = document.createElement("div");
    blankTable2Line3Cell1.style = ' display: table-cell; width: 25%; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: right; vertical-align: middle;';

    // Add the cell to the row
    blankTable2Line3Div.appendChild(blankTable2Line3Cell1);

    // Create the second cell of the second line
    var blankTable2Line3Cell2 = document.createElement("div");
    blankTable2Line3Cell2.style = ' display: table-cell; width: 25%; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: left; vertical-align: middle;';

    // Add the cell to the row
    blankTable2Line3Div.appendChild(blankTable2Line3Cell2);

    // Start table 2 cell 3 line 3
     
    // Create the third cell of the third line
    var blankTable2Line3Cell3 = document.createElement("div");
    blankTable2Line3Cell3.style = ' display: table-cell; width: 20%; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: right; vertical-align: middle;';

    // Add the cell to the row
    blankTable2Line3Div.appendChild(blankTable2Line3Cell3);

    // Create the Dimension 2 label
    var blankDimension2Label = document.createElement("label");
    blankDimension2Label.textContent="Dimension 2: ";

    // Add the Dimension 2 label to the cell
    blankTable2Line3Cell3.appendChild(blankDimension2Label);

    // Start table 2 cell 4 line 3
     
    // Create the forth cell of the third line
    var blankTable2Line3Cell4 = document.createElement("div");
    blankTable2Line3Cell4.style = ' display: table-cell; width: 80%; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: left; vertical-align: middle;';

    // Add the cell to the row
    blankTable2Line3Div.appendChild(blankTable2Line3Cell4);

    // Create the dimension 2 text
    var blankDimension2 = document.createElement("textarea");
    blankDimension2.rows = '1';
    blankDimension2.id = 'newBlankDimension2' + newBlankAmountID;    
    blankDimension2.name = 'newBlankDimension2' + newBlankAmountID;  
    blankDimension2.style = 'resize: none; border-color: #00b33c; border-width: 2px; border-style: solid;';
    blankDimension2.maxLength = 15;

    // Add the dimension 2 text to the cell
    blankTable2Line3Cell4.appendChild(blankDimension2);
    
    // Start table 2 row 4
     
    // Create a div to hold the blank row
    var blankTable2Line4Div = document.createElement("div");
    blankTable2Line4Div.style = 'vertical-align: center; display: table-row; width: 100%; margin: 5px; vertical-align: middle; text-align: right; vertical-align: middle;';

    // Add the blank row to the table div
    table2Div.appendChild(blankTable2Line4Div);
    
    // Start table 2 cell 1 line 4
    
    // Create the first cell of the second line
    var blankTable2Line4Cell1 = document.createElement("div");
    blankTable2Line4Cell1.style = ' display: table-cell; width: 25%; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: right; vertical-align: middle;';

    // Add the cell to the row
    blankTable2Line4Div.appendChild(blankTable2Line4Cell1);

    // Create the material label
    var blankMaterialLabel = document.createElement("label");
    blankMaterialLabel.textContent="Material: ";

    // Add the material label to the cell
    blankTable2Line4Cell1.appendChild(blankMaterialLabel);

    // Create the second cell of the forth line
    var blankTable2Line4Cell2 = document.createElement("div");
    blankTable2Line4Cell2.style = ' display: table-cell; width: 25%; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: left; vertical-align: middle;';

    // Add the cell to the row
    blankTable2Line4Div.appendChild(blankTable2Line4Cell2);
    
    // Create the material type text
    var blankMaterialType = document.createElement("div");
    blankMaterialType.innerHTML = createSelectHTMLFromList('newType' + newBlankAmountID, AvailableMaterialTypesAsSelectOptions, "");
    
    // Add the blank material type combobox to the cell div
    blankTable2Line4Cell2.appendChild(blankMaterialType);
    
    // Create the material category
    var blankMaterial = document.createElement("div");
    blankMaterial.style = 'width: 125px; white-space: initial;';
    blankMaterial.innerHTML = createSelectHTMLFromList('newBlankMaterialID' + newBlankAmountID, AvailableMaterialsAsSelectOptions, "width: 175px; white-space: initial;");
    
    // Add the blank material textbox to the cell div
    blankTable2Line4Cell2.appendChild(blankMaterial);
    
    // Create the hidden value for the suggested stock
    var recommendedBlank = document.createElement("input");
    recommendedBlank.id = 'newSuggestStockID' + newBlankAmountID;    
    recommendedBlank.name = 'newSuggestStockID' + newBlankAmountID;  
    recommendedBlank.type = 'hidden';
    recommendedBlank.value = '-1';

    // Add the blank material textbox to the cell div
    blankTable2Line4Cell2.appendChild(recommendedBlank);
    
    // Create the recommend button
    var recommendBtn = document.createElement("button");
    recommendBtn.textContent="Recommend";
    recommendBtn.id = 'newSuggestStock' + newBlankAmountID;    
    recommendBtn.name = 'newSuggestStock' + newBlankAmountID;    
    recommendBtn.class = 'suggestStock';
    recommendBtn.type = 'button';
    recommendBtn.onclick = function() {  
        getStock('newSuggestStock' + newBlankAmountID, 'showSelectStockBackgroundDiv', sessionID);
    };

    // Add the paragraph to the cell
    blankTable2Line4Cell2.appendChild(recommendBtn);
    
    // Create the recommend button
    var resetBtn = document.createElement("button");
    resetBtn.textContent="Reset";
    resetBtn.id = 'newResetSuggestion' + newBlankAmountID;    
    resetBtn.name = 'newResetSuggestion' + newBlankAmountID;    
    resetBtn.type = 'button';
    resetBtn.disabled=true;
    resetBtn.onclick = function() { 
        resetBlank(newBlankAmountID, 1);
    };

    // Add the paragraph to the cell
    blankTable2Line4Cell2.appendChild(resetBtn);
    
    // Start table 2 cell 3 line 2
     
    // Create the third cell of the forth line
    var blankTable2Line4Cell3 = document.createElement("div");
    blankTable2Line4Cell3.style = ' display: table-cell; width: 10%; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: right; vertical-align: middle;';

    // Add the cell to the row
    blankTable2Line4Div.appendChild(blankTable2Line4Cell3);

    // Start table 2 cell 4 line 4
     
    // Create the forth cell of the forth line
    var blankTable2Line4Cell4 = document.createElement("div");
    blankTable2Line4Cell4.style = ' display: table-cell; width: 40%; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: left; vertical-align: middle;';

    // Add the cell to the row
    blankTable2Line4Div.appendChild(blankTable2Line4Cell4);

    // Deep Copy the Radio Div
    var radioToCopy2 = (' ' + genericDimensionRadio).slice(1);;
    
    // Replace appropriate names of the new string
    var radioCopy3 = '';
    radioCopy3 = radioToCopy2.replace(/genericDimension1Radio/g, ('newBlankDimension2Radio' + newBlankAmountID));
    var radioCopy4 = '';
    radioCopy4 = radioCopy3.replace(/genericDimension1/g, ('newBlankDimension2' + newBlankAmountID));
    
    // Create a paragraph to hold the radio html and the add the html
    var div2 = document.createElement("div");
    div2.innerHTML = radioCopy4;            

    // Add the paragraph to the cell
    blankTable2Line4Cell4.appendChild(div2);
    
    // Start table 2 row 5
     
    // Create a div to hold the blank row
    var blankTable2Line5Div = document.createElement("div");
    blankTable2Line5Div.style = 'vertical-align: center; display: table-row; width: 100%; margin: 5px; vertical-align: middle; text-align: right; vertical-align: middle;';

    // Add the blank row to the table div
    table2Div.appendChild(blankTable2Line5Div);
    
    // Start table 2 cell 1 line 5
     
    // Create the first cell of the forth line
    var blankTable2Line5Cell1 = document.createElement("div");
    blankTable2Line5Cell1.style = ' display: table-cell; width: 25%; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: right; vertical-align: middle;';

    // Add the cell to the row
    blankTable2Line5Div.appendChild(blankTable2Line5Cell1);

    // Create the second cell of the fifth line
    var blankTable2Line5Cell2 = document.createElement("div");
    blankTable2Line5Cell2.style = ' display: table-cell; width: 25%; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: left; vertical-align: middle;';

    // Add the cell to the row
    blankTable2Line5Div.appendChild(blankTable2Line5Cell2);

    // Start table 2 cell 3 line 5
     
    // Create the third cell of the fifth line
    var blankTable2Line5Cell3 = document.createElement("div");
    blankTable2Line5Cell3.style = ' display: table-cell; width: 20%; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: right; vertical-align: middle;';

    // Add the cell to the row
    blankTable2Line5Div.appendChild(blankTable2Line5Cell3);

    // Create the Dimension 3 label
    var blankDimension2Label = document.createElement("label");
    blankDimension2Label.textContent="Dimension 3: ";

    // Add the Dimension 3 label to the cell
    blankTable2Line5Cell3.appendChild(blankDimension2Label);

    // Start table 2 cell 4 line 5
     
    // Create the forth cell of the fifth line
    var blankTable2Line5Cell4 = document.createElement("div");
    blankTable2Line5Cell4.style = ' display: table-cell; width: 80%; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: left; vertical-align: middle;';

    // Add the cell to the row
    blankTable2Line5Div.appendChild(blankTable2Line5Cell4);

    // Create the dimension 3 text
    var blankDimension3 = document.createElement("textarea");
    blankDimension3.rows = '1';
    blankDimension3.id = 'newBlankDimension3' + newBlankAmountID;    
    blankDimension3.name = 'newBlankDimension3' + newBlankAmountID;  
    blankDimension3.style = 'resize: none; border-color: #00b33c; border-width: 2px; border-style: solid;';
    blankDimension3.maxLength = 15;

    // Add the dimension 3 text to the cell
    blankTable2Line5Cell4.appendChild(blankDimension3);
    
    // Start table 2 row 6
     
    // Create a div to hold the blank row
    var blankTable2Line6Div = document.createElement("div");
    blankTable2Line6Div.style = 'vertical-align: center; display: table-row; width: 100%; margin: 5px; vertical-align: middle; text-align: right; vertical-align: middle;';

    // Add the blank row to the table div
    table2Div.appendChild(blankTable2Line6Div);
    
    // Start table 2 cell 1 line 6
     
    // Create the first cell of the sixth line
    var blankTable2Line6Cell1 = document.createElement("div");
    blankTable2Line6Cell1.style = ' display: table-cell; width: 25%; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: right; vertical-align: middle;';

    // Add the cell to the row
    blankTable2Line6Div.appendChild(blankTable2Line6Cell1);
    
    // Create the second cell of the sixth line
    var blankTable2Line6Cell2 = document.createElement("div");
    blankTable2Line6Cell2.style = ' display: table-cell; width: 25%; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: left; vertical-align: middle;';

    // Add the cell to the row
    blankTable2Line6Div.appendChild(blankTable2Line6Cell2);

    // Start table 2 cell 3 line 6
     
    // Create the third cell of the sixth line
    var blankTable2Line6Cell3 = document.createElement("div");
    blankTable2Line6Cell3.style = ' display: table-cell; width: 10%; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: right; vertical-align: middle;';

    // Add the cell to the row
    blankTable2Line6Div.appendChild(blankTable2Line6Cell3);

    // Start table 2 cell 4 line 6
     
    // Create the sixth cell of the sixth line
    var blankTable2Line6Cell4 = document.createElement("div");
    blankTable2Line6Cell4.style = ' display: table-cell; width: 40%; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: left; vertical-align: middle;';

    // Add the cell to the row
    blankTable2Line6Div.appendChild(blankTable2Line6Cell4);

    // Deep Copy the Radio Div
    var radioToCopy3 = (' ' + genericDimensionRadio).slice(1);;
    
    // Replace appropriate names of the new string
    var radioCopy5 = '';
    radioCopy5 = radioToCopy3.replace(/genericDimension1Radio/g, ('newBlankDimension3Radio' + newBlankAmountID));
    var radioCopy6 = '';
    radioCopy6 = radioCopy5.replace(/genericDimension1/g, ('newBlankDimension3' + newBlankAmountID));
    
    // Create a paragraph to hold the radio html and the add the html
    var div3 = document.createElement("div");
    div3.innerHTML = radioCopy6;            

    // Add the paragraph to the cell
    blankTable2Line6Cell4.appendChild(div3);
    
    // Start table 2 row 7
     
    // Create a div to hold the blank row
    var blankTable2Line7Div = document.createElement("div");
    blankTable2Line7Div.style = 'vertical-align: center; display: table-row; width: 100%; margin: 5px; vertical-align: middle; text-align: right; vertical-align: middle;';

    // Add the blank row to the table div
    table2Div.appendChild(blankTable2Line7Div);
    
    // Start table 2 cell 1 line 7
     
    // Create the first cell of the seventh line
    var blankTable2Line7Cell1 = document.createElement("div");
    blankTable2Line7Cell1.style = ' display: table-cell; width: 25%; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: right; vertical-align: middle;';

    // Add the cell to the row
    blankTable2Line7Div.appendChild(blankTable2Line7Cell1);

    // Create the blank reason label
    var blankReasonLabel = document.createElement("label");
    blankReasonLabel.textContent="Reason: ";

    // Add the material label to the cell
    blankTable2Line7Cell1.appendChild(blankReasonLabel);
    
    // Create the second cell of the seventh line
    var blankTable2Line7Cell2 = document.createElement("div");
    blankTable2Line7Cell2.style = ' display: table-cell; width: 25%; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: left; vertical-align: middle;';

    // Add the cell to the row
    blankTable2Line7Div.appendChild(blankTable2Line7Cell2);

    // Create the blank reason checkbox
    var blankReason = document.createElement("textarea");
    blankReason.rows = '4';
    blankReason.id = 'newBlankReason' + newBlankAmountID;    
    blankReason.name = 'newBlankReason' + newBlankAmountID;  
    blankReason.style = 'resize: none;';
    blankReason.maxLength = 500;

    // Add the material text to the cell
    blankTable2Line7Cell2.appendChild(blankReason);
    
    // Start table 2 cell 3 line 7
     
    // Create the third cell of the seventh line
    var blankTable2Line7Cell3 = document.createElement("div");
    blankTable2Line7Cell3.style = ' display: table-cell; width: 10%; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: right; vertical-align: middle;';

    // Add the cell to the row
    blankTable2Line7Div.appendChild(blankTable2Line7Cell3);
    
    // Create the blank reason label
    var blankWallThickness = document.createElement("label");
    blankWallThickness.textContent="Wall Thickness: ";

    // Add the material label to the cell
    blankTable2Line7Cell3.appendChild(blankWallThickness);

    // Start table 2 cell 4 line 7
     
    // Create the forth cell of the seventh line
    var blankTable2Line7Cell4 = document.createElement("div");
    blankTable2Line7Cell4.style = ' display: table-cell; width: 40%; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: left; vertical-align: middle;';

    // Add the cell to the row
    blankTable2Line7Div.appendChild(blankTable2Line7Cell4);

    // Create the dimension 3 text
    var wallThickness = document.createElement("textarea");
    wallThickness.rows = '1';
    wallThickness.id = 'newWallThickness' + newBlankAmountID;    
    wallThickness.name = 'newWallThickness' + newBlankAmountID;  
    wallThickness.style = 'resize: none;';
    wallThickness.maxLength = 15;

    // Add the dimension 3 text to the cell
    blankTable2Line7Cell4.appendChild(wallThickness);
    
    // Start table 2 row 8
     
    // Create a div to hold the blank row
    var blankTable2Line8Div = document.createElement("div");
    blankTable2Line8Div.style = 'vertical-align: center; display: table-row; width: 100%; margin: 5px; vertical-align: middle; text-align: right; vertical-align: middle;';

    // Add the blank row to the table div
    table2Div.appendChild(blankTable2Line8Div);
    
    // Start table 2 cell 1 line 8
     
    // Create the first cell of the eighth line
    var blankTable2Line8Cell1 = document.createElement("div");
    blankTable2Line8Cell1.style = ' display: table-cell; width: 25%; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: right; vertical-align: middle;';

    // Add the cell to the row
    blankTable2Line8Div.appendChild(blankTable2Line8Cell1);

    // Create the second cell of the eighth line
    var blankTable2Line8Cell2 = document.createElement("div");
    blankTable2Line8Cell2.style = ' display: table-cell; width: 25%; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: left; vertical-align: middle;';

    // Add the cell to the row
    blankTable2Line8Div.appendChild(blankTable2Line8Cell2);

    // Start table 2 cell 3 line 8
     
    // Create the third cell of the eight line
    var blankTable2Line8Cell3 = document.createElement("div");
    blankTable2Line8Cell3.style = ' display: table-cell; width: 10%; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: right; vertical-align: middle;';

    // Add the cell to the row
    blankTable2Line8Div.appendChild(blankTable2Line8Cell3);

    // Start table 2 cell 4 line 8
     
    // Create the forth cell of the eigth line
    var blankTable2Line8Cell4 = document.createElement("div");
    blankTable2Line8Cell4.style = ' display: table-cell; width: 40%; padding-right: 1px; font-weight: bold; font-size: 11px; text-align: right; vertical-align: bottom;';

    // Add the cell to the row
    blankTable2Line8Div.appendChild(blankTable2Line8Cell4);
    
    // Create the remove blank button
    var removeBtn = document.createElement("button");
    removeBtn.textContent="Remove Blank";
    removeBtn.id = 'outRemoveBtn' + newBlankAmountID;    
    removeBtn.style = 'margin-left: %90;';
    removeBtn.onclick = function(i) {  
        return function() {
           removeNewBlank(i);
        };
    }(newBlankAmountID);

    // Add the paragraph to the cell
    blankTable2Line8Cell4.appendChild(removeBtn);
    
    // Add the new div tag to the main div tag
    var container = document.getElementById("newBlanks");
    container.appendChild(blankDiv);
    
    // Add this ID to the list
    newBlankNumbersToAdd.push(newBlankAmountID);
    
    // Get the element and change the amount of blankes
    var blankAmountDiv = document.getElementById("newBlankNumbers");
    blankAmountDiv.value=newBlankNumbersToAdd.join('|');
    
    // Add any validation that we have
    addBlankValidation(newBlankAmountID);
}

function addBlankValidation(blankToAddValidation){
    console.log("in addBlankValidation");

    // Ensure that the validator object is available
    if (typeof frmvalidator !== 'undefined'){
        // Add the validators
        frmvalidator.addValidation("newBlankQuantity" +  blankToAddValidation,
                                   "req",
                                   "Please enter a quantity for all blanks.");
        frmvalidator.addValidation("newBlankQuantity" +  blankToAddValidation,
                                   "num",
                                   "Please enter the quantity for all blanks as a number.");
        frmvalidator.addValidation("newBlankQuantity" +  blankToAddValidation,
                                   "greaterthan=-.0000000001",
                                   "The quantity for all blanks should be greater than 0.");
        frmvalidator.addValidation("newBlankDimension1" +  blankToAddValidation,
                                   "req",
                                   "Please enter dimension 1 for all blanks.");
        frmvalidator.addValidation("newBlankDimension1" +  blankToAddValidation,
                                   "num",
                                   "Please enter dimension 1 for all blanks as a number.");
        frmvalidator.addValidation("newBlankDimension1" +  blankToAddValidation,
                                   "greaterthan=-.0000000001",
                                   "Dimension 1 for all blanks should be greater than 0.");
        frmvalidator.addValidation("newBlankDimension2" +  blankToAddValidation,
                                   "req",
                                   "Please enter dimension 2 for all blanks.");
        frmvalidator.addValidation("newBlankDimension2" +  blankToAddValidation,
                                   "num",
                                   "Please enter dimension 2 for all blanks as a number.");
        frmvalidator.addValidation("newBlankDimension2" +  blankToAddValidation,
                                   "greaterthan=-.0000000001",
                                   "Dimension 2 for all blanks should be greater than 0.");
        frmvalidator.addValidation("newBlankDimension3" +  blankToAddValidation,
                                   "req",
                                   "Please enter dimension 3 for all blanks.");
        frmvalidator.addValidation("newBlankDimension3" +  blankToAddValidation,
                                   "num",
                                   "Please enter dimension 3 for all blanks as a number.");
        frmvalidator.addValidation("newBlankDimension3" +  blankToAddValidation,
                                   "greaterthan=-.0000000001",
                                   "Dimension 3 for all blanks should be greater than 0.");
    }
}

function removeNewBlank(blankToRemove){
    console.log("in removeNewBlank");

    // Get the element to remove
    var blank = document.getElementById('newBlank'+blankToRemove);

    // Remove it
    blank.parentNode.removeChild(blank);    
    
    // Remove this from the list
    removeNewBlankNumber(blankToRemove);
    
    // Reset the blank number string
    var blankAmount = document.getElementById("newBlankNumbers");
    blankAmount.value=createNewBlankNumberString();
}


/* The next methods are mainly to select stock with the selected stock popup. */

//Function To Display Selected stock Popup
function div_showSelectStock() {
    // Get the outer div and show it
    div_show('showSelectStock');

    // Get the show all stock div
    var showSelectStockBackgroundDiv = document.getElementById('showSelectStockBackgroundDiv');

    // Scroll back to the top of the DIV
    showSelectStockBackgroundDiv.scrollTop = 0;
}

function resetBlank(number, newBlank){
    // Create variables to hold the elements to change
    var dimension1 = null;
    var dimension2 = null;
    var dimension3 = null;
    var wallThickness = null;
    var suggestStockID = null;
    var suggestStock = null;
    var resetSuggestion = null;
    var blankQuantityDimension = null;
    var type = null;
    var blankMaterialID = null;

    // Determine if this is from a current blank or new
    if (!newBlank){
        // Get the controls to change
        dimension1 = document.getElementById('dimension1' + number);
        dimension2 = document.getElementById('dimension2' + number);
        dimension3 = document.getElementById('dimension3' + number);
        wallThickness = document.getElementById('wallThickness' + number);
        suggestStockID = document.getElementById('suggestStockID' + number);
        suggestStock = document.getElementById('suggestStock' + number);
        resetSuggestion = document.getElementById('resetSuggestion' + number);
        blankQuantityDimension = document.getElementById('quantityDimension' + number);
        type = document.getElementById('type' + number);
        blankMaterialID = document.getElementById('materialID' + number);
    }
    else {
        // Get the controls to set
        dimension1 = document.getElementById('newBlankDimension1' + number);
        dimension2 = document.getElementById('newBlankDimension2' + number);
        dimension3 = document.getElementById('newBlankDimension3' + number);
        wallThickness = document.getElementById('newWallThickness' + number);
        suggestStockID = document.getElementById('newSuggestStockID' + number);
        suggestStock = document.getElementById('newSuggestStock' + number);
        resetSuggestion = document.getElementById('newResetSuggestion' + number);
        blankQuantityDimension = document.getElementById('newBlankQuantityDimension' + number);
        type = document.getElementById('newType' + number);
        blankMaterialID = document.getElementById('newBlankMaterialID' + number);
    }

    // Set the values if the control exists
    if (typeof(dimension1) !== 'undefined'){dimension1.readOnly =false; dimension1.style.color='black';}
    if (typeof(dimension2) !== 'undefined'){dimension2.readOnly =false; dimension2.style.color='black';}
    if (typeof(dimension3) !== 'undefined'){dimension3.readOnly =false; dimension3.style.color='black';}
    if (typeof(wallThickness) !== 'undefined'){wallThickness.readOnly =false; wallThickness.style.color='black';}
    if (typeof(suggestStockID) !== 'undefined'){suggestStockID.value = '-1';}
    if (typeof(blankQuantityDimension) !== 'undefined'){blankQuantityDimension.style.pointerEvents = "auto"; blankQuantityDimension.style.background='initial'; blankQuantityDimension.style.color='black';}
    if (typeof(blankQuantityDimension) !== 'undefined'){type.style.pointerEvents = "auto"; type.style.background='initial'; type.style.color='black';}
    if (typeof(blankQuantityDimension) !== 'undefined'){blankMaterialID.style.pointerEvents = "auto"; blankMaterialID.style.background='initial'; blankMaterialID.style.color='black';}

    // change swapping
    if (typeof(suggestStock) !== 'undefined'){suggestStock.disabled = false;}
    if (typeof(resetSuggestion) !== 'undefined'){resetSuggestion.disabled = true;}
}

function stockSelected(inControl, selectedID, inDimension1, inDimension2, inDimension3, inWallThickness, inDisableDimension1){
    // Determine if the ID control exists first thing
    if (typeof(inControl) !== 'undefined'){
        // Create a variable to hold the number we are on and blank type
        var number=-1;

        // Create variables to hold the elements to change
        var dimension1 = null;
        var dimension2 = null;
        var dimension3 = null;
        var wallThickness = null;
        var suggestStock = null;
        var resetSuggestion = null;
        var blankQuantityDimension = null;
        var type = null;
        var blankMaterialID = null;

        // Determine if this is from a current blank or new
        var theName = inControl.name;
        if (theName.includes("suggestStockID")){
            // Get the number from the name
            number = theName.replace("suggestStockID","");

            // Get the controls to set
            dimension1 = document.getElementById('dimension1' + number);
            dimension2 = document.getElementById('dimension2' + number);
            dimension3 = document.getElementById('dimension3' + number);
            wallThickness = document.getElementById('wallThickness' + number);
            suggestStock = document.getElementById('suggestStock' + number);
            resetSuggestion = document.getElementById('resetSuggestion' + number);
            blankQuantityDimension = document.getElementById('quantityDimension' + number);
            type = document.getElementById('type' + number);
            blankMaterialID = document.getElementById('materialID' + number);
        }
        else {
            // Get the number from the name
            number = theName.replace("newSuggestStockID","");

            // Get the controls to set
            dimension1 = document.getElementById('newBlankDimension1' + number);
            dimension2 = document.getElementById('newBlankDimension2' + number);
            dimension3 = document.getElementById('newBlankDimension3' + number);
            wallThickness = document.getElementById('newWallThickness' + number);
            suggestStock = document.getElementById('newSuggestStock' + number);
            resetSuggestion = document.getElementById('newResetSuggestion' + number);
            blankQuantityDimension = document.getElementById('newBlankQuantityDimension' + number);
            type = document.getElementById('newType' + number);
            blankMaterialID = document.getElementById('newBlankMaterialID' + number);
        }

        // Determine if dimension one is disabled
        var dimension1Color='black';
        
        // change it to be the read only and color to red
        if (typeof(blankQuantityDimension) !== 'undefined'){blankQuantityDimension.style.pointerEvents = "none"; blankQuantityDimension.style.background='lightgrey'; blankQuantityDimension.value = 'Dimension 1'; blankQuantityDimension.style.color='red';}
        
        // Determine if they passed in to have dimension 1 disabled
        if (inDisableDimension1){
            // change the color to red
            dimension1Color='red';
            
            // change it to be the read only state and set the first value as the selected value and turn red
            if (typeof(blankQuantityDimension) !== 'undefined'){blankQuantityDimension.style.pointerEvents = "auto"; blankQuantityDimension.style.background='initial'; blankQuantityDimension.style.color='black';}
        }

        // Set the values if the control exists
        if (typeof(dimension1) !== 'undefined'){dimension1.value = inDimension1; dimension1.readOnly = inDisableDimension1; dimension1.style.color=dimension1Color;}
        if (typeof(dimension2) !== 'undefined'){dimension2.value = inDimension2; dimension2.readOnly =true; dimension2.style.color='red';}
        if (typeof(dimension3) !== 'undefined'){dimension3.value = inDimension3; dimension3.readOnly =true; dimension3.style.color='red';}
        if (typeof(wallThickness) !== 'undefined'){wallThickness.value = inWallThickness; wallThickness.readOnly =true; wallThickness.style.color='red';}
        if (typeof(type) !== 'undefined'){type.style.pointerEvents = "none"; type.style.background='lightgrey'; type.style.color='red';}
        if (typeof(blankMaterialID) !== 'undefined'){blankMaterialID.style.pointerEvents = "none"; blankMaterialID.style.background='lightgrey'; blankMaterialID.style.color='red';}

        // Set the ID control
        inControl.value = selectedID;

        // change swapping
        if (typeof(suggestStock) !== 'undefined'){suggestStock.disabled = true;}
        if (typeof(resetSuggestion) !== 'undefined'){resetSuggestion.disabled = false;}
    }

    // Hide the assigned tools div that should still be shown
    div_hide('showSelectStock');
}

// Function to handle AJax
function getStock(inTheName, controlToPlaceHTML, sessionID=null){
    // Create a variable to hold the number we are on and blank type
    var number=-1;
    var controlName="";

    // Create variables to hold the passing parameters
    var type = "";
    var material=-1;

    // Determine if this is from a current blank or new
    var theName = inTheName;
    if (theName.includes("suggestStock")){
        // Get the number from the name
        number = theName.replace("suggestStock","");

        // Set the return control name appropriately
        controlName="suggestStockID" + number;

        // Get the type
        type = document.getElementById('type'+number).value;

        // Get the material
        material = document.getElementById('materialID'+number).value;
    }
    else {
        // Get the number from the name
        number = theName.replace("newSuggestStock","");

        // Set the return control name appropriately
        controlName="newSuggestStockID" + number;

        // Get the type
        type = document.getElementById('newType'+number).value;

        // Get the material
        material = document.getElementById('newBlankMaterialID'+number).value;
    }

    // Setup the parameters to pass to PHP
    var params = {
        "type" : type,
        "material" : material, 
        "controlname" : controlName,
        "sessionID" : sessionID
    };

    // Create the string containing the PHP file to use
    var url = "php_only_scripts/jquery_only/material_stock_bymaterialandtype.php";

    // Setup AJAX for communication
    $.ajax({
        context : this,
        type    : "GET", 
        url     : url, 
        data    : params, 
        dataType: "html", 
        encode  : true, 
        cache   : false
    })
    .done(function(data){
        // assign the inner HTML to be the returned HTML made from the query
        document.getElementById(controlToPlaceHTML).innerHTML = data;

        // Show the hidden stock div
        div_showSelectStock();
    })
    .fail(function(data){   
        // Log any errors to the console
        console.log(data);
    }); 
}

function copyBlank(sessionID, blankIDToCopy, quantity, addedReason, rushed){
//function addStickyNote(sessionID, taskIDStickyNote, category, stickyNoteTo, stickyNoteTitle, stickyNoteContent){
    // Set the return value to success for now
    $success=true;

    // Setup the parameters to pass to PHP
    var params = {
        "blankIDToCopy" : blankIDToCopy,
        "quantity" : quantity,
        "addedReason" : addedReason,
        "rushed" : rushed,
        "sessionID" : sessionID
    };

    // Create the string containing the PHP file to use
    var url = "php_only_scripts/jquery_only/copy_task_blank.php";

    // Setup AJAX for communication
    $.ajax({
        context : this,
        type    : "GET", 
        url     : url, 
        data    : params, 
        dataType: "text", 
        encode  : true,
        async   : false, 
        cache   : false
    })
    .done(function(returnData){
        // Check to see if there is a reason NOT to copy blanks
        if (returnData.includes("ABORT BLANK COPY")){
            // Set the return value failed
            $success=false;

            // Split the string on the double colon
            var errorStrings=returnData.trim().split("::");

            // Give an alert popup of the problem
            alert(errorStrings[1]);

            // Log any errors to the console
            console.log(returnData.trim());
        }
    })
    .fail(function(data){   
        // Log any errors to the console
        console.log(data);

        // Set the return value failed
        $success=false;
    });

    // Return what we got for success
    return $success;
}
