
function loadXMLDocument( xmlPath, callBack )
{
  var httpRequest = null;
  if( typeof XMLHttpRequest != 'undefined' ) { httpRequest = new XMLHttpRequest(); }
  else if( typeof ActiveXObject != 'undefined' )
  {
    /*@cc_on @*/
    /*@if(@_jscript_version >= 5)
    try { httpRequest = new ActiveXObject( 'Microsoft.XMLHTTP' ); }
    catch( e ) { }
    @end @*/  
  }
  if( httpRequest != null )
  {
    // synchronous - this way, the remaining code will not be run until the XML is fully loaded
    httpRequest.open( 'GET', xmlPath, false );
    httpRequest.send( null );
    callBack( httpRequest.responseXML );
  }  
}



/* cross browser method to find all values of a specific tag in the XML DOM
 * nodePath is a '/' separated path of nodes within the DOM tree; can be N levels deep.  
 * attribute is an optional parameter to retrieve the attribute of the target tag - currently, only 1 attribute is allowed to be retrieved (change later if ever a need)
 * attributeFilters and attributeFilterValues can filter out nodes that don't have the matching attribute values - number of filters should match number of nodes
 * Unfortunately, using xmlDocument.getElementsByTagName( 'gameTypeList/gameType' ) is only allowed in IE 
 */

var leafAttribute;              // optional attribute to be collected from leaf tag

var filterData = false;
var filters, filterValues;

var values,
    valuesIndex;
var nodes,
    nodesIndex,
    filterIndex;

function getNodeValues( xmlDocument, nodePath, attribute, attributeFilters, attributeFilterValues )
{
  if( attributeFilters != null )
  {
    filterData = true;
    filters = attributeFilters.split( '/' );
    filterValues = attributeFilterValues.split( '/' );        
  }
  
  leafAttribute = attribute;
  
  values = new Array();  
  valuesIndex = 0;

  nodes = nodePath.split( '/' );
  nodesIndex = 1;                                                         // skip the first node since it is the root and will be found by getElementsByTagName
  filterIndex = -1;                                                       // this will be incremented at the beginning of every recursive call, and decrememted at the end of the recursive call
  
  var nodeBranches = xmlDocument.getElementsByTagName( nodes[ 0 ] );      // get all instances of root node (array)  
  
  // for every pass, we will try to find the child in the nodePath
  for( i = 0; i < nodeBranches.length; i++ ) { traverse( nodeBranches[ i ] ); }
  
  return values;
}

    
function traverse( node )                  // recursive function
{
  filterIndex++;
  
  if( filterData && ( node.getAttribute( filters[ filterIndex ] ) != filterValues[ filterIndex ] ) ) { filterIndex--; return; }
  
  filterIndex++;
  
  for( var i = 0; i < node.childNodes.length; i++ )
  { 
    if( node.childNodes[ i ].tagName == nodes[ nodesIndex ] )       // is this the tag we're looking for?
    {
      // check for filter
      if( filterData && ( node.childNodes[ i ].getAttribute( filters[ filterIndex ] ) != filterValues[ filterIndex ] ) ) { filterIndex--; return; }

      // match found - now see if we should pick up the data or further traverse
      if( nodesIndex == ( nodes.length - 1 ) )
      {        
          if( leafAttribute != null ) 
          {
            values[ valuesIndex ] = new Array( 2 );
            if( node.childNodes[ i ].firstChild ) values[ valuesIndex ][ 0 ] = node.childNodes[ i ].firstChild.nodeValue;
            values[ valuesIndex ][ 1 ] = node.childNodes[ i ].getAttribute( leafAttribute );            
          }
          else values[ valuesIndex ] = node.childNodes[ i ].firstChild.nodeValue;
          
          valuesIndex++;
      }
      else
      {
        nodesIndex++;
        traverse( node.childNodes[ i ] );     // recursive call
      }
    }    
  }
  
  filterIndex--;
}
