function LTrim(s)
{
    for(var i=0;i<s.length;i++)
        if(s.charAt(i)!=' ')
         return s.substring(i,s.length);
     return "";
}

function RTrim(s)
{
    for(var i=s.length-1;i>=0;i--)
        if(s.charAt(i)!=' ')
            return s.substring(0,i+1);
        return "";
}

function Trim(s)
{
    return RTrim(LTrim(s));
}

function notice(s)
{
	alert(s);
	document.topsearch.keyword.focus();
	return false;
}

function gettopsearchword()
{
	var _keyword = document.topsearch.keyword.value;
	_keyword = Trim(_keyword);
	var _kwArray = _keyword.split(" ");
	var _searchword = "";
	var _sword = "";
	for(var i=0;i<_kwArray.length;i++)
	{
		if(i==0)
		{
			_searchword = Trim(_kwArray[0]);
		}
		else
		{
			_searchword = _searchword + "*" + Trim(_kwArray[i]);
		}
	}
	if(_searchword != "")
	{
		document.topsearch.searchword.value=_searchword;
	}
	else
	{
	return notice("搜索词不能为空");
	}
	
}
function submittopsearch()
{
	if (document.topsearch.channelid.value=="75002"){
        document.topsearch.action="http://202.101.105.176/czjs/transearchword.jsp";
        }
	if (document.topsearch.channelid.value=="75448"){
        document.topsearch.action="http://202.101.105.176/czjs/transearchword_zfwj.jsp";
        }
	if (document.topsearch.channelid.value=="75449"){
        document.topsearch.action="http://202.101.105.176/czjs/transearchword_flfg.jsp";
        }
	
	//搜索结果页
	
	if (document.topsearch.channelid.value=="75192"){
        document.topsearch.action="http://202.101.105.176/search/search.jsp?channelid=75192";
        }	
        var _keyword = Trim(document.topsearch.keyword.value);
	if(_keyword.length>0)
	{
		if(_keyword.indexOf("+")>=0)
		{
			return notice("搜索词中不能含有关键字'+'");
		}
		else if(_keyword.indexOf("*")>=0)
		{
			return notice("搜索词中不能含有关键字'*'");
		}
		else if(_keyword.indexOf("-")>=0)
		{
			return notice("搜索词中不能含有关键字'-'");
		}
	}
	else
	{
			return notice("搜索词不能为空");
	}
	gettopsearchword();
}
//高级搜索跳转页
function onChangeSel() {
  if(document.topsearch.channelid.value=="75192" )
  document.getElementById("advsearch").href="http://202.101.105.176/search/xmgovadvsearch.jsp";
   if(document.topsearch.channelid.value=="75002" )
  document.getElementById("advsearch").href="http://202.101.105.176/czjs/wz_adv.jsp";
   if(document.topsearch.channelid.value=="75448" )
  document.getElementById("advsearch").href="http://202.101.105.176/czjs/zfwjjs_govfile.jsp";
   if(document.topsearch.channelid.value=="75449" )
  document.getElementById("advsearch").href="http://202.101.105.176/czjs/flfg_flfgzhjs.jsp";
}

var searchtopHTML = "<table  cellspacing='0' cellpadding='5'><form method='post' action='http://202.101.105.176/czjs/search.jsp'  name='topsearch' onSubmit='return submittopsearch();'><tr><td><span class='iwhite'>搜索</span></td><td><input name='keyword' type='text' class='ibox' size='16'><INPUT type=hidden name=searchword></td><td><input type='image' src='http://www.xm.gov.cn/images/but_ss.gif' width='59' height='20' border='0' align='absmiddle' style='cursor:hand'></td></tr><tr><td>&nbsp;</td><td><select name='channelid' class='t9' onChange='onChangeSel();'><option value='75192' selected>站内检索</option><option value='75002'>部门网站检索</option><option value='75448'>政府文件检索</option><option value='75449'>法律法规检索</option></select></td><td><a id='advsearch' href='http://202.101.105.176/search/xmgovadvsearch.jsp' target=_blank><img src='http://www.xm.gov.cn/images/but_gjss.gif' width='59' height='20' border='0' align='absmiddle'></a></td></tr><tr><td colspan='3' align='center' class='iwhite'><a href='http://www.xm.gov.cn/' class='white'>简体</a> | <a href='http://www.big5.xm.gov.cn:82/' class='white'>繁体</a> | <a href='http://english.xm.gov.cn/' class='white ieng t9e'>English</a>|<a href=\"http:\/\/www.xm.gov.cn\/index_2250.htm\"  class=\"white\" target=\"_blank\">手机门户<\/a>&nbsp;<a href=\"http:\/\/www.xm.gov.cn\/rss\/index.htm\" target=\"_blank\"><img src=\"http://www.xm.gov.cn\/images\/2009_rss.gif\" width=\"28\" height=\"12\" border=\"0\"align=\"absmiddle\" alt=\"RSS信息订阅\"><\/a></td></tr></form></table>";
document.write(searchtopHTML);
