// Templates Script v.1.0
// todd@mindsharp.com  www.MindsharpBlogs.com/Todd
// CopyRight © 2005, All Rights Reserved
// Last updated 8/1/2005
// Please don't delete this header

// Allow the user to choose from multiple MultipleTemplates when
// creating a new document in a WSS 2.0 document library
// The script replaces the "New Document" link on any 
// document library with a dropdown list that allows the
// user to choose from the six built-in document MultipleTemplates.
function templatesJumpToCreateDoc(value)
{
  try
  {
    var template = "";
    var url = ctx.displayFormUrl;
    if(url)
    {
      url = url.substring(0, url.indexOf("/Forms"));
      var saveLoc = makeAbsUrl(url);
    }
    var progID = "SharePoint.OpenDocuments";

    switch(value)
    {
    case 101: //Word
      template = saveLoc + "/Forms/template.doc";
      createNewDocumentWithProgID(template, saveLoc, progID, false);
      break;

    case 102: //Front Page
      template = saveLoc + "/Forms/template.htm"; 
      createNewDocumentWithProgID(template, saveLoc, progID, false);
      break;

    case 103: //Excel
      template = saveLoc + "/Forms/template.xls"; 
      createNewDocumentWithProgID(template, saveLoc, progID, false);
      break;

    case 104: //PowerPoint
      template = saveLoc + "/Forms/template.pot"; 
      createNewDocumentWithProgID(template, saveLoc, progID, false);
      break;

    case 105: //Basic Page
      window.location = ctx.HttpRoot + "/_layouts/1033/bpcf.aspx?"
      + "List=" + ctx.listName + "&RootFolder=" 
      + "&RootFolderUrl=" + saveLoc
      break;

    case 106: //Smart Page
      window.location = ctx.HttpRoot + "/_layouts/1033/spcf.aspx?"
      + "List=" + ctx.listName + "&RootFolder=" 
      + "&RootFolderUrl=" + saveLoc
      break;
    }
  }
  catch(e){if(Silence_Errors){window.onerror = function(){return true;}}else{alert(e.message)};}
}

// Allow the user to choose from multiple MultipleTemplates when
// creating a new document in a WSS 2.0 document library
// The script replaces the "New Document" link on any 
// document library with a dropdown list that allows the
// user to choose from the six built-in document MultipleTemplates.
function templatesCreateNewItemMenu()
{
  try
  {
    //Create a replacement anchor tag for the existing New Document link
    //Use the same class, id, accessKey, and tabIndex of the existing link
    //Hookup the custom menu to open (if not already open) when the user clicks
    //Put an image to the right and absolute bottom of the link
    //with rollovers similar to the Web Part menu so that it is obvious
    //to end users that something is different about this New Document link.
    //The NewDocumentMenu is found on the bottom of the Page_AllItems.js file
    var menuHTML = "<a accessKey=N alt='New Document Menu' class=ms-toolbar";
    menuHTML += "  id=diidNewItem style='cursor: hand' tabIndex=2 title='New Document Menu'";
    menuHTML += "  onclick='if (!NewDocumentMenu.isOpen()) NewDocumentMenu.show(this, true);'"
    menuHTML += "  >New Document";
    menuHTML += "  <img align='absBottom' alt='New Document Menu' border='0'";
    menuHTML += "    class='ms-HoverCellInActive'";
    menuHTML += "    src='/_layouts/images/menu1.gif' title='New Document Menu'";
    menuHTML += "    onmouseout=this.className='ms-HoverCellInActive'";
    menuHTML += "    onmouseover=this.className='ms-HoverCellActiveDark'";
    menuHTML += "  >"
    menuHTML += "</a>"

    //Locate the "New Document" link and replace it with the dropdown
    utilityReplaceLink("New Document", menuHTML, true);
  }
  catch(e){if(Silence_Errors){window.onerror = function(){return true;}}else{alert(e.message)};}
}