/*global AZCAT,YAHOO,viewOpensInNewWindow,editOpensInNewWindow,portal_url,
         unicodeEscape,nav_location_lookup,Comment,urllib_quote,alert */

/*jslint browser: true, unparam: true, sloppy: true, nomen: true, maxerr: 50,
    maxlen: 80, indent: 2 */

AZCAT.siteman.nodeTemplates = [];

AZCAT.siteman.nodeTemplates.getMultiSelectCheckboxes = (function () {
  var el = document.createElement('input');
  el.type = 'checkbox';
  el.name = 'copy_pasta_checkbox';
  return function () {
    return el.cloneNode(true);
  };
}());

AZCAT.siteman.nodeTemplates.getActions = (function () {
  var el = document.createElement('a');
  el.appendChild(document.createElement('img'));
  el.appendChild(document.createTextNode(''));
  return function () {
    return el.cloneNode(true);
  };
}());

AZCAT.siteman.nodeTemplates.img_header = (function () {
  var el = document.createElement('img');
  el.style.verticalAlign = 'middle';
  el.className = 'clickme';
  return function () {
    return el.cloneNode(true);
  };
}());

AZCAT.siteman.nodeTemplates.div_header = (function () {
  var el = document.createElement('div');
  el.className = "header_item";
  return function () {
    return el.cloneNode(true);
  };
}());

AZCAT.siteman.nodeTemplates.div_absolute_center = (function () {
  var el = document.createElement('div');
  el.className = 'absolute_center';
  return function () {
    return el.cloneNode(true);
  };
}());

AZCAT.siteman.nodeTemplates.getTitleAndView = (function () {
  var el = document.createElement('img');
  el.style.height = '22px';
  el.style.width = '16px';
  el.style.verticalAlign = 'Top';
  return function () {
    return el.cloneNode(true);
  };
}());

AZCAT.siteman.sortCols = {
  getTitleAndView: 'title',
  getTitleAndEdit: 'title',
  review_state: 'review_state',
  getId: 'id',
  exclude_from_search: 'exclude_from_search',
  exclude_from_sitemap: 'exclude_from_sitemap',
  CreationDate: 'creation_date_epoch',
  ModificationDate: 'modification_date_epoch',
  Creator: 'creator',
  modifier: 'modifier',
  effective: 'effective_epoch',
  expires: 'expires_epoch',
  content_type: 'content_type',
  portal_type: 'portal_type',
  getFileSize: 'file_size_raw',
  id: 'id',
  email: 'email',
  useHTMLEditor: 'useHTMLEditor',
  viewOpensInNewWindow: 'viewOpensInNewWindow',
  editOpensInNewWindow: 'editOpensInNewWindow',
  dateFormat: 'dateFormat',
  timeFormat: 'timeFormat',
  useFuzzyDates: 'useFuzzyDates',
  portal_skin: 'portal_skin',
  roles: 'roles',
  isMemberEnabled: 'isMemberEnabled',
  last_login_time: 'last_login_time_epoch',
  description: 'description',
  sort_order: 'sort_order'
};

AZCAT.siteman.displayCode = {
  getMultiSelectCheckboxes: function (info) {
    info.td.appendChild(AZCAT.siteman.nodeTemplates.getMultiSelectCheckboxes());
  },
  getActions: function (info) {
    var firstAction = info.row.actions[0], a, img, textNode;
    if (firstAction) {
      a = document.createElement('a');
      a.href = info.row.path + info.row.id + firstAction.href;
      img = document.createElement('img');
      img.alt = firstAction.title;
      img.title = firstAction.title;
      img.src = firstAction.icon;
      textNode = document.createTextNode(' ' + firstAction.title);
      a.appendChild(img);
      a.appendChild(textNode);
      info.td.appendChild(a);
    }
    info = null;
  },
  getTitleAndView: function (info) {
    var spacer, level, l, tree, a, textNode;
    if (info.isTree) {
      level = info.row.cmf_uid === info.root_cmf_uid ?
          0 :
          (info.row.path + info.row.id).match(/\//g).length -
            (info.root_path === '' ? 0 : info.root_path.match(/\//g).length);
      for (l = 0; l < level; l += 1) {
        spacer = AZCAT.siteman.nodeTemplates.getTitleAndView();
        spacer.src = !info.last[l] ? '/tree/vline.gif' : '/spacer.gif';
        spacer.className = 'spacer';
        info.td.appendChild(spacer);
        spacer = null;
      }
      tree = AZCAT.siteman.nodeTemplates.getTitleAndView();
      tree.className = info.hasSubitems ? 'clickme' : '';
      tree.src = [
        '/tree/', info.isLast ? 'l' : 't',
        info.hasSubitems ? info.isOpen ? 'm' : 'p' : 'n', '.gif'
      ].join('');
      info.td.appendChild(tree);
      tree = null;
    }
    a = document.createElement('a');
    a.href = a.title = info.row.path + info.row.id;
    if (viewOpensInNewWindow) {
      a.target = "_blank";
    }
    a.className = 'titlelink';
    textNode = document.createTextNode(unicodeEscape(info.row.title) ||
                                       '(No Title)');
    info.td.appendChild(document.createTextNode(' '));
    a.appendChild(textNode);
    info.td.appendChild(a);

    a = null;
    textNode = null;
    info = null;
  },
  getTitleAndViewSitemap: function (info) {
    var spacer, level, l, tree, a, textNode;
    if (info.isTree) {
      level = info.row.cmf_uid === info.root_cmf_uid ?
          0 :
          (info.row.path + info.row.id).match(/\//g).length -
            (info.root_path === '' ? 0 : info.root_path.match(/\//g).length);
      for (l = 0; l < level; l += 1) {
        spacer = AZCAT.siteman.nodeTemplates.getTitleAndView();
        spacer.src = !info.last[l] ? '/tree/vline.gif' : '/spacer.gif';
        spacer.className = 'spacer';
        info.td.appendChild(spacer);
        spacer = null;
      }
      tree = AZCAT.siteman.nodeTemplates.getTitleAndView();
      tree.className = info.hasSubitems ? 'clickme' : '';
      tree.src = [
        '/tree/', info.isLast ? 'l' : 't',
        info.hasSubitems ? info.isOpen ? 'm' : 'p' : 'n', '.gif'
      ].join('');
      info.td.appendChild(tree);
      tree = null;
    }
    a = document.createElement('a');
    a.href = a.title = info.row.path + info.row.id;
    if (viewOpensInNewWindow) {
      a.target = "_blank";
    }
    a.className = 'titlelink';
    textNode = document.createTextNode(unicodeEscape(info.row.title_sitemap) ||
                                       '(No Title)');
    info.td.appendChild(document.createTextNode(' '));
    a.appendChild(textNode);
    info.td.appendChild(a);

    a = null;
    textNode = null;
    info = null;
  },
  getTitleAndEdit: function (info) {
    var spacer, level, tree, a, i, iLen, thisAction, item_url, div, img,
      l, effective_id, createVersionIndex = -1, textNode;

    // Create the view image
    div = document.createElement("div");
    YAHOO.util.Dom.setStyle(div, "float", "right");
    YAHOO.util.Dom.setStyle(div, "height", "16px");
    YAHOO.util.Dom.setStyle(div, "width", "16px");
    YAHOO.util.Dom.setStyle(div, "padding-left", "6px");
    a = document.createElement("a");
    a.href =
      info.row.path +
      info.row.id +
      (info.row.id !== '/' && info.row.view ? '/' : '') +
      info.row.view;
    a.title = info.row.title;
    if (viewOpensInNewWindow) {
      a.target = "_blank";
    }
    img = document.createElement('img');
    img.src = "/eye.png";
    img.className = "view_link_image";
    a.appendChild(img);
    div.appendChild(a);
    info.td.appendChild(div);

    if (YAHOO.env.ua.ie && YAHOO.env.ua.ie <= 7) {
      YAHOO.util.Event.onContentReady(info.td.id, function (col) {
        var getEl = YAHOO.util.Dom.getElementsByClassName, i, iLen,
          childWidthSum;
        col = document.getElementById(col);
        if (getEl(
            'view_link_image',
            'img',
            col
          )[0].parentNode.parentNode.offsetTop !== getEl(
            'titlelink',
            'a',
            col
          )[0].offsetTop) {
          childWidthSum = 0;
          for (i = 0, iLen = col.childNodes.length; i < iLen; i += 1) {
            if (!YAHOO.lang.isUndefined(col.childNodes[i].scrollWidth)) {
              childWidthSum += col.childNodes[i].scrollWidth;
            }
          }
          childWidthSum += parseInt(YAHOO.util.Dom.getStyle(col,
                                                            "padding-left"),
                                    10);
          childWidthSum += parseInt(YAHOO.util.Dom.getStyle(col,
                                                            "padding-right"),
                                    10);
          YAHOO.util.Dom.setStyle(col, "width", childWidthSum + "px");
        }
      }, info.td.id);
    }

    if (info.isTree) {
      level = info.row.cmf_uid === info.root_cmf_uid ?
          0 :
          (info.row.path + info.row.id).match(/\//g).length -
            (info.root_path === '' ? 0 : info.root_path.match(/\//g).length);
      for (l = 0; l < level; l += 1) {
        spacer = AZCAT.siteman.nodeTemplates.getTitleAndView();
        spacer.src = !info.last[l] ? '/tree/vline.gif' : '/spacer.gif';
        spacer.className = 'spacer';
        info.td.appendChild(spacer);
        spacer = null;
      }
      tree = AZCAT.siteman.nodeTemplates.getTitleAndView();
      tree.className = info.hasSubitems ? 'clickme' : '';
      tree.src = [
        '/tree/', info.isLast ? 'l' : 't',
        info.hasSubitems ? info.isOpen ? 'm' : 'p' : 'n', '.gif'
      ].join('');
      info.td.appendChild(tree);
      tree = null;
    }
    a = document.createElement('a');
    a.title = info.row.path + info.row.id;
    for (i = 0, iLen = info.row.actions.length; i < iLen; i += 1) {
      thisAction = info.row.actions[i];
      if (thisAction.id === 'edit') {
        item_url = info.row.path + info.row.id;
        if (item_url === '/') {
          effective_id = '';
        } else {
          effective_id = item_url;
        }
        if (thisAction.href.match(/^https?:\/\//)) {
          a.href = thisAction.href;
        } else if (thisAction.href) {
          a.href = portal_url + effective_id + thisAction.href;
        }
        break;
      } else if (thisAction.id === 'about_to_create_version') {
        createVersionIndex = i;
      }
    }

    if (!a.href && createVersionIndex !== -1) {
      thisAction = info.row.actions[createVersionIndex];
      item_url = info.row.path + info.row.id;
      if (item_url === '/') {
        effective_id = '';
      } else {
        effective_id = item_url;
      }
      if (thisAction.href.match(/^https?:\/\//)) {
        a.href = thisAction.href;
      } else if (thisAction.href) {
        a.href = portal_url + effective_id + thisAction.href;
      }
    }

    if (editOpensInNewWindow) {
      a.target = "_blank";
    }
    a.className = 'titlelink';
    a.title = 'Edit this item';
    textNode = document.createTextNode(unicodeEscape(info.row.title) ||
                                       '(No Title)');
    info.td.appendChild(document.createTextNode(' '));
    a.appendChild(textNode);
    info.td.appendChild(a);

    img = null;
    div = null;
    a = null;
    textNode = null;
    info = null;
  },
  getIcon: function (info) {
    var img = document.createElement('img');
    img.src = info.row.icon;
    img.alt = 'Icon';
    info.td.appendChild(img);
    info = null;
  },
  review_state: function (info) {
    var returntext = [], now;
    if (info.row.cmf_uid) {
      returntext.push(info.row.review_state);
    }
    if (info.row.expires_epoch && info.row.effective_epoch) {
      now = new Date();
      if (new Date(info.row.expires_epoch * 1000) < now) {
        returntext.push(' (Expired)');
      } else if (new Date(info.row.effective_epoch * 1000) > now) {
        returntext.push(' (Future)');
      }
    }
    info.td.appendChild(document.createTextNode(returntext.join('')));
    info = null;
  },
  getId: function (info) {
    info.td.appendChild(document.createTextNode(info.row.id));
    info = null;
  },
  exclude_from_search: function (info) {
    info.td.style.textTransform = 'capitalize';
    info.td.appendChild(document.createTextNode(!info.row.exclude_from_search));
    info = null;
  },
  exclude_from_sitemap: function (info) {
    info.td.style.textTransform = 'capitalize';
    info.td.appendChild(
      document.createTextNode(!info.row.exclude_from_sitemap)
    );
    info = null;
  },
  CreationDate: function (info) {
    info.td.appendChild(document.createTextNode(info.row.creation_date));
    info = null;
  },
  ModificationDate: function (info) {
    info.td.appendChild(document.createTextNode(info.row.modification_date));
    info = null;
  },
  Creator: function (info) {
    info.td.appendChild(document.createTextNode(info.row.creator));
    info = null;
  },
  modifier: function (info) {
    info.td.appendChild(document.createTextNode(info.row.modifier));
    info = null;
  },
  effective: function (info) {
    info.td.appendChild(document.createTextNode(info.row.effective));
    info = null;
  },
  'expires': function (info) {
    info.td.appendChild(document.createTextNode(info.row.expires));
    info = null;
  },
  content_type: function (info) {
    info.td.appendChild(document.createTextNode(info.row.content_type));
    info = null;
  },
  portal_type: function (info) {
    info.td.appendChild(document.createTextNode(info.row.portal_type));
    info = null;
  },
  getFileSize: function (info) {
    info.td.appendChild(document.createTextNode(info.row.file_size));
    info = null;
  },
  getThumbnail: function (info) {
    var div, a, img;
    if (!info.row.thumbnail.src) {
      return;
    }
    if (!info.row.thumbnail.url) {
      return;
    }
    div = AZCAT.siteman.nodeTemplates.div_absolute_center();
    if (info.row.thumbnail.width) {
      div.style.width = info.row.thumbnail.width + 'px';
    }
    if (info.row.thumbnail.height) {
      div.style.height = info.row.thumbnail.height + 'px';
    }
    a = document.createElement('a');
    a.href = info.row.thumbnail.url;
    a.target = "_blank";
    a.title = info.row.title;
    a.classname = 'thumbnail_link';
    img = document.createElement('img');
    img.src = info.row.thumbnail.src;
    img.className = 'thumbnail';
    a.appendChild(img);
    div.appendChild(a);
    info.td.appendChild(div);
    div = null;
    a = null;
    img = null;
    info = null;
  },
  getImagesHeightAndWidth: function (info) {
    info.td.appendChild(document.createTextNode(info.row.dimensions));
    info = null;
  },
  id: function (info) {
    var a, i, iLen, thisAction, item_url, div, img, effective_id,
      createVersionIndex = -1, textNode;

    a = document.createElement('a');
    a.title = info.row.path + info.row.id;
    for (i = 0, iLen = info.row.actions.length; i < iLen; i += 1) {
      thisAction = info.row.actions[i];
      if (thisAction.id === 'edit') {
        item_url = info.row.path + info.row.id;
        if (item_url === '/') {
          effective_id = '';
        } else {
          effective_id = item_url;
        }
        if (thisAction.href.match(/^https?:\/\//)) {
          a.href = thisAction.href;
        } else if (thisAction.href) {
          a.href = portal_url + effective_id + thisAction.href;
        }
        break;
      } else if (thisAction.id === 'about_to_create_version') {
        createVersionIndex = i;
      }
    }

    if (!a.href && createVersionIndex !== -1) {
      thisAction = info.row.actions[createVersionIndex];
      item_url = info.row.path + info.row.id;
      if (item_url === '/') {
        effective_id = '';
      } else {
        effective_id = item_url;
      }
      if (thisAction.href.match(/^https?:\/\//)) {
        a.href = thisAction.href;
      } else if (thisAction.href) {
        a.href = portal_url + effective_id + thisAction.href;
      }
    }

    if (editOpensInNewWindow) {
      a.target = "_blank";
    }
    a.className = 'titlelink';
    a.title = 'Edit this item';
    textNode = document.createTextNode(unicodeEscape(info.row.id));
    info.td.appendChild(document.createTextNode(' '));
    a.appendChild(textNode);
    info.td.appendChild(a);

    img = null;
    div = null;
    a = null;
    textNode = null;
    info = null;
  },
  email: function (info) {
    info.td.appendChild(document.createTextNode(info.row.email));
    info = null;
  },
  useHTMLEditor: function (info) {
    info.td.appendChild(document.createTextNode(info.row.useHTMLEditor));
    info = null;
  },
  viewOpensInNewWindow: function (info) {
    info.td.appendChild(document.createTextNode(info.row.viewOpensInNewWindow));
    info = null;
  },
  editOpensInNewWindow: function (info) {
    info.td.appendChild(document.createTextNode(info.row.editOpensInNewWindow));
    info = null;
  },
  dateFormat: function (info) {
    info.td.appendChild(document.createTextNode(info.row.dateFormat));
    info = null;
  },
  timeFormat: function (info) {
    info.td.appendChild(document.createTextNode(info.row.timeFormat));
    info = null;
  },
  useFuzzyDates: function (info) {
    info.td.appendChild(document.createTextNode(info.row.useFuzzyDates));
    info = null;
  },
  portal_skin: function (info) {
    info.td.appendChild(document.createTextNode(info.row.portal_skin));
    info = null;
  },
  roles: function (info) {
    info.td.appendChild(document.createTextNode(info.row.roles.join(", ")));
    info = null;
  },
  isMemberEnabled: function (info) {
    info.td.appendChild(document.createTextNode(info.row.isMemberEnabled));
    info = null;
  },
  last_login_time: function (info) {
    info.td.appendChild(document.createTextNode(info.row.last_login_time));
    info = null;
  },
  nav_location: function (info) {
    info.td.appendChild(
      document.createTextNode(nav_location_lookup[info.row.nav_location])
    );
    info = null;
  },
  comments: function (info) {
    var dummy = new Comment(info.td, info.row.comments);
    info = null;
  },
  description: function (info) {
    info.td.appendChild(document.createTextNode(info.row.description));
    info = null;
  },
  sort_order: function (info) {
    info.td.appendChild(document.createTextNode(info.row.sort_order));
    info = null;
  }
};

AZCAT.siteman.dataToColumns = {
  'actions': ['getActions', 'getTitleAndEdit', 'id'],
  'path': ['getActions', 'getTitleAndView', 'getTitleAndEdit'],
  'id': ['getActions', 'getTitleAndView', 'getTitleAndEdit', 'getId', 'id'],
  'view': ['getTitleAndEdit'],
  'title': ['getTitleAndView', 'getTitleAndEdit', 'getTitleAndViewSitemap',
            'getThumbnail'],
  'title_sitemap': ['getTitleAndViewSitemap'],
  'icon': ['getIcon'],
  'review_state': ['review_state'],
  'exclude_from_search': ['exclude_from_search'],
  'exclude_from_sitemap': ['exclude_from_sitemap'],
  'creation_date': ['CreationDate'],
  'modification_date': ['ModificationDate'],
  'creator': ['Creator'],
  'modifier': ['modifier'],
  'effective': ['effective'],
  'expires': ['expires'],
  'content_type': ['content_type'],
  'portal_type': ['portal_type'],
  'file_size': ['getFileSize'],
  'thumbnail': ['getThumbnail'],
  'dimensions': ['getImagesHeightAndWidth'],
  'email': ['email'],
  'useHTMLEditor': ['useHTMLEditor'],
  'viewOpensInNewWindow': ['viewOpensInNewWindow'],
  'editOpensInNewWindow': ['editOpensInNewWindow'],
  'dateFormat': ['dateFormat'],
  'timeFormat': ['timeFormat'],
  'useFuzzyDates': ['useFuzzyDates'],
  'portal_skin': ['portal_skin'],
  'roles': ['roles'],
  'isMemberEnabled': ['isMemberEnabled'],
  'last_login_time': ['last_login_time'],
  'nav_location': ['nav_location'],
  'comments': ['comments'],
  'description': ['description'],
  'sort_order': ['sort_order']
};

AZCAT.siteman.columnInfo = {
  'getTitleAndView': {
    'column_header': 'Name',
    'dropdown_header': 'Name',
    'sortable': true,
    'removable' : false
  },
  'getTitleAndEdit': {
    'column_header': 'Name',
    'dropdown_header': 'Name',
    'sortable': true,
    'removable' : false
  },
  'getTitleAndViewSitemap': {
    'column_header': 'Name',
    'dropdown_header': 'Name',
    'sortable': false,
    'removable' : false
  },
  'getActions': {
    'column_header': 'Default Task',
    'dropdown_header': 'Default Task',
    'sortable': false,
    'removable' : true
  },
  'CreationDate': {
    'column_header': 'Created',
    'dropdown_header': 'Created',
    'sortable': true,
    'removable' : true
  },
  'Creator': {
    'column_header': 'Created by',
    'dropdown_header': 'Created by',
    'sortable': true,
    'removable' : true
  },
  'modifier': {
    'column_header': 'Modified by',
    'dropdown_header': 'Modified by',
    'sortable': true,
    'removable' : true
  },
  'effective': {
    'column_header': 'Effective',
    'dropdown_header': 'Effective',
    'sortable': true,
    'removable' : true
  },
  'expires': {
    'column_header': 'Expires',
    'dropdown_header': 'Expires',
    'sortable': true,
    'removable' : true
  },
  'getIcon': {
    'column_header': '',
    'dropdown_header': 'Icon',
    'sortable': false,
    'removable' : true
  },
  'getId': {
    'column_header': 'Address',
    'dropdown_header': 'Address',
    'sortable': true,
    'removable' : true
  },
  'ModificationDate': {
    'column_header': 'Modified',
    'dropdown_header': 'Modified',
    'sortable': true,
    'removable' : true
  },
  'review_state': {
    'column_header': 'Status',
    'dropdown_header': 'Status',
    'sortable': true,
    'removable' : true
  },
  'exclude_from_search': {
    'column_header': 'Searchable',
    'dropdown_header': 'Searchable',
    'sortable': true,
    'removable' : true
  },
  'exclude_from_sitemap': {
    'column_header': 'In Sitemap',
    'dropdown_header': 'In Sitemap',
    'sortable': true,
    'removable' : true
  },
  'getImagesHeightAndWidth': {
    'column_header': 'Dimensions',
    'dropdown_header': 'Dimensions',
    'sortable': false,
    'removable' : true
  },
  'getThumbnail': {
    'column_header': 'Thumbnail',
    'dropdown_header': 'Thumbnail',
    'sortable': false,
    'removable' : true
  },
  'getMultiSelectCheckboxes': {
    'column_header': '<input type="checkbox" id="headers_select_all" />',
    'column_header_onclick': function (e) {
      var el, resultsLength, allOpen, openTo, x, xLen, cmf_uid, batchSize,
        filling, inputs, tbody, tr;
      el = YAHOO.util.Event.getTarget(e);
      if (el.nodeName.toLowerCase() !== "input") {
        el = YAHOO.util.Dom.getElementBy(function (el) {
          return el.type.toLowerCase() === "checkbox";
        }, "input", el);
        el.checked = !el.checked;
      }
      resultsLength = AZCAT.siteman.data.getListLength();
      if (resultsLength > 200) {
        alert(
          "Sorry, the select all button doesn't handle large results sets well."
        );
        el.checked = false;
        return;
      }
      if (AZCAT.siteman.dataView._isTree) {
        if (el.checked) {
          allOpen = true;
          openTo = AZCAT.siteman.dataView._openTo;
          for (x = 0, xLen = AZCAT.siteman.data._display_order.length;
               x < xLen;
               x += 1) {
            cmf_uid = AZCAT.siteman.data._display_order[x];
            if (!openTo.hasOwnProperty(cmf_uid) &&
                AZCAT.siteman.data.getTreeNode(cmf_uid).subitems.length) {
              AZCAT.siteman.dataView._openTo[cmf_uid] = true;
              allOpen = false;
            }
          }
          if (allOpen) {
            // If everything is open we don't need to update items from server.
            tbody = document.getElementById("site_manager_tbody");
            inputs = tbody.getElementsByTagName("input");
            for (x = 0, xLen = inputs.length; x < xLen; x += 1) {
              if (inputs[x].name === "copy_pasta_checkbox" &&
                  !inputs[x].checked) {
                inputs[x].checked = true;
                AZCAT.siteman.dataView._toggleItemSelection(
                  inputs[x],
                  false,
                  true
                );
              }
            }
            AZCAT.siteman.dataView._updateActiveSidebarActions();
          } else {
            AZCAT.siteman.data.updateItemsFromServer(function (allDirty) {
              var filling, inputs, x, xLen;
              this.updateDisplay(true);
              filling = document.getElementById(
                "filling__" + AZCAT.siteman.data.prefs_id
              );
              inputs = filling.getElementsByTagName("input");
              for (x = 0, xLen = inputs.length; x < xLen; x += 1) {
                if (inputs[x].id === "headers_select_all") {
                  inputs[x].checked = true;
                } else if (inputs[x].name === "copy_pasta_checkbox") {
                  inputs[x].checked = true;
                  this._toggleItemSelection(inputs[x], false, true);
                }
              }
              this._updateActiveSidebarActions();
            }, AZCAT.siteman.dataView);
          }
        } else {
          tbody = document.getElementById("site_manager_tbody");
          inputs = tbody.getElementsByTagName("input");
          for (x = 0, xLen = inputs.length; x < xLen; x += 1) {
            if (inputs[x].name === "copy_pasta_checkbox") {
              tr = YAHOO.util.Dom.getAncestorByTagName(inputs[x], "tr");
              cmf_uid = tr.id.split("_");
              cmf_uid = cmf_uid[cmf_uid.length - 1];
              inputs[x].checked = false;
              AZCAT.siteman.dataView._toggleItemSelection(
                inputs[x],
                false,
                true
              );
            }
          }
          AZCAT.siteman.dataView._updateActiveSidebarActions();
        }
      } else if (AZCAT.siteman.dataView._isList) {
        if (el.checked) {
          AZCAT.siteman.dataView._disablePerPage();
          batchSize =
            AZCAT.siteman.data._batching.perPageSelect *
            AZCAT.siteman.data._batching.perRowSelect;
          if (batchSize < resultsLength) {
            // we need to deal with batching by making it unbatched.
            AZCAT.siteman.data._batching.perPageSelect = resultsLength;
            AZCAT.siteman.data._batching.start = 0;
            AZCAT.siteman.data.updateItemsFromServer(function (allDirty) {
              var filling, inputs, x, xLen;
              this.updateDisplay(true);
              filling = document.getElementById(
                "filling__" + AZCAT.siteman.data.prefs_id
              );
              inputs = filling.getElementsByTagName("input");
              for (x = 0, xLen = inputs.length; x < xLen; x += 1) {
                if (inputs[x].id === "headers_select_all") {
                  inputs[x].checked = true;
                } else if (inputs[x].name === "copy_pasta_checkbox") {
                  inputs[x].checked = true;
                  this._toggleItemSelection(inputs[x], false, true);
                }
              }
              this._updateActiveSidebarActions();
            }, AZCAT.siteman.dataView);
          } else {
            filling = document.getElementById(
              "filling__" + AZCAT.siteman.data.prefs_id
            );
            inputs = filling.getElementsByTagName("input");
            for (x = 0, xLen = inputs.length; x < xLen; x += 1) {
              if (inputs[x].name === "copy_pasta_checkbox" &&
                  !inputs[x].checked) {
                inputs[x].checked = true;
                AZCAT.siteman.dataView._toggleItemSelection(
                  inputs[x],
                  false,
                  true
                );
              }
            }
            AZCAT.siteman.dataView._updateActiveSidebarActions();
          }
        } else {
          AZCAT.siteman.dataView._enablePerPage();
          if (
            AZCAT.siteman.data._batching.perPageSelect ===
              AZCAT.siteman.prefs.getPreference(
                "perPage",
                AZCAT.siteman.data.prefs_id
              )
          ) {
            filling = document.getElementById(
              "filling__" + AZCAT.siteman.data.prefs_id
            );
            inputs = filling.getElementsByTagName("input");
            for (x = 0, xLen = inputs.length; x < xLen; x += 1) {
              if (inputs[x].name === "copy_pasta_checkbox") {
                inputs[x].checked = false;
                AZCAT.siteman.dataView._toggleItemSelection(
                  inputs[x],
                  false,
                  true
                );
              }
            }
            AZCAT.siteman.dataView._updateActiveSidebarActions();
          } else {
            AZCAT.siteman.data._batching.perPageSelect =
              AZCAT.siteman.prefs.getPreference(
                "perPage",
                AZCAT.siteman.data.prefs_id
              );
            AZCAT.siteman.data.getBatchDataAndUpdateItemsFromServer();
          }
          AZCAT.siteman.dataView._updatePerPage();
        }
      }
    },
    'dropdown_header': 'Multi-Select Boxes',
    'sortable': false,
    'removable' : false
  },
  'getFileSize': {
    'column_header': 'Filesize',
    'dropdown_header': 'Filesize',
    'sortable': true,
    'removable' : true
  },
  'content_type': {
    'column_header': 'Type',
    'dropdown_header': 'Type',
    'sortable': true,
    'removable' : true
  },
  'portal_type': {
    'column_header': 'Type',
    'dropdown_header': 'Type',
    'sortable': true,
    'removable' : true
  },
  'id': {
    'column_header': 'ID',
    'dropdown_header': 'ID',
    'sortable': true,
    'removable' : true
  },
  'email': {
    'column_header': 'Email',
    'dropdown_header': 'Email',
    'sortable': true,
    'removable' : true
  },
  'useHTMLEditor': {
    'column_header': 'Use HTML Editor?',
    'dropdown_header': 'Use HTML Editor?',
    'sortable': true,
    'removable' : true
  },
  'viewOpensInNewWindow': {
    'column_header': 'View Opens In New Window?',
    'dropdown_header': 'View Opens In New Window',
    'sortable': true,
    'removable' : true
  },
  'editOpensInNewWindow': {
    'column_header': 'Edit Opens In New Window?',
    'dropdown_header': 'Edit Opens In New Window',
    'sortable': true,
    'removable' : true
  },
  'dateFormat': {
    'column_header': 'Date Format',
    'dropdown_header': 'Date Format',
    'sortable': true,
    'removable' : true
  },
  'timeFormat': {
    'column_header': 'Time Format',
    'dropdown_header': 'Time Format',
    'sortable': true,
    'removable' : true
  },
  'useFuzzyDates': {
    'column_header': 'Use Fuzzy Dates?',
    'dropdown_header': 'Use Fuzzy Dates?',
    'sortable': true,
    'removable' : true
  },
  'portal_skin': {
    'column_header': 'Skin',
    'dropdown_header': 'Skin',
    'sortable': true,
    'removable' : true
  },
  'roles': {
    'column_header': 'Roles',
    'dropdown_header': 'Roles',
    'sortable': true,
    'removable' : true
  },
  'isMemberEnabled': {
    'column_header': 'Account Enabled?',
    'dropdown_header' : 'Account Enabled?',
    'sortable': true,
    'removable' : true
  },
  'last_login_time': {
    'column_header': 'Last Login',
    'dropdown_header' : 'Last Login',
    'sortable': true,
    'removable' : true
  },
  'nav_location': {
    'column_header': 'Menu',
    'dropdown_header': 'Menu',
    'sortable': false,
    'removable' : true
  },
  'comments': {
    'column_header': 'Comments',
    'dropdown_header': 'Comments',
    'sortable': false,
    'removable' : true
  },
  'description': {
    'column_header': 'Filter Text',
    'dropdown_header': 'Filter Text',
    'sortable': true,
    'removable' : true
  },
  'sort_order': {
    'column_header': 'Sort Order',
    'dropdown_header': 'Sort Order',
    'sortable': true,
    'removable' : true
  }
};

AZCAT.siteman.infoColumnGroupings = {
  'General': [
    'getTitleAndView', 'getId', 'Creator', 'CreationDate', 'modifier',
    'ModificationDate', 'content_type', 'portal_type', 'getFileSize'
  ],
  'Workflow & Visibility': [
    'review_state', 'exclude_from_search', 'exclude_from_sitemap', 'effective',
    'expires'
  ],
  'Image': ['getImagesHeightAndWidth', 'getThumbnail']
};

AZCAT.siteman.deleteColumns = {
  'index_html': ['getTitleAndView', 'review_state'],
  'files': ['getTitleAndView', 'review_state'],
  'images': ['getTitleAndView', 'review_state'],
  'pdfs': ['getTitleAndView', 'review_state'],
  'default': ['getTitleAndView', 'review_state']
};

