/*

JSLib :: prakitka.hu

Author: Andras Nemeseri

*/

	/* Common functions */

	/* addEvent, removeEvent functions from http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html */
	addEvent = function ( obj, type, fn ) {
		if (obj.addEventListener)
			obj.addEventListener(type, fn, false);
		else 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]);
		}
	}

	/*
	JSTarget function by Roger Johansson, www.456bereastreet.com
	*/
	var JSTarget = {
		init: function(att,val) {
			if (document.getElementById && document.createElement && document.appendChild) {
				var strAtt = ((typeof att == 'undefined') || (att == null)) ? 'class' : att;
				var strVal = ((typeof val == 'undefined') || (val == null)) ? 'non-html' : val;
				var arrLinks = document.getElementsByTagName('a');
				var oLink;
				var oRegExp = new RegExp("(^|\\s)" + strVal + "(\\s|$)");
				for (var i = 0; i < arrLinks.length; i++) {
					oLink = arrLinks[i];
					if ((strAtt == 'class') && (oRegExp.test(oLink.className)) || (oRegExp.test(oLink.getAttribute(strAtt)))) {
						oLink.onclick = JSTarget.openWin;
					}
				}
				oWarning = null;
			}
		},
		openWin: function(e) {
			var event = (!e) ? window.event : e;
			if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) return true;
			else {
			    var oWin = window.open(this.getAttribute('href'), '_blank');
				if (oWin) {
					if (oWin.focus) oWin.focus();
					return false;
				}
				oWin = null;
				return true;
			}
		}
	};

	addEvent(window, 'load', function(){JSTarget.init("rel","external");});
	//addEvent(window, 'load', attachOpenUp );

	attachPrint = function() {

		if ( ! document.getElementById || ! document.createTextNode ) {
			return;
		}

		var aPrint = document.getElementById('article_print');

		if ( ! aPrint ) {
			return;
		}

		aPrint.style.display = 'block';

		aPrint.onclick = function() {
			window.print();
			return false;
		}

	}

	attachOpenUp = function() {

		if ( ! document.getElementById || ! document.createTextNode ) {
			return;
		}

		// Cikk kuldese
		var aEmail = document.getElementById('article_email');

		if ( ! aEmail ) {
			return;
		}

		aEmail.onclick = function() {
			openup( 'cikk' );
			return false;
		}
	}

	openup = function() {

		//Focsat
		var aScript = document.getElementsByTagName('script');
		var aSplitFocsat = aScript[0].src.split( '/' );
		var focsatid = aSplitFocsat[5];

		//Cikkid
		var aDocHref = document.location.href.split( '/' );
		var cid = aDocHref[5];

		window.open("/data/blocks/" + focsatid + "_praktika_sendarticle/block.inc.php?cid=" + cid + "&type=cikk", 'cikkuldes', 'left=20,top=20,width=500,height=250,toolbar=0,resizable=0');

	}

	addEvent(window, 'load', attachPrint );
	addEvent(window, 'load', attachOpenUp );