﻿function AllowNumericOnly(e) {
        var unicode = e.charCode ? e.charCode : e.keyCode
        if (unicode != 8) { //if the key isn't the backspace key (which we should allow)
            if (unicode < 48 || unicode > 57) //if not a number
                return false //disable key press
        }
    }
    

function ShowQuotedPricing(headerString, groupRowString, itemRowString) {

    headerButton = document.getElementById(headerString);
    groupRow = document.getElementById(groupRowString);
    itemRow = document.getElementById(itemRowString);


    if(headerButton.collapsed == true)
    {
        headerButton.src = '/Images/expand.jpg'; 
        headerButton.collapsed=false;
        groupRow.style.display = 'none';
        
        if(itemRow != null)
        {        
            itemRow.style.display = 'none';
        }
    } 
    else 
    { 
        headerButton.src= '/Images/collapse.jpg'; 
        headerButton.collapsed=true;

        groupRow.style.display = 'inline';
        
        if(itemRow != null)
        {        
            itemRow.style.display = 'inline';
        }
    }
}

function ShowQuotedPricingItem(headerButton, groupRow) {
    if (headerButton.collapsed == true) {
        headerButton.src = '/Images/expand.jpg';
        headerButton.collapsed = false;
        groupRow.style.display = 'none';
    }
    else {
        headerButton.src = '/Images/collapse.jpg';
        headerButton.collapsed = true;

        groupRow.style.display = 'inline';
    }
}

function tranzonic_BuildQuotedPricing(outputContainer, hierarchy) {

    outputContainer.innerHTML = tranzonic_CreateHiearchy(hierarchy, true);
}

function tranzonic_CreateHiearchy(hierarchy, showStrong) 
{
    var output = "";

    for (var i = 0; i < hierarchy.length; i++) {

        var onClickHandler = "ShowQuotedPricing('" + hierarchy[i][1] + "Image','" + hierarchy[i][1] + "Child','" + hierarchy[i][1] + "Items')";

        output +=
                    "<table width='100%' cellspacing='0px'>" +
                        "<tr onClick=\"" + onClickHandler + "\">" +
                            "<td style='width:15px' rowspan='2' valign='top'>" +
                                "<img src='/Images/expand.jpg' alt='expand' id='" + hierarchy[i][1] + "Image' />" +
                            "</td>" +
                            "<td colspan='2' align='left'>" +
                                 (showStrong ? "<strong>" : "") +
                                 hierarchy[i][0] +
                                 (showStrong ? "</strong>" : "") +
                            "</td>" +
                        "</tr>" +
                        "<tr id='" + hierarchy[i][1] + "Child' style='display:none'>" +
                            "<td style='width:20'></td>" +
                            "<td>";
        output +=               tranzonic_CreateHiearchy(hierarchy[i][2], false);
        output +=           "</td>" +                            
                        "</tr>" +
                        "<tr id='" + hierarchy[i][1] + "Items' style='display:none'>" +
                            "<td style='width:20'></td>" +
                            "<td>";
        output +=               tranzonic_CreateQuotedItems(hierarchy[i][3]);
        output +=           "</td>" +
                        "</tr>" +
                    "</table>";  
    }

    return output;
}

function tranzonic_CreateQuotedItems(items) {
 
    var output = "";
    
    for(var i = 0; i < items.length; i++)
    {
        output +=
                    "<table width='100%' cellpadding='0px' cellspacing='0px'>" +
                        "<tr onmouseover=\"this.className='rowHighlight'\" onmouseout=\"this.className='highLight'\" class=\"highLight\">" +
                            "<td width='120px' align='left' valign='top'>" +
                                "<div class='logItems'>";
                                
        if(items[i][2] == "Y")
        {
            output +=               "<a href='/StoreProduct/" + items[i][0] + ".aspx'>" + items[i][0] + "</a>";        
        }
        else
        {
            output +=               items[i][0];
        }                        
        
        output +=               "</div>" +
                            "</td>" +
                            "<td width='240px' align='left' valign='top'>" +
                                "<div class='logItems'>";
                          
        if(items[i][2] == "Y")
        {
            output +=               "<a href='/StoreProduct/" + items[i][0] + ".aspx'>" + items[i][3] + "</a>";        
        }
        else
        {
            output +=               items[i][3];
        }                                 
                                
        output +=               "</div>" +
                            "</td>" +
                            "<td width='70px' align='left' valign='middle'>" +
                                "<div align='middle'>" +
                                    "<input name='QTY" + items[i][0] + "' onkeypress='return AllowNumericOnly(event);' class='formFieldQty' Width='20px' Columns='3' />" +
                                    items[i][1] + 
                                "</div>" + 
                            "</td>" +
                        "</tr>" +
                    "</table>";
    }

    return output;
}
                                                                                                  
                                                                                                 
                                                                                                 
                                                                                                 
                                                                                                 
                                                                                                 
                                                                                                 
                                                                                                 
                                                                                                 
                                                                                                 
                                                                                                 
                                                                                                 
                                                                                                 
                                                                                                 
                                                                                                 
                                                                             
