// AJAX
function GetXMLHTTP()
{
	try {
		xmlhttpc = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	try {
		xmlhttpc = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (e2) {
		xmlhttpc = false;
	}
	}
	if (!xmlhttpc && typeof XMLHttpRequest != 'undefined') {
		xmlhttpc = new XMLHttpRequest();
	}
	if (!xmlhttpc) {
		alert("无法创建XMLHttp对象!");
	}
	else
	{
		return xmlhttpc;
	}
}


function pop_announce(nodeid,id,weburl)
{ 
	if(nodeid == "" || id == "") {
	    alert("参数有误,查看公告信息失败!");
		return false
	}
	xmlhttp = GetXMLHTTP();
	URL = weburl+"/d/announce.php?&n="+nodeid+"&id="+id;
	xmlhttp.open("GET",URL);
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttp.onreadystatechange = callback_announce;
	xmlhttp.send(null);
}

function callback_announce() 
{
    var backmsg = "";
		if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
		{
		    if(xmlhttp.responseText == "error") {
		        alert("获取数据时出错!");
				return false;
			}else if(xmlhttp.responseText == ""){
		        alert("没有取得需要的数据,请与管理员联系!");
				return false;
		    }else{
				backmsg = xmlhttp.responseText;
			}
			$("body").append("<div id='pop_ann'></div>");
			document.getElementById("pop_ann").style.display = '';
	        document.getElementById("pop_ann").innerHTML = backmsg ;
			if($.browser.msie && $.browser.version == "6.0"){
				$("#ann_content_div").css("position","absolute");
				$("#ann_content_div").css("top","60%");
			}
			delete(xmlhttp);
		}
}

function copycontent(nodeid,downid,jointime,weburl)
{ 
	if(nodeid == "" || downid == "") {
	    alert("参数有误,获取失败!");
		return false
	}
	xmlhttp = GetXMLHTTP();
	URL = weburl+"/d/axaj.php?mod=download&n="+nodeid+"&id="+downid+"&time="+jointime;
	xmlhttp.open("GET",URL);
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttp.onreadystatechange = callback_copycontent;
	xmlhttp.send(null);
}

function callback_copycontent() 
{
    var backmsg = "";
		if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
		{
		    if(xmlhttp.responseText == "error") {
		        alert("获取数据时出错!");
				return false;
			}else if(xmlhttp.responseText == ""){
		        alert("没有取得需要的数据,请与管理员联系!");
				return false;
		    }else{
				backmsg = xmlhttp.responseText;
			}
			window.clipboardData.setData('Text',backmsg); 
			alert("己成功复制到简贴板!");
			delete(xmlhttp);
		}
}

function downvote(nodeid,downid,poll,weburl)
{ 
	if(downid == "" || poll == "") {
	    alert("参数有误,投票失败!");
		return false
	}
	xmlhttp = GetXMLHTTP();
	URL = weburl+"/d/axaj.php?mod=downvote&n="+nodeid+"&id="+downid+"&poll="+poll;
	xmlhttp.open("GET",URL);
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttp.onreadystatechange = downvote_copycontent;
	xmlhttp.send(null);
}

function downvote_copycontent() 
{
    var backmsg = "";
		if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
		{
		    if(xmlhttp.responseText == "error") {
		        alert("投票出错!");
				return false;
			}else if(xmlhttp.responseText == ""){
		        alert("没有取得需要的数据,请与管理员联系!");
				return false;
		    }else{
				backmsg = xmlhttp.responseText;
			}
			if (backmsg == "1")
			{
				if (document.getElementById("good_count"))
				{
					document.getElementById("good_count").innerHTML = parseInt(document.getElementById("good_count").innerHTML)+1;
					var good_scale = parseInt(document.getElementById("good_count").innerHTML);
					var bad_scale  = parseInt(document.getElementById("bad_count").innerHTML);
					document.getElementById("good_scale").width = good_scale/(good_scale+bad_scale) * 100;
					document.getElementById("bad_scale").width = bad_scale/(good_scale+bad_scale) * 100;
				}
				alert("投票成功!");
				return true;
			}else if(backmsg == "2") {
				if (document.getElementById("bad_count"))
				{
					document.getElementById("bad_count").innerHTML = parseInt(document.getElementById("bad_count").innerHTML)+1;
					var good_scale = parseInt(document.getElementById("good_count").innerHTML);
					var bad_scale  = parseInt(document.getElementById("bad_count").innerHTML);
					document.getElementById("good_scale").width = good_scale/(good_scale+bad_scale) * 100;
					document.getElementById("bad_scale").width = bad_scale/(good_scale+bad_scale) * 100;
				}
				alert("投票成功!");
				return true;
			}else if(backmsg == "3") {
			    alert("您己经投过票了!");
			}
			delete(xmlhttp);
		}
}

function getdownvote(nodeid,voteid,weburl)
{ 
	if(voteid == "") {
	    alert("参数有误,投票失败!");
		return false
	}
	xmlhttp = GetXMLHTTP();
	URL = weburl+"/d/axaj.php?mod=getdownvote&n="+nodeid+"&id="+voteid;
	xmlhttp.open("GET",URL);
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlhttp.onreadystatechange = getdownvote_set;
	xmlhttp.send(null);
}

function getdownvote_set() 
{
		if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200))
		{
		    if(xmlhttp.responseText == "error") {
		        alert("获取投票信息出错!");
				return false;
			}else if(xmlhttp.responseText == ""){
		        alert("没有取得需要的数据,请与管理员联系!");
				return false;
		    }else{
				//var backmsg = "";
				//var backmsg = eval('(' + xmlhttp.responseText + ')');
				var backmsg = xmlhttp.responseText;

			}
			backmsg = eval("("+backmsg+")");
			if (backmsg.good)
			{
				document.getElementById("good_count").innerHTML = backmsg.good;
				document.getElementById("good_scale").width = backmsg.good_scale;
			}
			if (backmsg.bad)
			{
				document.getElementById("bad_count").innerHTML = backmsg.bad;
				document.getElementById("bad_scale").width = backmsg.bad_scale;
			}
			delete(xmlhttp);
		}
}
