var http_request=false;
var reobj;
  function send_request(url){
    http_request=false;
	if(window.XMLHttpRequest){
	 http_request=new XMLHttpRequest();
	 if(http_request.overrideMimeType){
	   http_request.overrideMimeType("text/xml");
	 }
	}
	else if(window.ActiveXObject){
	 try{
	  http_request=new ActiveXObject("Msxml2.XMLHttp");
	 }catch(e){
	  try{
	  http_request=new ActiveXobject("Microsoft.XMLHttp");
	  }catch(e){}
	 }
    }
	if(!http_request){
	 window.alert("創建XMLHttp對象失敗！");
	 return false;
	}
	http_request.onreadystatechange=processrequest;
	
    http_request.open("GET",url,true);
	http_request.send(null);
  }
  
  function processrequest(){
   if(http_request.readyState==4){
     if(http_request.status==200 && reobj== "server"){
			(function(){
				var data =	eval('(' + http_request.responseText + ')');
				var faq = document.getElementById('sid');
				var fs = document.getElementById('chid');
				
				for(var i=faq.childNodes.length-1; i>=0; i--) faq.remove(i);
				//faq .
				for(var i=0; i<data.length; i++){
					//console.log(data[i].name);
					var option = document.createElement('OPTION');
					option.text = data[i].name;
					option.innerText = data[i].name;
					option.value = data[i].id;
				
					faq.appendChild(option);
				}
				
				if(data[0].chil){
					var child_data = data[0].chil;
					for(var i=0; i<child_data.length; i++){
						var option = document.createElement('OPTION');
						option.text = child_data[i].cs_name;
						option.innerText = child_data[i].cs_name;
						option.value = child_data[i].cs_id;
				
						fs.appendChild(option);
					}
				}
				
				
				faq.onchange = function(){
					var id = this.value;
					var child_data = null;
					for(var i=0; i<data.length; i++){
						if(data[i].id == id){
							child_data = data[i].chil;
							break;
						}
					}
					for(var i=fs.childNodes.length-1; i>=0; i--) fs.remove(i);
					if(child_data){
				
						
				
						for(var i=0; i<child_data.length; i++){
							var option = document.createElement('OPTION');
							option.text = child_data[i].cs_name;
							option.innerText = child_data[i].cs_name;
							option.value = child_data[i].cs_id;
				
							fs.appendChild(option);
						}
					}
				}
								
			})();
	 }else if(http_request.status==200 && reobj== "myreport"){
	 	//alert(http_request.responseText);
	 	//return false;
	 	//document.write('<pre>' + http_request.responseText + '</pre>');
	 	document.getElementById("report").innerHTML = http_request.responseText;
		var aaid	=	document.getElementById('aaid').value;
		aid = aaid ? aaid : 1;
		addAttach();
	 }
	 else{
	  alert("您所請求的頁面不正常！");
	 }
   }
  }


  function getServer(gid){
	//document.getElementById(obj).innerHTML="...";
	send_request('script/getServer.script.php?gameid='+gid);
	reobj="server";
  }
  function myReport(fbid){
  	send_request('script/getReport.script.php?fbid='+fbid);
	reobj="myreport";
  }
  function rePage(){
	location.reload();
  }
