// -*- Encoding: euc-jp; -*-
function reply(id)
{
    document.tanaka.Body.focus();
    document.tanaka.elements["In-Reply-To"].value = id;
    if ( id != "" )
    {
//      document.tanaka.Subject.disabled = true;
        document.tanaka.submit.value = "返";
    }
}

function reply_select(obj)
{
    if ( obj.value == "" )
    {
//      document.tanaka.Subject.disabled = false;
        document.tanaka.submit.value = "送";
    }
    else
    {
//      document.tanaka.Subject.disabled = true;
        document.tanaka.submit.value = "返";
    }
}

function get_cookie(key)
{
    if (document.cookie)
    {
	search = key + "=";
	start = document.cookie.indexOf(search);
	if (start != -1)
	{
	    start += search.length;
	    end = document.cookie.indexOf(";", start);
	    if (end == -1)
		end = document.cookie.length;
	    return(unescape(document.cookie.substring(start, end)));
	}
    }

    return false;
}

function check_form()
{
    if (!document.tanaka.From.value.length || !document.tanaka.Body.value.length)
    {
	alert("名前と本文書きましたか。");
	document.tanaka.From.focus();
	return false;
    }

    date = new Date();
    date.setTime(date.getTime() + (30 * 24 * 60 * 60 * 1000));
    expires = date.toGMTString();
    document.cookie = "From=" + escape(document.tanaka.From.value) + ";expires=" + expires + ";path=/";
}

function get_cookies()
{
    from = get_cookie("From");
    if (from) document.tanaka.From.value = from;
}

function linkPrompt() {
    if (!document.selection) return;
    var str = document.selection.createRange().text;
    if (!str) return;
    var default_url = "http://";
    regex = "^s?https?://[-_.!~*'()a-zA-Z0-9;/?:@&=+$,%#]+$";
    var cbText = clipboardData.getData("Text");
    if(cbText && cbText.match(regex)) default_url = cbText;
    var url = prompt('URL: ', default_url);
    if ( url != null )
        document.selection.createRange().text = '{' + str + '|' + url + '}';
}

function toggle_disp(id)
{
    if ( elm = document.getElementById(id) )
        elm.style.display = ( elm.style.display == "none" ? "" : "none" );
}

function toggle_body(id)
{
    var article = document.getElementById(id);
    if ( article )
    {
        var nodes = article.childNodes;
        for ( var i=0; i < nodes.length; i++ )
        {
            if ( nodes[i].tagName == "TABLE" )
            {
                nodes[i].style.display = ( nodes[i].style.display == "none" ? "" : "none" );
                break;
            }
        }
    }
}

