function guestbookOnSubmit(max_length){

    $('guestbook-form-submit').disabled = true;
    var t=setTimeout("$('guestbook-form-submit').disabled=false", 10000);

    if ($("guestbook-form-content").value.length > max_length) {
        alert("抱歉, 每条留言至多" + max_length + "个字.\n你输入了" + $("guestbook-form-content").value.length + "个字, 请略作删节.");
        $("guestbook-form-content").focus();
        return false;
    } else if ($("guestbook-form-content").value.length == 0) {
        alert("请填写留言");
        $("guestbook-form-content").focus();
        return false;
    }
    return true;
}

function guestbookOnReplyClick(origin_nick_name, origin_uid, origin_pid) {
    $("guestbook-form-origin-uid").value = origin_uid;
    $("guestbook-form-origin-pid").value = origin_pid;
    $("guestbook-form-content").value = "回复" + origin_nick_name + ": ";
    $("guestbook-form-content").focus();
}

function guestbookOnDeleteClick() {
    return confirm("确定要删除吗?");
}

function photoReplyOnSubmit(max_length){

    $('photo-reply-form-submit').disabled = true;
    var t=setTimeout("$('photo-reply-form-submit').disabled=false", 10000);

    if ($("photo-reply-form-content").value.length > max_length) {
        alert("抱歉, 每条留言至多" + max_length + "个字.\n你输入了" + $("photo-reply-form-content").value.length + "个字, 请略作删节.");
        $("photo-reply-form-content").focus();
        return false;
    } else if ($("photo-reply-form-content").value.length == 0) {
        alert("请填写留言");
        $("photo-reply-form-content").focus();
        return false;
    }
    return true;
}

function photoReplyOnReplyClick(origin_nick_name, origin_uid, origin_rid) {
    $("photo-reply-form-origin-uid").value = origin_uid;
    $("photo-reply-form-origin-rid").value = origin_rid;
    $("photo-reply-form-content").value = "回复" + origin_nick_name + ": ";
    $("photo-reply-form-content").focus();
}

function photoReplyOnDeleteClick() {
    return confirm("确定要删除吗?");
}

function feedSetAsRead(row_id, action_ids, _type, action) {
    new Ajax("/newsfeed.php",
        {
            method: 'post',
            data: {
                act: "setasread",
                action_ids: action_ids,
                type: _type
            },
            onSuccess: function(result) {
                if (action == 1) {
                    $$("#"+row_id+" td").each( function(el){el.addClass("read")} );
                    if ($('#'+row_id)) $('#'+row_id).addClass("read");
                } else if (action == 2) {
                    $$("#"+row_id+" td").each( function(el){el.setStyle("display", "none")} );
                    if ($('#'+row_id)) $('#'+row_id).setStyle("display", "none");
                }
                return;
            },
            onFailure: function() {
                return;
            }
        }
        ).request();
    return true;
}

function feedHide(row_id, action_ids, uid) {

    if (confirm("你真的要隐藏这条个人新鲜事吗?")) {
        new Ajax("/minifeed.php",
            {
                method: 'post',
                data: {
                    act: "hide",
                    action_ids: action_ids,
                    uid: uid
                },
                onSuccess: function(result) {
                    $$("#"+row_id+" td").each( function(el){el.setStyle("display", "none")} );
                    if ($('#'+row_id)) $('#'+row_id).setStyle("display", "none");
                    return;
                },
                onFailure: function() {
                    return;
                }
            }
            ).request();
    }
    return true;
}

function friendDelete(friend_nick_name) {
    return confirm("你真的要把"+friend_nick_name+"从好友们中删除吗?");
}

function friendAddSpecial(friend_nick_name, friend_uid, friend_description, friend_description_maxlen) {
    friend_description = prompt('请用至多'+friend_description_maxlen+'个字来描述'+friend_nick_name+' (这段描述将和TA一起显示在你的个人主页上)', friend_description);
    if (friend_description != null) {
        document.location.href = "http://www.ycool.com/friend.php?act=addspecial&friend_uid="+friend_uid+"&description="+encodeURIComponent(friend_description);
    }
    return false;
}

function friendDeleteSpecial(friend_nick_name) {
    return confirm("你真的要取消"+friend_nick_name+"的特别好友标记吗? (TA将不再显示在你的个人主页上)");
}

function blacklistAdd(nick_name) {
    return confirm("你真的要把"+nick_name+"加到黑名单里去吗?");
}

function blacklistDelete(nick_name) {
    return confirm("你真的要把"+nick_name+"从黑名单里删掉吗?");
}

function copyToClipboard(e) {
    if(!$('flashCopier')){
        var flashCopierDiv = document.createElement('div');
        flashCopierDiv.id = 'flashCopier';
        document.body.appendChild(flashCopierDiv);
    }
    $('flashCopier').innerHTML = '<embed src="http://s.ycstatic.com/yc/clipboard.swf" FlashVars="clipboard='+escape(e.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    e.select();
    alert("已复制, 按 CTRL+V 就可以粘贴出来了.");
    return true;
}
