// JavaScript Document
  function getDownloadLink(feedPid, mediaId, assetTypes, tagId) {
   var head = document.getElementsByTagName("head")[0];
   var script = document.createElement("script");
   var feedUrl = "http://feed.theplatform.com/f/-/" + feedPid + "/" + mediaId + "?form=json" + "&byContent=byAssetTypes%3D" + escape(assetTypes.join("|")) + "&callback=gotDownloadLink" + "&context=" + tagId;
   script.src = feedUrl;
   script.type = "text/javascript";
   head.appendChild(script);
  }
  
  function gotDownloadLink(json, context) {
   var content;
   
   var tag = document.getElementById(context)
   
   if (json.media$content) {
    for(var i=0; i<json.media$content.length; i++) {
     content = json.media$content[i];
     if (content.plfile$url) {
      var link = document.createElement("a");
	  //link.target=blank;
      link.href = content.plfile$url;
      link.innerHTML = "Download " + content.plfile$format;
	  removeChildrenFromNode(tag);
      tag.appendChild(link);
      tag.appendChild(document.createElement("br"));
     }
    }
   }
  }   
  
  function removeChildrenFromNode(node)
{
	if(node.hasChildNodes())
	{
		while(node.childNodes.length >= 1 )
		{
			node.removeChild(node.firstChild);
		}
	}
}
  
//  getDownloadLink("D4SyonD74oWp", "1541068240", ["podcast", "wm 720p"], "jeremy");

 

