function displayGender(gender)
{
	var gendername = '女';
	gender = parseInt(gender);
	switch (gender)
	{
		case 0:
			gendername = '保密';
			break;
		case 1:
			gendername = '男';
			break;
		case 2:
			gendername = '女';
			break;
	}
	return gendername;
}
function replyToFloor(floor,poster, postid)
{
	if ($('title'))
	{
		$('postform').postid.value = postid;
		$('title').value = '回复 ' + floor + 'F ' + poster + ' 的帖子';
		$('message').focus();		
	}
}

function nospace(username)
{
	alert('抱歉, 用户 ' + username + ' 尚未开通个人空间');
}
function validate(theform, previewpost, switcheditormode) {
	var message = !theform.parseurloff.checked ? parseurl(theform.message.value) : theform.message.value;

	if (theform.title.value == "" || message == "") {
		alert("请完成标题和内容栏。");
		$("postsubmit").disabled = false;
		return false;
	} else if (theform.title.value.length > 60) {
		alert("您的标题超过 60 个字符的限制。");
		theform.title.focus();
		$("postsubmit").disabled = false;
		return false;
	}

	if(!disablepostctrl && ((postminchars != 0 && mb_strlen(message) < postminchars) || (postmaxchars != 0 && mb_strlen(message) > postmaxchars))) {
		alert("您的帖子长度不符合要求。\n\n当前长度: " + mb_strlen(message) + " 字节\n系统限制: " + postminchars + " 到 " + postmaxchars + " 字节");
		return false;
	}

	if (!switcheditormode && !previewpost) {
		$("postsubmit").disabled = true;
	}

	theform.message.value = message;
	return true;
}

function ShowStars(n, t) {
	var s = '';
	for(var i=3; i>0; i--) {
		level = parseInt(n / Math.pow(t, i-1));
		n = n % Math.pow(t, i-1);
		for(var j=0; j<level; j++) {
			s += '<img src="templates/' + templatepath + '/images/star_level'+i+'.gif" />';
		}
	}
	document.write(s);
}

function copycode(obj) {

	if(is_ie && obj.style.display != 'none') {

		var rng = document.body.createTextRange();

		rng.moveToElementText(obj);

		rng.scrollIntoView();

		rng.select();

		rng.execCommand("Copy");

		rng.collapse(false);
	}
}

function signature(obj) {
	if(obj.style.maxHeightIE != '') {
		var height = (obj.scrollHeight > parseInt(obj.style.maxHeightIE)) ? obj.style.maxHeightIE : obj.scrollHeight;
		if(obj.innerHTML.indexOf('<IMG ') == -1) {
			obj.style.maxHeightIE = '';
		}
		return height;
	}
}

function imgzoom(o)
{
	if(event.ctrlKey)
	{
		var zoom = parseInt(o.style.zoom, 10) || 100;
		zoom -= event.wheelDelta / 12;
		if(zoom > 0)
		{
			o.style.zoom = zoom + '%';
		}
		return false;
	}
	else
	{
		return true;
	}
}
 
function printinpostad(index){
	try{
		if (inpostad){
				document.write("<div class=\"line category\"><div style='float: left;'>[广告]&nbsp;</div><div style='text-align:left;'>");
				var tempstr = inpostad[index];
				var ad = tempstr.split("\\r\\n");
				for (var i = 0; i < ad.length; i++)
				{
					document.writeln(ad[i]);
				}
				document.write("</div>");
				document.write("</div>");
			}
		}
	catch(e){
	}
}

function showrate(pid,aspxrewrite)
{
	var rr = $("rate_" + pid + "_real");
	var rf = $("rate_" + pid + "_fake");
	
	if (rr.style.display == "none")
	{
		rr.style.display = "";
		rf.style.display = "none";
	}
	else
	{
		rr.style.display = "none";
		rf.style.display = "";
	}

	var ratediv = $("rate_" + pid);
	if (ratediv.innerHTML == "")
	{
		ratediv.innerHTML = "请稍侯..."
		var action = "tools/ajax.aspx?t=ratelist";



		var oXmlHttp = createXMLHttp();
		oXmlHttp.open("post", action, true);
		oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oXmlHttp.onreadystatechange = function () {
			if (oXmlHttp.readyState == 4) {
				if (oXmlHttp.status == 200) {
					outputRatelog(oXmlHttp.responseXML, pid, aspxrewrite);
					//bind current post;
				} else {
					alert("An error occurred: " + oXmlHttp.statusText);
				}
			}
		};
		oXmlHttp.send("pid=" + pid);


		//ratediv.appendChild(form);

	}


}

function outputRatelog(doc, pid, aspxrewrite)
{
	var err = doc.getElementsByTagName('error');
	if (err[0] != null && err[0] != undefined)
	{
		if (err[0].childNodes.length > 1) {
		    alert(err[0].childNodes[1].nodeValue);
		} else {
		    alert(err[0].firstChild.nodeValue);    		
		}
		return;
	}

	var ratediv = $("rate_" + pid);

	var html = "<table border='0' cellpadding='0' cellspacing='0'>";
	var ratelist = doc.getElementsByTagName('ratelog');
	for (var i = 0; i < ratelist.length; i++ )
	{
		var uid = getSpecificNodeValue(doc, "uid", i);
		var username = getSpecificNodeValue(doc, "username", i);
		var extcreditsname = getSpecificNodeValue(doc, "extcreditsname", i);
		var extcreditsunit = getSpecificNodeValue(doc, "extcreditsunit", i);
		var postdatetime = getSpecificNodeValue(doc, "postdatetime", i);
		var score = getSpecificNodeValue(doc, "score", i);
		var reason = getSpecificNodeValue(doc, "reason", i);

        if(aspxrewrite == 1)
        {
		    html += "<tr><td><a target='_blank' href='userinfo-" + uid + ".aspx'>" + username + "</a></td><td>&nbsp;&nbsp;" + postdatetime + "</td><td>&nbsp;&nbsp;" + extcreditsname + "&nbsp;&nbsp;<b>" + score + "</b>&nbsp;" + extcreditsunit + "</td><td>&nbsp;&nbsp;" + reason + "</td></tr>";
		}
		else
		{
		    html += "<tr><td><a target='_blank' href='userinfo.aspx?userid=" + uid + "'>" + username + "</a></td><td>&nbsp;&nbsp;" + postdatetime + "</td><td>&nbsp;&nbsp;" + extcreditsname + "&nbsp;&nbsp;<b>" + score + "</b>&nbsp;" + extcreditsunit + "</td><td>&nbsp;&nbsp;" + reason + "</td></tr>";
		}
	}
	html += "</table>";
	if (ratelist.length == 0)
	{
		html = "";
	}

	ratediv.innerHTML = html;

}

