<!--
var splitQueryWordsErrorMessage = "";
var splitQueryWordsErrorCount = 0;
var getWordPoint = 0;
var separators = ' *+-(<=>=)~"';          // 可能的分隔符。CGRS命令中不能用单引号

function isDigits(s) {                 // s 是否是由数字组成
      var b = true;
      if (s==null || s=="") {b = false;}
      else {for (var i=0; i<s.length; i++) {
                  if ("0123456789".indexOf(s.charAt(i)) < 0) {
                        b = false;
                        break;
                  }
            }
      }
      return b;
}

function splitQueryWords(fldId, wordString, fldType) {

      if (wordString==null || wordString=="") {return "";}
      if (fldId==null || fldId=="") {fldId = "@A";}//所有字段
      if (fldType==null || fldType=="") {fldType = " ";}//默认字段类型为空格？
      var prefix = "(";//前缀
      var postfix = ")";//后缀
      while (" *+".indexOf(wordString.charAt(0)) >= 0) {wordString = wordString.substring(1);}   // 过滤掉前缀空格和*、+
      while (wordString.length>0 && wordString.charAt(wordString.length-1)==" ") {          // 过滤掉后缀空格
            wordString = wordString.substring(0,wordString.length-1);
      }

      var isNum = ("345".indexOf(fldType)<0?false:true);//是否是数值类型
      var returnString = "";
      var parenthesisNumber = 0;
      var lastWordKind = "f";
      var matchingChar = "";
      splitQueryWordsErrorMessage = "";
      getWordPoint = 0;
      var currentWord = getWord(wordString);
      while (currentWord != "") {
            if (currentWord == "(") {
                  parenthesisNumber++;
                  if ("wd)".indexOf(lastWordKind) >= 0) {returnString += "*" + currentWord;}
                  else {returnString += currentWord;}
                  lastWordKind = "(";
                  currentWord = getWord(wordString);
            }
            else {if (currentWord == ")") {
                        parenthesisNumber--;
                        returnString += currentWord;
                        lastWordKind = ")";
                        currentWord = getWord(wordString);
                  }
                  else {if (currentWord=="+" || currentWord=="-" || currentWord=="*") {
                              if (lastWordKind=="o") {
                                    splitQueryWordsErrorMessage += "操作符重复(位置：" + getWordPoint + ")\n";
                                    splitQueryWordsErrorCount++;
                              }
                              returnString += currentWord;
                              lastWordKind = "o";
                              currentWord = getWord(wordString);
                        }
                        else {if (currentWord == "=") {
                                    if ("wd)".indexOf(lastWordKind) >= 0) {returnString += "*";}
                                    returnString += fldId + currentWord + "_";
                                    lastWordKind = "l";
                                    currentWord = getWord(wordString);
                              }
                              else {if (currentWord==">" || currentWord=="<" || currentWord=="<=" || currentWord==">=") {
                                          if (!isNum) {
                                                splitQueryWordsErrorMessage += "非数字型字段不能用<、>、<=、>=符(位置：" + getWordPoint + ")\n";
                                                splitQueryWordsErrorCount++;
                                          }
                                          if ("wd)".indexOf(lastWordKind) >= 0) {returnString += "*";}
                                          returnString += fldId + currentWord;
                                          if (currentWord==">" || currentWord=="<") {returnString += "_";}
                                          lastWordKind = "l";
                                          currentWord = getWord(wordString);
                                    }
                                    else {if (currentWord == "~") {
                                                if (!isNum) {
                                                      splitQueryWordsErrorMessage += "非数字型字段不能用~符(位置：" + getWordPoint + ")\n";
                                                      splitQueryWordsErrorCount++;
                                                }
                                                if (lastWordKind != "w") {
                                                      splitQueryWordsErrorMessage += "~前应有起始值(位置：" + getWordPoint + ")\n";
                                                      splitQueryWordsErrorCount++;
                                                      if ("wd)".indexOf(lastWordKind) >= 0) {returnString += "*";}
                                                      returnString += "00000000";
                                                }
                                                returnString += currentWord;
                                                currentWord = getWord(wordString);
                                                if (separators.indexOf(currentWord) >= 0) {
                                                      splitQueryWordsErrorMessage += "~后应有终止值(位置：" + getWordPoint + ")\n";
                                                      splitQueryWordsErrorCount++;
                                                      returnString += "99999999";
                                                }
                                                else {returnString += currentWord;
                                                      currentWord = getWord(wordString);
                                                }
                                                lastWordKind = "d";
                                          }
                                          else {if (currentWord.charAt(0)=='"') {
                                                      matchingChar = currentWord.charAt(0);
                                                      if (currentWord.length>0 && currentWord.charAt(currentWord.length-1)!=matchingChar) {
                                                            splitQueryWordsErrorMessage += "引号(" + matchingChar + ")不成对(位置：" + getWordPoint + ")\n";
                                                            splitQueryWordsErrorCount++;
                                                            currentWord += matchingChar;
                                                      }
//                                                      currentWord = currentWord.substring(0, currentWord.length-1);
//                                                      currentWord = currentWord.substring(1);
                                                }
                                                if (lastWordKind == "l") {returnString += currentWord;}
                                                else {if ("wd)".indexOf(lastWordKind) >= 0) {
                                                            returnString += "*" + fldId + "=_" + currentWord;
                                                      }
                                                      else {returnString += fldId + "=_" + currentWord;}
                                                }
                                                if (isNum && !isDigits(currentWord)) {
                                                      splitQueryWordsErrorMessage += "必须是数字的(位置：" + getWordPoint + ")\n";
                                                      splitQueryWordsErrorCount++;
                                                }
                                                lastWordKind = "w";
                                                currentWord = getWord(wordString);
                                          }
                                    }
                              }
                        }
                  }
            }
      }
      if (parenthesisNumber > 0) {
            splitQueryWordsErrorMessage += "括号不匹配（多"+parenthesisNumber+"个左括号）\n";
            splitQueryWordsErrorCount++;
            while (parenthesisNumber > 0) {returnString += ")"; parenthesisNumber--;}
      }
      if (parenthesisNumber < 0) {
            splitQueryWordsErrorMessage += "括号不匹配（少"+parenthesisNumber+"个左括号）\n";
            splitQueryWordsErrorCount++;
            while (parenthesisNumber < 0) {returnString = "("+returnString; parenthesisNumber++;}
      }
      if (returnString.indexOf("-")==0) {prefix += "@F=_";} //处理以"-"开头的查询词
      
      returnString = prefix + returnString + postfix;
      return returnString;
}

function getWord(str) {

      var returnWord = "";
      var matchingChar = "";
      if (getWordPoint < str.length) {
            while (getWordPoint<str.length && str.charAt(getWordPoint)==" ") {getWordPoint++;} // 过滤掉前缀空格
            if (getWordPoint < str.length) {
	          if (str.charAt(getWordPoint) == "(") {      // 如果首字符是：(
                        returnWord += str.charAt(getWordPoint);
                        getWordPoint++;
                        while (getWordPoint<str.length && " *+".indexOf(str.charAt(getWordPoint))>=0) {
                              getWordPoint++;              // 过滤掉“(”后的前缀空格和*、+
                        }
                  }
                  else {if (str.charAt(getWordPoint)=='<' || str.charAt(getWordPoint)=='>') {      // 如果首字符是：<>
                              returnWord += str.charAt(getWordPoint);
                              getWordPoint++;
                              if (getWordPoint<str.length && str.charAt(getWordPoint)=="=") {
                                    returnWord += str.charAt(getWordPoint);
                                    getWordPoint++;
                              }
                        }
                        else {if ("*+-~=)".indexOf(str.charAt(getWordPoint))>=0) {      // 如果首字符是：*+-~=)
                                    returnWord += str.charAt(getWordPoint);
                                    getWordPoint++;
                              }
                              else {if (str.charAt(getWordPoint)=='"') {                // 如果首字符是：引号
                                          matchingChar = str.charAt(getWordPoint);
                                          returnWord += str.charAt(getWordPoint);
                                          getWordPoint++;
                                          while (getWordPoint<str.length && str.charAt(getWordPoint)!=matchingChar) {
                                                returnWord += str.charAt(getWordPoint);
                                                getWordPoint++;
                                          }
                                          if (getWordPoint < str.length) {returnWord += str.charAt(getWordPoint);}
                                          getWordPoint++;
                                    }
                                    else {while (getWordPoint<str.length && separators.indexOf(str.charAt(getWordPoint))<0) {
                                                returnWord += str.charAt(getWordPoint);
                                                getWordPoint++;
                                          }
                                    }
                              }
                        }
                  }
            }
      }
      return returnWord;
}

function alternateCMD(srcStr) {

      if (srcStr == null) {srcStr = "";}
      var returnString = "", i = 0;
      for (i = 0; i < srcStr.length; i++) {
            if (srcStr.charAt(i) == "+") {returnString += '%2B';}
            else {if (srcStr.charAt(i) == "=") {returnString += '%3D';}
                  else {returnString += srcStr.charAt(i);}
            }
      }
      return returnString;
}

//转换url传递的参数
function alternateURL(s) {
  if (s==null || s=="") {return "";}
  var special_symbol = "=!#$%'()+,/:;<>?[]^`{|}~\t\n\"\\";
  var rs = "";
  for (var i=0; i<s.length; i++) {
    if (s.charAt(i) == "+") {rs += '%2B';}       // 等号(=)不会变，要特殊处理
    else {
      if (special_symbol.indexOf(s.charAt(i))>=0) {rs += escape(s.charAt(i));}
      else {rs += s.charAt(i);}
    }
  }
  return rs;
}

//-->
