
/***************************************************
	Function:		viewPrintReadyWindow
	Date:			June 1st, 2005
	Revised:		January 22, 2007
	Parameters:		none
	
	Description:	Responsible for determining the type of window being sent to
					a print screen and calling the appropriate function.
					
****************************************************/
function viewPrintReadyWindow() 
{
	try
	{
		var myForm = document.page.pageType.value;
		if (myForm=="FAQs")
		{
			
			printFaqsWindow("",0);	
		}
		else
		{
			printWindow();
		}
		
	}
	catch(err)
	{
		printWindow();
	}
}


/***************************************************
	Function:		printWindow
	Date:			January 22, 2007
	Parameters:		none
	
	Description:	Responsible for creating and filling a new window with the 
					contents of a document. 
					
****************************************************/
function printWindow()
{
	// Set the content delimiter values
	var delimStart = '<!-- InstanceBeginEditable name="CONTENT" -->';
	var delimEnd = '<!-- InstanceEndEditable -->';
	
	// Retreive the text of the document and store into a string
 	var content = retrieveContent(delimStart, delimEnd)
	
	//Create a new blank browser window
	var printWindow = setPrintWindow();
	var styleSheet = '<link href="/css/format.css" rel="stylesheet" type="text/css" />';

	//Generate the content for the new window . . . .
	printWindow.document.open();
	printWindow.document.writeln('<html><head>'); //header information
	printWindow.document.writeln('<title>Ohio Department of Taxation</title>'); //page title
	printWindow.document.writeln(styleSheet); //style sheet reference
	
	//Set common print Content
	buildPageContent(printWindow, content);


	printWindow.document.writeln('</body></html>');
	printWindow.document.close(); 
	
	//Move document to the upper left corner
	printWindow.moveTo(0,0);
	
	//Bubble window to top.
	printWindow.focus();
}


/***************************************************
	Function:		printFaqsWindow
	Date:			December 15th, 2006
	Parameters:		type - printQA or null
					qID  - Question (and answer) ID
	
	Description:	Responsible for creating and filling a new window with the 
					contents of a document.  THis will generate either all Q and As, 
					or a single response.
					
****************************************************/
function printFaqsWindow(type, qID) 
{
	try{
	// Set the content delimiter values
	var delimStart = '<!--  #CONTENT#  -->';
	var delimEnd = '<!--  #ENDCONTENT#  -->';
	
	// Retreive the text of the document and store into a string
	var content = retrieveContent(delimStart, delimEnd)

	//Create a new blank browser window
	var printWindow = setPrintWindow();
	var styleSheet = "";
	
	styleSheet += '<style type="text/css" >';
	styleSheet += '	@import "/css/format.css";'; 
	
	//Set up the style sheet.  If printing a single question, use QandA_PrintSingle.css
	//Otherwise, use QandA_Print.css
	
	if (type=="printQA")
	{
		styleSheet += '	@import "/css/FAQs_PrintSingle.css";';  //style sheet reference
	}
	else
	{
		styleSheet += '	@import "/css/FAQs_Print.css";';  //style sheet reference
	}
	styleSheet += '</style>'; 
	

	//Generate the content for the new window . . . .
	printWindow.document.open();
	printWindow.document.writeln('<html><head>'); //header information
	printWindow.document.writeln('<title>Ohio Department of Taxation</title>'); //page title
	printWindow.document.writeln(styleSheet); 
			
	
	//Set common print Content
	buildPageContent(printWindow, content);
	
	
	printWindow.document.writeln('</td></tr></table>');  
	
	// Handle the single question case

	if (type=="printQA")
	{
		printWindow.document.writeln('<script>');
		
		// Display Question Number
		printWindow.document.writeln('	document.getElementById("question_' + qID + '_container").className =" ";');
		printWindow.document.writeln('	document.getElementById("question_' + qID + '_no").className="showSingleQuestion";');
		printWindow.document.writeln('	document.getElementById("q_' + qID + '_no").className="showSingleQuestion";');
		
		//Display Question
		printWindow.document.writeln('	document.getElementById("question_' + qID + '").className="showSingleQuestion";');
		printWindow.document.writeln('	document.getElementById("q_' + qID + '").className="showSingleQuestion";');
		
		//Display Answer
		printWindow.document.writeln('	document.getElementById("answer_' + qID + '").className="showSingleAnswer";');
		
		printWindow.document.writeln('</script>')
	}
	
		// End of Document
		printWindow.document.writeln('</body></html>');
		printWindow.document.close(); 
		
		//Move document to the upper left corner
		printWindow.moveTo(0,0);
		
		//Bubble window to top.
		printWindow.focus();
	}
	catch(err){
	}
}

/***************************************************
	Function:		retrieveContent(startPosition, endPosition)
	Date:			March 1st, 2007
	Parameters:		startPosition as first string parse tag, endPosition as last string parse tag
	
	Description:	Sets the common print window parameters
	
****************************************************/

function retrieveContent(startPosition, endPosition)
{
	// Retreive the text of the document and store into a string
  	var allHTML = document.body.innerHTML;
	
	//Split the string into an array, using the content note tag as a delimiter.
	var startPOS = allHTML.split(startPosition);                                                                             
	var endPOS = startPOS[1].split(endPosition);
	return endPOS[0];
}

/***************************************************
	Function:		setPrintWindow()
	Date:			March 1st, 2007
	Parameters:		none
	
	Description:	Sets the common print window parameters
	
****************************************************/

function setPrintWindow()
{
	// seperate the javascript window parameters so they are easy to change
	var toolbar      = 'toolbar=yes'     ; //Include the browser toolbars
	var location     = 'location=no'     ; // Include the URL navigation bar
	var menubar      = 'menubar=yes'     ; // Enclude the default browser menues
	var scrollbars   = 'scrollbars=yes'  ; // Include the scroll bars
	var resizable    = 'resizable=yes'   ; // Is the window resizable by the user?
	var height       = 'height=400'      ; // window height
	var width        = 'width=750'       ; // window width
	
	//Create a new blank browser window
	return window.open('', 'myPrintWin', toolbar + ',' + location + ',' + menubar + ',' + scrollbars + ',' + resizable + ',' + height + ',' + width , true);
}

/***************************************************
	Function:		buildPageContent(printWindow, content)
	Date:			March 1st, 2007
	Parameters:		printWindow - output document object
					content - parsed page content to be displayed
	
	Description:	Builds the primary page data
	
****************************************************/

function buildPageContent(printWindow, content)
{
	/* Javascript to print the document.  In IE, the 'Print Now' buttom will be hidden and the document 
	   will be printed without it.
	*/
	
	printWindow.document.writeln('<script language="JavaScript">');  // Start of imbedded Javascript
	printWindow.document.writeln('function printDoc()');
	printWindow.document.writeln('{');
	 
	// Hide the print button, send the document to the printer, then show the print button again
	printWindow.document.writeln('document.getElementById("printButton").style.display="none";');
	printWindow.document.writeln('window.print();');
	printWindow.document.writeln('document.getElementById("printButton").style.display="block";');
	
	printWindow.document.writeln('}');
	printWindow.document.writeln('</script>');  // End of imbedded Javascript
							
	//Document Header
	printWindow.document.writeln('</head><body>');
	printWindow.document.writeln( '<TABLE bgColor=#ffffff border=0 cellspacing=20 id="printDoc" width="100%" >');
	
	//Location of Print Button image
	printWindow.document.writeln('<tr>');
	printWindow.document.writeln('<td><img src="/images/logo_odt_ohgov.jpg" /></td>');
	printWindow.document.writeln('<td align="right">');
	printWindow.document.writeln('<div id="printButton">');
	printWindow.document.writeln('<a href="javascript:printDoc()"><IMG border=0 id=buttonPrintNow alt="Print Now" src="/images/printer.gif"></a> ');
	printWindow.document.writeln('<a href="javascript:printDoc()">Print</a></div>');
	printWindow.document.writeln('</td></tr>');

	// Document's content
	printWindow.document.writeln('<tr><td class="Default" colspan="2">'); 
	printWindow.document.writeln( content ); // web page content, split from the main document
	printWindow.document.writeln('</td></tr>');

	printWindow.document.write('</table>'); 
	
	// End of Document
	printWindow.document.writeln('</td></tr></table>');  

}

/***************************************************
	Function:		Open
	Date:			December 15th, 2006
	Parameters:		answerID - id of Answer container
					QA_closer - id of Answer Menu Bar
	
	Description:	Responsible for Displaying (unhiding) the answer of a given question
	
****************************************************/

function Open(answerID, QA_closer)
{
	document.getElementById(QA_closer).className = 'QA_opener';
	document.getElementById(answerID).className = 'showAnswer';
}

/***************************************************
	Function:		Close
	Date:			December 15th, 2006
	Parameters:		answerID - id of Answer container
					QA_closer - id of Answer Menu Bar
	
	Description:	Responsible for hiding the answer of a given question
	
****************************************************/
function Close(answerID,  QA_closer)
{
	document.getElementById(QA_closer).className = 'QA_closer';
	document.getElementById(answerID).className = 'Answer';
}


/***************************************************
	Function:		CloseAll
	Date:			December 15th, 2006
	Parameters:		none
	
	Description:	Responsible for Displaying the answers for all questions
	
****************************************************/
function openAll()
{
	var numRows = 200;
	
	for (var i=0;i<numRows;i++)
		try
		{
			Open('answer_' + i , 'QA_closer_' + i);
		}
		catch(err){}
}		


/***************************************************
	Function:		CloseAll
	Date:			December 15th, 2006
	Parameters:		none
	
	Description:	Responsible for hiding the answers for all questions
	
****************************************************/
function closeAll()
{
	var numRows = 200;
	
	for (var i=0;i<numRows;i++)
		try
		{
			Close('answer_' + i , 'QA_closer_' + i);
			window.scrollTo(0,0);
			
		}
		catch(err){}
}

