//----------------BEGIN AutoFillDropDown ------------------------

function AutoFillDropDown( ParentId, ChildId, PleaseSelectText, PleaseWaitText, OthersValue, OthersLabel )
{
	// initialize member variables
	var oThis = this;
	var oParentDropDown		= document.getElementById(ParentId);
	var oChildDropDown		= document.getElementById(ChildId);
	this.ParentDropDown		= oParentDropDown;
	this.ChildDropDown		= oChildDropDown;
	this.PleaseSelectText	= PleaseSelectText;
	this.PleaseWaitText		= PleaseWaitText;
	this.OthersValue		= OthersValue;
	this.OthersLabel		= OthersLabel;

	// CallBackObject + Event Handlers
	this.Cbo = new CallBackObject();
	this.Cbo.OnComplete	= function(responseText,responseXML){oThis.Cbo_Complete(responseText,responseXML);};
	this.Cbo.onerror	= function(status,statusText,responseText){oThis.Cbo_Error(status,statusText,responseText);};

	// attach handlers to the TextBox
	oParentDropDown.AutoFillDropDown = this;
	oParentDropDown.onchange = AutoFillDropDown.prototype.OnChange;


}

// TextBox OnKeyUp
AutoFillDropDown.prototype.OnChange = function(oEvent)
{
	//check for the proper location of the event object
	if (!oEvent)
	{
		oEvent = window.event;
	}
	this.AutoFillDropDown.DropDown_OnChange(oEvent);
}

AutoFillDropDown.prototype.DropDown_OnChange = function(oEvent)
{
	var val = this.ParentDropDown.value;
	if( val.length > 0 )
	{
		if( this.PleaseWaitText.length > 0 )
		{
			this.ChildDropDown.options.length=0;
			this.ChildDropDown.options.add(new Option( this.PleaseWaitText, ""));
		}
		else
		{
			this.ChildDropDown.options.length = 0;
		}
		this.Cbo.DoCallBack( this.ParentDropDown.name, val );
	}
	else
	{
		this.Cbo.AbortCallBack();
	}
}

AutoFillDropDown.prototype.Cbo_Complete = function(responseText, responseXML)
{

	if( this.PleaseSelectText.length > 0 )
	{
		this.ChildDropDown.options.length=0;
		this.ChildDropDown.options.add(new Option( this.PleaseSelectText, ""));
	}
	else
	{
		this.ChildDropDown.options.length = 0;
	}

	var els = responseText.split( "\n" );
	for( var i = 0; i < els.length; i++ )
	{
		if( els[i].length > 0 )
		{
			var el = els[i].split( "|" );
			this.ChildDropDown.options.add( new Option( el[1], escape(el[0]) ));
		}
	}

	if( this.OthersLabel != "" )
	{
		this.ChildDropDown.options[this.ChildDropDown.options.length] = new Option( this.OthersLabel );
		this.ChildDropDown.options[this.ChildDropDown.options.length-1].value = escape(this.OthersValue);
	}

	if( this.ChildDropDown.options.length > 0 )
	{
		this.ChildDropDown.selectedIndex = 0;
	}

}

AutoFillDropDown.prototype.Cbo_Error = function(status, statusText, responseText)
{
	alert('CallBackObject Error: status=' + status + '\nstatusText=' + statusText + '\n' + responseText);
}
function RemoveText(SourceString, RemoveString)
{
	while(SourceString.indexOf(RemoveString)>=0)
	{
		SourceString=SourceString.replace(RemoveString, "");
	}
	return SourceString;
}
function InitDropdown(DropDownListId)
{
	
	oDropDownList=document.getElementById(DropDownListId);
	if(!oDropDownList)
	{
		aElemente=document.getElementsByName(DropDownListId);
		if(aElemente.length==1){oDropDownList=aElemente[0];}
	}
	if(oDropDownList)
	{
		if(oDropDownList.options.length>0)
		{
			if(oDropDownList.options[0].value!=""&&oDropDownList.options[0].text=="")
			{
				ActiveIndex=oDropDownList.options[0].value;
				oDropDownList.remove(0);
				oDropDownList.SelectedIndex=ActiveIndex;
			}
		}
	}
}
//----------------END AutoFillDropDown ------------------------

