﻿var Printer = new Object();

/*
    Initialize Printer
*/
Printer.Init = function()
{
    Navigator.OnDocumentLoad.Bind(this.SetDocument, this);
}

/**
    A new document is loaded
*/
Printer.SetDocument = function(menuitem, opened, content)
{
    if (opened == true){
        this.PrintDocument = content.ownerDocument;
    }
    else this.PrintDocument = null;
}

/**
    Prints the main page of the site
*/
Printer.Print = function()
{
    if (this.PrintDocument == null) alert("Unable to print: no document loaded.");
    else
    {
        var win;
        
        if (this.PrintDocument.parentWindow != null) win = this.PrintDocument.parentWindow;
        else if (this.PrintDocument.defaultView != null) win = this.PrintDocument.defaultView;
        else alert("Unable to Print: browser not supported.")
        
        win.focus();
        win.print();
    }
}
