function toggleSelection(Element, Name) {
  var theInput = document.getElementById(Name);
  if (theInput.value == "") {
    theInput.value = Element.getAttribute("class");
    Element.setAttribute("class", "selected");
  } else {
    Element.setAttribute("class", theInput.value);
    theInput.value = "";
  }
}

function execAction(Action) {
  var elements = document.getElementsByTagName("input");
  var selection = "";
  for (i = 0; i < elements.length; ++i) {
    var name = elements[i].nodeName;
    if (elements[i].getAttribute("name") == "Item" &&
        elements[i].getAttribute("value") != "") {
      if (selection == "") {
        selection = elements[i].getAttribute("id");
      } else {
        selection = selection + "," + elements[i].getAttribute("id");
      }
    }
  }
  var Form = document.getElementById("SelectionContainer");
  Form.sel.value = selection;
  Form.name.value = Action;
  Form.submit();
}

function applyPattern(TheMinSize,TheMaxSize, TheMinRate,
                      TheMaxRate, TheMedia)
{
  var form = document.forms["SearchOptions"];

  form.elements["media"].selectedIndex = TheMedia;

  if (TheMinSize == "0B")
    form.elements["size_min"].value = "";
  else
    form.elements["size_min"].value = TheMinSize;

  if (TheMaxSize == "0B")
    form.elements["size_max"].value = "";
  else
    form.elements["size_max"].value = TheMaxSize;
  
  if (TheMinRate == "0")
    form.elements["rate_min"].value = "";
  else
    form.elements["rate_min"].value = TheMinRate

  if (TheMaxRate == "0")
    form.elements["rate_max"].value = "";
  else
    form.elements["rate_max"].value = TheMaxRate;
    
}
