var containerCount = 0;

function batchIsolate(groupNumber){
	var tableRowCount = document.getElementById('productTable').rows.length;
	var batchCount = document.getElementById('batchCount').value;
	var rowPos = document.getElementById('batch'+groupNumber).rowIndex;
	var end = 0;
	if (groupNumber == batchCount){
		end = tableRowCount - 1;
	} else if (groupNumber < batchCount) {
		nextGroupNumber = groupNumber + 1;
		end = document.getElementById('batch'+nextGroupNumber).rowIndex - 1;
	}
	for(var i=rowPos+1;i<end+1;i++){
		if(document.getElementById('productTable').rows[i].style.display == ''){
			document.getElementById('productTable').rows[i].style.display = 'none';
			document.getElementById('batchLink'+groupNumber).innerHTML = '[ + ]';
		} else {
			document.getElementById('productTable').rows[i].style.display = '';
			document.getElementById('batchLink'+groupNumber).innerHTML = '[ - ]';			
		}
	}
	document.getElementById('batchLink'+groupNumber).blur();
}

function checkContainers() {
  $('#checkAllContainers').each(function() {
    if (this.checked) {  // check all container checkboxes
      $('.containerCheckBox').each(function() {
        this.checked = true;
      });
    } else {  // uncheck all container checkboxes
      $('.containerCheckBox').each(function() {
        this.checked = false;
      });
    }
  });
}

function submitUpdateContainers() {
  $('#attemptMultiUpdate').val('true');
  $('#attemptExport').val('false');
  $('#search').submit();
}

function getContainerUpdateHistory(containerID, containerNumber) {
  // alert('cID: ' + containerID + ", number: " + containerNumber);
  setPosBy('moreDisplay','historyImg'+containerID,18,5);
  $('#moreDisplay').show();
  loaderHeight('/images/loader.gif', 'loading container history', 'moreDisplay', 20);
  $('#historyLink'+containerID).blur();  
  $.get('/operations/container/getUpdateHistory.jsp?containerID='+containerID+'&containerNumber='+containerNumber, function(data) {
    $('#moreDisplay').html($.trim(data));
    setPosBy('moreDisplay','historyImg'+containerID,18,5);
    $('#moreDisplay').show();
  });
}

function retrieveContainerNotes() {  // cache the notes for all containers on the current search page
  var containerIdList = new Array();
  var counter = new Number(0);
  $('.containerIdList').each(function() {
    containerIdList[counter] = new Number(this.value);
    counter++;
  })
  if (containerIdList.length > 0) {
    containerCount = containerIdList.length;
    execContainerNotesLoad(containerIdList);
  }
}

function execContainerNotesLoad(containerIdList) {
  $.get('/operations/container/schedule/setContainerNotesList.jsp?containerIdList='+containerIdList, function(data){
    var error = new Number($.trim(data));
    if (error == 1) {  // session object successfuly set, now load up notes for each container
      updateSearchListWithNotes(containerIdList);
    } else {
      alert('There was a problem loading container notes!\n\nPlease contact an Pro Kinetics (Aust) Pty Ltd administrator if problems persist\nor email support@prokinetics.com.au.');
    }
  });
}

function updateSearchListWithNotes(containerIdList) {
  try {
    for (var i=0; i < containerIdList.length; i++) {
      containerCount--;
      fillContainerNotes(containerIdList[i]);
    }
  } catch (e) {  }
}

function fillContainerNotes(containerID) {
  $.get('/operations/container/schedule/getContainerNotes.jsp?containerID='+containerID, function(data){
    var error = new Number($.trim(data));
    if (error == 0) {
      return 0;
    } else {
      var content = $.trim(data);
      if (content.length > 0) {
        $('#containerNotes_'+containerID).html(content);
        $('#containerNotesRow_'+containerID).show();
      }
    }
    if (containerCount <= 0) {
      if (isIE6()) {
        var t = setTimeout('orderEditIe6()', 250);
      }
    } 
  });
}