/**
 * Utility functions
 * Copyright (C) 2003 OPENSPHERE Inc. All Rights Reserved.
 */

function arrayHasItem(array, item) {
  var i;
  for (i = 0; i < array.length; i++) {
    if (array[i] == item)
      return true;
  }
  return false;
}

function printCheckBox(name, value, state, def) {
  if (state == value || (def && state != value)) {
    document.writeln("<input type=\"checkbox\" name=\"" + name +
                     "\" value=\"" + value + "\" checked>");
  } else {
    document.writeln("<input type=\"checkbox\" name=\"" + name +
                     "\" value=\"" + value + "\">");
  }
}

function printRadioButton(name, value, state, def) {
  if (state == value || (def && state == "")) {
    document.writeln("<input type=\"radio\" name=\"" + name +
                     "\" value=\"" + value + "\" checked>");
  } else {
    document.writeln("<input type=\"radio\" name=\"" + name +
                     "\" value=\"" + value + "\">");
  }
}

function printSelectItem(caption, value, state, def) {
  if (state == value || (def && state == "")) {
    document.writeln("<option value=\"" + value + "\" selected>" + 
                     caption + "</option>");

  } else {
    document.writeln("<option value=\"" + value + "\">" + 
                     caption + "</option>");
  }
}

function clearAllInForm(formObj) {
  formObj.reset();
  /*
  var numObjs = formObj.length;
  //Search in all objects in form
  for (var i = 0; i < numObjs; i++) {
    var obj = formObj.elements(i);

    if (obj.type == "text") {
      //Clear value
      obj.value = "";
      continue;
    }
    if (obj.type=="textarea") {
      obj.value="";
      continue;
    }
    if (obj.type == "password") {
      //Clear value
      obj.value = "";
      continue;
    }
    if (obj.type=="fileUpload") {
      //CLiear value.
      obj.value="";
      continue;
    }
    if (obj.type == "select-one") {
      //Clear value
      if (obj.options[0] != null) {
        obj.options[0].selected = true;
      }
    }
  }
  */
}
