﻿var curPostCellId 

function setupPostingLists()
{

    $(".ContentGridPostings").each(function (index) {                   
       getPostingList($(this));             
    });
}


function getPostingList(tpList)
{


  cellid = $(tpList).attr("cellid");
  profileid = $(tpList).attr("profileid");
  postingmoduleid = $(tpList).attr("moduleid");
  curPostCellId = tpList;
  modToGet = moreCtlPath+"getPostingFeed.aspx?moduleid="+postingmoduleid+"&cellid="+cellid+"&profileid="+profileid+"&basePath="+moreDNNBasePath;
  
  $.ajax({
            type: "GET",
            async: false,
            url: modToGet,
            dataType: "xml",
            success: parsePostingListXml,            
            error: tposterror2,
            cache: false
       });   
}





function tposterror2(xreq,tstat,err)
{
    //alert(tstat);
}





function parsePostingListXml(xml)
{   
          header = $(curPostCellId).children(".ContentGridPostingHeader");
          $(header).html("Current Postings<br><img src=\"images/grid/greydot.png\" style=\"width:100%;height:1px;\">");
          postlist = $(curPostCellId).children("ul");          
          $(postlist).empty();
          
          feed = xml;
          $(xml).children("rss").children("channel").each(function() {           
            var channelTitle = $(this).children("title").text();                       
            if (channelTitle == "Posting Feed")
            {
            
              var itemiter = 1;
              //$(curPostCellId).empty();
               $(this).children("item").each(function() {
               
                 var tItems = parseInt($(curPostCellId).attr("maxItems"))                                  
                 if (itemiter <= tItems)
                 {
                   
                   var xmlItemId = $(this).children("itemid").text();
                   var xmlTitle = $(this).children("title").text();
                  // var xmlPostingDate = $(this).children("pubdate").text();
                   var xmlPostingDate = $(this).children("[nodeName=InceptionPoint.PostingFeed:PostingDateStr]").text();
                   
                   var xmlPostingLocation = $(this).children("[nodeName=InceptionPoint.PostingFeed:Location]").text();
                   var xmlItemModuleId = $(this).children("[nodeName=InceptionPoint.PostingFeed:ItemModuleId]").text();
                   var cellid = $(curPostCellId).attr("id")                   
                   var linkstub = "<a ";
                                     
                     linkstub += "profilerModuleId=\""+xmlItemModuleId+"\" profilerItemId=\""+xmlItemId+"\" postingitemid=\""+xmlItemId+"\" class=\"profileCollect postingPopupLink\">"
                   
                    var newli = "<li>";
                    newli += linkstub;                    
                    
                    newli += "<div class=\"PostingItemTitle\">"+xmlTitle+"</div>";
                    newli += "<div class=\"PostingItemDate\">"+xmlPostingDate+"</div>";
                    newli += "<span class=\"PostingItemLocation\">"+xmlPostingLocation+"</span>";                                        
                   
                    newli += "</li>";
                     newli +="</a>";
                    newli+="<img src=\"images/grid/greydot.png\" style=\"width:100%;height:1px;\">";
                   $(postlist).append(newli);
                   
                   
                 }
                   itemiter++;
               });
             var moreli = "<a class=\"postingListPopupLink\">more postings</a>"; 
             $(curPostCellId).append(moreli);  
            }
          });
          
          if (window.setupPostingPopupLinks)
            setupPostingPopupLinks();
}          
