
var iFrameVideoWidth = "317";
var iFrameVideoHeight = "273";
var newWindowVideoWidth = "323";
var newWindowVideoHeight = "278";
var embedPodtechWidth = "320";
var embedPodtechHeight = "269";
var newWindowPodtechWidth = "400";
var newWindowPodtechHeight = "350";

 function IT_buildFileTypeAndSize( record )
 {
     metaData = "";
     if (record.FileType.value != "" || record.FileSize.value != "")
     {
        metaData = "<span class='filesize'> (";

        if (record.FileType.value != "")
        {
            metaData += record.FileType.value;
        }

        if (record.FileSize.value != "" && metaData != "")
        {
            metaData += "&nbsp;";
        }
        metaData += record.FileSize.value + ") </span>";
     }
     
     return metaData;
 };
  
  /*
   *
   * Whitepaper HTML build functions
   *
   */
  function IT_whitepaperTitleAndDescEntry( record )
  {
      var returnValue;

      if(record.Title.value != "")
      {
          returnValue = "<ul><li><img src='/sites/sitewide/pix/icons/pdf_16.gif' alt='PDF' title='PDF' /><a href='" + record.URL.value + "' >" + record.Title.value + "</a>";

          returnValue += "  " + IT_buildFileTypeAndSize(record);

          if (record.Description.value.length > 0)
          {
              returnValue += "<p>";
              returnValue += record.Description.value; 
              returnValue += "</p></li></ul>";
          }
      }
      return returnValue;
  };
  
  function IT_whitepaperTitleOnlyEntry( record )
  {
      var returnValue;

      titleLabel = "";

      if(record.Title.value != "")
      {
          returnValue = "<p><a href='" + record.URL.value + "' target='whitepaper'>" + record.Title.value + "</a>";
          returnValue += " " + IT_buildFileTypeAndSize(record) + "</p>";
      }
      return returnValue;
  };
  
    /*
   *
   * Link to WEB page build functions
   *
   */
  function IT_htmlTitleAndDescEntry( record )
  {
      var returnValue;

      if(record.Title.value != "")
      {
          returnValue = "<ul><li><img src='/sites/sitewide/pix/icons/article_16.gif' alt='HTML' title='HTML' /><a href='" + record.URL.value + "' >" + record.Title.value + "</a>";

          returnValue += "  " + IT_buildFileTypeAndSize(record);

          if (record.Description.value.length > 0)
          {
              returnValue += "<p>";
              returnValue += record.Description.value; 
              returnValue += "</p></li></ul>";
          }
      }
      return returnValue;
  };
  
  function IT_htmlTitleOnlyEntry( record )
  {
      var returnValue;

      titleLabel = "";

      if(record.Title.value != "")
      {
          returnValue = "<p><a href='" + record.URL.value + "' target='whitepaper'>" + record.Title.value + "</a>";
          returnValue += " " + IT_buildFileTypeAndSize(record) + "</p>";
      }
      return returnValue;
  };
  
  /*
   *
   * Podtech HTML build functions
   *
   */
  
  /* parses the URL in the XML, and pulls out the flashvars so they are a part of the querystring */
  function buildPodtechPopupURL(url)
  {
    //get the URL
    var modifiedURL = url;
    
    var returnHtml = "src=";
    var flashvarsLocation = modifiedURL.search(/flashvars/);
    returnHtml += modifiedURL.substr(0,flashvarsLocation-1);
    
    //get the flashvars
    returnHtml += "&" + modifiedURL.substring(flashvarsLocation+11);
    return returnHtml.substr(0, returnHtml.length-1);
  }
  
  /* builds HTML to embed the podtech player with a title and description in the HTML */
  function IT_podtechEmbedPlayerDescEntry( record )
  {
      var returnValue = "";
      if (record.Description.value.length > 0)
       {
           returnValue += "<p>";
           returnValue += record.Description.value;  
           returnValue += "</p>";
       }
       
       var buildURL = record.URL.value.split(" ");
       var modifiedURL = buildURL[0] + "\" ";
       modifiedURL += buildURL[1];
       returnValue += "<embed type=\"application/x-shockwave-flash\" src=\"" + modifiedURL + " height=\"" + embedPodtechHeight + "\" width=\"" + embedPodtechWidth + "\" allowScriptAccess=\"always\" />";
       
       return returnValue;
  };
  
  /* builds HTML to display a link of the title and description. When the link is clicked, a new window with the podtech player pops up */
   function IT_podtechPopupTitleAndDescEntry( record )
  {      
	  var returnValue;
	
	  if(record.Title.value != "")
	  {
		  returnValue = "<ul><li><img src='/sites/sitewide/pix/icons/video_16.gif' alt='Video' title='Video'/><a href='javascript:void(0)' onclick='var vidWindow=window.open(\"/it/podcasts/podtech-popup.htm?" + buildPodtechPopupURL(record.URL.value) + "\", \"mpVideo\", \"height=" + newWindowPodtechHeight + ",width=" + newWindowPodtechWidth + "\").focus()'>" + record.Title.value + "</a>";
		
		  returnValue += " " + IT_buildFileTypeAndSize(record);
          if (record.Description.value.length > 0)
          {
              returnValue += "<br /><p>";
              returnValue += record.Description.value;  
              returnValue += "</p></li></ul>";
          }
	  }
	  return returnValue;
  };
  
  /* builds HTML to display a link of the title. When the link is clicked, a new window with the player will pop up */
  function IT_podtechTitleOnlyEntry( record )
  {
	  var returnValue;
	
	  if(record.Title.value != "")
	  {
		  returnValue = "<ul><li><img src='/sites/sitewide/pix/icons/video_16.gif' alt='video' title='video'/><a href='javascript:void(0)' onclick='var vidWindow=window.open(\"/it/podcasts/podtech-popup.htm?" + buildPodtechPopupURL(record.URL.value) + "\", \"mpVideo\", \"height=" + newWindowPodtechHeight + ",width=" + newWindowPodtechWidth + "\").focus()'>" + record.Title.value + "</a>";
		
		  returnValue += " " + IT_buildFileTypeAndSize(record);
      returnValue += "</li></ul>";
	  }
	  return returnValue;
  };
  

  /*
   *
   * Video HTML build functions
   *
   */
  
  /* parses the URL for the Feedrom story ID */
  function buildVideoPopupURL(link)
  {
    //get the URL
    var urlCopy = link;
    
    //Parse for story ID
    var re = /fr_story=([\d\w]+)/;
    var match = re.exec(urlCopy);
    //var storyID = match[0];
    return match[1];
  }
  
  /* builds HTML to display a link of the title and description. When the link is clicked, a new window with the podtech player pops up */
   function IT_videoPopupTitleAndDescEntry( record )
  {      
	  var returnValue;
	
	  if(record.Title.value != "")
	  {
		
		  returnValue = "<ul><li><img src='/sites/sitewide/pix/icons/video_16.gif' alt='video' title='video'/><a href='javascript:void(0)' onclick=\"window.open('http://video.intel.com/?skin=oneclip&fr_story=" + buildVideoPopupURL(record.URL.value) + "&rf=ev&autoplay=true', 'feedroom', 'width=317, height=273, scrollbars=0, resizable=1, status=no, toolbar=no, location=no');return false;\">" + record.Title.value + "</a>";

		  returnValue += " " + IT_buildFileTypeAndSize(record);
          if (record.Description.value.length > 0)
          {
              returnValue += "<br /><p>";
              returnValue += record.Description.value;  
              returnValue += "</p></li></ul>";
          }
	  }
	  return returnValue;
  };
  
  /* builds HTML to display a link of the title. When the link is clicked, a new window with the player will pop up */
  function IT_videoTitleOnlyEntry( record )
  {
	  var returnValue;
	
	  if(record.Title.value != "")
	  {
		  returnValue = "<ul><li><img src='/sites/sitewide/pix/icons/video_16.gif' alt='video' title='video'/><a href='javascript:void(0)' onclick=\"window.open('http://video.intel.com/?skin=oneclip&fr_story=" + buildVideoPopupURL(record.URL.value) + "&rf=ev&autoplay=true', 'video', 'width=317, height=273, scrollbars=0, resizable=1, status=no, toolbar=no, location=no');return false;\">" + record.Title.value + "</a>";
		
		  returnValue += " " + IT_buildFileTypeAndSize(record);
      returnValue += "</li></ul>";
	  }
	  return returnValue;
  };

  /* TODO: add an embed video method */
  
  /*
   *
   * webcast HTML build functions
   *
   */
   
  /* builds HTML to embed the webcast player with a title and description in the HTML */
  function IT_webcastEmbedPlayerDescEntry( record )
  {
      var returnValue = "";

      if (record.Description.value.length > 0)
       {
           returnValue += "<p>";
           returnValue += record.Description.value;  
           returnValue += "</p>";
       }
		returnValue += "<iframe align='left' src='" + record.URL.value + "' width='" + iFrameVideoWidth + "' height='" + iFrameVideoHeight + "' scrolling='no' frameborder='0' marginwidth='0' marginheight='0'></iframe>"
		returnValue += "<br /><br />";
     
      return returnValue;
  };
  
  /* builds HTML to display a link of the title and description. When the link is clicked, a new window with the webcast player pops up */
  function IT_webcastPopupTitleAndDescEntry( record )
  {
	  var returnValue;
	
	  if(record.Title.value != "")
	  {
		  returnValue = "<ul><li><img src='/sites/sitewide/pix/icons/video_16.gif' alt='video' title='video'/><a href='javascript:void(0)' onclick='var vidWindow=window.open(\"" + record.URL.value + "\", \"mpVideo\", \"height=" + newWindowVideoHeight + ",width=" + newWindowVideoWidth + "\").focus()'>" + record.Title.value + "</a>";
		
		  returnValue += " " + IT_buildFileTypeAndSize(record);
          if (record.Description.value.length > 0)
          {
              returnValue += "<br /><p>";
              returnValue += record.Description.value;  
              returnValue += "</p></li></ul>";
          }
	  }
	  return returnValue;
  };

  /* builds HTML to display a link of the title. When the link is clicked, a new window with the podtech player pops up */
  function IT_webcastTitleOnlyEntry( record )
  {
	  var returnValue;
	
	  if(record.Title.value != "")
	  {
		  returnValue = "<ul><li><img src='/sites/sitewide/pix/icons/video_16.gif' alt='video' title='video'/><a href='javascript:void(0)' onclick='var vidWindow=window.open(\"" + record.URL.value + "\", \"mpVideo\", \"height=" + newWindowVideoHeight + ",width=" + newWindowVideoWidth + "\").focus()'>" + record.Title.value + "</a>";
		
		  returnValue += " " + IT_buildFileTypeAndSize(record);
      returnValue += "</li></ul>";
	  }
	  return returnValue;
  };

  /*
   *
   * Build rules for the various HtmlTable objects
   *
   */  
  function titleOnlyBuildRule( record )
  {
    var returnHTML = "";
    switch (record.FileType.value.toLowerCase())
    {
        case "webcast": returnHTML = IT_webcastTitleOnlyEntry(record); break;
        case "podcast": returnHTML = IT_webcastTitleOnlyEntry(record); break;
        case "podtech": returnHTML = IT_podtechTitleOnlyEntry(record); break;
        case "video": returnHTML = IT_videoTitleOnlyEntry(record); break;
        case "html": returnHTML = IT_htmlTitleOnlyEntry(record); break;
        default: returnHTML = IT_whitepaperTitleOnlyEntry(record); break;
    };
    return returnHTML;
  };

  function titleAndDescBuildRule( record )
  {
      var returnHTML = "";
      switch (record.FileType.value.toLowerCase())
      {
        case "webcast": returnHTML = IT_webcastPopupTitleAndDescEntry( record ); break;
        case "podcast": returnHTML = IT_webcastPopupTitleAndDescEntry( record ); break;
        case "podtech": returnHTML = IT_podtechPopupTitleAndDescEntry( record ); break;
        case "video": returnHTML = IT_videoPopupTitleAndDescEntry( record ); break;
        case "html": returnHTML = IT_htmlTitleAndDescEntry( record ); break;
        default: returnHTML = IT_whitepaperTitleAndDescEntry(record); break;
      }; 
      
      return returnHTML;
  };

  function videoWhitePaperBuildRule( record )
  {
      var returnHTML = "";
      switch (record.FileType.value.toLowerCase())
      {
        case "webcast": returnHTML = IT_webcastEmbedPlayerDescEntry( record ); break;
        case "podcast": returnHTML = IT_webcastPopupTitleAndDescEntry( record ); break;
        case "podtech": returnHTML = IT_podtechEmbedPlayerDescEntry( record ); break;
        default: returnHTML = IT_whitepaperTitleAndDescEntry(record); break;
      }; 
      return returnHTML;
  };

  function topDownloadOrderBuildRule( record )
  {
    return "";
  };
