/*
	This file conatins the support functions for the searchresultsappearance
	template.
*/
// This function addresses the request of ascending order sorting on any attribute.
function sortAsc(attribName,formAction)
{
	//document.searchResultsForm.isSortingReq.value = "1";
	document.searchResultsForm.sortOrder.value = "1";
	document.searchResultsForm.sortOn.value = attribName;
	document.searchResultsForm.CMD.value = "SORT_ARTICLE_LIST";
	document.searchResultsForm.nextPageNo.value = 
									document.searchResultsForm.currPageNo.value;
//	setNextPageArticleIds(document.searchResultsForm.nextPageNo.value - 0.0);
//	alert("Ascending sort on " + attribName);
	postForm(formAction);
}

// This function addresses the request of descending order sorting on any attribute.
function sortDesc(attribName,formAction)
{
	document.searchResultsForm.isSortingReq.value = "1";
	document.searchResultsForm.sortOrder.value = "0";
	document.searchResultsForm.sortOn.value = attribName;
	document.searchResultsForm.CMD.value = "SORT_ARTICLE_LIST";
	document.searchResultsForm.nextPageNo.value =
									document.searchResultsForm.currPageNo.value;
//	setNextPageArticleIds(document.searchResultsForm.nextPageNo.value - 0.0);
//	alert("Descending sort on " + attribName);
	postForm(formAction);
}


// This function fetches the page corresponding to the page number passed.
function getPage(nextPageNo,formAction)
{
	document.searchResultsForm.nextPageNo.value = nextPageNo;
	//alert("The next page no is --- " + nextPageNo);
	//setNextPageArticleIds(nextPageNo);
	postForm(formAction);
}

// This function fetches the page previous to the current page.
function prevPage(formAction)
{
	var currPage = document.searchResultsForm.currPageNo.value - 0.0;
	var nextPage = 1;
	if(currPage > 1)
		nextPage = currPage - 1;
	document.searchResultsForm.nextPageNo.value = nextPage;
	//alert("The next page no is --- " + nextPage);
	//setNextPageArticleIds(nextPage);
	postForm(formAction);
}

// This function fetches the page next to the current page.
function nextPage(formAction)
{
	var currPage = document.searchResultsForm.currPageNo.value - 0.0;
	var lastpage = document.searchResultsForm.totalPages.value - 0.0;
	var nextPage = lastpage - 0.0;
	if(currPage != lastpage)
		nextPage = currPage + 1;
	document.searchResultsForm.nextPageNo.value = nextPage;
	//alert("The next page no is --- " + nextPage);
	//setNextPageArticleIds(nextPage);
	postForm(formAction);
}

// This function sets the next page article ids in the form.
/*function setNextPageArticleIds(pageNo)
{
	var articleIds = "";
	var allArticleIds = document.searchResultsForm.allArticleIds.value;
	var articlePerPage = document.searchResultsForm.articlePerPage.value - 0.0;
	var allArticleIdsArray = allArticleIds.split(',');
	var startIndex = (articlePerPage * (pageNo - 1));
	var endIndex = startIndex + articlePerPage;
	for(i=startIndex;i<endIndex;i++)
	{
		if(i == startIndex)
			articleIds += allArticleIdsArray[i];
		else
			articleIds += "," + allArticleIdsArray[i];
	}
	//alert("The next set of ids =" + articleIds)
	document.searchResultsForm.nextPageArticleIds.value = articleIds;
}*/

// This function opens a new article.
function getArticle(articleId,isNewWindow,formAction,currCMD, configurationId, partitionId)
{
	if(isNewWindow == 1){
		var theURL = formAction + "?CMD=VIEW_ARTICLE&ARTICLE_ID="+articleId+"&CURRENT_CMD="+currCMD;		
		theURL = theURL + "&CONFIGURATION=" + configurationId + "&PARTITION_ID" + partitionId;
		var randomNumber=Math.floor(Math.random()*101);
		var windowName = 'ArticleDetails'+ randomNumber;		
		var newArticleWind = window.open(theURL,windowName); 
		
		newArticleWind.focus();
	}
	else{
		postForm(formAction + "?CMD=VIEW_ARTICLE&ARTICLE_ID="+articleId);
	}
}

function postForm(action)
{
	document.searchResultsForm.action = action;
	document.searchResultsForm.method = "POST";
	document.searchResultsForm.submit();
}
