var div_search=document.getElementById('div_search');var isResultFound=false;var oldValue='';var logDelay=2;var resultDelay=1;var logTimeOut=null;var resultTimeOut=null;var lastlog='';var QsRequest;function getAbsolutePos(el){var r={x:el.offsetLeft,y:el.offsetTop};if(el.offsetParent){var tmp=getAbsolutePos(el.offsetParent);r.x+=tmp.x;r.y+=tmp.y;}
return r;}
function registerListeners(){var input=document.getElementById('q');addEvent(input,"keyup",setTyping);addEvent(input,"keypress",checkForSave);addEvent(input,"blur",setLogData);addEvent(input.form,"submit",function(e){var reg=/^W\d+$/i;if(reg.test(document.getElementById('q').value)){var f=function(){if(QsRequest.getStatus()==200&&oldValue==document.getElementById('q').value){window.location.href=$$('#div_search a')[0].href;}else{window.setTimeout(f,50);}}
window.setTimeout(f,1);Event.stop(e);}
return true;});if(get_qs!=""){$('q').value=get_qs;setTyping();}}
function checkForSave(e){lastlog='';if(e.keyCode==13){setLogDataForce();}}
function setTyping(){window.clearTimeout(resultTimeOut);resultTimeOut=null;resultTimeOut=window.setTimeout('getResult()',resultDelay*250);}
function setLogData(){window.clearTimeout(logTimeOut);logTimeOut=null;var searchWhat=encodeURIComponent($('q').value);if(lastlog==searchWhat)return;lastlog=searchWhat;var url=href+language+'/quicksearch/saveQSLog/q.'+searchWhat+"/";var Request=new Ajax.Request(url,{method:'get',asynchronous:true});}
function setLogDataForce(){window.clearTimeout(logTimeOut);logTimeOut=null;var searchWhat=encodeURIComponent($('q').value);var url=href+language+'/quicksearch/saveQSLog/q.'+searchWhat+"/";var Request=new Ajax.Request(url,{method:'get',asynchronous:false});}
function addEvent(elm,evType,fn,useCapture){if(elm.addEventListener){elm.addEventListener(evType,fn,useCapture);return true;}else if(elm.attachEvent){var r=elm.attachEvent("on"+evType,fn);return r;}}
function removeEvent(elm,evType,fn,useCapture){if(elm.removeEventListener){elm.removeEventListener(evType,fn,useCapture);return true;}else if(elm.detachEvent){var r=elm.detachEvent("on"+evType,fn);return r;}}
function alertSize(){var myWidth=0,myHeight=0;if(typeof(window.innerWidth)=='number'){myWidth=window.innerWidth;myHeight=window.innerHeight;}else if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)){myWidth=document.documentElement.clientWidth;myHeight=document.documentElement.clientHeight;}else if(document.body&&(document.body.clientWidth||document.body.clientHeight)){myWidth=document.body.clientWidth;myHeight=document.body.clientHeight;}
this.wWidth=myWidth;this.wHeight=myHeight;return this;}
function showResult(){$('div_search_body').style.left=parseInt(getAbsolutePos($('header_pic')).x)+'px';$('div_search_body').style.top=parseInt(getAbsolutePos($('header_pic')).y)+'px';$('div_search_body').style.display='block';_flash("hidden");}
function hideResult(){$('div_search_body').style.display='none';_flash("visible");}
function getResult(){var codeReg=/^W\d+$/i;window.clearTimeout(resultTimeOut);resultTimeOut=null;var searchWhat=encodeURIComponent($('q').value);var url=href+language+'/quicksearch/q.'+searchWhat+"/";if(!searchWhat||oldValue==searchWhat)
return;oldValue=searchWhat;QsRequest=new Ajax.Updater('div_search',url,{method:'get',asynchronous:true});if(!codeReg.test(searchWhat)){showResult();}else{hideResult();}}
