var isIE=document.all?true:false;
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 search(type){
	if (type==0)
	{
		if (event.keyCode!=13 || event.keyCode!=0)
		{
			//alert(event.keyCode);
			return;
		}
	}
	var kw = $('q').value.replace(/(^\s*)|(\s*$)/g, "");
	if(kw == "") {
	  //$('q').focus();
	  //return;
	}	
	$("suggest").style.display = "none";
}
function goSearch(event) {
	if(!isIE)  return ;
	if(!event) return;
	if(event.keyCode==13) 
		search(0);
}

function googleHint(key){
  if(key.charCodeAt(0) == 32) return;  
  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='search/xhauto.aspx?q=' + key;
   }
}
function myhint(event){
   if(!isIE)  return ;
   var q=$('q');
   var h=$('suggest');
//        alert(q);

   if(!q.value || !q.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="#29ABE2";
        q.value=cells[0].innerText;
      }else{
        q.value=h._kw;
        h._i=-1;
      } 
    }else{
	
      h._i=-1;
      h._kw=q.value;
      googleHint(q.value);
      var pos=getPosition(q);
      with(h.style){
        left=pos.x;
        top=pos.y+q.offsetHeight;
        width=q.offsetWidth + 13;
      } 
    } 
}

qvodauto=function(a,b,c,d){
 if(!c || c.length<3)
 {
//  alert(c+"小于三");
    $('suggest').style.display="none";
  return;
  }
 if(b != $('q').value) return;
 var ihtml='';
 if (document.readyState=="complete")
 {
  for(var j=1;j<c.length;j+=2)ihtml+='<tr style="cursor:hand;" onmouseover="this.style.background=\'#29ABE2\';$(\'q\').value=\'' +c[j] +'\';" onmouseout="this.style.background=\'#FFF\';"><td class="Au1">' +c[j] +'</td><td class="Au2">' +c[j+1] +'</td></tr>';
    $('suggest').innerHTML='<table class="qvodtable" border="0" cellpadding="0" cellspacing="0">'+ihtml+'</table><table class="close" border="0" cellpadding="0" cellspacing="0"><tr><td><span onclick="qvodclose()">关闭</span></td></tr></table>';
    $('suggest').style.display="block";
  }else{
    $('suggest').style.display="none";
    //setTimeout("myhint(event)", 2000);
  }
};

function getPosition(ele){
	var overflown = [];
	var el = ele, left = -5, top = 2;
	do {
		left += el.offsetLeft || 0;
		top += el.offsetTop || 0;
		el = el.offsetParent;
	} while (el);
	return {'x': left, 'y': top};
}
function qvodclose(){
	$("suggest").style.display = "none";
}