﻿function gb2312(key) {var r = ""; for(var i=0;i<key.length;i++){ var t = key.charCodeAt(i); if(t>=0x4e00 || t==0x300A || t==0x300B){ try{execScript("ascCode=hex(asc(\""+key.charAt(i)+"\"))", "vbscript"); r += ascCode.replace(/(.{2})/g, "%$1"); }catch(e){}}else{r += escape(key.charAt(i))} } return r; }
var SearchBar = function(refData, Parent) { var refThis = this; refThis.refData = refData; refThis.activeTab = null; this.Init = function() { var divBar = _newElement("div", "sBar"); var barTab = _newElement("ul", "barTab"); var barInp = _newElement("div", "barInp"); var barKws = _newElement("div", "barKws"); refThis.barKws = barKws; var items = [ ['网页',                  [['百度','http://www.baidu.com/s?ie=utf-8&wd=', 0],
                  ['Google','http://www.google.cn/search?hl=zh-CN&q=', 0]
],1], ['资讯',                  [['谷歌', 'http://news.google.cn/news?hl=zh-CN&q=', 1],
                  ['百度', 'http://news.baidu.com/ns?tn=baidu&gb2312=1&word=', 3]
],2], ['视频',                  [['迅雷', 'http://video.gougou.com/search?s=', 0],
                  ['百度', 'http://video.baidu.com/v?gb2312=1&word=', 3]
],3], ['图片',                  [['谷歌', 'http://images.google.cn/images?hl=zh-CN&q=', 0],
                  ['百度', 'http://image.baidu.com/i?gb2312=1&tn=baiduimage&ct=201326592&cl=2&pv=&lm=-1&word=', 3]
],4], ['音乐',                  [['百度', 'http://mp3.baidu.com/m?ie=gb2312&word=', 3],
                  ['雅虎', 'http://music.cn.yahoo.com/search?mimetype=all&ei=gbk&p=', 3]
],5], ['地图',                  [['谷歌', 'http://ditu.google.cn/maps?hl=zh-CN&q=', 0],
                  ['百度', 'http://map.baidu.com/#word=', 0]
],6], ['购物',                  [['卓越', 'http://www.amazon.cn/mn/searchApp?ix=sunray&pageletid=headsearch&searchType=&keywords=', 0],
                  ['易趣', 'http://search.eachnet.com/search/basicsearch.do?satitle=', 0],
                  ['当当', 'http://search.dangdang.com/search.aspx?gb2312=1&selectcatalog=&key=', 3]
],7], ['词典',                  [['词霸', 'http://www.iciba.com/', 0],
                  ['汉英', 'http://dict.cn/search/?q=', 3]
],8] ]; if(Browser.isIE) { var sVer = navigator.userAgent; if(sVer.indexOf("MSIE 7.0") > 0 || sVer.indexOf("MSIE 8.0") > 0) {                  var vBaidu = ['百度','http://www.baidu.com/s?ie=gb2312&wd=', 3];
items[0][1][0] = vBaidu; } } function insertTab(tab) { var li = _newElement("li", "tabItem"); li.refTab = tab; var span = _newElement('span', "tabTitle"); span.appendChild(_newText(tab[0])); li.appendChild(span); li.onclick = function() { if(refThis.activeTab != this) { if(refThis.activeTab) { refThis.activeTab.className = "tabItem"; } this.className = "tabActive"; refThis.activeTab = this; refThis.onSelect(tab); } }; li.onmouseover = function() { if(this != refThis.activeTab) { this.className = "tabOver"; } }; li.onmouseout = function() { if(this != refThis.activeTab) { this.className = "tabItem"; } }; return li; }; var inpSel = _newElement("select", "inpSel"); inpSel.onupdate = function(tab) { _removeChildNodes(this); for(var i=0; i<tab[1].length; i++) { var o = _newElement("option"); o.appendChild(_newText(tab[1][i][0])); o.value = tab[1][i][1]; o.flag = tab[1][i][2]; this.appendChild(o); } }; refThis.inpSel = inpSel; var inpTxt = _newElement("input", "inpTxt"); inpTxt.size = items.length*6; refThis.inpTxt = inpTxt; inpTxt.onfocus = function() { this.select(); }; inpTxt.onmouseover = function() { this.select(); }; var inpBtn = _newElement("input", "inpBtn"); inpBtn.type = "button"; inpBtn.value = Local.Search; refThis.inpBtn = inpBtn; inpBtn.onclick = function() { if(inpTxt.value != "") { var i = refThis.inpSel.selectedIndex; var url = refThis.inpSel.options[i].value; var flag = refThis.inpSel.options[i].flag; if(flag == 3) url += gb2312(inpTxt.value); else if(flag == 0) url += inpTxt.value; else url += escape(inpTxt.value); window.open(url); function nclear(response) { } url = "/webx/Hot.aspx?f=" + refThis.activeTab.refTab[2] + "&s="+escape(inpTxt.value); Request.GET(url, nclear); } }; inpTxt.onkeypress = function(event) { var e=event || window.event; if(e) { var key=window.event ? e.keyCode : e.which; if(key == 13)inpBtn.onclick(); } }; barInp.appendChild(inpSel); barInp.appendChild(inpTxt); barInp.appendChild(inpBtn); var firstTab = null; for(var i=0; i<items.length; i++) { var tab = barTab.appendChild(insertTab(items[i])); if(firstTab == null) { firstTab = tab; } } firstTab.onclick(); divBar.appendChild(barTab); divBar.appendChild(barInp); divBar.appendChild(barKws); Parent.appendChild(divBar); }; this.onSelect = function(tab) { refThis.inpSel.onupdate(tab); refThis.inpTxt.focus(); function setKws(response) { if(response != null) { _removeChildNodes(refThis.barKws); var rootNode = response.responseXML.documentElement; var lis = rootNode.getElementsByTagName("li"); for(var i=0; i<lis.length; i++) { var span = _newElement("span"); span.innerHTML = _text(lis[i]); span.onclick = function() { refThis.inpTxt.value = this.innerHTML; refThis.inpBtn.onclick(); }; refThis.barKws.appendChild(span); } } } Request.GET("/webx/Hot.aspx?f="+tab[2], setKws); }; this.Init(); }; 
