
var EngineIndex = 1;
function WebEngine(idx)
{
	$("web").style.display = (idx==2) ? "" : "none";
	EngineIndex = idx;
	if(idx<2) 
	{
		$("spanSearch").innerHTML = "<img src=\"/images/search.jpg\" onclick=\"SearchGone()\" title=\"内网\">";
	}
	else 
	{
		$("spanSearch").innerHTML = "<a id=\"webs\" href=\"#\" target=\"_blank\"><img src=\"/images/search.jpg\" onclick=\"SearchGone()\" title=\"外网\"></a>";
	}
}

function SearchSave()
{
	if($("Words").value.Trim()=="") return;
	var sword = $("Words").value;
	sword = sword.replaceAll2("#"," ");
	sword = sword.replaceAll2("?"," ");
	sword = sword.replaceAll2("="," ");
	sword = sword.replaceAll2(":"," ");
	switch(EngineIndex)
	{
		case 0:
			AjaxPost("/desk/ajax/href.aspx?m=0&p=" + sword);
			break;
		case 1:
			AjaxPost("/desk/ajax/href.aspx?m=1&p=" + sword);
			break;
		case 2:
			if($("sengine").value == "http://www.baidu.com") {
				AjaxPost("/desk/ajax/href.aspx?m=2&p=" + sword);
			}
			if($("sengine").value == "http://www.g.cn") {
				AjaxPost("/desk/ajax/href.aspx?m=3&p=" + sword);
			}
			if($("sengine").value == "http://www.sogou.com") {
				AjaxPost("/desk/ajax/href.aspx?m=4&p=" + sword);
			}
			if($("sengine").value == "http://www.jike.com") {
				AjaxPost("/desk/ajax/href.aspx?m=5&p=" + sword);
			}
			if($("sengine").value == "http://www.yahoo.cn") {
				AjaxPost("/desk/ajax/href.aspx?m=6&p=" + sword);
			}
			if($("sengine").value == "http://cn.bing.com") {
				AjaxPost("/desk/ajax/href.aspx?m=7&p=" + sword);
			}
			if($("sengine").value == "http://www.soso.com") {
				AjaxPost("/desk/ajax/href.aspx?m=8&p=" + sword);
			}
			if($("sengine").value == "http://www.google.com") {
				AjaxPost("/desk/ajax/href.aspx?m=8&p=" + sword);
			}
			if($("sengine").value == "http://www.70018.com") {
				AjaxPost("/desk/ajax/href.aspx?m=9&p=" + sword);
			}
			break;
	}
}

function SearchRun()
{
	if($("Words").value.Trim()=="") {
		alert("请输入搜索词（多个词之间用空格分开）");
		return;
	}

	var sword = $("Words").value;
	sword = sword.replaceAll2("#"," ");
	sword = sword.replaceAll2("?"," ");
	sword = sword.replaceAll2("="," ");
	sword = sword.replaceAll2(":"," ");

	if(EngineIndex>1) 
	{
		if(sword.Contains("彩票")) sword = "幸运之门 " + sword;
		if(sword.Contains("文档管理")) sword = "多可 " + sword;
		if(sword.Contains("文件管理")) sword = "多可 " + sword;
	}

	switch(EngineIndex)
	{
		case 0:
			window.location = "/desk/search.aspx?m=local&q=" + sword;
			break;
		case 1:
			window.location = "/desk/search.aspx?m=lan&q=" + sword;
			break;
		case 2:
			if($("sengine").value == "http://www.baidu.com") {
				$("webs").href = "http://www.baidu.com/s?wd=" + sword;
			}
			if($("sengine").value == "http://www.g.cn") {
				$("webs").href = "http://www.google.com.hk/webhp?source=g_cn#hl=zh-CN&source=hp&q=" + sword;
			}
			if($("sengine").value == "http://www.soso.com") {
				$("webs").href = "http://www.soso.com/q?pid=s.idx&w=" + sword;
			}
			if($("sengine").value == "http://www.jike.com") {
				$("webs").href = "http://www.jike.com/so?q=" + encodeURI(sword);
			}
			if($("sengine").value == "http://www.sogou.com") {
				$("webs").href = "http://www.sogou.com/web?query=" + sword;
			}
			if($("sengine").value == "http://cn.bing.com") {
				$("webs").href = "http://cn.bing.com/search?q=" + encodeURI(sword);
			}
			if($("sengine").value == "http://www.google.com") {
				$("webs").href = "http://www.google.com/#sclient=psy&hl=en&site=&source=hp&q=" + sword;
			}
			if($("sengine").value == "http://www.yahoo.cn") {
				$("webs").href = "http://www.yahoo.cn/s?q=" + sword;
			}
			if($("sengine").value == "http://www.70018.com") {
				$("webs").href = "http://www.70018.com/search/?q=" + sword;
			}
			break;
	}
}

function SearchGone()
{
	SearchSave();
	SearchRun();
}

// 内网搜索分页需要的函数
function BuildPager()
{
	if($("PAGE_PANEL").innerHTML!="") return;
	var counts = getElementsById2("span", "LAN_COUNT");
	if(counts.length>0) 
	{
		var imax=0;
		var unum = 0;
		var dsum = 0;
		for(var i=0; i<counts.length; i++) {
			var vna = counts[i].innerHTML.split(",");
			var vn = parseInt(vna[0], 10);
			if(vn>imax) imax = vn;
			dsum += vn;
			unum ++;
		}
		if(imax>20) 
		{
			var pcount = imax / 20;
			if((imax % 20)!=0) pcount++;
			var str = "第 ";
			for(var j=1; j<=pcount; j++) 
			{
				if(j==parseInt(lan_page))
				{
					str += "<b>" + j +"</b> ";
				}
				else 
				{
					str += "<a href=\"/desk/search.aspx?m=lan&q=" + lan_words + "&page=" + j + "\">" + j + "</a> ";
				}
			}
			str += " 页";
			$("PAGE_PANEL").innerHTML = str;
		}
		else 
		{
			$("PAGE_PANEL").innerHTML = " ";
		}
		$("PAGE_HEAD").innerHTML = "\"" + lan_words + "\" 内网搜索结果为" + unum  +"位同事的电脑共" + dsum + "条(当前为第" + lan_page +"页)";
	}
}
