var xmlHttp;
function GetXmlHttpObject()
{
	var xmlHttp=null;
	try{// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e){
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
function answer_post(f,mode,target_id){
	xmlHttp=GetXmlHttpObject();
	var comment=f.comment.value;
	var artid=f.artid.value;
	var userip=f.userip.value;
	var url='/qna/answer_post.php';
	if(!comment){alert("請輸入內容.");f.comment.focus();return false;}
	var postdate = 'comment='+encodeURIComponent(comment)+'&artid='+artid+'&mode='+mode+'&userip='+userip+'&target_id='+target_id;
	postdate = encodeURI(postdate);
	f.innerHTML="回答已經發表。";
	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=='complete'){
			var gettext=xmlHttp.responseText.split('@@');
			document.getElementById(gettext[0]).innerHTML=gettext[1];
			document.getElementById(gettext[0]).style.display = "block";
		}
	}; 
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Cache-Control","no-cache");
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;"); 
	xmlHttp.send(postdate);
	return false;
}
function select_category(obj,type){
	xmlHttp=GetXmlHttpObject();
	var id=obj.value;
	var type=type;
	var url='/qna/select_category.php';
	if(id==0){document.getElementById('category_id').innerHTML='<option value="0">=請選擇=</option>';return false;}
	url=url+'?id='+id+'&type='+type;
	url=encodeURI(url);
	xmlHttp.onreadystatechange=function() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=='complete'){
			var gettext=xmlHttp.responseText.split('@@');
			document.getElementById(gettext[0]).innerHTML=gettext[1];
		}
	}; 
	xmlHttp.open('GET',url,true);
	xmlHttp.send(null);
	return false;
}

function expert_answer () {
	var isVisible = document.getElementById("expert_answer").style.visibility;
	if (isVisible == "hidden") {
		document.getElementById("expert_answer").style.visibility="visible";
	}
	else {
		document.getElementById("expert_answer").style.visibility="hidden";
	}
}

