function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

    for(var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }

    return vars;
}

function loadXmlDoc(docName) {
    var xmlDoc;
    if (window.ActiveXObject) { // code for IE
        xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
    }
    else if (document.implementation && document.implementation.createDocument) { // non IE
        xmlDoc=document.implementation.createDocument("","",null);
    }
    else { // unsupported
        alert('Your browser is not compatible with this document');
    }

    xmlDoc.async=false;
    xmlDoc.load(docName);

    return xmlDoc;
}

function xslTransform() {
    urlVars = getUrlVars();
    xmlDocName = urlVars['xmldoc'];
    xslDocName = urlVars['xsldoc'];

    bookmark = null;
    markIndex = xslDocName.indexOf("#");
    if (markIndex != -1) {
        bookmark = xslDocName.substring(markIndex+1);
        xslDocName = xslDocName.substring(0, markIndex);
    }

    xmlDoc = loadXmlDoc(xmlDocName);
    xslDoc = loadXmlDoc(xslDocName);

    if (window.ActiveXObject) { // IE
        xhtml = xmlDoc.transformNode(xslDoc);
        document.getElementById("xslbody").innerHTML = xhtml;
    }
    else if (document.implementation && document.implementation.createDocument) { // non IE
        xsltProcessor = new XSLTProcessor();
        xsltProcessor.importStylesheet(xslDoc);
        resultDocument = xsltProcessor.transformToFragment(xmlDoc, document);
        document.getElementById("xslbody").appendChild(resultDocument);
    }
}

function printContent() {
    parent.document.getElementById('main_content').focus();
    window.print();
}

