//显示表情菜单
function showFace(showid, target) {
	var div = $('uchome_face_bg');
	if(div) {
		div.parentNode.removeChild(div);
	}
	div = document.createElement('div');
	div.id = 'uchome_face_bg';
	div.style.position = 'absolute';
	div.style.left = div.style.top = '0px';
	div.style.width = '100%';
	div.style.height = document.body.scrollHeight + 'px';
	div.style.backgroundColor = '#FFFFFF';
	div.style.zIndex = 10000;
	div.style.display = 'none';
	div.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0,finishOpacity=100,style=0)';
	div.style.opacity = 0;
	div.onclick = function() {
		$(showid+'_menu').style.display = 'none';
		$('uchome_face_bg').style.display = 'none';
	}
	$('append_parent').appendChild(div);
	
	if($(showid + '_menu') != null) {
		$(showid+'_menu').style.display = '';
	} else {
		var faceDiv = document.createElement("div");
		faceDiv.id = showid+'_menu';
		faceDiv.className = 'facebox';
		faceDiv.style.position = 'absolute';
		var faceul = document.createElement("ul");
		for(i=1; i<31; i++) {
			var faceli = document.createElement("li");
			faceli.innerHTML = '<img src="image/face/'+i+'.gif" onclick="insertFace(\''+showid+'\','+i+', \''+ target +'\')" style="cursor:pointer; position:relative;" />';
			faceul.appendChild(faceli);
		}
		faceDiv.appendChild(faceul);
		$('append_parent').appendChild(faceDiv)
	}
	//定位菜单
	setMenuPosition(showid, 0);
	div.style.display = '';
}
//插入表情
function insertFace(showid, id, target) {
	var faceText = '[em:'+id+':]';
	if($(target) != null) {
		insertContent(target, faceText);
	}
	$(showid+'_menu').style.display = 'none';
	$('uchome_face_bg').style.display = 'none';
}

function textCounter(obj, showid, maxlimit) {
	var len = strLen(obj.value);
	var showobj = $(showid);
	if(len > maxlimit) {
		obj.value = getStrbylen(obj.value, maxlimit);
		showobj.innerHTML = '0';
	} else {
		showobj.innerHTML = maxlimit - len;
	}
	if(maxlimit - len > 0) {
		showobj.parentNode.style.color = "";
	} else {
		showobj.parentNode.style.color = "red";
	}
	
}
function textCounters(obj, showid) {
	var len = strLen(obj.value);
	var showobj = $(showid);
	showobj.innerHTML = Math.round(len/2);
}
function prompts()
				{
					var content = document.getElementById("post_content").value;
					var len = strLen(content);
					len = Math.round(len/2);
					if(len <= 0)
					{
						alert("请至少输入一个字！");
						return false;
					}
					if(len <= 100)
					{
						credit = 10;
					}
					else
					{
						alert("对不起，字数限制在100字以内！");
						return false;
						//credit = Math.round((len/100)*10);
					}
					str = "您输入了" + len + "个字,将收取您" + credit + "个T币，您确定吗？";
					p = confirm(str);
					if(p)
					{
						return true;
					}
					return false;
				}
function getStrbylen(str, len) {
	var num = 0;
	var strlen = 0;
	var newstr = "";
	var obj_value_arr = str.split("");
	for(var i = 0; i < obj_value_arr.length; i ++) {
		if(i < len && num + byteLength(obj_value_arr[i]) <= len) {
			num += byteLength(obj_value_arr[i]);
			strlen = i + 1;
		}
	}
	if(str.length > strlen) {
		newstr = str.substr(0, strlen);
	} else {
		newstr = str;
	}
	return newstr;
}
function byteLength (sStr) {
	aMatch = sStr.match(/[^\x00-\x80]/g);
	return (sStr.length + (! aMatch ? 0 : aMatch.length));
}
function strLen(str) {
	var charset = document.charset; 
	var len = 0;
	for(var i = 0; i < str.length; i++) {
		len += str.charCodeAt(i) < 0 || str.charCodeAt(i) > 255 ? (charset == "utf-8" ? 3 : 2) : 1;
	}
	return len;
}
function checktcoin()
{
	if(!/^\d+$/.test($('tcoin').value))
	{
		$('tcoin').value = "";
	}
}
function checktcoins() 
{
	if(!/^\d+$/.test($('tcoin').value))
	{
		$('tcoin').value = "";
		$('credit').innerHTML = 0;
	}
	else
	{
		$('credit').innerHTML = $('tcoin').value;
	}
}
function checkStock()
{
	if(!/^-?\d+[\.\d]?\d{0,2}$/.test($('stock_closeprice').value))
	{
		$('stock_closeprice').value = "";
	}
}
function moneycounter()
{
	if($('tcoin').value < 10000)
	{
		$('discount').innerHTML = "无";
		count = $('tcoin').value*0.01;
		count = count.toFixed(2);
		$('money').innerHTML = count;
		$('paym').value = count;
	}
	else if($('tcoin').value >= 10000 && $('tcoin').value < 30000)
	{
		$('discount').innerHTML = "无";
		count = $('tcoin').value*0.01;
		count = count.toFixed(2);
		$('money').innerHTML = count;
		$('paym').value = count;
	}
	else if($('tcoin').value >= 30000 && $('tcoin').value < 50000)
	{
		$('discount').innerHTML = "无";
		count = $('tcoin').value*0.01;
		count = count.toFixed(2);
		$('money').innerHTML = count;
		$('paym').value = count;
	}
	else if($('tcoin').value >= 50000)
	{
		$('discount').innerHTML = "无";
		count = $('tcoin').value*0.01;
		count = count.toFixed(2);
		$('money').innerHTML = count;
		$('paym').value = count;
	}
}
function changeurl_alipay()
{
	document.form1.action = "cp.php?ac=pay&type=alipay";
	$('pay_sub').innerHTML = '<input type="submit" name="sub" id="sub" value="支 付" onClick="return checkmoney();" />';
}
function changeurl_chinabank()
{
	document.form1.action = "pay/chinabank/Send.php";
	$('pay_sub').innerHTML = '<input type="submit" name="sub" id="sub" value="支 付" onClick="a = confirm(\'注意：网银电话卡充值，我们将收取15%的手续费，确定充值吗？\');if(a){return checkmoney();}else{return false;}" />';
}
function checkmoney()
{
	if($('tcoin').value < 100)
	{
		alert("充值T币数量必须大于100个！");
		return false;
	}
	document.getElementById('light').style.display='block';
	document.getElementById('fade').style.display='block';
	return true;
}
function showMyList()
{
	document.getElementById('app_my').style.height = "20px";
	document.getElementById('app_my').style.backgroundColor = "#FFF";
	document.getElementById('app_my').style.borderLeft = "1px solid #D0E2EE";
	document.getElementById('app_my').style.borderTop = "1px solid #D0E2EE";
	document.getElementById('app_my').style.borderBottom = "1px solid #D0E2EE";
	document.getElementById('my_list').style.display = "block";
}
function closeMyList()
{
	document.getElementById('app_my').style.height = "20px";
	document.getElementById('app_my').style.backgroundColor = "";
	document.getElementById('app_my').style.borderLeft = "";
	document.getElementById('app_my').style.borderTop = "";
	document.getElementById('app_my').style.borderBottom = "";
	document.getElementById('my_list').style.display = "none";
}
