// XMLを読み込むための処理
function XmlReader() {
    this.xml = null;
    this.handler = null;
    try {
        if (isSafari()) {
            this.xml = new XMLHttpRequest();
            this.xml.onload = handleXmlEvent;
        } else if( document.implementation && document.implementation.createDocument ) {
            this.xml = document.implementation.createDocument("", "", null);
            this.xml.onload = handleXmlEvent;
        } else {
            this.xml = new ActiveXObject("Microsoft.XMLDOM");
            this.xml.onreadystatechange = handleXmlEvent;
        }
    } catch (e) {
        alert("XMLに未対応:" + e);
    }

    this.readXml = function(filePath, handler){
        this.handler = handler;
        if (this.xml == null) {
            this.handler(null);
        }
        if (isSafari() ) {
            try{
                this.xml.open("GET", filePath, true);
                this.xml.send(null);
            } catch (e) {
                handler(null);
            }
         } else {
            this.xml.load(filePath);
        }
    }
}

xmlReader = new XmlReader();

function handleXmlEvent() {
    if (xmlReader.xml.readyState) {
        if (xmlReader.xml.readyState == 4) {
            if(xmlReader.xml.parseError && xmlReader.xml.parseError.status) {
                if (xmlReader.xml.parseError.status == 200) {
                    xmlReader.handler(xmlReader.xml);
                } else {
                    xmlReader.handler(null);
                }
            } else {
                xmlReader.handler(xmlReader.xml);
            }
        }
     } else {
        xmlReader.handler(xmlReader.xml);
     }
}

function isIE() {
    if( document.implementation && document.implementation.createDocument ) {
        return false;
    }
    return true;
}

function isKonqueror() {
    var ua = navigator.userAgent;
    return (ua.indexOf("Konqueror") != -1);
}

function isSafari() {
    // とりあえずDashboardはブラウザの振舞としてはSafariと見做す
    if (window.widget) {
        return true;
    }
    var ua = navigator.userAgent;
    return (ua.indexOf("Safari") != -1);
}

