var req;
var url;
var obj;
var nextDefaultValue;

function getXmlHttpRequest(){
       if(window.ActiveXObject){
            var ieArr=["Microsoft.XMLHTTP","MSXML2.XMLHTTP","Msxml2.XMLHTTP.6.0","MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP.2.6"];                
            for(var i=0;i<ieArr.length;i++){
                try{
                	var xmlhttp= new ActiveXObject(ieArr[i]);
                	break;
                }catch(e){
                }
            }
            return xmlhttp;
       } else if(window.XMLHttpRequest){
            return new XMLHttpRequest();
       }            
}

function init() {
	req=getXmlHttpRequest();
	var url = "http://jdxx.zhs.mofcom.gov.cn/ajax";
	req.open("POST", url, true);
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
}

function sel_pro(curr,next,nextValue,alone) {
	init();
	var currObj = document.getElementById(curr);
	var index = currObj.selectedIndex;
	var val = currObj.options[index].value;
	
	obj = document.getElementById(next);
	nextDefaultValue=nextValue;
	req.onreadystatechange = provincesHandler;	
	req.send("par_index=" + val + "&alone="+alone);
}

function provincesHandler() {
	if (req.readyState == 4) {
		if (req.status == 200) {
		try{
			var xmlDoc=req.responseXML.documentElement;
			var xSel=xmlDoc.getElementsByTagName('select');
			obj.options.length=1;
			for(var i=0;i<xSel.length;i++){
			    var xValue=xSel[i].childNodes[0].firstChild.nodeValue;
			    var xText=xSel[i].childNodes[1].firstChild.nodeValue;
			    var option=new Option(xText,xValue);
			    
			    obj.options.add(option);
			}
			if(nextDefaultValue!=null&&nextDefaultValue!='')
			{
				for(i=0; i < obj.length; i++){
					if(obj.options[i].value==nextDefaultValue){
				      obj.options[i].selected=true;
					  break;
					}
				}
			}
	        obj.onchange();
	       }catch(e){
	       }
		}
	}
}

