/*
 * Author: Vertex Logic, Inc
 * Copyright 2005, 2006, 2007 - All rights reserved
 *
 * Vertex Logic, Inc., California, USA 
 *
 * Vertex Logic grants you ("Licensee") a non-exclusive license to use
 * and modify this source and recompile it in
 * accordance with the terms of the Agreement under which this software is bought
 * and provided that (i) this copyright notice appear on all copies of the Software; 
 * (ii) Licensee does not sale the software as is or with modification without
 * the prior consent of Vertex Logic. (iii) Licensee agrees that it does not have any 
 * title or ownership of the Software.
 *
 * The program is provided "as is" without any warranty express or
 * implied, including the warranty of non-infringement and the implied
 * warranties of merchantibility and fitness for a particular purpose.
 * Vertex Logic will not be liable for any damages suffered 
 * by you as a result of using the Program. 
 * In no event will Vertex Logic be liable for any
 * special, indirect or consequential damages or lost profits even if
 * Vertex Logic have been advised of the possibility of their occurrence. 
 * Vertex Logic will not be liable for any third party claims against you.
 */
 
Af.PrintUtil = Class.create();

Af.PrintUtil.prototype = {

   initialize: function(listener) {
      this.printTable = null;
      this.listener = listener;
   },
   
   showPrintView: function(response)	{
        var b = document.getElementsByTagName("body")[0];
        //b.style.width = "70%";
        //b.style.textAlign = "center";
		
        var tbl = document.createElement("table");
        tbl.style.margin = "auto";
        var tr = tbl.insertRow(0);
        var td = tr.insertCell(0);
        td.width="100%";		
        td.style.textAlign = "left";
        td.innerHTML = response.responseText;
        tr = tbl.insertRow(1);
        td = tr.insertCell(0);
        td.width="100%";
        td.style.textAlign = "right";
        td.style.padding = "5px";
        var lnk = document.createElement("a");
        lnk.appendChild(document.createTextNode("Return"));
        td.appendChild(lnk);
        lnk.onclick = this.printingDone.bind(this);
        lnk.className = 'Link';
        lnk.href = "#";
        for (var i=0; i<b.childNodes.length; i++) {
           if (b.childNodes[i].style) {
              b.childNodes[i].style.display = "none";
           }
        }
        
        
        b.appendChild(tbl);
        
        this.printTable = tbl;
  },
  
  printingDone: function() {
     var b = document.getElementsByTagName("body")[0];
     b.removeChild(this.printTable);
     for (var i=0; i<b.childNodes.length; i++) {
        if (b.childNodes[i].style) {
           b.childNodes[i].style.display = "";
        }
     }
     if (this.listener != null) {
        this.listener.printingDone();
     }
  }
}
