/* 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. */

/* Basic keyword functions */

var keywordDesc;

function loadKeywords(letterString)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Loading keywords...]";
	xmlHttp = new GetXmlHttpObject();
	url = "/includes/ajax/keywords/loadkeywords.asp?letterString="+letterString+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){xmlHttpResponse('messageDisplayBox','','keywordDisplayBox');};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function updateKeyword(keywordID,letterString)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Updating keyword...]";
	xmlHttp = new GetXmlHttpObject();
	keywordDesc = escape(document.getElementById('keywordDesc'+keywordID).value);
	if (keywordDesc.length === 0)
	{
		document.getElementById('messageDisplayBox').innerHTML = "Please enter a keyword";
	}
	else
	{
		url = "/includes/ajax/keywords/updatekeyword.asp?keywordID="+keywordID+
			"&keywordDesc="+keywordDesc+"&letterString="+letterString+"&sid="+Math.random();
		xmlHttp.onreadystatechange = function(){xmlHttpResponse('messageDisplayBox','','keywordDisplayBox');};
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}

function removeKeyword(keywordID,letterString)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Removing keyword...]";
	xmlHttp = new GetXmlHttpObject();
	url = "/includes/ajax/keywords/removekeyword.asp?keywordID="+keywordID+
		"&letterString="+letterString+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){xmlHttpResponse('messageDisplayBox','','keywordDisplayBox');};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function removeKeywordPrompt(keywordID,letterString)
{
	document.getElementById('messageDisplayBox').innerHTML = "<p class=\"himessage\">"+
		"You have chosen to remove this keyword. This will not be possible if it "+
		"is currently attached to any existing papers. If you receive this error "+
		"please ensure that the corresponding papers that have caused the "+
		"failure have had this keyword removed and try again. Please <a "+
		"href=\"#\" onclick=\"removeKeyword("+keywordID+",'"+letterString+"');"+
		"return false;\">Confirm</a> or <a href=\"#\" onclick=\""+
		"clearMessageDisplayBox();return false;\">Cancel</a> this action.</p>";
}

function addKeyword(letterString)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Adding keyword...]";
	xmlHttp = new GetXmlHttpObject();
	keywordDesc = escape(document.getElementById('keywordDesc').value);
	if (keywordDesc.length === 0)
	{
		document.getElementById('messageDisplayBox').innerHTML = "Please enter a keyword";
	}
	else
	{
		url = "/includes/ajax/keywords/addkeyword.asp?keywordDesc="+keywordDesc+
			"&letterString="+letterString+"&sid="+Math.random();
		xmlHttp.onreadystatechange = function(){xmlHttpResponse('messageDisplayBox','','keywordDisplayBox');};
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}

function reactivateKeyword(keywordID,letterString)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Reactivating keyword...]";
	xmlHttp = new GetXmlHttpObject();
	url = "/includes/ajax/keywords/reactivatekeyword.asp?keywordID="+keywordID+
		"&letterString="+letterString+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){xmlHttpResponse('messageDisplayBox','','keywordDisplayBox');};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

/* Keyword linking functions */

function loadKeyLinkWords(keywordID,letterString)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Loading keywords...]";
	xmlHttp = new GetXmlHttpObject();
	url = "/includes/ajax/keywords/loadlinkkeywords.asp?keywordID="+keywordID+
		"&letterString="+letterString+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){xmlHttpResponse('messageDisplayBox','','keywordDisplayBox');};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function linkKeyword(keywordID,linkwordID,relatedLevel,letterString)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Updating keyword links...]";
	xmlHttp = new GetXmlHttpObject();
	url = "/includes/ajax/keywords/linkkeyword.asp?keywordID="+keywordID+"&linkwordID="+
		linkwordID+"&relatedLevel="+relatedLevel+"&letterString="+letterString+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){xmlHttpResponse('messageDisplayBox','','keywordDisplayBox');};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function identicalKeyPrompt(keywordID,linkwordID,letterString)
{
	document.getElementById('messageDisplayBox').innerHTML = "You have attempted "+
		"to mark this as an identical keyword. Both keywords will automatically "+
		"share existing identical and related keywords. Please <a "+
		"href=\"#\" onclick=\"linkKeyword("+keywordID+","+linkwordID+",1,'"+
		letterString+"');return false;\">Confirm</a> or <a href=\"#\" onclick=\""+
		"clearMessageDisplayBox();return false;\">Cancel</a> this action.";
}

function relatedKeyPrompt(keywordID,linkwordID,letterString)
{
	document.getElementById('messageDisplayBox').innerHTML = "You have attempted "+
		"to mark this as a related keyword. Both keywords will acquire the other's "+
		"indentical keywords as related also, and you will be given the option "+
		"to manually include related keywords as appropriate. Please <a "+
		"href=\"#\" onclick=\"linkKeyword("+keywordID+","+linkwordID+",2,'"+
		letterString+"');return false;\">Confirm</a> or <a href=\"#\" onclick=\""+
		"clearMessageDisplayBox();return false;\">Cancel</a> this action.";
}

function delinkKeyword(keywordID,linkwordID)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Updating keyword links...]";
	xmlHttp = new GetXmlHttpObject();
	url = "/includes/ajax/keywords/delinkkeyword.asp?keywordID="+keywordID+"&linkwordID="+
		linkwordID+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){xmlHttpResponse('messageDisplayBox','','keywordDisplayBox');};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function delinkKeyPrompt(keywordID,linkwordID)
{
	document.getElementById('messageDisplayBox').innerHTML = "You have attempted "+
		"to remove the link between these two keywords. Any identical keywords to "+
		"the main selected keyword will also be removed. Please <a "+
		"href=\"#\" onclick=\"delinkKeyword("+keywordID+","+linkwordID+");"+
		"return false;\">Confirm</a> or <a href=\"#\" onclick=\""+
		"clearMessageDisplayBox();return false;\">Cancel</a> this action.";
}

function updateKeyLinks(keywordID)
{
	document.getElementById('messageDisplayBox').innerHTML = "[Updating keyword link display...]";
	xmlHttp = new GetXmlHttpObject();
	url = "/includes/ajax/keywords/updatekeylinks.asp?keywordID="+keywordID+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){xmlHttpResponse('messageDisplayBox','','existingLinksBox');};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	document.getElementById('keywordDisplayBox').innerHTML = "";
}

function finaliseRelatedKeylinks(keywordID,linkwordID,letterString)
{
	var keywordString = "(0";
	
	inputForm = document.getElementById('relatedKeylinks');
	for(var i = 0;inputForm.elements[i];i++)
	{
		if (inputForm.elements[i].type == 'checkbox')
		{
			if (inputForm.elements[i].checked === true)
			{
				keywordString = keywordString + "," + inputForm.elements[i].value;
			}
		}
	}
	keywordString = keywordString + ")";
	document.getElementById('messageDisplayBox').innerHTML = "[Finalising keyword link relationships...]";
	xmlHttp = new GetXmlHttpObject();
	url = "/includes/ajax/keywords/finaliserelatedkeylinks.asp?keywordID="+keywordID+"&linkwordID="+
		linkwordID+"&keywordString="+keywordString+"&letterString="+letterString+"&sid="+Math.random();
	xmlHttp.onreadystatechange = function(){xmlHttpResponse('messageDisplayBox','','keywordDisplayBox');};
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

// -->