// 评论时插入回复
var fnInsertReply = function(label_reply, url, rid, author_name) {
    $('text_comment').innerHTML += '['+label_reply+']&nbsp;&lt;strong&gt;&lt;a href=\''+url+'#'+rid+'\'&gt;@'+author_name+':&lt;/a&gt;&lt;/strong&gt;';
}

// 评论时插入引用
var fnInsertQuote = function(label_quote, url, rid, author_name, content) {
    $('text_comment').innerHTML += getHtmlEntity('['+label_quote+']&nbsp;&lt;blockquote cite='+url+'#'+rid+'&gt;&lt;strong&gt;&lt;a href='+url+'#'+rid+'&gt;'+author_name+'&lt;/a&gt; :&lt;/strong&gt;&lt;p&gt;['+content+']…&lt;/p&gt;&lt;/blockquote&gt;');
}

// 插入值
var fnInsertEditor = function(sVal){
    $('text_comment').value += sVal;
}

// 提交表单
var fnSubForm = function(actionUrl) {
    oForm = document.form1;

    var name  = oForm.elements['text_name'].value;
    var email = oForm.elements['text_email'].value;
    var site = oForm.elements['text_website'].value;
    var comment = oForm.elements['text_comment'].value;

    // 验证用户名
    flag = name.length > 2;
    if(!flag || name=='Name'){
        $('notice_name').innerHTML = ("<font color=red>input error!</font>");
        oForm.text_name.focus();
        return false;
    } else {
        $('notice_name').innerHTML = ("<font color=green>OK!</font>");
    }

    // 验证邮件
    var pattern1 = /^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
    flag = pattern1.test(email);
    if(!flag){
        $('notice_email').innerHTML = ("<font color=red>input error!</font>");
        oForm.text_email.focus();
        return false;
    } else {
        $('notice_email').innerHTML = ("<font color=green>OK!</font>");
    }

    // 验证站点
    if(site == '' || site == 'Website') {
        site.value = '';
        $('notice_website').innerHTML = ("<font color=green>OK!</font>");
    } else {
        var pattern2 = /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/;
        flag = pattern2.test(site);
        if(!flag){
            $('notice_website').innerHTML = ("<font color=red>input error!</font>");
            oForm.text_website.focus();
            return false;
        } else {
            $('notice_website').innerHTML = ("<font color=green>OK!</font>");
        }
    }

    // 检查留言内容的字数
    if (comment.length > 5000 || comment.length < 5) {
        $('comment_notice_relative').style.display = 'block';
        oForm.text_comment.focus();
        return false;
    }
    
    oForm.action = actionUrl;
    oForm.submit();
}

// 关闭评论提示窗口
var fnClockNoticeComment = function() {
    $('comment_notice_relative').style.display = 'none';
}

var fnFocus = function(obj, val) {
    if (obj.value == val) {obj.value = '';}
}

var fnBlur = function(obj, val) {
    if (obj.value == '') {obj.value = val;}
}