function check()
{
    var msg = "";
    if (!document.all["uName"].value)
        msg += "請填寫您的稱呼\n";

    if (!document.all["uContent"].value)
        msg += "請填寫留言內容\n";

    if ("" != msg)
    {
        alert(msg);
        return false;
    }

    return true;
}

function styleString(format)
{
    document.noteForm.uContent.focus();
    
    if (document.selection)
    {
        var s = document.selection.createRange().text;
        if (s)
        {
            document.selection.createRange().text = "<" + format + ">" + s + "</" + format + ">";
        }
        else
            alert("請先選取文字");
    }
    else
    {   // for other browser
        var input = prompt("Enter the string:", "");
        
        if (input)
        {
            var old = document.getElementById("uContent").value;
            var s = "<" + format + ">" + input + "</" + format + ">";
            document.getElementById("uContent").value = old + s;
        }    
    }
}

function doPreview(source)
{
    var form = document.noteForm;
    if (!form)
        return;
    
    var err = "";
    if (!form.uName.value)
        err += "請輸入稱呼\n";

    if (!form.uContent.value)
        err += "請輸入留言\n";

    if ("" != err)
    {
        alert(err);
        return;
    }

    form.action = "./previewNote.php";
    form.target = "preview";
    
    window.open("./previewNote.php", "preview", "resizable=yes,status=no,width=500, height=200");
    form.submit();

    form.action = source;
    form.target = "_self";
}

function switchFeelingIcon()
{
    if ("" == document.all["FeelingIcon"].style.display)
    {
        document.all["FeelingIcon"].style.display = "none";
        document.all["moreFeeling"].innerText = "更多";
    }
    else
    {
        document.all["FeelingIcon"].style.display = "";
        document.all["moreFeeling"].innerText = "關閉";
    }
}

function addEm(s, t)
{
    if ("note" == t)
    {
        document.noteForm.uContent.value += s;
        document.noteForm.uContent.focus();
    }
    else if ("reply" == t)
    {
        document.replyForm.replyBody.value += s;
        document.replyForm.replyBody.focus();
    }
}

function changeFeeling(n)
{
    document.all["uFeelingImg"].src = "./pic/feeling/" + n + ".gif";
    document.all["uFeeling"].value = n;
}

function spotElm(s)
{
    s.style.position = "relative";
    s.style.top = -2;
    s.style.background = "#E3F0FF";
}

function unSpotElm(s)
{
    s.style.position = "relative";
    s.style.top = 0;
    s.style.background = "#FFFFFF";
}

