var DISABLE_AUTO_SUGGEST;var IS_DEBUG=false;var DISABLE_AUTO_HIDE=false;var autoSuggestConfig={panelId:"sw_as",debug:IS_DEBUG,inputId:"sh",formId:"sf",closedIndicatorId:"as_indicator_closed",openedIndicatorId:"as_indicator_opened",messagePanelHeight:25,disableTxt:"Turn Auto Suggestion off",enableTxt:"Turn Auto Suggestion on",maxSug:8,typeDel:50,expDays:60,market:"en-au",apiUrl:"http://api.bing.com/qson.aspx?FORM=ASMSNA",animate:true};var QS_AS='&qs=n';$(document).ready(function(){attachAS2Main();executeAutoSuggest();});function attachAS2Main(){try{var contentsPanel=document.getElementById("main");var wrapperPanel=document.createElement("div");wrapperPanel.id="auto_suggestion_wrapper";var suggestionPanel=document.createElement("div");suggestionPanel.id=autoSuggestConfig.panelId;wrapperPanel.appendChild(suggestionPanel);var indicatorPanel=document.createElement("div");indicatorPanel.id=autoSuggestConfig.closedIndicatorId;wrapperPanel.appendChild(indicatorPanel);contentsPanel.appendChild(wrapperPanel);promoTopAdjust('increase','auto_suggestion_wrapper');}
catch(error){if(IS_DEBUG){alert("attachAS2Main:"+error);};};};var autoSuggestInstance;function autoSuggest(config){var pc=window,m=document,ib=undefined,yc=location.search,Pb=m.getElementsByTagName("head")[0],pb=navigator.userAgent.indexOf("MSIE")>-1,kc=pb&&!window.XMLHttpRequest,e,R={},wb={},K=-1,J=1,vb=2,Rb=3,sb=8,tb=15,xb=65,Sb=128,Fb=35,To=50,ec="firstChild",y="innerHTML",c="appendChild",F="className",o="div",l="style",Z="onreadystatechange",Lb="onload",Kb="onerror",nb="value",u="length",jb="height",U="display",wc="indexOf",Db="nextSibling",yb="previousSibling",O="readyState",kb="loaded",gb="onmousedown",G="mouseout",Q="mouseover",fb="offsetHeight",ob="href",Hb="0",qc="ul",qb="li",rb="a",tc="AutoSugg",fc="sa_sg",Mb="as_sc",containerId="sa_as",i=this,V=false,nc=new RegExp("^\\s*|\\s*$","g"),Xb=new RegExp("\\s+","g"),vc=m.body.innerText!=ib?"innerText":"textContent",hc=config.animBounce&&config.animate,disabled,panelOpened,form,input,container,arrowPanel,mainPanel,listPanel,messagePanel,indicatorPanelOpened,indicatorPanelClosed,onMessageClick,hb,ab,Ab,mb,lb,D,uc,xc,Qb,M,I,f,Cb,z,eb,Gb,j,C,db,v,t,h,Jb,b,bb,cb,p;eb=j=C=db=v=t=0;this.init=function(i){try{QS_AS='&qs=n';cookieName="search_as";disabled=mc();form=X(config.formId);input=X(config.inputId);input.blur();input.setAttribute("autocomplete",(disabled?"on":"off"));input.focus();var j=X(config.panelId);f=config.enableHist?true:false;Cb=config.hitHigh?true:false;if(kc){try{m.execCommand("BackgroundImageCache",false,true);}
catch(k){};};container=X(containerId);if(container){container.parentNode.removeChild(container);};container=d(o,containerId);Gb=container[l].left;j[c](container);var e=d(o,"","sw_b3");container[c](e);var h=d(o,"","sw_b2");e[c](h);mainPanel=d(o,"sa_as3","sw_b1");h[c](mainPanel);Ab=i;listPanel=d(o,"sa_drw");if(f){p=new HistSuggest;if(!(f=p.init())){setLocalCookie("search_as",'1',true,0);};};mainPanel[c](listPanel);messagePanel=d(o,"sa_om");var b=d(qc);mb=d(qb,"sa_tf");_anchorTurnOff=d(rb);_anchorTurnOff[y]=disabled?config.enableTxt:config.disableTxt;_anchorTurnOff[gb]=onMessageClick;_anchorTurnOff[ob]="javascript:void(null);";mb[c](_anchorTurnOff);b[c](mb);if(config.optTxt!=ib){lb=d(qb,"sa_ol");D=d(rb);D[ob]=config.optUrl+"&sh=4";D[y]=config.optTxt;D[gb]=Zb;lb[c](D);b[c](lb);};if(config.helpTxt!=ib){_help=d(qb,"sa_hl");_anchorHelp=d(rb);_anchorHelp[ob]=config.helpUrl;_anchorHelp.target="_blank";_anchorHelp[y]=config.helpTxt;_anchorHelp[gb]=dc;_anchorHelp.onmouseup=jc;_help[c](_anchorHelp);b[c](_help);};messagePanel[c](b);mainPanel[c](messagePanel);Qb="";M=config.maxSug;I=1;apiUrl=config.apiUrl+"?market="+config.market.Mkt+"&options=EnableSuggestionType"+(Cb?"+EnableHighlighting":"")+"&JsonType=callback&JsonCallback="+Ab+".setData";var topMenu=$("#portal_nav_menu");if(topMenu.length>0){attachEvent(topMenu[0],"mouseover",closePanel);};if(config.outofScope){appendIndicator();}
else{this.attachEvents2Form();if(disabled){disableAS();}
else{enableAS();};};swapIndicator();onMessageClick=false;}
catch(error){if(IS_DEBUG){alert("init:"+error);};};};this.attachEvents2Form=function(){attachEvent(form,"submit",onSubmit);attachEvent(input,"keyup",onKeyup);attachEvent(input,"click",onClick);attachEvent(input,"blur",onBlur)};this.createSuggestion=function(l,p,m,n){try{var j=listPanel.childNodes;if(n){for(var h=0;h<j.length;h++){if(j[h]&&(j[h].tid==m)){break;};};}
else if(j[h]&&(j[h].sug==l.Text)){return null;};var b=d(o,"",p);attachEvent(b,"mousedown",i.onMouseDownSuggestion);attachEvent(b,Q,Vb);attachEvent(b,G,Ub);attachEvent(b,"mousemove",ub);var k=d(o,"","sa_tm");b.tid=k.tid=m;b[c](k);var e=l.Text;b.sug=e;if(f&&config.enableMetaData&&e.length>Fb){e=e.substring(0,Fb)+"...";};k[y]=e;listPanel[c](b);}
catch(error){if(IS_DEBUG){alert("createSuggestion:"+error);};};return b;};this.setData=function(d){var a="",b=[];--v;try{a=lc(d.SearchSuggestion.Query);if(!(b=d.SearchSuggestion.Section)){b=[];};var c=Hb+a;if(b.length==0){wb[c]=true;}
else if(!R[c]&&eb<Sb){R[c]=d;eb++;};N();if(a!=h.toLowerCase()){if(v>0){L();};return;};}
catch(e){i.buildSuggestions("","",true);return;};i.buildSuggestions(b,a);};this.getSelectedSug=function(){return bb;};this.getHistCont=function(){return p;};this.showDropDown=function(){swapIndicator(true);};this.buildSuggestions=function(a,e,d){try{listPanel[y]="";if(f){C=db=p.buildHistorySuggestionList(d?M:M-a[u]);};if(!d){var b=Math.min(a[u],M-db);for(var c=0;c<b;c++){if(!i.createSuggestion(a[c],fc,1,f)){b<a[u]?++b:"";};};C=listPanel.childNodes.length;};if(C==0){ab=setTimeout(Y(closePanel,true),To);return;};if(!disabled){openPanel();};}
catch(error){if(IS_DEBUG){alert("buildSuggestion:"+error);};};};this.getCurrentQuery=function(){return h;};this.doFetch=function(a){try{if(e){e.src=a;Jb=h;if(pb){e[Z]=i.onBeforeFetchComplete;}
else{e[O]=kb;e[Lb]=e[Kb]=Bb;i.onBeforeFetchComplete();};};}
catch(error){if(IS_DEBUG){alert("doFetch:"+error);};};};this.onBeforeFetchComplete=function(){try{if(e[O]==kb||e[O]=="complete"){e[Z]=Bb;var a=X(Mb);if(a){Pb.removeChild(a);};Pb[c](e);};}
catch(error){if(IS_DEBUG){alert("onBeforeFetchComplete:"+error);};};};function X(a){return m.getElementById(a);};function attachEvent(a,d,b,c){if(a.addEventListener){a.addEventListener(d,b,c);}
else if(a.attachEvent&&!c){a.attachEvent("on"+d,b);}
else if(a.setAttribute&&!c){a.setAttribute("on"+d,b);};};function removeEvent(a,d,b,c){if(a.removeEventListener){a.removeEventListener(d,b,c);}
else if(a.detachEvent&&!c){a.detachEvent("on"+d,b);};};function s(e,c,b){var a;try{if(pb){if(b){a=m.createEventObject();a.sourceElement=b;e.fireEvent("on"+c,a)}
else{e.fireEvent("on"+c);};}
else{var d="HTMLEvents";if(c!="submit"){d="MouseEvents";a=m.createEvent(d);a.initEvent(c,true,true,pc,0,0,0,0,0,false,false,false,false,0,b)}
else{a=m.createEvent(d);a.initEvent(c,true,true)}
if(b)a.sourceElement=b;e.dispatchEvent(a)};}
catch(error){if(IS_DEBUG){alert("s:"+error);};};};function d(d,c,b){try{var a=m.createElement(d);if(c){a.id=c;};if(b){a["className"]=b;};}
catch(error){if(IS_DEBUG){alert("d:"+error);};};return a;};function Y(c){try{var b=new Array;for(var i=1;i<arguments.length;i++){b[i-1]=arguments[i];};}
catch(error){if(IS_DEBUG){alert("Y:"+error);};};return function(){c.apply(null,b);};};function sc(a){return a.replace(nc,"").replace(Xb," ");};function T(b){try{var a=b.srcElement?b.srcElement:b.target;if(a[F]=="sa_tm"){a=a.parentNode;};}
catch(error){if(IS_DEBUG){alert("T:"+error);};};return a;};function ub(b){try{var a=T(b);if(z){z=false;s(a,Q,a);removeEvent(a,"mousemove",ub);};}
catch(error){if(IS_DEBUG){alert("ub:"+error);};};};this.onMouseDownSuggestion=function(a){try{var b=T(a);cb=b;}
catch(error){if(IS_DEBUG){alert("onMouseDownSuggestion:"+error);};};};function Vb(c){try{var a=T(c);if(z){return;};if(b){s(b,G,a);};if(!a.hover){a[F]=a[F]+" sa_hv";a.hover=true;b=a;};}
catch(error){if(IS_DEBUG){alert("Vb:"+error);};};};function Ub(c){try{var a=T(c);if(a.hover){a[F]=a[F].replace(" sa_hv","");a.hover=false;b=null;};}
catch(error){if(IS_DEBUG){alert("Ub:"+error);};};};function onMessageClick(){try{onMessageClick=true;if(disabled){if(h==""){listPanel[y]="";};enableAS();AdTrack.t('http://ninemsn.com.au/','NH_SEARCH_AS_INT',2);panelOpened=false;onClick();if(isListExist()){displayMainPanel();}
else{onCloseCompleted();};}
else{swapIndicator(false);disableAS();AdTrack.t('http://ninemsn.com.au/','NH_SEARCH_AS_INT',3);closePanel();hideMainPanel();setTimeout(displayMainPanel,To*10);};this[y]=disabled?config.enableTxt:config.disableTxt;}
catch(error){if(IS_DEBUG){alert("onMessageClick:"+error);};};};function Zb(){V=true;};function dc(){V=true;};function jc(){V=false;closePanel();};function mc(){var enabled;if(GetCookie("search_as")==='0'){enabled=true;}
else{enabled=false;}
return enabled;};function x(c,d,e,b){try{if(!b){b=Rb;};if(config.animate&&Math.abs(c-d)>tb){c+=tb*e;setHeight(c);setTimeout(Y(x,c,d,e,b),b);}
else{onOpenCompleted(d,e,b);};}
catch(error){if(IS_DEBUG){alert("x:"+error);};};};function onOpenCompleted(a,c,b){try{setHeight(a);if(hc&&t<vb){if(c==J){setTimeout(Y(x,a,j-(xb-xb/vb*t),K,sb*(t+2)),b);}
else{setTimeout(Y(x,a,j,J,sb*(t+1)),b);t++;};}
else if(c==K&&a==0){onCloseCompleted();};}
catch(error){if(IS_DEBUG){alert("onOpenCompleted:"+error);};};};function setHeight(height){try{mainPanel[l][jb]=(disabled?config.messagePanelHeight:parseInt(height))+"px";}
catch(error){if(IS_DEBUG){alert("setHeight["+height+"]:"+error);};};};function openPanel(){try{if(disabled||(isListExist()&&(h!=""))){z=true;if(!panelOpened){container[l].left="-1000px";container[l][U]="block";};var b=disabled?config.messagePanelHeight:Math.max(listPanel.childNodes[0][fb]*C,102);var a=j;j=b+messagePanel[fb];listPanel[l][jb]=b+"px";if(f){p.resizeUI(listPanel[fb]);};container[l][jb]=0;if(!panelOpened){container[l].left=Gb;};if(!panelOpened){panelOpened=true;t=0;x(0,j,J);i.showDropDown();}
else if(a!=j){x(a,j,a<j?J:K);};}}
catch(error){if(IS_DEBUG){alert("openPanel:"+error);};};};function closePanel(){try{if(panelOpened){if(!DISABLE_AUTO_HIDE){if(f){p.hideUI();};x(j,0,K);panelOpened=false};};appendIndicator();if(h==""){};}
catch(error){if(IS_DEBUG){alert("closePanel:"+error);};};};function onCloseCompleted(){try{if(!DISABLE_AUTO_HIDE){container[l][U]="none";panelOpened=false;};swapIndicator(false);if(h==""){};}
catch(error){if(IS_DEBUG){alert("onCloseCompleted:"+error);};};};function onBlur(){try{if(cb){E(cb);s(form,"submit");}
else if(!V){if(onMessageClick){onMessageClick=false;}
else{closePanel();};};}
catch(error){if(IS_DEBUG){alert("onBlur:"+error);};};};function onSubmit(){Eb();onCloseCompleted();};function onClick(){try{if(!panelOpened){N();if(h[u]>=I){L();}
else if(f){i.buildSuggestions("","",true);};b=null;};}
catch(error){if(IS_DEBUG){alert("onClick:"+error);};};};function onKeyup(d){try{z=false;switch(d.keyCode){case 9:case 13:case 16:case 17:case 37:case 39:break;case 27:closePanel();break;case 38:var c=null;if(b&&b[yb]){c=b[yb];}
else if(b){s(b,G,null);E();break;}
else if(panelOpened){c=listPanel.lastChild;};s(c,Q,b);E(c);break;case 40:var c=null;if(!panelOpened){N();if(h[u]>=I){L();}
else if(f){i.buildSuggestions("","",true);};return;};if(b&&b[Db]){c=b[Db];}
else if(b){s(b,G,null);E();if(f){p.hideUI();};break;}
else{c=listPanel[ec];};s(c,Q,c);E(c);break;default:z=true;if(b){s(b,G);b=null;};if(f){p.hideUI();};if(ab){clearTimeout(ab);};Eb();N();if(h[u]<I){closePanel();return;};if(v<2){hb=setTimeout(L,config.typeDel);};};}
catch(error){if(IS_DEBUG){alert("onKeyup:"+error);};};};function E(a){try{if(!a){input[nb]=h;bb=null;QS_AS='&qs=n'}
else{input[nb]=a.sug;bb=a;QS_AS='&qs=AS'}}
catch(error){if(IS_DEBUG){alert("E:"+error);};};};function N(){h=sc(input[nb]);};function Eb(){if(hb){clearTimeout(hb);};};function L(){try{if(v&&Jb==h||h[u]<I){return;};var c=h.toLowerCase(),a=Hb+c;++v;if(R[a]){i.setData(R[a]);return;};e=d("script",Mb);var b=apiUrl+"&query="+encodeURIComponent(c);if(wb[a]){b=b+"&qt="+(new Date).getTime();};i.doFetch(b);}
catch(error){if(IS_DEBUG){alert("L:"+error);};};};function Bb(){if(e[O]==kb){e[Z]=e[Lb]=e[Kb]=null;};};function lc(a){return a.replace(/&/g,"&").replace(/>/g,">").replace(/</g,"<").replace(/'/g,"'").replace(/"/g,'"');};function enableAS(){try{disabled=false;input.setAttribute("autocomplete","off");setLocalCookie("search_as",'1',true,0);appendIndicator();}
catch(error){if(IS_DEBUG){alert("enableAS:"+error);};};};function disableAS(){try{disabled=true;input.setAttribute("autocomplete","on");setLocalCookie("search_as",'0',false,30);appendIndicator();}
catch(error){if(IS_DEBUG){alert("disableAS:"+error);};};};function hideMainPanel(){mainPanel[l][U]="none";};function displayMainPanel(){mainPanel[l][U]="block";};function isListExist(){return listPanel&&(listPanel.childNodes.length>0);};function appendIndicator(){try{indicatorPanelClosed=X(config.closedIndicatorId);indicatorPanelClosed.className="as-indicator indicator-closed"+(disabled?" as-disabled":" as-enabled");if(disabled){attachEvent(indicatorPanelClosed,"click",openPanel);indicatorPanelClosed[l]["cursor"]="pointer";}
else{if(isListExist()&&(h!="")){attachEvent(indicatorPanelClosed,"click",onClick);indicatorPanelClosed[l]["cursor"]="pointer";}
else{removeEvent(indicatorPanelClosed,"click",onClick);indicatorPanelClosed[l]["cursor"]="auto";};};indicatorPanelOpened=X(config.openedIndicatorId);if(!indicatorPanelOpened){indicatorPanelOpened=d(o,config.openedIndicatorId);container[c](indicatorPanelOpened);attachEvent(indicatorPanelOpened,"click",closePanel);};indicatorPanelOpened.className="as-indicator indicator-opened"+(disabled?" as-disabled":" as-enabled");listPanel[l][U]=disabled?"none":"block";}
catch(error){if(IS_DEBUG){alert("appendIndicator:"+error);};};};function swapIndicator(isOn){try{indicatorPanelOpened[l][U]=isOn&&!config.outofScope?"block":"none";indicatorPanelClosed[l][U]=isOn||config.outofScope?"none":"block";}
catch(error){if(IS_DEBUG){alert("swapIndicator:"+error);};};};};function executeAutoSuggest(outofScope){try{if(!DISABLE_AUTO_SUGGEST){autoSuggestConfig.outofScope=outofScope;autoSuggestInstance=new autoSuggest(autoSuggestConfig);autoSuggestInstance.init("autoSuggestInstance");};}
catch(error){if(IS_DEBUG){alert("executeAutoSuggest:"+error);};};};

