/**
* Conference javascript functions
*/

//Initialise global variables
var confAbstractId = 0;
var spIndexId = 0;
var strSearchQuery = '';
var confCatid = 158;
var confSubcat = '';

//load and render conference abstracts by catid and/or search (Grid - centre)
function renderConferenceAbstracts(catid, strQuery, currentPage, elibId, spIndex, subcat) {
	getObj('renderAbstracts');
	if (!obj) return false;
	else
		obj.innerHTML = '<br/>Loading ...&nbsp;<img src="/core/assets/images/spinner_14.gif"/><br/><br/>';

	//set global variable
	strSearchQuery = strQuery;
	confCatid = catid;
	confSubcat = subcat;

	var strRequest = '/conference/ajax/ajaxDo.php?action=renderConfAbstracts&catid=' + catid + '&search=' + strQuery + '&page=' + currentPage + '&id=' + elibId + '&spindex=' + spIndex + '&subcat=' + subcat;
	sendRequest(strRequest, renderConferenceAbstracts_Callback);

}

//load and render conference abstracts callback function
function renderConferenceAbstracts_Callback(req) {
	//handle callback data from the ajax call
	var s = req.responseText;

	getObj('renderAbstracts');
	if (!obj) return false;
	else
		obj.innerHTML = s;

	searchtermHighlightId('renderAbstracts');	//highlight search word(s) if available
}

//load and render conference abstracts by catid and/or search (Grid - side)
function renderConferenceAbstractsSideGrid(catid, strQuery, currentPage, elibId, spIndex, subcat) {
	getObj('renderAbstractsSideGrid');
	if (!obj) return false;
	else
		obj.innerHTML = '<br/>Loading ...&nbsp;<img src="/core/assets/images/spinner_14.gif"/><br/><br/>';

	//set global variable
	strSearchQuery = strQuery;
	confCatid = catid;
	confSubcat = subcat;

	var strRequest = '/conference/ajax/ajaxDo.php?action=renderConfAbstractsSideGrid&catid=' + catid + '&search=' + strQuery + '&page=' + currentPage + '&id=' + elibId + '&spindex=' + spIndex + '&subcat=' + subcat;
	sendRequest(strRequest, renderConferenceAbstractsSideGrid_Callback);

}

//load and render conference abstracts callback function
function renderConferenceAbstractsSideGrid_Callback(req) {
	//handle callback data from the ajax call
	var s = req.responseText;

	getObj('renderAbstractsSideGrid');
	if (!obj) return false;
	else
		obj.innerHTML = s;

	searchtermHighlightId('renderAbstractsSideGrid');	//highlight search word(s) if available
}

//Load conference abstract (individual abstract)
function loadConferenceAbstract(intSPIndex, intId, showHidden) {

	//set global variables
	confAbstractId = intId;
	spIndexId = intSPIndex;

	var strRequest = '/conference/ajax/ajaxDo.php?action=loadConfAbstract&spindex=' + spIndexId + '&id=' + confAbstractId + '&showHidden' + showHidden;
	sendRequest(strRequest, loadConferenceAbstract_Callback);

}

//Load conference abstract callback function
function loadConferenceAbstract_Callback(req) {
	// handle callback data from the ajax call
	var s = req.responseText;

	getObj('renderConfAbstract');
	if (!obj) return false;
	else
		obj.innerHTML = s;

	searchtermHighlightId('renderConfAbstract');	//highlight search word(s) if available

	//call to display other abstracts related to selected conf abstract
	loadAbstractByAuthor(spIndexId, confAbstractId, 1);

}

//Load Abstract(s) by Author
function loadAbstractByAuthor(spIndexId, confAbstractId, selectedPage) {
	getObj('otherRelatedAbstract');
	if (!obj) return false;
	else
		obj.innerHTML = '<br/>Loading ...&nbsp;<img src="/core/assets/images/spinner_14.gif"/><br/><br/>';

	//call to display other abstracts related to selected conf abstract
	var strRequest = '/conference/ajax/ajaxDo.php?action=loadAbstractByAuthor&spindex=' + spIndexId + '&id=' + confAbstractId + '&pageno=' + selectedPage + '&search=' + strSearchQuery + '&catid=' + confCatid + '&subcat=' + confSubcat;
	sendRequest(strRequest, loadAbstractByAuthor_Callback);
}

//Load Abstract by Author callback function
function loadAbstractByAuthor_Callback(req) {
	// handle callback data from the ajax call
	var s = req.responseText;

	getObj('otherRelatedAbstract');
	if (!obj) return false;
	else
		obj.innerHTML = s;
}

//open abstract
function openAbstract(url, newWindow) {
	if (newWindow == 'yes')
		window.open(url, "conferenceAbstract");
	else
		document.location.href = url;
}

//reset filter options
function resetFilters() {
	var strRequest = '/conference/ajax/ajaxDo.php?action=resetFilters';
	sendRequest(strRequest, resetFilters_Callback);
}// function resetFilters

//render resetFilters callback function
function resetFilters_Callback(req) {
	var s = req.responseText;

	if (s != 'success') alert(s);// display message if error

	// redirect to linkDB page
	window.location.href = '/conference/browse.php';
}// function resetFilters_Callback
