function Report( reportTitle, reportName, oCalculator)
{ 
  this.create          = report_createReport;
  this.assemble        = report_assembleReport;
  this.show            = report_showReport;
  this.hide            = report_hideReport;
  this.header          = report_Header;
  this.title           = reportTitle;
  this.insertBody      = report_insertBody;
  this.footer          = report_Footer;
  
  this.addCloseListener = report_addCloseListener;
  this.restoreForm      = report_restoreForm;
  
  this.calculator      = oCalculator;
  
  this.hideElementArray= null;
  var divReportName    = "div" + reportName; 
  this.layer           = report_createLayer(divReportName);
  this.layerName       = divReportName;
  this.oCloseSink      = null;
  
  this.pageno          = 1;
 
  this.reportDate      = new Date();
 
  theReport            = this;
    
  this.headerHTML      = '<TABLE WIDTH="100%"><TR><TD WIDTH="10%"><IMG SRC="/calculators/images/spacer.gif"></TD><TD><FONT size="2" face="Arial, Helvetica, sans-serif"><b>Office of State Revenue</b></FONT></TD><TD><IMG src="/calculators/images/spacer.gif"></TD><TD><FONT size="2" face="Arial, Helvetica, sans-serif"><b>OSR Calculators (Version 3.0.1)</b></FONT></TD></TR></TABLE>';
  this.horizontalLine  = '<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><TD bgcolor="#ffffff" WIDTH="10%"><IMG height=2 SRC="/calculators/images/spacer.gif"></TD><td bgcolor="#0000ff" width="80%"><IMG height=2 src="/calculators/images/spacer.gif" width=1></td><TD bgcolor="#ffffff" WIDTH="10%"><IMG height=2 SRC="/calculators/images/spacer.gif"></TD></tr></table><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><TD bgcolor="#ffffff" WIDTH="10%"><IMG height=2 SRC="/calculators/images/spacer.gif"></TD><td bgcolor="#000000" width="80%"><IMG height=2 src="/calculators/images/spacer.gif" width=1></td><TD bgcolor="#ffffff" WIDTH="10%"><IMG height=2 SRC="/calculators/images/spacer.gif"></TD></tr></table>';
  //this.retToCalcBtn    = '<TABLE WIDTH="100%" border="0" cellpadding="0" cellspacing="0"><TR><TD WIDTH="10%"><IMG SRC="/calculators/images/spacer.gif"></TD><TD width="80%" BGCOLOR="#cccccc"><div><a style="cursor:hand;" onClick="theReport.hide();"><FONT color="#0000ff" size="2" face="Arial, Helvetica, sans-serif"><< Return to Calculator <<</font></a></div></TD><TD bgcolor="#ffffff" WIDTH="10%"><IMG SRC="/calculators/images/spacer.gif"></TD></TR></TABLE>';
  
  this.retToCalcBtn    = '<TABLE WIDTH="100%" border="0" cellpadding="0" cellspacing="0"><TR><TD WIDTH="10%"><IMG SRC="/calculators/images/spacer.gif"></TD><TD width="80%" BGCOLOR="#cccccc"><div><input class="reporthidden" value="Return To Calculator" title="Press to Return to Calculator" accessKey="B" type="button" onClick="theReport.hide();"></div></TD><TD bgcolor="#ffffff" WIDTH="10%"><IMG SRC="/calculators/images/spacer.gif"></TD></TR></TABLE>';
 
  this.titleHTML       = '<TABLE WIDTH="100%"><TR><TD WIDTH="10%"><IMG SRC="/calculators/images/spacer.gif"></TD><TD align="center"><FONT size="3" face="Arial, Helvetica, sans-serif"><b><span style="text-decoration: underline;">' + this.title + '</span></b></FONT></TD></TR></TABLE>';
  this.footerHTML      = '<TABLE WIDTH="100%"><TR><TD WIDTH="10%"><IMG SRC="/calculators/images/spacer.gif"></TD><TD><FONT size="2" face="Arial, Helvetica, sans-serif">' + this.reportDate.toLocaleString() + '</FONT></TD><TD><IMG src="/calculators/images/spacer.gif"</TD><TD><FONT size="2" face="Arial, Helvetica, sans-serif"><b>End of Report</b></FONT></TD></TR></TABLE>';
  this.bodyHTML        = '<TABLE WIDTH="100%"><TR><TD>No Content Initialized</TD></TR></TABLE>';
  this.reportHTML      = '';
 
}

function report_showReport( hideElementArray)
{   
  if (hideElementArray != null || typeof(hideElementArray) == "undefined") {
  
      this.hideElementArray = hideElementArray;
  
      for (i = 0; i < this.hideElementArray.length; i++) {
           report_hideElement(this.hideElementArray[i]);
      }     
  }
  
  var bodyHTML = this.calculator.getReportHTML();
  
  if (bodyHTML == null) {
  
      alert("Cannot generate report, prior to calculation");
      return;
  }
  
  this.insertBody(bodyHTML);
  
  this.create();
  
  report_showElement(this.layerName);
}

function report_hideReport()
{
  report_hideElement(this.layerName);
  
  if (this.hideElementArray != null || typeof(this.hideElementArray) == "undefined") {
    
      for (i = 0; i < this.hideElementArray.length; i++) {
           report_showElement(this.hideElementArray[i]);
      }     
  }
  
  this.hideElementArray = null;
  
  this.restoreForm();
    
}

function report_getDivStyle(divname) {
  var style;
  
  if (isDOM) { 
  	style = document.getElementById(divname).style; 
  } else { 
  	style = isIE ? document.all[divname].style : document.layers[divname]; 
  } // NS4

  return style;
}

function report_showElement(divname) {

  report_getDivStyle(divname).visibility = 'visible';
}

function report_hideElement(divname) {
  report_getDivStyle(divname).visibility = 'hidden';
    var i;
  // This fixes an IE bug that always forces <select> elements to be on top
  if (document.all && !window.opera && !window.XMLHttpRequest) {
	var selects = document.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) {
		selects[i].style.visibility =  'hidden';
	}
  }
}

function report_Header()
{
   return this.headerHTML;
}

function report_Footer()
{
   return this.footerHTML;
}

function report_insertBody( body)
{
   this.bodyHTML = body;
}

function report_createLayer( layerName)
{
  var layer = null;
  
  this.layerName = layerName;

  if (at.ns4) {
	 layer=new Layer(50);
  }
  else if (at.ie4) 
  {
  	  var code='<DIV ID="' + layerName + '" NAME="' + layerName + '" style="visibility:hidden;position:absolute;left: 0px; top: 0px; height: 100%; width: 100%; z-index:100000; background-color: #ffffff; layer-background-color: #ffffff""></DIV>';
	  document.body.insertAdjacentHTML("beforeEnd", code);
      layer=document.all[layerName];
  }
  else if (at.ie7 || at.ie6 || at.ie5 || at.ie55 || at.ns5 || at.ns7) {
  
	  layer=document.createElement("DIV");
	  layer.style.position="absolute";
      layer.style.zIndex=100000;
      layer.style.left=0;
      layer.style.top=0;
      layer.style.width="100%";
      layer.style.height="100%";
      layer.style.visibility="hidden";
      layer.style.backgroundColor="#ffffff";
      layer.id=layerName;
	  document.body.appendChild(layer);
	 
  }

  return layer;
}
 
function report_createReport()
{    
 this.reportHTML = this.assemble();
     
 if (isIE) {
	    
     this.layer.innerHTML = this.reportHTML;
              
 } else if (isDOM) {
     
   
         this.layer.innerHTML = this.reportHTML;
    
       } else {
    
               var elt = document.body;
	           elt.open();
	           elt.write(this.reportHTML);
	           elt.close();
	       }
}

function report_assembleReport()
{
   //return "<TABLE border='0' WIDTH='100%' HEIGHT='100%' cellspacing='0' cellpadding='0'><TR><TD align='left' valign='top'  height='100%' width='100%'>" + this.headerHTML + this.horizontalLine + this.retToCalcBtn + this.titleHTML + this.bodyHTML +  this.horizontalLine + this.footerHTML + "</TD></TR></TABLE>";
    return this.headerHTML + this.horizontalLine + this.retToCalcBtn + this.titleHTML + "<TABLE WIDTH='100%'><TR><TD WIDTH='10%'><IMG SRC='/calculators/images/spacer.gif'></TD><TD>" + this.bodyHTML + "</TD></TR></TABLE>" +  this.horizontalLine + this.footerHTML;
}

function report_addCloseListener( obj)
{
   if (obj == null || typeof(obj) != "function") return;
   
   this.oCloseSink = obj;
}

function report_restoreForm()
{
   if (this.oCloseSink == null || typeof(this.oCloseSink) != "function") return;
    
   this.oCloseSink();
}