/////////////////////////////////////////////////////////////////
// USED IN
// shorex/resultsNavigation.jsp

/* sets paging hidden fileds and submits */
function shorexSearchPaging(startingRowNumber) {
  searchForm = document.getElementById('shorexSearchForm');

  //sets startingRowNumber for paging ;
  searchForm.startingRowNumber.value = (startingRowNumber < 0) ? 0: startingRowNumber;

  formSubmit('shorexSearchForm', 'shorexSearch'); 
}

/////////////////////////////////////////////////////////////////
// USED IN
// shorex/shorexsearchform.jsp

function submitShorexSearchForm() {
  var shorexForm = document.getElementById('shorexSearchForm');
  var destinationCodeDropdown = getElement('destinationSelect');
  var portCodeDropdown = getElement('portSelectDiv').getElementsByTagName('select')[0];

  displayContent('errors.no.criteria.selected', 'hide');
  displayContent('errors.no.port.selected', 'hide');

  destinationCodeDropdown.className = destinationCodeDropdown.className.replace('error', '');
  portCodeDropdown.className = portCodeDropdown.className.replace('error', '');
  
  if (destinationCodeDropdown.value == 'ALL') {
    displayContent('errors.no.criteria.selected', 'show');
    destinationCodeDropdown.className += ' error';
    return false;
  } 

//  if (portCodeDropdown.value == 'ALL') {
//    displayContent('errors.no.port.selected', 'show');
//    portCodeDropdown.className += ' error';
//    return false;
//  }
  
  shorexForm.submit();
}

onloads.push(destinationChanged);

function destinationChanged() {
  if (getElement('destinationSelect') != null) {
    var destinationCode = getElement('destinationSelect').value;
    var previousValue = getElement('previousValue').value;
    
    // Replace the portCode dropdown
    sendAjaxRequest('shorex.html',
      'dispatch=getAjaxPortsDropdownForDestination'
      + '&destinationCode=' + destinationCode
      + '&propertyAndValue=portCode'
      + '&previousValue=' + previousValue
      + '&id=portSelectId', 
      'portSelectDiv');
  }
}
