/* $Id: script.js,v 1.5 2009-06-17 10:40:13 mmajer Exp $ */
function $(id) { return document.getElementById(id); }
function $c(name) { return document.createElement(name); }

var nn = (document.layers)? true:false;
var ms = (document.all)? true:false;
var n6 = (document.getElementById) ? true:false;

function checkSearch(form){
	//form = document.formsearch;
	if (trim(form["search-clause"].value) != "")
		return true
	else
		return false
}

function trim(lancuch){
	while (lancuch.charAt(0) == " ")
		lancuch = lancuch.substring(1,lancuch.length);
	while (lancuch.charAt(lancuch.length-1) == " ")
		lancuch = lancuch.substring(0,lancuch.length-2);
	return lancuch;
}


function openWindow(file,szer,wys,scrollec){
	wys = (!wys)?(300):(wys);
	szer = (!szer)?(400):(szer);
	scrollec = (!scrollec)?('no'):('yes');
	if (ms) var xMax = screen.width, yMax = screen.height
	else if (nn) var xMax = window.outerWidth, yMax = window.outerHeight
	var xOffset = (xMax - szer)/2, yOffset = (yMax - wys)/2;
	okienko = window.open(file,'TWTPop','scrollbars='+scrollec+',height='+wys+',width='+szer+',screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+',resizable=yes');
	okienko.focus();
}

function addParameter(href, param, value){
	if (href.indexOf("?") > -1)
		href += "&";
	else
		href += "?";

	return href + param + "=" + value;
}

function getClientSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [myWidth, myHeight]
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}


/* ----------------------------------------------------------------------
	ADD EVENT
---------------------------------------------------------------------- */
function addEvent(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]);
  }
}

function aEL(o,t,f){
	var a=Array.prototype.slice.call(arguments,3)
	o[t+f]=function(e){return !1===f.apply(o,[e||window.event].concat(a))?e.preventDefault?e.preventDefault():!1:1}
	return(o.x=o.addEventListener)?o.x(t,o[t+f],!1):(o.x=o.attachEvent)?o.x('on'+t,o[t+f]):!1;
}

function PopupWindow(url,width,height,name){
    if (name==null){
      name = 'popup';
    }

    var left = (screen.width - width)/2;
    var top = (screen.height - height)/2 - 18;

    var win = window.open(url,name,"toolbar=no,location=no,directories=no,"+
      "status=no,menubar=no,scrollbars=no,resizable=no,"+
      "copyhistory=no, width="+width+",height="+height+",left="+left+",top="+top);
    if (win) win.focus();
}

function PopupImage(url,width,height,title,name)
{
    if (name==null){
      name = new String(Math.round(Math.random()*10000000));
    }
    var windowheight = height+40;
    var windowwidth = width+20;

    var left = (screen.width - windowwidth)/2;
    var top = (screen.height - windowheight)/2 - 18;

    var scrollbars = "no";

    if (left<0) { scrollbars = "yes"; left = 32; windowwidth = screen.width - 2*left; }
    if (top<0) { scrollbars = "yes"; top = 32; windowheight =  screen.height - 2*top - 18; top = top - 18; }

    var win = window.open("",name,"toolbar=no,location=no,directories=no,"+
        "status=no,menubar=no,scrollbars=" + scrollbars + ",resizable=no,"+
        "copyhistory=no, width="+windowwidth+",height="+windowheight+",left=" + left + ",top=" + top);
    win.document.write("\<HEAD\>\<link rel=\"stylesheet\" type=\"text\/css\" href=\"\/style.css\"\/\>\<meta http-equiv=\"pragma\" content=\"no-cache\"\>\<TITLE\>"+title+"\<\/TITLE\>");
    win.document.write("\<link rel=\"STYLESHEET\" type=\"text/css\" href=\"css/style.css\"\>");
    win.document.write("\<\/HEAD\>");
    win.document.write("\<BODY topmargin=0 leftmargin=0\>\<center\>\<img src=\""+url+"\" width=\""+width+"\" height=\""+height+"\" border=0 vspace=\"10\" hspace=\"10\"\>\<BR\>\<a href=\"javascript:window.close();\" class=\"popup\"\>Close\<\/a\>\<\/center\>\<\/BODY\><\/HTML\>");
}


/*=============================================================================
	FLASH IMAGE
==============================================================================*/
function flashImageInit(){
	if (mediaPrint)
		return;

	var allTags = document.getElementsByTagName("img");
	var allElements = new Array();
	if (allTags) {
		for (q=0; q<allTags.length; q++) {
			obj = allTags[q];

			if (obj.className == "flash_border"){
				allElements[allElements.length] = obj;
			}
		}
	}

	if (allElements.length == 0)
		return;

	for (w=0; w<allElements.length; w++)
		transformImageToFlash(allElements[w]);

}


function transformImageToFlash(imgObj){
	var divObj = imgObj.parentNode;
	if (!divObj){
		alert("transformImageToFlash ERROR: Parent not found!");
		return;
	}

	var href = "";
	if (divObj.tagName == "A"){
		href = divObj.href;
		divObj = divObj.parentNode;
	}
	if (divObj.tagName != "DIV"){
		alert("transformImageToFlash ERROR: Parent is not the DIV!");
		return;
	}

	var imgWidth = imgObj.width;
	var imgHeight = imgObj.height;
	var imgSrc = imgObj.src;

	divObj.style.width = imgWidth + "px";
	divObj.style.height = imgHeight + "px";

	var swfImage = new FlashTag("/swf/flash_image.swf", "550", "400");
	var flashVars = "wi=" + imgWidth + "&he=" + imgHeight + "&imgSrc=" + escape(imgSrc);
	if (href.length > 1)
		flashVars += "&href=" + escape(href);
	swfImage.flashVars = flashVars;
	swfImage.wmode = "transparent";
	swfImage.scale = "noscale";
	//exactfit,
	swfImage.salign = "lt";
	swfImage.writeObjElement(divObj);

	return true;
}

/* ----------------------------------------------------------------------
	COOKIE
---------------------------------------------------------------------- */
function getCookie(name)
{
	var arg	= name + '=';
	var alen = arg.length;
	var	clen =document.cookie.length;
	var i = 0;
	while (i<clen)
	{
		var j = i + alen;
		if (document.cookie.substring(i,j)==arg) return getCookieVal(j);
		i = document.cookie.indexOf(" ",i) + 1;
		if (i==0) break;
	};
	return null;
}


function setCookieValue(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookieVal(offset)
{
	var endstr = document.cookie.indexOf(";", offset);
	if (endstr==-1) endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset,endstr));
}

function delCookie(name)
{
	if (getCookie(name))
		document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

