﻿function fixLogoLink() {
    if (location.href.toUpperCase().search('/BL/PERFORMANCEPIPE/') != -1) {
        var logoLink = document.getElementById('ctl00_PlaceHolderGlobalNavigation_PlaceHolderSiteLogo_A1');
        logoLink.href = '/bl/performancepipe/';
    }
}
function fixBreadCrumb() {
    var bc = document.getElementById('ctl00_PlaceHolderTitleBreadcrumb_siteMapPath');
    if (bc != undefined && bc != null && bc.hasChildNodes) {
        var fe = bc.childNodes[1];

        if (fe.childNodes[0].nodeValue == ' > ') {
            fe.childNodes[0].nodeValue = '';
        }
        var le = bc.childNodes[bc.childNodes.length - 1];
        le.className = 'page_bread_crumb_last';
    }
}

function print_preview() {
    window.open(document.location, 'PrintPreview', 'toolbar=no,scrollbars=yes,status=no');
}
function setActiveStyleSheet() {
    var title = 'Print Preview';
    var i, a, main;
    for (i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
        if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
            a.disabled = true;
            if (a.getAttribute("title") == title) { a.disabled = false; }
        }
    }
}
var util_old_minHeight = 0;
function resizeToWindow() {
    var el = document.getElementById('page_body');
    if (el == null) return;
    var offset = el.offsetTop;
    var minHeight = document.documentElement.clientHeight - offset - 15;
    if (util_old_minHeight != minHeight) {
        util_old_minHeight = minHeight;
        el.style.height = minHeight + "px";
    }
}

function IsEmpty(e) {
    var newElement = e.cloneNode(true);
    var allScripts = newElement.getElementsByTagName("script");
    var i = allScripts.length - 1;
    while (allScripts.length != 0) {
        allScripts[i].parentNode.removeChild(allScripts[i]);
        i--;
    }
    var text = "";
    if (newElement.textContent == undefined) { text = newElement.innerText; } else { text = newElement.textContent; }
    text = text.replace(/^\s*/, '');

    var imageCount = newElement.getElementsByTagName('img').length
		            + newElement.getElementsByTagName('object').length
		            + newElement.getElementsByTagName('button').length
		            + newElement.getElementsByTagName('input').length;
    return (text.length <= 1 && imageCount == 0);
}
function formMSDSPacket(listID, specID) {
    return("<?xml version='1.0' encoding='utf-8'?>"
                    + "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
                        + "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
                        + "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope\/\">"
                        + "<soap:Header xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope\/\">"
                            + " <dsp:versions xmlns:dsp=\"http://schemas.microsoft.com/sharepoint/dsp\">"
                                + "<dsp:version>1.0</dsp:version>"
                            + "</dsp:versions>"
                            + "<dsp:request xmlns:dsp=\"http://schemas.microsoft.com/sharepoint/dsp\" service=\"DspSts\" document=\"content\" method=\"query\">"
                            + "</dsp:request>"
                        + "</soap:Header>"
                        + "<soap:Body>"
                            + "<queryRequest "
                                + "xmlns=\"http://schemas.microsoft.com/sharepoint/dsp\">"
                                + "<dsQuery select=\"/list[@id='" + listID + "']\""
                                    + " resultContent=\"dataOnly\""
                                    + " columnMapping=\"attribute\" resultRoot=\"Rows\" resultRow=\"Row\">"
                                    + "<Query>"
                                        + "<Fields><Field Name='MSDSGenerationVariant' /><Field Name='FileRef' /><Field Name='MSDSRevisionDate' /><Field Name='MSDSVersion' /><Field Name='MSDSLanguage' /></Fields>"
                                        + "<Where><Eq><FieldRef Name='MSDSSpecificationID' /><Value Type='Text'>" + specID + "</Value></Eq></Where>"
                                        + "<OrderBy><FieldRef Name='MSDSGenerationVariant' Ascending='True' /><FieldRef Name='MSDSLanguage' Ascending='True' /></OrderBy>"
                                    + "</Query>"
                                + "</dsQuery>"
                            + "</queryRequest>"
                        + "</soap:Body>"
                    + "</soap:Envelope>");
}