function sendFormActionRedirect(formname, action, redirect){
	document.forms[formname].action = redirect;
	document.forms[formname].k_a.value = action;
	document.forms[formname].submit();
}

function sendFormAction(formname, action){
	document.forms[formname].k_a.value = action;
	document.forms[formname].submit();
}

function sendFormActionAsk(formname, action,pytanie){
	if(confirm(pytanie)){
		document.forms[formname].k_a.value = action;
		document.forms[formname].submit();
	}
}

function sendFormAsk(formname,pytanie){
	if(confirm(pytanie)){
		document.forms[formname].submit();
	}
}


function sendForm(formname){
	document.forms[formname].submit();
}

function linkAsk(pytanie, link){
	if(confirm(pytanie)){
		location.href = link;
	}
}

function linkTo(link){
	location.href = link;
}

function checkAll(nazwa)
  {
  for (var i=0;i<document.list.elements.length;i++)
    {
    var e = document.list.elements[i];
    var re = new RegExp(nazwa);
    if ((e.name != nazwa) && (re.test(e.name))){
      e.checked = document.list.lidall.checked;
      }
    }
  }

function newWindow(strona,_width,_height,_positionX,_positionY,autoprint){
	var width=450;
	var height=350;
	if (_width!=0 && _height!=0) {
		if (_width<0) {
			width=-0.01*screen.width*_width;
		}else {width=_width;}
		if (_width<0) {
			{height=-0.01*screen.height*_height;}
		}else 	 {height=_height;}
	}
	if (_positionX!=0 && _positionY!=0){
		var top=(screen.height-height)*0.01*_positionY;
		var left=(screen.width-width)*0.01*_positionX;
		}
	okienko=window.open(strona,'','left='+left+',top='+top+',toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes,personalbar=no,directories=no,status=no,width='+width+',height='+height);
	okienko.focus();
	if (autoprint==true) okienko.onload=okienko.print;
}	

function newWindowAsk(pytanie,strona,_width,_height,_positionX,_positionY,autoprint){
	if(confirm(pytanie)){
		newWindow(strona,_width,_height,_positionX,_positionY,autoprint);
	}
}


function newWindow2(strona){
	okienko=window.open(strona,'');
	okienko.focus();
}	



function resize() {
  var i=0;
  if (navigator.appName == 'Netscape') i=40;
  if (document.images[0]) window.resizeTo(document.images[0].width +30, document.images[0].height+60-i);
  self.focus();
}


function dymek(T,t){
 T.title='';
 T.parentNode.lastChild.style.display=t?'block':'none';
}

function flipDisplay(rid)
	{
	current=(document.getElementById(rid).style.display == 'none') ? 'block' : 'none';
	document.getElementById(rid).style.display = current;
	}

function flipDisplayNewsEditor(rid1,rid2)
	{
	current=(document.getElementById(rid1).style.display == 'none') ? 'block' : 'none';
	document.getElementById(rid1).style.display = current;

	current=(current=='none') ? 'block' : 'none';
	document.getElementById(rid2).style.display = current;
	}

function sendNumber(url,ile,podpis,endlink)
{
	var ilosc =  prompt (podpis, ile );		
	
	if ( !isNaN(parseInt(ilosc)) ) 
	{
		location.href = url + ilosc + endlink;
	}
}
function sendText(url,text,podpis,endlink)
{
	var text =  prompt (podpis, text );
	if (text!=null){
		location.href = url + text + endlink;
	}
}

function trim(value) {
   var temp = value;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
   var obj = / +/g;
   temp = temp.replace(obj, " ");
   if (temp == " ") { temp = ""; }
   return temp;
}

function k_hide_obj(hide){
		if (hide){
			embeds = document.getElementsByTagName('embed');
			for(i = 0; i < embeds.length; i++) {
			embeds[i].style.visibility = 'hidden';
			}
			objects = document.getElementsByTagName('object');
			for(i = 0; i < objects.length; i++) {
			objects[i].style.visibility = 'hidden';
			}
			applets = document.getElementsByTagName('applet');
			for(i = 0; i < applets.length; i++) {
			applets[i].style.visibility = 'hidden';
			}
		}else{
			embeds = document.getElementsByTagName('embed');
			for(i = 0; i < embeds.length; i++) {
			embeds[i].style.visibility = 'visible';
			}
			objects = document.getElementsByTagName('object');
			for(i = 0; i < objects.length; i++) {
			objects[i].style.visibility = 'visible';
			}
			applets = document.getElementsByTagName('applet');
			for(i = 0; i < applets.length; i++) {
			applets[i].style.visibility = 'visible';
			}
		}
}

function kengine_result(code,header,message){
	//if (document.getElementById('flash_message')==null) return;
	$('flash_message_title').innerHTML= header;
	$('flash_message_contents').innerHTML= message;
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	//sreodek:var flashTop = arrayPageScroll[1] + ((arrayPageSize[3] - Element.getHeight('flash_message')) / 2);
	//sreodek:var flashLeft = ((arrayPageSize[2] - Element.getWidth('flash_message'))/2);
	var flashTop = arrayPageScroll[1] + (30);
	var flashLeft = 30;

	Element.setTop('flash_message', flashTop);
	Element.setLeft('flash_message', flashLeft);
	switch(code){
		case "ok"://ok 
			$('flash_message').className="flash_message_ok";
			setTimeout(function(){new Effect.Fade('flash_message')},1000);
		break;
		case "error"://blad
				$('flash_message').className="flash_message_error";
		break;
	}
	Element.show('flash_message');

	/*
	obj = document.getElementById('flash_message');
	if (obj==null) return;
	obj.innerHTML = text;
	*/
	
}


/*---------------------------------------*/
// -----------------------------------------------------------------------------------
// Powtorzone w lightbox..
//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

// -----------------------------------------------------------------------------------
// Powtorzone w lightbox..
//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

// -----------------------------------------------------------------------------------


/*--------------DODATKI DO ELEMENTS-----*/
//https://www.tennaxia.net/ujf/doc/overview-summary-common.js.html
/**
 * takes care of adding the 'px' unit if not present
 */
Element.toPx = function(measure) {
    if (! isNaN(measure)) {
        measure += 'px';
    }
    return measure;
}

/**
 * Sets the height of an element, taking care of adding the 'px' unit if not present
 */
Element.setHeight = function(element, h) {
    if (h == null || h == undefined) return;
    $(element).style.height = Element.toPx(h);
}

/**
 * Sets the width of an element, taking care of adding the 'px' unit if not present
 */
Element.setWidth = function(element, w) {
    if (w == null || w == undefined) return;
    $(element).style.width = Element.toPx(w);
}

/**
 * Sets the width and the height of an element, taking care of adding the 'px' unit if
 * not present
 */
Element.setDimensions = function(element, w, h) {
    Element.setHeight(element, h);
    Element.setWidth(element, w);
}

/**
 * Sets the top coordinate of an element, taking care of adding the 'px'
 * unit if not present
 */
Element.setTop = function(element, top) {
    if (top == null || top == undefined) return;
    $(element).style.top = Element.toPx(top);
}

/**
 * Sets the left coordinate of an element, taking care of adding the 'px'
 * unit if not present
 */
Element.setLeft = function(element, left) {
    if (left == null || left == undefined) return;
    $(element).style.left = Element.toPx(left);
}

/**
 * Sets the top and the left coordinate of an element, taking care of adding the 'px'
 * unit if not present
 */
Element.setPosition = function(element, left, top) {
    Element.setTop(element, top);
    Element.setLeft(element, left);
}
