var xmlHttp;
var xmlHttpforarchive;
function craeteXMLHTTPRequest()
{
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest ();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject ("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject ("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				//alert ("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	return true;
}
function craeteXMLHTTPRequestforarchive()
{
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttpforarchive=new XMLHttpRequest ();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttpforarchive=new ActiveXObject ("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttpforarchive=new ActiveXObject ("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				//alert ("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	return true;
}
function getnextthreearticles(categoryID, issueID, multipleofthree)
{
	eval("collapsepanel(document.getElementById('onlyright" + categoryID + "'));");
	eval("collapsepanel(document.getElementById('rightleft" + categoryID + "'));");
	eval("collapsepanel(document.getElementById('onlyleft" + categoryID + "'));");
	eval("expandpanel(document.getElementById('norightnoleft" + categoryID + "'));");
	var e = document.getElementById('articles' + categoryID);
	e.style.visibility = 'hidden';
	if(craeteXMLHTTPRequest())
	{
		xmlHttp.onreadystatechange=function ()
		{
			if (xmlHttp.readyState == 4)
			{
				if (xmlHttp.responseText.length>0)
				{
					var responsetext = xmlHttp.responseText.split(';;;...!!!');
					e.innerHTML = responsetext[0];
					var foundrows = responsetext[1];
					e.style.visibility = 'visible';
					eval('multipleofthree' + categoryID + '++;');
					eval("collapsepanel(document.getElementById('norightnoleft" + categoryID + "'));");
					var statement = "if(multipleofthree" + categoryID + " == 1) expandpanel(document.getElementById('onlyright" + categoryID + "'));";
					eval(statement);
					var statement = "if((multipleofthree" + categoryID + " > 1) && (foundrows > (3 * multipleofthree" + categoryID + "))) expandpanel(document.getElementById('rightleft" + categoryID + "'));";
					eval(statement);
					var statement = "if((multipleofthree" + categoryID + " > 1) && (foundrows <= (3 * multipleofthree" + categoryID + "))) expandpanel(document.getElementById('onlyleft" + categoryID + "'));";
					eval(statement);
				}
			}
		}
		xmlHttp.open ('POST', 'getnextarticles.php', true);
		xmlHttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');
		xmlHttp.send ('categoryID=' + categoryID + '&multipleofthree=' + multipleofthree + '&issueID=' + issueID);
	}
}
function getsummary(articleID, query)
{
	var s='';
	for(i=0; i<query.length; i++)
	{
		if(i>0)s+='a';
		s+=query.charCodeAt(i);
	}
	var e = document.getElementById('resultsummary' + articleID);
	if(e.innerHTML.length==0)
	{
		if(craeteXMLHTTPRequest())
		{
			xmlHttp.onreadystatechange=function ()
			{
				if (xmlHttp.readyState == 4)
				{
					if (xmlHttp.responseText.length>0)
					{
						e.innerHTML = xmlHttp.responseText;
					}
				}
			}
			var Ajax_values = 'articleID=' + articleID + '&query=' + s;
			xmlHttp.open ('POST', 'getsummary.php', true);
			xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded;');
			xmlHttp.setRequestHeader('Content-length', Ajax_values.length);
			xmlHttp.setRequestHeader('Connection', 'close');
			xmlHttp.send (Ajax_values);
		}
	}
	else
	{
		var e = document.getElementById('introandbody' + articleID);
		if(iscollapsed(e) == true) expandpanel(e);
		else collapsepanel(e);
		if(browser=='firefox') e.innerHTML = e.innerHTML;
	}
}
function getsummaryofarchive(articleID, issuedate, query)
{
	var e = document.getElementById('resultsummary' + articleID);
	if(e.innerHTML.length==0)
	{
		if(craeteXMLHTTPRequest())
		{
			var s='';
			for(i=0; i<query.length; i++)
			{
				if(i>0)s+='a';
				s+=query.charCodeAt(i);
			}
			xmlHttp.onreadystatechange=function ()
			{
				if (xmlHttp.readyState == 4)
				{
					if (xmlHttp.responseText.length>0)
					{
						e.innerHTML = xmlHttp.responseText;
					}
				}
			}
			var Ajax_values = 'issuedate=' + issuedate + '&articleID=' + articleID + '&query=' + s;
			xmlHttp.open('GET', 'transport.php?action=' + encodeURI('http://localhost:81/archive.alanwar.com/getsummary.php') + '&method=post&' + Ajax_values, true );
//			xmlHttp.open('GET', 'transport.php?action=' + encodeURI('http://wwww.archive.alanwar.com/getsummary.php') + '&method=post&' + Ajax_values, true );
			xmlHttp.send(null);
		}
	}
	else
	{
		var e = document.getElementById('introandbody' + articleID);
		if(iscollapsed(e) == true) expandpanel(e);
		else collapsepanel(e);
		if(browser=='firefox') e.innerHTML = e.innerHTML;
	}
}
function getarchive(query, yearmonth)
{
	var s='';
	for(i=0; i<query.length; i++)
	{
		if(i>0)s+='a';
		s+=query.charCodeAt(i);
	}
	var archive = document.getElementById('archive');
	var numberofarchivedresults = document.getElementById('numberofarchivedresults');
	if(craeteXMLHTTPRequestforarchive())
	{
		xmlHttpforarchive.onreadystatechange=function ()
		{
			if (xmlHttpforarchive.readyState == 4)
			{
				if (xmlHttpforarchive.responseText.length>0)
				{
					var responsetext = xmlHttpforarchive.responseText.split(';;;...!!!');
					archive.innerHTML = responsetext[0];
					numberofarchivedresults.innerHTML = responsetext[1];
				}
			}
		}
		var Ajax_values = 'yearmonth=' + yearmonth + '&query=' + s;
		xmlHttpforarchive.open('GET', 'transport.php?action=' + encodeURI('http://www.archive.alanwar.com/search.php') + '&method=post&' + Ajax_values, true );
//		xmlHttpforarchive.open('GET', 'transport.php?action=' + encodeURI('http://localhost:81/archive.alanwar.com/search.php') + '&method=post&' + Ajax_values, true );
		xmlHttpforarchive.send(null);
	}
}