
var xmldoc=new ActiveXObject("MSXML2.DOMDocument");
xmldoc.async=false;

xmldoc.load("js/PlaceContinueChange.xml");
//-----------------------
//根据xml查询语句返回数组
//-----------------------
function getArray( doc, path )
{
  var array = new Array();
  var nodes = doc.selectSingleNode(path).childNodes;
  for( var j=0;j<nodes.length;j++ )
  {
    var node=nodes[j];
    array.push(node.getAttribute('name'));
  }
  return array;
}

//-----------------------
//      初始化下拉框
//-----------------------
function initSelected( provinceID,cityID )
{
   var pDrop =  document.getElementById(provinceID);
   for( var i=0;i<pDrop.options.length;i++ )
   {
       pDrop.options[i] = null;
   }
   var array = getArray(xmldoc,"/Place/Country[@name='中国']");
   for( var i=0;i<array.length;i++ )
   {
      if( i==0 )
         pDrop.options[i] = new Option(array[i],"");
      else
         pDrop.options[i] = new Option(array[i],array[i]);
   }
   pDrop.options[0].selected = true;
   var cDrop = document.getElementById(cityID);
   for( var i=0;i<cDrop.options.length;i++ )
   {
       cDrop.options[i] = null;
   }
   var arrayCity = getArray(xmldoc,"/Place/Country[@name='中国']/Province[@name='请选择省份']");
   for( var i=0;i<arrayCity.length;i++ )
   {
      if( i==0 )
         cDrop.options[i] = new Option(arrayCity[i],"");
      else
         cDrop.options[i] = new Option(arrayCity[i],arrayCity[i]);
   }
   cDrop.options[0].selected = true;
   pDrop.onchange = function(){provinceChange(provinceID,cityID)};
}

//-----------------------
//更改省份相应城市也改变
//-----------------------
function provinceChange( provinceID,cityID )
{
   var pDrop = document.getElementById(provinceID);
   var cDrop = document.getElementById(cityID);
   var arrayCity = getArray(xmldoc,"/Place/Country[@name='中国']/Province[@name='"+pDrop.value+"']");
   for( var i=0;i<cDrop.options.length;i++ )
   {
       cDrop.options[i] = null;
   }
   for( var i=0;i<arrayCity.length;i++ )
   {
      if( i==0 )
         cDrop.options[i] = new Option(arrayCity[i],"");
      else
         cDrop.options[i] = new Option(arrayCity[i],arrayCity[i]);
   }
}