(function(){var e=n,t=W("#mysite-url-add")[0],n=W("#mysite-name-add")[0],r=W("#mysite .site-name")[0],i=W("#mysite-url-suggest")[0],s=W("#mysite-name-suggest")[0],o=t.form,u=function(){var r=e;return W(t).on("focus",function(){r=t}),W(n).on("focus",function(){r=n}),function(){return r}}(),a=function(e){return placeholderHook?placeholderHook(e).getVal():e.value},f=function(e,t){placeholderHook?placeholderHook(e).setVal(t):e.value=t},l=function(){return u()==t?a(n)=="":a(t)==""},c=new qSuggest(t,{uiReferElem:r,uiContainerElem:i,posAdjust:{top:-1,"z-index":430}}),h=new qSuggest(n,{uiReferElem:r,uiContainerElem:s,posAdjust:{top:-1,"z-index":430}}),p=function(){var e=qSuggest.log,r="common",i={},s={},o=function(e){return String(e).replace(/[^\x00-\xff]/g,"abc").replace(/[\d]/g,"abc").length};return function(a){if(!a)return;s[r]=[1,20],i[r]=[];var c=a.ui,h=a.data,p=c.textInput[0];h.bindGroupHandler(r,{request:function(e,n){if(!l())return;if(!n||!e)return;var i=u()==t?"websiteurl":"websitename",a=o(e);a>=s[r][0]&&a<=s[r][1]&&qboot.jsonp("http://suggest.h.qhimg.com/index.php?biz="+i+"&word="+encodeURIComponent(e)+"&fmt=jsonp&cnt=8",function(t,r){n({q:e,data:t})},{jsonp:"cb"})},receive:function(e){return e&&e.data&&e.data.length>0?{query:e.q,data:e.data}:null}}),c.bindGroupHandler(r,{render:{setup:function(){i[r]=[]},build:function(){var e=0;return function(e){if(!e)return"";var t="",n,i,s=a.query.length;c.setGroupTotal(r,e.length);for(var o=0,u=e.length;o<u;o++){var f=e[o].split(",");if(f.length!=2)continue;f[0]=f[0]?f[0].trim():"",f[1]=f[1].trim(),n=f[0].toLowerCase(),i=f[1].toLowerCase(),n=n.replace(new RegExp(a.query,"ig"),"<em>"+a.query+"</em>"),i=i.replace(new RegExp(a.query,"ig"),"<em>"+a.query+"</em>"),t+='<li><div class="sug-name" data-text="'+f[0]+'">'+n+'</div><div class="sug-url" data-text="'+f[1]+'">'+i+"</div></li>"}return t}}(),teardown:function(){i[r]=W("li",c.container)}},init:function(){c.initGroupMouseBehavior(r,"li"),c.on("itemSelect",function(s){if(s.group!==r)return;if(s.index>-1&&i[r][s.index]){var o=i[r].item(s.index);f(t,o.query(">div.sug-url").attr("data-text")),f(n,o.query(">div.sug-name").attr("data-text")),s.trigger=="keyboard"&&c.fire("enter",{trigger:s.trigger}),s.trigger=="mouse"&&c.focusTextInput(),e("itemSelect[COMMON] index:"+s.index)}}),c.on("itemFocus",function(e){if(e.group!==r)return;if(e.index>-1&&i[r][e.index]){var s=i[r].item(e.index);s.addClass("hover"),e.trigger==="keyboard"&&(f(t,s.query(">div.sug-url").attr("data-text")),f(n,s.query(">div.sug-name").attr("data-text")))}}),c.on("itemBlur",function(e){if(e.group!==r)return;e.index>-1&&i[r][e.index]&&i[r].item(e.index).removeClass("hover")})}}),c.on("restoreQuery",function(e){u()==t&&f(n,""),u()==n&&f(t,"")}),c.on("itemSelect",function(e){c.hide()}),c.on("enter",function(e){c.resetTextInput()}),c.oldShow=c.show,c.show=function(){if(!l()){c.hide();return}c.oldShow()},W(document).on("mouseup",function(e){var t=W(e.target),r="mysite-url-add",i="mysite-url-suggest";u()==n&&(r="mysite-name-add",i="mysite-name-suggest"),(!t.attr("id")||[r,i].indexOf(t.attr("id"))==-1)&&!t.parentNode("#"+r)[0]&&!t.parentNode("#"+i)[0]&&c.hide()}),W(p==t?n:t).on("focus",function(e){if(!l()){c.hide();return}}),W(window).on("blur",function(){c.hide()})}}();p(h),p(c)})();