var g_aoBestandRequest = new Array();

function ClsBestandRequest()
{
	var m_iIDArtikel = 0;
	var m_sBestandRequestLabel = '';
	var m_oHttpRequest = false;
	
	function ARTGetHttpRequestObject()
	{
		var oHttpRequest = false;
	
		if (window.XMLHttpRequest)
		{
			oHttpRequest = new XMLHttpRequest();
			if (oHttpRequest.overrideMimeType)
			{
				oHttpRequest.overrideMimeType('text/xml');
			}
		}
		else
		{
			if (window.ActiveXObject)
			{
				try
				{
					oHttpRequest = new ActiveXObject('MSXML2.XMLHTTP.6.0');
				}			
				catch (oException)
				{
					try
					{
						oHttpRequest = new ActiveXObject('MSXML2.XMLHTTP.5.0');
					}
					catch (oException)
					{
						try
						{
							oHttpRequest = new ActiveXObject('MSXML2.XMLHTTP.4.0');
						}
						catch (oException)
						{
							try
							{
								oHttpRequest = new ActiveXObject('MSXML2.XMLHTTP.3.0');
							}
							catch (oException)
							{
								try
								{
									oHttpRequest = new ActiveXObject('MSXML2.XMLHTTP');
								}
								catch (oException)
								{
									try
									{
										oHttpRequest = new ActiveXObject('Microsoft.XMLHTTP');
									}
									catch (oException)
									{
									}
								}						
							}					
						}
					}
				}
			}
		}
		
		return oHttpRequest;
	}
	
	function ARTGetSpanContent()
	{
		var oSpan = document.getElementById('spnBestand' + m_iIDArtikel);
			
		if (oSpan)
		{
			return oSpan.innerHTML;
		}
		else
		{
			return '';
		}
	}
	
	function ARTSetSpanContent(sText)
	{
		var oSpan = document.getElementById('spnBestand' + m_iIDArtikel);
			
		if (oSpan)
		{
			oSpan.innerHTML = sText;					
			return true;
		}
		else
		{
			return false;
		}
	}
	
	this.ARTProcessHttpRequest = function()
	{	
		var sResponse = '';
		
		if (m_oHttpRequest.readyState == 4)
		{
			if (m_oHttpRequest.status == 200)
			{
				sResponse = m_oHttpRequest.responseText;
				
				if (sResponse != '')
				{
					ARTSetSpanContent(sResponse);
				}
				else
				{
					ARTSetSpanContent(m_sBestandRequestLabel);
				}
			}
			else
			{
				ARTSetSpanContent(m_sBestandRequestLabel);
			}
		}		
	}
	
	this.ARTExecute = function(iIDArtikel, sLabel)
	{
		m_iIDArtikel = iIDArtikel;
		m_sBestandRequestLabel = ARTGetSpanContent();
		m_oHttpRequest = ARTGetHttpRequestObject();
				
		if (m_oHttpRequest)
		{					
			if (ARTSetSpanContent(sLabel))
			{
				m_oHttpRequest.onreadystatechange = this.ARTProcessHttpRequest;
				m_oHttpRequest.open('GET', 'bestand/get.asp?idartikel=' + m_iIDArtikel, true);
				m_oHttpRequest.send(null);
				
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}
}

function ARTExecuteBestandRequest(iIDArtikel, sLabel)
{
	g_aoBestandRequest[g_aoBestandRequest.length] = new ClsBestandRequest();
	g_aoBestandRequest[g_aoBestandRequest.length - 1].ARTExecute(iIDArtikel, sLabel);
}
