function pobierz(nazwa) {
    if (document.cookie.length > 0) {
        startc = document.cookie.indexOf(nazwa + "=");
        if (startc != -1) {
            startc += nazwa.length + 1;
            endc = document.cookie.indexOf(";", startc);
            if (endc == -1) {
                endc = document.cookie.length;
            }
            return unescape(document.cookie.substring(startc,endc));
        }
	return false;
    }
    return false;
}

function rejestruj(nazwa, wartosc,dni) {
    var dzisiaj=new Date();
    var wygasnie=new Date();
    !dni ?dni=7 :"";
    wygasnie.setTime(dzisiaj.getTime()+1000*60*60*24*dni);
	document.cookie=nazwa+"="+escape(wartosc)+";expires="+wygasnie.toGMTString();
}

jQuery(function( $ ){

	//borrowed from jQuery easing plugin
	//http://gsgd.co.uk/sandbox/jquery.easing.php
	$.easing.elasout = function(x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	};

});


$(window).load(function(){
	if ($("#main_brown").height() < $("#left").height()) {
		$("#left, #main_brown").equalizeCols();
		$("#main_brown").height($("#main_brown").height()-16);
	}
	
});

var allGminy = '';

function all_gminy() {


	var opts = document.getElementById('s_gmina').options;

	opts.length = 1;

	var i = 1;
	var g,l;
	var ii = 0;
	/*		
	for (g in gminy) {
		
		op = document.createElement('optgroup');
		op.label = g;

		try {
			opts.add(op, opts.options[i]); // firefox
		
		}
		catch (ex) {
			opts.add(op, i); // ie
		} 
		++i;
		


			for (l in gminy[g]) {
				op = document.createElement('option');
				op.text = gminy[g][l];
		
				try {
				  opts.add(op, opts.options[i]); // firefox
					
				}
				catch (ex) {
				  opts.add(op, i); // ie
							
				} 
				++i;

			}

	}
*/

		for (l in agminy) {
			op = document.createElement('option');
			op.text = agminy[l];
		
			try {
				  opts.add(op, opts.options[i]); // firefox
			}
			catch (ex) {
				opts.add(op, i); // ie
					
			} 
			++i;

		}

}

$(document).ready( function(){



	$('input.onclick-clear').each(function() {
		if (this.title != '' && this.value == '') {
			this.value = this.title;
			this.title = '';
		}
		else if (this.title != '' && this.value != '' && this.title != this.value) {
			$(this).removeClass('onclick-clear');
		}
		else if (this.title != '' && this.value != '' && this.title == this.value) {
			this.title = '';
		}		
	});

	
	$('input.onclick-clear').focus(function(){
		if (this.title == '') {
			this.title = this.value;
			this.value = '';
			$(this).removeClass('onclick-clear');
		}

	});

	$('input.onclick-clear').blur(function(){
		if (this.title != '' && this.value == '' ) {
			this.value = this.title;
			this.title = '';
			$(this).addClass('onclick-clear');	
		}
	});




	$("form").submit(function() {
		$('input.onclick-clear', this).each(function() {
			if (this.title == '' && this.value != '') this.value = '';
		});
	});







// http://bassistance.de/jquery-plugins/jquery-plugin-tooltip/


	




	$("#s_powiat").change(function(){
		

		if (this.value != '') {

		var opts = document.getElementById('s_gmina').options;
		opts.length = 1;

		var i = 1;
		for (l in gminy[this.value]) {
			op = document.createElement('option');
			op.text = gminy[this.value][l];

			try {
			  opts.add(op, opts.options[i]); // firefox
			
			}
			catch (ex) {
				opts.add(op, i); // ie
			} 
			++i;
		}
		}
		else all_gminy();


		
	});
	
});



/*
	
	ind = document.getElementById('cecha'+n).options.length;
	document.getElementById('cecha'+n).options[ind] = new Option(ptypy[kod][n],ptypy[kod][n]);
	optVals[n][kod] = ptypy[kod][n];
	if (selOpt[n] == ptypy[kod][n]) document.getElementById('cecha'+n).selectedIndex = ind;

*/

$(function() {
   $('a[rel*=lightbox]').lightBox({
	overlayBgColor: '#000',
	overlayOpacity: 0.7,
	imageLoading: '/img/lb/lightbox-ico-loading.gif',
	imageBtnClose: '/img/lb/closelabel.gif',
	imageBtnPrev: '/img/lb/prev.gif',
	imageBtnNext: '/img/lb/next.gif',
	containerResizeSpeed: 350,
	txtImage: 'Ilustracja',
	txtOf: 'z'
   });
});
