WeatherLocation=Class.create({initialize:function(container,fieldName,options)
{this.options={selectedValue:''};Object.extend(this.options,options||{});this.locationName='';this.container=$(container);this.container.innerHTML='Cargando...';this.xoapUrl=URL_BASE+"clima/proxyLocation";this.xoapLocation=URL_BASE+"clima/locationName";this.fieldName=fieldName;this.getLocationName();this.start();this.finderActive=false;},appendElements:function()
{oSelf=this;this.container.innerHTML='';this.location_display=new Element('input',{'id':'location_display','class':'location_display','value':this.locationName});this.button=new Element('a',{'id':'location_button'});this.loading=new Element('span',{'id':'location_loading','class':'loading'});this.autocomplete_container=new Element('div',{'id':'autocomplete_container','class':'autocomplete_container'});this.input_field=new Element('input',{'type':'hidden','name':this.fieldName,'value':this.options.selectedValue,'id':'location_value'});this.container.appendChild(this.location_display);this.container.appendChild(this.button);this.container.appendChild(this.loading);this.container.appendChild(this.autocomplete_container);this.container.appendChild(this.input_field);Element.hide(this.loading);this.oACDS=new YAHOO.widget.DS_XHR(this.xoapUrl,["loc","name","id"]);this.oACDS.scriptQueryParam="where";this.oACDS.responseType=YAHOO.widget.DS_XHR.TYPE_JSON;this.oACDS.maxCacheEntries=0;this.oAutoComp=new YAHOO.widget.AutoComplete('location_display','autocomplete_container',this.oACDS);this.oAutoComp.autoHighlight=true;this.oAutoComp.highlightClassName="itemHighlight";this.oAutoComp.doBeforeSendQuery=function(sQuery)
{Element.show('location_loading');return sQuery;};this.oAutoComp.doBeforeExpandContainer=function(elTextbox,elContainer,sQuery,aResults)
{Element.hide('location_loading');return true;};this.oAutoComp.itemSelectEvent.subscribe(function(sType,aArgs)
{oSelf.itemSelectHandler(sType,aArgs)},oSelf,oSelf);this.deactivateFinder();},start:function()
{if(this.container)
{Element.show(this.container);}},deactivateFinder:function()
{var elm=$('location_display');var button=$('location_button');YAHOO.util.Event.removeListener(button,"click");Element.hide('location_loading');Element.removeClassName(elm,'active');elm.disable();button.innerHTML='Cambiar';YAHOO.util.Event.addListener(button,"click",this.activateFinder,this,true);},activateFinder:function()
{var elm=$('location_display');var button=$('location_button');YAHOO.util.Event.removeListener(button,"click");Element.addClassName(elm,'active');button.innerHTML='Cancelar';elm.enable();elm.clear();elm.focus();YAHOO.util.Event.addListener(button,"click",this.resetLocation,this,true);},resetLocation:function()
{var elm=$('location_display');var elmValue=$('location_value');this.deactivateFinder();elmValue.value=this.options.selectedValue;elm.value=this.locationName;},itemSelectHandler:function(sType,aArgs)
{var aData=aArgs[2];this.deactivateFinder();var elm=$('location_value');var attribute={'value':aData[1]};Element.writeAttribute(elm,attribute);this.locationName=aData[0];this.options.selectedValue=aData[1];},getLocationName:function()
{var oSelf=this;if(this.options.selectedValue!='')
{var url=this.xoapLocation+'/'+this.options.selectedValue;new Ajax.Request(url,{onComplete:function(r)
{oSelf.locationName=r.responseText;oSelf.appendElements();}});}
else
{oSelf.locationName='(ninguno)';oSelf.appendElements();}}});