//获得当前日期
function showdate(){ 
	var dayList = new Array('天','一','二','三', '四', '五', '六');
	var dateo = new Date();
	var year  = dateo.getFullYear();
	var month = dateo.getMonth()+1;
	var date  = dateo.getDate();
	var day   = dateo.getDay();
	var dateString = year + '年' + month + '月' + date + '日' + '  星期' + dayList[day];
	document.write('今天是'+dateString);
}

//获得验证码
function GetCode(obj){
	document.getElementById("ShowCode").innerHTML = "<img style='cursor:pointer;width:40px;height:10px;' onclick='javascript:GetCode();' alt='看不清验证码？' border='0' src='inc/GetCode.asp?"+Math.random()+"' id='randImage'/>";
}

//显示验证码
function ShowCode(sg) {
	if(sg=='show') {
		var obj = document.getElementById("ShowCode");
		if(obj.style.visibility=='hidden') {
			GetCode();
			obj.style.visibility="visible";
		}
	}else{
		document.getElementById("ShowCode").style.visibility="hidden";
	}
}

//函数作用：获取信件内容
function GetMailContents(id,action,suffix){
	var ajax = new AJAXRequest({
		onrequeststart : function(obj) {	//请求开始执行回调函数
			$("#mail_"+suffix).html("<img src=\"public/images/loading.gif\" />正在读取……");
		},
		timeout : 20000,
		ontimeout : function(obj) {	//请求超时时执行回调函数
			$("#mail_"+suffix).html("读取超时……");
		},
		onexception : function(e) {	//请求异常时执行回调函数
			var str="请求时出现错误：";
			str+="\n请求地址: "+e.url;
			str+="\n发送数据: "+e.content;
			str+="\n请求方式: "+e.method;
			str+="\n返回状态: "+e.status;
			alert(str);
		},
		async : true,
		method : "GET"
	});
	ajax.get('mail_getcontent.asp?action='+action+'&id='+id, oncomplete = function(obj) {
		var text = obj.responseText;
		if (text == ""){
			$("#"+suffix).hide();
		}else{
			$("#"+suffix).show();
			$("#mail_"+suffix).html(text);
		}
	});
}

//函数作用：用户登陆
function maillogin(sid){
	var ajax =new AJAXRequest({
		onrequeststart : function(obj) {	//请求开始执行回调函数
			$("#check").html("<img src=\"public/images/loading.gif\" />正在提交……");
		},
		timeout : 20000,
		ontimeout : function(obj) {	//请求超时时执行回调函数
			$("#check").html("提交超时……");
		},
		onexception : function(e) {	//请求异常时执行回调函数
			var str="请求时出现错误：";
			str+="\n请求地址: "+e.url;
			str+="\n发送数据: "+e.content;
			str+="\n请求方式: "+e.method;
			str+="\n返回状态: "+e.status;
			alert(str);
		},
		async : true,
		method : "POST"
	});
	var password = $("#password").val();
	if (password == ""){
		$("#check").html("密码不能为空！");
	}
	else
	{
		ajax.post("mail_getcontent.asp?action=checklogin&id="+sid,"password="+escape(password),function(obj) {
			//alert(obj.responseText);
			//GetObj("postcontent1").innerHTML = obj.responseText;
			if (obj.responseText == "onlogin"){
				//GetObj("check").innerHTML = "发送成功！";
				GetMailContents(sid,"mailcontent","content");
				GetMailContents(sid,"mailinstructions","instructions");
				GetMailContents(sid,"mailreply","reply");
				GetMailContents(sid,"mailvote","vote");
			}else{
				$("#check").html(obj.responseText);
			}
		});
	}
}

//函数作用：投票登陆
function votelogin(sid){
	var ajax =new AJAXRequest({
		onrequeststart : function(obj) {	//请求开始执行回调函数
			$("#check").html("<img src=\"public/images/loading.gif\" />正在提交……");
		},
		timeout : 20000,
		ontimeout : function(obj) {	//请求超时时执行回调函数
			$("#check").html("提交超时……");
		},
		onexception : function(e) {	//请求异常时执行回调函数
			var str="请求时出现错误：";
			str+="\n请求地址: "+e.url;
			str+="\n发送数据: "+e.content;
			str+="\n请求方式: "+e.method;
			str+="\n返回状态: "+e.status;
			alert(str);
		},
		async : true,
		method : "POST"
	});
	var password = $("#password").val();
	if (password == ""){
		$("#check").html("密码不能为空！");
	}else{
		ajax.post("mail_getcontent.asp?action=checklogin&id="+sid,"password="+escape(password),function(obj) {
			if (obj.responseText == "onlogin"){
				GetMailContents(sid,"mailvote","vote");
			}else{
				$("#check").html(obj.responseText);
			}
		});
	}
}

//函数作用：用户投票
function voting(sid){
	var ajax =new AJAXRequest({
		onrequeststart : function(obj) {	//请求开始执行回调函数
			$("#mail_vote").html("<img src=\"public/images/loading.gif\" />正在提交……");
		},
		timeout : 20000,
		ontimeout : function(obj) {	//请求超时时执行回调函数
			$("#mail_vote").html("提交超时……");
		},
		onexception : function(e) {	//请求异常时执行回调函数
			var str="请求时出现错误：";
			str+="\n请求地址: "+e.url;
			str+="\n发送数据: "+e.content;
			str+="\n请求方式: "+e.method;
			str+="\n返回状态: "+e.status;
			alert(str);
		},
		async : true,
		method : "POST"
	});
	var vote = $("input[type=radio]:checked").val();
	var len = $("input[type=radio]:checked").length; 
	if (len == 0){
		alert("请选择您对本回复的满意度！");
	}else{
		ajax.post("mail_getcontent.asp?action=voting&id="+sid,"vote="+escape(vote),function(obj) {
			if (obj.responseText == "ok"){
				GetMailContents(sid,"mailvote","vote");
			}else{
				$("#mail_vote").html(obj.responseText);
			}
		});
	}
}
