

var searchBoxUserKeyed = false;

function setfocus(){
   var input = document.getElementById('query');
    var flag = isIE6();
    if(flag){
        var tagName = document.activeElement.tagName;
	var id = document.activeElement.id;
	if(tagName == "IFRAME" || tagName == "BODY" ||(tagName == "INPUT" && id == "query")){
   	    if(!isFocusChange())
		input.focus();
	}
    }
   Event.observe(input, "keydown", autoBlurSearchBox);
 }

function isIE6(){
   var notMSIE=(navigator&&navigator.userAgent.toLowerCase().indexOf("msie")==-1);
   if(!notMSIE){
	if(navigator.appVersion.indexOf("MSIE 6") != -1)
		return true;
    }
   return false;
}

function isFocusChange(){
   var input = document.getElementById("userName");
   if(input && input.value != "")
	return true;
   return false;
}
function autoBlurSearchBox(e) {
  var navkeys = new Array(32, 33, 34, 35, 36, 37, 38, 39, 40);
  if(!searchBoxUserKeyed) {
    if(navkeys.indexOf(e.keyCode) != -1) {
        var input = document.getElementById('query');
        input.blur();
    }else{
       var input = document.getElementById('query');
       input.focus();
    }
  }
  searchBoxUserKeyed = true;
}

/*
查找点亮的tab的ID
*/
function getSlectTabId() {
    var ids = new Array("2010Focus", "2010News", "2010Blog", "2010BBS", "2010Guba", "2010Web", "2010TopView");
    var className;
    var selIdName = "2010News";
    var bFound = false;
    for (i = 0; i < ids.length; i++) {
        selIdName = ids[i];

        className = document.getElementById(selIdName).className;
        if ("cTabSelected" == className) {
            bFound = true;
            break;
        }
    }
    if (!bFound) {
        selIdName = "2010News";
    }

    return selIdName;

}
document.getElementById('query').focus();
var YodaoCurrentTab = document.getElementById(getSlectTabId());

function changeProduct(o){

       var BtnName = "新闻搜索";
	var SoBtn = document.getElementById("jerryBtn");
	var SoForm = document.getElementById("searchForm");
        if(o == YodaoCurrentTab){
                return false;
        }else {
                o.className = "cTabSelected";
                YodaoCurrentTab.className = "cTab";
                switch(o.id){
                        case "2010TopView":
                                BtnName = "topview搜索";
                                SoForm['st'].value = "10";
                                SoForm['searchdate'].style.display = "display";
                                break;
                        case "2010News":
                                BtnName = "新闻搜索";
                                act = "http://www.2010.com/s?ac=init&cla=%E8%93%9D%E7%AD%B9%E8%82%A1";
                                sserver = "http://www.2010.com";
                                SoForm['st'].value = "0";
                                SoForm['searchdate'].style.display = "none";
                                break;
                        case "2010Blog":
                                BtnName = "博客搜索";
                                act = "http://www.2010.com/s?ac=init&st=1&cla=";
                                sserver = "http://www.2010.com";
                                SoForm['st'].value = "1";
                                SoForm['searchdate'].style.display = "none";
                                break;
                        case "2010BBS":
                                BtnName = "论坛搜索";
                                act = "http://www.2010.com/s?ac=init&st=2&cla=";
                                sserver = "http://www.2010.com";
                                SoForm['st'].value = "2";
                                SoForm['searchdate'].style.display = "none";
                                break;
                        case "2010Guba":
                                BtnName = "股吧搜索";
                                act = "http://www.2010.com/s?ac=init&st=3&cla=";
                                sserver = "http://www.2010.com";
                                SoForm['searchdate'].style.display = "none";
                                SoForm['st'].value = "3";

                                break;
                        case "2010Web":
                                BtnName = "网页搜索";
                                act = "http://www.2010.com/s?ac=init&st=3&cla=";
                                sserver = "http://www.2010.com";
                                SoForm['st'].value = "4";
                                SoForm['searchdate'].style.display = "none";

                                break;

                }
		if(typeof(aa) != "undefined") {
                	aa.setSearchServer(act);
                	aa.setSuggestServer(sserver);
		}
                // SoForm.action = act;
                SoBtn.value = BtnName;
                YodaoCurrentTab = o;
                // document.getElementById("cla").focus();
                return false;
        }
}
