/* Research Database Management System (RDMS)
 ' Copyright(C) 2008 Graham Philips
 ' RDMS is licensed under the GNU General Public License.
 ' Please See license.html or http://www.gnu.org/licenses/gpl.txt for the full license
 ' If there are problems, see http://sourceforge.net/projects/rdms/ for support.
 '
 ' RDMS comes with ABSOLUTELY NO WARRANTY
 '  
 ' This program is free software; you can redistribute it and/or modify it under
 ' the terms of the GNU General Public License as published by the Free Software
 ' Foundation; either version 2 of the License, or (at your option) any later
 ' version. */

 /* Main Paper Functions */

function lookupPaperFormJournals(paperID,stageLimit)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Loading Journals...]";
	xmlHttp = new GetXmlHttpObject();
	var journalLookup = escape(document.getElementById('journalLookup').value);
	if (journalLookup.length < 3)
	{
		document.getElementById('messageDisplayBox').innerHTML = "Please enter at least 3 characters";
	}
	else
	{
		url = "/includes/ajax/paper/lookuppaperformjournals.asp?paperID="+paperID+
			"&stageLimit="+stageLimit+"&journalLookup="+journalLookup+"&sid="+Math.random();
		xmlHttp.onreadystatechange = function(){xmlHttpResponse('messageDisplayBox','','contextLoadForm');};
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}

function addPaperJournalForm()
{
	document.getElementById('messageDisplayBox').innerHTML = "[Loading Journal Form...]";
	xmlHttp = new GetXmlHttpObject();
	url = "/includes/ajax/paper/addpaperjournalform.asp?sid="+Math.random();
	xmlHttp.onreadystatechange = function(){xmlHttpResponse('messageDisplayBox','','contextLoadForm');};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function submitPaperJournalForm()
{
	var errorFlag = 0;
	document.getElementById('pubNameMessage').innerHTML = "";
	document.getElementById('pubAbbrevMessage').innerHTML = "";
	document.getElementById('pubLanguageMessage').innerHTML = "";
	var pubName = escape(document.getElementById('pubName').value);
	var pubAbbrev = escape(document.getElementById('pubAbbrev').value);
	var languageSelect = document.getElementById('pubLanguage');
	var pubLanguage = languageSelect.options[languageSelect.selectedIndex].value;
	if (pubName.length < 1)
	{
		document.getElementById('pubNameMessage').innerHTML = "You must enter a journal title!";
		errorFlag = 1;
	}
	if (pubAbbrev.length < 1)
	{
		document.getElementById('pubAbbrevMessage').innerHTML = "You must enter a journal abbreviation!";
		errorFlag = 1;
	}
	if (pubLanguage == "Unselected")
	{
		document.getElementById('pubLanguageMessage').innerHTML = "You must enter a journal language!";
		errorFlag = 1;
	}
	if (errorFlag == 1)
	{
		return false;
	}
}

function confirmPaperJournal(paperID,journalID,stageLimit)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Selecting Journal...]";
	xmlHttp = new GetXmlHttpObject();
	url = "/includes/ajax/paper/confirmpaperjournal.asp?paperID="+paperID+
		"&stageLimit="+stageLimit+"&journalID="+journalID+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){xmlHttpResponse('contextLoadForm','','mainFormBox');};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function submitBasicPaperForm()
{
	var errorFlag = 0;
	document.getElementById('paperJournalIssueMessage').innerHTML = "";
	document.getElementById('paperTitleMessage').innerHTML = "";
	var paperJournalIssue = escape(document.getElementById('paperJournalIssue').value);
	var paperTitle = escape(document.getElementById('paperTitle').value);
	if (paperJournalIssue.length < 1)
	{
		document.getElementById('paperJournalIssueMessage').innerHTML = "You must enter a journal issue!";
		errorFlag = 1;
	}
	if (paperTitle.length < 1)
	{
		document.getElementById('paperTitleMessage').innerHTML = "You must enter a paper title!";
		errorFlag = 1;
	}
	if (errorFlag == 1)
	{
		return false;
	}
}

function lookupPaperFormOrganisations(paperID,stageLimit)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Loading Organisations...]";
	xmlHttp = new GetXmlHttpObject();
	var organisationLookup = escape(document.getElementById('organisationLookup').value);
	if (organisationLookup.length < 3)
	{
		document.getElementById('messageDisplayBox').innerHTML = "Please enter at least 3 characters";
	}
	else
	{
		url = "/includes/ajax/paper/lookuppaperformorganisations.asp?paperID="+paperID+
			"&stageLimit="+stageLimit+"&organisationLookup="+organisationLookup+"&sid="+Math.random();
		xmlHttp.onreadystatechange = function(){xmlHttpResponse('messageDisplayBox','','contextLoadForm');};
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}

function addPaperOrganisationForm(paperID)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Loading Organisation Form...]";
	xmlHttp = new GetXmlHttpObject();
	url = "/includes/ajax/paper/addpaperorganisationform.asp?paperID="+paperID+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){xmlHttpResponse('messageDisplayBox','','contextLoadForm');};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function submitPaperOrganisationForm()
{
	var errorFlag = 0;
	document.getElementById('orgNameMessage').innerHTML = "";
	document.getElementById('orgNationMessage').innerHTML = "";
	document.getElementById('orgLanguageMessage').innerHTML = "";
	var orgName = escape(document.getElementById('orgName').value);
	var nationSelect = document.getElementById('orgNation');
	var orgNation = nationSelect.options[nationSelect.selectedIndex].value;
	var languageSelect = document.getElementById('orgLanguage');
	var orgLanguage = languageSelect.options[languageSelect.selectedIndex].value;
	if (orgName.length < 1)
	{
		document.getElementById('orgNameMessage').innerHTML = "You must enter a organisation name!";
		errorFlag = 1;
	}
	if (orgNation == "Unselected")
	{
		document.getElementById('orgNationMessage').innerHTML = "You must enter a organisation country!";
		errorFlag = 1;
	}
	if (orgLanguage == "Unselected")
	{
		document.getElementById('orgLanguageMessage').innerHTML = "You must enter a organisation language!";
		errorFlag = 1;
	}
	if (errorFlag == 1)
	{
		return false;
	}
}

function confirmPaperOrganisation(paperID,organisationID,stageLimit)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Selecting organisation...]";
	xmlHttp = new GetXmlHttpObject();
	url = "/includes/ajax/paper/confirmpaperorganisation.asp?paperID="+paperID+
		"&stageLimit="+stageLimit+"&organisationID="+organisationID+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){xmlHttpResponse('contextLoadForm','','mainFormBox');};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function removePaperOrganisation(paperID,organisationID,stageLimit)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Removing organisation...]";
	xmlHttp = new GetXmlHttpObject();
	url = "/includes/ajax/paper/removepaperorganisation.asp?paperID="+paperID+
		"&stageLimit="+stageLimit+"&organisationID="+organisationID+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){xmlHttpResponse('contextLoadForm','','mainFormBox');};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function setPaperOrganisation(paperID,organisationID,stageLimit)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Setting main paper organisation...]";
	xmlHttp = new GetXmlHttpObject();
	url = "/includes/ajax/paper/setpaperorganisation.asp?paperID="+paperID+
		"&stageLimit="+stageLimit+"&organisationID="+organisationID+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){xmlHttpResponse('contextLoadForm','','mainFormBox');};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function setPaperOrganisational(paperID,stageLimit)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Bypassing author stage...]";
	xmlHttp = new GetXmlHttpObject();
	url = "/includes/ajax/paper/setpaperorganisational.asp?paperID="+paperID+
		"&stageLimit="+stageLimit+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){xmlHttpResponse('contextLoadForm','','mainFormBox');};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function lookupPaperFormAuthors(paperID,stageLimit)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Loading authors...]";
	xmlHttp = new GetXmlHttpObject();
	var authorLookup = escape(document.getElementById('authorLookup').value);
	if (authorLookup.length < 3)
	{
		document.getElementById('messageDisplayBox').innerHTML = "Please enter at least 3 characters";
	}
	else
	{
		url = "/includes/ajax/paper/lookuppaperformauthors.asp?paperID="+paperID+
			"&stageLimit="+stageLimit+"&authorLookup="+authorLookup+"&sid="+Math.random();
		xmlHttp.onreadystatechange = function(){xmlHttpResponse('messageDisplayBox','','contextLoadForm');};
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}

function addPaperAuthorForm(paperID)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Loading author Form...]";
	xmlHttp = new GetXmlHttpObject();
	url = "/includes/ajax/paper/addpaperauthorform.asp?paperID="+paperID+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){xmlHttpResponse('messageDisplayBox','','contextLoadForm');};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function submitPaperAuthorForm()
{
	var errorFlag = 0;
	document.getElementById('authFirstName').innerHTML = "";
	document.getElementById('authLastName').innerHTML = "";
	var authFirstName = escape(document.getElementById('authFirstName').value);
	var authLastName = escape(document.getElementById('authLastName').value);

	if (authFirstName.length < 1)
	{
		document.getElementById('authFirstNameMessage').innerHTML = "You must enter a first name!";
		errorFlag = 1;
	}
	if (authLastName.length < 1)
	{
		document.getElementById('authLastNameMessage').innerHTML = "You must enter a last name!";
		errorFlag = 1;
	}
	if (errorFlag == 1)
	{
		return false;
	}
}

function confirmPaperAuthor(paperID,authorID,stageLimit)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Selecting author...]";
	xmlHttp = new GetXmlHttpObject();
	url = "/includes/ajax/paper/confirmpaperauthor.asp?paperID="+paperID+
		"&stageLimit="+stageLimit+"&authorID="+authorID+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){xmlHttpResponse('contextLoadForm','','mainFormBox');};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function removePaperAuthor(paperID,authorID,stageLimit)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Removing author...]";
	xmlHttp = new GetXmlHttpObject();
	url = "/includes/ajax/paper/removepaperauthor.asp?paperID="+paperID+
		"&stageLimit="+stageLimit+"&authorID="+authorID+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){xmlHttpResponse('contextLoadForm','','mainFormBox');};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function setPrimaryAuthor(paperID,authorID,stageLimit)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Setting primary organisation...]";
	xmlHttp = new GetXmlHttpObject();
	url = "/includes/ajax/paper/setprimaryauthor.asp?paperID="+paperID+
		"&stageLimit="+stageLimit+"&authorID="+authorID+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){xmlHttpResponse('contextLoadForm','','mainFormBox');};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function setCorrespondingAuthor(paperID,authorID,stageLimit)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Setting corresponding author...]";
	xmlHttp = new GetXmlHttpObject();
	url = "/includes/ajax/paper/setcorrespondingauthor.asp?paperID="+paperID+
		"&stageLimit="+stageLimit+"&authorID="+authorID+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){xmlHttpResponse('contextLoadForm','','mainFormBox');};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function updatePaperAuthorOrganisation(paperID,paperAuthorID,stageLimit)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Setting author organisation...]";
	xmlHttp = new GetXmlHttpObject();
	var organisationID = document.getElementById('authorOrganisation'+paperAuthorID).value;
	url = "/includes/ajax/paper/updatepaperauthororganisation.asp?paperID="+paperID+
		"&paperAuthorID="+paperAuthorID+"&organisationID="+organisationID+
		"&stageLimit="+stageLimit+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){xmlHttpResponse('contextLoadForm','','mainFormBox');};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function updatePaperClass(paperID,stageLimit)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Setting paper class...]";
	xmlHttp = new GetXmlHttpObject();
	var classID = document.getElementById('paperClass').value;
	url = "/includes/ajax/paper/updatepaperclass.asp?paperID="+paperID+
		"&classID="+classID+"&stageLimit="+stageLimit+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){xmlHttpResponse('contextLoadForm','','mainFormBox');};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function updatePaperType(paperID,stageLimit)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Setting paper type...]";
	xmlHttp = new GetXmlHttpObject();
	var typeID = document.getElementById('paperType').value;
	url = "/includes/ajax/paper/updatepapertype.asp?paperID="+paperID+
		"&typeID="+typeID+"&stageLimit="+stageLimit+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){xmlHttpResponse('contextLoadForm','','mainFormBox');};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function updatePaperReviewal(paperID,stageLimit)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Setting paper reviewal process...]";
	xmlHttp = new GetXmlHttpObject();
	var reviewalID = document.getElementById('paperReviewal').value;
	url = "/includes/ajax/paper/updatepaperreviewal.asp?paperID="+paperID+
		"&reviewalID="+reviewalID+"&stageLimit="+stageLimit+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){xmlHttpResponse('contextLoadForm','','mainFormBox');};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function setPaperAuthOrg(paperID,stageLimit)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Updating author / organisation status...]";
	xmlHttp = new GetXmlHttpObject();
	inputRadios = document.getElementsByName('paperAuthOrg');
	for(var i = 0;i < inputRadios.length;i++)
	{
		if (inputRadios[i].checked === true)
		{
			var paperAuthOrg = inputRadios[i].value;
		}
	}
	url = "/includes/ajax/paper/setpaperauthorg.asp?paperID="+paperID+
		"&paperAuthOrg="+paperAuthOrg+"&stageLimit="+stageLimit+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){xmlHttpResponse('contextLoadForm','','mainFormBox');};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function updatePaperAbstract(paperID,stageLimit)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Updating abstract and comments...]";
	xmlHttp = new GetXmlHttpObject();
	var paperAbstract = escape(document.getElementById('paperAbstract').value);
	var paperComments = escape(document.getElementById('paperComments').value);
	url = "/includes/ajax/paper/updatepaperabstract.asp?paperID="+paperID+"&paperAbstract="+paperAbstract+
		"&paperComments="+paperComments+"&stageLimit="+stageLimit+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){xmlHttpResponse('contextLoadForm','','mainFormBox');};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

/* Paper Keyword Functions */

function loadPaperWords(paperID,letterString)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Loading keywords...]";
	xmlHttp = new GetXmlHttpObject();
	url = "/includes/ajax/paper/loadpaperwords.asp?paperID="+paperID+
		"&letterString="+letterString+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){xmlHttpResponse('messageDisplayBox','','paperWordFilter');};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function addKeywordPaper(paperID,letterString)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Adding keyword...]";
	xmlHttp = new GetXmlHttpObject();
	var keywordDesc = escape(document.getElementById('keywordDesc').value);
	inputRadios = document.getElementsByName('keywordScore');
	for(var i = 0;i < inputRadios.length;i++)
	{
		if (inputRadios[i].checked === true)
		{
			var keywordScore = inputRadios[i].value;
		}
	}
	if (keywordDesc.length === 0)
	{
		document.getElementById('messageDisplayBox').innerHTML = "Please enter a keyword";
	}
	else
	{
		url = "/includes/ajax/paper/addkeywordpaper.asp?paperID="+paperID+
			"&keywordDesc="+keywordDesc+"&keywordScore="+keywordScore+
			"&letterString="+letterString+"&sid="+Math.random();
		xmlHttp.onreadystatechange = function(){xmlHttpResponse('messageDisplayBox','','paperWordFilter');};
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}

function setPaperKeyword(paperID,keywordID,letterString,keywordScore)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Updating keyword...]";
	xmlHttp = new GetXmlHttpObject();
	url = "/includes/ajax/paper/setpaperkeyword.asp?paperID="+paperID+
		"&keywordID="+keywordID+"&keywordScore="+keywordScore+
		"&letterString="+letterString+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){xmlHttpResponse('messageDisplayBox','','paperWordFilter');};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function removePaperKeyword(paperID,keywordID,letterString)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Removing keyword...]";
	xmlHttp = new GetXmlHttpObject();
	url = "/includes/ajax/paper/removepaperkeyword.asp?paperID="+paperID+
		"&keywordID="+keywordID+"&letterString="+letterString+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){xmlHttpResponse('messageDisplayBox','','paperWordFilter');};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

// -->