var PrintView = {

    _printIndex: -1,
    _printLink: null,
    enabled: false,

    enable: function() {

        if (this.enabled) return;
        $('.logo').attr('src', '/_i/logo_print.jpg');
        if (this._printLink == null) {
            this._printLink = document.createElement("link");
            this._printLink.setAttribute("rel", "stylesheet");
            this._printLink.setAttribute("href", "/_css/print.css");
            document.body.appendChild(this._printLink);
            this._printIndex = document.styleSheets.length - 1;
        }
        this.enabled = true;
        for (var i = 0; i < document.styleSheets.length; ++i) {
            if (i == this._printIndex)
                document.styleSheets[i].disabled = false;
            else
                document.styleSheets[i].disabled = true;
        }
    }
  ,
    disable: function() {
        if (this._printLink == null || !this.enabled) return;
        this.enabled = false;
        for (var i = 0; i < document.styleSheets.length; ++i) {
            if (i == this._printIndex)
                document.styleSheets[i].disabled = true;
            else
                document.styleSheets[i].disabled = false;
        }
    }
  ,
    autoPrint: function() {
        if (document.location.search.indexOf("?printv") >= 0 || document.location.search.indexOf("&printv") >= 0) {
            this.run();
        }
    }
  ,
    run: function() {
        this.enable();
        window.print();
    }
  ,
    openWindow: function() {
        var url = document.location.pathname+document.location.search;
        if (document.location.search.indexOf('?') >= 0) url += "&printv";
        else url += "?printv";
        url += document.location.hash;
        var pwin = window.open(url, 'printWindow');
    }
}

jQuery(function() { PrintView.autoPrint(); });

function AddToFavorites(obj, title, url) {
    if (window.sidebar) {
        // Mozilla Firefox 
        window.sidebar.addPanel(title, url, "");
    }
    else if (window.external) {
        // IE 
        window.external.AddFavorite(url, title);
    }
    else if (window.opera && window.print) {
        //Opera
        obj.setAttribute('href', url);
        obj.setAttribute('title', title);
        obj.setAttribute('rel', 'sidebar');
        obj.click();
    }
    return false;
}