﻿//*****************


function parseCatalog(objFeed, selected, passedPageID)
{
    var outputHTML = "";
    var savedOutputHTML = "";
    var strSelected = false;
    
    try
    {
        if (selected)
        {
            strSelected = "true";
            Debug("in parseCatalog",1);
        }

        if (!passedPageID)
        {
            passedPageID = glGet("glPGID");
        }

        if (objFeed.getAttribute("name") == null)
        {
            
            outputHTML += "<ul selected=\"true\" id=\"PG" + passedPageID + "\" title=\"Guide\">";
        }
        else
        {
            outputHTML += "<ul selected=\"" + strSelected +"\" ";
            if (isNaN(passedPageID))  //Conserve a text NetStationID
            {
                outputHTML += "id=\"" + passedPageID + "\" ";
            }
            else
            {
                outputHTML += "id=\"PG" + passedPageID + "\" ";
            }
            outputHTML += "name=\"" + escape(objFeed.getAttribute("name")) + "\" ";
            
            if (objFeed.getAttribute("title"))
            {
                outputHTML += " title=\"" + objFeed.getAttribute("title") + "\">";
            }
            else
            {
                outputHTML += " title=\"" + objFeed.getAttribute("name") + "\">";
            }
        }
        
        //Debug(objFeed.getAttribute("name"),1);

        for (var x=0; x< objFeed.childNodes.length; x++)
        {
            var strNetStationID="";
            var infoURL="";
            var strDescription="";
            var strLinkURL="";
            var strAdImageURL="";
            var strAdLinkURL="";
            var strAdPageURL="";
            var strLinkName="";
            var strLinkImage="";
            var strADID="";
            var adHeight="43"; //the basic size of an ad
            var adWidth="320";  //the basic size of an ad
            if (objFeed.childNodes[x].getAttribute("id") != "null")
            {
                if (objFeed.childNodes[x].getAttribute("id") != null)
                {
                    strNetStationID = objFeed.childNodes[x].getAttribute("id");
                }
            }
            if ((objFeed.childNodes[x].getAttribute("info") != "null")&&(objFeed.childNodes[x].getAttribute("info") != null))
            {
                infoURL = objFeed.childNodes[x].getAttribute("info");
            }
            if (objFeed.childNodes[x].getAttribute("description"));
            {
                if (objFeed.childNodes[x].getAttribute("description") != null)
                {
                    strDescription = objFeed.childNodes[x].getAttribute("description");
                }
            }
            if (objFeed.childNodes[x].getAttribute("url") != "null")
            {
                if (objFeed.childNodes[x].getAttribute("url") != null)
                {
                    strLinkURL = objFeed.childNodes[x].getAttribute("url");
                }
            }
            if (objFeed.childNodes[x].getAttribute("adimg"));
            {
                if (objFeed.childNodes[x].getAttribute("adimg") != null)
                {
                     if (objFeed.childNodes[x].getAttribute("height") != null)
                     {
                        adHeight = objFeed.childNodes[x].getAttribute("height");
                     }
                    strAdImageURL = objFeed.childNodes[x].getAttribute("adimg");
                }
            }
            if (objFeed.childNodes[x].getAttribute("adurl"));
            {
                if (objFeed.childNodes[x].getAttribute("adurl") != null)
                {
                    strAdLinkURL = objFeed.childNodes[x].getAttribute("adurl");
                    strLinkURL = strAdLinkURL;
                }
            }
            if (objFeed.childNodes[x].getAttribute("adpage"));
            {
                if (objFeed.childNodes[x].getAttribute("adpage") != null)
                {
                     if (objFeed.childNodes[x].getAttribute("height") != null)
                     {
                        adHeight = objFeed.childNodes[x].getAttribute("height");
                     }
                     if (objFeed.childNodes[x].getAttribute("width") != null)
                     {
                        adWidth = objFeed.childNodes[x].getAttribute("width");
                     }
                    strAdPageURL = objFeed.childNodes[x].getAttribute("adpage");
                }
            }
            if (objFeed.childNodes[x].getAttribute("url"));
            {
                if (objFeed.childNodes[x].getAttribute("url") != null)
                {
                    strAdLinkURL = objFeed.childNodes[x].getAttribute("url");
                    strLinkURL = strAdLinkURL;
                }
            }
            if (objFeed.childNodes[x].getAttribute("name"));
            {
                if (objFeed.childNodes[x].getAttribute("name") != null)
                {
                    strLinkName = objFeed.childNodes[x].getAttribute("name");
                }
            }
            if (objFeed.childNodes[x].getAttribute("img"));
            {
                if (objFeed.childNodes[x].getAttribute("img") != null)
                {
                    strLinkImage = objFeed.childNodes[x].getAttribute("img");
                }
            }

            if (objFeed.childNodes[x].getAttribute("adid"));
            {
                if (objFeed.childNodes[x].getAttribute("adid") != null)
                {
                    strADID = objFeed.childNodes[x].getAttribute("adid");
                }
            }
            glSet("glPGID",glGet("glPGID")+1)
            glSet("glLKID",glGet("glLKID")+1)
            if (strAdImageURL != "")
            {
                //show the advertisement entry

                if ((strAdLinkURL != "")&&(strAdImageURL != ""))
                {
                    outputHTML += "<li style=\"background:none; background-image:none !important; padding:0px; border-top:0px !important; border-bottom:0px !important; text-align:center; width:100%;\">";
                    outputHTML += "<center><img class=\"base\" style=\"cursor:pointer;\" src=\"" + strAdImageURL + "\" ";
                    outputHTML += "onclick=\"glSet('glWebToolbarState',1); glRootWindow.glWebURL= '" + strAdLinkURL + "'; glRootWindow.glType='webpage'; glRootWindow.glPlayer='internal'; glRootWindow.loadMode(1);\" ";
                    outputHTML += "/></center>";
                }
                else
                {
                    outputHTML += "<li style=\"background-image:none !important; cursor:pointer !important; background-repeat: no-repeat; background-image: url(" + strAdImageURL + ") !important; padding:0px; border-top:0px !important; border-bottom:0px !important; text-align:center; width:100%; height:" + adHeight + "px;\">";
                    outputHTML += "<center>";
                    if (objFeed.childNodes[x].childNodes.length > 0)
                    {
                        outputHTML += "<a class=\"noselect\"style=\"background:none; [selected]\" class=\"link\" id=\"LK" + glGet("glLKID") + "\" ";
                        if ((strNetStationID != "")&&(isNaN(strNetStationID)))
                        {
                            outputHTML += " href=\"#" + strNetStationID + "\" parentid=\"" + passedPageID + "\" ";
                        }
                        else
                        {
                            outputHTML += " href=\"#PG" + glGet("glPGID") + "\" parentid=\"" + passedPageID + "\" ";
                        }
                        outputHTML += "><img class=\"base\" style=\"cursor:pointer;\"  src=\"" + strAdImageURL + "\" height=\"" + adHeight + "\"  /></a>";
                    }
                    else
                    {
                        if (strNetStationID != "")
                        {
                            outputHTML += "<a class=\"noselect\"style=\"background:none; [selected]\" class=\"link\" id=\"LK" + glGet("glLKID") + "\" ";
                            outputHTML += " href=\"#" + strNetStationID + "\" parentid=\"" + passedPageID + "\" ";
                            if (strNetStationID != "")
                            {
                                outputHTML += "nsid=\"" + strNetStationID + "\" ";
                            }
                            outputHTML += "><img class=\"base\" style=\"cursor:pointer;\" src=\"" + strAdImageURL + "\" height=\"" + adHeight + "\"  /></a>";
                        }
                        else
                        {
                            outputHTML += "<img class=\"base\" style=\"cursor:pointer;\" src=\"" + strAdImageURL + "\" height=\"" + adHeight + "\"  />";
                        }
                    }
                    outputHTML += "</center>";
                }

                outputHTML += "</li>";
            }
            else
            {
                if (strAdPageURL != "")
                {
                    if (glGet("glVersionNumber") != "1.3" && glGet("glVersionNumber") != "1.2" && glGet("glVersionNumber") != "1.1" && glGet("glVersionNumber") != "1.0" && glGet("glVersionNumber") != "1")
                    {
                        //if (adHeight == 50) { adHeight=60; }
                        if (passedPageID == 0)
                        {
                            //this page is on the root -- open immediately
                            //outputHTML += "<button onclick='alert(1); alert(parentSandboxBridge.testREMOTE()); alert(2);'>Test</button>";
                            var tempFMID="FM" + glGet("glLKID");
                            outputHTML += "<iframe name=\""+ tempFMID +"\" id=\"" + tempFMID +"\" width=\"" + adWidth  + "\" height=\"" + adHeight + "\" src=\"" + strAdPageURL + "\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" frameborder=\"0\" onload=\"document.getElementById('" + tempFMID + "').contentWindow.parentSandboxBridge = parentSandboxBridge;\"></iframe>";
                        }
                        else
                        {
                        
                            outputHTML += "<li style=\"background:none; background-image:none !important; padding:0px; border-top:0px !important; border-bottom:0px !important; text-align:center; width:100%;\">";
                            //these frames are now built and loaded on view, not on load
                            //outputHTML += "<iframe width=\"" + adWidth  + "\" height=\"" + adHeight + "\" src=\"" + strAdPageURL + "\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" frameborder=\"0\" ></iframe>";
                            outputHTML += "<IFRAME_PLACEHOLDER parentid=\"PG" + passedPageID + "\" id=\"FM" + glGet("glLKID") + "\" width=\"" + adWidth  + "\" height=\"" + adHeight + "\" src=\"" + strAdPageURL + "\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" frameborder=\"0\" ></IFRAME_PLACEHOLDER>";
                            outputHTML += "</li>";
                        }
                    }
                }
                else
                {
                    outputHTML += "<li>";
                    outputHTML += "<a class=\"link\" id=\"LK" + glGet("glLKID") + "\" ";
                    if (infoURL != "")
                    { 
                        outputHTML += " style=\"background-image:none !important;\" ";
                    }
                    
                    //Conserve a text NetStationID, but automatically generate IDs for numeric NetStationIDs
                    if ((strNetStationID != "")&&(isNaN(strNetStationID)))
                    {
                        outputHTML += " href=\"#" + strNetStationID + "\" parentid=\"" + passedPageID + "\" ";
                    }
                    else
                    {
                        outputHTML += " href=\"#PG" + glGet("glPGID") + "\" parentid=\"" + passedPageID + "\" ";
                    }
                    
                    if (strLinkImage != "")
                    {   
                        outputHTML += "img=\"" + strLinkImage + "\" ";
                    }
                    
                    if (strLinkName != "")
                    {   
                        outputHTML += "name=\"" + strLinkName + "\" ";
                    }

                    if (strLinkURL != "")
                    {   
                        outputHTML += "lnkurl=\"" + strLinkURL + "\" ";
                    }
                    
                    if (strNetStationID != "")
                    {
                        outputHTML += "nsid=\"" + strNetStationID + "\" ";
                    }
                    
                    if (strADID != "")
                    {
                        outputHTML += "adid=\"" + strADID + "\" ";
                    }
                    
                    outputHTML += ">" +  objFeed.childNodes[x].getAttribute("name") + "</a>";
                    if (strDescription != "")
                    {
                        outputHTML += "<div class=\"description\">" + strDescription + "</div>";
                    }
                    if (infoURL != "")
                    {
                        outputHTML += "<img class=\"infoIcon\" class=\"base\" src=\"style/info.png\" onclick=\"glSet('glWebToolbarState',1); glRootWindow.glWebURL= '" + infoURL + "&UID=' +  glGet('glUserID'); glRootWindow.glType='webpage'; glRootWindow.glPlayer='internal'; glRootWindow.loadMode(1);\" style=\"position:absolute; top:3px; right:5px; cursor:pointer;\" />";
                    }
                    outputHTML += "</li>";
                }
            }

            
            if ((objFeed.childNodes[x].childNodes.length > 0)&&(objFeed.childNodes[x].nodeName == "DIR"))
            {
                if (objFeed.childNodes[x].name != "undefined")
                {
                    //Debug(objFeed.childNodes[x].name,1);
                    savedOutputHTML += parseCatalog(objFeed.childNodes[x],false, glGet("glPGID"));
                }
            }
        }

        outputHTML += "</ul>";
    }
    catch(e)
    { Debug("error in parseCatalog:" + e.description); }
   
    return outputHTML + savedOutputHTML;

    //Debug("parsing catalog complete",1);

}

//************

function parseFavorites(objFeed, selected, passedPageID)
{
    var outputHTML = "";
    var savedOutputHTML = "";
    var strSelected = "false";
    
    Debug("in parseFavorites",1);
    
    if (selected)
    {
        strSelected = "true";
    }


    if (!passedPageID)
    {
        if (passedPageID != 0)
        {
            passedPageID = glGet("glPGID");
        }
    }
    
    try
    {
        Debug("parsing favorites",1);
        
        outputHTML += "<ul selected=\"" + strSelected + "\" ";
        outputHTML += "id=\"PG" + passedPageID + "\" ";
        outputHTML += "name=\"" + escape(objFeed.getAttribute("name")) + "\" ";
        
        if (objFeed.getAttribute("title"))
        {
            outputHTML += " title=\"" + objFeed.getAttribute("title") + "\">";
        }
        else
        {
            outputHTML += " title=\"" + objFeed.getAttribute("name") + "\">";
        }
            
        Debug(objFeed.getAttribute("name"),1);
        
        for (var x=0; x< objFeed.childNodes.length; x++)
        {
            var infoURL = "";
            var strDescription = "";
            var strNetStationID = "";
            var strLinkURL = "";
            var strAdImageURL="";
            var strAdLinkURL="";
            var strAdPageURL="";
            var strLinkName="";
            var strLinkImage="";
            var strADID="";
            var adHeight="43"; //the basic size of an ad
            var adWidth="320";  //the basic size of an ad
            
            if (objFeed.childNodes[x].getAttribute("id") != "null")
            {
                if (objFeed.childNodes[x].getAttribute("id") != null)
                {
                    strNetStationID = objFeed.childNodes[x].getAttribute("id");
                }
            }
            if ((objFeed.childNodes[x].getAttribute("info") != "null")&&(objFeed.childNodes[x].getAttribute("info") != null))
            {
                infoURL = objFeed.childNodes[x].getAttribute("info");
            }
            if (objFeed.childNodes[x].getAttribute("description"));
            {
                if (objFeed.childNodes[x].getAttribute("description") != null)
                {
                    strDescription = objFeed.childNodes[x].getAttribute("description");
                }
            }
            if (objFeed.childNodes[x].getAttribute("url") != "null")
            {
                if (objFeed.childNodes[x].getAttribute("url") != null)
                {
                    strLinkURL = objFeed.childNodes[x].getAttribute("url");
                }
            }
            if (objFeed.childNodes[x].getAttribute("adpage"));
            {
                if (objFeed.childNodes[x].getAttribute("adpage") != null)
                {
                     if (objFeed.childNodes[x].getAttribute("height") != null)
                     {
                        adHeight = objFeed.childNodes[x].getAttribute("height");
                     }
                     if (objFeed.childNodes[x].getAttribute("width") != null)
                     {
                        adWidth = objFeed.childNodes[x].getAttribute("width");
                     }
                    strAdPageURL = objFeed.childNodes[x].getAttribute("adpage");
                }
            }
            if (objFeed.childNodes[x].getAttribute("adimg"));
            {
                if (objFeed.childNodes[x].getAttribute("adimg") != null)
                {
                    strAdImageURL = objFeed.childNodes[x].getAttribute("adimg");
                }
            }
            if (objFeed.childNodes[x].getAttribute("adurl"));
            {
                if (objFeed.childNodes[x].getAttribute("adurl") != null)
                {
                    strAdLinkURL = objFeed.childNodes[x].getAttribute("adurl");
                }
            }
            if (objFeed.childNodes[x].getAttribute("name"));
            {
                if (objFeed.childNodes[x].getAttribute("name") != null)
                {
                    strLinkName = objFeed.childNodes[x].getAttribute("name");
                }
            }
            if (objFeed.childNodes[x].getAttribute("img"));
            {
                if (objFeed.childNodes[x].getAttribute("img") != null)
                {
                    strLinkImage = objFeed.childNodes[x].getAttribute("img");
                }
            }

            glSet("glPGID",glGet("glPGID")+1)
            glSet("glLKID",glGet("glLKID")+1)

            if (strAdImageURL != "")
            {
                if ((strAdLinkURL != "")&&(strAdImageURL != ""))
                {
                    outputHTML += "<li style=\"background:none; background-image:none !important; padding:0px; border-top:0px !important; border-bottom:0px !important; text-align:center; width:100%;\">";
                    outputHTML += "<center><img class=\"base\" style=\"cursor:pointer;\" src=\"" + strAdImageURL + "\" ";
                    outputHTML += "onclick=\"glSet('glWebToolbarState',1); glRootWindow.glWebURL= '" + strAdLinkURL + "'; glRootWindow.glType='webpage'; glRootWindow.glPlayer='internal'; glRootWindow.loadMode(1);\" ";
                    outputHTML += "/></center>";
                }
                else
                {
                    outputHTML += "<li style=\"background-image:none !important; cursor:pointer !important; background-repeat: no-repeat; background-image: url(" + strAdImageURL + ") !important; padding:0px; border-top:0px !important; border-bottom:0px !important; text-align:center; width:100%; height:" + adHeight + "px;\">";
                    outputHTML += "<center>";
                    if (objFeed.childNodes[x].childNodes.length > 0)
                    {
                        outputHTML += "<a class=\"noselect\"style=\"background:none; [selected]\" class=\"link\" id=\"LK" + glGet("glLKID") + "\" ";
                        if ((strNetStationID != "")&&(isNaN(strNetStationID)))
                        {
                            outputHTML += " href=\"#" + strNetStationID + "\" parentid=\"" + passedPageID + "\" ";
                        }
                        else
                        {
                            outputHTML += " href=\"#PG" + glGet("glPGID") + "\" parentid=\"" + passedPageID + "\" ";
                        }
                        outputHTML += "><img class=\"base\" style=\"cursor:pointer;\"  src=\"" + strAdImageURL + "\" height=\"" + adHeight + "\"  /></a>";
                    }
                    else
                    {
                        if (strNetStationID != "")
                        {
                            outputHTML += "<a class=\"noselect\"style=\"background:none; [selected]\" class=\"link\" id=\"LK" + glGet("glLKID") + "\" ";
                            outputHTML += " href=\"#" + strNetStationID + "\" parentid=\"" + passedPageID + "\" ";
                            if (strNetStationID != "")
                            {
                                outputHTML += "nsid=\"" + strNetStationID + "\" ";
                            }
                            outputHTML += "><img class=\"base\" style=\"cursor:pointer;\" src=\"" + strAdImageURL + "\" height=\"" + adHeight + "\"  /></a>";
                        }
                        else
                        {
                            outputHTML += "<img class=\"base\" style=\"cursor:pointer;\" src=\"" + strAdImageURL + "\" height=\"" + adHeight + "\"  />";
                        }
                    }
                    outputHTML += "</center>";
                }

                outputHTML += "</li>";
            }
            else
            {
                if (strAdPageURL != "")
                {
                    if (glGet("glVersionNumber") != "1.3" && glGet("glVersionNumber") != "1.2" && glGet("glVersionNumber") != "1.1" && glGet("glVersionNumber") != "1.0" && glGet("glVersionNumber") != "1")
                    {
                        //if (adHeight == 50) { adHeight=60; }
                        if (passedPageID == 0)
                        {
                            //this page is on the root -- open immediately
                            //outputHTML += "<button onclick='alert(1); alert(parentSandboxBridge.testREMOTE()); alert(2);'>Test</button>";
                            var tempFMID="FM" + glGet("glLKID");
                            outputHTML += "<iframe name=\""+ tempFMID +"\" id=\"" + tempFMID +"\" width=\"" + adWidth  + "\" height=\"" + adHeight + "\" src=\"" + strAdPageURL + "\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" frameborder=\"0\" onload=\"document.getElementById('" + tempFMID + "').contentWindow.parentSandboxBridge = parentSandboxBridge;\"></iframe>";
                        }
                        else
                        {
                        
                            outputHTML += "<li style=\"background:none; background-image:none !important; padding:0px; border-top:0px !important; border-bottom:0px !important; text-align:center; width:100%;\">";
                            //these frames are now built and loaded on view, not on load
                            //outputHTML += "<iframe width=\"" + adWidth  + "\" height=\"" + adHeight + "\" src=\"" + strAdPageURL + "\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" frameborder=\"0\" ></iframe>";
                            outputHTML += "<IFRAME_PLACEHOLDER parentid=\"PG" + passedPageID + "\" id=\"FM" + glGet("glLKID") + "\" width=\"" + adWidth  + "\" height=\"" + adHeight + "\" src=\"" + strAdPageURL + "\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" frameborder=\"0\" ></IFRAME_PLACEHOLDER>";
                            outputHTML += "</li>";
                        }
                    }
                }
                else
                {
                
                    if ((objFeed.childNodes[x].nodeName == "NOD")&&(strAdLinkURL == "")&&(strNetStationID=="")&&(strLinkURL==""))
                    {
                        //text headings
                        outputHTML += "<li style=\"background:none; background-image:none !important; \">";
                        outputHTML += "<span class=\"link\" style=\"background:none; background-image:none !important; margin: -8px 0 -8px -10px; padding: 8px 32px 8px 10px; cursor:default;\" ";
                        outputHTML += ">" +  objFeed.childNodes[x].getAttribute("name") + "</span>";
                        if (strDescription != "")
                        {
                            outputHTML += "<div class=\"description\">" + strDescription + "</div>";
                        }
                    }
                    else
                    {
                        outputHTML += "<li id=\"item" + glGet("glLKID") + "\">";
                        outputHTML += "<a class=\"link\" id=\"LK" + glGet("glLKID") + "\" ";
                    
                        //Conserve a text NetStationID, but automatically generate IDs for numeric NetStationIDs
                        if ((strNetStationID != "")&&(isNaN(strNetStationID)))
                        {
                            outputHTML += " href=\"#" + strNetStationID + "\" parentid=\"" + passedPageID + "\" ";
                        }
                        else
                        {
                            outputHTML += " href=\"#PG" + glGet("glPGID") + "\" parentid=\"" + passedPageID + "\" ";
                        }
                        
                        if (strLinkURL != "")
                        {   
                            outputHTML += "lnkurl=\"" + strLinkURL + "\" ";
                        }
                        
                        if (strNetStationID != "")
                        {
                            outputHTML += "nsid=\"" + strNetStationID + "\" ";
                        }
                    
                        if (strLinkImage != "")
                        {   
                            outputHTML += "img=\"" + strLinkImage + "\" ";
                        }
                        
                        if (strLinkName != "")
                        {   
                            outputHTML += "name=\"" + strLinkName + "\" ";
                        }
                       
                        outputHTML += ">" +  objFeed.childNodes[x].getAttribute("name") + "</a>";
                        if (strDescription != "")
                        {
                            outputHTML += "<div class=\"description\">" + strDescription + "</div>";
                        }
                        if (infoURL != "")
                        {
                            try
                            {
                                if (glGet("glPlatformName").toUpperCase() != "ANDROID")
                                {
                                    if (infoURL.indexOf("?") == -1)
                                    {
                                        infoURL = infoURL + "?1=1"; //make sure this isn't the first querystring entry
                                    }
                                    outputHTML += "<img class=\"infoIcon\" class=\"base\" src=\"style/info.png\" onclick=\"glSet('glWebToolbarState',1); glRootWindow.glWebURL= '" + infoURL + "&UID=' +  glGet('glUserID'); glRootWindow.glType='webpage'; glRootWindow.glPlayer='internal'; glRootWindow.loadMode(1);\" style=\"position:absolute; top:3px; left:272px; cursor:pointer;\" />";
                                }
                            }
                            catch(e){}
                        }
                    
                    }

                    if ((objFeed.childNodes[x].nodeName == "NOD")&&((strAdLinkURL != "")||(strNetStationID!="")||(strLinkURL!="")))
                    {
                        //parse in the delete icons
                        if (strNetStationID)
                        {
                            //Debug(strNetStationID);
                            outputHTML += "<img class=\"deleteMarker\" style=\"position:absolute; top:5px; left:15px; display:none; \" src=\"/app/html/style/delete1.png\" id=\"dmrk" + glGet("glLKID") + "\" onclick=\"markFavoriteToDelete('" + glGet("glLKID") + "','" + strNetStationID + "');\" />";
                            outputHTML += "<a class=\"button redButton deleteButton\" style=\"position:absolute; top:5px; right:15px; display:none; \" id=\"del" + glGet("glLKID") + "\" onclick=\"document.getElementById('item" + glGet("glLKID") + "').style.display='none'; deleteMarkedFavorite('" + strNetStationID + "');\" >Delete</a>";
                        }
                        else
                        {

                            //Debug(escape(objFeed.childNodes[x].getAttribute("name")));
                            outputHTML += "<img class=\"deleteMarker\" style=\"position:absolute; top:5px; left:15px; display:none; \" src=\"/app/html/style/delete1.png\" id=\"dmrk" + glGet("glLKID") + "\" onclick=\"markFavoriteToDelete('" + glGet("glLKID") + "','" + escape(objFeed.childNodes[x].getAttribute("name")) + "');\" />";
                            outputHTML += "<a class=\"button redButton deleteButton\" style=\"position:absolute; top:5px; right:15px; display:none; \" id=\"del" + glGet("glLKID") + "\" onclick=\"document.getElementById('item" + glGet("glLKID") + "').style.display='none'; deleteMarkedFavorite('" + escape(objFeed.childNodes[x].getAttribute("name")) + "','TITLE');\" >Delete</a>";
                        }
                    }
                    outputHTML += "</li>";
                }
            }

            if ((objFeed.childNodes[x].childNodes.length > 0)&&(objFeed.childNodes[x].nodeName == "DIR"))
            {
                if (objFeed.childNodes[x].name != "undefined")
                {
                    //Debug(objFeed.childNodes[x].name,1);
                    savedOutputHTML += parseFavorites(objFeed.childNodes[x],false,glGet("glPGID"));
                }
            }
        }

        outputHTML += "</ul>";
    }
    catch(e)
    { Debug("error in parseFavorites:" + e.description); }
   
    return outputHTML + savedOutputHTML;

}

//****************

function parseHistory(objFeed, selected,passedPageID)
{
    var outputHTML = "";
    var savedOutputHTML = "";
    var strSelected = "false";
    
    Debug("in parseHistory",1);
    
    if (selected)
    {
        strSelected = "true";
    }

    if (!passedPageID)
    {
        passedPageID = glGet("glPGID");
    }
    try
    {
        outputHTML += "<ul selected=\"" + strSelected + "\" ";
        outputHTML += "id=\"PG" + passedPageID + "\" ";
        outputHTML += "name=\"" + escape(objFeed.getAttribute("name")) + "\" ";
        
        if (objFeed.getAttribute("title"))
        {
            outputHTML += " title=\"" + objFeed.getAttribute("title") + "\">";
        }
        else
        {
            outputHTML += " title=\"" + objFeed.getAttribute("name") + "\">";
        }
            
        Debug(objFeed.getAttribute("name"),1);
        
        for (var x=0; x< objFeed.childNodes.length; x++)
        {
            var infoURL = "";
            var strDescription = "";
            var strNetStationID = "";
            var strLinkURL = "";
            if (objFeed.childNodes[x].getAttribute("id") != "null")
            {
                if (objFeed.childNodes[x].getAttribute("id") != null)
                {
                    strNetStationID = objFeed.childNodes[x].getAttribute("id");
                }
            }
//            if (objFeed.childNodes[x].getAttribute("info") != "null")
//            {
//                infoURL = objFeed.childNodes[x].getAttribute("info");
//            }
            if (objFeed.childNodes[x].getAttribute("description"));
            {
                if (objFeed.childNodes[x].getAttribute("description") != null)
                {
                    strDescription = objFeed.childNodes[x].getAttribute("description");
                }
            }
            if (objFeed.childNodes[x].getAttribute("url") != "null")
            {
                if (objFeed.childNodes[x].getAttribute("url") != null)
                {
                    strLinkURL = objFeed.childNodes[x].getAttribute("url");
                }
            }
             
            glSet("glPGID",glGet("glPGID")+1)
            glSet("glLKID",glGet("glLKID")+1)
            outputHTML += "<li>";
            outputHTML += "<a class=\"link\" id=\"LK" + glGet("glLKID") + "\"  parentid=\"" + passedPageID + "\" ";
            
            if (objFeed.childNodes[x].getAttribute("name").toUpperCase() == glMsgNoHistory[1])
            {
                outputHTML += "href=\"#PG" + glGet("glPGID") + "\" ";
            }
            else
            {
                //most history shouldn't link
                outputHTML += " style=\"background:none; background-image:none !important;\" href=\"#\" ";
            }
            
//            if (strLinkURL != "")
//            {   
//                outputHTML += "lnkurl=\"" + strLinkURL + "\" ";
//            }
            
//            if (strNetStationID != "")
//            {
//                outputHTML += "nsid=\"" + strNetStationID + "\" ";
//            }
            
            outputHTML += ">" +  objFeed.childNodes[x].getAttribute("name") + "</a>";
            if (strDescription != "")
            {
                outputHTML += "<div class=\"description\">" + strDescription + "</div>";
            }
            if (infoURL != "")
            {
                outputHTML += "<img class=\"infoIcon\" class=\"base\" src=\"style/info.png\" onclick=\"glSet('glWebToolbarState',1); glRootWindow.glWebURL= '" + infoURL + "&UID=' +  glGet('glUserID'); glRootWindow.glType='webpage'; glRootWindow.glPlayer='internal'; glRootWindow.loadMode(1);\" style=\"position:absolute; top:3px; left:272px; cursor:pointer;\" />";
            }
 
            outputHTML += "</li>";
            
            if ((objFeed.childNodes[x].childNodes.length > 0)&&(objFeed.childNodes[x].nodeName == "DIR"))
            {
                if (objFeed.childNodes[x].name != "undefined")
                {
                    //Debug(objFeed.childNodes[x].name,1);
                    savedOutputHTML += parseHistory(objFeed.childNodes[x],false,glGet("glPGID"));
                }
            }
        }

        outputHTML += "</ul>";
    }
    catch(e)
    {
        Debug("error in parseFavorites:" + e.description);
    }
   
    return outputHTML + savedOutputHTML;

    //Debug("parsing favorites complete",1);

}

//*********************

function parseSearchResults(objFeed, selected)
{
    var outputHTML = "";
    var savedOutputHTML = "";
    var strSelected = "false";
    
    Debug("parsing search results",1);
    
    if (selected)
    {
        strSelected = "true";
    }

    try
    {
        if (objFeed.getAttribute("title"))
        {
            outputHTML += "<ul selected=\"" + strSelected + "\" id=\"" + escape(objFeed.getAttribute("name")) + "\" title=\"" + objFeed.getAttribute("title") + "\">";
        }
        else
        {
            outputHTML += "<ul selected=\"" + strSelected + "\" id=\"" + escape(objFeed.getAttribute("name")) + "\" title=\"" + objFeed.getAttribute("name") + "\">";
        }
        
        Debug(objFeed.getAttribute("name"),1);
        
        for (var x=0; x< objFeed.childNodes.length; x++)
        {
            var infoURL = "";
            var strDescription = "";
            var strNetStationID = "";
            if (objFeed.childNodes[x].getAttribute("id") != "null")
            {
                if (objFeed.childNodes[x].getAttribute("id") != null)
                {
                    strNetStationID = objFeed.childNodes[x].getAttribute("id");
                }
            }
            if (objFeed.childNodes[x].getAttribute("info") != "null")
            {
                infoURL = objFeed.childNodes[x].getAttribute("info");
            }
            if (objFeed.childNodes[x].getAttribute("description"));
            {
                if (objFeed.childNodes[x].getAttribute("description") != null)
                {
                    strDescription = objFeed.childNodes[x].getAttribute("description");
                }
            }
          

            outputHTML += "<li><a ";
            if (objFeed.childNodes[x].getAttribute("name").toUpperCase() == "NO RESULTS FOUND")
            {
                outputHTML += " style=\"background:none;\" href=\"#\"";
            } 
            else
            {
                outputHTML += "id=\"linkto" + escape(objFeed.childNodes[x].getAttribute("name")) + "\" href=\"#" + escape(objFeed.childNodes[x].getAttribute("name")) + "\" ";
            }
            if (strNetStationID != "")
            {
                outputHTML += "nsid=\"" + strNetStationID + "\" ";
            }
            outputHTML += ">" +  objFeed.childNodes[x].getAttribute("name") + "</a>";
            if (strDescription != "")
            {
                outputHTML += "<div class=\"description\">" + strDescription + "</div>";
            }
            outputHTML += "</li>";
            
            if ((objFeed.childNodes[x].childNodes.length > 0)&&(objFeed.childNodes[x].nodeName == "DIR"))
            {
                if (objFeed.childNodes[x].name != "undefined")
                {
                    Debug(objFeed.childNodes[x].name,1);
                    savedOutputHTML += parseSearchResults(objFeed.childNodes[x],false);
                }
            }
        }
        outputHTML += "</ul>";
    }
    catch(e)
    {
        Debug("error in parseSearchResults:" + e.description);
    }
   
    return outputHTML + savedOutputHTML;

    //Debug("parsing favorites complete",1);

}

//****************

//function parsePodcast(objFeed)
//{
//    var outputHTML = "";
//    var savedOutputHTML = "";

//    try
//    {
////        Debug(escape(objFeed.getAttribute("name")));
////        Debug(escape(objFeed.getAttribute("title")));
//        if (objFeed.getAttribute("title"))
//        {
//            outputHTML += "<ul selected=\"true\" id=\"" + escape(objFeed.getAttribute("name")) + "\" title=\"" + objFeed.getAttribute("title") + "\">";
//        }
//        else
//        {
//            outputHTML += "<ul selected=\"true\" id=\"" + escape(objFeed.getAttribute("name")) + "\" title=\"" + objFeed.getAttribute("name") + "\">";
//        }
//        

//        
//        
//        for (var x=0; x< objFeed.childNodes.length; x++)
//        {
//            var infoURL = "";
//            var strDescription = "";
//            var strNetStationID = "";
//            if (objFeed.childNodes[x].getAttribute("id") != "null")
//            {
//                if (objFeed.childNodes[x].getAttribute("id") != null)
//                {
//                    strNetStationID = objFeed.childNodes[x].getAttribute("id");
//                }
//            }
//            if (objFeed.childNodes[x].getAttribute("info") != "null")
//            {
//                infoURL = objFeed.childNodes[x].getAttribute("info");
//            }
//            if (objFeed.childNodes[x].getAttribute("description"));
//            {
//                if (objFeed.childNodes[x].getAttribute("description") != null)
//                {
//                    strDescription = objFeed.childNodes[x].getAttribute("description");
//                }
//            }

//            outputHTML += "<li><a id=\"linkto" + escape(objFeed.childNodes[x].getAttribute("name")) + "\" href=\"#" + escape(objFeed.childNodes[x].getAttribute("name")) + "\" ";
//            if (strNetStationID != "")
//            {
//                outputHTML += "nsid=\"" + strNetStationID + "\" ";
//            }
//            outputHTML += ">" +  objFeed.childNodes[x].getAttribute("name") + "</a>";
//            if (strDescription != "")
//            {
//                outputHTML += "<div class=\"description\">" + strDescription + "</div>";
//            }
//            outputHTML += "</li>";
//            
//            if ((objFeed.childNodes[x].childNodes.length > 0)&&(objFeed.childNodes[x].nodeName == "DIR"))
//            {
//                if (objFeed.childNodes[x].name != "undefined")
//                {
//                    savedOutputHTML += parseCatalog(objFeed.childNodes[x],false);
//                }
//            }
//        }

//        outputHTML += "</ul>";
//    }
//    catch(e)
//    {
//        Debug("error in parsePodcast:" + e.description);
//    }
//   
//    return outputHTML + savedOutputHTML;

//}



///!!!! this may go away in favor of parseStationInformation since it would be faster
//function parseStation(objFeed)
//{
//    var outputHTML = "";
//    var savedOutputHTML = "";
//    var arrStationInformation = new Array();

//    try
//    {
//        var tempURL = "";
//        var tempSID = "";
//        var tempType = "";
//        var tempPlayer = "";
//        var tempName = "";
//        var tempDescription = "";
//        var tempFavorite = "";
//        
//        for (var x=0; x< objFeed.childNodes[0].attributes.length; x++)
//        {
//            //Debug(objFeed.childNodes[0].attributes[x].name + " -- " + objFeed.childNodes[0].attributes[x].value);
//            switch (objFeed.childNodes[0].attributes[x].name.toUpperCase())
//            {
//                case "URL":
//                    tempURL = objFeed.childNodes[0].attributes[x].value;
//                    arrStationInformation[0][x] = "URL";
//                    arrStationInformation[1][x] = tempURL;
//                break;   
//                case "SID":
//                    tempSID = objFeed.childNodes[0].attributes[x].value;
//                    arrStationInformation[0][x] = "SID";
//                    arrStationInformation[1][x] = tempSID;
//                break; 
//                case "TYPE":
//                    tempType = objFeed.childNodes[0].attributes[x].value;
//                    arrStationInformation[0][x] = "TYPE";
//                    arrStationInformation[1][x] = tempType;
//                break; 
//                case "PLAYER":
//                    tempPlayer = objFeed.childNodes[0].attributes[x].value;
//                    arrStationInformation[0][x] = "PLAYER";
//                    arrStationInformation[1][x] = tempPlayer;
//                break; 
//                case "NAME":
//                    tempName = objFeed.childNodes[0].attributes[x].value;
//                    arrStationInformation[0][x] = "NAME";
//                    arrStationInformation[1][x] = tempName;
//                break; 
//                case "DESCRIPTION":
//                    tempDescription = objFeed.childNodes[0].attributes[x].value;
//                    arrStationInformation[0][x] = "DESCRIPTION";
//                    arrStationInformation[1][x] = tempDescription;
//                break; 
//                case "FAVORITE":
//                    tempFavorite = objFeed.childNodes[0].attributes[x].value;
//                    arrStationInformation[0][x] = "FAVORITE";
//                    arrStationInformation[1][x] = tempFavorite;
//                break;              
//            }
//        }
//        return arrStationInformation;
//    }
//    catch(e)
//    {
//        Debug("error in parseStation:" + e.description);
//    }

//    //Debug("parsing catalog complete",1);

//}

//**************


///This function returns attributes based on the first NOD it finds
function parseStationInformation(objFeed, strName)
{
    try
    {
        //Debug("in parseStationInformation");
        var root = objFeed.getElementsByTagName('NOD')[0];
        for (var x=0; x< root.attributes.length; x++)
        {
            if (root.attributes[x].name.toUpperCase() == strName.toUpperCase())
            return root.attributes[x].value;
        }
        return "";
    }
    catch(e) 
    { 
        Debug("error in parseStationInformation: " + e.description); 
    }
}