/* --------------------------------
- Print preview functions for Rabobank.com
- Version: 1.1 - 20100331
*/

/* --------------------------------
- Set sPrintHeader and sPrintMsg to show the print only message
*/

// Header of print message
var sPrintHeader = "About Rabobank Group";

// Body of print message
var sPrintMsg = "<p>Rabobank Group is a Netherlands based, international financial services provider operating on the basis of cooperative principles with a predominant focus on providing allfinanz services in the domestic market. Internationally the Group's focus is on food and agriculture. In line with its cooperative roots, Rabobank Group is a cooperative bank, comprised of independent local Rabobanks, plus their central organisation Rabobank Nederland and its (international) subsidiaries.The organisation has more than 60,000 employees worldwide and operates in 48 countries.</p>";

sPrintMsg += "<p>Rabobank Group has the highest credit rating, Triple A, awarded by international rating agencies including Standard &amp; Poor's and Moody's. In terms of Tier I capital, the organisation is among the top 25 largest financial institutions in the world. Total assets amount to EUR 607 billion and a net profit to EUR 2.3 billion of 2009.</p>";

sPrintMsg += "<p>Internationally, the Rabobank Group operates specialized entities including De Lage Landen (leasing and vendor financing), Robeco Group (asset management), Rabo Real Estate Group (real estate management) and Sarasin (private banking).</p>";

sPrintMsg += "<p>For more information about the Rabobank Group go to <a href=\"http:\/\/www.rabobank.com\">www.rabobank.com</a></p>";

// Style sheet titles
var sStyleTitleDefault = "Default";
var sStyleTitlePrint = "PrintPreview";

/* --------------------------------
- Functions for print preview
*/

// Attach print preview to the page
function fnAddEvent( obj, type, fn ) {
        if ( obj.attachEvent ) {
                obj['e'+type+fn] = fn;
                obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
                obj.attachEvent( 'on'+type, obj[type+fn] );
        } else {
                obj.addEventListener( type, fn, false );
        }
};
// Init print preview message
fnAddEvent(window, "load", fnPrintPreviewMsg);

// Function to show the print preview
fnPrintPreview = function(){
	fnSetActiveStyleSheet(sStyleTitlePrint);
	// Show print modal dialog
	// window.print();
};

// Function to return to normal view
fnPrintPreviewCancel = function() {
	fnSetActiveStyleSheet(sStyleTitleDefault);
};

// Function to add a print preview message to the page
// Use sPrintHeader and sPrintMsg to set the message text
function fnPrintPreviewMsg(){
	if (document.getElementById){
		// fetch the footer 
		var oFooter = document.getElementById("footer");
		var oFooterParent = null;
		if (!oFooter) {
			// or else the footer on the homepage
			oFooter = document.getElementById("footer-home");
		};
		if (oFooter) {
			oFooterParent = oFooter.parentNode;
		};
		if (oFooterParent) {
			// Create print preview message
			var oPrintMsg = document.createElement('div');
			oPrintMsg.id = "print-preview-msg";
			// Create heading
			var oPrintHead = document.createElement('h3');
			oPrintHead.innerHTML = sPrintHeader;
			// Create body text of message
			var oPrintBody = document.createElement('div');
			oPrintBody.innerHTML = sPrintMsg;
			// Create return link
			var oPrintPreviewCancel = document.createElement('a');
			oPrintPreviewCancel.onclick = function(){ fnPrintPreviewCancel(); return false; };
			oPrintPreviewCancel.setAttribute('href', '#');	
			oPrintPreviewCancel.innerHTML = "&laquo; Close the print preview and return to normal view.";
			// Put it all toegether
			oPrintMsg.appendChild(oPrintPreviewCancel);
			oPrintMsg.appendChild(oPrintHead); 
			oPrintMsg.appendChild(oPrintBody);
			oFooterParent.insertBefore(oPrintMsg, oFooter);
		}
	}
};

// Function to switch stylesheets
// Stylesheet references need to have title and media=screen attribute!
// Eg.: <link rel="{alternate }stylesheet" title="..." media="screen, ..." /> 
// Usage: fnSetActiveStyleSheet("PrintPreview");
fnSetActiveStyleSheet = function(sTitle) {
   var i, a, main;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
     if(a.getAttribute("rel").indexOf("style") != -1 
     		&& a.getAttribute("title")
     		&& a.getAttribute("media").indexOf("screen") != -1) {
       a.disabled = true;
       if(a.getAttribute("title") == sTitle) a.disabled = false;
     }
   }
}

