function del_confirm(itm, qs, tbl) {//v1
  if (confirm("Are you sure you want to delete " + itm + " from " + tbl)) window.location.href = window.location.pathname+"?"+qs;
}

function textareaLimiter(field, maxlimit) {
  if (field.value.length > maxlimit) field.value = field.value.substring(0, maxlimit);
}

//find the checked radio button and return the checked value.
function getSelectedRadio(radiogroup) {
  if (radiogroup.length) {
    for (i=0; i<radiogroup.length; i++) {
      if (radiogroup[i].checked) return radiogroup[i].value;
    }
  } else if (radiogroup.value) {
      return radiogroup.value;
  }
  return 0;
}

function getStrArrayVal(str, i) {
  var arr = str.split('~');
  return arr[i];
}

function setContainerHeight(offset, container) {
  if (window.innerHeight) document.getElementById(container).style.height = (window.innerHeight - offset) + 'px';
  else if (document.body.clientHeight) document.getElementById(container).style.height = (document.body.clientHeight - offset) + 'px';
}

//Escapes apostrophes.
function fixQuotes(strText) {
  strText = strText.replace("'", "\\'")
  return(strText);
}

//function to handle page actions for table listing
function pageAction(strAction, strItem, strEditFile) {
  var idItem = 0;
  var fm = document.forms['fmListing'];
  if (fm.ID) idItem = getSelectedRadio(fm.ID);
  if (idItem > 0 || strAction == 'export' || strAction == 'add') {
    switch (strAction) {
      case 'add' :
        window.location.href = strEditFile;
        break;
      case 'delete' :
        del_confirm('this ' + strItem, 'action=delete&itm=' + idItem, 'the ' + strItem + ' list');
        break;
      case 'export' :
        var fmFilter = document.forms['fmFilter'];
        fmFilter.action = fmFilter.action + '?action=export';
	fmFilter.submit();
        break;
      default :
        window.location.href = strEditFile + '?action=' + strAction + '&itm=' + idItem;
        break;
    }
  } else {
    alert('Please select an ' + strItem + ' to ' + strAction);
  }
}