﻿// JScript 文件

//编码与解码
function StrCode(str){if(encodeURIComponent) return encodeURIComponent(str);if(escape) return escape(str);}
function UnStrCode(str){if(decodeURIComponent ) return decodeURIComponent (str);if(unescape) return unescape(str);}

//删除两边的空格
function trim(s){
var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);
return (m == null)?"":m[1];
}

//检查是否是数字
function checkNum(str){
return str.match(/\D/)==null
}

//获得对象
function gid(id)
{
		return document.getElementById?document.getElementById(id):null;
}
function gname(name)
{
		return document.getElementsByTagName?document.getElementsByTagName(name):new Array();
}
	
//文本框按回车时返回的正确处理
function ClickButton(event, buttonId)
{
	var btnObj = gid(buttonId);
	if (btnObj)
	{
		var e = (event||window.event);
		if (e.keyCode == 13)
		{
			btnObj.click();
			return false;
		}
	}
	return true;
}
//当搜索按扭被按下时提交菜单
function SearchItem(inputType,inputOption, inputContent)
{
	var sel1Obj = gid(inputOption);
	var sel2Obj = gid(inputContent);
	if (sel1Obj && sel2Obj)
	{
		var sel1Value = trim(sel1Obj.value);
		var sel2Value = trim(sel2Obj.value);

		while(sel2Value.indexOf("*")!=-1){
		sel2Value = sel2Value.replace("*","");
		}
		while(sel2Value.indexOf("%")!=-1){
		sel2Value = sel2Value.replace("%","");
		}
		while(sel2Value.indexOf("\\")!=-1){
		sel2Value = sel2Value.replace("\\","");
		}
		while(sel2Value.indexOf("/")!=-1){
		sel2Value = sel2Value.replace("/","");
		}
		while(sel2Value.indexOf("'")!=-1){
		sel2Value = sel2Value.replace("'","");
		}
		while(sel2Value.indexOf("\"")!=-1){
		sel2Value = sel2Value.replace("\"","");
		}
		while(sel2Value.indexOf(".")!=-1){
		sel2Value = sel2Value.replace(".","");
		}
		while(sel2Value.indexOf(":")!=-1){
		sel2Value = sel2Value.replace(":","");
		}
		if (sel2Value==""){
		sel2Obj.value="";
		alert("请填写查询内容!");
		sel2Obj.onfocus();
		return;
		}
		
		var typeObj = gid(inputType);
		var toUrl;
		if(trim(typeObj.value)==0)
		{
		toUrl="SearchFood";
		}else
		{
		toUrl="SearchChemical";
		}
		
		var SearchURL = toUrl+ sel1Value + "C" + StrCode(sel2Value)+".aspx";
		location.href = SearchURL;
	}
}
