/**************************************************
FreeanceXMLParser.js
  XML parser for the freeance configuration libraries
  extends the base xml parser, adding appropriate
  functions for dealing with the possible freeance
  extensions and core modules.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Dependancies:
  XMLParser-base.js
  Util.js
  X.js

**************************************************/

FreeanceXMLParser = function(newID)
{
  if (arguments.length > 0)
    this.init(newID);
};
FreeanceXMLParser.prototype = new XMLParser();
FreeanceXMLParser.prototype.constructor = FreeanceXMLParser;
FreeanceXMLParser.superclass = XMLParser.prototype;

FreeanceXMLParser.prototype.init = function(newID)
{
  FreeanceXMLParser.superclass.init.call(this, newID);  //call parent's init function
};

FreeanceXMLParser.prototype.getObject = function(objectName)
{
  //this overrides the default parser's getObject function
  if (this.xmlDoc == null)
    return null;
  if (arguments.length > 0)
  {
    switch (arguments[0])
    {
      case 'applicationConfig':
        return (this.parseApplicationConfig(this.xmlDoc.getElementsByTagName("applicationConfig").item(0)));
        break;
      case 'mapConfig':
        return (this.parseMapConfig(this.xmlDoc.getElementsByTagName("map").item(0)));
        break;
      case 'templateConfig':
        return (this.parseTemplateConfig(this.xmlDoc.getElementsByTagName("templates").item(0)));
        break;
      case 'extensionConfig':
        return(this.parseExtensionConfig(this.xmlDoc.getElementsByTagName('extensionConfig').item(0)));
        break;
      case 'queryConfig':
        return (this.parseQueryConfig(this.xmlDoc.getElementsByTagName("queryConfig").item(0)));
        break;
      case 'measureConfig':
        return (this.parseMeasureConfig(this.xmlDoc.getElementsByTagName(arguments[0]).item(0)));
        break;
      case 'coordConvConfig':
        return (this.parseCoordConvConfig(this.xmlDoc.getElementsByTagName(arguments[0]).item(0)));
        break;
      case 'emailConfig':
        return (this.parseEMailConfig(this.xmlDoc.getElementsByTagName(arguments[0]).item(0)));
        break;
      default:
        return (this.getObjectRecurse(this.xmlDoc.getElementsByTagName("value").item(0)));
    }
  }
  else
    return (this.getObjectRecurse(this.xmlDoc.getElementsByTagName("value").item(0)));
    //here we assume that they incorrectly declared the parser...
};

FreeanceXMLParser.prototype.getObjectRecurse = function()
{
  //first argument is the starting node. 
  //additional parameters may be required for certain node types; these vary
  
  
  //dprintf('FreeanceXMLParser.getObjectRecurse;executing native code for '+arguments[0].nodeName,false);
  var theNode = arguments[0];
  var returnValue = null;
  var i = 0;
  if (this.xmlDoc == null) 
    return null;
  else      
    switch (theNode.nodeName)
    {
      case 'left':
      case 'top':
      case 'zpos':
      case 'width':
      case 'height':
      case 'visibility':
      case 'style':
      case 'label':
      case 'imageName':
      case 'partOfExtension':
      case 'tooltip':
      case 'onTooltip':
      case 'offTooltip':
      case 'buttonState':
      case 'useRollover':
      case 'enableDrag':
      case 'groupName':
      case 'imageSource':
      case 'scaleImage':
      case 'orientation':
      case 'caption':
      case 'setActive':
      case 'useScroll':
      case 'pageType':
      case 'usePageControl':
      case 'color':
      case 'font':
      case 'fontSize': 
      case 'valueFontSize':
      case 'cellSpacing':
        if (this.__helper__getNextElementNamedChildNode(theNode,0,"value")!= -1)
          return (this.getObjectRecurse(theNode.childNodes[this.__helper__getNextElementNamedChildNode(theNode,0,"value")]));
        else
        {
          return null;
        }
        break;
      default:
      {
        return FreeanceXMLParser.superclass.getObjectRecurse.call(this, arguments[0]);
        break;
      }
    }
  return returnValue;
};

FreeanceXMLParser.prototype.parseApplicationConfig = function(appNode)
{
  var appConfig = new Array;
  appConfig.id = this.decodeSTRING(appNode.childNodes[this.__helper__getNextElementNamedChildNode(appNode,0,"applicationId")]);
  appConfig.organization = this.decodeSTRING(appNode.childNodes[this.__helper__getNextElementNamedChildNode(appNode,0,"organization")]);
  appConfig.title = this.decodeSTRING(appNode.childNodes[this.__helper__getNextElementNamedChildNode(appNode,0,"title")]);
  appConfig.clientType = this.decodeSTRING(appNode.childNodes[this.__helper__getNextElementNamedChildNode(appNode,0,"clientType")]);
  if (this.__helper__getNextElementNamedChildNode(appNode,0,"stylesheet") != -1)
    appConfig.stylesheet = this.decodeSTRING(appNode.childNodes[this.__helper__getNextElementNamedChildNode(appNode,0,"stylesheet")]);
  else
    appConfig.stylesheet = 'default';
  appConfig.administrator = this.decodeSTRING(appNode.childNodes[this.__helper__getNextElementNamedChildNode(appNode,0,"administrator")]);
  appConfig.adminEmail = this.decodeSTRING(appNode.childNodes[this.__helper__getNextElementNamedChildNode(appNode,0,"adminEmail")]);
  
  var customLayoutIndex = this.__helper__getNextElementNamedChildNode(appNode,0,"customOptions");
  appConfig.customOptions = ((customLayoutIndex!=-1)?(this.parseApplicationCustomOptions(appNode.childNodes[customLayoutIndex])):(null));
  OBJECT_MANAGER.setGuiValue("ApplicationConfig", appConfig);
  return appConfig;
};

FreeanceXMLParser.prototype.parseApplicationCustomOptions = function (customNode)
{
  var customConfig = new Object;
  customConfig.pageHeaderHeight = this.decodeINT(customNode.childNodes[this.__helper__getNextElementNamedChildNode(customNode,0,"pageHeaderHeight")]);
  customConfig.rightPanelWidth = this.decodeINT(customNode.childNodes[this.__helper__getNextElementNamedChildNode(customNode,0,"rightPanelWidth")]);
  customConfig.mapToolOptionHeight = this.decodeINT(customNode.childNodes[this.__helper__getNextElementNamedChildNode(customNode,0,"mapToolOptionHeight")]);
  customConfig.vicinityMapWidthOpen = this.decodeINT(customNode.childNodes[this.__helper__getNextElementNamedChildNode(customNode,0,"vicinityMapWidthOpen")]);
  customConfig.homeLinkHeight =this.decodeINT(customNode.childNodes[this.__helper__getNextElementNamedChildNode(customNode,0,"homeLinkHeight")]);
  var nodeIndex = this.__helper__getNextElementNamedChildNode(customNode,0,"defaultActivePanel");
  customConfig.defaultActivePanel = (nodeIndex>-1)?(this.decodeSTRING(customNode.childNodes[nodeIndex])):('userIntro');
  nodeIndex = this.__helper__getNextElementNamedChildNode(customNode,0,"mapAutoRedraw");
  customConfig.mapAutoRedraw = (nodeIndex==-1)?(true):(this.decodeINT(customNode.childNodes[nodeIndex])==1);
  nodeIndex = this.__helper__getNextElementNamedChildNode(customNode,0,"clickDeselect");
  customConfig.clickDeselect = (nodeIndex==-1)?(true):(this.decodeINT(customNode.childNodes[nodeIndex])==1);
  nodeIndex = this.__helper__getNextElementNamedChildNode(customNode,0,"expandSearch");
  customConfig.expandSearch = (nodeIndex==-1)?(false):(this.decodeINT(customNode.childNodes[nodeIndex])==1);
  nodeIndex = this.__helper__getNextElementNamedChildNode(customNode,0,"freezeTableHeader");
  customConfig.freezeTableHeader = (nodeIndex==-1)?(true):(this.decodeINT(customNode.childNodes[nodeIndex])==1);
  nodeIndex = this.__helper__getNextElementNamedChildNode(customNode,0,"customLegendURL");
  customConfig.customLegendURL = (nodeIndex==-1)?(''):(this.decodeSTRING(customNode.childNodes[nodeIndex]));
  return customConfig;
};

FreeanceXMLParser.prototype.parseMapConfig = function(mapNode)
{
  var mapConfig = new Object();
  mapConfig['id'] = mapNode.getAttribute("id");
  mapConfig["resourceId"] = this.decodeSTRING(mapNode.childNodes[this.__helper__getNextElementNamedChildNode(mapNode,0,"resourceId")]);
  mapConfig["imsHostname"] = this.decodeSTRING(mapNode.childNodes[this.__helper__getNextElementNamedChildNode(mapNode,0,"imsHostname")]);
  mapConfig["previousStates"] = this.decodeINT(mapNode.childNodes[this.__helper__getNextElementNamedChildNode(mapNode,0,"previousStates")]);
  if (this.__helper__getNextElementNamedChildNode(mapNode,0,"vicinityMap")!=-1)
    mapConfig['vmap'] = this.parseVMapConfig(mapNode.childNodes[this.__helper__getNextElementNamedChildNode(mapNode,0,"vicinityMap")]);
  if (this.__helper__getNextElementNamedChildNode(mapNode,0,"themeDefinitions")!=-1)
    mapConfig['themes'] = this.parseThemeDefinitions(mapNode.childNodes[this.__helper__getNextElementNamedChildNode(mapNode,0,"themeDefinitions")]);
  mapConfig["activeTheme"] = this.decodeSTRING(mapNode.childNodes[this.__helper__getNextElementNamedChildNode(mapNode,0,"activeTheme")]);
  if (this.__helper__getNextElementNamedChildNode(mapNode,0,"themeGroupDefinitions")!=-1)
    mapConfig['themeGroups'] = this.parseThemeGroupDefinitions(mapNode.childNodes[this.__helper__getNextElementNamedChildNode(mapNode,0,"themeGroupDefinitions")]);
  if (this.__helper__getNextElementNamedChildNode(mapNode,0,"legendAttributes")!=-1)
    mapConfig['legendAttributes'] = this.parseLegendAttributes(mapNode.childNodes[this.__helper__getNextElementNamedChildNode(mapNode,0,"legendAttributes")]);

  //These are extensions; don't parse them if the appropriate extension is not loaded!

  if (this.__helper__getNextElementNamedChildNode(mapNode,0,"labelConfig")!=-1)
    mapConfig['labelConfig'] = this.parseLabelConfig(mapNode.childNodes[this.__helper__getNextElementNamedChildNode(mapNode,0,"labelConfig")]);
  if (this.__helper__getNextElementNamedChildNode(mapNode,0,"loginQuery")!=-1)
    mapConfig['loginQuery'] = this.parseMapLoginQuery(mapNode.childNodes[this.__helper__getNextElementNamedChildNode(mapNode,0,"loginQuery")]);

  //Configure the printing system
  
  var printConfigTags = this.__helper__getRemainingNextElementNamedChildNodes(mapNode,0,"pdfPrintConfig");
  if (printConfigTags.length > 0){
    mapConfig.printConfig = this.parsePdfPrintConfig(printConfigTags[0]);
  }
  else{
    mapConfig.printConfig = new Object;
    mapConfig.printConfig.templates = new Array;
    mapConfig.printConfig.defaultTemplate = -1;
  }
  
  //Configure the CSV export system
  if (this.__helper__getNextElementNamedChildNode(mapNode,0,"exportConfig")!=-1)
    mapConfig['exportConfig'] = this.parseMapExportConfig(mapNode.childNodes[this.__helper__getNextElementNamedChildNode(mapNode,0,"exportConfig")]);
  if (this.__helper__getNextElementNamedChildNode(mapNode,0,"scalebar")!=-1)
  {
    var scalebarConfigNode = mapNode.childNodes[this.__helper__getNextElementNamedChildNode(mapNode,0,"scalebar")];
    mapConfig['scalebarConfig'] = this.parseScalebarConfig(scalebarConfigNode);
  }
  else
  {
    mapConfig['scalebarConfig'] = null;
  }
  //Capture any geocode extension data
  if (this.__helper__getNextElementNamedChildNode(mapNode,0,"geocodeConfig")!=-1)
    mapConfig['geocodeConfig'] = this.parseGeocodeConfig(mapNode.childNodes[this.__helper__getNextElementNamedChildNode(mapNode,0,"geocodeConfig")]);

  //Capture any directmapping extension data
  try
  {
    if (this.__helper__getNextElementNamedChildNode(mapNode,0,"directMappingConfig")!=-1)
      mapConfig['directMappingConfig'] = this.parseDirectMappingConfig(mapNode.childNodes[this.__helper__getNextElementNamedChildNode(mapNode,0,"directMappingConfig")]);
  }
  catch(e)
  {
    //A direct mapping configuration is present but the direct mapping extension has not been loaded.
    //this can happen in some circumstances so let the error go, it won't hurt anything.
    //alert('Freeance Direct is configured but not installed.');
  }
  OBJECT_MANAGER.setGuiValue(mapConfig['id'], mapConfig);
  return mapConfig;
};

FreeanceXMLParser.prototype.parseScalebarConfig = function(newNode)
{
  var scalebarConfig = new Array();
  for (var levelIndex = this.__helper__getNextElementNamedChildNode(newNode,0,"level");levelIndex!=-1;levelIndex=this.__helper__getNextElementNamedChildNode(newNode,levelIndex+1,"level"))
  {
    var levelNode = newNode.childNodes[levelIndex];
    var currentLevel = scalebarConfig.length;
    scalebarConfig[currentLevel] = new Array;
    scalebarConfig[currentLevel][0] = parseInt(levelNode.getAttribute('topUnit'));
    scalebarConfig[currentLevel][1] = parseFloat(levelNode.getAttribute('topLength'));
    scalebarConfig[currentLevel][2] = parseInt(levelNode.getAttribute('bottomUnit'));
    scalebarConfig[currentLevel][3] = parseFloat(levelNode.getAttribute('bottomLength'));
    scalebarConfig[currentLevel][4] = parseFloat(levelNode.getAttribute('mapWidth'));
  }
  return scalebarConfig;
};

FreeanceXMLParser.prototype.parseVMapConfig = function(vmapNode)
{
  var vmapConfig = new Array();
  var childNodeIndex = 0;
  vmapConfig['id'] = vmapNode.getAttribute("id");
  vmapConfig["resourceId"] = this.decodeSTRING(vmapNode.childNodes[this.__helper__getNextElementNamedChildNode(vmapNode,0,"resourceId")]);
  vmapConfig["slaveType"] = this.decodeSTRING(vmapNode.childNodes[this.__helper__getNextElementNamedChildNode(vmapNode,0,"slaveType")]);
  vmapConfig["boundBoxPercentMin"] = this.decodeDOUBLE(vmapNode.childNodes[this.__helper__getNextElementNamedChildNode(vmapNode,0,"boundBoxPercentMin")]);
  vmapConfig["styleSheet"] = this.decodeSTRING(vmapNode.childNodes[this.__helper__getNextElementNamedChildNode(vmapNode,0,"styleSheet")]);
  return vmapConfig;
};

FreeanceXMLParser.prototype.parseTemplateConfig = function(templateRootNode)
{
  var templates = new Object();
  var htmlString = '';
  for (var templateIndex = this.__helper__getNextElementNamedChildNode(templateRootNode,0,"template");templateIndex!=-1;templateIndex=this.__helper__getNextElementNamedChildNode(templateRootNode,templateIndex+1,"template"))
  {
    for (var lcv=0;lcv < templateRootNode.childNodes[templateIndex].childNodes.length;lcv++)
    {
      if (templateRootNode.childNodes[templateIndex].childNodes.item(lcv).nodeType == 4)
        htmlString = templateRootNode.childNodes[templateIndex].childNodes.item(lcv).nodeValue;
    }
    templates[templateRootNode.childNodes[templateIndex].getAttribute("id")] = htmlString;
  }
  OBJECT_MANAGER.setGuiValue('templates', templates);
  return templates;
};

FreeanceXMLParser.prototype.parseExtensionConfig = function(extensionConfigNode)
{
  var extensions = new Object();
  var extensionNodes = extensionConfigNode.getElementsByTagName('extension');
  for(var lcv=0; lcv < extensionNodes.length;lcv++)
  {
    var extension = extensionNodes[lcv];
    var name = extension.getAttribute('name');
    var enabled = extension.getAttribute('enabled');
    extensions[name] = new Object();
    extensions[name].enabled = (enabled == 'true'); //?true:false;
    if (extensions[name].enabled)
    {
      var forceLoad = extension.getAttribute('forceLoad');
      extensions[name].forceLoad = ((typeof(forceLoad)=='string')?((forceLoad == 'true')?true:false):(false));
    }
    extensions[name].loaded = false;
  }
  OBJECT_MANAGER.setGuiValue('extensions',extensions);
  return(extensions);
};

FreeanceXMLParser.prototype.parseThemeDefinitions = function (newNode)
{
  var themeDefinitions = new Array();
  for (themeIndex=this.__helper__getNextElementNamedChildNode(newNode,0,"theme");themeIndex!=-1;themeIndex=this.__helper__getNextElementNamedChildNode(newNode,themeIndex+1,"theme"))
  {
    themeDefinitions[newNode.childNodes[themeIndex].getAttribute("id")] = this.parseTheme(newNode.childNodes[themeIndex]);
  }
  return themeDefinitions;
};

FreeanceXMLParser.prototype.parseTheme = function (themeNode)
{
  var themeAttributes = new Array();
  themeAttributes["id"] = themeNode.getAttribute("id");
  themeAttributes["hideTheme"] = themeNode.getAttribute("hideTheme");
  if (themeAttributes["hideTheme"] == null)
    themeAttributes["hideTheme"] = false;
  else
    themeAttributes["hideTheme"] = themeAttributes["hideTheme"] == 'true';
  
  themeAttributes["themeName"] = this.decodeSTRING(themeNode.childNodes[this.__helper__getNextElementNamedChildNode(themeNode,0,"themeName")]);
  if (this.__helper__getNextElementNamedChildNode(themeNode,0,"selectOptions")!=-1)
    themeAttributes["selectOptions"] = this.parseThemeSelectOptions(themeNode.childNodes[this.__helper__getNextElementNamedChildNode(themeNode,0,"selectOptions")]);
  else
    themeAttributes["selectOptions"] = null;
  if (this.__helper__getNextElementNamedChildNode(themeNode,0,"bufferOptions")!=-1)
    themeAttributes["bufferOptions"] = this.parseThemeBufferOptions(themeNode.childNodes[this.__helper__getNextElementNamedChildNode(themeNode,0,"bufferOptions")]);
  else
    themeAttributes["bufferOptions"] = null;
  themeAttributes["visibility"] = false;
  themeAttributes["altLegends"] = new Array();
  
  var altLegends = themeNode.getElementsByTagName('altLegend');
  for(var lcv=0;lcv < altLegends.length;lcv++)
  {
    var currentNode = altLegends[lcv];
    themeAttributes["altLegends"][lcv] = new Object;
    themeAttributes["altLegends"][lcv].legendName = this.decodeSTRING(currentNode.childNodes[this.__helper__getNextElementNamedChildNode(currentNode,0,"legendName")]);
    themeAttributes["altLegends"][lcv].legendLabel = this.decodeSTRING(currentNode.childNodes[this.__helper__getNextElementNamedChildNode(currentNode,0,"legendLabel")]);
  }
  return themeAttributes;
};

FreeanceXMLParser.prototype.parseThemeSelectOptions = function(newNode)
{
  var selectAttributes = new Array();
  selectAttributes["styleSheet"] = this.decodeSTRING(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"styleSheet")]);
  selectAttributes["fieldList"] = this.decodeSTRING(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"fieldList")]);
  selectAttributes["limit"] = this.decodeINT(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"limit")]);
  selectAttributes["tolerance"] = this.decodeDOUBLE(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"tolerance")]);
  selectAttributes["idField"] = this.decodeSTRING(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"idField")]);
  selectAttributes["keyField"] = this.decodeSTRING(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"keyField")]);
  var keyFieldTypeIndex = this.__helper__getNextElementNamedChildNode(newNode,0,"keyFieldType");
  selectAttributes["keyFieldType"] = ((keyFieldTypeIndex!=-1)?(this.decodeINT(newNode.childNodes[keyFieldTypeIndex])):(12));
  var zoomExtentRatioIndex = this.__helper__getNextElementNamedChildNode(newNode,0,"zoomExtentRatio");
  if (zoomExtentRatioIndex == -1)
    selectAttributes["zoomExtentRatio"] = 1.2;
  else
    selectAttributes["zoomExtentRatio"] = this.decodeDOUBLE(newNode.childNodes[zoomExtentRatioIndex]);
  selectAttributes["resultTemplate"] = this.decodeSTRING(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"resultTemplate")]);
  var sqlParamsIndex = this.__helper__getNextElementNamedChildNode(newNode,0,"sqlParams");
  if (sqlParamsIndex > -1)
    selectAttributes["sqlParams"] = this.parseChainedQuerySqlParams(newNode.childNodes[sqlParamsIndex]);
  else
    selectAttributes["sqlParams"] = null;
  return selectAttributes;
};

FreeanceXMLParser.prototype.parseChainedQuerySqlParams = function(sqlParamsNode)
{
  var sqlParams = new Array();
  var sqlParamNodeList = sqlParamsNode.getElementsByTagName('sqlParam');
  var numQueries = 0;
  for(var lcv=0;lcv < sqlParamNodeList.length;lcv++)
  {
    numQueries++;
    var theNode = sqlParamNodeList[lcv];
    sqlParams[lcv] = new Object;
    sqlParams[lcv]["pdqIdentifier"] = this.decodeSTRING(theNode.childNodes[this.__helper__getNextElementNamedChildNode(theNode,0,"pdqIdentifier")]);
    sqlParams[lcv]["fieldList"] = new Array();
    var fieldListNode = theNode.childNodes[this.__helper__getNextElementNamedChildNode(theNode,0,"fieldList")];
    var fieldNodeList = fieldListNode.getElementsByTagName('field');
    for(var fieldIndex=0;fieldIndex < fieldNodeList.length;fieldIndex++)
    {
      var fieldListIndex = sqlParams[lcv]["fieldList"].length;
      sqlParams[lcv]["fieldList"][fieldListIndex] = new Object();
      sqlParams[lcv]["fieldList"][fieldListIndex]["fieldName"] = this.decodeSTRING(fieldNodeList[fieldIndex].getElementsByTagName("fieldName")[0]);
      sqlParams[lcv]["fieldList"][fieldListIndex]["pdqFieldName"] = this.decodeSTRING(fieldNodeList[fieldIndex].getElementsByTagName("pdqFieldName")[0]);
    }
    if (this.__helper__getNextElementNamedChildNode(theNode,0,"queryType") > -1)
    {
      sqlParams[lcv]["queryType"] = this.decodeSTRING(theNode.childNodes[this.__helper__getNextElementNamedChildNode(theNode,0,"queryType")]);
      sqlParams[lcv]["numRows"]   = this.decodeINT(theNode.childNodes[this.__helper__getNextElementNamedChildNode(theNode,0,"numRows")]);
      sqlParams[lcv]["startAt"] = this.decodeINT(theNode.childNodes[this.__helper__getNextElementNamedChildNode(theNode,0,"startAt")]);
    }
    else  // do not want.  use full select instead
    {
      sqlParams[lcv]["queryType"] = '';
      sqlParams[lcv]["numRows"] = 0;
      sqlParams[lcv]["startAt"] = 0;
    }
  }
  if (numQueries == 0)
    sqlParams = null;
  return(sqlParams);
};

FreeanceXMLParser.prototype.parseThemeBufferOptions = function(newNode)
{
  var bufferAttributes = new Object;
  bufferAttributes["styleSheet"] = this.decodeSTRING(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"styleSheet")]);
  bufferAttributes["fieldList"] = this.decodeSTRING(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"fieldList")]);
  bufferAttributes["limit"] = this.decodeINT(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"limit")]);
  bufferAttributes["resultTemplate"] = this.decodeSTRING(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"resultTemplate")]);
  bufferAttributes["invalidTemplate"] = this.decodeSTRING(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"invalidTemplate")]);
  bufferAttributes["maxSelect"] = this.decodeINT(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"maxSelect")]);
  var sqlParamsIndex = this.__helper__getNextElementNamedChildNode(newNode,0,"sqlParams");
  if (sqlParamsIndex > -1)
    bufferAttributes["sqlParams"] = this.parseChainedQuerySqlParams(newNode.childNodes[sqlParamsIndex]);
  else
    bufferAttributes["sqlParams"] = null;
  if (this.__helper__getNextElementNamedChildNode(newNode,0,"filterQueries") != -1)
  {
    var queryListNode = newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"filterQueries")];
    bufferAttributes["filterQueries"] = new Object;
    for (var queryIndex = this.__helper__getNextElementNamedChildNode(queryListNode,0,"query");queryIndex!=-1;queryIndex=this.__helper__getNextElementNamedChildNode(queryListNode,queryIndex+1,"query"))
    {
      bufferAttributes["filterQueries"][this.decodeSTRING(queryListNode.childNodes[queryIndex])] = null;
    }
  }
  else
    bufferAttributes["filterQueries"] = null;
  if (this.__helper__getNextElementNamedChildNode(newNode,0,"export_csv")!=-1)
  {
    if (!bufferAttributes["export"])
      bufferAttributes["export"] = new Object;
    bufferAttributes["export"].csv = new Object;
    if(this.decodeSTRING(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"export_csv")]) == 'true')
    {
      bufferAttributes["export"].csv.enabled = true;
      bufferAttributes["export"].csv.delim = this.decodeSTRING(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"export_csv_delim")]);
      if(this.decodeSTRING(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"export_csv_includefieldnames")])=='true')
        bufferAttributes["export"].csv.includeFieldNames = true;
      else
        bufferAttributes["export"].csv.includeFieldNames = false;
    }
    else
      bufferAttributes["export"].csv.enabled = false;
  }
  return bufferAttributes;
};

FreeanceXMLParser.prototype.parseThemeGroupDefinitions = function (newNode)
{
  var themeGroupDefinitions = new Object();
  for(var groupIndex=this.__helper__getNextElementNamedChildNode(newNode,0,"themeGroup");groupIndex!=-1;groupIndex=this.__helper__getNextElementNamedChildNode(newNode,groupIndex+1,"themeGroup"))
  {
    var groupNode = newNode.childNodes[groupIndex];
    var groupNameIndex = this.__helper__getNextElementNamedChildNode(groupNode,0,"themeGroupName");
    if (groupNameIndex==-1)
      var groupName = String.escapeHTML(groupNode.getAttribute("name"));
    else
      var groupName = this.decodeSTRING(groupNode.childNodes[groupNameIndex]);
    themeGroupDefinitions[groupName] = new Array;
    for (var groupMemberIndex = this.__helper__getNextElementNamedChildNode(groupNode,0,"themeGroupMember");groupMemberIndex!=-1;groupMemberIndex=this.__helper__getNextElementNamedChildNode(groupNode,groupMemberIndex+1,"themeGroupMember"))
    {
      var groupMemberNode = groupNode.childNodes[groupMemberIndex];
      var groupMemberName = this.decodeSTRING(groupMemberNode);
      themeGroupDefinitions[groupName][groupMemberName] = groupMemberName;
    }
  }
  return themeGroupDefinitions;
};

FreeanceXMLParser.prototype.parseLegendAttributes = function (newNode)
{
  var legendAttributes = new Array();
  legendAttributes["width"] = this.getObjectRecurse(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"width")].childNodes[this.__helper__getNextElementNamedChildNode(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"width")],0,"value")]);
  legendAttributes["height"] = this.getObjectRecurse(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"height")].childNodes[this.__helper__getNextElementNamedChildNode(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"height")],0,"value")]);
  legendAttributes["color"] = this.getObjectRecurse(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"color")].childNodes[this.__helper__getNextElementNamedChildNode(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"color")],0,"value")]);
  legendAttributes["font"] = this.getObjectRecurse(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"font")].childNodes[this.__helper__getNextElementNamedChildNode(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"font")],0,"value")]);
  legendAttributes["fontSize"] = this.getObjectRecurse(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"fontSize")].childNodes[this.__helper__getNextElementNamedChildNode(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"fontSize")],0,"value")]);
  legendAttributes["valueFontSize"] = this.getObjectRecurse(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"valueFontSize")].childNodes[this.__helper__getNextElementNamedChildNode(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"valueFontSize")],0,"value")]);
  legendAttributes["cellSpacing"] = this.getObjectRecurse(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"cellSpacing")].childNodes[this.__helper__getNextElementNamedChildNode(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"cellSpacing")],0,"value")]);
  return legendAttributes;
};

FreeanceXMLParser.prototype.parseMapExportConfig = function(newNode)
{
  var exportConfig = new Object;
  exportConfig.enabled = newNode.getAttribute('enabled');
  return exportConfig;
};

FreeanceXMLParser.prototype.parsePdfPrintConfig = function (newNode)
{
  var printConfig = new Object;
  printConfig.templates = new Array;
  printConfig.defaultTemplate = parseInt(newNode.getAttribute('defaultTemplate'));
  for(var templateIndex=this.__helper__getNextElementNamedChildNode(newNode,0,"template");templateIndex!=-1;templateIndex=this.__helper__getNextElementNamedChildNode(newNode,templateIndex+1,"template"))
  {
    var templateNode = newNode.childNodes[templateIndex];
    var template = new Object;
    template.displayName = this.decodeSTRING(templateNode.childNodes[this.__helper__getNextElementNamedChildNode(templateNode,0,"displayname")]);
    template.templateName = this.decodeSTRING(templateNode.childNodes[this.__helper__getNextElementNamedChildNode(templateNode,0,"templatename")]);
    template.orientation = templateNode.getAttribute('orientation');
    template.unit = templateNode.getAttribute('unit');
    template.width = parseFloat(templateNode.getAttribute('width'));
    template.height = parseFloat(templateNode.getAttribute('height'));
    printConfig.templates[printConfig.templates.length] = template;
  }
  if ((printConfig.templates.length > 0)&&(printConfig.defaultTemplate==-1))
    printConfig.defaultTemplate = 0;
  if (printConfig.templates.length==0)
    printConfig.defaultTemplate = -1;
  printConfig.activeTemplate = printConfig.defaultTemplate;
  return printConfig;
};

FreeanceXMLParser.prototype.parseMapPrintConfig = function (newNode)
{
  var printConfig = new Object;
  //check for old style templates
  if (this.__helper__getNextElementNamedChildNode(newNode,0,"layoutName")!=-1)
    printConfig["layoutName"] = this.decodeSTRING(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"layoutName")]);
  else
    if (this.__helper__getNextElementNamedChildNode(newNode,0,"templateName")!=-1)
      printConfig["layoutName"] = this.decodeSTRING(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"templateName")]);
    else
      printConfig["layoutName"] = 'Invalid Print Configuration';

  if (this.__helper__getNextElementNamedChildNode(newNode,0,"templateName")!=-1)
    printConfig["templateName"] = this.decodeSTRING(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"templateName")]);
  else
    printConfig["templateName"] = null;
  
  //check for new style templates
  if (this.__helper__getNextElementNamedChildNode(newNode,0,"templateContent")!=-1)
    printConfig["templateContent"] = this.decodeSTRING(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"templateContent")]);
  else
    printConfig["templateContent"] = null;
  
  if (this.__helper__getNextElementNamedChildNode(newNode,0,"mapSize")!=-1)
  {
    printConfig["mapSize"] = new Object;
    var mapSizeNode = newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"mapSize")];
    printConfig["mapSize"]["width"] = this.getObjectRecurse(mapSizeNode.childNodes[this.__helper__getNextElementNamedChildNode(mapSizeNode,0,"width")]);
    printConfig["mapSize"]["height"] = this.getObjectRecurse(mapSizeNode.childNodes[this.__helper__getNextElementNamedChildNode(mapSizeNode,0,"height")]);
  }
  
  if (this.__helper__getNextElementNamedChildNode(newNode,0,"pageOrientation")!=-1)
    printConfig["pageOrientation"] = this.decodeSTRING(newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"pageOrientation")]);
  else
    printConfig["pageOrientation"] = 'portrait';

  printConfig["pageSize"] = new Object();
  if (this.__helper__getNextElementNamedChildNode(newNode,0,"pageSize")!=-1)
  {
    var pageSizeNode = newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"pageSize")];
    printConfig["pageSize"]["width"] = this.getObjectRecurse(pageSizeNode.childNodes[this.__helper__getNextElementNamedChildNode(pageSizeNode,0,"width")]);
    printConfig["pageSize"]["height"] = this.getObjectRecurse(pageSizeNode.childNodes[this.__helper__getNextElementNamedChildNode(pageSizeNode,0,"height")]);
  }
  else
  {
    printConfig["pageSize"]["width"] = 8.5;
    printConfig["pageSize"]["height"] = 11;
  }
  
  if (this.__helper__getNextElementNamedChildNode(newNode,0,"vmapSize")!=-1)
  {
    printConfig["vmapSize"] = new Object;
    var vmapSizeNode = newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"vmapSize")];
    printConfig["vmapSize"]["width"] = this.getObjectRecurse(vmapSizeNode.childNodes[this.__helper__getNextElementNamedChildNode(vmapSizeNode,0,"width")]);
    printConfig["vmapSize"]["height"] = this.getObjectRecurse(vmapSizeNode.childNodes[this.__helper__getNextElementNamedChildNode(vmapSizeNode,0,"height")]);
  }
  if (this.__helper__getNextElementNamedChildNode(newNode,0,"legendSize")!=-1)
  {
    printConfig["legendSize"] = new Object;
    var legendSizeNode = newNode.childNodes[this.__helper__getNextElementNamedChildNode(newNode,0,"legendSize")];
    printConfig["legendSize"]["width"] = this.getObjectRecurse(legendSizeNode.childNodes[this.__helper__getNextElementNamedChildNode(legendSizeNode,0,"width")]);
    printConfig["legendSize"]["height"] = this.getObjectRecurse(legendSizeNode.childNodes[this.__helper__getNextElementNamedChildNode(legendSizeNode,0,"height")]);
  }
  
  return printConfig;
};

FreeanceXMLParser.prototype.parseLabelConfig = function (newNode)
{
  var labelConfig = new Object;
  labelConfig["pointLabels"] = new Object;
  for(var labelIndex=this.__helper__getNextElementNamedChildNode(newNode,0,"pointLabel");labelIndex!=-1;labelIndex=this.__helper__getNextElementNamedChildNode(newNode,labelIndex+1,"pointLabel"))
  {
    var currentNode = newNode.childNodes[labelIndex];
    var nameIndex = this.__helper__getNextElementNamedChildNode(currentNode,0,'labelName');
    if (nameIndex==-1)
      var labelId = currentNode.getAttribute("id");
    else
      var labelId = this.decodeSTRING(currentNode.childNodes[nameIndex]);
    labelConfig.pointLabels[labelId] = new Object;
    labelConfig.pointLabels[labelId].styleSheet = this.decodeSTRING(currentNode.childNodes[this.__helper__getNextElementNamedChildNode(currentNode,0,"styleSheet")]);
    labelConfig.pointLabels[labelId].sampleURL = this.decodeSTRING(currentNode.childNodes[this.__helper__getNextElementNamedChildNode(currentNode,0,"sampleURL")]);
    labelConfig.pointLabels[labelId].description = this.decodeSTRING(currentNode.childNodes[this.__helper__getNextElementNamedChildNode(currentNode,0,"description")]);
    if (this.__helper__getNextElementNamedChildNode(currentNode,0,"hidden")!=-1)
      labelConfig.pointLabels[labelId].hidden = (this.decodeSTRING(currentNode.childNodes[this.__helper__getNextElementNamedChildNode(currentNode,0,"hidden")])=='true');
    else
      labelConfig.pointLabels[labelId].hidden = false;
  }
  labelConfig["textLabels"] = new Object;
  for(var labelIndex=this.__helper__getNextElementNamedChildNode(newNode,0,"textLabel");labelIndex!=-1;labelIndex=this.__helper__getNextElementNamedChildNode(newNode,labelIndex+1,"textLabel"))
  {
    var currentNode = newNode.childNodes[labelIndex];
    var nameIndex = this.__helper__getNextElementNamedChildNode(currentNode,0,'labelName');
    if (nameIndex==-1)
      var labelId = currentNode.getAttribute("id");
    else
      var labelId = this.decodeSTRING(currentNode.childNodes[nameIndex]);
    labelConfig.textLabels[labelId] = new Object;
    labelConfig.textLabels[labelId].styleSheet = this.decodeSTRING(currentNode.childNodes[this.__helper__getNextElementNamedChildNode(currentNode,0,"styleSheet")]);
    labelConfig.textLabels[labelId].sampleCSS  = this.decodeSTRING(currentNode.childNodes[this.__helper__getNextElementNamedChildNode(currentNode,0,"sampleCSS")]);
    labelConfig.textLabels[labelId].sampleText = this.decodeSTRING(currentNode.childNodes[this.__helper__getNextElementNamedChildNode(currentNode,0,"sampleText")]);
    if (this.__helper__getNextElementNamedChildNode(currentNode,0,"hidden")!=-1)
      labelConfig.textLabels[labelId].hidden = (this.decodeSTRING(currentNode.childNodes[this.__helper__getNextElementNamedChildNode(currentNode,0,"hidden")])=='true');
    else
      labelConfig.textLabels[labelId].hidden = false;
  }
  labelConfig["lineLabels"] = new Object;
  for(var labelIndex=this.__helper__getNextElementNamedChildNode(newNode,0,"lineLabel");labelIndex!=-1;labelIndex=this.__helper__getNextElementNamedChildNode(newNode,labelIndex+1,"lineLabel"))
  {
    var currentNode = newNode.childNodes[labelIndex];
    var nameIndex = this.__helper__getNextElementNamedChildNode(currentNode,0,'labelName');
    if (nameIndex==-1)
      var labelId = currentNode.getAttribute("id");
    else
      var labelId = this.decodeSTRING(currentNode.childNodes[nameIndex]);
    labelConfig.lineLabels[labelId] = new Object;
    labelConfig.lineLabels[labelId].styleSheet = this.decodeSTRING(currentNode.childNodes[this.__helper__getNextElementNamedChildNode(currentNode,0,"styleSheet")]);
    labelConfig.lineLabels[labelId].color = this.decodeSTRING(currentNode.childNodes[this.__helper__getNextElementNamedChildNode(currentNode,0,"color")]);
    labelConfig.lineLabels[labelId].thickness = this.decodeSTRING(currentNode.childNodes[this.__helper__getNextElementNamedChildNode(currentNode,0,"thickness")]);
    labelConfig.lineLabels[labelId].description = this.decodeSTRING(currentNode.childNodes[this.__helper__getNextElementNamedChildNode(currentNode,0,"description")]);
    if (this.__helper__getNextElementNamedChildNode(currentNode,0,"hidden")!=-1)
      labelConfig.lineLabels[labelId].hidden = (this.decodeSTRING(currentNode.childNodes[this.__helper__getNextElementNamedChildNode(currentNode,0,"hidden")])=='true');
    else
      labelConfig.lineLabels[labelId].hidden = false;
  }
  return labelConfig;
};

FreeanceXMLParser.prototype.parseMapLoginQuery = function(queryNode)
{
  var definedQueryNode = queryNode.childNodes[this.__helper__getNextElementNamedChildNode(queryNode,0,"definedQuery")];
  return this.parseDefinedQuery(definedQueryNode);
};

FreeanceXMLParser.prototype.parseQueryGroup = function(groupNode)
{
  var groupId = groupNode.getAttribute("id");
  var queryGroup = new Array;
  var queryIndex = 0;
  for (var childIndex=this.__helper__getNextElementNamedChildNode(groupNode,0,"query");childIndex!=-1;childIndex=this.__helper__getNextElementNamedChildNode(groupNode,childIndex+1,"query"))
  {
    queryGroup[queryIndex] = this.decodeSTRING(groupNode.childNodes[childIndex]);
    queryIndex++;  
  }
  OBJECT_MANAGER.setGuiValue(groupId, queryGroup);
  return queryGroup;
};

FreeanceXMLParser.prototype.parseQueryConfig = function(queryRootNode)
{
  var queries = new Object();
  var htmlString = '';
  for (var queryIndex = this.__helper__getNextElementNamedChildNode(queryRootNode,0,"definedQuery");queryIndex!=-1;queryIndex=this.__helper__getNextElementNamedChildNode(queryRootNode,queryIndex+1,"definedQuery"))
  {
    var currentQuery = queryRootNode.childNodes[queryIndex];
    queries[currentQuery.getAttribute("id")] = this.parseDefinedQuery(currentQuery);
  }
  OBJECT_MANAGER.setGuiValue('queries', queries);
  return queries;
};

FreeanceXMLParser.prototype.parseDefinedQuery = function(queryNode)
{
  var queryConfig = new Object();
  var requestNode = queryNode.childNodes[this.__helper__getNextElementNamedChildNode(queryNode,0,"request")];
  var fieldsNode = queryNode.childNodes[this.__helper__getNextElementNamedChildNode(queryNode,0,"fieldList")];
  queryConfig["id"] = queryNode.getAttribute("id");
  queryConfig["description"] = this.decodeSTRING(queryNode.childNodes[this.__helper__getNextElementNamedChildNode(queryNode,0,"description")]);
  if (this.__helper__getNextElementNamedChildNode(queryNode,0,"display")!=-1)
    queryConfig["display"] = (this.decodeSTRING(queryNode.childNodes[this.__helper__getNextElementNamedChildNode(queryNode,0,"display")])=='true');
  else
    queryConfig["display"] = true;
  if (this.__helper__getNextElementNamedChildNode(queryNode,0,"title") != -1)
    queryConfig["title"] = this.decodeSTRING(queryNode.childNodes[this.__helper__getNextElementNamedChildNode(queryNode,0,"title")]);
  else
    queryConfig["title"] = queryConfig["description"];
  if (this.__helper__getNextElementNamedChildNode(queryNode,0,"HTMLForm") != -1)
    queryConfig["HTMLForm"] = this.decodeSTRING(queryNode.childNodes[this.__helper__getNextElementNamedChildNode(queryNode,0,"HTMLForm")]);
  else
    queryConfig["title"] = "Query Form Not Defined";
  queryConfig["request"] = new Object;
  queryConfig["request"]["requestMethod"] = this.decodeSTRING(requestNode.childNodes[this.__helper__getNextElementNamedChildNode(requestNode,0,"requestMethod")]);
  queryConfig["request"]["pdqIdentifier"] = this.decodeSTRING(requestNode.childNodes[this.__helper__getNextElementNamedChildNode(requestNode,0,"pdqIdentifier")]);
  var dbtypeIndex = this.__helper__getNextElementNamedChildNode(requestNode,0,"dbtype");
  if (dbtypeIndex==-1)
    queryConfig["request"]["dbtype"] = '';
  else
    queryConfig["request"]["dbtype"] = this.decodeSTRING(requestNode.childNodes[dbtypeIndex]);
  queryConfig["fieldList"] = this.parseQueryFields(fieldsNode);
  if (this.__helper__getNextElementNamedChildNode(queryNode,0,"exportQuery")!=-1)
  {
    queryConfig["export"] = new Object;
    var exportQueryNode = queryNode.childNodes[this.__helper__getNextElementNamedChildNode(queryNode,0,"exportQuery")];
    if (this.__helper__getNextElementNamedChildNode(exportQueryNode,0,"export_csv")!=-1)
    {
      queryConfig["export"].csv = new Object;
      if(this.decodeSTRING(exportQueryNode.childNodes[this.__helper__getNextElementNamedChildNode(exportQueryNode,0,"export_csv")]) == 'true')
      {
        queryConfig["export"].csv.enabled = true;
        queryConfig["export"].csv.delim = this.decodeSTRING(exportQueryNode.childNodes[this.__helper__getNextElementNamedChildNode(exportQueryNode,0,"export_csv_delim")]);
        if(this.decodeSTRING(exportQueryNode.childNodes[this.__helper__getNextElementNamedChildNode(exportQueryNode,0,"export_csv_includefieldnames")])=='true')
          queryConfig["export"].csv.includeFieldNames = true;
        else
          queryConfig["export"].csv.includeFieldNames = false;
      }
      else
        queryConfig["export"].csv.enabled = false;
    }
    if (this.__helper__getNextElementNamedChildNode(exportQueryNode,0,"export_xml")!=-1)
    {
      queryConfig["export"].xml = new Object;
      if(this.decodeSTRING(exportQueryNode.childNodes[this.__helper__getNextElementNamedChildNode(exportQueryNode,0,"export_xml")]) == 'true')
        queryConfig["export"].xml.enabled = true;
      else
        queryConfig["export"].xml.enabled = false;
    }
  }
  if (this.__helper__getNextElementNamedChildNode(queryNode,0,"resultTemplates")!=-1)
  {
    var templateNode = queryNode.childNodes[this.__helper__getNextElementNamedChildNode(queryNode,0,"resultTemplates")];
    queryConfig["templates"] = new Object;
    if (this.__helper__getNextElementNamedChildNode(templateNode,0,"validTemplate")!=-1)
      queryConfig["templates"]["validTemplate"] = this.decodeSTRING(templateNode.childNodes[this.__helper__getNextElementNamedChildNode(templateNode,0,"validTemplate")]);
    else
      queryConfig["templates"]["validTemplate"] = null;
    if (this.__helper__getNextElementNamedChildNode(templateNode,0,"invalidTemplate")!=-1)
      queryConfig["templates"]["invalidTemplate"] = this.decodeSTRING(templateNode.childNodes[this.__helper__getNextElementNamedChildNode(templateNode,0,"invalidTemplate")]);
    else
      queryConfig["templates"]["invalidTemplate"] = null;
    if (this.__helper__getNextElementNamedChildNode(templateNode,0,"emptyTemplate")!=-1)
      queryConfig["templates"]["emptyTemplate"] = this.decodeSTRING(templateNode.childNodes[this.__helper__getNextElementNamedChildNode(templateNode,0,"emptyTemplate")]);
    else
      queryConfig["templates"]["emptyTemplate"] = null;
    if (this.__helper__getNextElementNamedChildNode(templateNode,0,"pageRows")!=-1)
      queryConfig["templates"]["pageRows"] = this.decodeINT(templateNode.childNodes[this.__helper__getNextElementNamedChildNode(templateNode,0,"pageRows")]);
    else
      queryConfig["templates"]["pageRows"] = null;
  }
  else
    queryConfig["templates"] = null;
  var suggestNodeIndex = this.__helper__getNextElementNamedChildNode(queryNode,0,"suggestConfig");
  if (suggestNodeIndex!=-1)
  {
    suggestNode = queryNode.childNodes[suggestNodeIndex];
    queryConfig["suggestConfig"] = new Array();
    var configIndex = 0;
    for (suggestNodeIndex=this.__helper__getNextElementNamedChildNode(suggestNode,0,"suggestInput");
         suggestNodeIndex!=-1;
         suggestNodeIndex=this.__helper__getNextElementNamedChildNode(suggestNode,suggestNodeIndex+1,"suggestInput"))
    {
      suggestNodeElement = suggestNode.childNodes[suggestNodeIndex];
      queryConfig.suggestConfig[configIndex]=new Object;
      queryConfig.suggestConfig[configIndex].pdqfield=suggestNodeElement.getAttribute('pdqfield');
      queryConfig.suggestConfig[configIndex].elementId=suggestNodeElement.getAttribute('elementId');
      queryConfig.suggestConfig[configIndex].resultElementId=suggestNodeElement.getAttribute('resultElementId');
      queryConfig.suggestConfig[configIndex].timeout=parseInt(suggestNodeElement.getAttribute('timeout'));
      queryConfig.suggestConfig[configIndex].dbid=suggestNodeElement.getAttribute('dbid');
      queryConfig.suggestConfig[configIndex].tablename=suggestNodeElement.getAttribute('tablename');
      queryConfig.suggestConfig[configIndex].fieldname=suggestNodeElement.getAttribute('fieldname');
      queryConfig.suggestConfig[configIndex].resultlimit=parseInt(suggestNodeElement.getAttribute('resultlimit'));
      configIndex++;
    }
  }
  else
    queryConfig["suggestConfig"] = null;
  return queryConfig;
};

FreeanceXMLParser.prototype.parseQueryFields = function(fieldsNode)
{
  var fieldsConfig = new Object;

  for (var fieldIndex=this.__helper__getNextElementChildNode(fieldsNode,0);fieldIndex!=-1;fieldIndex=this.__helper__getNextElementChildNode(fieldsNode,fieldIndex+1))
  {
    var currentNode = fieldsNode.childNodes[fieldIndex];
    var currentField = currentNode.getAttribute("id");
    fieldsConfig[currentField] = new Object;
    fieldsConfig[currentField].fieldType = currentNode.nodeName;
    switch (currentNode.nodeName)
    {
      case 'labelField':
        fieldsConfig[currentField].value = this.decodeSTRING(currentNode);
        break;
      case 'textField':
        if (this.__helper__getNextElementNamedChildNode(currentNode,0,"caption") != -1)
          fieldsConfig[currentField].caption = this.decodeSTRING(currentNode.childNodes[this.__helper__getNextElementNamedChildNode(currentNode,0,"caption")]);
        else
          fieldsConfig[currentField].caption = null;
        if (this.__helper__getNextElementNamedChildNode(currentNode,0,"fieldName") != -1)
          fieldsConfig[currentField].fieldName = this.decodeSTRING(currentNode.childNodes[this.__helper__getNextElementNamedChildNode(currentNode,0,"fieldName")]);
        else
          fieldsConfig[currentField].fieldName = null;
        if (this.__helper__getNextElementNamedChildNode(currentNode,0,"width") != -1)
          fieldsConfig[currentField].width = this.decodeSTRING(currentNode.childNodes[this.__helper__getNextElementNamedChildNode(currentNode,0,"width")]);
        else
          fieldsConfig[currentField].width = null;
        if (this.__helper__getNextElementNamedChildNode(currentNode,0,"defaultValue") != -1)
          fieldsConfig[currentField].defaultValue = this.decodeSTRING(currentNode.childNodes[this.__helper__getNextElementNamedChildNode(currentNode,0,"defaultValue")]);
        else
          fieldsConfig[currentField].defaultValue = '';
        if (this.__helper__getNextElementNamedChildNode(currentNode,0,"initialValue") != -1)
          fieldsConfig[currentField].initialValue = this.decodeSTRING(currentNode.childNodes[this.__helper__getNextElementNamedChildNode(currentNode,0,"initialValue")]);
        else
          fieldsConfig[currentField].initialValue = '';
        break;
      case 'selectField':
        if (this.__helper__getNextElementNamedChildNode(currentNode,0,"caption") != -1)
          fieldsConfig[currentField].caption = this.decodeSTRING(currentNode.childNodes[this.__helper__getNextElementNamedChildNode(currentNode,0,"caption")]);
        else
          fieldsConfig[currentField].caption = null;
        if (this.__helper__getNextElementNamedChildNode(currentNode,0,"fieldName") != -1)
          fieldsConfig[currentField].fieldName = this.decodeSTRING(currentNode.childNodes[this.__helper__getNextElementNamedChildNode(currentNode,0,"fieldName")]);
        else
          fieldsConfig[currentField].fieldName = null;
        if (this.__helper__getNextElementNamedChildNode(currentNode,0,"default") != -1)
        {
          fieldsConfig[currentField].defaultValue = this.decodeSTRING(currentNode.childNodes[this.__helper__getNextElementNamedChildNode(currentNode,0,"default")]);
        }
        else
          fieldsConfig[currentField].defaultValue = '';
        if (this.__helper__getNextElementNamedChildNode(currentNode,0,"optionList") != -1)
        {
          fieldsConfig[currentField].optionList = this.parseOptionList(currentNode.childNodes[this.__helper__getNextElementNamedChildNode(currentNode,0,"optionList")]);
        }
        else
          fieldsConfig[currentField].optionList = null;
        break;
      case 'hiddenField':
        break;
      default:
        alert('Unknown query field type: '+currentNode.nodeName);
        break;
    }
  }
  return fieldsConfig;
};

FreeanceXMLParser.prototype.parseOptionList = function(listParentNode)
{
  var optionList = new Array();
  var optionArrayIndex = 0;
  for (var optionIndex=this.__helper__getNextElementChildNode(listParentNode,0);optionIndex!=-1;optionIndex=this.__helper__getNextElementChildNode(listParentNode,optionIndex+1))
  {
    var currentNode = listParentNode.childNodes[optionIndex];
    switch (currentNode.nodeName)
    {
      case 'option':
        optionList[optionArrayIndex] = new Object;
        optionList[optionArrayIndex].type = 'option';
        optionList[optionArrayIndex].value = currentNode.getAttribute("value");
        optionList[optionArrayIndex].description = this.decodeSTRING(currentNode);
        break;
      case 'optgroup':
        optionList[optionArrayIndex] = new Object;
        optionList[optionArrayIndex].type = 'optgroup';
        optionList[optionArrayIndex].description = currentNode.getAttribute("label");
        optionList[optionArrayIndex].value = this.parseOptionList(currentNode);
        break;
      default:
        break;
    }
    optionArrayIndex++;
  }
  return optionList;
};

FreeanceXMLParser.prototype.parseCoordConvConfig = function(configNode)
{
  var config = null;
  if (configNode != null)
  {
    config = new Array();
    config.SP2LL_StatePlaneID = this.decodeSTRING(configNode.childNodes[this.__helper__getNextElementNamedChildNode(configNode,0,'SP2LL_StatePlaneID')]);
    config.SP2LL_DatumID = this.decodeSTRING(configNode.childNodes[this.__helper__getNextElementNamedChildNode(configNode,0,'SP2LL_DatumID')]);
  }
  OBJECT_MANAGER.setGuiValue('CoordConvConfig',config);
  return (config);
};

FreeanceXMLParser.prototype.parseMeasureConfig = function(configNode)
{
  var config = null;
  if (configNode != null)
  {
    config = new Array();
    config.distanceSourceUnits = this.decodeSTRING(configNode.childNodes[this.__helper__getNextElementNamedChildNode(configNode,0,'distanceSourceUnits')]);
    config.distanceMeasureUnits = this.decodeSTRING(configNode.childNodes[this.__helper__getNextElementNamedChildNode(configNode,0,'distanceMeasureUnits')]);
    config.distanceColor = this.decodeSTRING(configNode.childNodes[this.__helper__getNextElementNamedChildNode(configNode,0,'distanceColor')]);
    config.distanceThickness = this.decodeSTRING(configNode.childNodes[this.__helper__getNextElementNamedChildNode(configNode,0,'distanceThickness')]);
  }
  OBJECT_MANAGER.setGuiValue('MeasureConfig',config);
  return (config);
};

