﻿   function makeRequest(url, ddl_no) {
   
	var http_request = false;
    var n_url=url+'&LANG_COD=001&MODID=CMS060207001&INSID=10';
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_request) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
		return false;
	}
	// 定義事件處理函數為 alterContents()
	http_request.onreadystatechange = function() { 
                                      alertContents(http_request, ddl_no); };
	http_request.open('GET', n_url, true);
	http_request.send(null);
}

function alertContents(http_request, ddl_no) {
	var max_ddl_no = 3; //最大下拉數
	
    if (http_request.readyState == 4) {
		if (http_request.status == 200) {

			var xmldoc = http_request.responseXML;

			for ( i=ddl_no;i<=max_ddl_no;i++ ) {
				var ddl_name = "C" + i;
				var tag_name = "lvl_" + i;
				var nodes = xmldoc.getElementsByTagName(tag_name);

				C_list = document.getElementById(ddl_name);

				if ( C_list ) {
				   if (C_list.name=="C1"){	
					C_list.options.length = 0;	// 清空下拉內容
					C_list.options[C_list.options.length] = new Option("All", "");
					C_list.options[C_list.options.length-1].value = "0";
					//C_list.style.display = "none";
					}
					else
					{
					C_list.options.length = 0;	// 清空下拉內容
					C_list.options[C_list.options.length] = new Option("All", "");					
					//C_list.style.display = "none";
					}
				}
				
				
				  for(var j=0; j<nodes.length; j++) {
					var Class_ID = nodes[j].getAttribute("Class_ID");
					var Class_NAME = retutnString(nodes[j].getAttribute("Class_NAME")); 
//					C_list.options[C_list.options.length] = new Option(nodes[j].firstChild.nodeValue, nodes[j].firstChild.nodeValue);
					C_list.options[C_list.options.length] = new Option(Class_NAME, Class_ID);
				  }				
								
				var __ddl_no;		// 控制要顯示的下拉編號
				if ( ddl_no == 1 ) {
					__ddl_no = ddl_no+1;
				}else{
					__ddl_no = ddl_no
				}
				
				if ( ( C_list.options.length > 1 ) && ( i == ddl_no ) || ( i == __ddl_no ) ) {
					C_list.style.display = "";
				}
	          
			}
		} else {
		  if (ddl_no==2){		  
			var C_list2 = eval("document.all.C2");
			var C_list3 = eval("document.all.C3");
			C_list2.options.length = 0;	// 清空下拉內容
			C_list2.options[C_list2.options.length] = new Option("All", "");
			C_list2.options[C_list2.options.length-1].value = "0";
			
			C_list3.options.length = 0;	// 清空下拉內容
			C_list3.options[C_list3.options.length] = new Option("All", "");
			C_list3.options[C_list3.options.length-1].value = "0";
		  }
		  
		   if (ddl_no==3){		  
			
			var C_list3 = eval("document.all.C3");
		
			C_list3.options.length = 0;	// 清空下拉內容
			C_list3.options[C_list3.options.length] = new Option("All", "");
			C_list3.options[C_list3.options.length-1].value = "0";
		  }
		    
			//alert('There was a problem with the request.');
		}


	}
}

 function retutnString(sString){
        //轉換關鍵字       
        return sString.replace("[and]","&")   
    }
