var g_BootOnPageChange = false;
var g_MayNeedToReboot = false;
var g_RowNumber = 1;
var form = null

function AddToAndList (currentList)
{
  var newString;
  
  for (index = 1; index < arguments.length; index++)
  {
    newString = arguments[index];
    if (currentList == null || currentList == "") currentList = newString;
    else if (newString != null && newString != "") currentList += " && "+ newString;
  }
  return currentList;
}

function AddFormStart (form, action, method, encType, accept)
{
  if (!action) action = ""
  if (!method) method = "post";
  encType = (encType) ? (' enctype="'+encType+'"') : "";
  accept = (accept) ? (' accept="'+accept+'"') : "";
  document.write ('<form name="'+form+'" method="'+method+'" action="'+action+'"'+encType+accept+'>');
}

function AddHiddenInput (name, value)
{
  document.write ('<input name="'+name+'" type="hidden" id="'+name+'" value="'+value+'">');
}

function AddInput (type, name, value, length, size, dataValidation,
  onChange, isRequired, requiredText, rebootOnChange, parameters)
{
  var dataValidationCmds = "";
  var onChangeCmds = "";
  var thisObj = "document.getElementById ('"+name+"')";
  var requiredFunc = (isRequired) ?
    'VerifyNotBlank ('+thisObj+', \''+requiredText+'\')' : "";
  
  if (!onChange) onChange = "";
  if (!length) length = "";
  if (!size) size = (length == "") ? "" : length * 1.4;
  if (size > kMaxEditBoxLength) size = kMaxEditBoxLength;
  
  // if the type is range the real type is still input but we need to add paramaters to
  // the validation function 
  if (dataValidation)
  {
    dataValidation += '('+thisObj
     if (parameters && parameters != "") dataValidation += ", " + parameters
       dataValidation += ')'
  }
 
  dataValidationCmds = AddToAndList (dataValidationCmds, dataValidation, 
    requiredFunc);
  onChangeCmds = AddToAndList (onChangeCmds, "ValidateField (this)", onChange);
  if (onChangeCmds != "") onChangeCmds = "return ("+onChangeCmds+")";
  if (rebootOnChange) AddFootnoteIndecator ();
  document.write ('<input name="'+name+'" type="'+type+'" id="'+name+
    '" vFunction="'+dataValidationCmds+'" onChange="'+onChangeCmds+
    '" value="'+value+'" size="'+size+'" maxlength="'+length+'">');
  SetCommonAttributes (name, rebootOnChange);
}

function AddDoubleByteEditBox (name, value, length, size, onChange, 
  isRequired, requiredText, rebootOnChange)
{
  AddEditBox (name, value, length, size, 'ValidateDoubleByte', onChange, 
    isRequired, requiredText, rebootOnChange);
}

function AddEditBox (name, value, length, size, dataValidation,
  onChange, isRequired, requiredText, rebootOnChange, parameters)
{
  AddInput ("text", name, value, length, size, dataValidation,
  onChange, isRequired, requiredText, rebootOnChange, parameters)
}

function AddPasswordEditBox (name, value, length, size, dataValidation,
  onChange, isRequired, requiredText, rebootOnChange)
{
  AddInput ("password", name, value, length, size, dataValidation,
  onChange, isRequired, requiredText, rebootOnChange)
}

function AddDoubleBytePasswordEditBox(name, value, length, size,
  onChange, isRequired, requiredText, rebootOnChange)
  {
	AddPasswordEditBox(name, value, length, size, 'ValidateDoubleByte', onChange,
	isRequired, requiredText, rebootOnChange)
  }

function AddPhoneNumberEditBox (name, value, length, size,
  onChange, isRequired, requiredText, rebootOnChange)
{
  AddEditBox (name, value, length, size, 'CheckPhoneInput',
    onChange, isRequired, requiredText, rebootOnChange);
}

function AddISDNNumberEditBox (name, value, length, size,
  onChange, isRequired, requiredText, rebootOnChange)
{
  AddEditBox (name, value, length, size, 'CheckISDNInput',
    onChange, isRequired, requiredText, rebootOnChange);
}

function AddEmailEditBox (name, value, length, size,
  onChange, isRequired, requiredText, rebootOnChange)
{
 // var validateFunc = 'tmt_RegExpValidator(\''+name+'\',\'%5E%5B%5Cw%5C.=-%5D%2B@%5B%5Cw%5C.-%5D%2B%5C.%5Ba-z%5D%7B2,3%7D$\',langString(strINVALID_EMAIL),\'\',\'\');';
  AddEditBox (name, value, length, size, "EmailOnly", onChange, 
    isRequired, requiredText, rebootOnChange);
}

function AddIPEditBox (name, value, length, size, onChange,
  isRequired, requiredText, rebootOnChange)
{
  AddEditBox (name, value, length, size, "IpOnly", onChange,
    isRequired, requiredText, rebootOnChange);
}

function AddIntegersOnlyEditBox (name, value, length, size, 
  onChange, isRequired, requiredText, rebootOnChange)
{
  AddEditBox (name, value, length, size, "IntegersOnly", 
    onChange, isRequired, requiredText, rebootOnChange);
}

function AddASCIIOnlyEditBox (name, value, length, size, 
  onChange, isRequired, requiredText, rebootOnChange)
{
  AddEditBox (name, value, length, size, "ExtendedAsciiOnly", 
    onChange, isRequired, requiredText, rebootOnChange);
}

function AddNumbersOnlyEditBox (name, value, length, size, 
  onChange, isRequired, requiredText, rebootOnChange)
{
  AddEditBox (name, value, length, size, "NumbersOnly", 
    onChange, isRequired, requiredText, rebootOnChange);
}

function AddKeyboardOnlyEditBox (name, value, length, size, 
  onChange, isRequired, requiredText, rebootOnChange)
{
  AddEditBox (name, value, length, size, "KeyboardInputOnly",
    onChange, isRequired, requiredText, rebootOnChange);
}

function GetNumberOfDigits (value)
{
  if (typeof value == "string") return value.length
  else return value.toString().length
}

function AddRangeEditBox (name, value, start, end, length, size, 
  onChange, isRequired, requiredText, rebootOnChange)
{
  AddEditBox (name, value, 
    (!length ? GetNumberOfDigits(end) : length),
    size, 'CheckIntRange', onChange, 
    isRequired, requiredText, rebootOnChange, start + ", " + end);
}

function  LoadPage (onLoad)
{
  if (onLoad != null && onLoad != "") eval (onLoad);
}

function AddDataTableStart ()
{
  document.write ('<tr><td>');
    document.write ('<table class="dataTable" id="dataTable" border="0" cellpadding="0" cellspacing="2">');
      // Dummy row for automation
      document.write ('<thead>')
        document.write ('<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>')
      document.write ('</thead>')
      document.write ('<tbody id="dataTableBody">');
}

function AddHeaderRow ()
{
    document.write ('<table width="100%" border="0" cellspacing="0" cellpadding="2"><tbody>');
      document.write('<tr class="pageTitle">');
        document.write('<td class="pageTitle" id="pageTitle"></td>');
        document.write('<td class="buttons" name="buttons" id="buttons"></td>');
      document.write('</tr>');
    document.write('</tbody></table>');
}

function AddButton (name, value, onclick, style)
{
  GetEndOfBody ().appendChild (page.CreateButton (name, value, onclick, style))
}

function AddBodyStart (pageName, formName, groupName, action, onLoad,
  showNav, method, encType, accept, style)
{
  if (!action) action = ""
  if (showNav == null) showNav = !isOOB;
  if (!method) method = "post";
  //encType = (encType) ? ' enctype="'+encType+'"' : "";
  accept = (accept) ? ' accept="'+accept+'"' : "";
  if (!style) style = "configData";
  
  if (onLoad == null) onLoad = "";
  
  document.write ('<body onLoad="LoadPage(\''+onLoad+'\');">');
    document.write ('<table class="'+style+'">');
      if (!parent.document.getElementById ("pageTitle"))
      {
        document.write('<tr><td>');
          AddHeaderRow ();
        document.write('</td></tr>');
      }
      AddPageLabel (pageName)
      document.write('<tr><td>');
        if (formName != null)
          AddFormStart (formName, action, method, encType, accept)
        if ( groupName != null && groupName != "")
          document.write ('<input type="hidden" name="_groupname" value="'+groupName+'">');
        AddDataTableStart ()                    
        if (g_BootOnPageChange) AddFootnoteText (CHANGES_WILL_REBOOT)
}

function AddDataTableEnd ()
{
      document.write ('</tbody>');                    
    document.write ('</table>');                    
  document.write ('</td></tr>');
}

function StartNewDataTable (formName, action)
{
  AddDataTableEnd ();
  if (formName != null)
  {
    if (action == null) action = "";
    document.write ('</form>');
    document.write ('<form name="'+formName+'" method="post" action="'+action+'">');
  }
  AddDataTableStart ();
}

function AddDataTableScreenAndBodyEnd (backPage, nextPage, showUpdate, endForm, onSubmit)
{
  if (endForm == null) endForm = true;
        if (g_BootOnPageChange) AddFootnoteText (CHANGES_WILL_REBOOT)
        if (g_MayNeedToReboot) AddFootnoteText (CHANGES_RESTART_WEB)
        AddDataTableEnd ();                    
      if (document.getElementById (NOERROR_PAGE) == null)                    
        AddHiddenInput (NOERROR_PAGE, (nextPage) ?
          nextPage : GetCurrentPageName ())
      AddUpdateNextButtons(backPage, nextPage, showUpdate, onSubmit)
    if (endForm) document.write ('</form>');
  document.write ('</body>');
}

// This function would have to modifed to work for page 2 or higher.
function AddPageLabel (pageName)
{
  var titleBar = parent.document.getElementById ("pageTitle")
  if (titleBar) titleBar.innerHTML = pageName;
}

function ValidateField (object)
{
  var vFunction = object.getAttribute ("vFunction");
  var bDataIsValid = true
  
  if (!IsDisabled (object) && vFunction) bDataIsValid = eval (vFunction)
  if (!bDataIsValid) page.UpdateCommonAttributes (object)
  
  return bDataIsValid
}

function CheckListForReboot (inputs)
{
  for (index = 0; index < inputs.length; index++)
  {
    // if the field has rebotOnChange defined and it is true check
    // to see if the values has changed and if it has return true;
    // alert ("type = " + inputs[index].type);
    if (inputs[index].type != "hidden" &&
      (page.bootOnAnyChanges ||g_BootOnPageChange || 
      GetBooleanAttribute (inputs[index], "rebootOnChange")))
    {
      // Check to see if the value has changed
      //alert (GetObjectOValue(inputs[index]) + ", " + GetObjectValue (inputs[index]))
      if (GetObjectOValue(inputs[index]) != GetObjectValue (inputs[index]))
      {        
        return true;
      }
    }
  }
  return false
}

function IsRebootNeeded ()
{
  if (isOOB) return false
  var inputFields = document.getElementsByTagName('input')
  var selectFields = document.getElementsByTagName('select')
  
  if (CheckListForReboot (inputFields)) return true
  if (CheckListForReboot (selectFields)) return true
  return false
}
    
function ResetObject (object)
{
  SetObjectValue (object, object.getAttribute ("oValue"))
}
    
function ConfirmChange (object, previousValue, message)
{
  var bConfirm;
  // If no message is supplied use the default one
  if (message == null) message = IDS_REBOOT_CONFIRM;
  // If the system already needs to be rebooted than don't prompt
  // the user.
  var bConfirm = confirm (message);
  if (!bConfirm)
  {
    SetObjectValue (object, previousValue)
  }
  return bConfirm;
}

function VerifyData ()
{
  var inputFields = document.getElementsByTagName('input');
  var rValue = true;
  var onChange;

  for (index = 0; index < inputFields.length; index++)
  {
    // Only validate the text fields
    if (inputFields[index].type == "text" || inputFields[index].type == "password")
    {
      // If just one field fails do not submit
      if (! ValidateField (inputFields[index]))
      {
        rValue = false;
      }
    }
  }
  return rValue;
}

// We do not want to reboot if the system is oob
function ForceBootOnAnyChange () {g_BootOnPageChange = !isOOB}

function GetHTMFile () {return document.getElementById (NOERROR_PAGE).value}

function CheckAndSubmitForm (onSubmit)
{
  // If the page contains a content frame then we are viewing the inside the
  // frame on the main page and we need to call the submit function from
  // within that frame.
  // alert ("CheckAndSubmitForm")
  var cFrame = document.getElementById ("contentFrame")
  if (cFrame) 
    return cFrame.contentWindow.CheckAndSubmitForm (onSubmit)

  if (VerifyData ())
  {
    // If the system needs to be rebooted prompt the user to make sure
    // they want to submit the page
    // alert ("onSubmit = \"" + onSubmit + "\"");
    if (((onSubmit == null || onSubmit == "" ) ? true : eval (onSubmit)))
    {
      if (IsRebootNeeded ()) 
      {
        if (confirm (APPLICATION_MUST_BE_RESTARTED))
        {
          // If we need to reboot and the page has an action than that
          // action will have to force the reboot.
          //if (!GetAction () || GetAction () == "") SetAction (rebootAction);
          //document.getElementById (NOERROR_PAGE).value = "a_rebootmeter.htm"
          showPopWin('u_processing.htm?message=PLEWAIWHISYSRES&pollstatus=true', 400, 130, null, false)
        }
        else
        {
           return false;
        }
      }
      //alert ("Submit the form and reload "+GetHTMFile()+" action = "+page.GetAction ())
      document.forms[0].submit ()
      return true;  // For completeness
    }
  }
  return false;
}
    
function AddUpdateNextButtons (backPage, nextPage, showUpdate, onSubmit)
{
  // Cluge to get the update button to work until all VSX pages are updated
  // to use the page object
  if (!page.formName && form) page.formName = form
  page.AddUpdateNextButtons (backPage, nextPage, showUpdate, onSubmit)
}

////////////////////////////////////////////////////////////////////////////////
//  Name:        IsChecked
//  Description: Verify that a checkbox is checked.
////////////////////////////////////////////////////////////////////////////////

function IsChecked (object)
{
  if (typeof object == "string") object = document.getElementsByName (object)[0]
  return GetBooleanAttribute (object, "checked")
}

function Disable (object, bDisabled)
{
  if (typeof object == "string") object = document.getElementsByName (object)[0]
  if (object)
  {
    // If the object is provisioned it should always be disabled.
    if (bDisabled == null || IsProvisioned (object.id)) bDisabled = true
  
    if (object.setAttribute) object.setAttribute ("disabled", bDisabled)
    if (object.disabled) object.disabled = bDisabled // for ns/firefox
    if (object.type == "img" || object.tagName == "IMG")
    {
      object.src = GetCheckBoxImageName (object)
    }
  }
}

function IsDisabled (object)
{
  if (typeof object == "string") object = document.getElementsByName (object)[0]
  return GetBooleanAttribute (object, "disabled")
}

function UpdateCheckBoxHelper(checkBox)
{
  if (typeof checkBox == "string")
    checkBox = document.getElementById (checkBox)
  document.getElementById (checkBox.getAttribute("helper")).value =
    IsChecked(checkBox) ? "True" : "False";
  return true;
}

function SetCommonAttributes (objectID, rebootOnChange)
{
  var object = objectID;
  var value
  
  if (typeof object == "string") object = document.getElementById (objectID);
  rebootOnChange = (rebootOnChange == true)// Check for true in case it is null
   
  if (object != null)
  {
    value = GetObjectValue (object)
    object.setAttribute ("oValue", value);
    object.setAttribute ("cValue", value)
    object.setAttribute ("pValue", value);
    object.setAttribute ("rebootOnChange", rebootOnChange);
    if (rebootOnChange) g_MayNeedToReboot = true;
    // Moved the check to see if this provisioned into the disable function.
    // This prevents object specific code from overriding this.
    Disable (object, false)
  }
}

function ClickCheckBoxImage (object)
{
  if( !IsDisabled (object))
  {
    SetCheckBoxImage (object, !IsChecked (object))
  eval (object.getAttribute ("onchange"))
  }
}

function GetCheckBoxImageName (object)
{
  return object.src = "checkbox" + 
   ((IsChecked (object)) ? "True" : "False") +
   ((IsDisabled (object)) ? "Disabled" : "") +
   ".png"
}

function SetCheckBoxImage (object, value)
{
  //alert ("SetCheckBoxImage ("+object.id+", "+value+")")
  if (IsChecked (object) != value)
  {
    SetImageValue (object, value)
    object.src = GetCheckBoxImageName (object)
    UpdateCheckBoxHelper (object)
  }
}

// If the language is left to right we may have to adjust for that.
function AddFootnoteIndecator () {document.write ("<b>*</b> ")}

function AddCheckBox (name, value, onClick, forceNavUpdate, rebootOnChange)
{
  var checked = (value == "True" ? " checked" : "" );

  if (onClick == null) onClick = "";
  onClick = 'UpdateCheckBoxHelper(this);'+onClick;
  if (forceNavUpdate) onClick += 'UpdateNavReloadCB(this);'

  if (rebootOnChange) AddFootnoteIndecator ();
  document.write ('<input type="hidden" id="'+name+'" name="'+name+'" value ="'+value+'">');
  document.write ('<input helper="'+name+'" type="checkbox" '+
    'name="'+name+'checkbox"'+checked+' onClick="'+onClick+'">');
  SetCommonAttributes (name+"checkbox", rebootOnChange);
}
//**************************************************************
//    ussage:
//      AddRow (
//        ["tabed=<number>"] (default = 0),
//        ["name=rowName"] (default = NONE),
//        ["columns=<number>] (default = 1),
//        ["dataColumns=<number>] (default = 1),
//        ["style=class] (default = ""),
//        ["width=widthValue] (default = 40%),
//        ["usecols=true|false] (default = 1),
//        items to add to the array],
//        ...
//       )
//***************************************************************
function AddRow ()
{
  var index;
  var startIndex = 0;
  var tabed = 0;
  var columns = 1;
  var dataColumns = 1;
  var align = "";
  var valign = "middle"
  var name = "row"+g_RowNumber++
  var dataName = "";
  var titleName = "";
  var args;
  var usecols = false;
  var style = "";
  var width = "40%";
  var labelstyle = ""
  var datastyle = ""

//  args = arguments[startIndex].match (/^\s*([^ =]+)\s*=\s*(.+)\s*$/);
  while (/.+=.+/.test(arguments[startIndex]))
  {
    args = arguments[startIndex].split("=");
    if (/(usecols)/i.test(args[0]))
    {
      eval (args[0] + " = /true/i.test('"+args[1]+"')");
    }
    else if (/name/i.test(args[0]))
    {
      name = args[1];
    }
    else if (/tabed/i.test(args[0]))
    {
      eval (args[0]+" = "+args[1]+"");
    }
    else
    {
      eval (args[0]+" = '"+args[1]+"'");
    }
    //alert ("name = \""+name+"\"");
    startIndex++;
  }
  var noWrap = (columns == 1) ? "nowrap " : "";
  var dataName = name+"data"
  var titleName = name+"label"

  document.write('<tr class="'+style+'" id="'+name+'">');
    document.write('<td class="'+labelstyle+'" '+noWrap+'colSpan="'+columns+'" id="'+titleName+'" align="'+align
      +'" width="'+width+'" valign="'+valign+'">');
      for (index = 0; index < tabed; index++)
      {
        document.write('&nbsp;&nbsp;&nbsp;&nbsp;');
      }
      eval (arguments[startIndex++]);
    document.write('</td>');
    if (!usecols)
    {
      document.write('<td class="'+datastyle+'" colspan="'+dataColumns+'" id="'+dataName+'">');
        for (index = startIndex; index < arguments.length; index++)
        {
          if (!arguments[index] || arguments[index] == "") continue
          if (index != startIndex) document.write ("&nbsp;");
          eval (arguments[index]);
        }
      document.write('</td>');
    }
    else
    {
      for (index = startIndex; index < arguments.length; index++)
      {
        if (!arguments[index] || arguments[index] == "") continue
        document.write('<td class="'+datastyle+'" colspan="'+dataColumns+'" id="'+dataName+(index-startIndex)+'">');
          eval (arguments[index]);
        document.write('</td>');
      }
    }
  document.write('</tr>');
}

function AddFootnoteText (text)
{
  document.write('<tr><td colspan="2" align="center">');
    document.write('<br/><b>'+ text + '</b><br/><br/>');
  document.write('</td></tr>');
}

function TranslateOptionValue (choiceFileName, value)
{
  var tValue

  // Look for a specific translation associated with the choice file and the value
  try
  {
    if (choiceFileName.toUpperCase() == "RS232CAMERACONTROL2" && isChurchill)
    {
      //alert (choiceFileName.toUpperCase() + "_" + value.toUpperCase())
      if (value == "CAMERA3A")
      {
        tValue = eval (choiceFileName.toUpperCase() + "_CAMERA2A")
      }
      else if (value == "CAMERA4A")
      {
        tValue = eval (choiceFileName.toUpperCase() + "_CAMERA3A")
      }
    }
    else
    {
    // alert (choiceFileName.toUpperCase() + "_" + value.toUpperCase())
    tValue = eval (choiceFileName.toUpperCase() + "_" + value.toUpperCase())
  }
  }
  catch (e)
  {
    // Try without any trailing digits
    try
    {
      tValue = eval (choiceFileName.replace (/[\d]+$/, "").toUpperCase() +
        "_" + value.toUpperCase())
    }
    catch (e)
    {
      // That did not work try look for a translation of the value directly
      // alert (value.toUpperCase())
      try
      {
        tValue = eval (value.toUpperCase());
      }
      catch (e)
      {
      try
      {
        tValue = eval ("RESOLUTION" + value.toUpperCase() + "_STR");
      }
      catch (e)
        {
        tValue = eval (value.toUpperCase() + "_STR");
      }
    }
  }
  }
  return tValue   
}

// Function Name: TranslateOption
// Params:
//    choiceFileName - The name of the choice file the value came from.
//    value - The value to translate.
// Description:
//    Look for a translation for value using the following rules:
//    1. Look for a specific translation associated with the choice file and the value.
//    2. Looki for a translation of the value directly.
//    3. Return the original value.

function TranslateOption (choiceFileName, value)
{
  var tValue

  value += "" // Make sure value is a string
  //alert ("TranslateOption ("+choiceFileName+", "+value+")")

  try
  {
    tValue = TranslateOptionValue (choiceFileName, value.replace (/\W/g, "_"))
  }
  catch (e)
  {
    // That did not work try look for a translation of the value with no spaces
    try
    {
      tValue = TranslateOptionValue (choiceFileName, value.replace (/ /g, "").replace (/\W/g, "_"))
    }
    catch (e)
    {
      // That did not work try look for a translation of the value with no spaces
      try
      {
        tValue = TranslateOptionValue (choiceFileName.replace (/[0-9]*$/,""), value.replace (/\W/g, "_"))
      }
      catch (e)
      {
        // Could not find a translation just return the original text.
        tValue = value
      }
    }
  }

  return tValue   
}

function AddRadioList (name, values, selectedValue, onChange,
  forceTranslations, rebootOnChange, multiLine)
{
  var options
  var sOption
  var aOption
  var index
  var choiceFile = (typeof forceTranslations == "string") ? forceTranslations : name
  
  if (multiLine == null) multiLine = true;
  if (onChange == null) onChange = ""
  if (rebootOnChange) AddFootnoteIndecator ()

  if (values != null && values != "")
  {
    options = values.split ("?")
    for (index = 0; index < options.length; index++)
    {
      var text
      var value
      aOption = options[index].split("|")
      text = (forceTranslations) ? TranslateOption (choiceFile, aOption[1]) : aOption[1]
      value = aOption[0]
      document.write('<input type="radio" id="'+name+'" name="'+name+'"'+
        ((value == selectedValue) ? ' checked ' : ' ') +
        'value="' + value + '" onclick="'+onChange+'">' +
        (/(\.gif|\.png)$/.test (text) ? '<img src="'+text+'" border="0" hspace="1" />'
          : text)
         + '</input>')
      if (multiLine) document.write ('<br />');
    }
  }
  SetCommonAttributes (name, rebootOnChange)
}
function TranslateV35CallType(calltype)
{
   var retVal = calltype;
   if(calltype == "isdn" || calltype == "h320")
   {
       if(IsV35())
       {
           retVal =  "V35";
       }
   }
   return retVal;
}

function AddSelect (name, values, onChange, forceTranslations, rebootOnChange, selectedValue)
{
  var options
  var sOption
  var aOption
  var index
  var choiceFile = (typeof forceTranslations == "string") ? forceTranslations : name
  var text
  var isSelected
  var defaultValue = ""
  var isFistLineADup = false

  if (onChange == null) onChange = "";
  if (rebootOnChange) AddFootnoteIndecator ();

  document.write ('<select name="'+name+'" id="'+name+'" onchange="'+onChange+'">')
  if (values != null && values != "")
  {
    options = values.split ("?");
    for (index = 0; index < options.length; index++)
    {
      aOption = options[index].split("|")
      text = TranslateOption (choiceFile, aOption[0])
      value = (name == "calltype") ? TranslateV35CallType(aOption[0]) : aOption[0]
      
      // save the selected value
      if (!selectedValue && aOption.length > 1 && aOption[aOption.length-1] == kSelected)
        selectedValue = value
      // If this is the first line save it as the default
      if (index == 0)
      {
        defaultValue = value
      }
      // If this is not the first line check to see if it is a dup of the first line
      // so that we can remove the fist line when we are done.
      else
      {
        if (!isFistLineADup) isFistLineADup = value == defaultValue
      }
      document.write('<option value="' + aOption[0] + '">' + text + '</option>')
    }
  }
  document.write ('</select>');
  // If the fist line is a dup of one of the other lines remove it
  var selectObj = document.getElementById (name)
  
  if (isFistLineADup) selectObj.options[0]=null
  SetObjectValue (selectObj, selectedValue, false)
  SetCommonAttributes (name, rebootOnChange);
  if (selectObj.options.length == 1) Disable (selectObj)
}

function AddLink (link, label) {document.write ('<a href="'+link+'">'+label+'</a>')}

function SetGroup (group) {document.forms[form]._groupname.value = group}

function SetAction (action) {document.forms[form].action = action}

function GetAction () {return document.forms[form].action}

function GetSearchParams()
{ 
  var params = new Object ();
  var qry = window.location.search.substring(1); 
  if (qry.length == 0)
  {
    return null; 
  }
  else
  { 
    var pars = unescape(qry).split( '&' ); 
    var idx = 0; 
    for ( var i=0; i<pars.length; i++)
    { 
      idx = pars[i].indexOf('='); 
      if (idx >= 0)
      { 
        params[pars[i].substring(0, idx).toLowerCase()] = pars[i].substring(idx+1);
      } 
    }
  }
  return params; 
}

