﻿function createXMLHttp() {
	var xmlHttp = null;
		var ex;
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.4.0");
		}
		catch (ex)
		{
			try
			{
				xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
			}
			catch (ex)
			{
				try
				{
					xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (ex)
				{
	                
	                try
	                {
	                 xmlHttp = new XMLHttpRequest();
				    }
				    catch(ex)
				    {
				      throw new Error("XMLHttp object could be created.");
				    }
				}
			}
		}
	return xmlHttp;
}

//将用户输入异步提交到服务器
function ajaxSubmit(type,id){
	//获取用户输入
	//var title=document.forms[0].title.value;
     var Type=type
	//alert(nr);
	//创建XMLHttpRequest对象
	var xmlhttp=createXMLHttp();
	
	//创建请求结果处理程序
	xmlhttp.onreadystatechange=function(){
		if (4==xmlhttp.readyState){
			if (200==xmlhttp.status){
				var requestinfo=xmlhttp.responseText;
				addToList(requestinfo);
			}else{
				alert("error");
			}
	}
	}
	//打开连接，true表示异步提交
	xmlhttp.open("post", "comment.asp", true);
	//当方法为post时需要如下设置http头
	xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	//发送数据
	xmlhttp.send("Type="+escape(Type)+"&id="+escape(id));
	
}

//将用户输入显示到页面
function addToList(date){
	if(date=="erroinfo")
	{
		str = "对不起，您已经投过票！";
	}
	else
	{
		str = "投票成功！";
		document.getElementById(""+date+"").innerHTML=parseInt(document.getElementById(""+date+"").innerHTML)+1
	}
	//alert(str);

}


//导航js
function changesubdiv(e,n,i,div){	
	for (j=1;j<=n;j++){
		obj = document.getElementById(e+j);
		if (j==i){
			obj.className='current';
			document.getElementById(div+j).style.display="block";
		}else{
			obj.className='';
			document.getElementById(div+j).style.display="none";
			
		}
	}
}