﻿// JavaScript Document

var articlePrint = Class.create();
articlePrint.prototype = {
	initialize: function(options) {
		this.printWindow = window.open("", 'tportal - Ispis', "height=700, width=520, scrollbars=yes");
		this.articleObj = $(options.articleId).cloneNode(true);
		//<link src=\"http://localhost/css/articlePrint.css\" />';
		this.printWindow.document.body.innerHTML = '<div class="articleHeader">Objavljeno <span id="articleDateTime"></span></div>\n<div class="articleSupTitle" id="articleSupTitle"></div>\n<div class="articleTitle" id="articleTitle"></div>\n<div class="articleLead" id="articleLead"></div>';
		this.initPrintPage();
	},
	initPrintPage: function() {
		this.printWindow.document.getElementsByTagName('head')[0].removeChild(this.printWindow.document.getElementsByTagName('title')[0]);
		
		var style;
		var node;
		var attr;
		
		style += 'body {margin:0px;padding:10px;width:500px;}';
		style += 'div.articleHeader {margin-bottom:42px;padding-top:14px;border-bottom:4px solid #000000;height:18px;background:url(http://www.tportal.hr/imagesT/logoTportalPrint.png) no-repeat;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:11px;text-align:right;}';		
		style += 'div.articleSupTitle {font-family:Georgia,"Times New Roman",Times,serif; font-size:12px;font-weight:bold;}';
		style += 'div.articleTitle {padding:10px 0px;color:#990000;font-family:Georgia,"Times New Roman",Times,serif;font-size:22px;font-weight:bold;line-height:24px;}';		
		style += 'div.articleLead {font-family:Georgia,"Times New Roman",Times,serif;font-size:12px;font-weight:bold;}';
		style += 'p {margin:10px 0px;font-family:Georgia,"Times New Roman",Times,serif; font-size:12px;line-height:20px;text-align:justify;}';	
		style += 'div.tportalAutor {padding-right:10px;color:#990000;font-family:Georgia,"Times New Roman",Times,serif;font-size:18px;font-style:italic;text-align:right;}';
		style += 'div.articleFooter {margin-top:20px;border-top:4px solid #000000;height:50px;background:url(http://www.tportal.hr/imagesT/logoShoppingPrintFooter.png) no-repeat right;}';		
		style += 'div.articleFooterPrint {margin-top:-20px;padding-left:30px;height:20px;background:url(http://www.tportal.hr/imagesT/icons/silver/print.gif) no-repeat;font-family:Verdana, Arial, Helvetica, sans-serif;font-size:12px; cursor:pointer;}';		
		style += 'div.editorRecommendsAll2 {display:none;}';
		/*
		node = document.createElement('title');
		node.appendChild(document.createTextNode('tportal.hr - Ispis clanka'));
		this.printWindow.document.getElementsByTagName('head')[0].appendChild(node);
		*/
		
		
		node = document.createElement('style');
				
		attr = document.createAttribute('type');
		attr.nodeValue = "text/css";
		node.setAttributeNode(attr);
		
		attr = document.createAttribute('media');
		attr.nodeValue = "print";
		node.setAttributeNode(attr);
		
		node.appendChild(document.createTextNode(style));
				
		this.printWindow.document.getElementsByTagName('head')[0].appendChild(node);
		
		node = document.createElement('style');
				
		attr = document.createAttribute('type');
		attr.nodeValue = "text/css";
		node.setAttributeNode(attr);
		
		attr = document.createAttribute('media');
		attr.nodeValue = "screen";
		node.setAttributeNode(attr);
		
		node.appendChild(document.createTextNode(style));
				
		this.printWindow.document.getElementsByTagName('head')[0].appendChild(node);
		
		if($('superTitleDateTime').childNodes[0]) {
			this.printWindow.document.getElementById('articleDateTime').innerHTML = $('superTitleDateTime').childNodes[0].nodeValue;
		}
		if($('superTitleText').childNodes[0]) {
			this.printWindow.document.getElementById('articleSupTitle').innerHTML = $('superTitleText').childNodes[0].nodeValue;
		}
		if($('articleTitle').childNodes[0]) {
			this.printWindow.document.getElementById('articleTitle').innerHTML =    $('articleTitle').childNodes[0].nodeValue;
		}
		if($('articleLead').childNodes[0]) {
			this.printWindow.document.getElementById('articleLead').innerHTML =    $('articleLead').childNodes[0].nodeValue;
		}
		
		node = document.createElement('link');
		
		var attr = document.createAttribute('src');
		attr.nodeValue = "http://ktkalcec.dnsdojo.com/css/articlePrint.css";
		node.setAttributeNode(attr);
		
		attr = document.createAttribute('rel');
		attr.nodeValue = "stylesheet";
		node.setAttributeNode(attr);
		
		attr = document.createAttribute('type');
		attr.nodeValue = "text/css";
		node.setAttributeNode(attr);
		
		this.printWindow.document.getElementsByTagName('head')[0].appendChild(node);
		
		this.printWindow.document.body.appendChild(this.articleObj);
		
		node = document.createElement('div');
		attr = document.createAttribute('class');
		attr.nodeValue = "articleFooter";
		node.setAttributeNode(attr);
		attr = document.createAttribute('id');
		attr.nodeValue = "articleFooter";
		node.setAttributeNode(attr);
		this.printWindow.document.body.appendChild(node);
		
		node = document.createElement('div');
		attr = document.createAttribute('class');
		attr.nodeValue = "articleFooterPrint";
		node.setAttributeNode(attr);
		attr = document.createAttribute('id');
		attr.nodeValue = "articleFooterPrint";
		node.setAttributeNode(attr);
		attr = document.createAttribute('onClick');
		attr.nodeValue = "window.print()";
		node.setAttributeNode(attr);
		this.printWindow.document.body.appendChild(node);
		this.printWindow.document.getElementById('articleFooterPrint').innerHTML = 'Ispiši';
	}
}