function getXMLHTTP()
{var A=null;try{A=new ActiveXObject('Msxml2.XMLHTTP');}
catch(e){try{A=new ActiveXObject('Microsoft.XMLHTTP');}catch(oc){A=null;}}
if(!A&&typeof XMLHttpRequest!='undefined'){A=new XMLHttpRequest();}
return A;}
function AjaxDropDownController(controlClientId,lookupName,baseUrl){var self=this;this.controlClientId=controlClientId;this.hiddenId='__'+self.controlClientId;this.lookupName=lookupName;this.baseUrl=baseUrl;this.delimiter='|';var xmlHttp;var observers=[];this.getSource=getSource;this.addObserver=addObserver;this.notify=notify;this.load=load;this.init=init;this.persist=persist;function getSource(filter)
{var requestUrl=baseUrl+'&id='+self.lookupName;if(filter!=undefined&&filter!='')
{requestUrl+='&filter='+filter;}
xmlHttp=getXMLHTTP();if(xmlHttp)
{xmlHttp.onreadystatechange=doReadyStateChange;xmlHttp.open('GET',requestUrl,true);xmlHttp.send(null);}}
function doReadyStateChange()
{if(xmlHttp.readyState==4)
{if(xmlHttp.status==200)
{eval('var d='+xmlHttp.responseText);if(d!=null)
{populateList(d);}}
else
{alert('There was a problem retrieving the data:\n'+xmlHttp.statusText);}}}
function populateList(namevalue)
{if(oSelect=document.getElementById(self.controlClientId))
{var content='';for(var i=oSelect.length-1;i>=0;i--)
{oSelect.options[i]=null;}
for(var i=0;i<namevalue.length;i++)
{if(namevalue[i].value==undefined)
{oSelect.options[oSelect.length]=new Option(namevalue[i].name);content+=namevalue[i].name+self.delimiter+namevalue[i].name+self.delimiter;}
else
{opt=new Option(namevalue[i].name,namevalue[i].value);oSelect.options[oSelect.length]=opt;content+=namevalue[i].name+self.delimiter+namevalue[i].value+self.delimiter;}}
if(content.substr(content.length-1,1)==self.delimiter)
{content=content.substr(0,content.length-1);}
if(oHidden=document.getElementById(self.hiddenId))
{oHidden.value=content;}
if(oSelect.selectedIndex>-1){if(oSelect.fireEvent)
{oSelect.fireEvent('onchange');}
else if(oSelect.dispatchEvent)
{var oEvent=document.createEvent('HTMLEvents');oEvent.initEvent('change',true,true);oSelect.dispatchEvent(oEvent);}}}}
function addObserver(obj)
{var length=observers.length;var found=false;for(var i=0;i<length;i++)
{if(observers[i]==obj)
{found=true;break;}}
if(!found)
{observers[observers.length]=obj;}}
function notify()
{var filter='';var oSelect=document.getElementById(self.controlClientId);if(oSelect!=null&&oSelect.selectedIndex!=-1)
{filter=self.lookupName+','+oSelect.options[oSelect.selectedIndex].value;}
for(i=0;i<observers.length;i++)
{eval(observers[i]+'.load(filter);');}}
function load(filter)
{this.getSource(filter);}
function init()
{if((oSelect=document.getElementById(self.controlClientId)))
{if(!(hidden=document.getElementById(self.hiddenId)))
{hidden=document.createElement('input');hidden.id=self.hiddenId;hidden.name=self.hiddenId;hidden.type='hidden';oSelect.form.appendChild(hidden);}
if(oSelect.options.length==0)
{this.load();}
else
{this.persist(oSelect);}
if(oSelect.attachEvent)
{oSelect.attachEvent('onchange',notify);}
else if(oSelect.addEventListener)
{oSelect.addEventListener('change',notify,false);}
else
{oSelect.onchange=notify;}}}
function persist(oSelect)
{var content='';for(var i=0;i<oSelect.options.length;i++)
{content+=oSelect.options[i].text+self.delimiter+oSelect.options[i].value+self.delimiter;}
if(content.substr(content.length-1,1)==self.delimiter)
{content=content.substr(0,content.length-1);}
if((hidden=document.getElementById(self.hiddenId)))
{hidden.value=content;}}}
