with (classes) {

with (dom) {

with (xpath) {

if (classes.XPathExpression) xpath.XPathExpression = classes.XPathExpression;
else {

xpath.XPathExpression = function (resolver)
{
 with (XPathExpression)
 {
  this.evaluate = evaluate;
  this.resolver = resolver;
 }

 return this;
}

XPathExpression.evaluate = function (contextNode, type, result) { with (this)
{
 if (! contextNode) throw new XPathException(XPathException.TYPE_ERR); // ??

 var SelectionNamespaces_String;

 if (resolver)
 {
  var the_prefixes = new Array;

  with (new RegExp("[\\w_][\\w\\d_]*(?=:)", "g"))
  {
   var This_Array;

   while (This_Array = exec(this.valueOf())) the_prefixes[the_prefixes.length] = This_Array[0];
  }

  the_prefixes.sort();

  var prefix_index = 0;

  while (prefix_index != the_prefixes.length)
   if (prefix_index + 1 != the_prefixes.length && the_prefixes[prefix_index] == the_prefixes[prefix_index + 1]) the_prefixes[prefix_index] = null;
   else ++ prefix_index;

  var SelectionNamespaces_String = "";

  var prefix_count = the_prefixes.length;

  for (prefix_index = 0; prefix_index != prefix_count; ++ prefix_index)
  {
   var the_prefix = the_prefixes[prefix_index];

   if (the_prefix)
   {
    namespace_uri = resolver(the_prefix);

    if (namespace_uri) SelectionNamespaces_String += ("xmlns:" + the_prefix + "=\"" + namespace_uri + "\" ");
   }
  }

  var defaultNamespace_uri = resolver("");

  if (defaultNamespace_uri) SelectionNamespaces_String += ("xmlns=\"" + defaultNamespace_uri + "\"");

  contextNode.ownerDocument.setProperty("SelectionNamespaces", SelectionNamespaces_String);
 }

// var The_RegExp = new RegExp("\"[^\"]*\"|'[^']*'|,|\\s+|[\\+\\-\\*\\|]|div(?![\\)\\[/])|mod(?![\\)\\[/])|[^\\,\\(\\)\\+\\-\\*\\|\\[\\]]+(?:\\[[^\\[\\]]+\\])?|\\(|\\)", "g");
// var The_RegExp = new RegExp("([^ ]+::[^ ]+)|\"[^\"]*\"|'[^']*'|,|\\s+|[\\+\\-\\*\\|]|div(?=[ \\(])|mod(?=[ \\(])|[^\\,\\(\\)\\+\\-\\*\\|\\[\\]]+(?:\\[[^\\[\\]]+\\])?|\\(|\\)", "g");
 var The_RegExp = /([^ \(]+::[^ \)]+)|"[^"]*"|'[^']*'|,|\s+|[\+\-\*\|]|div(?=[ \(])|mod(?=[ \(])|[^\,\(\)\+\-\*\|\[\]]+(?:\[[^\[\]]+\])?|\(|\)/g;

 var The_XPathResult = XPathExpression.get_XPathResult(The_RegExp, contextNode, valueOf(), type);

 contextNode.ownerDocument.setProperty("SelectionNamespaces", "");

 return The_XPathResult;
}}

XPathExpression.get_XPathResult = function (The_RegExp, Context_Node, Expression_String, the_XPathResult_type) { with (XPathExpression)
{
 var lastIndex, result_Array, The_XPathResult, subexpression = "";

 do
 {
  lastIndex = The_RegExp.lastIndex;

  result_Array = The_RegExp.exec(Expression_String);

  if (result_Array && result_Array[0] && The_RegExp.lastIndex > lastIndex) switch (result_Array[0])
  {
   case "concat":
   {
    var stringValue = "";

    var This_XPathResult;

    while (This_XPathResult = get_XPathResult(The_RegExp, Context_Node, Expression_String, XPathResult.STRING_TYPE))
     stringValue += This_XPathResult.stringValue;

    The_XPathResult = new XPathResult(stringValue, XPathResult.STRING_TYPE);
   }
    break;
   case "string": The_XPathResult = get_XPathResult(The_RegExp, Context_Node, Expression_String, XPathResult.STRING_TYPE);
    break;
   case "count":
   case "number": The_XPathResult = get_XPathResult(The_RegExp, Context_Node, Expression_String, XPathResult.NUMBER_TYPE);
    break;
   case "boolean": The_XPathResult = get_XPathResult(The_RegExp, Context_Node, Expression_String, XPathResult.BOOLEAN);
    break;
   case "|":
   {
    if (the_XPathResult_type != XPathResult.STRING_TYPE) throw new XPathException(XPathException.INVALID_EXPRESSION_ERR);

    if (! The_XPathResult) The_XPathResult = new XPathResult(0, XPathResult.STRING_TYPE);

    The_XPathResult.stringValue += get_XPathResult(The_RegExp, Context_Node, Expression_String, XPathResult.STRING_TYPE).stringValue;
   }
    break;
   case "div":
   case "mod":
   {
    if (! The_XPathResult)
    {
     The_XPathResult = new XPathResult(Context_Node.selectNodes(result_Array[0]), the_XPathResult_type);

     break;
    }
   }
   case "+":
   case "-":
   case "*":
   {
    if (the_XPathResult_type != XPathResult.NUMBER_TYPE) throw new XPathException(XPathException.INVALID_EXPRESSION_ERR);

    if (! The_XPathResult) The_XPathResult = new XPathResult(0, XPathResult.NUMBER_TYPE);

    var Expression_XPathResult = get_XPathResult(The_RegExp, Context_Node, Expression_String, XPathResult.NUMBER_TYPE);

    The_XPathResult.numberValue = eval("The_XPathResult.numberValue " +
     (result_Array[0] == "mod"? "%" : result_Array[0] == "div"? "/" : result_Array[0]) +
     " Expression_XPathResult.numberValue");
   }
    break;
   case "(": return get_XPathResult(The_RegExp, Context_Node, Expression_String, the_XPathResult_type);
    break;
   case ",":
   case ")": result_Array = null;
    break;
   case " ":
    break;
   default:
   {
    with (result_Array[0])
    {
     The_XPathResult = (charAt(0) == '"' || charAt(0) == "'")?
       new XPathResult(substring(1, length - 1), XPathResult.STRING_TYPE)
     : Number(valueOf())? new XPathResult(Number(valueOf()), XPathResult.NUMBER_TYPE)
     : null; // new XPathResult(Context_Node.selectNodes(valueOf()), the_XPathResult_type);
    }

    subexpression += result_Array[0];
   }
  }
 } while (result_Array && The_RegExp.lastIndex > lastIndex);

 return The_XPathResult? The_XPathResult : new XPathResult(Context_Node.selectNodes(subexpression), the_XPathResult_type);
}}

}

}

}

}
