﻿var isIE=1;

if (!window.ActiveXObject) {
    isIE = 0;
}

//function clickIE() { if (document.all) { return false; } }
//function clickNS(e) {
//    if
//(document.layers || (document.getElementById && !document.all)) {
//        if (e.which == 2 || e.which == 3) { return false; }
//    }
//}
//if (document.layers)
//{ document.captureEvents(Event.MOUSEDOWN); document.onmousedown = clickNS; }
//else { document.onmouseup = clickNS; document.oncontextmenu = clickIE; }
//document.oncontextmenu = new Function("return false");

function getDomAdapter() {
    var adapter = '';
    if ('undefined' != typeof ActiveXObject) {
        adapter = 'MS';
    } else if ('undefined' != typeof document
		&& document.implementation
		&& document.implementation.createDocument
		&& 'undefined' != typeof DOMParser) {
        adapter = 'default';
    }
    switch (adapter) {
        case 'MS':
            return new (function() {
                this.createDocument = function() {
                    var names = ["Msxml2.DOMDocument.6.0",
						"Msxml2.DOMDocument.3.0", "MSXML2.DOMDocument",
						"MSXML.DOMDocument", "Microsoft.XMLDOM"];
                    for (var key in names) {
                        try {
                            return new ActiveXObject(names[key]);
                        } catch (e) { }
                    }
                    throw new Error('Unable to create DOMDocument');
                };
                this.serialize = function(doc) {
                    return doc.xml;
                };
                this.parseXml = function(xml) {
                    var doc = this.createDocument();
                    if (!doc.loadXML(xml)) {
                        throw new Error('Parse error');
                    }
                    return doc;
                };
            })();
        case 'default':
            return new (function() {
                this.createDocument = function() {
                    return document.implementation.createDocument("", "", null);
                };
                this.serialize = function(doc) {
                    return new XMLSerializer().serializeToString(doc);
                };
                this.parseXml = function(xml) {
                    var doc = new DOMParser().parseFromString(xml, "text/xml");
                    if ("parsererror" == doc.documentElement.nodeName) {
                        throw new Error('Parse error');
                    }
                    return doc;
                };
            })();
        default:
            throw new Error('Unable to select the DOM adapter');
    }
}

function SelectSingleNode(xmlDoc, elementPath) {
    if (isIE == 0) {
        var nodes = xmlDoc.evaluate(elementPath, xmlDoc, null, XPathResult.ANY_TYPE, null);
        var results = nodes.iterateNext();
        return results;
    }
    else {
        return xmlDoc.selectSingleNode(elementPath);
    }
}

function GetFrame(nm) {
    var theFrame = document.getElementById ? document.getElementById(nm) : document.all ? document.all[nm] : null;
    return theFrame;
}