﻿/* SearchResults.js */

function SearchRefreshControl(type) {
	var container = $("._search_" + type),
		containerID = container[0].id,
		dto = SearchDTOs[type];
	showSpinnerLarge(containerID);
	Amway.Core.Web.UI.Search.SearchResultsControl.GetContainerHTML(type, SearchDTOs.ViewAllType, SearchDTOs.SearchTerm, dto.PageIndex, dto.PageSize, dto.SelectedSortValue, function(response) {
		container.html(response.value);
		hideSpinnerLarge(containerID);
	});
}

function SearchPaginationClick(pageIndex, type) {
	var dto = SearchDTOs[type];
	if (pageIndex == 'VIEWALL') {
		// Redirect to the view all page
		window.location.href = dto.ViewAllURL;
	} else if (pageIndex == 'VIEWFEWER') {
		window.location.href = dto.ViewFewerURL;
	} else {
		dto.PageIndex = pageIndex;
		SearchRefreshControl(type);
	}
}

function SearchSortClick(selectedSort, type) {
	var dto = SearchDTOs[type];
	dto.PageIndex = 0;
	dto.SelectedSortValue = selectedSort;
	SearchRefreshControl(type);
}

function SearchResultsClick(pageSize, type) {
	var dto = SearchDTOs[type];
	dto.PageSize = pageSize;
	SearchRefreshControl(type);
}