	/******************************************************************************
	 * Helper Functions for Creating Drop Down Lists
	 *****************************************************************************/
	   function E(ctlId) {
	      return document.getElementById(ctlId);
	   }
	 
	 
      function GetNewDdl(listItems, id, name, context, attributes)
      /******************************************************************************
       * Creates a new list containing the listItems passed in
       * Parameters:
       *    listItems    = HTML string of <option> items for list
       *    id           = (optional) DHTML ID of <select> control created
       *    name         = (optional) DHTML NAME of <select> control created
       *    context      = (optional) Context in which to create <input>
       *                   (ie: document, frame.contentWindow.document, opener.document)
       *    attributes   = (optional) HTML snippet to specify additional attributes
       *
       * Returns:
       *    list as a DHTML <select> control
       *****************************************************************************/
      {
         var txtOptions = listItems;
         var strContainerHtml;
      
         if (context == null || context == undefined)
         {
            context = document;
         }
      
         var container = context.createElement('div');
         var ddlCtl = context.createElement('select');
         container.appendChild(ddlCtl);
      
         strContainerHtml = container.innerHTML;
         var re = /(<select>.*)?(<\/select>)/i;
         strContainerHtml = strContainerHtml.replace(re, '$1' + txtOptions + '$2');
         container.innerHTML = strContainerHtml;
      
         ddlCtl = container.getElementsByTagName('select')[0];
         return ddlCtl;
      }
      
      
      function AddOptionsToDdl(ddlCtl, optionsHtml, clearFirst)
      /******************************************************************************
       * Adds new <option> items to a <select> drop down list.
       * Parameters:
       *    ddlCtl      = <select> drop down list to add items to
       *    optionsHtml = HTML string of <option>s to add
       *    clearFirst  = (boolean) If true, clears the ddlCtl items before adding new items
       *
       * Returns:
       *    void
       *****************************************************************************/
      {
         if (clearFirst)
         {
            ddlCtl.options.length = 0;
         }
      
         var ddlTempCtl = GetNewDdl(optionsHtml);
         var opt;
      
         for (var i = 0; i < ddlTempCtl.options.length; i++)
         {
            opt = document.createElement('option');
            ddlCtl.appendChild(opt);
      
            for (var j = 0; j < ddlTempCtl.options[i].attributes.length; j++)
            {
               opt.setAttribute(ddlTempCtl.options[i].attributes[j].nodeName, ddlTempCtl.options[i].attributes[j].nodeValue, 0);
            }
            opt.text = ddlTempCtl.options[i].text;
         }
      }
      
 
   	function CreateElementAsHTML (tagName, lstAttributes, context) 
    	/******************************************************************************
   	 * Creates a new element in the context specified with attributes
   	 * set as specified in the attributes list. 
   	 *
   	 * @method constructor
   	 * @param {String} tagName The tag name of the element to create.
   	 * @param {Object} lstAttributes A key-value map of Attribute properties.
   	 * @param {Document} context (Optional) Document object within which to create element.
   	 * @return {String} Element created as HTML.
   	 *****************************************************************************/   	   
   	{   	 
   		if (context == null || context == undefined)
   		{
   		   context = document;
   		   this.context = context;
   		}   
   		
   		if (tagName != null && tagName != undefined && 
   		    lstAttributes != null && lstAttributes != undefined) {
   		
   			var lstIgnoreAttrs = ["innerText", "text", "innerHTML", "outerHTML"];
   		   lstIgnoreAttrs.contains = function(itemToFind) {
   		      for (k = 0; k < this.length; k++) {
   		         if (itemToFind == this[k]) {
   		            return true;
   		         }
   		      }
   		      return false;
   		   }		
   			
   			// Build a string for the attributes
   			var sAttributes = " ";
   			var text = null;
   			for (var attr in lstAttributes) {
   			    if (! lstIgnoreAttrs.contains(attr)) {
   			       sAttributes += attr + "=\"" + lstAttributes[attr] + "\" ";
   			    } 
   			    if (attr == "text") {
   			      text = lstAttributes[attr];
   			    }
   			}
   			
   			// Build the HTML tag with the tagName and the attributes
   			var sTag = "";
   			if (text == null) {
   			   sTag = "<" + tagName + sAttributes + " />"; 
   			} else {
   			   sTag = "<" + tagName + sAttributes + ">" + text + "</" + tagName + ">"; 
   			}

   			return sTag;
   		} 
   	}

      function CreateOptions(lstOptions, context, lstAttributes)
      /******************************************************************************
       * Creates a new list containing the listItems passed in
       * Parameters:
       *    @param {Object} lstOptions    = javascript array of list items to create
       *    @param {Object} context       = (optional) Context in which to create <input>
       *                                    (ie: document, frame.contentWindow.document, opener.document)
       *    @param {Object} lstAttributes = A key-value map of Attribute properties.
       *
       *    @return {String} String containing HTML <option>s
       *****************************************************************************/
      {      	 
         var elem = null;
         var text = null;
         var val = null;
         var lstAttr = null;
         var optId = null;
         var opt = null;
         var retVal = "";
         
         for (var i = 0; i < lstOptions.length; i++) {
            opt = lstOptions[i];
            // See if this is a key/value pair
            if ( opt instanceof Array && 
                (opt[0] != undefined || opt[0] != null) &&
                (opt[1] != undefined || opt[1] != null)) {
               text = opt[0];
               val = opt[1];
            } else {
               // Not a key/value pair
               text = opt;
               val = opt;
            }
            
            // Set attributes
            if (lstAttributes == null || lstAttributes == undefined) {
               lstAttr = new Object();
            } else {
               lstAttr = lstAttributes;
            }
            
            lstAttr["text"] = text;
            lstAttr["value"] = val;
            
            elem = CreateElementAsHTML("option", lstAttr, context);
            
            retVal += elem;
         }
         
         return retVal;
      }
      

