﻿function getPageScroll() {
    var yScroll;

    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {  // Explorer 6 Strict
        yScroll = document.documentElement.scrollTop;
    }
    else if (document.body) {// all other Explorers
        yScroll = document.body.scrollTop;
    }

    arrayPageScroll = new Array('', yScroll)

    return arrayPageScroll;
}

function getPageSize() {
    var xScroll, yScroll;

    if (window.innerHeight && window.scrollMaxY) {
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    var windowWidth, windowHeight;
    // Commented, in FF worked incorrectly 
    /*if (self.innerHeight) { // All except Explorer
    windowWidth = self.innerWidth;
    windowHeight = self.innerHeight;
    } else*/
    if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }

    // For small pages with total height less then height of the viewport
    if (yScroll < windowHeight) {
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }

    // For small pages with total width less then width of the viewport
    if (xScroll < windowWidth) {
        pageWidth = windowWidth;
    } else {
        pageWidth = xScroll;
    }

    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight)

    return arrayPageSize;
}

function getQueryStringParameterByName(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);

    return results == null ? "" : results[1];
}

String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function queryString(key) {
    qs = window.location.search.substring(1);
    pairs = qs.split("&");
    for (i = 0; i < pairs.length; i++) {
        ft = pairs[i].split("=");
        if (ft[0] == key)
            return ft[1];
    }
}

function isIE6() {
    return $.browser.msie && $.browser.version == "6.0";
}

function isIE7() {
    return $.browser.msie && $.browser.version == "7.0";
}

$(document).ready(function () {
    if (typeof (locationS) != 'undefined' && locationS == 1) {
        setWidthOfCommandButtonsPanel("cmd_buttons");
        setWidthOfCommandButtonsPanel("cmp_p2_title_smb");
    }
});

function setWidthOfCommandButtonsPanel(selector) {
    $("." + selector).each(function () {
        cmp_p2_title_smb = $(this);
        wd = 0;
        i = 0;
        cmp_p2_title_smb.find("span").each(function () {
            if ($(this).parent().hasClass(selector)) {
                wd += $(this).width();
                i++;
            }
        });
        cmp_p2_title_smb.css({ width: wd + 6 * i });
    });
}
