var elementSort = [];
elementSort['current'] = '';


jQuery.fn.sort = function() {
  return this.pushStack( [].sort.apply( this, arguments ), []);
};

getSortValue = function(value,type) {
  var revtal = null;
  if (type == "Date") {
    retval = Date.parse(value);    
    if (isNaN(retval)) retval = 0;
  } else {
    retval = value;
  }

  return retval;
}

sortBy = function(which,direction,type) {
  var $j = jQuery.noConflict();
  //alert(which + " - " + direction + " - " + type);
  if (direction == 'ascending') {
    $j("div.filesetentry").sort(function(a,b) {
      return getSortValue($j(a).find(which).html(),type) > getSortValue($j(b).find(which).html(),type) ? 1 : -1;
    }).appendTo("#filesets");
  } else {
    $j("div.filesetentry").sort(function(a,b) {
      return getSortValue($j(b).find(which).html(),type) > getSortValue($j(a).find(which).html(),type) ? 1 : -1;
    }).appendTo("#filesets");
  }
}

setupViewPageTables = function() {
  var $j = jQuery.noConflict();
 
  $j("#habitatPlanTable").dataTable({ 
    "bPaginate": false,
    "bLengthChange": false,
    "bFilter": false,
    "bSort": true, 
    "bInfo": false,
    "bAutoWidth": false,
    "asStripClasses": [],
    "aaSorting": [[ 0, "asc" ]],"aoColumns": [{ "sType": 'html'},{ "sType": 'html' },{ "sType": 'acres'},{ "sType": 'html' }]});

  $j("#projectIdentificationTable").dataTable({ 
    "bPaginate": false,
    "bLengthChange": false,
    "bFilter": false,
    "bSort": true, 
    "bInfo": false,
    "bAutoWidth": false,
    "asStripClasses": [],
    "aaSorting": [[ 0, "asc" ]],"aoColumns": [{ "sType": 'html'},{ "sType": 'html' }]});

  $j("#relatedHabitatImpactsTable").dataTable({ 
    "bPaginate": false,
    "bLengthChange": false,
    "bFilter": false,
    "bSort": true, 
    "bInfo": false,
    "bAutoWidth": false,
    "asStripClasses": [],
    "aaSorting": [[ 0, "asc" ]],"aoColumns": [{ "sType": 'html'},{"sType": 'acres'},{ "sType": 'html' }]});

  $j("#historicalHabitatsTable").dataTable({ 
    "bPaginate": false,
    "bLengthChange": false,
    "bFilter": false, 
    "bSort": true, 
    "bInfo": false,
    "bAutoWidth": false,
    "asStripClasses": [],
    "aaSorting": [[ 0, "asc" ]],"aoColumns": [{ "sType": 'html'},{"sType": 'acres'}]});

  $j("#sitesTable").dataTable({ 
    "bPaginate": false,
    "bLengthChange": false,
    "bFilter": false,
    "bSort": true, 
    "bInfo": false,
    "bAutoWidth": false,
    "asStripClasses": [],
    "aaSorting": [[ 0, "asc" ]],"aoColumns": [{ "sType": 'html'},{ "sType": 'html'},{"sType": 'acres'}]});

  $j("#eventsTable").dataTable({ 
    "bPaginate": false,
    "bLengthChange": false,
    "bFilter": false,
    "bSort": true, 
    "bInfo": false,
    "bAutoWidth": false,
    "asStripClasses": [],
    "aaSorting": [[ 0, "asc" ]],"aoColumns": [{ "sType": 'html'},{ "sType": 'html'},{"sType": 'html'}]});

  $j("#peopleTable").dataTable({ 
    "bPaginate": false,
    "bLengthChange": false,
    "bFilter": false,
    "bSort": true, 
    "bInfo": false,
    "bAutoWidth": false,
    "asStripClasses": [],
    "aaSorting": [[ 0, "asc" ]],"aoColumns": [{ "sType": 'html'},{ "sType": 'html'},{"sType": 'html'}]});

  $j("#cramAssessmentsTable").dataTable({ 
    "bPaginate": false,
    "bLengthChange": false,
    "bFilter": false,
    "bSort": true, 
    "bInfo": false,
    "bAutoWidth": false,
    "asStripClasses": [],
    "aaSorting": [[ 0, "asc" ]],"aoColumns": [{ "sType": 'date'},{ "sType": 'html'},{"sType": 'html'},{"sType": 'numeric'}]});

  $j("#performanceCriteriaTable").dataTable({ 
    "bPaginate": false,
    "bLengthChange": false,
    "bFilter": false,
    "bSort": true, 
    "bInfo": false,
    "bAutoWidth": false,
    "asStripClasses": [],
    "aaSorting": [[ 0, "asc" ]],"aoColumns": [{ "sType": 'html'},{ "sType": 'html'}]});
}

function adjustHeights() {
  var $j = jQuery.noConflict();
  hContent  = $j('#content').height();                         // Get height
  hLeftSide = $j('#leftside').height();                        // Get height
  mHeight = hContent > hLeftSide ? hContent : hLeftSide;       // Set mHeight to the larger of the two heights
  $j('#content').height(mHeight);                  // Set both to equal heights
  $j('#leftside').height(mHeight+4);
  $j('#main').height(mHeight+4);
}

