document.write('<script type="text/javascript" src="/js_new/lib/application.js"></script>');
/**
* Get list of guest.
*
*/
var gid = null;
var classid = null;
function listGuest(id,classid) 
{
	if(!id) return false;
	classid = classid || 'guest';
	jsApp.get("Guest:topGuest","id="+id+"&classid="+classid,listSucc,listWait,listFail,"guestList");
	gid = classid = null;
}
function listSucc(o,tar)
{
	//alert(o.responseText);
	$(tar).innerHTML = o.responseText=='error'?'<div class="m_c01_text_ly">留言加载失败</div>':o.responseText;
}
function listWait(o,tar)
{
	$(tar).innerHTML = '正在加载留言……';
}
function listFail(o,tar)
{
	$(tar).innerHTML = '留言加载失败';
}
/**
* Post guest.
*
*/
function postGuest(id,cid)
{
	jsApp.get("Guest:checkUserLimit","",
			   function(o){ if(o.responseText == 'limit') { top.location.href = '/limit.php'; }
			   				else {
								if(!check_content_guest()) return false;
								gid = id; classid = cid;
								jsApp.post("Guest:postGuest","id="+id,postSucc,postWait,postFail,"postMsg","postBtn","postForm");
							}
			   },
			   function(o){},function(o){ alert("信息发送失败！"); }
	);
}
function postSucc(o,tar)
{
	//alert(o.responseText);
	try {
		if(o.responseText == 'ok') {
			//$(tar).innerHTML = '<img src="'+imgRoot+'isucc_01.jpg" width="29" height="29" align="absmiddle" /> 评论发表成功！';
			showMsgHtml(tar,'succ');
			if($('commentCount'))
				$('commentCount').innerHTML = parseInt($('commentCount').innerHTML) + 1;
			$('content').value = '';
			$('remLen').innerHTML = '600';
			setTimeout("postFinish()",2000);
		}else if(o.responseText == 'error')
			//$(tar).innerHTML = '<img src="'+imgRoot+'ierror_01.jpg" width="29" height="29" align="absmiddle" /> 评论发表失败！';
			showMsgHtml(tar,'fail');
		else {
			$(tar).innerHTML = '<img src="'+imgRoot+'ierror_01.jpg" width="29" height="29" align="absmiddle" /> '+o.responseText+'！';
		}
	}catch(e) {}
}
function postWait(o,tar)
{
	//$(tar).style.display = 'block';
	//$(tar).innerHTML = '<img src="'+imgRoot+'iload_01.gif" width="19" height="18" align="absmiddle" /> 正在提交评论……';
	showMsgHtml(tar,'load');
}
function postFail(o,tar)
{
	//$(tar).style.display = 'block';
	//$(tar).innerHTML = '<img src="'+imgRoot+'ierror_01.jpg" width="29" height="29" align="absmiddle" /> 评论发表失败！';
	showMsgHtml(tar,'succ');
}
function postFinish()
{
	$('postMsg').style.display = 'none';
	$('postMsg').innerHTML = '';
	//alert(gid+' '+classid);
	listGuest(gid,classid);
}
/**
* show messages
*/
function showMsgHtml(tar,type)
{
	$(tar).style.display = 'block';
	switch(type) {
		case 'succ': var msg = '<img src="'+imgRoot+'isucc_01.jpg" width="29" height="29" align="absmiddle" /> '+(!classid || classid=='guest'?'留言':'评论')+'发表成功！';
					 break;
		case 'load':var msg = '<img src="'+imgRoot+'iload_01.gif" width="19" height="18" align="absmiddle" /> 正在提交'+(!classid || classid=='guest'?'留言':'评论')+'……'; break;
		case 'fail':var msg = '<img src="'+imgRoot+'ierror_01.jpg" width="29" height="29" align="absmiddle" /> '+(!classid || classid=='guest'?'留言':'评论')+'发表失败！'; break;
	}
	$(tar).innerHTML = msg;
}



function showDel(u)
{
	$('delete_'+u).style.display = 'block';
	$('bg_'+u).style.backgroundColor='#CCCCCC';
	//alert($('bg_'+u));
	var cList = $('bg_'+u).getElementsByTagName('span');
	for(var i=0;i<cList.length;i++)
		cList[i].style.color = '#000000';
}
function hiddDel(u)
{
	$('delete_'+u).style.display = 'none';
	$('bg_'+u).style.backgroundColor='#FFFFFF';
	var cList = $('bg_'+u).getElementsByTagName('span');
	for(var i=0;i<cList.length;i++)
		cList[i].style.color = '#999999'
}

function textCounter(field,countfield,maxlimit)
{
	//var filterValue = field.value.replace(//g,'');
	var totallength=0;  
	var s = "";
	for (var i=0;i<field.value.length;i++)
	{
		var intCode=field.value.charCodeAt(i);
		if (intCode>=0&&intCode<=128) 
		{
			if(maxlimit - totallength >= 1)
			{
			   s += field.value.charAt(i);
			   totallength=totallength+1; //非中文单个字符长度加 1
			}
		}
		else 
		{
		    if(maxlimit - totallength >= 3)
			{
				s += field.value.charAt(i);
				totallength=totallength+3; //中文字符长度则加 3
			}
		}
	 }
	 //field.value = s;
	 if(maxlimit - totallength == 0)
	 {
		//field.value = s;
	 }
	 document.getElementById(countfield).innerHTML = "<span style='font:#ff0000;'>"+(maxlimit - totallength)+"</span>";
}
function check_content_guest(w)
{	
	if(!w) {
		var u = $('content');
	}else {
		var u = $('content_'+w);
	}
	if(u.value.length<1 || u.value.match(/^\s+$/)) {
			window.alert('留言内容不能为空');
			u.focus();
			return false;
	}else if(u.value.length>600) {
			window.alert('留言内容不能超过600个字');
			u.focus();
			return false;
	}
	return true;
}

