//var s = document.location.search.substr(1).split("&");
//var key	= val("Key");
//$('i_keyword').value = key.replace(/\+/g, " ");

function val(key){
	for(var i=0; i<s.length; i++)
	{
		var kv = s[i].split("=");
		if(kv.length != 2) continue;

		if(kv[0] == key) return kv[1];
	}
  return "";
}
function $(i) { return document.getElementById(i);}
function getPosition(ele){
	var overflown = [];
	var el = ele, left = 0, top = 0;
	do {
		left += el.offsetLeft || 0;
		top += el.offsetTop || 0;
		el = el.offsetParent;
	} while (el);
	return {'x': left, 'y': top};
}
function setCookie(k, v, opt)
{
	var val = encodeURIComponent(v);
	if(opt)
	{
		if(opt.duration)
		{
			var d = new Date();
			d.setTime(d.getTime() + opt.duration*24*3600*1000);
			val += '; expires=' + d.toGMTString();
		}
		if(opt.path)
			val += '; path=' + opt.path;
	}
	document.cookie = k + '=' + val + ';';
}

function getCookie(k)
{
  var c = document.cookie.split("; ");
  for(var i=0; i<c.length; i++)
  {
    var p = c[i].split("=");
    if(k == p[0])
      return decodeURIComponent(p[1]);
  }
  return null;
}

function googleHint(key)
{
    if($('gsuggest')!=null)$('gsuggest').removeNode(true);
    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);
}
function hint()
{
    var keyword=$('i_keyword');
    var h=$('kwh');
    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.backgroundColor="#ECF5FF";
        if(h._i >= 0 && h._i < h.firstChild.rows.length)
            with(h.firstChild.rows[h._i])
            {
                style.backgroundColor="#D0ECF9";keyword.value=cells[0].innerText;
            }
        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;}
    }
}
window.google={};
window.google.ac={};
window.google.ac.Suggest_apply=function(a,b,c,d)
{
    if(!c || c.length<3)
        return;
    var ihtml='';
    for(var j=1;j<c.length;j+=2)
        ihtml+='<tr bgcolor="#FFFFFF" style="cursor:hand" onmouseover="this.bgColor=\'#e8e8e8\';$(\'i_keyword\').value=\'' +c[j] +'\';" onmouseout="this.bgColor=\'#FFFFFF\';"><td style="color:#000" align="left">' +c[j] +'</td></tr>';
     $('kwh').innerHTML='<table width="100%" border="0" cellpadding="1" cellspacing="0" bgcolor="#FFFFFF" style="font-size:13px;border-top:3px solid #dcdcdc;;border-right:1px solid #dcdcdc;border-bottom:1px solid #dcdcdc;border-left:1px solid #dcdcdc;">'+ihtml+'</table>';
     $('kwh').style.display="block";
};