
// ##############  dataSelect definition ####################


dataSelect.prototype.OnDataReceived = OnDataReceived;
dataSelect.prototype.AddOption = AddOption;
dataSelect.prototype.ParseOption = ParseOption;
dataSelect.prototype.GetData = GetData;
dataSelect.prototype.Clear = Clear;

function dataSelect(name,AddEmpty,EmptyItemValue,EmptyItemText)
{
  this.name = name;
	this.id = name;
	this.http = getHTTPObject();
	this.GetDataUrl = "async_DBSelect_GetData.cfm";
	this.FilterValue = "-1";
	this.FilterValue2 = "-1";
	this.AddEmpty = AddEmpty;
	this.EmptyItemValue = EmptyItemValue;
	this.EmptyItemText = EmptyItemText;
	return this;
}


function OnDataReceived()
{
  if(this.http.readyState == 4)
	{
	  if(this.http.status == 200)
		{
		
		  this.Clear();								
		  var xmlDoc = this.http.responseXML;
			var Options = xmlDoc.getElementsByTagName("option");
			
			if(this.AddEmpty)
			{
			  this.AddOption(this.EmptyItemValue,this.EmptyItemText);
			}
			
			for(var idx = 0; idx < Options.length; idx++)
			{
			  this.ParseOption(Options.item(idx));
			}
		}
		else
		{
		  alert("Error receiving data. HTTP Error Code: " + this.http.status);
		}
	}		  				
}

function AddOption(OptionValue,OptionText)
{
  var selectObj = document.getElementById(this.id);
	try
	{
		selectObj.add(new Option(OptionText,OptionValue),null);	
	}
	catch(ex)
	{
		selectObj.add(new Option(OptionText,OptionValue));	
	}	
}

function ParseOption(OptionData)
{
  var ElementValue = OptionData.getAttribute("itemvalue");
	var ElementText = OptionData.getAttribute("itemtext");
	this.AddOption(ElementValue,ElementText);
}


function GetData()
{
	//prompt("",this.GetDataUrl+"?Id="+this.id+"&FilterValue="+this.FilterValue+"&FilterValue2="+this.FilterValue2);
  this.http.open("GET",this.GetDataUrl+"?Id="+this.id+"&FilterValue="+this.FilterValue+"&FilterValue2="+this.FilterValue2,true);
	this.http.onreadystatechange = eval(this.name+"_dataReceived");
	this.http.send(null);
}

function Clear()
{
  var selectObj = document.getElementById(this.id);
	for(var Idx = selectObj.options.length; Idx > 0; Idx--)
	{
	  selectObj.remove(Idx-1);
	}
}




