var g_arrayPicDetails;
var g_strPathRoot;

function AddTableRows(nTableId, strRowText) 
{
    //expects string of text in form cell text|cell text|cell text
    var objTable = document.getElementById(nTableId);
    if (objTable) 
        {
        var arrayRowText = strRowText.split("|");
        for (nIndex = 0; nIndex < arrayRowText.length; nIndex++) 
            {
            objRow = objTable.insertRow(-1);
            objCell = objRow.insertCell(-1);
            objCell.innerHTML = arrayRowText[nIndex];
            }
        }
}

function SetPictureArrays(strDetails, strPathRoot) 
{
    //expects string of text in form url~name|url~name
    var arrayPics = strDetails.split("|");
    g_strPathRoot = strPathRoot;
    g_arrayPicDetails = new Array(arrayPics.length);
    for (nIndex = 0; nIndex < arrayPics.length; nIndex++) 
        {
        g_arrayPicDetails[nIndex] = arrayPics[nIndex];
        }
}

function UpdatePicture() 
{
    //assumes file name of form DYCS01_kWh.png
    var strThisPic;
    var objUtility = document.getElementById("UtilityOptions");
    var objPeriod = document.getElementById("PeriodOptions");
    var objType = document.getElementById("TypeOptions");
    var strFileSearch = objPeriod.options[objPeriod.selectedIndex].value;
    strFileSearch += "CS";
    strFileSearch += objUtility.options[objUtility.selectedIndex].value;
    strFileSearch += "_";
    strFileSearch += objType.options[objType.selectedIndex].value;
    strFileSearch += ".png";
    for (nIndex = 0; nIndex < g_arrayPicDetails.length; nIndex++) 
        {
        strThisPic = g_arrayPicDetails[nIndex];
        if (0 == strThisPic.indexOf(strFileSearch)) 
            {
            var objImage = document.getElementById("ImagePreview");
            var objImageText = document.getElementById("ImagePreviewText");
            var objImageLink = document.getElementById("LargeImageLink");
            var arrayDetails = strThisPic.split("~");
            objImage.src = g_strPathRoot + arrayDetails[0];
            objImageLink.href = objImage.src;
            objImageText.innerHTML = arrayDetails[1];
            }
        }
}
