﻿function addPoint(point,novelID){
    //创建XMLHttpRequest对象
    var xmlhttp
    try{
        xmlhttp = new XMLHttpRequest();
    }catch(e){
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    //创建请求结果处理程序
    xmlhttp.onreadystatechange = function(){
        if(4 == xmlhttp.readyState){
            if(200 == xmlhttp.status){
                var info = xmlhttp.responseText;
                HandlingPoint(info);
            }else{
                alert("提交中出现不可预料的错误,请刷新当前页面,然后重试!");
            }
        }
    }
    //打开连接，true代表异步提交
    xmlhttp.open("post","../../CGI/AddPoint.aspx?NovelID="+novelID+"&Point="+point,true);
    //当方法为POST时需要设置HTTP头
    xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xmlhttp.send(null);
}

function addStick(stick,novelID){

    if(1==2)
    {
	alert('您在本周已经顶或踩过该作品了,您要等下周才能重新顶踩她.');
    }
    else
    {
	//创建XMLHttpRequest对象
    	var xmlhttp
    	try{
        	xmlhttp = new XMLHttpRequest();
    	}catch(e){
        	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    	}
    	//创建请求结果处理程序
    	xmlhttp.onreadystatechange = function(){
        	if(4 == xmlhttp.readyState){
            	if(200 == xmlhttp.status){
                	var info = xmlhttp.responseText;
                	HandlingStick(info);
            	}else{
                	alert("提交中出现不可预料的错误,请刷新当前页面,然后重试!");
            	}
        	}
    }
    //打开连接，true代表异步提交
    xmlhttp.open("post","../../CGI/AddStick.aspx?NovelID="+novelID+"&Stick="+stick,true);
    //当方法为POST时需要设置HTTP头
    xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xmlhttp.send(null);
    }
}

//处理程序
function HandlingPoint(info){
    if(info==0)
	alert("您需要先登录,才能进行评分操作.");
    else if(info==1)
	alert("评分提交的参数有误,请刷新後重新提交.");
    else if(info==2)
	alert("您在之前已经为本作品评过分了,谢谢您的支持:).");
    else if(info==3)
	alert("提交成功!您的这次评分将影响该作品的最终评分.");
}

//处理程序
function HandlingStick(info){
    var infoList = info.split(',');
    if(infoList[0]==-2)
	alert("您需要先登录,才能进行顶和踩操作.");
    else if(infoList[0]==-1)
	alert("提交的参数有误,请刷新後重新提交.");
    else if(infoList[0]==-3)
	alert("您的当前登陆帐户积分太低,您需要至少积分5才能执行顶和踩操作.");
    else if(infoList[0]==0)
	alert("您在本周已经顶或踩过该作品了,您要等下周才能重新顶踩她.");
    else
	{
		alert("提交成功!");
		if(infoList[0]==1)
			document.getElementById('StickContent1').innerHTML = infoList[1]+"人";
		else	document.getElementById('StickContent2').innerHTML = infoList[1]+"人";
	}
}

function CheckUser(novelID)
{
	var cookieString = new String(document.cookie);
	var cookieName = 'userbookstick-'+novelID;
	var beginPosition = cookieString.indexOf(cookieName);
	if(beginPosition==-1) //not stick yet
	{
		var Then = new Date();
		Then.setTime(Then.getTime()+3600000*24*7); //a week
		document.cookie=cookieName+'=1;expires='+ Then.toGMTString()+';path=/;';
		return 1;
	}
	return 0;
}