﻿
var ajax;

function CheckForm(formObj)
{
    if (formObj.authcode.value.match(/^\w{4}$/gi) == null) return alert("请仔细填写好验证码的内容."), false;
    if (formObj.content.value.replace(/\s+/gi).length == 0) return alert("请填写好您的评论内容."), false;
    if (formObj.content.value.length >= 500) return alert("评论内容请保持在500字以内,或者您可以分为多次发表."), false;
}

function InsertEmotion(imgObj)
{
    if (null == imgObj) return;
    var src = imgObj.src;
    src = src.replace(/^.*?\/face\/(\w+)\.gif$/gi, "[$1]");
    if (src.match(/^\[\w+\]$/gi) == null) return;
    
    var txtObj = GetE("content");
    if (null == txtObj) return;
    
    txtObj.focus();
    if (document.selection)
    {
        document.selection.createRange().text = src;
    }
    else if(typeof(txtObj.selectionStart) != "undefined")
    {
        txtObj.value = txtObj.value.replace(new RegExp("^([\\s\\S]{" + txtObj.selectionStart + "})([\\s\\S]{" + (txtObj.selectionEnd - txtObj.selectionStart) + "})([\\s\\S]*)$", "gi"), "$1" + src + "$3");
    }
    txtObj.focus();
}

function loadInfo()
{
    ajax = CreateAjax();
    Send(ajax, '/comments/details.jsp?type=' + GetE('type').value + '&sid=' + GetE('sid').value, 'GET', null, _loadInfo, true, true);
}

function _loadInfo()
{
    if (null == ajax) return;
    if (4 != ajax.readyState) return;
    if (200 == ajax.status)
    {
        var info = null;
        eval('info=' + ajax.responseText);
        if (info != null)
        {
            GetE('_title').innerHTML = info.Title;
            GetE('_title').href = info.Url;
            document.title = info.Title;
        }
    }
    ajax = null;
}
