/////////////////////////////////////////////////////////////////
// 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;
  }

  shorexForm.submit();
}

Evt.onContentReady('submit_search_form_button', function () {
	Evt.on('submit_search_form_button', 'click', function (e) {
		Evt.stopEvent(e);
		submitShorexSearchForm();
	});
});

/* Pulled from shorexLanding */
function showRegistration() {
	var container = document.getElementById('register_container');
	if(container != "undefined") {
		container.style.display = "block";
		container.style.visibility = "visible";
	}
	return;
}

function HideRegContainer()
{
	elem = document.getElementById('register_container');

	if(elem)
	{
		elem.style.visibility = 'visible';
		// not sure why it works, but it fixes swf font rendering while still allowing div with display:none property in IE6
		setTimeout("elem.style.display = 'none'", 0);
	}
}

App.register_component("YAHOO.util.App.Page", {
  initialize: function () {
  	Evt.on('destinationSelect', 'change', YAHOO.util.App.Page.destinationChanged);
		YAHOO.util.App.Page.destinationChanged();
	},

	destinationChanged: function () {
	  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');
	  }
	}
});
