	function AjaxDrop(controlClientId,lookupName){
		var self=this;
		this.controlClientId=controlClientId;
		this.hiddenId='__'+self.controlClientId;
		this.lookupName=lookupName;
		this.baseUrl=document.location.protocol + '//' + document.location.host + '/cms/ajaxDrop.aspx';
		this.delimiter='|';
		this.StartValue='';
		this.StartName='';
        this.onchange=null;
		var observers=[];
		this.addObserver=addObserver;
		this.notify=notify;
		this.load=load;
		this.init=initialize;
        this.clear=clear;

        function clear() {
			if(oSelect=$(self.controlClientId)){
				for(var i=oSelect.length-1;i>=0;i--){
					oSelect.options[i]=null;
				}
            }
        }

		function load(filter){
		  var obj_date = new Date();
			var requestUrl=self.baseUrl+'?filter='+self.lookupName;
			if(filter!=undefined&&filter!=''){
                requestUrl = requestUrl.replace('((value))',filter);
                requestUrl = requestUrl.replace('[[value]]',filter);
			}
            $(self.controlClientId).disabled = true;
			clear();

			if (filter=='-1'){
			  notify();
			  oSelect.disabled = true;
			  return;
			}

			oSelect.options[oSelect.length]=new Option('Loading...','-1');
		
            new Ajax.Request (requestUrl, {method:'get',onComplete:function(r){
                clear();
                //alert(r.responseText);
                eval('var d='+r.responseText);
			    if(d){
			      populateList(d);
			      notify();
			    }
       
            }});
            
		}

		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='-1';
			var oSelect=$(self.controlClientId);
			if(oSelect!=null&&oSelect.selectedIndex!=-1){
				filter=oSelect.options[oSelect.selectedIndex].value;
			}
			for(i=0;i<observers.length;i++){
				eval(observers[i]+'.load(filter);');
			}
            if (self.onchange) self.onchange(oSelect,filter)
		}

		function initialize(value){
			var oSelect=$(self.controlClientId);
            var frm = oSelect.form;
			if(oSelect){
		      if(frm){
				if(oSelect.options.length==0){
					this.load();
				}
				if(oSelect.attachEvent){
					oSelect.attachEvent('onchange',notify);
				}else if(oSelect.addEventListener){
					oSelect.addEventListener('change',notify,true);
				}else{
					oSelect.onchange=notify;
				}
              } else {
                alert('Unable to find form for control [' + self.controlClientId + ']');
			  }
            } else {
              alert('Unable to find control [' + self.controlClientId + ']');
			}
		}

		function populateList(namevalue){
			if(oSelect==$(self.controlClientId)){
				var content='';
				var e = 0;
                clear();
                oSelect.disabled = false;
				if (self.StartName != ''){
					if (self.StartValue == ''){
						oSelect.options[oSelect.length]=new Option(self.StartName,'-1');
					}else{
						oSelect.options[oSelect.length]=new Option(self.StartName,self.StartValue);
					}
				}
				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=$(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);
					}
				}
			}
		}

	}

