function popupWindow(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=300,height=350,screenX=150,screenY=150,top=150,left=50');
}


var okno = null;
function window_open(page,PosX,PosY,width,height)
{
  borderless = false;
  
  if(okno != null && !document.layers)
  {
    okno.close();
  }
  if(borderless && !document.layers)
  {
	okno = window.open(page, "", "fullscreen=0, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=yes, resizable=0");
	okno.resizeTo(w, s);
	okno.moveTo(PosX, PosY);
  }
  else
  {
	okno = window.open(page, "", "menubar=no, toolbar=no, location=no, directories=no, status=no, scrollbars=yes, resizable=no, copyhistory=no, width=" + width + ", height=" + height + ", left=" + PosX + ", top=" + PosY);
  }
  okno.focus()
}
function window_open_scroll(page,PosX,PosY,width,height)
{
  borderless = false;
  
  if(okno != null && !document.layers)
  {
    okno.close();
  }
  if(borderless && !document.layers)
  {
	okno = window.open(page, "", "fullscreen=0, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=yes, resizable=0");
	okno.resizeTo(w, s);
	okno.moveTo(PosX, PosY);
  }
  else
  {
	okno = window.open(page, "", "menubar=no, toolbar=no, location=no, directories=no, status=no, scrollbars=yes, resizable=no, copyhistory=no, width=" + width + ", height=" + height + ", left=" + PosX + ", top=" + PosY);
  }
  okno.focus()
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

function showAndHide(id) {
	var oMyDiv = document.getElementById(id);
	if(oMyDiv.style.display=='none') oMyDiv.style.display='block';
	else if(oMyDiv.style.display=='block') oMyDiv.style.display='none';
}

function start() {

	//start
//	alert($('header_inf'));
//	$('header_inf').appear();
	Effect.Pulsate('header_inf', { pulses: 110, duration: 60, from: 0.2 });
	Effect.Pulsate('inf_med', { pulses: 110, duration: 60, from: 0.2 });
	if(jskomShow&&$('komunikat')) {

		jskomAppear();

		$('komunikat').observe('click',jskomFadeOut);

	}

}

window.onload = start;



function setText(oTextInput) {

	if(oTextInput.value=='') oTextInput.value = oTextInput.defaultValue;

}

function clearText(oTextInput) {

	if(oTextInput.value==oTextInput.defaultValue) oTextInput.value = '';

}



function isEmail(address) {

   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

   return(reg.test(address));

}



function newImage(arg) {

	if (document.images) {

		rslt = new Image();

		rslt.src = arg;

		return rslt;

	}

}



function changeImages() {

	if (document.images && (preloadFlag == true)) {

		for (var i=0; i<changeImages.arguments.length; i+=2) {

			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];

		}

	}

}



function selectedRadioValue(oForm, sRadioName) {

	var retval = '';

	for(var i=0;i<oForm.elements.length;i++) {

		if(oForm.elements[i].type!='radio'||oForm.elements[i].name!=sRadioName) continue;

		if(oForm.elements[i].checked) retval = oForm.elements[i].value;

	}

	return retval;

}



var jskomShow=false;

var jskomZostaw=true;

var peJskom;

function jskomAppear() {

	try{

		//Effect.Appear('jskom');

		$('komunikat').show();

	}

	catch (exc) {

		$('komunikat').show();

	}

	if(!jskomZostaw) peJskom = new PeriodicalExecuter(function(peJskom) {

			jskomFadeOut();

		}, 4);

}

function jskomFadeOut() {

	try{

		Effect.Fade('komunikat');

		}

	catch (exc) {

		$('komunikat').hide();

	}

	//$('komunikat').update('');

	if(peJskom) peJskom.stop();

}



var img;

var galFotos = [];

var aktFoto = 0;

function setGal(fot,fotos) {

	if(typeof fotos=='object') galFotos = fotos;

	else galFotos = [];

	$('bigFotoContainer').show();

	aktFoto = 0;

	if(galFotos.length>0) {

		for(var i=0;i<galFotos.length;i++) {

			if(galFotos[i]==fot) aktFoto = i;

		}

	}

	pokazFotoGal(fot);

}

function pokazFotoGal(fot) {

	$('bigFotoImg').update('<img src="images/czekaj_pl.gif" border="0" />')

	img = new Element('img');

	img.id = 'theimage';

	img.observe('load', showimg);

	//document.body.appendChild(img);

	img.src = fot;

	//$('bigFotoImg').update('<img src="'+fot+'" border="0" />';

	$('bigFotoImg').show();

	fotoNav();

	//$('main').hide();	

}

function pokazFoto(fot) {

	galFotos = [];

	$('bigFotoImg').update('<img src="images/czekaj_pl.gif" border="0" />')

	img = new Element('img');

	img.id = 'theimage';

	img.observe('load', showimg);

	//document.body.appendChild(img);

	img.src = fot;

	//$('bigFotoImg').update('<img src="'+fot+'" border="0" />';

	$('bigFotoImg').show();

	$('bigFotoContainer').show();

	//$('main').hide();

	aktFoto = 0;

	fotoNav();

}

function showimg(evt) {

	$('bigFotoImg').hide();

	$('bigFotoImg').update(img);

	$('bigFotoImg').show();

	var dim = document.viewport.getDimensions();

	if(img.width>dim.width||img.height>dim.height-160) {

		var new_size = image_small_maker(img.width, img.height, dim.width, dim.height-160)

		img.setStyle({'width':new_size[0]+'px','height':new_size[1]+'px'});

	}

}

function wywalFoto() {

	$('bigFotoContainer').hide();

	$('bigFotoImg').hide();

	//$('main').show();

}

function fotoNav() {

	if(aktFoto>0) $('bigFotoPrev').show();

	else $('bigFotoPrev').hide();

	if(aktFoto<galFotos.length-1) $('bigFotoNext').show();

	else $('bigFotoNext').hide();

}

function prevFoto() {

	if(aktFoto<=0) return;

	aktFoto--;

	pokazFotoGal(galFotos[aktFoto]);

}

function nextFoto() {

	if(aktFoto>galFotos.length-1) return;

	aktFoto++;

	pokazFotoGal(galFotos[aktFoto]);

}

function image_small_maker(orig_width, orig_height, max_width, max_height) {

	var xRatio = max_width / orig_width; 

	var yRatio = max_height / orig_height; 

	var new_width = 0;

	var new_height = 0;

	if ( (orig_width <= max_width) && (orig_height <= max_height) ) { 

	 new_width = orig_width; 

	 new_height = orig_height; 

	} 

	else if ((xRatio * orig_height) < max_height) { 

	 new_height = Math.ceil(xRatio * orig_height); 

	 new_width = max_width; 

	} 

	else { 

		new_width = Math.ceil(yRatio * orig_width); 

		new_height = max_height; 

		}

	var output = [];

	output.push(Math.round(new_width));

	output.push(Math.round(new_height));

	return output;

}



function trim(str, chars) {

	return ltrim(rtrim(str, chars), chars);

}

 

function ltrim(str, chars) {

	chars = chars || "\\s";

	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");

}

 

function rtrim(str, chars) {

	chars = chars || "\\s";

	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");

}



/*var okno = null;

function window_open(page,PosX,PosY,width,height)

{

  borderless = false;

  

  if(okno != null && !document.layers)

  {

    okno.close();

  }

  if(borderless && !document.layers)

  {

	okno = window.open(page, "", "fullscreen=0, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=yes, resizable=0");

	okno.resizeTo(w, s);

	okno.moveTo(PosX, PosY);

  }

  else

  {

	okno = window.open(page, "", "menubar=no, toolbar=no, location=no, directories=no, status=no, scrollbars=yes, resizable=no, copyhistory=no, width=" + width + ", height=" + height + ", left=" + PosX + ", top=" + PosY);

  }

  okno.focus();

  okno = null;

}

function window_open_scroll(page,PosX,PosY,width,height)

{

  borderless = false;

  

  if(okno != null && !document.layers)

  {

    okno.close();

  }

  if(borderless && !document.layers)

  {

	okno = window.open(page, "", "fullscreen=0, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=yes, resizable=0");

	okno.resizeTo(w, s);

	okno.moveTo(PosX, PosY);

  }

  else

  {

	okno = window.open(page, "", "menubar=no, toolbar=no, location=no, directories=no, status=no, scrollbars=yes, resizable=no, copyhistory=no, width=" + width + ", height=" + height + ", left=" + PosX + ", top=" + PosY);

  }

  okno.focus()

}*/


