﻿var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        xmlhttp = new XMLHttpRequest();
}
function getCommentList(page,id,divID) {
	if (xmlhttp) {
		d=document
		var oInputArray = new Array();
		var requestFile = "/Include/ajax.aspx?oper=get&id=" + id + "&page=" + page + "&m=" + Math.random();
		xmlhttp.open("GET", requestFile ,true);
		xmlhttp.onreadystatechange= function () {
			if (xmlhttp.readyState==1) {
				document.getElementById(divID).innerHTML='<img src="/images/ajax.gif" alt="正在加载……" /> ';
			}
			if (xmlhttp.readyState==4) {
				document.getElementById(divID).innerHTML=xmlhttp.responseText
			}
		}
		xmlhttp.send(null);
	}
}

function addReview(id,divID) {
	var username=$("reviewName").value;
	var content=$("reviewContent").value;
	if(!username || !content || content.length < 10) {
		alert("Please input your nick name and the comment character must be more than ten !");
	return;
	}

	var ps = "id=" + id + "&username=" + username + "&content=" + content;
	if (xmlhttp) {
		d=document
		var oInputArray = new Array();
		var requestFile = "/Include/ajax.aspx?oper=add";
		xmlhttp.open("POST", requestFile ,true);

		xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		xmlhttp.send(ps)

		xmlhttp.onreadystatechange= function () {
			if (xmlhttp.readyState==3) {
				document.getElementById(divID).innerHTML='<p><strong>submit ......</strong><img src="/images/ajax.gif" alt="正在加载……" /></p> ';
			}
			if (xmlhttp.readyState==4) {
				document.getElementById("CommentForm").style.visibility = "hidden";
				getCommentList("1",id,divID)
			}
		}
	}
}


function digg(behavior,id) {
	if (xmlhttp) {
		d=document
		var oInputArray = new Array();
		var requestFile = "/Include/ajax.aspx?oper=updown&id=" + id + "&dig=" + behavior + "&m=" + Math.random();
		xmlhttp.open("GET", requestFile ,true);
		xmlhttp.onreadystatechange= function () {
			if (xmlhttp.readyState==1) {
				document.getElementById('newdigg').innerHTML='<img src="/images/ajax.gif" alt="正在加载……" />';
			}
			if (xmlhttp.readyState==4) {
				document.getElementById('newdigg').innerHTML=xmlhttp.responseText
			}
		}
		xmlhttp.send(null);
	}
}