/*******************************************************************
 函数名：    	CheckCharacter(Character)
 功能：		替换敏感字符。
 入口参数：	Character：需要替换的字符串
 返回值：    String 
*******************************************************************/
//------------------------------------------------------------------
function CheckCharacter(Character){
    var target =  new Array("(",")",",","/","@", "=",">","<","!","&","*","^","-","+",",","%","?","'","[","]","ADJ ","EQU ","PRE ","AND ","XOR ","NOT ","OR ","TO ");
	var result  = "",pre="";
	Character = Character.toUpperCase()+" ";
	for(var i=0;i<target.length;i++)
	{
	   var temp = target[i];
	   while(Character.indexOf(temp)!=-1&&Character.substring(Character.indexOf(temp)-1,Character.indexOf(temp)).charCodeAt(0)!=92)
	   {
            Character         = replaceStr(Character,temp,"\\"+temp);
	   }
	}

	while(Character.indexOf("\\\\")!=-1)
        Character = replaceStr(Character,"\\\\","\\");
	return Character;
}

/*******************************************************************
 函数名：replaceStr(target,str1,str2)
 功能：		替换字符串
 入口参数：	target:目标串;str1:需要替换的字符串；str2:替换为
 返回值：	    完成替换的结果
*******************************************************************/
function replaceStr(target,str1,str2)
{
	var pre,i=0,result="";
	while(target.indexOf(str1)!=-1)
	{
			pre      = target.substring(0,target.indexOf(str1));
			target   = target.substring(target.indexOf(str1)+str1.length,target.length);
			result   = result+pre+str2.toUpperCase();
	}
    return result+target;
}

/*******************************************************************
 函数名：	Trim(Liter)
 功能：		Trim。
 入口参数：	Liter:字符串
 返回值：	去除前后空格的字符串
*******************************************************************/
function Trim(Liter){
	if (Liter==null)
	{
		return Liter;
	}
	if (Liter=="")
	{
		return Liter;
	}
	for (var i=0;i<Liter.length ;i++ )
	{
		var temp=Liter.substring(i,i+1);
		if ((temp!=" ")&&(temp!="\t") && (temp.charCodeAt(0)!=13) && (temp.charCodeAt(0)!=10))
		{
			Liter=Liter.substring(i,Liter.length);
			break;
		}
	}
	for (var i=Liter.length;i>=0 ;i-- )
	{
		var temp=Liter.substring(i-1,i);
		if ((temp!=" ")&&(temp!="\t") && (temp.charCodeAt(0)!=13) && (temp.charCodeAt(0)!=10))
		{
			Liter=Liter.substring(0,i);
			break;
		}
	}
	return Liter;
}

/*******************************************************************
 函数名：	Translate(result)
 功能：		转译，按照GOOGLE搜索规则进行转译，转译为TRS可识别的串
 入口参数：	result:字符串
 返回值：	    完成转译的字符串
*******************************************************************/
function Translate(result)
{
	result = Trim(result);
	if(result=="")
	{
		return "";
	}
	else
	{
		result = replaceStr(result," "," + ");
		result = replaceStr(result,","," + ");
		result = replaceStr(result,"，"," + ");
		if(result.lastIndexOf("+")+1==result.length)
		  result = result.substring(0,result.lastIndexOf("+")-1);
		while(result.indexOf(" +  + ")!=-1)
			result = replaceStr(result," +  + "," + ");
		return "("+result+")";
	}
}

/*******************************************************************
 函数名：	isNumber(inputstr,mode)
 功能：		判断inputstr是否为十进制的mode型数字（整型或浮点型）
 入口参数：	inputstr：。
 		mode: "float",浮点型；"int"，整型。
 返回值：	BOOLEAN型 （true/false）
*******************************************************************/
//---------------------------------------------------------------------------
  function isNumber(inputstr,mode){
  	 var str = " " + inputstr + " " ;
  	 var startindex, endindex ;
  	 var returnbool=true, tag = true ;
  	 var i ;
  	 var firstchar ;
  	 var negative = false, positive = false, unuse = false, zero = false ;
  	 startindex = str.indexOf(" ")
  	 endindex = str.lastIndexOf(" ")
  	 while(tag){
  	 	tag = false
  	 	firstchar = str.substring(startindex, startindex+1)
  	 	if(firstchar == " " && !zero){
  	 	  startindex++
  	 	  tag = true
  	 	  unuse=true
  	 	}else if( firstchar == "0" ){
  	 	  startindex++
  	 	  tag = true
  	 	  zero = true
  	 	}else if(firstchar == "-"){
  	 	  if(negative || positive || zero){returnbool = false}
  	 	  else{
  	 	  startindex++
  	 	  tag = true
  	 	  negative=true
  	 	  }
  	 	}else if(firstchar == "+"){
  	 	  if(negative || positive || zero){returnbool = false}
  	 	  else{
  	 	  startindex++
  	 	  tag = true
  	 	  positive=true
  	 	  }
  	 	}  
  	 	if(str.substring(endindex,endindex+1) <= " "){ //相当于RTrim()
  	 	  endindex--
  	 	  tag=true
  	 	}
  	 	if (endindex <= startindex) tag = false
  	 }
    str = str.substring(startindex, endindex+1)
    if(returnbool){
  	 if (mode.toLowerCase() == "int"){
        if(str.indexOf(".")!=-1)returnbool=false;
  	 	else {
			if (negative) str = "-" + str
  			i = parseInt(str)
		}
  	 }
  	 else if(mode.toLowerCase() == "float"){
  	   if (str.substring(0,1) == ".") str = "0" + str
  	   if (negative) str = "-" + str
  	   i = parseFloat(str)
  	 }
  	 else i = parseFloat(str)
  	 if (i == str){
  	 	returnbool = true
  	 }
  	 else returnbool = false
  	 }
  	 return returnbool
  }