var ajaxWaitingObject=Class.create();ajaxWaitingObject.prototype={initialize:function(d,a,c,b){this.populateId=d;this.populate=$(d);this.datasourceUrl=a;this.datasourceParms="";this.cache={};this.events=Object.extend({build:[],behavior:[],hide:[],fetch:[],retrieve:[],show:[],fail:[]},c||{});this.options=Object.extend({startWithData:true,cached:true,waitActive:true,waitImage:"wait.gif",waitHeight:"16px",waitWidth:"16px",imageDirectory:"ub/images/",primable:true,periodicalExecute:false,periodicalPeriod:0,primeData:"",primeId:""},b||{});this._createView();this._createBehavior();if(this.options.startWithData||this.options.primeData){this._initAjax()}},subscribe:function(a,b){this.events.eventName.push(b)},getPopulateId:function(){return this.populateId},getPopulate:function(){return this.populate},getDatasourceUrl:function(){return this.datasourceUrl},setDatasourceParams:function(a){this.datasourceParms=a},getDatasourceParams:function(){return this.datasourceParms},getOptions:function(){return this.options},_createView:function(){if(this.options.waitActive){var a=new Element("div");a.className="wait";a.style.background='transparent url("'+this.options.imageDirectory+this.options.waitImage+'") center center no-repeat';a.style.width=this.options.waitWidth;a.style.height=this.options.waitHeight;a.style.position="absolute";a.style.left="-9999px";Element.insert(this.populate,{after:a});this.waitbox=a}this.events.build.each(function(b){b.build(this)},this)},_createBehavior:function(){this.events.behavior.each(function(a){a.behavior(this)},this)},activateWait:function(){this.events.hide.each(function(a){a.hide(this)},this);if(this.options.waitActive){this.waitbox.style.left="0"}},deactivateWait:function(){this.events.show.each(function(a){a.show(this)},this);if(this.options.waitActive){this.waitbox.style.left="-9999px"}},_initAjax:function(){if(this.options.primeData){var a={};if(window.navigator.userAgent.indexOf("MSIE")>0){a.responseXML=new ActiveXObject("Microsoft.XMLDOM");a.responseXML.async="false";a.responseXML.loadXML(this.options.primeData)}else{try{var c=new DOMParser();a.responseXML=c.parseFromString(this.options.primeData,"text/xml")}catch(b){a.responseXML=null}}this._ajaxResponse(a,this.options.primeId)}else{this._callAjax()}if(this.options.periodicalExecute){new PeriodicalExecuter(this._callAjax.bindAsEventListener(this),this.options.periodicalPeriod)}},_callAjax:function(){this.activateWait();this.events.fetch.each(function(c){c.fetch(this)},this);var b=this.datasourceUrl+(this.datasourceParms==""?"":"?"+this.datasourceParms);if(this.options.cached&&this.cache[b]){this._ajaxResponse(this.cache[b])}else{var a=new Ajax.Request(b,{method:"get",onSuccess:this._ajaxResponseCache.bindAsEventListener(this,b),onFailure:this._errorHandler.bindAsEventListener(this),asynchronous:true})}},_ajaxResponseCache:function(b,c){var a=b.responseXML;this.deactivateWait();if(a){this.events.retrieve.each(function(d){d.retrieve(this,a)},this);if(this.options.cached){this.cache[c]=b}}else{this.events.hide.each(function(d){d.hide(this)},this)}},_ajaxResponse:function(b,c){var a=b.responseXML;this.deactivateWait();if(a){this.events.retrieve.each(function(d){d.retrieve(this,a,c)},this)}else{this.events.hide.each(function(d){d.hide(this)},this)}},_errorHandler:function(a){this.events.fail.each(function(b){b.fail(this,a)},this)}};var activeSelectObj=Class.create();activeSelectObj.prototype={initialize:function(d,a,c,b,e){this.target=$(a);this.defaultName=e?e:"-- Choose below --";this.cached=b||true;new ajaxWaitingObject(d,c,{build:[this],behavior:[this],hide:[this],fetch:[this],retrieve:[this],show:[this],fail:[this]},{startWithData:false})},clear:function(){this.hide();this._clearTarget()},_clearTarget:function(){this.target.options.length=0;this.target.selectedIndex=0},build:function(a){this.clear()},behavior:function(a){var b=a.getPopulate();b.observe("change",function(c,f){try{this.target.clear()}catch(d){}finally{f._callAjax()}}.bindAsEventListener(this,a));b.clear=this.clear.bind(this)},hide:function(a){this.target.style.display="none"},fetch:function(a){var c=a.getPopulate();var b="";if(!this.cached){b+="nocache=1&"}if(c.selectedIndex&&c.selectedIndex>0){b+="prereq="+c.options[c.selectedIndex].value}a.setDatasourceParams(b)},retrieve:function(g,j,c){var d,b,h,e;this._clearTarget();j=j.getElementsByTagName("root")[0];e=j.getElementsByTagName("options");h=e[0].getElementsByTagName("option");if(h.length>0){var a;for(var f=0;f<h.length;f++){if(f===0){a=document.createElement("option");a.value="";a.innerHTML=this.defaultName;this.target.appendChild(a)}d=h[f].getAttributeNode("id")?h[f].getAttributeNode("id").nodeValue:null;b=h[f].firstChild.nodeValue?h[f].firstChild.nodeValue:null;if(d&&b){a=document.createElement("option");a.value=d;a.innerHTML=b;this.target.appendChild(a)}}}else{this.clear()}},show:function(a){this.target.style.display="block"},fail:function(b,a){alert("An error occured while receiving options.")}};