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(divid,inputname,aaction){
  //var tab = $(divid).adjacent('input[name='+inputname+']');
  var tab = $(divid).adjacent('input[name=\''+inputname+'\']');
  //var tab = $(divid).adjacent('input');
  for (var i=0;i<tab.length;i++){
	//alert(tab[i].name);
      switch(aaction){
      case 'select': tab[i].checked=true;break;
      case 'unselect':tab[i].checked=false;break;
      case 'flip':
      default:
       tab[i].checked = !tab[i].checked;break;
      }
  }
/*
  var es = document.getElementsByTagName("input");
  for (var i=0;i<es.length;i++)
    {
    var e = es[i];
    var re = new RegExp(nazwa);
    if ((e.name != nazwa) && (re.test(e.name))){
      switch(tryb){
      case 'select': e.checked=true;break;
      case 'unselect':e.checked=false;break;
      case 'flip':
      default:
       e.checked = !e.checked;break;
      }
      }
    }
*/
}

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;
}

var hide_obj_stack=0;
function k_hide_obj(hide,force){
		if (hide){
			hide_obj_stack++;
			//alert(hide_obj_stack);
			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{
			hide_obj_stack--;
			if (hide_obj_stack<=0 || force==true){
				hide_obj_stack=0;
				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;
	*/
	
}

function k_background(divid){
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	var topposition = arrayPageScroll[1] + (arrayPageSize[3] / 15);
	Element.setWidth(divid,arrayPageSize[0]);
	Element.setHeight(divid,arrayPageSize[1]);
}

function k_overlay(enable,showclosebutton,divid){
	if (divid==null) divid='koverlay';
	var div = document.getElementById(divid);
	if (div==null){
		var objBody = document.getElementsByTagName("body").item(0);
		var objOverlay = document.createElement("div");
		objOverlay.setAttribute('id',divid);
		objOverlay.style.display = 'block';
		if (showclosebutton==true) {
			var objOverlayCloseButton = document.createElement("a");
			objOverlayCloseButton.setAttribute('class','closewindow');
			objOverlayCloseButton.setAttribute('title','ZAMKNIJ OKNO');
			objOverlayCloseButton.setAttribute('onclick',"javascript:window.close();return false");
			objBody.appendChild(objOverlayCloseButton);
		}
		objBody.appendChild(objOverlay);
		var arrayPageSize = getPageSize();
		var arrayPageScroll = getPageScroll();
		var topposition = arrayPageScroll[1] + (arrayPageSize[3] / 15);
		Element.setWidth(divid,arrayPageSize[0]-25);
		Element.setHeight(divid,arrayPageSize[1]);
	}
}

function k_loadjscssfile(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script');
  fileref.setAttribute("type","text/javascript");
  fileref.setAttribute("src", filename);
 }
 else if (filetype=="css"){ //if filename is an external CSS file
  var fileref=document.createElement("link");
  fileref.setAttribute("rel", "stylesheet");
  fileref.setAttribute("type", "text/css");
  fileref.setAttribute("href", filename);
 }
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref);
}
/*---------------------------------------*/
// -----------------------------------------------------------------------------------
// 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;
}

// -------calendar ---------
	/** 
	 @param p_dateformat 'yyyy-mm-dd hh:ii'
	 @param p_isDragable - true|false
	 @param p_displayTimeBar - true|false
	 @param p_lang pl|de|en
	*/
	function _pickDate(buttonObj,inputObject,p_dateFormat,p_lang,p_displayTimeBar,p_isDragable){
		
		var myCalendarModel = new DHTMLSuite.calendarModel({});
		if (p_lang==null) p_lang='pl';
		myCalendarModel.setLanguageCode(p_lang);
	
		var calendarObjForForm = new DHTMLSuite.calendar({minuteDropDownInterval:1,numberOfRowsInHourDropDown:5,callbackFunctionOnDayClick:'__pickDateGetDateFromCalendar'
		,isDragable:p_isDragable,displayTimeBar:p_displayTimeBar}); 
		calendarObjForForm.setCalendarModelReference(myCalendarModel);
		calendarObjForForm.dateformat = p_dateFormat;
		calendarObjForForm.setCalendarPositionByHTMLElement(inputObject,0,inputObject.offsetHeight+2);	// Position the calendar right below the form input
		calendarObjForForm.setInitialDateFromInput(inputObject,p_dateFormat);	// Specify that the calendar should set it's initial date from the value of the input field.
		calendarObjForForm.addHtmlElementReference('myDate',inputObject);	// Adding a reference to this element so that I can pick it up in the getDateFromCalendar below(myInput is a unique key)
		if(calendarObjForForm.isVisible()){
			calendarObjForForm.hide();
		}else{
			calendarObjForForm.resetViewDisplayedMonth();	// This line resets the view back to the inital display, i.e. it displays the inital month and not the month it displayed the last time it was open.
			calendarObjForForm.display();
		}		
	}	

	/* inputArray is an associative array with the properties
	year
	month
	day
	hour
	minute
	calendarRef - Reference to the DHTMLSuite.calendar object.
	*/
	function __pickDateGetDateFromCalendar(inputArray){
		var references = inputArray.calendarRef.getHtmlElementReferences(); // Get back reference to form field.
		references.myDate.value = inputArray.calendarRef.dateformat.replace(/(y)+/gi, inputArray.year);
		references.myDate.value = references.myDate.value.replace(/(m)+/gi, inputArray.month);
		references.myDate.value = references.myDate.value.replace(/(d)+/gi, inputArray.day);
		references.myDate.value = references.myDate.value.replace(/(h)+/gi, inputArray.hour);
		references.myDate.value = references.myDate.value.replace(/(i)+/gi, inputArray.minute);
		inputArray.calendarRef.hide();
	}	
/*--------------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);
}

//loader odpalany w onload. Moze byc nadpisany np. podczas podgladu strony
function k_loader(){
	k_loader2();
}

function k_loader2(){
}

function k_tab(params,id){
	//alert(params.tabs.length);	
 	for (var i=0;i<params.tabs.length;i++){
		$(params.tabs[i]).hide();
	}

 	for (var i=0;i<params.tabs.length;i++){
		if (params.tabs[i]==id)	$(params.tabs[i]).show();
	}

}

function k_inplaceeditor(type,id,value){
    //var undo = $(id).innerHTML;
    new Ajax.InPlaceEditor('id', '/demoajaxreturn.html', {rows:15,cols:40});
    //$(id).innerHTML='<input type="text" value="' + value + '" /><a hrf="#" onclick="javascript:$(\'' + id + '\').innerHTML = \'' + value + '\'">anuluj</a>';
}

function kengine_tiny_presubmit(textareaid){
	tinyMCE.get(textareaid).save();
}


document.observe('dom:loaded',function(){k_patentFlash();}) 


