var transport = {
    xhr: new XMLHttpRequest(),
    loadXML: function (xmlFile) {
        this.xhr.open('GET', xmlFile, false);
        this.xhr.send(null);
        return this.xhr.status == 200 ? this.xhr.responseXML : null;
    },
    loadText: function (xmlFile) {
        this.xhr.open('GET', xmlFile, false);
        this.xhr.send(null);
        return this.xhr.status == 200 ? this.xhr.responseText : null;
    },
    loadJSON: function (url) {
        this.xhr.open('GET', url, false);
        this.xhr.send(null);
        return this.xhr.status == 200 ? JSON.parse(this.xhr.responseText) : null;
    }
};

function transformXML(xmlDoc, xslDoc, element) {
    var XSLT = new XSLTProcessor;
    XSLT.importStylesheet(xslDoc);
    var e = document.getElementById(element);
    if (e) {
        e.innerHTML = "";
        e.appendChild(XSLT.transformToFragment(xmlDoc, document));
    }
}

function getNodeValue(xml, tagname) {
    var tags = xml.getElementsByTagName(tagname);
    if (tags.length > 0)
        return tags[0].firstChild ? tags[0].firstChild.nodeValue : null;
    else
        return null;
}

function showCtrl(id) {
    document.getElementById(id).style.display = "block";
}

function hideCtrl(id) {
    document.getElementById(id).style.display = "none";
}

function enableCtrl(id) {
    document.getElementById(id).disabled = false;
}

function disableCtrl(id) {
    document.getElementById(id).disabled = true;
}

function setValue(id, value) {
    document.getElementById(id).value = value;
}

function setContent(id, content) {
    document.getElementById(id).innerHTML = content;
}

const shell = require('electron').shell;

function openLink(url) {
    shell.openExternal(url);
}

function openItem(path) {
    shell.openItem(path);
}

/*
const ipc = require('electron').ipcRenderer;
ipc.on('information-dialog', function (event, index) {
});

function alert(msg) {
    ipc.send('open-information', msg);
}

*/