var WAITING_BOX="<table cellspacing=\"5\" class=\"add_comment\"><tr><th><br/><br/><br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;谢谢您的支持,正在发送请求…………&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/><br/><br/><br/><br/></th></tr></table>";
var xmlHttp;
var article_id;
var memo_id;
var div_flag;
function createXMLHttpRequest(){
	if(window.ActiveXObject){
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if(window.XMLHttpRequest){
		xmlHttp = new XMLHttpRequest();
	}
}
function startRequest(id){
	article_id=id;
	createXMLHttpRequest();
	xmlHttp.onreadystatechange=handleStateChange;
	xmlHttp.open("POST","/blog/add_comment/"+id+"?layout=false",true);
	xmlHttp.send("");
}
function startRequestMemo(memoId){
  memo_id=memoId;
  document.getElementById("loading_"+memo_id).innerHTML = "正在加载资料说明，请稍候……"
  createXMLHttpRequest();
  xmlHttp.onreadystatechange=handleStateChange3;
  xmlHttp.open("POST","/download/"+memoId,true);
  xmlHttp.send("");
}
function startRequestPerm(id,agree,layout){
  if(!document.getElementById("read_ok").checked){
  		window.alert("请先阅读服务条款，并勾上“已阅”复选框");
  		return;
	}
	article_id=id;
	div_flag=layout;
	document.getElementById("commentForm"+article_id).innerHTML=WAITING_BOX;
	
	createXMLHttpRequest();
	xmlHttp.onreadystatechange=handleStateChange2;
	var params="agree="+agree;
	params += layout ?"":"&layout=false";
	xmlHttp.open("POST","/blog/comment_perm/"+id+"?"+params,true);
	xmlHttp.send("");
	
}
function handleStateChange(){
	if(xmlHttp.readyState==4){
		if(xmlHttp.status==200){
			document.getElementById("commentForm"+article_id).innerHTML = xmlHttp.responseText;	
			if(document.getElementById("reviewer_name")!=null){
			    moreInputs();
			    document.getElementById("reviewer_name").focus();
		  }//if
		  else if(document.getElementById("read_ok")!=null){
		  		document.getElementById("read_ok").focus();
			}//else if
			else {
					document.getElementById("comment_content").focus();
			}
		}//if
	}//if
}
function handleStateChange2(){
  
	if(xmlHttp.readyState==4){
		if(xmlHttp.status==200){
		  
			var divEle=null;
			
			if(!div_flag) { 
			   divEle=document.getElementById("commentForm"+article_id);
		  }
		  
			if(divEle!=null){
				divEle.innerHTML = xmlHttp.responseText;
				moreInputs();	
		  }
		  else {
		  	document.getElementById("inside").innerHTML=xmlHttp.responseText;
		  	moreInputs();
			}
			
		}
	}
}
function handleStateChange3(){
	if(xmlHttp.readyState==4){
		if(xmlHttp.status==200){
			document.getElementById("download").innerHTML = xmlHttp.responseText;	
			document.getElementById("loading_"+memo_id).innerHTML = "";
		}//if
	}//if
}
function moreInputs(){
	if(document.getElementById("create_reviewer")!=null){
	  if(document.getElementById("create_reviewer").checked){
			document.getElementById("email_input").style.display="";
			document.getElementById("msn_input").style.display="";
			document.getElementById("qq_input").style.display="";
	  }
	  else {
			document.getElementById("email_input").style.display="none";
			document.getElementById("msn_input").style.display="none";
			document.getElementById("qq_input").style.display="none";
		}//else
	}//if
}

