function okno(url, width, height) {
        var win = window.open(url,"okienko",'width=' + width + ',height=' + height + ',resizable=yes,scrollbars=yes,menubar=no' );
}


function empty(elem, helperMsg){
	if($(elem).value.length == 0){		
		$(elem).focus(); // set the focus to this input
		$(elem + "v").innerHTML = helperMsg;
		return true;
	}
	$(elem + "v").innerHTML = '';
	return false;
}

function emptyTwo(elem1, elem2, helperMsg){
	if($(elem1).value.length == 0 && $(elem2).value.length == 0){
		$(elem1 + "v").innerHTML = helperMsg;
		$(elem1).focus(); // set the focus to this input
		return true;
	}
	$(elem1 + "v").innerHTML = '';
	return false;
}

function lengthMinMax(elem, min, max){
	var uInput = $(elem).value;
	if(uInput.length >= min && uInput.length <= max){
		$(elem + "v").innerHTML = '';
		return true;
	}else{
		$(elem + "v").innerHTML = "Pole powinno zawierać od " +min+ " do " +max+ " znaków.";
		$(elem).focus();
		return false;
	}
}

function lengthMax(elem, max){
	var uInput = $(elem).value;
	if(uInput.length <= max){
		$(elem + "v").innerHTML = '';
		return true;
	}else{
		$(elem + "v").innerHTML = "Pole powinno zawierać maksymalnie do " +max+ " znaków.";
		$(elem).focus();
		return false;
	}
}

function emailValidator(elem, helperMsg){
	var Input = $(elem).value;
	if(Input.length > 0) //jesliwypelnione pole mail to wtedy sprawdzamy
	{
		var Exp = /^[0-9a-z_.-]+@([0-9a-z-]+\.)+[a-z]{2,6}$/;
		if($(elem).value.match(Exp)){
			$(elem + "v").innerHTML = '';
			return true;
		}else{
			$(elem + "v").innerHTML = helperMsg;
			$(elem).focus();
			return false;
		}
	}return true;
}

function telValidator(elem, helperMsg){
	var Input = $(elem).value;
	if(Input.length > 0) //jesliwypelnione pole mail to wtedy sprawdzamy
	{
		var Exp = /^\+?[0-9- ]+$/;
		if($(elem).value.match(Exp)){
			$(elem + "v").innerHTML = '';
			return true;
		}else{
			$(elem + "v").innerHTML = helperMsg;
			$(elem).focus();
			return false;
		}
	}return true;
}



function isNumeric(elem, helperMsg, idMsg){
	var numericExpression = /^[0-9]+$/;
	if($(elem).value.match(numericExpression)){
		return true;
	}else{
		$(idMsg).innerHTML = helperMsg;
		$(elem).focus();
		return false;
	}
}

function isAlphabet(elem, helperMsg, idMsg){
	var alphaExp = /^[a-zA-Z]+$/;
	if($(elem).value.match(alphaExp)){
		return true;
	}else{
		$(idMsg).innerHTML = helperMsg;
		$(elem).focus();
		return false;
	}
}

function isAlphanumeric(elem, helperMsg, idMsg){
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if($(elem).value.match(alphaExp)){
		return true;
	}else{
		$(idMsg).innerHTML = helperMsg;
		$(elem).focus();
		return false;
	}
}
function refreshCena(f)
{
	
	var rds = document.getElementsByTagName("input");
	var cena_cech = 0;
	var cena_bazowa = parseFloat($("cena_bazowa").value);
	
	var cena_bazowa_prom = parseFloat($("cena_bazowa_prom").value);
	
	for(i = 0; i < rds.length; i++) {
        
        if(rds[i].type=="radio"  && rds[i].checked) 
		{   				
			cena_cech += parseFloat($("cena_a_" + rds[i].value).value); 			
        }
    }
	
	
	
	if(cena_bazowa > 0 )//&& cena_cech > 0
	{
	if(cena_bazowa_prom>0) $("cena").innerHTML =  "cena: <b class=\"szczeg_oper_cena_p\">" + (cena_bazowa + cena_cech).toFixed(2) + " zł</b>";
		else $("cena").innerHTML =  "cena: " + (cena_bazowa + cena_cech).toFixed(2) + " zł";
		//new Effect.Shake('cena', { duration: 0.5, distance: 5});
	}
	//else $("cena").innerHTML =  "cena: "+ cena_bazowa.toFixed(2) + " zł";
	
	if(cena_bazowa_prom > 0 )//&& cena_cech > 0
	{	
		$("cena_prom").innerHTML =  "promocja: " + (cena_bazowa_prom + cena_cech).toFixed(2) + " zł";
		//new Effect.Shake('cena_prom', { duration: 0.5, distance: 5});
	}
	//else $("cena_prom").innerHTML =  "promocja: "+ cena_bazowa_prom.toFixed(2) + " zł";
	

}



function rozwijanie_cech(cecha){

var cecha_link = $(cecha+'_link');
cecha = $(cecha);

if(cecha.style.display=='none' && cecha.style.height==0)
{
	Effect.BlindDown(cecha,{duration: 0.3});
	cecha_link.style.backgroundImage="url(images/minus.png)";
}
else if(cecha.style.display=='' && cecha.style.height=='')
{
	Effect.BlindUp(cecha,{duration: 0.3});

	cecha_link.style.backgroundImage="url(images/plus.png)";
}
cecha_link.style.backgroundRepeat="no-repeat";
cecha_link.style.backgroundPosition="right";


}

function buttony(ob)
{
	
	ob = $(ob);
	var hide = ob.visible() ? false : true;
	ob.show();
	
	var cont = new Element('span');
	var cont_left = new Element('span');
	var cont_right = new Element('span');
	cont.addClassName('buttony');
	cont_left.addClassName('buttony_left');
	cont_right.addClassName('buttony_right');
	cont.clonePosition(ob,{setHeight:false});
	ob.replace(cont)
	cont.appendChild(cont_left);
	cont.appendChild(cont_right);
	cont.appendChild(ob);
	
	
	
	cont.style.width = ((cont.getWidth() || 31) + 7) + 'px';

	if(hide) cont.hide();
	
}
function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = false; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

function selecty(ob)
{
	
	ob = $(ob);
	
	var cont = new Element('span');
	var inputh = new Element('input',{'type':'hidden','name':ob.name});
	var input = new Element('input',{'type':'text','readonly':'readonly'});
	var lista = new Element('ul');
	
	inputh.onchange = Object.isFunction(ob.onchange) ? ob.onchange : function(){};
	
	
	var focusInput = function(event){
		lista.show();
	}	
	
	var blurInput = function(event){
		lista.hide();
	}	
	
	var clickInput = function(event){
		lista.toggle();
	}
	
	var clickLi = function(event,ob){
		input.value = ob.innerHTML;
	
		inputh.value = ob.wart;
		
		inputh.onchange();
		
		lista.hide();
	}	
	
	
	var option2li = function(ob)
	{
	
		var li = new Element('li');
		li.wart = ob.value;
		li.update(ob.text);
		lista.appendChild(li);
		Element.observe(li,'click',clickLi.bindAsEventListener(this,li));
		
	}
	
	$A(ob.options).each(option2li);
	
	cont.addClassName('selecty');
	input.clonePosition(ob,{setLeft:false,setTop:false,setHeight:false});
	input.value = ob.options[ob.selectedIndex].text;
	inputh.value = ob.value;
	cont.appendChild(input);
	cont.appendChild(inputh);
	cont.appendChild(lista);
	cont.style.height = input.getHeight() + 'px';
	lista.hide();
	ob.replace(cont);
	
	
	Element.observe(input,'click',clickInput.bindAsEventListener(this));
	Element.observe(lista,'mouseover',focusInput.bindAsEventListener(this));
	Element.observe(lista,'mouseout',blurInput.bindAsEventListener(this));
}

function animacjaLogo()
{
	var logo = $('logo');
	Element.setStyle(logo,{top: (200 * Math.random() - 100) + 'px', left: (500 * Math.random()) + 'px'});
	var listaEf = [new Effect.Morph(logo,{style:'top:80px;left:340px',duration:2,transition:Effect.Transitions.spring})];
	if(!Prototype.Browser.IE) listaEf.push(new Effect.Opacity(logo, {duration:2, from:0, to:1.0}));
	new Effect.Parallel(listaEf);
}

function zoomImg(container,opcje)
{
	opcje = opcje || {};
	
	opcje.max = opcje.max || 100;
	opcje.min = opcje.min || 50;
	opcje.duration = opcje.duration || 0.3
	
	this.margin = (opcje.min - opcje.max) / 2;

	this.elements = $A($(container).select('img'));
	
	this._appear = function(event,element){
			new Effect.Morph($(element),{style:'width:' + opcje.max + 'px;margin:' + this.margin + 'px 0 0 ' + this.margin + 'px',duration:opcje.duration});
		}
	
	this._fade = function(element){
			new Effect.Morph($(element),{style:'width:' + opcje.min + 'px;margin:0',duration:opcje.duration})
		}
			
	this._fadeTimeout = function(event,element){
			this._fade.delay(0.2,element);
		}
	
	this.init = function(element){
			Element.observe(element,'mouseover',this._appear.bindAsEventListener(this,element));	
			Element.observe(element,'mouseout',this._fadeTimeout.bindAsEventListener(this,element));
		}

	this.elements.each(this.init);
	
}

document.observe('dom:loaded',function(){
	$A($$('button, input[type="button"]:not([alt="nb"]), input[type="submit"]:not([alt="nb"])')).each(buttony); 

	//animacjaLogo()
	
	
	
	
	
});

if((getInternetExplorerVersion() || 8) > 7) document.observe('dom:loaded',function(){$A($$('select')).each(selecty);});

function preloaderAjax(obiektId)
{
	try
	{
		var ob = $(obiektId);
		var preloader = new Element('div',{'id':'preloaderAjax','class':'preloader'});
		document.body.appendChild(preloader);
		Element.clonePosition(preloader,ob);
	
	}
	catch(e){}
}

function hidePreloader(){
	var preloader = $('preloaderAjax');
	if(preloader) preloader.remove();
}

function wyszukiwarkaClick(ob)
{
	var tekst = $F(ob);
	$(ob).onfocus = function(){
		if(this.value == tekst) this.value = '';
	};

	$(ob).onblur = function(){
		if(this.value == '') this.value = tekst;
	};
}

