function start() {
	//start
	
	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 aktFotoG = 0;
function pokazFotoG(fot,top,left,width,height) {
	for(var i=0;i<gFotos.length;i++) {
		if(gFotos[i].file==fot) {
			aktFotoG=i;
			break;
		}
	}
	/*$('bigFotoGImg').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;*/
	$('bigFotoGImg').update('<img src="'+fot+'" border="0" style="display:block; position:absolute; top:'+top+'px; left:'+left+'px; width:'+width+'px; height:'+height+'px; margin;0px; padding:0px; border:1px solid #eee;" />');
	$('bigFotoGImg').show();
	$('bigFotoGContainer').show();
	//$('main').hide();
	//aktFoto = 0;
	fotoNavG();
}
function wywalFotoG() {
	$('bigFotoGContainer').hide();
	$('bigFotoGImg').hide();
	//$('main').show();
}
function fotoNavG() {
	if(aktFotoG>0) $('bigFotoGNavPrev').show();
	else $('bigFotoGNavPrev').hide();
	if(aktFotoG<gFotos.length-1) $('bigFotoGNavNext').show();
	else $('bigFotoGNavNext').hide();
}
function prevFotoG() {
	if(aktFotoG<=0) return;
	aktFotoG--;
	pokazFotoG(gFotos[aktFotoG].file,gFotos[aktFotoG].top,gFotos[aktFotoG].left,gFotos[aktFotoG].width,gFotos[aktFotoG].height);
}
function nextFotoG() {
	if(aktFotoG>gFotos.length-1) return;
	aktFotoG++;
	pokazFotoG(gFotos[aktFotoG]);
	pokazFotoG(gFotos[aktFotoG].file,gFotos[aktFotoG].top,gFotos[aktFotoG].left,gFotos[aktFotoG].width,gFotos[aktFotoG].height);
}



/*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()
}*/

