﻿// JScript File

    var iconLocation = "/images/template/online-tools/product-adapter/appliance/";

    function clearStyles(strUL_ID)
    {    
        //Bug Fix since the first column does not use a UL.
        if (strUL_ID == "applianceColumn")
        {            
            for (x = 0; x < ApplianceTypes.length; x++)
            {
                var strTemp = ApplianceTypes[x].split(':');
                
                document.getElementById("appliance_" + strTemp[1]).className = "";
            }
        }
        else
        {
            var tagUL = document.getElementById(strUL_ID)

            tagLI = tagUL.firstChild;
            
            while (tagLI)
            {  
                tagA = tagLI.firstChild;
                tagA.className = "";
                tagLI = tagLI.nextSibling;
            }    
        }
    }
    
    
    function displayAppliances()
    {
        var strAppliances = "";
        var strImage = "";

        for (x = 0; x < ApplianceTypes.length; x++)
        {
            //Split Our Current Array Item
            var currentAppliance = ApplianceTypes[x].split(':');
            //Bug fix to use english naming for icons 
            var pngFile = currentAppliance[2].replaceAll(" ", "-") + '.png'; 

            //Create Appliances List
            strAppliances = strAppliances + '<div class="left-buttons">';
            strAppliances = strAppliances + '<a id="appliance_' + currentAppliance[1] + '" href="javascript: void(0);" onclick="showFuel(' + currentAppliance[1] + ');"><img src="' + iconLocation + pngFile.toLowerCase() + '"  />';
            strAppliances = strAppliances + '<br/>' + currentAppliance[0];
            strAppliances = strAppliances + '</a>';
            strAppliances = strAppliances + '</div>' + '\r\n';          
        }
                
        //Clear all other Columns        
        document.getElementById('fuelColumn').innerHTML = "&nbsp;";     
        document.getElementById('typeColumn').innerHTML = "&nbsp;";   
        document.getElementById('requiredColumn').innerHTML = "&nbsp;";

        //Populate the Appliance column with newly created HTML
        document.getElementById('applianceColumn').innerHTML = strAppliances;  
    }    
    
    function showFuel(parentApplianceID)
    {        
        var strFuel = "";
    
        //Get the Listing of Fuel Types for this Appliance
        var arrayFuelTypes = FuelTypes[parentApplianceID].split("|");
        
        for (x = 0; x < arrayFuelTypes.length; x++)
        {
            var arrayFuelItem = arrayFuelTypes[x].split(":");
            
            strFuel = strFuel + '<li><a id="fuel_' + arrayFuelItem[1] + '" href="javascript: void(0);" onclick="showType(' + arrayFuelItem[1] + ');">';
                        
            if (arrayFuelItem[2] == "Gas")
            {
                strFuel = strFuel + '<img align="absmiddle" src="/images/template/online-tools/product-adapter/fuels/gas.jpg" align="absmiddle" border="0" />&nbsp;';
            }
            else if(arrayFuelItem[2] == "Wood")
            {
                strFuel = strFuel + '<img align="absmiddle" src="/images/template/online-tools/product-adapter/fuels/wood.jpg" align="absmiddle" border="0" />&nbsp;';
            }
            else if(arrayFuelItem[2] == "Multi-Fuel")
            {
                strFuel = strFuel + '<img align="absmiddle" src="/images/template/online-tools/product-adapter/fuels/corn.jpg" align="absmiddle" border="0" />&nbsp;';
            }
            else if(arrayFuelItem[2] == "Coal")
            {
                strFuel = strFuel + '<img align="absmiddle" src="/images/template/online-tools/product-adapter/fuels/coal.jpg" align="absmiddle" border="0" />&nbsp;';
            }
            else if(arrayFuelItem[2] == "Oil")
            {
                strFuel = strFuel + '<img align="absmiddle" src="/images/template/online-tools/product-adapter/fuels/oil.jpg" align="absmiddle" border="0" />&nbsp;';
            }
            else if(arrayFuelItem[2] == "Pellet-Corn" || arrayFuelItem[0] == "Pellet")
            {
                strFuel = strFuel + '<img align="absmiddle" src="/images/template/online-tools/product-adapter/fuels/pellet.jpg" align="absmiddle" border="0" />&nbsp;';
            }
            else
            {
                strFuel = strFuel + '<img align="absmiddle" src="/images/template/online-tools/product-adapter/fuels/na.jpg" align="absmiddle" border="0" />&nbsp;';
            }
        
            strFuel = strFuel + arrayFuelItem[0] + '</a></li>'
        }
        
        
    
        document.getElementById('fuelColumn').innerHTML = strFuel;     
        document.getElementById('typeColumn').innerHTML = "&nbsp;";     
        document.getElementById('requiredColumn').innerHTML = "&nbsp;";

        clearStyles("applianceColumn");
       
        document.getElementById("appliance_" + parentApplianceID).className = "activeButton";
    }
    
    
    
    
    function showType(parentApplianceID)
    {      
            
        var strType = "";
        
        //Get the Listing of Fuel Types for this Appliance
        var arrayVentingTypes = VentingTypes[parentApplianceID].split("|");      
        
        for (x = 0; x < arrayVentingTypes.length; x++)
        {
            var arrayVentingItem = arrayVentingTypes[x].split(":");
            
            strType = strType + '<li><a id="type_' + arrayVentingItem[1] + '" href="javascript: void(0);" onclick="showContent(' + arrayVentingItem[1] + ');"><img src="/images/template/online-tools/product-adapter/bullet.png" align="absmiddle" border="0" />&nbsp;' + arrayVentingItem[0] + '</a></li>';
        }

        document.getElementById('typeColumn').innerHTML = strType;    
        document.getElementById('requiredColumn').innerHTML = "&nbsp;";    
        
        clearStyles("fuelColumn");
        
        document.getElementById("fuel_" + parentApplianceID).className = "activeButton";   
    }
    
    
    function showContent(parentApplianceID)
    {
        document.getElementById('requiredColumn').innerHTML = AdapterContent[parentApplianceID]; 
        
        clearStyles("typeColumn");
        
        document.getElementById("type_" + parentApplianceID).className = "activeButton";   

/*        
        for (x = 0; x < eval("Appliance_" + parentApplianceID + "_" + parentFuelID + "_Type.length"); x++)
        {           
            document.getElementById(eval("'type" + x + "'")).className = "";
        }
                
        document.getElementById(eval("'type" + parentTypeID + "'")).className = "activeButton";                   
*/
    }
    
    
// Replaces all instances of the given substring.
String.prototype.replaceAll = function(strTarget, strSubString)
{
    var strText = this;
    var intIndexOfMatch = strText.indexOf( strTarget );
    while (intIndexOfMatch != -1)
    {
        strText = strText.replace( strTarget, strSubString )
        intIndexOfMatch = strText.indexOf( strTarget );
    }
    
    return( strText );
}
    