﻿function PrepareEmote(page) {
    var ajax = new Ajax();
    var url = "Emote.aspx?Page=" + page;
    ajax.RequestURL(url, DealEmote);
}
function DealEmote(data) {
    var divObj = document.getElementById("emoteBox");
    divObj.innerHTML = data;
}

function Prepare() {
    var EmoteBox = document.getElementById("emoteBox");
    var InsertBtn = document.getElementById("insertBtn");
    var bigEmoteDivObj = document.getElementById("BigEmoteDiv");
    var biEmoteObj = document.getElementById("BigEmote");
    if (InsertBtn != null) {
        InsertBtn.onmouseout = function() {
            EmoteBox.style.display = "none";
            InsertBtn.className = "insertBtn";
        }
        InsertBtn.onmouseover = function() {

            if (EmoteBox.innerHTML == '') {
                PrepareEmote();
            }
            EmoteBox.style.display = "block";
            InsertBtn.className = "insertBtn-on";
        }
    }
    if (EmoteBox != null) {
        EmoteBox.onmouseover = function() {
            EmoteBox.style.display = "block";
            InsertBtn.className = "insertBtn-on";
        }
   
        EmoteBox.onmouseout = function() {
            EmoteBox.style.display = "none";
            InsertBtn.className = "insertBtn";
        } 
    }
}
function ShowBigEmote(obj, bigEmote) {
    var bigEmoteDivObj = document.getElementById("BigEmoteDiv");
    var biEmoteObj = document.getElementById("BigEmote");
    bigEmoteDivObj.style.display = "";
    if (obj.offsetLeft < 150) {
        bigEmoteDivObj.style.left = "";
        bigEmoteDivObj.style.right = "0px";
    }
    else {
        bigEmoteDivObj.style.right = "";
        bigEmoteDivObj.style.left = "0px"; 
    }
    biEmoteObj.src = bigEmote;
}
function HideEmote() {
    var bigEmoteDivObj = document.getElementById("BigEmoteDiv");
    bigEmoteDivObj.style.display = "none";
}
function SelectBigEmote(bigEmote) {
    var contentObj = document.getElementById("ctl00$MainContent$Content");
    contentObj.value += "[emote]" + bigEmote + "[/emote]";
    var numberObj = document.getElementById("number");
    numberObj.innerHTML = 300 - contentObj.value.length;
    var EmoteBox = document.getElementById("emoteBox");
    EmoteBox.style.display = "none";
}

function PrepareCheckContentNumber() {
    var contentObj = document.getElementById("ctl00$MainContent$Content");
    if (contentObj != null) {
        contentObj.onchange = function() {
            CheckContentNumber();
        }
        contentObj.onblur = function() {
            CheckContentNumber(); 
        }
        contentObj.onkeyup = function() {
            CheckContentNumber();
        }
        contentObj.onpaste = function() {
            contentObj.blur();
        }
        contentObj.oncut = function() {
            contentObj.blur();
        }
    }
}
function CheckContentNumber() {
    var contentObj = document.getElementById("ctl00$MainContent$Content");
    var numberObj = document.getElementById("number");
    numberObj.innerHTML = 300 - contentObj.value.length;
    if (300 - contentObj.value.length < 0) {
        contentObj.value = contentObj.value.substring(0, 299);
        numberObj.innerHTML = 0; 
    }
}

//复制
function CopyClipboard(clipBoardContent, msg) {
    if (window.clipboardData) {
        window.clipboardData.clearData();
        window.clipboardData.setData("Text", clipBoardContent);
        alert(msg);
    }
    else if (navigator.userAgent.indexOf("Opera") != -1) {
        window.location = clipBoardContent;
    } else if(window.netscape){
        try {
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
        } catch (e) {
            alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");
            return false;
        }
        var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
        if (!clip)
            return;

        var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
        if (!trans)
            return;
        trans.addDataFlavor('text/unicode');
        var str = new Object();
        var len = new Object();
        var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
        var copytext = clipBoardContent;
        str.data = copytext;
        trans.setTransferData("text/unicode", str, copytext.length * 2);
        var clipid = Components.interfaces.nsIClipboard;
        if (!clip)
            return false;
        clip.setData(trans, null, clipid.kGlobalClipboard);
        alert(msg);
        }
}
