YAHOO.namespace("ProjectX.helper.InputChecker");YAHOO.ProjectX.helper.InputChecker=function(B,A){this.config=YAHOO.ProjectX.js.base.config;this.lang=YAHOO.ProjectX.data.lang.Ajax;this.oInput=B;this.allowManualMode=!YAHOO.util.Dom.hasClass(this.oInput,"ic-force");this.directlyShowResult=!YAHOO.util.Dom.hasClass(this.oInput,"ic-noresult");this.createEvent("containerCollapseEvent");this.createEvent("containerExpandEvent");this.createEvent("selectionEnforceEvent");this.createEvent("itemSelectEvent");this.findObjects();this.createContainerSelect();if(this.oDefault&&this.oInput&&this.oInput.value.length==0){this.oInput.value=this.oDefault.innerHTML}this.oOldInputValue=this.getInputValue();this.DS=new YAHOO.ProjectX.helper.DataSource(A);this.DS.scriptQueryParam=this.config.AjaxParams["queryParamName"];this.DS.maxCacheEntries=0;this.DS.subscribe("requestEvent",this.onDataRequest,null,this);this.DS.subscribe("responseEvent",this.onDataReturn,null,this);this.DS.subscribe("responseParseErrorEvent",this.onDataReturnError,null,this);this.DS.subscribe("dataErrorEvent",this.onDataReturnError,null,this);this.DS.subscribe("connectionTimeoutEvent",this.onDataReturnError,null,this);this.DS.subscribe("connectionErrorEvent",this.onDataReturnError,null,this);YAHOO.util.Event.addListener(this.oContainerSelect,"change",this.onCheckSelect,null,this);YAHOO.util.Event.addListener(this.oContainerSelect,"blur",this.onCheckSelect,null,this);YAHOO.util.Event.addListener(this.oInput,"blur",this.blurInput,null,this);YAHOO.util.Event.addListener(this.oInput,"focus",this.focusInput,null,this);if(this.oReset!=null){YAHOO.util.Event.addListener(this.oReset,"click",this.onReset,null,this)}if(this.oButton!=null){YAHOO.util.Event.addListener(this.oButton,"click",this.onButton,null,this)}if(this.oInput.form){YAHOO.util.Event.addListener(this.oInput.form,"submit",this.setValuesFromResult,null,this);YAHOO.util.Event.addListener(this.oInput.form,"submit",this.removeObsoleteResults,null,this);if(!this.directlyShowResult){YAHOO.util.Event.addListener(this.oInput.form,"submit",this.showResult,null,this)}}YAHOO.util.Event.addListener(this.oInput,"keydown",this.onTextBoxKey,null,this);this.manualModeQueryLengthRestore=this.minQueryLength;if(this.oId!=null){this.subscribe("selectionEnforceEvent",YAHOO.ProjectX.js.manipulators.clearer.simpleClear,this.oId);if(this.oId.value&&this.oId.value.length>0){this.showOk()}}if(this.oDefault!=null){YAHOO.ProjectX.js.manipulators.clearer.alwaysClearOnDefault(this.oInput,this.oDefault.innerHTML)}if(this.oRadioon!=null&&!this.oRadioon.checked){this.toggleoff()}if(this.oRadioon!=null){YAHOO.util.Event.addListener(this.oRadioon,"click",this.toggleon,this,this)}if(this.oRadiooff!=null){YAHOO.util.Event.addListener(this.oRadiooff,"click",this.toggleoff,this,this)}if(this.oCountrySelect){YAHOO.util.Event.addListener(this.oCountrySelect,"change",this.onItemDeselect,this,this);YAHOO.util.Event.addListener(this.oCountrySelect,"change",this.DS.flushCache,this.DS,this.DS);YAHOO.util.Event.addListener(this.oCountrySelect,"change",this.onCountryChange,this,this)}this.resetSearchParams()};YAHOO.augment(YAHOO.ProjectX.helper.InputChecker,YAHOO.util.EventProvider);YAHOO.ProjectX.helper.InputChecker._instances=0;YAHOO.ProjectX.helper.InputChecker.prototype.config=null;YAHOO.ProjectX.helper.InputChecker.prototype.lang=null;YAHOO.ProjectX.helper.InputChecker.prototype.minQueryLength=2;YAHOO.ProjectX.helper.InputChecker.prototype.maxResultsDisplayed=1000;YAHOO.ProjectX.helper.InputChecker.prototype.directlyShowContainer=true;YAHOO.ProjectX.helper.InputChecker.prototype.DS=null;YAHOO.ProjectX.helper.InputChecker.prototype.oCountrySelect=null;YAHOO.ProjectX.helper.InputChecker.prototype.oInput=null;YAHOO.ProjectX.helper.InputChecker.prototype.oInputGrandparent=null;YAHOO.ProjectX.helper.InputChecker.prototype.oOldInputValue=null;YAHOO.ProjectX.helper.InputChecker.prototype.oInputHasFocus=false;YAHOO.ProjectX.helper.InputChecker.prototype.oContainer=null;YAHOO.ProjectX.helper.InputChecker.prototype.oContainerSelect=null;YAHOO.ProjectX.helper.InputChecker.prototype.oContainerOk=null;YAHOO.ProjectX.helper.InputChecker.prototype.oContainerMessage=null;YAHOO.ProjectX.helper.InputChecker.prototype._oShownResults=null;YAHOO.ProjectX.helper.InputChecker.prototype._recievedAllResults=false;YAHOO.ProjectX.helper.InputChecker.prototype._oSelectedResult=null;YAHOO.ProjectX.helper.InputChecker.prototype.results=-1;YAHOO.ProjectX.helper.InputChecker.prototype.oButton=null;YAHOO.ProjectX.helper.InputChecker.prototype.oReset=null;YAHOO.ProjectX.helper.InputChecker.prototype.oDefault=null;YAHOO.ProjectX.helper.InputChecker.prototype.oHidden=null;YAHOO.ProjectX.helper.InputChecker.prototype.oId=null;YAHOO.ProjectX.helper.InputChecker.prototype.sMessage=null;YAHOO.ProjectX.helper.InputChecker.prototype.copyValuesToInputs=true;YAHOO.ProjectX.helper.InputChecker.prototype.setAllResultsClass=false;YAHOO.ProjectX.helper.InputChecker.prototype.hideContainerOnSelect=false;YAHOO.ProjectX.helper.InputChecker.prototype.allowManualMode=false;YAHOO.ProjectX.helper.InputChecker.prototype.manualMode=false;YAHOO.ProjectX.helper.InputChecker.prototype.manualModeQueryLengthRestore=0;YAHOO.ProjectX.helper.InputChecker.prototype.waitsOnQueryResult=false;YAHOO.ProjectX.helper.InputChecker.prototype.directlyShowResult=true;YAHOO.ProjectX.helper.InputChecker.prototype.oRadioon=null;YAHOO.ProjectX.helper.InputChecker.prototype.oRadiooff=null;YAHOO.ProjectX.helper.InputChecker.prototype.oToggle=null;YAHOO.ProjectX.helper.InputChecker.prototype.reset=function(){if(this.manualMode){this.manualMode=false;this.minQueryLength=this.manualModeQueryLengthRestore;this.manualModeQUeryLengthRestore=0}this.oOldInputValue=null;this._oShownResults=null;this._oSelectedResult=null;this._recievedAllResults=false;this.sMessage=null;this.results=-1;this.waitsOnQueryResult=false;this.DS.clear();if(this.oCountrySelect){this.DS.setQueryParam("country",this.oCountrySelect.options[this.oCountrySelect.selectedIndex].value)}if(this.directlyShowResult){this.showResult()}};YAHOO.ProjectX.helper.InputChecker.prototype.deleteOk=function(){if(this.oId){this.oId.value=""}this.results=-1;if(this.directlyShowResult==true){this.sMessage=null;this.showResult()}};YAHOO.ProjectX.helper.InputChecker.prototype.findObjects=function(){var A=this.oInput.className;if(A!=null&&A.length>0){var G=A.split(" ");findCountry:for(var C=0;C<G.length;C++){var F="ic-country-";if(G[C].length>F.length&&G[C].substr(0,F.length)==F){var B=G[C].substr(F.length,G[C].length);this.oCountrySelect=document.getElementById(B);break findCountry}}findContainer:for(var C=0;C<G.length;C++){var F="ic-container-";if(G[C].length>F.length&&G[C].substr(0,F.length)==F){var B=G[C].substr(F.length,G[C].length);this.oContainer=document.getElementById(B);break findContainer}}findContainerOk:for(var C=0;C<G.length;C++){var F="ic-containerok-";if(G[C].length>F.length&&G[C].substr(0,F.length)==F){var B=G[C].substr(F.length,G[C].length);this.oContainerOk=document.getElementById(B);break findContainerOk}}findContainerMessage:for(var C=0;C<G.length;C++){var F="ic-containermessage-";if(G[C].length>F.length&&G[C].substr(0,F.length)==F){var B=G[C].substr(F.length,G[C].length);this.oContainerMessage=document.getElementById(B);break findContainerMessage}}findOptButton:for(var C=0;C<G.length;C++){var F="ic-button-";if(G[C].length>F.length&&G[C].substr(0,F.length)==F){var B=G[C].substr(F.length,G[C].length);this.oButton=document.getElementById(B);break findOptButton}}findOptReset:for(var C=0;C<G.length;C++){var F="ic-reset-";if(G[C].length>F.length&&G[C].substr(0,F.length)==F){var B=G[C].substr(F.length,G[C].length);this.oReset=document.getElementById(B);break findOptReset}}findOptDefault:for(var C=0;C<G.length;C++){if(G[C].length>11&&G[C].substr(0,11)=="ic-default-"){var E=G[C].substr(11,G[C].length);this.oDefault=document.getElementById(E);break findOptDefault}}findOptId:for(var C=0;C<G.length;C++){if(G[C].length>6&&G[C].substr(0,6)=="ic-id-"){var D=G[C].substr(6,G[C].length);this.oId=document.getElementById(D);break findOptId}}findOptRadioon:for(var C=0;C<G.length;C++){var F="ic-radioon-";if(G[C].length>F.length&&G[C].substr(0,F.length)==F){var B=G[C].substr(F.length,G[C].length);this.oRadioon=document.getElementById(B);break findOptRadioon}}findOptRadiooff:for(var C=0;C<G.length;C++){var F="ic-radiooff-";if(G[C].length>F.length&&G[C].substr(0,F.length)==F){var B=G[C].substr(F.length,G[C].length);this.oRadiooff=document.getElementById(B);break findOptRadiooff}}findOptToggle:for(var C=0;C<G.length;C++){var F="ic-toggle-";if(G[C].length>F.length&&G[C].substr(0,F.length)==F){var B=G[C].substr(F.length,G[C].length);this.oToggle=document.getElementById(B);break findOptToggle}}this.findObjectsExtension(G)}};YAHOO.ProjectX.helper.InputChecker.prototype.createContainerSelect=function(){if(this.oContainer){this.oContainerSelect=document.createElement("select");YAHOO.util.Dom.setStyle(this.oContainerSelect,"display","none");this.oContainer.appendChild(this.oContainerSelect)}};YAHOO.ProjectX.helper.InputChecker.prototype.findObjectsExtension=function(A){};YAHOO.ProjectX.helper.InputChecker.prototype.activateAllResultsClass=function(){this.oInputGrandparent=this.oInput.parentNode.parentNode;this.setAllResultsClass=true};YAHOO.ProjectX.helper.InputChecker.prototype.deactivateAllResultsClass=function(){this.oInputgrandparent=null;this.setAllResultsClass=false};YAHOO.ProjectX.helper.InputChecker.prototype.toggleoff=function(B,A){if(this.oToggle){YAHOO.util.Dom.setStyle(this.oToggle,"display","none")}};YAHOO.ProjectX.helper.InputChecker.prototype.toggleon=function(B,A){if(this.oToggle){YAHOO.util.Dom.setStyle(this.oToggle,"display","")}};YAHOO.ProjectX.helper.InputChecker.prototype.formatResult=function(B,E){var A="";if(B){var D=false;for(var C in B){if(B.hasOwnProperty(C)&&C!="id"){if(D){A+=" "}A+=B[C];D=true}}}return A};YAHOO.ProjectX.helper.InputChecker.prototype.getIdFromResult=function(B,D){var A="";if(B){A=B.id;if(A==null||A.length==0){for(var C in B){if(B.hasOwnProperty(C)){return B[C]}}}}return A};YAHOO.ProjectX.helper.InputChecker.prototype.getInputValue=function(){if(this.oDefault!=null){if(this.oDefault.innerHTML==this.oInput.value){return""}}return YAHOO.ProjectX.helper.string.trim(this.oInput.value).toLowerCase()};YAHOO.ProjectX.helper.InputChecker.prototype.setValuesFromResult=function(B,C){if(B==null||B==undefined||B.type=="submit"){B=this._oSelectedResult}if(B==null){YAHOO.log("No ResultItem given","warn","InputChecker");return }var A=B.name;this.oInput.value=A;this.setIdFromResult(B,C);this.results=1;this.oOldInputValue=this.getInputValue();return B};YAHOO.ProjectX.helper.InputChecker.prototype.setInputIfPossible=function(B){var A=YAHOO.ProjectX.helper.string.trim(this.oInput.value).toLowerCase();var C=YAHOO.ProjectX.helper.string.trim(B).toLowerCase();if(A.length<=C.length){if(A.length==0||C.substr(0,A.length)==A){this.oInput.value=B}}};YAHOO.ProjectX.helper.InputChecker.prototype.setIdFromResult=function(A,B){if(this.oId){this.oId.value=this.getIdFromResult(A)}};YAHOO.ProjectX.helper.InputChecker.prototype.formatContainerResults=function(){YAHOO.log("Starting reset of Options..","info","InputChecker");for(var C=this.oContainerSelect.options.length-1;C>=0;C--){this.oContainerSelect.options[C]=null}YAHOO.log("ShownResults: "+this._oShownResults,"info","InputChecker");if(this._oShownResults==null){return }YAHOO.log("Generating empty option","info","InputChecker");var B=new Option("-","-",true,false);this.oContainerSelect.appendChild(B);YAHOO.log("generating the options "+this._oShownResults.length,"info","InputChecker");for(var A=0;A<this._oShownResults.length;A++){YAHOO.log("in for ("+A+")","info","InputChecker");if(this._oShownResults.hasOwnProperty(A)){var E=this.getIdFromResult(this._oShownResults[A]);var D=new Option(this.formatResult(this._oShownResults[A]),E,false,(this.oId&&this.oId.value==E));this.oContainerSelect.options[this.oContainerSelect.length]=D}}};YAHOO.ProjectX.helper.InputChecker.prototype.showOk=function(){this.hideMessage();if(this.oContainerOk){YAHOO.util.Dom.addClass(this.oContainerOk,"inputchecker-ok");this.oContainerOk.innerHTML="&nbsp;";YAHOO.log("show ok ","info","InputChecker")}this.hideContainer()};YAHOO.ProjectX.helper.InputChecker.prototype.hideOk=function(){if(this.oContainerOk){YAHOO.util.Dom.removeClass(this.oContainerOk,"inputchecker-ok");YAHOO.log("hiding ok ","info","InputChecker")}};YAHOO.ProjectX.helper.InputChecker.prototype.showMessage=function(A){this.hideOk();if(this.oContainerMessage&&A!=null&&A.length>0){YAHOO.util.Dom.addClass(this.oContainerMessage,"inputchecker-message");this.oContainerMessage.innerHTML=A;YAHOO.log("show message ","info","InputChecker")}if(this.oContainerOk){YAHOO.util.Dom.addClass(this.oContainerOk,"inputchecker-notok");this.oContainerOk.innerHTML="&nbsp;";YAHOO.log("show not-ok ","info","InputChecker")}};YAHOO.ProjectX.helper.InputChecker.prototype.hideMessage=function(){if(this.oContainerMessage){YAHOO.util.Dom.removeClass(this.oContainerMessage,"inputchecker-message");this.oContainerMessage.innerHTML="";YAHOO.log("hiding message ","info","InputChecker")}if(this.oContainerOk){YAHOO.util.Dom.removeClass(this.oContainerOk,"inputchecker-notok");this.oContainerOk.innerHTML="";YAHOO.log("hiding not-ok ","info","InputChecker")}};YAHOO.ProjectX.helper.InputChecker.prototype.showAllResultsClass=function(){if(this.oInputGrandparent!=null){YAHOO.util.Dom.addClass(this.oInputGrandparent,"inputchecker-allresults");this.oContainerSelect.focus()}};YAHOO.ProjectX.helper.InputChecker.prototype.hideAllResultsClass=function(){if(this.oInputGrandparent!=null){YAHOO.util.Dom.removeClass(this.oInputGrandparent,"inputchecker-allresults")}};YAHOO.ProjectX.helper.InputChecker.prototype.showContainer=function(){if(this._oShownResults!=null){YAHOO.util.Dom.setStyle(this.oContainerSelect,"display","");if(this.setAllResultsClass&&this._recievedAllResults==true){this.showAllResultsClass();this.oContainer.focus()}this.fireEvent("containerExpandEvent")}};YAHOO.ProjectX.helper.InputChecker.prototype.hideContainer=function(){YAHOO.util.Dom.setStyle(this.oContainerSelect,"display","none");if(this.setAllResultsClass&&this._recievedAllResults==true){this.hideAllResultsClass()}this.fireEvent("containerCollapseEvent")};YAHOO.ProjectX.helper.InputChecker.prototype.showResult=function(){if(this.waitsOnQueryResult==true){return }if(this.sMessage!=null&&this.sMessage.length>0){this.showMessage(this.sMessage)}else{this.hideMessage()}if(this.results<=0){this.hideOk();this.hideContainer();if(this.manualMode==false){this.fireEvent("selectionEnforceEvent")}}else{if(this.results==1){this.showOk();this.hideContainer();if(this.copyValuesToInputs==true){this.setValuesFromResult(this._oSelectedResult)}this.fireEvent("itemSelectEvent")}else{if(this.results>1){this.hideOk();if(this._oShownResults!=null&&this._oShownResults.length>0){this.showContainer()}}else{this.hideContainer();this.hideOk()}}}};YAHOO.ProjectX.helper.InputChecker.prototype.onCountryChange=function(){this.reset()};YAHOO.ProjectX.helper.InputChecker.prototype.onDataRequest=function(B,A){if(this.manualMode==true){return }if(this.waitsOnQueryResult==true){return }YAHOO.log("OnDataRequest","info","AutocompleteSend");if(this.directlyShowResult==true){YAHOO.ProjectX.helper.dom.showLoading(this.oInput,"right")}this.waitsOnQueryResult=true;this.sMessage=""};YAHOO.ProjectX.helper.InputChecker.prototype.onDataReturn=function(D){YAHOO.log("OnDataReturn","info","InputChecker");var C=D.request;var E=D.result;var A=D.response;if(this.directlyShowResult==true){YAHOO.ProjectX.helper.dom.hideLoading(this.oInput)}this.waitsOnQueryResult=false;var B=null;this.sMessage=null;this.hideOk();if(this.oId){this.oId.value=""}this._oShownResults=null;this._oSelectedResult=null;this._recievedAllResults=false;if(E.length==0){YAHOO.log("OnDataReturn:size==0, query:"+C,"info","InputChecker");B="NoResults";this.results=0;if(this.allowManualMode==true){YAHOO.log("no results msg:"+this.lang.NoResultsPleaseTypeIn,"info","InputChecker");B="NoResultsPleaseTypeIn";this.manualMode=true}else{this.fireEvent("selectionEnforceEvent")}}else{if(E.length==1){this.results=1;this.sMessage=null;YAHOO.log("Exactly one item","info","InputChecker");this.manualMode=false;this._oSelectedResult=E[0];this.setIdFromResult(E[0],C);this.showOk()}else{if(E.length>1){this.results=E.length;B="ManyResults";this._oShownResults=E;this.manualMode=false;YAHOO.log("ManyResults","info","InputChecker");if((C==null||C.length==0)&&this.setAllResultsClass==true){this._recievedAllResults=true;B="AllResults"}this.formatContainerResults()}}}if((this.sMessage==null||this.sMessage.length==0)&&B!=null&&this.lang.hasOwnProperty(B)){this.sMessage=this.lang[B]}if(this.directlyShowResult==true){this.showResult()}};YAHOO.ProjectX.helper.InputChecker.prototype.onDataReturnError=function(C){YAHOO.log("OnDataReturnError","info","InputChecker");if(this.directlyShowResult==true){YAHOO.ProjectX.helper.dom.hideLoading(this.oInput)}var B=C.request;var D=C.result;this._oJSONResult=C.response;this.waitsOnQueryResult=false;this.results=-1;this.sMessage=null;var A=null;if(this._oJSONResult!=undefined){A=this._oJSONResult.getErrorMessage()}if(A==null){A="ConnectionError"}if(A=="NoResults"&&this.allowManualMode==true){A="NoResultsPleaseTypeIn"}if(A!=null&&this.lang.hasOwnProperty(A)){this.sMessage=this.lang[A]}if(this.directlyShowResult==true){this.showResult()}else{this.hideOk()}};YAHOO.ProjectX.helper.InputChecker.prototype.focusInput=function(B,A){this.oInputHasFocus=true};YAHOO.ProjectX.helper.InputChecker.prototype.blurCheck=function(){if(this.getInputValue().length==0){this.reset();return }if(this.getInputValue()!=this.oOldInputValue){this.deleteOk()}};YAHOO.ProjectX.helper.InputChecker.prototype.blurInput=function(D,C){this.blurCheck();this.oInputHasFocus=false;if(this.manualMode==true){if(this.oId){this.oId.value=""}var A=this.getInputValue();if(A!=null&&A.length>0){this.oInput.value=YAHOO.ProjectX.helper.string.firstToUpper(A)}}else{if(this.oButton==null){var B=this.getInputValue();if(this.isQueryAllowed()){this.sendQuery(B)}}}};YAHOO.ProjectX.helper.InputChecker.prototype.onButton=function(C,B){YAHOO.log("onButton","info","InputChecker");if(this.isQueryAllowed()){var A=this.getInputValue();this.sendQuery(A)}if(C!=null){YAHOO.util.Event.preventDefault(C)}};YAHOO.ProjectX.helper.InputChecker.prototype.onReset=function(B,A){YAHOO.log("onReset","info","InputChecker");this.reset();this.showResult()};YAHOO.ProjectX.helper.InputChecker.prototype.onTextBoxKey=function(D,C){if(this.getInputValue().length==0&&this.manualMode==true){this.manualMode=false;this.minQueryLength=this.manualModeQueryLengthRestore}var B;var A;if(C==null){B=D.keyCode;A=D}else{B=C[1];A=null}YAHOO.log("key: "+B+" waits: "+this.waitsOnQueryResult,"info","InputChecker");if(B==13){if(this.oButton!=null){this.onButton()}if(A){YAHOO.util.Event.preventDefault(A)}return false}};YAHOO.ProjectX.helper.InputChecker.prototype.onCheckSelect=function(C,B){YAHOO.log("OnCheckSelect","info","InputChecker");this.hideOk();if(this._oShownResults){var A=this.oContainerSelect.selectedIndex-1;if(A==-2){if(!this.allowManualMode){YAHOO.log("Reseting values (enforce) "+C+"aArgs "+B[0],"info","InputChecker");this.oInput.value="";this.resetSearchParams();this.fireEvent("selectionEnforceEvent")}}else{if(A==-1){}else{this._oSelectedResult=this._oShownResults[A];this.setValuesFromResult(this._oShownResults[A],this.oOldInputValue);this.results=1;this.showOk();if(this.hideContainerOnSelect==true){this.hideContainer()}this.fireEvent("itemSelectEvent")}}}};YAHOO.ProjectX.helper.InputChecker.prototype.isQueryAllowed=function(){var A=this.getInputValue();if(A==this.oOldInputValue){return false}if(A!=null&&A.length<this.minQueryLength){return false}return true};YAHOO.ProjectX.helper.InputChecker.prototype.sendQuery=function(A){A=YAHOO.ProjectX.helper.string.trim(A).toLowerCase();var B=false;if(this.oOldInputValue!=null&&this.oOldInputValue.length>0){B=(A.substr(0,this.oOldInputValue.length)==this.oOldInputValue)}if(!B){this.manualMode=false}if(this.manualMode!=true){this.resetSearchParams();this.DS.query(A,B);this.oOldInputValue=A}};YAHOO.ProjectX.helper.InputChecker.prototype.resetSearchParams=function(){if(this.oCountrySelect&&this.oCountrySelect.selectedIndex>=0){this.DS.setQueryParam("country",this.oCountrySelect.options[this.oCountrySelect.selectedIndex].value)}else{this.DS.setQueryParam("country",this.config.Global["defaultCountry"])}};