﻿
function PrintThisPage()
{
	var sOption='width=620,height=800,toolbar=no,location=no,directories=no,status=no,';
	sOption+='menubar=no,scrollbars=yes,resizable=no,copyhistory=no,left=100,top=25';
	var strContent = "";
	
    // load page content 
	try
	{
		strContent = document.getElementById('mainContent').innerHTML;	
	}
	catch(err)
	{
		
	}
	
/* Remove in body script to circumvent document.write overwriting content in firefox */
	var sTmpContent		= "";
	var scanComplete	= false;
	var i = 0, j = 0;

	while(!(scanComplete))
	{
		scanComplete = true;

		i = strContent.toLowerCase().indexOf("<script");
		j = strContent.toLowerCase().indexOf("</script>");
		if((-1 != i)&&(-1 != j))
		{
			sTmpContent =  strContent.substring(0, i - 1);
			sTmpContent += strContent.substring(j + 9, strContent.length);
			strContent   = sTmpContent;
			
			scanComplete = false;
		}
	}


/* Replace Links (href) */
	var replacehref=/ href=/gi;
	strContent = strContent.replace(replacehref," dontprinthref=");

/* Replace alt  */
	var replacehref=/ alt=/gi;
	strContent = strContent.replace(replacehref," dontprintalt=");

/* Replace title  */
	var replacehref=/ title=/gi;
	strContent = strContent.replace(replacehref," dontprinttitle=");
	
	var winprint = window.open('','PrintPopup',sOption);
	winprint.document.open();
	
	winprint.document.write("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>\n");
	winprint.document.write("<html xmlns='http://www.w3.org/1999/xhtml'>\n");
	winprint.document.write("<head>");
	
	var styles,i;
	styles = document.getElementsByTagName('Link');
	for(i in styles)
	{
		var element = document.getElementsByTagName('Link')[i];
		winprint.document.write("<LINK href='" + element.href + "' type='text/css' rel='stylesheet'>");
	}
	
/* builds a new print-friendly html doc */
	winprint.document.write("<title>");
	winprint.document.write("Purina PRO PLAN");
	winprint.document.write("</title>");
	winprint.document.write("</head>");
	winprint.document.write("<body>");
	winprint.document.write("<div style='text-align: right; height: 26px;'>");
	winprint.document.write("<img src='/purina-proplan/Images/print_icon.gif' width=26 height=26 style='cursor:pointer;' alt='Seite drucken' title='Seite drucken' onclick='javascript:window.print();'>");
	winprint.document.write("<img src='/purina-proplan/Images/close_icon.gif' width=26 height=26 style='cursor:pointer;' alt='Fenster schließen' title='Fenster schließen' onclick='javascript:window.close();'>");
	winprint.document.write("</div>");
	var div = '<div id="mainContent">';
	div += strContent;
	div += '</div>';
	winprint.document.write(div);
	winprint.document.write("</body>");
	winprint.document.write("</html>");
	winprint.document.close();
	winprint.focus();
}		
	
