// <br>
// <b>*** Do not edit in Design View ***</b><br>
// <br>
// This JavaScript library file contains functions common to<br>
// all pages in the CCM Administration application.<br>
// <br>
// <script>

// string validation character sets; concatenate these in scripts to form strings for 
// validation. E.g., validChars = maskAlphaNumeric + charUnderScore + charDash
var charAmpersand     = "&";
var charApostrophe    = "'";
var charAsterisk      = "*";
var charBackSlash     = "\\";   // double backslash here evaluates to single slash where used
var charBang          = "!";
var charBraces        = "{}";
var charBrackets      = "<>";
var charCarat         = "^";
var charComma         = ",";
var charColon         = ":";
var charDash          = "-";
var charDot           = ".";
var charDoubleQuote   = "\"";
var charForwardSlash  = "/";
var charParens        = "()";
var charPercent       = "%";
var charPlus          = "+";
var charQuestionMark  = "?";
var charSingleQuote   = "'";
var charSpace         = " ";
var charUnderscore    = "_";
var charX             = "X";    //these characters are used for route pattern
var charN             = "N";    //these characters are used for route pattern
var charPound         = "#";    //these characters are used for route pattern
var charAtSign        = "@";    //these characters are used for route pattern
var charPrefixDigits  = "[+]";  //these characters are used for route pattern
var charSuffixDigits  = "!";    //these characters are used for route pattern

// Masks for validating limited character sets; for less restrictive validation use exclusion (see isValidTextData)
var maskAlpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";  // base ASCII chars only
var maskNumeric = "1234567890";
var maskHexDigits = "0123456789abcdefABCDEF";
var maskAlphaNumeric = maskAlpha + maskNumeric;
var maskMACAddress = maskHexDigits;
var maskIPAddress = maskNumeric + charDot;
var maskDate = maskNumeric + charForwardSlash;

// Masks for validating characters in DNs and Patterns
var maskRangeNotation = "[^-]";                                             // allowable range or set of chars
var maskMultiChar = "+?";                                                   // 0 or more, 1 or more of preceeding char/range

var maskNumericDigits = maskNumeric;                                        // 0-9
var maskAllDigits = maskNumericDigits + charAsterisk + charPound;           // 0-9 *#
var maskMask = maskAllDigits + charX;                                       // 0-9 *# X
var maskPattern = maskMask + maskRangeNotation + maskMultiChar + charBang;  // 0-9 *# X [^-] +? !
var maskAtPattern = maskPattern + charDot + charAtSign;                     // 0-9 *# X [^-] +? ! .@

var flgInProcess = false;       // used to prevent multiple calls to same remote scripting function

//
// functions to produce standard error message for common validation
//
function getIsDuplicateNameMessage(duplicateName, itemName)
{
  if (!itemName)
    itemName = lblAnItem;
    
  var msg = jsErrDuplicate.replace(/@/, itemName).toString();
  return msg.replace(/#/, duplicateName).toString();
}

function getIsRequiredMessage(name)
{
  return jsErrIsRequired.replace(/@/gi, name).toString();
}

function getIsTooLongMessage(name, len)
{
 var msg = jsErrIsTooLong.replace(/@/gi, name).toString();
 return msg.replace(/#/, len).toString();
}

function getIsTooShortMessage(name, len)
{
 var msg = jsErrIsTooShort.replace(/@/gi, name).toString();
 return msg.replace(/#/, len).toString();
}

function getOutOfRangeMessage(name, min, max)
{
 var msg = jsErrOutOfRange.replace(/@/gi, name).toString();
 msg = msg.replace(/#/, min).toString();
 return msg.replace(/%/, max).toString();
}

function getNamedCharTests()
{
  var tests = new Array();
  var count = 0
  tests[count++] = { mask: maskHexDigits, friendlyName: nameHexNumbers, expression: maskHexDigits };
  tests[count++] = { mask: maskAlpha, friendlyName: nameLetters, expression: maskAlpha };
  tests[count++] = { mask: maskNumeric, friendlyName: nameNumbers, expression: maskNumeric };
  tests[count++] = { mask: charSpace, friendlyName: nameSpaces, expression: charSpace };
  tests[count++] = { mask: charDash, friendlyName: nameDashes, expression: "\\-" };
  tests[count++] = { mask: charDot, friendlyName: nameDots, expression: charDot };
  tests[count++] = { mask: charComma, friendlyName: nameComma, expression: charComma };
  tests[count++] = { mask: charUnderscore, friendlyName: nameUnderscores, expression: charUnderscore };
  
  return tests;
}

function getValidStringMessage(mask, displayName)
{
  var friendlyNames = "";
  var namedCharacters = "";
  var namedCharTests = getNamedCharTests();
  var charSets = new Array();
  var lastCharSet;
    
  for (var i=0; i< namedCharTests.length; i++)
  {
    if (mask.indexOf(namedCharTests[i].mask) != -1)
    {
      // mask contains this named set of characters
      if (lastCharSet)
        { charSets[charSets.length] = lastCharSet; }
      lastCharSet = namedCharTests[i].friendlyName;
    }
    namedCharacters += namedCharTests[i].expression;
  }
    
  var reCharsNotTested = new RegExp("[^" + namedCharacters + "]","gi");
  var arrayOtherValidChars = mask.match(reCharsNotTested);
  if (arrayOtherValidChars)
  {
      if (lastCharSet)
        { charSets[charSets.length] = lastCharSet; }
      lastCharSet = msgOtherValidChars + arrayOtherValidChars.join(" ");
  }
    
    
  // create friendly name string for named characters
  if (charSets.length > 0)
    friendlyNames = charSets.join(", ") + msgConjunction + lastCharSet;
  else
    friendlyNames = lastCharSet;
    
  var msg = msgValidCharacters.replace(/@/gi, displayName).toString();
  msg = msg.replace(/#/, friendlyNames).toString();
  if (!arrayOtherValidChars) msg += charDot;  // add a period if only named sets are present
    
  return msg;
}

// function isValidString:
//   checks the contents of a string (s) to make sure all characters 
//   are in the set of specified valid characters (validChars).
// Takes as input:
//   s - the string to validate. An empty string is always valid.
//   mask - the list of valid characters, which can include letters, number, symbols, 
//          etc. Use the string validation character sets above to construct the mask.
//   displayName - (optional) name of the field being validated; if supplied, the function
//                displays standard validation error message using displayName.
// Returns:
//   Boolean - true if all characters in s are valid, or if s is empty; false if any 
//   characters in s are not in the specified valid character set.
//
function isValidString(s, mask, displayName, isRequired)
{
  if ( (typeof(s) == "string") && (s.length > 0) )
  {
    for (var i = 0; i < s.length; i++)
    {
      if (mask.indexOf(s.charAt(i)) == -1)
      {
        if (displayName)
        {
          alert(getValidStringMessage(mask, displayName));
        }
        return false;                       // a character was found that is not valid
      }
    }
  }
  else if (isRequired && displayName)
  {
    alert(getIsRequiredMessage(displayName));
    return false;
  }
  return true;                              // all characters in the string were valid
}


// function isValidStringData:
//   same as isValidString, but accepts element object as first parameter, and
//   takes care of error messages and selecting element on error condition.
// Takes as input:
//   el - the text element to validate (INPUT type="text").
//   mask - the list of valid characters, which can include letters, number, symbols, 
//          etc. Use the string validation character sets above to construct the mask.
//   displayName - (optional) name of the field being validated; if supplied, the function
//                displays standard validation error message using displayName.
//   maxLength - the maximum number of characters allowed in the string; false or missing
//               argument defaults to 255 characters
//   minLength - the minimum number of characters allowed in the string; zero is same as 
//               not required (false or missing argument defaults to 0)
// Returns:
//   Boolean - true if all characters in el.value are valid, or if el.value is empty string; 
//   false if any characters in el.value are not in the specified valid character set.
//
function isValidStringData(el, mask, displayName, maxLength, minLength)
{
  if ( (el.type != "text") && (el.type != "password") )
    return false; // not text data
  
  // define max and min length if not passed in arguments
  maxLength = (maxLength) ? maxLength : 255;
  minLength = (minLength) ? minLength : 0;

  var s = jTrim(el.value);
  el.value = s;

  if (s.length > 0)
  {
    if (s.length > maxLength)
    {
      showValidationError(el, getIsTooLongMessage(displayName, maxLength), 1);
      return false;
    }
    else if (s.length < minLength)
    {
      showValidationError(el, getIsTooShortMessage(displayName, minLength), 1);
      return false;
    }
    
    if (!isValidString(s, mask, displayName))
    {
      el.focus();
      el.select();
      return false;
    }
  }
  else if (minLength)
  {
    showValidationError(el, getIsRequiredMessage(displayName), 0);
    return false;
  }
  return true;
}


function isValidDNOrPattern(pattern, type)
{
  //
  // !!! Remote Scripting must be enabled on any page that calls this function !!!
  //
  
  // optional third parameter "fieldName"
  var fieldName;
  
  if (isValidDNOrPattern.arguments.length == 3)
    fieldName = isValidDNOrPattern.arguments[2];
  
  var rs_result = RSExecute("_RemoteScripts/rs_numplan.asp", "isValidPatternSyntax", type, pattern);
  var err = getSafeReturnValue(rs_result);
  if (err)
  {
    alert(((fieldName) ? fieldName + ":\n" : "") + err);
    return false;
  }
  return true;
}

// function isValidTextData:
//   validates the contents of a Description field to make sure restricted characters 
//   are not used; by default, double-quote is not allowed.
// Takes as input:
//   el - the form element to validate (assumes a description, but can be any text input).
//   displayName - (optional, string) name of the field being validated. Description is the default. 
//   maxLength - maximum number of characters to accept.
//   minLength - (optional, int) minimum number of characters to accept (if field is required)
//   additionalRestrictions - other characters that are not valid in string (e.g., spaces, colons)
// Returns:
//   Boolean - true if all characters in elDescription.value are valid, or if elDescription is empty; 
//   false if any invalid (restricted) characters are present in elDescription.value.
//
function isValidTextData(el, displayName, maxLength, minLength, additionalRestrictions)
{
  var invalidChars = charDoubleQuote;
  var spacesAllowed = true;
  var s = jTrim(el.value);
  el.value = s;
  
  if (!displayName) displayName = lblDescription;
  if (!maxLength) maxLength = 255;
  if (!minLength) minLength = 0;
  if (additionalRestrictions)
  { 
    invalidChars += additionalRestrictions;
    spacesAllowed = (additionalRestrictions.indexOf(charSpace) == -1);
  }

  if (s.length > 0)
  {
    if (s.length > maxLength)
    {
      showValidationError(el, getIsTooLongMessage(displayName, maxLength), 1);
      return false;
    }
    else if (s.length < minLength)
    {
      showValidationError(el, getIsTooShortMessage(displayName, minLength), 1);
      return false;
    }
    
    for (var i = 0; i < s.length; i++)
    {
      if (invalidChars.indexOf(s.charAt(i)) != -1)
      {
        var msg;
        if (!spacesAllowed)
          additionalRestrictions = additionalRestrictions.replace(/ /, "").toString();
        
        if (additionalRestrictions)
        {
          msg = jsErrInvalidCharacters.replace(/%S1/, displayName).toString();
          msg = msg.replace(/%S2/, additionalRestrictions).toString();
        }
        else
        {
          msg = jsErrInvalidDescription.replace(/%S1/gi, displayName).toString();
        }
        if (!spacesAllowed)
          msg += "\n" + jsErrSpacesNotAllowed.replace(/%S1/, displayName).toString();

        showValidationError(el, msg, 1);
        return false;
      }
    }
  }
  else if (minLength)
  {
    showValidationError(el, getIsRequiredMessage(displayName), 0);
    return false;
  }
  return true;  // all characters in the string were valid
}

// function isDataInRange:
//   validates the contents of a numeric data field to make sure entered value falls 
//   within the specified range.
// Takes as input:
//   el - the form element to validate (assumes a description, but can be any text input).
//   displayName - name of the field being validated, used in alert on error.
//   maxLength - the maximum number of digits in the entry
//   minVal - the lower bound of the valid range
//   maxVal - the upper bound of the valid range 
// Returns:
//   Boolean - true if the value is within the range, or if it is empty and not required;
//             false if the value is out of range, too long, or missing when required.
//
function isValidNumericData(el, displayName, maxLength, minVal, maxVal, isRequired)
{
  window.status = jsStatusValidating;
  var s = el.value;
    
  if (s.length == 0)
  {
    if (isRequired)
    {
      showValidationError(el, getIsRequiredMessage(displayName), 0);
      return false;
    }
    else
      return true;
  }
    
  if (s.length > maxLength)
  {
    showValidationError(el, getIsTooLongMessage(displayName, maxLength), 1);
    return false;
  }
    
  if (!isValidString(s, maskNumeric, displayName))
  {
    el.focus();
    el.select();
    return false;
  }
    
  if ( (Number(s) < minVal) || (Number(s) > maxVal) )
  {
    showValidationError(el, getOutOfRangeMessage(displayName, minVal, maxVal), 1);
    return false;
  }
  
  el.value = Number(s);
  window.status = "";
  return true;
    
}


// function showValidationError:
//   Display an alert message for invalid data, and put focus on the 
//   element that has the error. Optionally select the error value.
// Takes as input:
//   el - the element that you want to get focus (usually the element that
//        contains the error, but not always)
//   msg - message that you want displayed in a JavaScript alert dialog.
//   doSelect - 1 = select the data in el (usually only needed for text); 0 = don't do select
// Returns:
//   nothing - pops up alert dialog and sets window.status to generic error message
//
function showValidationError(el, msg, doSelect)
{
  alert(msg);
  el.focus();
  if (doSelect) el.select();
  status = jsStatusError;
}


// function confirmDelete:
//   prompts user to confirm that they want to delete the specified item.
// inputs:
//   item - a description of the type of item being deleted. For example, if 
//     you are deleting a Device Pool, use "Device Pool". The user will see this 
//     in the prompt ("You are about to permanently delete this Device Pool...").
// returns:
//     Boolean - true if the user clicks Yes (continue); false if the user clicks No.
//
function confirmDelete(item)
{
  if (confirm(msgDeleteConfirm.replace(/@/, item)))
    return true;
  else
    return false;
}

// function jLTrim:
//   javascript version of VBScript LTrim function
// inputs:
//   s - a string object
// returns:
//   s with leading spaces removed
//
function jLTrim(s)
{
  if (typeof(s) == "string")
  {
    while ((s.length > 0) && (s.charAt(0) == " "))
    {
      s = s.substring(1, s.length)
    }
  }
  return s;
}

// function jRTrim:
//   javascript version of VBScript RTrim function
// inputs:
//   s - a string object
// returns:
//   s with trailing spaces removed
//
function jRTrim(s)
{
  if (typeof(s) == "string")
  {
    while ((s.length > 0) && (s.charAt(s.length -1) == " "))
    {
      s = s.substring(0, s.length - 1)
    }
  }
  return s;
}

// function jTrim:
//   javascript version of VBScript Trim function
// inputs:
//   s - a string object
// returns:
//   s with leading and trailing spaces removed (spaces within string remain intact)
//
function jTrim(s)
{
  if (typeof(s) == "string")
    s = jRTrim(jLTrim(s));
  return s;
}

// function getBaseURL
//   utility function to get the virtual root for the project
// inputs:
//   none
// returns:
//   the base URL (virtual root) of the Cisco CallManager Admin web
//
function getBaseURL()
{
    var secondSlash, path;
    var projectBase = '';
    if ((secondSlash = (path = window.location.pathname).indexOf('/',1)) != -1)
      projectBase = path.substring(0,secondSlash);
    
    // Check if we are running under ICS
    if (projectBase.toUpperCase() == "/ICS")
      projectBase += "/CCMAdmin"
    
    return projectBase;
}


// function getElement:
//   utility for accessing form elements
// inputs:
//   formName - name of the form (string) containing the element
//   elName - name of the element to get
// returns:
//   specified element, if it exists; null if element doesn't exist;
//
function getElement(formName, elName)
{
  el = eval('document.' + formName + '.' + elName);
  if (typeof(el) == "object")
    return el;
  else
    return null;
}

// function getValue:
//   utility to get the value of any form element
// inputs:
//   el - the form element object
// returns:
//   value of the element object, or null if there is no
//   value defined for the element; in the case of multi-select
//   lists, returns an array of selected values;
//
function getValue(el)
{
  var isUndefined;
  
  if (!el) return isUndefined;    // element (el) doesn't exist
  
  // gets the specified elements value based on type
  switch (el.type)
  {
    case "select-one":
    {
      return el.options[el.selectedIndex].value;
    }
    case "select-multiple":
    {
      var hr = new Array();
      var count = 0;
      for (var i = 0; i < el.options.length; i++)
      {
        if (el.options[i].selected)
        {
          hr[count++] = el.options[i].value;
        }
      }
      return hr;
    }
    case "radio":
    {
      var buttonGroup = el.form.elements[el.name];

      if (typeof(buttonGroup.value) != "undefined")
        return buttonGroup.value;
      else
      {
        for (var i = 0; i < buttonGroup.length; i++)
        {
          if (buttonGroup[i].checked)
            return buttonGroup[i].value;
        }
      }
      return null;
    }
    case "checkbox":
    {
      if (el.checked)
        return el.value;
      else
        return null;
    }
    case "undefined":
    {
      return null;
    }
    default:
    {
      return el.value;
    }
  }
}

// function setValue:
//   utility to set the value of any form element
// inputs:
//   formName - the name of the form object (object is not required)
//   elNameOrID - the name or unique ID of the element; unique ID is required if
//                the target element is a radio button in a group
//   newValue - the value to set for the form element
// returns:
//   result - true if the value was set, false if not; for non-text elements (checkbox,
//            radio, select), and the selection state of the element is changed to true
//            if new value matches an existing value, or false if the values don't match
//   
function setValue(formName, elNameOrID, newValue)
{
  var el = eval('document.' + formName + '.' + elNameOrID);
  if (typeof(el) == "object")
    var type = el.type;
  else
    return false;
      
  switch (type)
  {
    case "checkbox":
    case "radio":
    {
      if (el.value == newValue)
        el.checked = true;
      else
        el.checked = false;
      return true;
    }

    case "select-one":
    case "select-multiple":
    {
      // sets the new value of the specified select list form element
      for (var i = 0; i < el.options.length; i++)
      {
        if (el.options[i].value == newValue)
        {
          el.selectedIndex = i;
          return true;
        }
      }
      return false;
    }

    default:
    {
      // sets the new value of the specified text or hidden form element
      el.value = newValue;
      return true;
    }
  }
}

// function selectItemByValue:
//   selects an item in a select list using a specified value.
// Takes as input:
//   elSelectList - the selectList object by name/ID
//   newValue - the value to be selected
// Returns:
//   nothing - if the value is found that item is selected
//             otherwise the list is not changed
//
function selectItemByValue(elSelectList, newValue)
{
  if (!newValue)
    return;
      
  for (var i = 0; i < elSelectList.length; i++)
  {
    if (elSelectList.options[i].value == newValue)
    {
      elSelectList.selectedIndex = i;
      break;
    }
  }
  return;
}

// function selectItemByText:
//   selects an item in a select list using a text value. 
// Takes as input:
//   elSelectList - the selectList object by name/ID
//   newText - the text (display) string value to be selected
// Returns:
//   nothing - if the value is found that item is selected
//             otherwise the list is not changed
//
function selectItemByText(elSelectList, newText)
{
  if (newText.length == 0)
    return;
      
  for (var i = 0; i < elSelectList.length; i++)
  {
    if (elSelectList.options[i].text.toLowerCase() == newText.toLowerCase())
    {
      elSelectList.selectedIndex = i;
      break;
    }
  }
  return;
}

// function selectItemByPartialText:
//   selects an item in a select list if it starts with a specified string (partial text). 
// Takes as input:
//   elSelectList - the selectList object by name/ID
//   partialText - the partial text string to match against
// Returns:
//   nothing - if the partial text is found, the first item starting with
//             that string is selected, otherwise the list is not changed
//
function selectItemByPartialText(elSelectList, partialText)
{
  var s;  //holds temp strings
      
  if (partialText.length == 0)
    return;
      
  for (var i = 0; i < elSelectList.length; i++)
  {
    s = elSelectList.options[i].text.toLowerCase();
    if (s.indexOf(partialText.toLowerCase()) == 0)
    {
      elSelectList.selectedIndex = i;
      break;
    }
  }
  return;
}
  
 
// function selectOptionByValue:
//   selects a radio button from a group of radio buttons using a value. 
// Takes as input:
//   buttonGroup - the radio button group name
//   newValue - the value of the button to selected
// Returns:
//   nothing - if the value is found that button is selected
//             otherwise the button group is not changed
//
function selectOptionByValue(buttonGroup, newValue)
{
  for (var i = 0; i < buttonGroup.length; i++)
  {
    if (buttonGroup[i].value == newValue)
    {
      buttonGroup[i].checked = true;
      break;
    }
  }
  return;
}

// 
// Utility functions for moving items between lists
//
function _switchItems(list, a, b)
{
  var optionA = { text: list.options[a].text, value: list.options[a].value };
  var optionB = { text: list.options[b].text, value: list.options[b].value };
    
  list.options[a].text = optionB.text;
  list.options[a].value = optionB.value;

  list.options[b].text = optionA.text;
  list.options[b].value = optionA.value;
    
}

function moveSelectedItem(fromList, toList)
{
  if (fromList.selectedIndex == -1)
    { return; }
      
      
  var fromSelectedIndex = fromList.selectedIndex;
  var toSelectedIndex = toList.selectedIndex;
    
  var itemValue = fromList.options[fromSelectedIndex].value;
  var itemText = fromList.options[fromSelectedIndex].text;
  var itemIndex = toList.length;
  toList.options[itemIndex] = new Option(itemText, itemValue);
    
  // if there is a selection in toList, move new item after selection
  fromList.options[fromSelectedIndex] = null;
  if (toSelectedIndex != -1)
  {
    while (toSelectedIndex < itemIndex - 1)
    {
      _switchItems(toList, itemIndex, --itemIndex);
    }
  }
    
  toList.selectedIndex = itemIndex;
  toList.focus();
}
  
function moveSelectedItemUp(list)
{
  if (list.selectedIndex < 1)
    { return; }
      
  _switchItems(list, list.selectedIndex, list.selectedIndex - 1);
  list.selectedIndex = list.selectedIndex - 1;
}
  
function moveSelectedItemDown(list)
{
  if ( (list.selectedIndex == -1) || (list.selectedIndex == list.length - 1) )
    { return; }
  
  _switchItems(list, list.selectedIndex, list.selectedIndex + 1);
  list.selectedIndex = list.selectedIndex + 1;
}
  
function openCenteredWindow(url, name, width, height, options)
{
  var centeredWin;
  var posX, posY;
  var winWidth  = (window.innerWidth) ? window.innerWidth : (document.body.clientWidth) ? document.body.clientWidth : 640;
  var winHeight = (window.innerHeight) ? window.innerHeight : (document.body.clientHeight) ? document.body.clientHeight : 400;
  var offsetX   = Math.round((winWidth - width)/2);
  var offsetY   = Math.round((winHeight - height)/2);
  
  
  /* uncomment to debug other browser and OS versions
  alert("screenX: " + window.screenX + "\n" + 
        "screenY: " + window.screenY + "\n" +
        "screenLeft: " + window.screenLeft + "\n" +
        "screenTop: " + window.screenTop);
  */
  
  if (typeof(window.screenX) != "undefined")  // JS 1.2 standard
  {
    posX        = window.screenX + (offsetX);
    posY        = window.screenY + (offsetY);
    centeredWin = "height=" + height + ",width=" + width + ",screenY=" + posY + ",screenX=" + posX;
  }
  else if (typeof(window.screenLeft) != "undefined") // IE's way
  {
    // with IE, smaller windows look better a little above center, so move window up if there's a big vertical offset
    offsetY     = (offsetY > 100) ? Math.round(offsetY * .8) : offsetY;
    posX        = window.screenLeft + (offsetX);
    posY        = window.screenTop + (offsetY);
    centeredWin = "height=" + height + ",width=" + width + ",top=" + posY + ",left=" + posX;
  }
  
  if (options)
    centeredWin += ",";
    
  var newWin = window.open(url, name, centeredWin + options);
  
  return newWin;
}

// function setIESelectWidth:
//   Changes the width of select lists (drop-downs) in IE to be at 
//   least a specified width.
// Takes as input:
//   thisForm - the form containing elements to be updated
//   widhtInPixels - the minimum width to apply to select elements in the form
// Returns:
//   nothing
//
function setIESelectWidth(thisForm, widthInPixels)
{
  var width;
  if ((thisForm) && (document.all))
  {
    for (var i = 0; i < thisForm.length; i++)
    {
      el = thisForm.elements[i];
      if ((el.type == "select-one") || (el.type == "select-multiple"))
      {
        if (el.minWidth)
          width = el.minWidth;
        else
          width = widthInPixels;
        
        if ((el.offsetWidth - el.offsetLeft) < Number(width))
          el.style.width = width + "px";
      }
    }
  }
  return;
}
  

// the following line of code reloads a page if it was reached using 
// the browser's Back button. (History.Forward only exists after using Back.)
// if (history.forward) document.location.reload();