function createXMLHttpRequest() {
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    }
}
function addSelect(sid,elementID) {
    //不用var声明变量，并将其最先执行，该变量就具有了全局性
    oElement = document.getElementById(elementID);
    //ddz=document.getElementById("ddZip");
    //ddc=document.getElementById("ddCode");
    youwww=document.getElementById("selectB");
    initSelect(oElement);
    initSelect(youwww);
    
    if(elementID=="selectA"){
        youwww.options[0].innerHTML="--------";
    }
    
    if(sid==""){
        oElement.options[0].innerHTML="--------";
    }else{
        
        createXMLHttpRequest();
        var url = "/inc/GetClass.asp?sid="+sid;
        /*当准备状态改变时，需要为readyState属性指定事件处理函数，该处理函数有两种传递参数的方法：
        xmlhttp.onreadystatechange= function(){HandleStateChange(param1,param2...)}; 或者  
        xmlhttp.onreadystatechange=new Function("HandleStateChange(param1,param2...)"); 
        */
        xmlHttp.onreadystatechange = function(){onStateChange(oElement,youwww)};
        xmlHttp.open("GET", url, true);
        xmlHttp.send(null);
    }
}
function onStateChange(oElement) {
    if(xmlHttp.readyState == 4) {
        if(xmlHttp.status == 200) {
            showSelect(xmlHttp.responseXML);
        }
    }
}
function showSelect(xmlData) {
    if(xmlData.documentElement.hasChildNodes()){
        oElement.options[0].innerHTML="-请选择-";
    }else{
        oElement.options[0].innerHTML="None";
        youwww.options[0].innerHTML="None";
    }
    var names = xmlData.getElementsByTagName("Name");
    var ids = xmlData.getElementsByTagName("Value");
    for(var i = 0; i < names.length; i++) {
        var op=new Option(names[i].firstChild.nodeValue);  
        //为列表/菜单添加选项时，object.options.add方法比object.appendChild方法更适用。   
        oElement.options.add(op);
	    op.value=ids[i].firstChild.nodeValue;
    }
}

function initSelect(oElement) {
    while(oElement.options.length > 0) {
        oElement.remove(oElement.options.length-1);
    }
    var op=new Option("Loading...");        
    oElement.options.add(op);
    op.value="";
}