(function(){u8.Crm.ConditionalRecordSelector=function(e){$.extend(this,e);var t=this.target?this.target.adapter:null;if(t){if(this.trueOptions&&this.trueOptions.target&&!this.trueOptions.adapter){this.trueOptions.target.adapter=t}if(this.falseOptions&&this.falseOptions.target&&!this.falseOptions.adapter){this.falseOptions.target.adapter=t}}};$.extend(u8.Crm.ConditionalRecordSelector.prototype,{execute:function(e){var t=this._evalCondition();if(t){u8.services.selectors.selectRecord(this.trueOptions,e)}else{u8.services.selectors.selectRecord(this.falseOptions,e)}},_evalCondition:function(){var e=this.condition;if(!e){return false}var t=this.target.adapter;var a,i=[];var r=/\$\{(\d*)\}/g;while(a=r.exec(e)){i.push(parseInt(a[1]))}var s,n=/\$([a-z0-9_.]+)/i;var o=u8.session.webConfigValues;while(s=n.exec(e)){var l=o[s[1]];if(l===undefined||l===null){l=""}e=e.replace(new RegExp("\\$"+s[1],"g"),l)}var c=this.target.infoAreaId;for(var d=0;d<i.length;d++){var p=i[d];var u=t.getValue(p);var f=new RegExp("\\$\\{"+p+"\\}","g");var v=u8.services.schema.getField(c,p);if(v.dataType=="C"){e=e.replace(f,"'"+u+"'")}else if(v.isNumericField()){if(!u){e=e.replace(f,0)}else{e=e.replace(f,u)}}else if(v.isCatalogField()){if(u.charAt(0)=="#"){e=e.replace(f,parseInt(u.substring(1)))}else{e=e.replace(f,u)}}else{e=e.replace(f,u)}}var h;try{h=evalValue(e)}catch(t){$error({message:"Failed to evaluate condition of conditional record selector!\nEvaluated JavaScript: '"+e+"'\nCondition failed to evaluate: '"+this.condition+"'.",innerError:t});return false}return h}});u8.Crm.ConditionalRecordSelector.makeClass({name:"ConditionalRecordSelector"})})();