var TMall=window.TMall||{};TMall.THeader=function(){var g=KISSY,t=g.DOM,v=g.Event,w=document,u="active",j=g.UA.ie,m=navigator.appVersion.indexOf("Mac")>-1,l,k,f,i,c,h,a=['\u6309<span class="'+(m?"cmd":"ctrl")+' key">Ctrl</span>+<span class="enter key">Enter</span>\u53ef\u76f4\u63a5\u641c\u7d22\u6dd8\u5b9d\u5546\u57ce\u5e97\u94fa','\u6309 <span class="tab key">tab</span> \u5207\u6362\u641c\u7d22\u8303\u56f4'],q=a[Math.floor(Math.random()*a.length)];function p(x){if("A"==x.tagName){f.setAttribute("value",x.getAttribute("data-type"));c.setAttribute("action",x.href||"http://list.tmall.com/search_dispatcher.htm");g.each(l.getElementsByTagName("A"),function(y){t.removeClass(y,u)});t.addClass(x,u);i.innerHTML=x.getAttribute("data-label");e();k.focus();if(j){k.value=k.value}}}function e(){}function s(){var y,A=q,D,x=/(\?|\&)area=b2c(\&|$)/;function z(){return false}function E(){h.query="";h._dataCache={};h.detach("beforeStart",z)}function B(){var F=document.createElement("div");F.className="mall-search-tip";F.innerHTML=A;return F}if(g.Suggest&&g.Suggest.version>=1.1){h=new g.Suggest(k,"http://suggest.taobao.com/sug?area=b2c&code=utf-8",{containerCls:"mall-suggest-container",resultFormat:"",offset:0});y=h.container;e=function(){var F=f.value;if("p"==F||""==F){E();A=q;if(h.dataSource.search(x)<0){h.dataSource=h.dataSource.replace(/\?([^&]*)(&|$)/,"?area=b2c&$1$2")}}else{if("taobao"==F){E();A=a[1];var G=h.dataSource.replace(x,"$1");h.dataSource=G}else{h.stop();h.hide();h.on("beforeStart",z)}}};h.on("updateFooter",function(F){if(t.text(h.content)){h.footer.appendChild(B())}})}else{if(window.TB&&TB.Suggest){h=new TB.Suggest(k,"http://suggest.taobao.com/sug",{resultFormat:"",containerClassName:"suggest-container mall-tb-suggest-container"});y=h.container;D=h.container.style.left;h.subscribe("beforeDataRequest",function(){if(h.dataSource.search(x)<0){h.queryParams=h.queryParams.replace(/^([^&]*)&/,"area=b2c&$1&")}});h.subscribe("beforeShow",function(){y.appendChild(B());if(y.shim){y.shim.style.top=(parseInt(y.style.top)-2)+"px";y.shim.style.height=y.offsetHeight+"px"}});if((!j||j>7)&&f.value=="p"){var C=true;v.on(k,"focus",function(){if(C){console.log("fix");h._setContainerRegion();D=h.container.style.left;C=false}v.remove(k,"focus",arguments.callee)})}e=function(){if("s"==f.value){y.style.left="-9999px";if(y.shim){y.shim.style.left="-9999px"}}else{y.style.left=D;if(y.shim){y.shim.style.left=(parseInt(D)-2)+"px"}}}}}}function r(z,A){function x(B,C){var D=document.createElement("input");D.setAttribute("type","hidden");D.setAttribute("name",B);D.setAttribute("value",C);return D}for(var y in A){if(!z[y]){z.appendChild(x(y,A[y]))}else{z[y].value=A[y]}}}function o(C,B){var z,x,A,y=t.children(B);for(z=0,x=y.length;z<x;){A=y[z++];if(A.getAttribute("data-type")==C){return A.href}}}function b(){setTimeout(function(){f.value=g.get("."+u,l).getAttribute("data-type");if(k.value==""){i.style.visibility="visible"}},100)}function n(C){function x(E){return E.offsetHeight>0&&C.offsetWidth>0}function y(G){var F={A:1,AREA:1,BUTTON:1,INPUT:1,OBJECT:1,SELECT:1,TEXTAREA:1},E;return x(G)&&(F[G.nodeName]||((E=G.getAttributeNode("tabIndex"))&&E.specified&&E.nodeValue>-1))}var A,z,B,D=C.parentNode;while(C=t.prev(C)){A=C.getElementsByTagName("*");z=A.length;while(z>0){if((B=A[--z])&&y(B)){return B}}if(y(C)){return C}}return D&&n(D)}var d=function(A){var y="",C,x=false,z=false,B;l=g.get("#J_SelectTypes");k=g.get("#mq");f=g.get("#J_Type");i=t.prev(k);c=k.form;B=o("s",l);b();if(j&&j<8){C=t.children(l,function(D){D.hideFocus=true;return true})}else{C=t.children(l)}v.on(k,"focus",function(){i.style.color="#ccc"});v.on(k,"blur",function(D){if(this.value==""&&!x){i.style.visibility="visible";i.style.color="#666"}x=false});v.on(l,"mousedown",function(){x=true});v.on(l,"click",function(D){p(D.target);D.halt()});v.on(C,"focus",function(D){k.focus();D.halt()});v.on(k,"keydown",function(G){var F=G.keyCode,D,E;y=k.value;if(F==9){z=true;D=g.get("."+u,l);if(G.shiftKey){if(E=t.prev(D)){p(E)}else{E=n(c.parentNode);E&&E.focus()}}else{if(E=t.next(D)){p(E)}else{t.next(k).focus()}}G.halt()}else{if((G.ctrlKey||G.metaKey)&&F==13){f.setAttribute("value","s");c.setAttribute("action",B);c.submit();G.halt()}else{if(F==8||F==46){i.style.visibility="hidden"}else{if(F<13||(F>41&&F<112)||F>123){i.style.visibility="hidden"}}}}});v.on(k,"keypress",function(D){if(z){z=false;D.halt()}});v.on(k,"keyup",function(E){var D=E.keyCode;if(this.value==""){if(y!=""||!(D==8||D==46)){i.style.visibility="visible"}}});v.on(k,"mouseover",function(D){if(this.value!=""){i.style.visibility="hidden"}});v.on(c,"submit",function(){if(f.value==="taobao"){r(c,{sort:"",cat:"",style:"grid"})}else{if(f.value==="item"){r(c,{search:"y",newHeader_b:"s_from",searcy_type:"item"})}}});s();e();A&&k.focus()};d.init=function(x){d(x)};d.switchTo=function(A){var y=l.getElementsByTagName("A"),x=y.length,z;while(x>0){z=y[--x];if(z.getAttribute("data-type")==A){return p(z)}}};return d}();
