function v(objName) {

	return trim($(objName).value);
}

function checkTitle(id){

	var objName = id;
	var title = v(objName);

	if (title==''){
		alert('请填写标题');
		return false;
	}

	var len=getLen(title);
	if(len > 70){
		alert('标题过长，请修改');
		return false;
	}
}

function checkContent() {

	var objName = 'content';
	var content = v(objName);

	if (content==''){
		alert('请填写评论内容');
		return false;
	}

}

function updateverifyCode() {

	if ($('verifyCodePic').style.display == 'none') {
		changeverifycode();
	}
}

function changeverifycode() {
	var s=$('verifyCodePic');
	if(s){
		s.style.display = 'none';
		s.src = 'http://submit.tieba.pchome.net/verifyCode.php?system=download&rand='+Math.random();
		s.style.display = '';
	}
}

function ajaxVerify(url) {

		var x = new Ajax('HTML');

		x.get(url, function(result) {

			if(result!=''){
				changeverifycode();
				alert(result);
			}else{
				$('comment').submit();
			}

		});

}

function checkverifyCode() {

	var objName = 'verifyCode';
	var code = v(objName);

	var regExp = /^[0-9]{4,5}$/;

	if (code==''){
		alert('请填写验证码');
		return false;
	}

	if (!regExp.test(code)) {

		alert('不正确的验证码，验证码为 4-5 位的数字');
		return false;
	}

	//ajaxVerify('/js/verifyCode.php?type=check&code='+code);

	$('comment').submit();
}

function threadSubmit(){

	var flag=true;

	flag=checkTitle('title');
	if(flag==false)return;

	flag=checkContent();
	if(flag==false)return;

	checkverifyCode();
}

function postSubmit(){

	var flag=true;

	flag=checkContent();
	if(flag==false)return;

	checkverifyCode();
}

function ctrlEnterSubmit(event){

	if((event.ctrlKey && event.keyCode == 13)) {
		$('button3').click();
		//threadSubmit();
		//$('comment').submit();
	}
}

function enterSubmit(event){

	if((event.keyCode == 13)) {
		$('postbutton').click();
	}
}

//回复引用

function html_trans(str) {
	var str;
	str = str.replace(/<\/embed>/ig,"");
    str = str.replace(/[\r\n]/g,"");
	str = str.replace(/<b>(.*?)<\/b>/ig,"[b]$1[/b]");
	str = str.replace(/<i>(.*?)<\/i>/ig,"[i]$1[/i]");
	str = str.replace(/<u>(.*?)<\/u>/ig,"[u]$1[/u]");
	str = str.replace(/<font[^>]+color="([^">]+)"[^>]*>(.*?)<\/font>/ig,"[color=$1]$2[/color]");
	str = str.replace(/<font[^>]+color=([^ >]+)[^>]*>(.*?)<\/font>/ig,"[color=$1]$2[/color]");
	str = str.replace(/<embed[^>]+src=([^ ]+)[^>]*>/ig,"[swf=$1][/swf]");
	str = str.replace(/<embed[^>]+src="([^"]+)"[^>]*>/ig,"[swf=$1][/swf]");
	str = str.replace(/<br><a[^>]+href="(http|https|mms|rstp|ed2k|ftp|news|thunder|tencent|gopher|telnet)([^"]+)"[^>]*><img[^>]+src="([^"]+)"[^>]*><\/a><br>/ig,"[img=$3][/img]");
	str = str.replace(/<a[^>]+href="(http|https|mms|rstp|ed2k|ftp|news|thunder|tencent|gopher|telnet)([^"]+)"[^>]*>(.*?)<\/a>/ig,"[url=$1$2]$3[/url]");
	str = str.replace(/<blockquote>/ig,"[quote]");
	str = str.replace(/<\/blockquote>/ig,"[/quote]");
	str = str.replace(/<br>/ig,"[br]");
	str = str.replace(/&nbsp;/g," ");
	str = str.replace(/&amp;/g,"&");
	str = str.replace(/&quot;/g,"\"");
	str = str.replace(/&lt;/g,"<");
	str = str.replace(/&gt;/g,">");
    return str;
}

function quoteMsg(msgId){

    var msgObj  = $('__Message_' + msgId);

	var quoteHTML=html_trans(msgObj.innerHTML);

    var quoteMessage = "[quote]" + quoteHTML + "[/quote]";

	$('content').focus();

	$('content').value=quoteMessage;

}