var g_sPrintHTML='';
//---------------------------------------------
function WindowCleanup()
{
	// close criteria window if still open
	if( winCrit != null && !winCrit.closed )
		winCrit.window.close();
		
	// close print window if still open
	if( win != null && !win.closed )
		win.window.close();
		
	// close help window if still open
	if( winHelp != null && !winHelp.closed )
		winHelp.window.close();	

	// close additional doc window if still open
	if( winDoc != null && !winDoc.closed )
		winDoc.window.close();	
}

//-------------------------------------------------------------------------
function DoPrint(bNoStyleSheet)
{
	if( g_bPrintOk )
	{
		g_bPrintOk = false;
		var sHTML='';
		var sContent='';
		var oElem = document.getElementById("contentDiv");
		if( oElem != null )
			sContent = String(oElem.innerHTML);

		sHTML = BuildPrintHTML( sContent, typeof(bNoStyleSheet)=='undefined'?false:bNoStyleSheet);

if( typeof(window.parent.arFileInfo)!='undefined')
{		
		var nReport = ( window.parent.nCurrReport != null ? window.parent.nCurrReport : 0 );
		var nNumPages = 1;
		var	bPrintVersion = false;
		var i;
		var re;
		if(	typeof(window.parent.arFileInfo[nReport].nNumPages) != 'undefined' )
			nNumPages = window.parent.arFileInfo[nReport].nNumPages;
		if(	typeof(window.parent.arFileInfo[nReport].bPrintVersion) != 'undefined' )
			bPrintVersion = window.parent.arFileInfo[nReport].bPrintVersion;
		
		if( bPrintVersion )
		{		// replace with alternate print image(s)
			if(	typeof(window.parent.arFileInfo[nReport].sFileName) != 'undefined' )
			{
				arName = window.parent.arFileInfo[nReport].sFileName.split(".");
				var sFl, sF2;
				for( i=0; i< nNumPages; i++ )
				{	
					sF1 = arName[0] + "_" + (i+1) + "." + arName[1];	
					sF2 = arName[0] + "_" + (i+1) + "P." + arName[1];
					re = new RegExp(sF1,"gi");
					sHTML = sHTML.replace(re, sF2);
				}
			}	
		}
}	

	
		if( win == null || win.closed )
			win = OpenPrintWindow();				

		win.window.document.clear();
		win.window.document.write( sHTML );
		win.window.document.close();
		g_bPrintOk = true;	
		
	}
}

//-----------------------------------------------
function EntityConversion(sString)
{
	var re=/>/gi
	var sRet;
	sRet = sString.replace(re,'&gt;');
	re=/</gi
	sRet = sRet.replace(re,'&lt;');
	return sRet;
}


//-----------------------------------------------
function BuildPrintHTML( sContent, bNoStyleSheet)
{
	var sInfo = String(sContent);

			// remove unneeded stuff 
	sInfo = sInfo.replace(/NormalView/gi, 'PrintView');
	sInfo = sInfo.replace(/MarkAllLabel/gi, 'PrintView');
	sInfo = sInfo.replace(/TitleInstr/gi, 'PrintView');
	sInfo = sInfo.replace(/TitlePrintInstr/gi, 'PrintView');

		// remove links from html
	sInfo = sInfo.replace(/<a/gi, "<span ");
	sInfo = sInfo.replace(/<\/a>/gi, "</span>");
	
	sHTML = '<html>\n'
			 	+ '<head>\n';
		if(bNoStyleSheet == null ||  (bNoStyleSheet != null && !bNoStyleSheet) )
			sHTML += '<link rel="stylesheet" type="text/css" href="Config/ViewReport.css">\n';
	sHTML	+= '<' + 'script language="javascript">'
					+ 'function DoPrint()\n'
					+'	{\n'
					+'		var sBody = String(document.body.innerHTML);'					
					+'		nIndex = sBody.search(/div>/gi);\n'
					+'		if( nIndex >= 0 )\n'
					+'			document.body.innerHTML = sBody.substring(nIndex+4);\n'
					+'		window.print();\n'
					+'		window.close();\n'
					+ '}\n'
					+ 'function Load()\n'
					+'	{\n'
					+' var oLink = document.getElementById("PrintLink");\n'
					+' if(oLink)\n'
					+'  oLink.style.visibility="visible";\n'
					+ '}\n'
					+ '</' + 'script>\n'
					+ '</head>\n'
					+ '<body onload="Load()">\n'
					+ '<div id="PrintLink" style="visibility:hidden; text-align:center">\n<a href="javascript:DoPrint()"><img border="0" src="graphics/preview_print.gif"></a>&nbsp;'
					+ '\n<a href="javascript:window.close()" ><img border="0" src="graphics/preview_close.gif" ></a>\n</div>\n'
					+ sInfo
					+ '\n</body>\n'
					+ '</html>';
	return sHTML;	
}


//-------------------------------------------------
function OpenPrintWindow()
{
	var win;
			var left=20;
			var top=20;
			var height=400;
			var width=700;
			var	sFeatures = 'channelmode=no'
								+ ',directories=no'
								+ ',fullscreen=no'
								+ ',location=no'
								+ ',menubar=no'
								+ ',resizable=yes'
								+ ',scrollbars=yes'
								+ ',status=no'
								+ ',titlebar=no'
								+ ',toolbar=no'
								+ ',left=' + left
								+ ',top=' + top
								+ ',height=' + height
								+ ',width=' + width;
				win = OpenWindow('', width, height, top,left,'',sFeatures);
		return win;		
} 	
