finished = true; 
waiting = false;
function SendXMLRequest(formname,extra)
{
	if(finished)
	{
		finished = false;
		document.getElementById('XMLHttpRequestResult').style.display = 'block';
		document.getElementById('XMLHttpRequestResult').style.left = getXPos('XMLHttpRequestResultPosition')+'px';
		document.getElementById('XMLHttpRequestResult').style.top = getYPos('XMLHttpRequestResultPosition')+'px';
	
		document.getElementById('XMLHttpRequestResult').innerHTML = '<IMG SRC=images/comment_button.gif>';
		if(window.XMLHttpRequest)
			connection = new XMLHttpRequest();
		else if(window.ActiveXObject)
		{
			try
			{
				connection = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e)
			{
				try 
				{
					connection = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch(e)
				{
					connection = false;
				}
			}
		}
		if(!connection)
			alert('AJAX connection could not be made.');
	
		connection.onreadystatechange = processRequest;
		url = "modloader.php?servicemod=" + getRequestVar('servicemod') + "&CREATEPDF=true&servicefunction=" + extra + '&' + (new Date()).getTime()
		elems = document.forms[formname].elements;
		for(elemindex = 0;elemindex<elems.length;elemindex++)
		{
			elem = document.forms[formname].elements[elemindex];
			if(elem.name && elem.value)
			{
				url = url + "&" + elem.name + "=" + urlencode(elem.value);
			}
			else if(elem.name && elem.options)
				url = url + "&" + elem.name + "=" + urlencode(elem.options.length>elem.selectedIndex && elem.selectedIndex>=0?elem.options[elem.selectedIndex].value:'');
		}
		connection.open("GET",url,true);
		connection.send(null);
	}
	else if(!waiting)
	{
		SendXMLRequestForm = formname;
		SendXMLRequestExtra = extra;
		waiting = true;
		window.setTimeout("setWaitingFalse()",2010);
		window.setTimeout('SendXMLRequest(SendXMLRequestForm,SendXMLRequestExtra)',2000);
	}
}

function processRequest()
{
	// LOADED && ACCEPTED
	if(connection.readyState == 4 && connection.status == 200) 
	{
		XMLResponse = connection.responseXML;
		if(true || XMLResponse.length>0)
		{
			//document.getElementById("XMLHttpRequestResult").style.visibility = "visible";
			var columns_list = XMLResponse.getElementsByTagName("xml");
			columns_list = columns_list[0].getElementsByTagName("columns");
			columns_list = columns_list[0].getElementsByTagName('C');
	
			var results_list = XMLResponse.getElementsByTagName("results");
			results_list = results_list[0].getElementsByTagName("result");

			var variables_list = XMLResponse.getElementsByTagName("variables");
			variables_list = variables_list[0].getElementsByTagName("V");
	
			var link = XMLResponse.getElementsByTagName("link")[0].firstChild.data;
			var this_link = '';
			var val;
	
			if(results_list.length>0)
			{
				var table = '<TABLE style="border:solid;cellspacing:0;">';
				table = table + '<TR bgcolor=#3366FF style="background-color:#3366FF;color:white;">';
				for(i=0;i<columns_list.length;i++)
				{
					if(columns_list[i].firstChild.data!='~')
					{
						table = table + '<TD>';
						table = table + columns_list[i].firstChild.data;
						table = table + '</TD>';
					}
				}
				table = table + '</TR>';
	
				for(o=0;o<results_list.length;o++)
				{
					if(link)
					{
						this_link = 'onclick="document.location.href=\''+unescape(link);
						if(variables_list.length>0)
						{
							for(i=0;i<variables_list.length;i++)
							{
								col = variables_list[i].getAttribute('col');
								this_link = this_link + '&' + variables_list[i].firstChild.data + '=' + results_list[o].getElementsByTagName('C'+col)[0].firstChild.data;
							}
						}
						this_link = this_link + '\';"';
					}
	
					table = table + '<TR '+this_link+' onmouseover="this.style.cssText=\'cursor:pointer;background-color:#3366FF;color:#FFFFFF;\'" onmouseout="this.style.cssText=\'\'">';
					for(i=0;i<columns_list.length;i++)
					{
						if(columns_list[i].firstChild.data!='~')
						{
							table = table + '<TD>';
							val = results_list[o].getElementsByTagName('C'+(i+1))[0].firstChild.data;
							if(val!="=null=")
								table = table + val;
							table = table + '</TD>';
						}
					}
					table = table + '</TR>';
				}
				table = table + '</TABLE>';
			}
			else
				table = '';
			document.getElementById("XMLHttpRequestResult").innerHTML = table;
			finished = true;
		}
		else
			finished = true;
	}
}

function getRequestVar(variable)
{
	var request = window.location.search.substring(1);
	var vars = request.split("&");
	for(var i=0;i<vars.length;i++)
	{
		var pair = vars[i].split("=");
		if(pair[0] == variable)
			return pair[1];
	}
	return false;
}

function urlencode(variable) 
{
	return escape(variable).replace("\+",'%2B').replace("\"",'%22').replace("\'", '%27').replace("\/",'%2F');
}

function setWaitingFalse()
{
	waiting = false;
}

/*
function move(from,to)
{
	for(var i=0; i<from.options.length; i++)
	{
		if(from.options[i].selected && from.options[i].value != "")
		{
			var no = new Option();
			no.value = from.options[i].value;
			no.text = from.options[i].text;
			to.options[to.options.length] = no;
			from.options[i]=null;
			i--;
		}
	}
        return null;
}
 */