function textBoxOnFocus(n,t){$(n).val()==t&&($(n).val(""),$(n).removeClass("grayText"),$(n).css("background-image","none"))}function textBoxOnBlur(n,t){$(n).val()==""&&($(n).val(t),$(n).addClass("grayText"),IntelliSearch.target.parent().find(".updateMe").length>0&&IntelliSearch.target.parent().find(".updateMe").val(0),$(n).css("background-image","url(''"+IntelliSearch.getUrl()+"/images/dropDown.png')"))}var IntelliSearch={};IntelliSearch.currentChoice=-1,IntelliSearch.choiceSize=0,IntelliSearch.isSearchFieldFocus=!1,IntelliSearch.lazyCache={},IntelliSearch.cancelSubmit=function(n){typeof n=="undefined"&&(n=window.event||arguments.callee.caller.arguments[0]);var t=n.which?n.which:n.keyCode;if(t==13)return IntelliSearch.target.parent().find(".IntelliSuggest .IntelliSuggestInner .current").length>0&&IntelliSearch.target.parent().find(".IntelliSuggest .IntelliSuggestInner .current").click(),main.cancelEvent()},IntelliSearch.autocompleteIntelliSearch=function(n){var r,t,i;if(typeof n=="undefined"&&(n=window.event||arguments.callee.caller.arguments[0]),IntelliSearch.target=$(n.target||n.srcElement),r=!1,t=n.which?n.which:n.keyCode,t==38||t==40)return!1;if(t==13&&IntelliSearch.target.parent().find(".IntelliSuggest .IntelliSuggestInner .current").length>0)return IntelliSearch.target.parent().find(".IntelliSuggest .IntelliSuggestInner .current").click(),main.cancelEvent();if(IntelliSearch.target.parent().attr("data-for")=="PracticeArea"&&(i=applicationPath+"Trainers/GetPracticeAreasAutocomplete/"),IntelliSearch.target.parent().attr("data-for")=="GeoArea"&&(i=applicationPath+"Trainers/GetGoeAreasAutocomplete/"),IntelliSearch.target.css("background-image","url('"+applicationPath+"Images/loading29.gif')"),IntelliSearch.lazyCache[IntelliSearch.target.attr("name")]){setTimeout(function(){IntelliSearch.onAutocompleteIntelliSearchSuccess(IntelliSearch.lazyCache[IntelliSearch.target.attr("name")])},100);return}$.ajax({type:"POST",url:i,dataType:"json",data:"{'SearchText':'"+$(IntelliSearch.target).val()+"'}",contentType:"application/json;charset=windows-1255",scriptCharset:"windows-1255",success:IntelliSearch.onAutocompleteIntelliSearchSuccess,error:IntelliSearch.onAutocompleteIntelliSearchSuccess})},IntelliSearch.onAutocompleteIntelliSearchSuccess=function(n){$(IntelliSearch.target).css("background-image",""),n[0]!="noNodes"?(n=IntelliSearch.getFilteredResults(n),IntelliSearch.nodesJSON=n,IntelliSearch.deployAutocomplete()):n.responseXML.childNodes[0].textContent!="noNodes"&&typeof n.responseXML.childNodes[0].textContent!="undefined"?(IntelliSearch.nodesJSON=IntelliSearch.parseJSON(n.responseXML.childNodes[0].textContent),IntelliSearch.deployAutocomplete()):(IntelliSearch.target.parent().find(".IntelliSuggest .IntelliSuggestInner").html(""),IntelliSearch.target.parent().find(".IntelliSuggest .IntelliSuggestInner").hide("slide",{direction:"up"},150),IntelliSearch.nodesJSON="undefined")},IntelliSearch.getFilteredResults=function(n){for(var r=IntelliSearch.target.val().toLowerCase(),i=[],t=0;t<n.length;t++)n[t].Value&&n[t].Value.toLowerCase().indexOf(r)>-1&&i.push(n[t]);return i},IntelliSearch.deployAutocomplete=function(){var n,t;if(typeof IntelliSearch.nodesJSON!="undefined"){var i="",r="",u="";for(IntelliSearch.choiceSize=IntelliSearch.nodesJSON.length,n=0;n<IntelliSearch.nodesJSON.length;n++){for(t=IntelliSearch.nodesJSON[n].Value;t.indexOf("''")>0;)t=t.replace("''","");while(t.indexOf('"')>0)t=t.replace('"',"");u=t,i+=n%2==0?"<span id='choice_"+n+"' onclick='IntelliSearch.handleChoice(\""+t+'", "'+IntelliSearch.nodesJSON[n].Key+"\")'>":"<span id='choice_"+n+"' class='alt' onclick='IntelliSearch.handleChoice(\""+t+'", "'+IntelliSearch.nodesJSON[n].Key+"\")'>",r=IntelliSearch.nodesJSON[n].Value.replace(IntelliSearch.searchText,"<label>"+IntelliSearch.searchText+"</label>"),i+=r,i+="</span>"}IntelliSearch.target.parent().find(".IntelliSuggest .IntelliSuggestInner").html(i).css("height","auto"),IntelliSearch.target.parent().find(".IntelliSuggest .IntelliSuggestInner").show("slide",{direction:"up"},150,function(){$(this).html(i)})}},IntelliSearch.handleChoice=function(n,t){IntelliSearch.target.val(n),IntelliSearch.target.parent().find(".updateMe").val(t)},IntelliSearch.getUrl=function(){for(var n=window.location.href,t="";n.indexOf("/")>-1;)t+=n.substring(0,n.indexOf("/")+1),n=n.replace(n.substring(0,n.indexOf("/")+1),"");return t},IntelliSearch.documentEvent=function(n){if(typeof n=="undefined"&&(n=window.event||arguments.callee.caller.arguments[0]),typeof n!="undefined"&&n.type=="click"){var t=arguments[0]||window.event,i=t.target||t.srcElement;(i.id!="PracticeAreaName"||i.id!="GeoAreaName")&&($(".IntelliSuggest .IntelliSuggestInner").hide("slide",{direction:"up"},150,function(){$(".IntelliSuggest .IntelliSuggestInner").html("").css("height","0")}),IntelliSearch.currentChoice=-1)}return!0},IntelliSearch.handleUpButton=function(){$("#choice_"+IntelliSearch.currentChoice).removeClass("current"),IntelliSearch.currentChoice>0?IntelliSearch.currentChoice--:IntelliSearch.currentChoice=IntelliSearch.choiceSize,IntelliSearch.choiceSize>=IntelliSearch.currentChoice&&$("#choice_"+IntelliSearch.currentChoice).addClass("current")},IntelliSearch.handleDownButton=function(){$("#choice_"+IntelliSearch.currentChoice).removeClass("current"),IntelliSearch.currentChoice<IntelliSearch.choiceSize?IntelliSearch.currentChoice++:IntelliSearch.currentChoice=0,IntelliSearch.choiceSize>=IntelliSearch.currentChoice&&$("#choice_"+IntelliSearch.currentChoice).addClass("current")},IntelliSearch.chooseByKey=function(n){typeof n=="undefined"&&(n=window.event||arguments.callee.caller.arguments[0]);var i=!1,t=n.which?n.which:n.keyCode;return t==38?(IntelliSearch.handleUpButton(),main.cancelEvent()):t==40?(IntelliSearch.handleDownButton(),main.cancelEvent()):void 0},typeof document.captureEvents!="undefined"&&document.captureEvents(Event.CLICK),typeof document.onclick!="undefined"&&(document.onclick=IntelliSearch.documentEvent),IntelliSearch.parseJSON=function(n){if(rvalidchars=/^[\],:{}\s]*$/,rvalidescape=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,rvalidtokens=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,rvalidbraces=/(?:^|:|,)(?:\s*\[)+/g,typeof n!="string"||!n)return null;if(n=jQuery.trim(n),window.JSON&&window.JSON.parse)return window.JSON.parse(n);if(rvalidchars.test(n.replace(rvalidescape,"@").replace(rvalidtokens,"]").replace(rvalidbraces,"")))return new Function("return "+n)();jQuery.error("Invalid JSON: "+n)},IntelliSearch.init=function(){$.each($(".IntelliSearch .autocompleteSearch"),function(){$(this).val()==""&&$(this).val($(this).attr("data-placeholder")),$(this).on("keypress",function(){return IntelliSearch.cancelSubmit()}).on("keyup",function(){return IntelliSearch.autocompleteIntelliSearch()}).on("keydown",function(){return IntelliSearch.chooseByKey()}).on("click",function(){return IntelliSearch.autocompleteIntelliSearch()}).on("focus",function(){IntelliSearch.isSearchFieldFocus=!0,textBoxOnFocus(this,$(this).attr("data-placeholder"))}).on("blur",function(){IntelliSearch.isSearchFieldFocus=!1,textBoxOnBlur(this,$(this).attr("data-placeholder"))}).attr("autocomplete","off")})},$(function(){IntelliSearch.init()})