// 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 printMapURL="";
var printOVURL="";
var printLegURL="";

var legVis2=false;

var currentAttributes = "";

/*
***************************************************************************************

Print functions 

***************************************************************************************
*/


// display print form
function printIt() {
	hideLayer("measureBox");
	if (useTextFrame) {
		parent.TextFrame.document.location = "printform.htm";
	} else {
		var Win1 = open("printform.htm","PrintFormWindow","width=1024,height=768,scrollbars=yes,resizable=yes");
	}
}

// create web page for printing
	// first get Map
function getPrintMap(title) {
	showRetrieveMap();
	printTitle=title;
	var tempWidth = iWidth;
	var tempHeight = iHeight;
	var tempLegW = legWidth;
	var tempLegH = legHeight;
	iWidth=450;
	iHeight=450;
	legWidth = 150;
	legHeight = 300;

	legVis2=legendVisible;
	if (aimsLegendPresent) legendVisible=true;
	var theString = writeXML();
	iWidth=tempWidth;
	iHeight = tempHeight;
	legWidth = tempLegW;
	legHeight = tempLegH;
	legendVisible = legVis2;
	sendToServer(imsURL,theString,101);
	tempWidth=null;
	tempHeight=null;
	theString=null;
}
// second, get OVMap
function getPrintOV() {
	var tempWidth = i2Width;
	var tempHeight = i2Height;
	i2Width=110;
	i2Height=90;
	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
function writePrintPage() {
	var Win1 = open("","PrintPage");
	//Win1.document.open();
      Win1.document.writeln('<html><meta http-equiv="Content-Type" content="text/html; charset=' + charSet + '">');
      Win1.document.writeln('<meta http-equiv="imagetoolbar" content="false">');
      Win1.document.writeln('<head>');
      // Win1.document.writeln('<link rel="stylesheet" href="http://dev-maps2.woolpert.com/website/Charleston/print.css" type="text/css">');
	 Win1.document.writeln('<link rel="stylesheet" href="http://ccgisdev.charlestoncounty.org/website/Charleston/print.css" type="text/css">');

	Win1.document.writeln('<script language="javascript">');
	Win1.document.writeln('function showHighlight(x){');
	Win1.document.writeln('}');

	Win1.document.writeln('function writeAttributes()');
	Win1.document.writeln('{');
	Win1.document.writeln('		if (opener) ');
	Win1.document.writeln('		{	    ');
	Win1.document.writeln('			var divHTML = opener.parent.MapFrame.currentAttributes;');
	Win1.document.writeln('			var divHTML2 = opener.parent.MapFrame.replace(divHTML, "parent.MapFrame.", "");');
	Win1.document.writeln('			if (document.all) {');
	Win1.document.writeln('				document.all("printAttributesDIV").innerHTML = divHTML2;');
	Win1.document.writeln('			} else {');
	Win1.document.writeln('				document.getElementById("printAttributesDIV").innerHTML = divHTML2;');
	Win1.document.writeln('			}');
	Win1.document.writeln('			opener.parent.MapFrame.currentAttributes = "";');


	Win1.document.writeln('		}	    ');
	Win1.document.writeln('}');
	Win1.document.writeln('</script>');

	Win1.document.writeln('<style type="text/css">');
	Win1.document.writeln('a{text-decoration:none;}a:link{color:#003366;}a:visited{color:#003366;}a:active{color:#003366;}a:hover{color:#003366;}');
	Win1.document.writeln('</style>');

	Win1.document.writeln('</head>');
      Win1.document.writeln('<body BGCOLOR="White" TEXT="#003366" LEFTMARGIN=0 TOPMARGIN=0 onload="writeAttributes()">');
	Win1.document.writeln('<FONT FACE="Arial"><B>');
	Win1.document.writeln('<TABLE WIDTH="650" BORDER="2" CELLSPACING="0" CELLPADDING="0" NOWRAP>');
      Win1.document.writeln('<TR>');
      Win1.document.writeln('<TD align="CENTER"><img src="'+baseURL+'images/maplogo.jpg"></TD>');
      Win1.document.writeln('<TD><font face="Arial, sans-serif" size="4"><B>' +printTitle + '</B></FONT><BR><font face="Palatino Linotype" size="1"><B>Copyright 2004</font><br><font face="Palatino Linotype" size="1">Charleston County GIS</font><br><font face="Palatino Linotype" size="1">4045 Bridge View Drive</font><br><font face="Palatino Linotype" size="1">North Charleston, SC 29405-7464</font><b></TD>')
	// Win1.document.writeln('<TD ALIGN="CENTER" WIDTH="110px"><IMG SRC="' + printOVURL + '" HSPACE=0 VSPACE=0 BORDER=0 ALT=""></TD>');
      Win1.document.writeln('</TR>')
      Win1.document.writeln('</TABLE>')
      Win1.document.writeln('<TABLE WIDTH="650" BORDER="2" CELLSPACING="0" CELLPADDING="0" NOWRAP>')
      Win1.document.writeln('<TR>')
      Win1.document.writeln('<TD ALIGN="CENTER" VALIGN="TOP"  BGCOLOR="#ffffcc" WIDTH="150"><IMG SRC="' + printLegURL + '" SPACE=0 VSPACE=0 BORDER=0 ALT=""></TD>')
      Win1.document.writeln('<TD ALIGN="CENTER" VALIGN="TOP"><IMG SRC="' + printMapURL + '" HEIGHT=450 WIDTH=460 HSPACE=0 VSPACE=0 BORDER=0 ALT=""></TD>')
      Win1.document.writeln('</TR>')
      Win1.document.writeln('</TABLE>')
     
      Win1.document.writeln('<div STYLE="width:650px" id="printAttributesDIV">')
      Win1.document.writeln('</div>')	
      Win1.document.writeln('</body></html>');
      Win1.document.close();
	legendVisible=legVis2;
	Win1=null;
	hideRetrieveMap();
}


//=====================================
//Akinmade & Rees - 8/18/2004

function printAttributes()
{
	if (document.all) {
		currentAttributes = parent.TextFrame.document.all("attributesDIV").innerHTML;
	} else {
		currentAttributes = parent.TextFrame.document.getElementById("attributesDIV").innerHTML;
	}
      parent.MapFrame.aimsSelectPresent = true;
	var printWin = window.open(baseURL + "printform2.htm", "", "width=400,height=125,toolbars=no,scrollbars=no,menubar=no,resizable=yes");
	printWin.focus();
}


function replace(s, t, u) {
  /*
  **  Replace a token in a string
  **    s  string to be processed
  **    t  token to be found and removed
  **    u  token to be inserted
  **  returns new String
  */
  i = s.indexOf(t);
  r = "";
  if (i == -1) return s;
  r += s.substring(0,i) + u;
  if ( i + t.length < s.length)
    r += replace(s.substring(i + t.length, s.length), t, u);
  return r;
  }

function printit2() {
	hideLayer("measureBox");
	if (useTextFrame) {
		parent.TextFrame.document.location = "onlinehelp1.html";
	} else {
		var Win1 = open("onlinehelp1.htm","PrintFormWindow","width=575,height=150,scrollbars=yes,resizable=yes");
	}
}

function printit3() {
	hideLayer("measureBox");
	if (useTextFrame) {
		parent.TextFrame.document.location = "links.html";
	} else {
		var Win1 = open("links.htm","target=_blank","width=575,height=150,scrollbars=yes,resizable=yes");
	}
}


