/**
 * Interactive printer module for printing user defined pages.
 * It is cross browser javascript code and works is all major
 * browsers.
 *
 * @author Veeresh D.
 * @date March 2008
 */

var printDataSupplyDelay = 2000;

var printerPageType = 0;			
/*
Type of print page
0 = Artile list report
1 = Artile report
2 = Author report
3 = Help information report
4 = Shopping Cart
5 = My ComSoc - Personalization
6 = Check Out
7 = Download Cart
8 = Receipt
*/
var printerPageTitle = new Array(9);
var pritnWindow;

printerPageTitle[0] = "Article List Report";
printerPageTitle[1] = "Article Report";
printerPageTitle[2] = "Author Report";
printerPageTitle[3] = "Help Information Report";
printerPageTitle[4] = "Shopping Cart";
printerPageTitle[5] = "My ComSoc";
printerPageTitle[6] = "Check Out";
printerPageTitle[7] = "Download Cart";
printerPageTitle[8] = "Receipt";
printerPageTitle[9] = "Author Directory";

var printer =
{

/**
Returns the HTML content of a author directory tab component. It may also
get from server dynamically and it is recommented in future

@return authorDirTabComponentHTML HTML content of author tab component
*/
getArticlePrinterPage: function()
{
	pritnWindow = window.open("html/global/printLayout.htm", "ComSocDigitalLibrary", "scrollbars=1,status=1,menubar=1,resizable=1,width=800,height=400");	
	/* The below causes synchronization problem.  Because, the above function make take
	some time to load, so the below function cannot be called to update its content. So */
	//window.setTimeout("printer.updatePrinterPage()", printDataSupplyDelay);
	return false;
},

/**
Update the print page after loading its static page.
It will be called by the child window(print page).
*/
updateAfterLoadingPrintPage: function()
{
    window.setTimeout("printer.updatePrinterPage()", 1);
},

/**
Updates the blank print page by supplying catched content dynamically. This
operation could have been done in that above code itself, but there is time 
factor causing problem here, i.e, the window.open() method takes more time
to popup a black page, so the following or next statement cannot be doing
assignment operation.  It may not assign value immediately, so, alternatively
it assigns necessary data after some delay(500ms).
*/
updatePrinterPage: function()
{	
    if ( document.getElementById("queryResultsDivId").innerHTML.length != 0)
	{
	    var queryResultsHTML = document.getElementById("queryResultsDivId").innerHTML;
	    var queryResultsDetailsHTML = document.getElementById("queryResultDetailsDivId").innerHTML;
	    
	    if ( queryResultsDetailsHTML != null || queryResultsDetailsHTML.length > 0 )
	    {
	        queryResultsDetailsHTML = queryResultsDetailsHTML.replaceAll(eval(/onclick=.*?/i),'');
		    queryResultsDetailsHTML = queryResultsDetailsHTML.replaceAll(eval(/href=.*?/i),'');
		}
		
		if ( queryResultsHTML != null || queryResultsHTML.length > 0 )
	    {
	        queryResultsHTML = queryResultsHTML.replaceAll( eval(/onclick=.*?/i),'');
		    queryResultsHTML = queryResultsHTML.replaceAll( eval(/href=.*?/i),'');
		}
		
	    pritnWindow.document.getElementById("pageTitle").innerHTML = printerPageTitle[printer.printerPageType];
		pritnWindow.document.getElementById("pageBody").innerHTML = queryResultsDetailsHTML + "<BR>" + queryResultsHTML;
	}
	else
	{
		pritnWindow.pageBody.innerHTML = "<BR><BR><BR><BR>No data available!";
		pritnWindow.pageBody.style.textAlign = "center";					
	}
},

/**
Show the printer page link
*/
showPrinterPageLink: function()
{
	document.getElementById("printerIconId").style.display = '';	
	document.getElementById("queryTopAlerts").style.display = '';
	parityHistory.showHistoryLinks();
},

/**
Hide the printer page link
*/
hidePrinterPageLink: function()
{
	document.getElementById("queryTopAlerts").style.display = "none";
	document.getElementById("printerIconId").style.display = "none";	
	parityHistory.hideHistoryLinks();
}
}

