﻿
(function ($) {
    //plugin to enable/disable control
    jQuery.fn.extend({
        enable: function (enable, fn) {
            return this.each(function () {
                var control = $(this);

                if (control.length) {
                    if (enable)
                        control.removeAttr("disabled");
                    else
                        control.attr("disabled", "disabled");
                }
            });
        }
    });

    jQuery.fn.extend({
        hoverFilter: function () {
            return this.each(function () {
                var control = $(this);

                if (control.length) {
                    control.hover(
                        function () { this.src = this.src.replace("go.png", "go_over.png"); },
                        function () { this.src = this.src.replace("go_over.png", "go.png"); }
                    );
                }
            });
        }
    });

})(jQuery);

function prepTooltip() {
    $("td[id$='tdDatePosted']").bt({
        cssStyles: { fontSize: 'smaller' }
    });
}

function printPanel(pnlView) {
    var printContent = pnlView.html();
    var windowUrl = 'about:blank';
    var uniqueName = new Date();
    var windowName = 'Print' + uniqueName.getTime();
    var printWindow = window.open(windowUrl, windowName, "scrollbars=yes,width=780, height=600, left=100, top=25");
    var isChorme = navigator.userAgent.toLowerCase().indexOf("chrome") > -1;
    var isFireFox = navigator.userAgent.toLowerCase().indexOf("firefox") > -1;

    printWindow.document.write('<html>\n');
    printWindow.document.write('<head>\n');

    if (!isChorme)
        printWindow.document.write('<link href="../StyleSheet/Print.css" rel="stylesheet" type="text/css" />\n');

    printWindow.document.write('<script>\n');

    if (isChorme) {
        printWindow.document.write('var chromeCss = document.createElement("link");\n');
        printWindow.document.write('chromeCss.rel = "stylesheet";\n');
        printWindow.document.write('chromeCss.href = "../StyleSheet/Print.css";\n');
        printWindow.document.write('document.getElementsByTagName("head")[0].appendChild(chromeCss);\n');
    }

    printWindow.document.write('function winPrint() {\n');
    printWindow.document.write('window.focus();\n');

    if (isChorme)
        printWindow.document.write('printChrome();\n');
    else
        printWindow.document.write('window.print();\n');


    if (isFireFox)
        printWindow.document.write('window.close();\n');
    else
        printWindow.document.write('chkstate();\n');

    printWindow.document.write('}\n');

    printWindow.document.write('function chkstate() {\n');
    printWindow.document.write('if(document.readyState=="complete") { window.close(); }\n');
    printWindow.document.write('else { setTimeout("chkstate();",3000); }\n');
    printWindow.document.write('}\n');

    printWindow.document.write('function printChrome() {\n');
    printWindow.document.write('if(document.readyState=="complete") { window.print(); }\n');
    printWindow.document.write('else { setTimeout("printChrome();",3000); }\n');
    printWindow.document.write('}\n');

    printWindow.document.write('</script>');
    printWindow.document.write('</head>');
    printWindow.document.write('<body onload="winPrint()" >');
    printWindow.document.write(printContent);
    printWindow.document.write('</body>');
    printWindow.document.write('</html>');
    printWindow.document.close(); 
}


