//
// is4_setInput
//
function is4_setInput(inputId, inputVal) {
   var retVal = 0;
   if (inputId) {
      inputObj = document.getElementById(inputId);
   }
   if (inputObj) {
         inputObj.value = inputVal;
   }
   return retVal;
}

//
// is4_setSelected
//
// Set option element in select list as selected
//
// Arguments:
//  selectId    id of select element
//  selectVal   value for option element which has to be selected
//
// Returns:
//  0           if option not found or other error
//  1           if option found and selected has been set.
//
function is4_setSelected(selectId, selectVal) {
   var selectList;
   var retVal = 0;
   if (selectId) {
      selectList = document.getElementById(selectId);
   }
   if (selectList) {
         var optList = selectList.options;
         // EJT: Note: start of for loos was 0. Why ?
         for(o = 1; o < optList.length && !retVal; o++) {
             if (optList[o].value == selectVal) {
                     optList[o].selected = true;
                     retVal = 1;
             }
         }
   }
   return retVal;
}


//
// is4_getSelected
//
// Get selected option element value from select list
//
// Arguments:
//  selectList  select object
//
// Returns:
//  value       if option not found or other error
//  "undef"     if not found
//
function is4_getSelected(selectList) {
        var selectList;
        var retVal = 0;
        if (selectList) {
                var optList = selectList.options;
                for(o = 0; o < optList.length && !retVal; o++) {
                        if (optList[o].selected) {
                                return optList[o].value;
                        }
                }
        }
        return "undef";
}

//
// setChecked
//
// Arguments
//  cbId       id of checkbox object
//  cbChecked  checked status ('f' or 0 is NOT checked, anything other means true)
//
// Returns
//  0          if object found
//  1          if not found
//
function is4_setChecked(cbId, cbChecked) {
  var retVal = 0;
  if (cbId) {
          var cbObj = document.getElementById(cbId);
          if (cbObj) {
                  if (cbChecked == 'f' || cbChecked == '0') { cbObj.checked = false; }
                  else { cbObj.checked = true; }
                  retVal = 1;
          }
  }
  return retVal;
}


//
// getRadioId
//
// Arguments
//  radioName   name of radio input element
//  radioValue  value of target radio
//
// Returns
//  id          of input element
//  0           if not found
//
function is4_getRadioId(radioName, radioValue) {
  var pf = document.forms;
  boxType = "radio"; 
  for(f=0;f<pf.length;f++) {
     var ib = pf[f][radioName];
     if (ib) {
	     for(b=0;b<ib.length;b++) {
		     if (ib[b].value == radioValue) {
			     return ib[b].id;
		     }
	     }
     }
  }
  return 0;
}

//
// radioIsChecked
//
// Arguments
//  radioName   name of radio input element
//
// Returns
//  value of radio           if some value was checked
//  null                     if not 
//
function is4_radioIsChecked(radioObj) {
  retVal = null;
  if (radioObj.length) {
	  for (i=0;i<radioObj.length;i++) {
		  if (radioObj[i].checked) { retVal = 1; } // FIXME
	  }
  }
  return retVal;
}

//
// getCheckboxId
//
// Arguments
//  radioName   name of checkbox input element
//  radioValue  value of target checkbox
//
// Returns
//  id          of input element
//  0           if not found
//
function is4_getCheckboxId(radioName, radioValue) {
  var pf = document.forms;
  boxType = "checkbox";
  for(f=0;f<pf.length;f++) {
     var ib = pf[f][radioName];
     if (ib) {
	     for(b=0;b<ib.length;b++) {
		     if (ib[b].value == radioValue) {
			     return ib[b].id;
		     }
	     }
     }
  }
  return 0;
}

//
// clearCheckboxes
//
// Arguments
//  elmName     name of checkbox element
//
// Returns
//  0           
//
function is4_clearCheckboxes(elmName) {
  var pf = document.forms;
  boxType = "checkbox";
  for(f=0;f<pf.length;f++) {
     var ib = pf[f][elmName];
     if (ib) {
	     for(b=0;b<ib.length;b++) {
		     ib[b].checked = false;
	     }
     }
  }
  return 0;
}


//
// capitalizeFirst
//
// Arguments
//  somestring    string to capitalize the first word of
//
// Returns
//  Capitalized string
function is4_capitalizeFirst(somestring) {
        var retVal = somestring;
        if (somestring.length) {
          retVal = somestring.substring(0,1).toUpperCase()
                 + somestring.substring(1,somestring.length);
        }
        return retVal;
}


/*
**
** findForm
**
** finds containing form for the given object
** if instructed, submits form
**
** Arguments
**  obj           object to start search from
**  submitform    boolean indicating if the submit()
**                handler should be called on the found object
**
** Returns
**  formobject if found
**  null       otherwise
**
*/
function is4_findForm(obj, verzend) {
    while (obj && obj.tagName != "FORM" && obj.parentNode) {
        obj = obj.parentNode;
    }
    if (obj.tagName == "FORM") {
        if (verzend) {
            obj.submit();
        }
        return obj;
    }
    return null;
}


