/**
 * 주소 복사.
 */
function copyUrl()
{
    var res = window.clipboardData.setData('Text', document.URL);

    if (res) {
        alert("주소가 복사되었습니다.");
    } else {
        alert("주소 복사가 실패하였습니다.");
    }
}

/**
 * 관련 기사 검색.
 */
function searchRelArticle()
{
    var xmlHttp = getXmlHttpRequest();
    var title = document.getElementById("main_title").innerHTML;
    var domain = getDomain();

    xmlHttp.open("GET",
            "http://" + domain + "/rel_article.php?title="
            + encodeURI(title),
            false);
    xmlHttp.send();
    if (xmlHttp.status == 200) {
        var div = document.getElementById("rel_article_list");

        var res = xmlHttp.responseText;
        if (!res) {
            return;
            /*
            var listTitle = document.getElementById("rel_title");
            listTitle.innerHTML = "최신 기사";
            res = searchNewArticle("rel_article_list");
            */
        }

        articleList = res.split("||");
        var list = "";
        for (var i = 0; i < articleList.length; i++) {
            var tmpList = articleList[i].split("|");

            list += '<tr height="20">'
                + '<td width="597"><a href="' + tmpList[1]
                + '" target="_blank" class="f13 fc01 ln20">'
                + '<img src="http://img.thescience.co.kr/icon/view_arrow.gif" '
                + 'width="7" height="8" align="absmiddle" '
                + 'style="margin:0 5px 3px 0;">' + tmpList[0] + '</a></td>'
                + '<td align="right" class="f11 fc14" width="73" '
                + 'style="padding:0 0 0 20px;">' + tmpList[2] + '</td>'
                + '</tr>';
        }

        div.innerHTML = '<table width="725" border="0" cellpadding="0" '
            + 'cellspacing="0" style="margin:16px 0 17px 0; '
            + 'background:#ffffff; border:1px solid #c9c9c9; ">'
            + '<tr>'
            + '<td style="padding:16px 0 4px 16px;" class="b fc01 f13">'
            + '관련 기사</td>'
            + '</tr><tr>'
            + '<td style="padding:2px 29px 12px 21px;">'
            + '<table width="671" cellpadding="0" cellspacing="0" '
            + 'border="0">' + list + '</tr></table>'
            + '</tr></table>';
    }
}

/**
 * 최신 기사 검색.
 */
function searchNewArticle()
{
    var xmlHttp = getXmlHttpRequest();
    var domain = getDomain();

    xmlHttp.open("GET",
            "http://" + domain + "/new_article.php",
            false);
    xmlHttp.send();
    if (xmlHttp.status == 200) {
        var res = xmlHttp.responseText;

        return res;
    }
}

/**
 * 많이 본 기사 검색.
 */
function searchBestArticle()
{
    var xmlHttp = getXmlHttpRequest();
    var domain = getDomain();

    xmlHttp.open("GET",
            "http://" + domain + "/best_article.php",
            false);
    xmlHttp.send();
    if (xmlHttp.status == 200) {
        var div = document.getElementById("best_article_list");

        var res = xmlHttp.responseText;
        articleList = res.split("||");

        var list = "";
        for (var i = 0; i < articleList.length; i++) {
            var tmpList = articleList[i].split("|");

            list += "<span class=\"2px_dot\">·</span> <a href=\""
                + tmpList[1] + "\" class=\"fc04 ln18\">" + tmpList[0]
                + "</a><br>";
        }

        div.innerHTML = '<table width="200" border="0" cellpadding="0" '
            + 'cellspacing="0" style="margin:15px 10px 17px 10px; ">'
            + '<tr>'
            + '<td style="padding:0 0 4px 2px;" class="b fc07">인기 '
            + '<span class="fc04 b">기사</span></td>'
            + '</tr>'
            + '<tr>'
            + '<td class="ln20" style="background:#ffffff; border:1px '
            + 'solid #c9c9c9; padding:9px 9px 10px 9px;">'
            + list
            + '</td>'
            + '</tr>'
            + '</table>';
    }
}
