var isIE=document.all?true:false;
var qi=0;
function $(id) {return document.getElementById(id);}
function G(A){return document.getElementById(A);}
function C(A){return document.createElement(A);}
function createCookie(name,value,days){
     var argv=createCookie.arguments;
     var argc=createCookie.arguments.length;
     //var expires=(2<argc)?argv[2]:null;
     //var path=(3<argc)?argv[3]:null;
     //var domain=(4<argc)?argv[4]:null;
     //var secure=(5<argc)?argv[5]:false;
	if (days) { 
		var expires = new Date(); 
		expires.setTime(expires.getTime()+(days*24*60*60*1000)); 
		//var expires = date.toGMTString(); 
	}
	 var path = '/';
	 //var domain = '369.com';
	 var domain = null;
	 var secure = false;
     document.cookie=name+"="+escape(value)+((expires==null)?"":("; expires="+expires.toGMTString()))+((path==null)?"":("; path="+path))+((domain==null)?"":("; domain="+domain))+((secure==true)?"; secure":"");
}
function readCookie(Name) {
 var search = Name + "=";
 var returnvalue = "";
 if (document.cookie.length > 0) {
  offset = document.cookie.lastIndexOf(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 stat(ev){if ($('stat_monitor').value==0){ssd('kwh', 0);}return true;}
function ru(u) { return u == "http://www.baidu.com" ? u+"/index.php?tn=yjhy_pg" : u }
function dcs(s, i) {var js=document.body.appendChild(document.createElement("SCRIPT")); js.charset='GB2312';js.src=s; if(i)js.id=i}
function ssd(i, d) {document.getElementById(i).style.display=d ? "block" : "none"}
function trim(t) {return t.replace( /^\s+|\s+$/g, "");}
var pref_sp_str = readCookie('pref_sp_str');
if (!pref_sp_str) {
var pref_sp_str = "0,0,0,0,0,0,0";
createCookie('pref_sp_str', pref_sp_str, 180);
} else if(pref_sp_str.length == 11) {
pref_sp_str+=',0';
}
pref_sp = pref_sp_str.split(',');
var cur_so=0, cur_bc=0, o_bests=[], udus=[], l_t, l_u, l_udu=null;
var gs_d={i: -1, kw: '', u: '', gkw: ''}, fs_d=[];

window.baidu={};
window.baidu.sug=function(a) {
	var ih='', _shmh=" onmouseover='this.style.backgroundColor=\"#AACCFF\";gs_d.u=\"\"' onmouseout='this.style.backgroundColor=\"#FFFFFF\"' onclick='shmd(this,"+qi+")'", _shmf=" onmouseover='this.style.backgroundColor=\"#AACCFF\";gs_d.u=\"\"' onmouseout='this.style.backgroundColor=\"#FFFFFF\"' onclick='shmf(this,"+qi+")'"; 
	var ainfo = a.s;
	for (var i = 0; i < ainfo.length; i++) {
		ih += '<tr'+_shmh+'><td _h="'+ainfo[i].replace(/\"/g, '')+'"><a>'+ainfo[i]+'</a></td></tr>'; 
	}

	document.getElementById('kwh').innerHTML='<table onmousedown="stopBubble(event)" width="100%" cellpadding=0 cellspacing=1>'+ih+'</table>'; 
	ssd('kwh', ih.length > 0);
}

function stopBubble(e) { if (e.stopPropagation) e.stopPropagation(); else e.cancelBubble=true;}
function shmd(o,ki) { var u=o.cells[0].attributes['_u'], h=o.cells[0].attributes['_h'].value; if (u) gs_d.u=ru(h); else document.getElementById('keyword'+ki).value=h;synkey(ki);do_search(ki);}

function shmf(o) {ssd('kwh', 0);}
function synkey(ki){
	var kwd=$('keyword'+ki);
	for(hi=0;hi<6; hi++){
		if (hi!=ki){
			$('keyword'+hi).value=kwd.value;
		}
	}
}
function hint(e,ki) {
var kwd=$('keyword'+ki),h=$('kwh');
qi=ki;
for(hi=0;hi<6; hi++){
	if (hi!=ki){
		$('keyword'+hi).value=kwd.value;
	}
}
var ek=e.keyCode; 
if (!kwd.value.length || (ek < 28 && ek != 8)) {
ssd('kwh', 0);
gs_d.u=""; return;
}

if (ek == 38 || ek == 40) {
if (h.style.display == 'none') {
ssd('kwh', 1);

return
}
var hfr=h.firstChild.rows;
if (ek == 38) gs_d.i=(gs_d.i == -1) ? hfr.length - 1 : gs_d.i - 1; else gs_d.i++;

for (var i=0; i < hfr.length; i++)hfr[i].style.backgroundColor="#FFFFFF";
if (gs_d.i >= 0 && gs_d.i < hfr.length)with (hfr[gs_d.i]) {
style.backgroundColor="#AACCFF";
kwd.value=cells[0].attributes['_h'].value;
if (cells[0].attributes['_u']) gs_d.u=ru(cells[0].attributes['_h'].value);else gs_d.u=""; 
} else {
gs_d.u="";
kwd.value=gs_d.kw;
gs_d.i=-1;
}
} else {
gs_d.i=-1;
gs_d.kw=kwd.value;
if(document.getElementById('gsg')) document.getElementById('gsg').parentNode.removeChild(document.getElementById('gsg'));
	if (ki == 1) {
		dcs('http://sug.mp3.baidu.com/su?wd='+encodeURIComponent(trim(kwd.value))+'&sc=hao123&t='+(new Date()).getTime(), 'gsg');
	} else if (ki == 2) {
		dcs('http://sug.image.baidu.com/su?wd='+encodeURIComponent(trim(kwd.value))+'&sc=hao123&t='+(new Date()).getTime(), 'gsg');
	} else if (ki == 4) {
		dcs('http://zhidao.sug.baidu.com/su?wd='+encodeURIComponent(trim(kwd.value))+'&sc=hao123&t='+(new Date()).getTime(), 'gsg');
	} else if (ki == 3) {
		dcs('http://sug.video.baidu.com/su?wd='+encodeURIComponent(trim(kwd.value))+'&sc=hao123&t='+(new Date()).getTime(), 'gsg');
	} else {
		dcs('http://suggestion.baidu.com/su?wd='+encodeURIComponent(trim(kwd.value))+'&p=3&t='+(new Date()).getTime(), 'gsg');
	}
}
}
var B=[]
function do_search(ki){//
var s_kw = document.getElementById("keyword"+ki).value;
my_search_add(s_kw);
switch(parseInt(ki)){
	case 1:
		document.mp3.submit();
		break;
	case 2:
		document.image.submit();
		break;
	case 3:
		document.video.submit();
		break;
	case 4:
		document.zhidao.submit();
		break;
	case 5:
		document.news.submit();
		break;
	default:
		document.bdfm.submit();
}
ssd('kwh', 0);
B=I(B);
}
function I(K){for(var L=0,J=K.length;L<J;L++){document.bdfm.removeChild(K[L])}return[]}
function my_search_add(k) {
var my_search_state = readCookie("my_search_state");
if (my_search_state == "open" || my_search_state == "") {
var my_search_history = readCookie("my_search_history");
var msh_arr = new Array();
var msh_arr_tmp = new Array();
if (!my_search_history) {
createCookie('my_search_history', '_'+k+'_', 365);
} else {
msh_arr = my_search_history.split('_');
msh_arr_tmp.push(k);
for(var i=0; i < msh_arr.length; i++) {
if (msh_arr[i] != '' && msh_arr[i] != k) {
msh_arr_tmp.push(msh_arr[i]);
}
}
createCookie('my_search_history', '_'+msh_arr_tmp.join('_')+'_', 365);
}
}
}
function my_search_show() {
var ih='', ihb='';
var my_search_history = readCookie("my_search_history");
if (my_search_history) {
var k = my_search_history.split('_');
for(var i=0; i < k.length; i++) {
if (k[i] != '') {
ih += '<tr onmouseover="document.getElementById(\'ms_'+i+'\').style.color=\'#F00\';gs_d.u=\'\'" onmouseout="document.getElementById(\'ms_'+i+'\').style.color=\'#000\'" style="cursor:pointer" onclick="shmd(this)"><td _h="'+k[i].replace(/\"/g, '')+'"><a id="ms_'+i+'">'+k[i]+'</a></td></tr>'; 
}
}
}
ihb += '<tr><td align="right"><a style="display:inline" href="javascript:;" target="_self" title="点此可以清除您“最近我的搜索”的搜索搜索内容。" onclick="clear_my_search();">[清除记录]</a>'; 
var my_search_state = readCookie("my_search_state");
if (my_search_state == "open" || my_search_state == "") {
ihb += '&nbsp;<a style="display:inline" href="javascript:;" target="_self" title="点此停用“最近我的搜索”的功能，系统将不再记录您最近搜索过的内容。" onclick="chg_my_search(\'close\');">[停用]</a>'; 
} else {
ihb += '&nbsp;<a style="display:inline" href="javascript:;" target="_self" title="点此启用“最近我的搜索”的功能，系统将记录您最近搜索过的内容。" onclick="chg_my_search(\'open\');">[启用]</a>'; 
}
ihb += '&nbsp;<a style="display:inline" href="javascript:;" target="_self" title="临时关闭此提示窗口。" onclick="document.getElementById(\'kwh\').style.display=\'none\';">[关闭]</a></td></tr>'; 

document.getElementById('kwh').innerHTML='<div style="height:200px;overflow:auto;" onmousedown="document.getElementById(\'stat_monitor\').value = 1" onmouseout="document.getElementById(\'stat_monitor\').value = 0"><table onmousedown="stopBubble(event)" width="96%" cellpadding=0 cellspacing=1>'+ih+'</table></div><div><table onmousedown="stopBubble(event)" width="100%" cellpadding=0 cellspacing=1>'+ihb+'</table></div>';
ssd('kwh', 1);
document.getElementById('stat_monitor').value = 0;
}
function chg_my_search(stat){
createCookie("my_search_state", stat, 365);
my_search_show();
}
function clear_my_search(stat){
createCookie("my_search_history", '', 365);
my_search_show();
}
G('keyword0').focus();

function selectTag(showContent,selfObj){
	var tag = document.getElementById("tags").getElementsByTagName("a");
	var taglength = tag.length;
	for(i=0; i<taglength; i++){
		tag[i].className = "";
	}
	selfObj.className = "active";
	for(i=0; j=document.getElementById("baidu"+i); i++){
		j.style.display = "none";
	}
	document.getElementById(showContent).style.display = "block";
	if(document.getElementById('gsg')) document.getElementById('gsg').parentNode.removeChild(document.getElementById('gsg'));
}
var isIE=document.all?true:false;
	
var searchurl='http://www.baidu.com/s?tn=yjhy_pg&ch=2&ie=utf-8&wd=';
function get_so(cur_so) {
if(cur_so==0) {
	searchurl='http://www.baidu.com/s?tn=yjhy_pg&ch=2&ie=utf-8&wd=';
} else if(cur_so==1) {
	searchurl='http://mp3.baidu.com/m?tn=yjhy_pg&ie=utf-8&ct=134217728&word=';
} else if(cur_so==2) {
	searchurl='http://image.baidu.com/i?tn=yjhy_pg&ie=utf-8&ct=201326592&lm=-1&word=';
} else if(cur_so==3) {
	searchurl='http://video.baidu.com/v?tn=yjhy_pg&ie=utf-8&word=';
} else if(cur_so==4) {
	searchurl='http://zhidao.baidu.com/q?tn=yjhy_pg&pt=yjhy_ik&ct=17&word=';
}
return searchurl;
}

try{var isMaxthon=!!external.max_version}catch(e){}
var isGB=navigator.userAgent.indexOf("GreenBrowser")!=-1;
var isTT=navigator.userAgent.indexOf("TencentTraveler")!=-1;
var isAlexaTool=navigator.userAgent.indexOf("Alexa Toolbar")!=-1;
var isIE6=navigator.userAgent.indexOf("MSIE 6")!=-1&&!window.opera;
var isIE7=navigator.userAgent.indexOf("MSIE 7")!=-1&&!window.opera;
var isWebKit=(navigator.userAgent.indexOf("AppleWebKit/")>-1);
var isGecko=(navigator.userAgent.indexOf("Gecko")>-1)&&(navigator.userAgent.indexOf("KHTML")==-1);
var isOpera=navigator.userAgent.indexOf("Opera")!=-1;

function getPosition(ele){
	var overflown = [];
	var el = ele, left = 1, top = 2;
	//do {
	//	left += el.offsetLeft || 0;
	//	top += el.offsetTop || 0;
	//	el = el.offsetParent;
	//} while (el);
	left = el.scrollLeft + 118;
	top = el.scrollTop + 136;
	return {'x': left, 'y': top};
}

function sug_t() {
	setTimeout("$('suggest').style.display = 'none';", 1000);
}