function expandNarrative(order_line_id) {
  var line = document.getElementById('order_line_' + order_line_id + 'c');

  if (line.style.height == 'none') {
    line.style.display = 'inline';
  } else {
    line.style.display = 'none';
  }

}

function postbackUNSPSC(seg, fam, cls) {
  var f = document.getElementById('user_form');
  if (seg) f.action += '&next_seg=' + seg;
  if (fam) f.action += '&next_fam=' + fam;
  if (cls) f.action += '&next_cls=' + cls;
  f.submit();
}

function setAllPermissionImage(that) {

  if (that.options[that.selectedIndex].value == '1' || that.options[that.selectedIndex].value == '2') {
    switch (that.options[that.selectedIndex].value) {
      case '1':
        perm = 'Allowed';
        image = 'url(/images/ledgreen.16x16.png)';
        break;
      case '2':
        perm = 'Warning';
        image = 'url(/images/ledorange.16x16.png)';
        break;
    }

    if (window.confirm('Are you sure you want to set all permissions on this level and below to ' + perm + '?')) {
      var el = document.getElementById('td_0');
      el.style.backgroundImage = image;

      var nodes = document.getElementsByTagName('select');
      for (i=0;i<nodes.length;i++) {
        var id = nodes[i].id;
        if (id.substr(0, 7) == 'select_') {
          nodes[i].selectedIndex = that.selectedIndex;
          setPermissionImage(nodes[i], id.substring(7));
        }
      }
    }
  }

}
function setPermissionImage(that, id) {
  var el = document.getElementById('td_' + id);

  if (el) {
    switch (that.options[that.selectedIndex].value) {
      case '1':
        el.style.backgroundImage = 'url(/images/ledgreen.16x16.png)';
        break;
      case '2':
        el.style.backgroundImage = 'url(/images/ledorange.16x16.png)';
        break;
      default:
        el.style.backgroundImage = '';
    }
  }

  el = document.getElementById('dirty_' + id);
  if (el) el.value = '1';
}

function confirmOrderApprove() {
  return window.confirm('Are you sure you want to Approve this Order?');
}

function confirmOrderReject() {
  return window.confirm('Are you sure you want to Reject this Order?');
}

function confirmUserDelete() {
  return window.confirm('Are you sure you want to delete this User?');
}

function confirmAccountDelete() {
  return window.confirm('Are you sure you want to delete this Account?');
}

function confirmOrderLineDelete(order_line_id) {

  var deleted = document.getElementById('deleted_' + order_line_id);

  if (window.confirm('Are you sure you want to delete this line?')) {
    deleted.value = '1';
    document.getElementById('order_line_' + order_line_id + 'a').style.display = 'none';
    document.getElementById('order_line_' + order_line_id + 'b').style.display = 'none';
    document.getElementById('order_line_' + order_line_id + 'c').style.display = 'none';
  }
}
