// aimsPrint.js
/*
*  JavaScript template file for ArcIMS HTML Viewer
*    dependent on aimsXML.js, ArcIMSparam.js, aimsCommon.js, aimsMap.js,
*    aimsLayers.js, aimsDHTML.js
*    aimsClick.js, aimsNavigation.js,
*    aimsLegend.js
*/

aimsPrintPresent=true;

var printTitle = titleList[4];
var mapTitle1="";
var mapTitle2="";

var printMapURL="";
var printOVURL="";
var printLegURL="";
var tempWidth = 0;
var tempHeight = 0;
var printMapImageWidth=0;
var printMapImageHeight=0;
var mapBufferWidth=6;                  // supports the inner table buffer for the map image
var mapBufferHeight=4;

var printData="";
var tableLayout="";                           // Supports the tableLayout data retrieval - add CAT
var showDataTable=false;

var pWidth=0;
var pHeight=0;
var pAnnoCol=190;

var legVis2=false;

var printSize="";

/*
***************************************************************************************

Print functions

***************************************************************************************
*/


// display print form
function printIt() {
  hideLayer("measureBox");
  if (useTextFrame) {
    parent.TextFrame.document.location = "JB_PRINTFORM.htm";
  } else {
    var Win1 = open("JB_PRINTFORM.htm","PrintFormWindow","width=575,height=250,scrollbars=yes,resizable=yes");
    }
  }

// create web page for printing
// first get Map
  function getPrintMap(pageSize, title1, title2, showData) {
  showRetrieveMap();
  mapTitle1=title1;
  mapTitle2=title2;

  printSize = pageSize;
  showDataTable = showData;

  // Set the page size which in turn will define the size of hte map image requested
  if (pageSize==1) {
    pWidth=940;
    pHeight=690;
  } else if (pageSize==2) {
    //pWidth=1495;
    //pHeight=920;
	//pWidth=1390;
    //pHeight=856;
	pWidth=1405;
    pHeight=865;
	//pWidth=1420;
    //pHeight=874;
  }

  tempWidth = iWidth;
  tempHeight = iHeight;

  iWidth = Math.floor( parseFloat(pWidth) - pAnnoCol - (mapBufferWidth * 2));
  iHeight = Math.floor( parseFloat(pHeight) - (mapBufferWidth * 2));
  printMapImageWidth=iWidth;
  printMapImageHeight=iHeight;

  legVis2=legendVisible;
  if (aimsLegendPresent) legendVisible=true;
  var theString = writeXML();
  iWidth=tempWidth;
  iHeight = tempHeight;
  legendVisible = legVis2;
  sendToServer(imsURL,theString,101);
  tempWidth=null;
  tempHeight=null;
  theString=null;
}
// second, get OVMap
function getPrintOV() {
  var tempWidth = i2Width;
  var tempHeight = i2Height;
  i2Width=190;
  i2Height=150;
  var tempDraw=drawOVExtentBox;
  drawOVExtentBox=true;
  var theString = writeOVXML();
  drawOVExtentBox=tempDraw;
  i2Width=tempWidth;
  i2Height = tempHeight;
  sendToServer(imsOVURL,theString,102);
  tempWidth=null;
  tempHeight=null;
  theString=null;
}
// third, get Legend
function getPrintLegend() {
  //  waiting for Legend tags
  if (printLegURL=="") printLegURL = "images/nolegend.gif";
  writePrintPage();
}
// fourth, write the web page
// To improve teh printing, basically need to line up the following variables:
// iHeight, iWidth - these are the image ratios established by the size of the
// map image at the time the browser loads (as currently implemented).  That is to say
// if the map display frame has a w=320 and h=100 - that is what iwidth and iheight will be
// pHeight, pWidth - these are numbers established in the printform.htm - which
// as currently implemented are the size of the image given the requested image size (small, medium large).
// these need to have the same ratio - in getPrintMap - the value of the iHeight and iWidth are
// established as a factor of the requested image size - ...

//alert(SiteName);

function writePrintPage() {
  var Win1 = open("","PrintPage");
  //Win1.document.open();
  Win1.document.writeln('<html><meta http-equiv="Content-Type" content="text/html; charset=' + charSet + '"><head>');
  Win1.document.writeln('  <title>' + titleList[5] + '</title>');
  Win1.document.writeln('<LINK REL=\"Stylesheet\" TYPE=\"text\/css\" TITLE=\"AuburnStyles\" HREF=\"\/' + SiteName + '\/Aubstyles.css\">');
  Win1.document.writeln('</head>');
  Win1.document.writeln('<body BGCOLOR="White" TEXT="Black" LEFTMARGIN=0 TOPMARGIN=0>');
  Win1.document.writeln('<TABLE WIDTH="' + pWidth + '" HEIGHT="' + pHeight + '" BORDER="0" CELLSPACING="0" CELLPADDING="0" NOWRAP>');
  Win1.document.writeln('  <TR>');
  Win1.document.writeln('    <TD class="otb">');
  Win1.document.writeln('     <TABLE WIDTH="' + pWidth + '" HEIGHT="' + pHeight + '" BORDER="0" CELLSPACING="0" CELLPADDING="0" NOWRAP>');
  Win1.document.writeln('      <TR>');
  Win1.document.writeln('          <TD align="center" rowspan=3 WIDTH="'+ (printMapImageWidth + (2 * mapBufferWidth)) + '" HEIGHT="'+ (printMapImageHeight + (2 * mapBufferWidth)) + '" valign="middle">');
  Win1.document.writeln('          <TABLE align="center" WIDTH="' + printMapImageWidth + '" HEIGHT="' + printMapImageHeight + '" BORDER="0" CELLSPACING="0" CELLPADDING="0" NOWRAP>');
  Win1.document.writeln('            <TR>');
  Win1.document.writeln('              <TD class="imb">');
  Win1.document.writeln('                <IMG SRC="' + printMapURL + '" WIDTH="'+printMapImageWidth+'" HEIGHT="'+printMapImageHeight+'" HSPACE=0 VSPACE=0 BORDER=0 ALT="">');
  Win1.document.writeln('              </TD>');
  Win1.document.writeln('            </TR>');
  Win1.document.writeln('          </TABLE>');
  Win1.document.writeln('        </TD>');

  // Display the Seal and Source Title.
  Win1.document.writeln('        <TD ALIGN="CENTER" VALIGN="center" WIDTH="'+pAnnoCol+'" height="150">');
  //Win1.document.writeln('          <br><img src=\"\/' + SiteName + '\/Images\/Claremont_m.gif" WIDTH="'+pAnnoCol+'" border=0 ALT="seal"><br>');
  Win1.document.writeln('          <span class="mp_h4"><font color=#478727> <br>City of Claremont<br></span>');
  Win1.document.writeln('          <span class="mp_h4"><font color=#478727>New Hampshire</span><br>');
  Win1.document.writeln('          <span class="mp_h3"><b><i><font color=#478727>Geographic Information System</i></b></span><br><br>');
  Win1.document.writeln('     <img src=\"\/' + SiteName + '\/Images\/lineonwhite.gif" width="150" border=0"><br><br>');
  //Win1.document.writeln('          <span class="mp_h1"><font color=#478727>' + mapTitle1 + ' ' + (printMapImageWidth + (2 * mapBufferWidth)) + '</span><br>');
  Win1.document.writeln('          <span class="mp_h1"><font color=#478727>' + mapTitle1 + '</span><br>');
  Win1.document.writeln('          <span class="mp_h2"><font color=#478727>' + mapTitle2 + '</span>');
  Win1.document.writeln('        </TD>');
  Win1.document.writeln('      </TR>');
  Win1.document.writeln('      <TR>');

  // THIS IS THE CENTER FRAME... WHERE EITHER THE LOCUS MAP OR THE PROPERTY DATA GOES
  Win1.document.writeln('        <TD align="center" valign="top" height="370">');
  // Display either the Overview Map or the data table
  if (showDataTable=='true') {
    Win1.document.writeln('      <br><br>');
    Win1.document.writeln(printData);
  } else if (hasOVMap) {
    Win1.document.writeln('      <br><br><FONT face="Arial Narrow" size=3><b>Locus Map</b><br>');
    Win1.document.writeln('      <IMG SRC="' + printOVURL + '" WIDTH=190 HEIGHT=150 HSPACE=0 VSPACE=0 BORDER=0 ALT="">');
  }

  Win1.document.writeln('       </TD>');
  Win1.document.writeln('     </TR>');

  // THIS IS THE BOTTOM RIGHT FRAME IN THE PRINT SCREEN
  Win1.document.writeln('     <TR>');
  Win1.document.writeln('       <TD ALIGN="center" VALIGN="bottom" height="150">');
  Win1.document.writeln('     <img src=\"\/' + SiteName + '\/Images\/lineonwhite.gif" width="150" border=0"><br><br>');
  Win1.document.writeln('        <FONT size=1><b>Disclaimer</b></FONT><br>');
  Win1.document.writeln('        <FONT face="Arial Narrow" size=1>The City of Claremont makes no warranty or representation as to the accuracy, timeliness or completeness of any of the data.  The City of Claremont shall have no liability for the data or lack thereof, or any decision made or action taken or not taken in reliance upon any of the data.</FONT><p>');
  Win1.document.writeln('       </TD>');
  Win1.document.writeln('     </TR>');
  Win1.document.writeln('    </TABLE>');
  Win1.document.writeln('   </TD>');
  Win1.document.writeln('  </TR>');
  Win1.document.writeln('</TABLE>');
  Win1.document.writeln('</B></FONT>');
  //Win1.document.writeln('</body></html>');
  Win1.document.close();

  legendVisible=legVis2;
  Win1=null;
  hideRetrieveMap();
}

