//-----------------------------------------------------------
// 文件名称: Web25175_Hotel2.print.v1.1.js
// 页面名称: Web25175_Hotel2.print.v1.1
//　
// 描    述: 打印
// 版　　本: 1.1
// 兼容情况: IE6+,Chrome,Mozilla, Netscape, Firefox,Maxthon3+,
// 创建标识: Add By 吴希 2011-12-13
//------------------------------------------------------------------------------------------
uiPrint = function() {}
uiPrint.prototype = {
    getCss: function() {
        var Css = "";
        if (true) {
            var link = uiGetTag(document, "link");
            for (var i = 0; i < link.length; i++) {
                var type = link[i].getAttribute("type");
                var rel = link[i].getAttribute("rel");
                var href = link[i].getAttribute("href");
                if (type == "text/css" && rel == "stylesheet" && href != "") {
                    Css += "<link href='" + href + "' rel='stylesheet' type='text/css' />";
                }
            }
        }
        if (true) {
            var style = uiGetTag(document, "style");
            for (var i = 0; i < style.length; i++) {
                var HTML = style[i].innerHTML;
                if (HTML != "") {
                    Css += "<style>";
                    Css += HTML;
                    Css += "</style>";
                }
            }
        }
        return Css;
    },
    getDocument: function(ele) {
        var doc = null;
        if (ele.contentDocument) { // Other
            doc = ele.contentDocument;
        } else if (ele.contentWindow) { //ie5.5,ie6.0
            doc = ele.contentWindow.document;
        } else if (ele.document) { //ie5
            doc = ele.document;
        } else {
            return null;
        }
        return doc;
    },
    getJavascript: function() {
        var Js = "";
        if (true) {
            var script = uiGetTag(document, "script");
            for (var i = 0; i < script.length; i++) {
                var src = script[i].getAttribute("src");
                if (src != "") {
                    Js += "<script src='" + src + "' type='text/javascript'><\/script>";
                }
            }
        }
        if (true) {
            var script = uiGetTag(document, "script");
            for (var i = 0; i < script.length; i++) {
                var HTML = script[i].innerHTML;
                if (HTML != "") {
                    Js += "<script type='text/javascript'>";
                    Js += HTML;
                    Js += "<\/script>";
                }
            }
        }
        return Js;
    },
    run: function(id) {
        var ele = uiGet(id);
        if (ele == null) {
            window.print();
        } else {
            var html = ele.innerHTML;
            if (document.all) {
                var iframe = window.document.createElement("iframe");
                iframe.id = "printiframe";
                iframe.style.position = "absolute";
                iframe.style.height = "0px";
                iframe.style.width = "0px";
                iframe.style.left = "-100px";
                iframe.style.top = "0px";
                window.document.body.appendChild(iframe);
                var doc = this.getDocument(uiGet("printiframe"));
                html += this.getCss();
                doc.write(html);
                doc.close();
                window.parent.window.frames["printiframe"].focus();
                window.parent.window.frames["printiframe"].print();
            } else {
                var blank = window.open("about:blank","print");
                blank.document.writeln('<html><HEAD><title>Print</title>')
                blank.document.writeln('</head>')
                blank.document.writeln('<body bottomMargin="0"');
                blank.document.writeln(' leftMargin="0" topMargin="0" rightMargin="0">');
                html += this.getCss();
                html += "<script type='text/javascript'>";
                html += "window.print();";
                html += "<\/script>";
                blank.document.writeln(html);
                blank.document.writeln('</body></html>'); 
                blank.close();
            }
        }
    }
}
var Print = new uiPrint();
