function killerror(){
   return true;
}
var isIE=document.all?true:false;
window.error=killerror;
function $(i){return document.getElementById(i);}
function addBookmark(title,url) {
    if (window.sidebar) {
        window.sidebar.addPanel(title, url,"");
    } else if( document.all ) {
        window.external.AddFavorite( url, title);
    } else if( window.opera && window.print ) {
        return true;
    }
}
function setHomePage(url){
    if (window.sidebar)
    {
        try { 
           netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
        } 
        catch (e) 
        {  
           alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将[signed.applets.codebase_principal_support]设置为'true'"); 
        } 
        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
            prefs.setCharPref('browser.startup.homepage',url);

    }
}

function selectTag(showContent,selfObj){
	// 操作标签
	var tag = document.getElementById("srcbox").getElementsByTagName("span");
	var taglength = tag.length;
	for(i=0; i<taglength; i++){
		tag[i].className = "";
	}
	selfObj.className = "focu";
	// 操作内容
	for(i=0; j=document.getElementById("sbox"+i); i++){
		j.style.display = "none";
	}
	document.getElementById(showContent).style.display = "block";
	if (showContent=='sbox0')
	{
		SetCookie('search','bdimg');
	}else{
        SetCookie('search','ggimg');
	}
	
}
function changesearch(obj){
     if (obj=='bdimg')
     {
		 selectTag('sbox0',document.getElementById(obj))
     }else{
	     selectTag('sbox1',document.getElementById(obj))
	 }
}
function changefocus(){
	search=get_cookie('search');
	if (search!='')
	{
      if (search=='bdimg')
      {
		  $('wd').focus();
      }else{
		  $('q').focus();
	  }
	}
     
}
function googleHint(key){
  if($('gsuggest'))$('gsuggest').removeNode(true);
  if (document.readyState=="complete"){
    var sg=document.body.appendChild(document.createElement('script'));
    sg.language='javascript';
    sg.id='gsuggest';
    sg.charset='utf-8';
    sg.src='http://www.google.cn/complete/search?hl=zh-CN&client=suggest&js=true&q=' + encodeURIComponent(key);
   }
}
var showobj;
function myhint(event,obj){
   if(!isIE)  return ;
   var keyword=obj;
   showobj=obj;
   var h=$('suggest');
   if(!keyword.value || !keyword.value.length || event.keyCode==27 || event.keyCode==13){
       h.style.display='none';
       return;
   }
   if(event.keyCode==38 || event.keyCode==40){
     if(h.style.display=='none') return;
       if(event.keyCode==38){
         if(h._i==-1)h._i=h.firstChild.rows.length-1;
         else{
	     h._i--;
         } 
      }else{
         h._i++;
      } 
    for(var i=0;i<h.firstChild.rows.length;i++)h.firstChild.rows[i].style.background="#FFF";
      if(h._i >= 0 && h._i < h.firstChild.rows.length)with(h.firstChild.rows[h._i]){
        style.background="#E6E6E6";
        tmp=cells[0].innerHTML.split("</em>");
        keyword.value=tmp[1].replace("</a>",'');
      }else{
        keyword.value=h._kw;
        h._i=-1;
      } 
    }else{
      h._i=-1;
      h._kw=keyword.value;
      googleHint(keyword.value);
      var pos=getPosition(keyword);
      with(h.style){
        left=pos.x;
        top=pos.y+keyword.offsetHeight;
        width=keyword.offsetWidth + 26;
      } 
    } 
}
var searchurl_wd='http://www.baidu.com/s?tn=592js_pg&ie=utf-8&wd=';
var searchurl_q='http://www.google.hk/search?forid=1&prog=aff&ie=utf8&oe=utf8&hl=zh-CN&client=pub-3675750120992823&q='
window.google={
} ;
window.google.ac={
} ;
window.google.ac.Suggest_apply=function(a,b,c,d){
 if(!c || c.length<3) return;
 if(b != showobj.value) return;
 var ihtml='';
 if (document.readyState=="complete")
 {
  for(var j=1;j<c.length;j+=2){
	  if (showobj.id=='wd')
	  {
       url=searchurl_wd+encodeURIComponent(c[j]);
	  }else{
	  url=searchurl_q+encodeURIComponent(c[j]);
	  }
	  ihtml+='<tr style="cursor:hand" onmouseover="this.style.background=\'#E6E6E6\';$(\''+showobj.id+'\').value=\'' +c[j] +'\';" onmouseout="this.style.background=\'#FFF\';"><td style="color:#000;" align="left"><a href="'+url+'" target="_blank" onclick="$(\'suggest\').style.display=\'none\';"><em style="cursor:pointer">' +c[j+1] +'</em>' +c[j] +'</a></td></tr>';
    $('suggest').innerHTML='<table width="100%" border="0" cellpadding="0" cellspacing="0">'+ihtml+'</table>';
    $('suggest').style.display="block";
	
	}
  }else{
    //setTimeout("myhint(event)", 2000);
  }
};
function getPosition(ele){
	var overflown = [];
	var el = ele, left = -23, top = 1;
	do {
		left += el.offsetLeft || 0;
		top += el.offsetTop || 0;
		el = el.offsetParent;
	} while (el);
	return {'x': left, 'y': top};
}

function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}
function SetCookie (name, value) { 
       var exp = new Date(); 
       exp.setTime (exp.getTime()+8640000000000); 
       document.cookie = name + "=" + value + "; expires=" + exp.toGMTString()+"; path=/"; 
}
