// Misc
function hasWindowExternal() {
    return (typeof(window.external) != 'undefined');
}

function hasWindowSidebar() {
    return (typeof(window.sidebar) != 'undefined');
}
// /Misc

// Focus
function setFocus(id) {
    if (typeof(document.getElementById) != 'undefined') {
        var obj = document.getElementById(id);
        if (obj) {
            obj.focus();
        }
    }
}
// /Focus

// Move
function moveTo(url, qp, id, ie, op) {
    var q = document.forms[0].q.value;
    if (typeof(encodeURIComponent) == 'function') {
        var eq = encodeURIComponent(q);
        location.href = url + '?' + (op ? op + '&' : '') + 'ie=utf8&' + qp + '=' + eq;
        return false;
    }
    if (ie) {
        window.location.href = url + '?' + (op ? op + '&' : '') + 'ie=' + ie + '&' + qp + '=' + q;
        return false;
    }
    window.location.href = url + '?' + qp + '=' + q;
    return false;
}
// /Move

// Favorite
function writeFavoriteLink(favoriteName, favoriteUrl, searchProviderXml, searchEngineSrcBase) {
    if (hasAddSearchProvider()) {
        var src;
        src = '';
        src += '<a href="#" onclick="addSearchProvider(';
        src += '&quot;' + searchProviderXml + '&quot;';
        src += ')">ブラウザに追加</a>';
        document.write(src);
    } else if (hasAddSearchEngine()) {
        var src;
        src = '';
        src += '<a href="#" onclick="addSearchEngine(';
        src += '&quot;' + favoriteName + '&quot;, &quot;' + searchEngineSrcBase + '&quot;';
        src += ')">ブラウザに追加</a>';
        document.write(src);
    } else if (hasAddFavorite()) {
        var src;
        src = '';
        src += '<a href="#" onclick="addFavorite(';
        src += '&quot;' + favoriteName + '&quot;, &quot;' + favoriteUrl + '&quot;';
        src += ')">お気に入りに登録</a>';
        document.write(src);
    } else {
        var src;
        src = '';
        src += '<a href="http://docs.livedoor.com/dokodemo/bookmark.html">お気に入りに登録</a>';
        document.write(src);
    }
}

function hasAddFavorite() {
    if (hasWindowExternal()) {
        try {
            return  (typeof(window.external.AddFavorite) != 'undefined');
        } catch (e)
        {
        }
    }
    return false;
}

function addFavorite(favoriteName, favoriteUrl) {
    if (hasAddFavorite()) {
        window.external.AddFavorite(favoriteUrl, favoriteName);
    } else {
        document.location.href = "http://docs.livedoor.com/dokodemo/bookmark.html";
    }
}

function hasAddSearchProvider() {
    if (hasWindowExternal()) {
        try {
            return (typeof(window.external.AddSearchProvider) != 'undefined');
        } catch (e)
        {
        }
    }
    return false;
}

function addSearchProvider(searchProviderXml) {
    if (hasAddSearchProvider()) {
        window.external.AddSearchProvider(searchProviderXml);
    }
}

function hasAddSearchEngine() {
    if (hasWindowSidebar()) {
        return (typeof(window.sidebar.addSearchEngine) != 'undefined');
    }
    return false;
}

function addSearchEngine(favoriteName, searchEngineSrcBase) {
    if (hasAddSearchEngine()) {
        window.sidebar.addSearchEngine(
            searchEngineSrcBase + '.src',
            searchEngineSrcBase + '.gif',
            favoriteName,
            ''
        );
    }
}
// /Favorite

function size() {
    var fsize = [ 'xx-small' , 'small', 'large' ];
    var csize = 1;
    if (getCookie("f")) { csize = getCookie("f") };
    document.write ("<style type=text/css>");
    document.write ("#content {font-size:" + fsize[csize] + ";}");
    document.write ("</style>");
}
function isize() {
    var csize = 1;
    if (getCookie("f")) { csize = getCookie("f") };
    document.write ("<div align=right><div style=margin-bottom:10px;>");
    document.write ("<small>文字サイズ&nbsp;&nbsp;");
    if (csize == 2) { document.write ("<strong>大</strong>&nbsp;-&nbsp;"); }
        else { document.write ("<a href=javascript:dsize(2);>大</a>&nbsp;-&nbsp;");};
    if (csize == 1) { document.write ("<strong>中</strong>&nbsp;-&nbsp;"); }
        else { document.write ("<a href=javascript:dsize(1);>中</a>&nbsp;-&nbsp;");};
    if (csize == 0) { document.write ("<strong>小</strong>");}
        else { document.write ("<a href=javascript:dsize(0);>小</a>");};
    document.write ("</small></div></div>");
}

function dsize(size) {
    var setday = new Date();
    setday.setTime(setday.getTime()+1000*60*60*24*365);
    var expires= setday.toGMTString();
    document.cookie = "f=" + size +"; expires=" + expires + "; path=/;";
    window.location.reload();
    return "";
}

function hasCookieFunction() {
    if (typeof(document.cookie) != 'undefined') {
        return true;
    }
    return false;
}

function getCookie(id) {
    if (hasCookieFunction()) {
        var ida = id + "=";
        var idlen = ida.length;
        var clen = document.cookie.length;
        var i = 0;
        while (i < clen) {
            var j= i + idlen;
            if (document.cookie.substring(i, j) == ida) {
                var endstr = document.cookie.indexOf(";", j);
                if (endstr == -1) {
                    endstr = document.cookie.length;
                }
                return unescape(document.cookie.substring(j, endstr));
            }
            i = document.cookie.indexOf(" ", i) + 1;
            if (i == 0) break;
        }
    }
    return "";
}
