var userag = 0;

if ( navigator.userAgent.match(/MSIE.*Win/) && !navigator.userAgent.match(/Opera/) ) {
  var userag = 1;
}


if ( userag == 0 ) {

/*
document.write.js Copyright 2006, "Nyarla," <thotep@nyarla.net>

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/

document.write = function () {
    var self = document.write.prototype;

    var content = Array.prototype.slice.call(arguments);
    var current = self.getCurrent();

    self.addContent( content, current );
}

document.write.prototype = {
    'getCurrent'    : function () {
        return (function (e) {
            if ( e.nodeName.toLowerCase() == 'script') return e;
            return arguments.callee(e.lastChild)
        })(document);
    },
    'addContent'    : function ( content, current ) {
        var buffer = document.write.buffer;

        var currentNum  = buffer.length;
        var lastNum     = currentNum - 1;

        if ( lastNum < 0 ) {
            currentNum  = 1;
            lastNum     = 0;
        }

        if ( typeof(buffer[lastNum]) == 'undefined' ) {
            buffer[lastNum]         = {};
            buffer[lastNum].script  = current;
            buffer[lastNum].content = content;
        }
        else if ( buffer[lastNum].script == current ) {
            buffer[lastNum].content = buffer[lastNum].content.concat( content );
        }
        else {
            buffer[currentNum]          = {};
            buffer[currentNum].script   = current;
            buffer[currentNum].content  = content;
        }
    },
    'text2xmldom'   : function ( text ) {
        var xmldom;
        text = text.replace(/&amp;/g, '&').replace(/&/g, '&amp;');
        text = '<div>'+ text + '</div>';
        // Firefox, Safari, Opera
        if ( window.DOMParser ) {
            var parser = new DOMParser();
            xmldom = parser.parseFromString( text, 'application/xml' );
        }
        // Internet Exprorer 7 ?
        else if ( window.ActiveXObject ) {
            var parser = new ActiveXObject('Microsoft.XMLDOM');
            parser.async = false;
            xmldom = parser.loadXML( text );
        }
        else {
            return;
        }

        var root = xmldom.documentElement;
        if ( !root ) { return }
        return root;
    },
    'xmldom2htmldom'    : function ( xmldom ) {
        var self = this;
        if ( !xmldom.nodeType ) { return }
        var htmldom;
        
        switch ( xmldom.nodeType ) {
            case 1: // ElementNode
                htmldom = document.createElement( xmldom.nodeName );
                // parse Attributes
                if (
                    xmldom.attributes
                    && xmldom.attributes.length
                ) {
                    var attributes = xmldom.attributes;
                    for ( var i = 0, len = attributes.length; i < len; i++ ) {
                        var attribute = attributes[i];

                        var name = attribute.nodeName;
                        if ( typeof(name) != 'string' ) { continue }

                        var value = attribute.nodeValue;
                        if ( !value ) { continue }

                        htmldom.setAttribute( name, value );
                    }
                }

                // parse ChildNodes
                if (
                    xmldom.childNodes
                    && xmldom.childNodes.length
                ) {
                    var childNodes = xmldom.childNodes;
                    for ( var i = 0, len = childNodes.length; i < len; i++ ) {
                        var childNode = self.xmldom2htmldom( childNodes[i] );
                        if ( !childNode ) { continue }
                        if ( childNode.nodeType == 1 || childNode.nodeType == 3 ) {
                            htmldom.appendChild( childNode );
                        }
                    }
                }
                break;
            case 3: // TextNode
                htmldom = document.createTextNode( xmldom.nodeValue );
                break;
            case 4: // CDATASectionNode
                htmldom = document.createTextNode( xmldom.nodeValue );
                break;
            }
        return htmldom;
    },
    'text2dom'      : function ( text ) {
        var self = this;

        var xmldom = self.text2xmldom( text );
        if ( !xmldom ) { return }

        var html = self.xmldom2htmldom( xmldom );
        if ( !html ) { return }

        return html;
    },
    'run'           : function () {
        var self = document.write.prototype;
        var buffer = document.write.buffer;
        for ( var i = 0, len = buffer.length; i < len; i++ ) {
            var buf = buffer[i];

            var referenceNode   = buf.script;
            var parent          = referenceNode.parentNode;
            var root            = self.text2dom( buf.content.join('') );

            if ( !root ) { continue }

            if (
                root.childNodes
                && root.childNodes.length
            ) {
                var childNodes = root.childNodes;
                for ( var j = 0, c_len = childNodes.length; j < len; j++ ) {
                    var childNode = childNodes[j];
                    if ( !childNode ) { continue }
                    parent.insertBefore( childNode, referenceNode.nextSibling );
                }
            }
        }
    }
};

document.write.buffer = [];
document.write.run = document.write.prototype.run;

document.writeln = function () {
    var self = document.write.prototype;

    var content = Array.prototype.slice.call(arguments);
    var current = self.getCurrent();

    content[content.length - 1] += "\n";

    self.addContent( content, current );
}

document.writeln.run = document.write.prototype.run;

}


// アクセス解析のためCGIを呼び出す
document.write("<div id='rep'><img src='http://kita2.net/report/acclog.cgi?");
document.write("referrer="+document.referrer+"&");
document.write("width="+screen.width+"&");
document.write("height="+screen.height+"&");
document.write("color="+screen.colorDepth+"' /></div>");


if ( userag == 0 ) {

document.write.run();
//document.write();

}

