﻿//	todo - strip_tags	-> do wyszukiwarki np (wyswietlanie czego sie szukalo)
if (navigator.userAgent.indexOf('Mac')==-1&&top!=self) { top.location=self.location; };
if(document.all && !document.getElementById) {
    document.getElementById = function(id) {
         return document.all[id];
    }
}
function $$(s) { 
	if ( document.getElementById ) {
		return document.getElementById(s); 
	} else if ( document.all ) {
		return document.all[s];
	}
};
function $$$(s) { 
	if ( s.substring(0,1) == '#' ){
		if (document.getElementById) {
			var a = document.getElementById(s.substr(1));
		} else if ( document.all ) {
			var a = document.all[s.substr(1)];
		}
		if (a) {
			return a;
		}
	} else if ( s.substring(0,1) == '.' ) {
		var body = document.getElementsByTagName('body')[0];
		var a = body.getElementsByTagName('*');
		var w = new Array();
		var c = s.substring(1);
		for (var i=0; i<a.length; i++) {
			if (hasClass(a[i],c)) {
				w.push(a[i]);
			}
		}
		return w;
	}else {
		var w = new Array();
		var a = document.getElementsByTagName(s);
		for (var i=0; i<a.length; i++) {
			w.push(a[i]);
		}
		return w;
	}
};

/* rozszerzenia standardu */
//	string
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g,''); };
function trim(s) { return s.replace(/^\s+|\s+$/g, ""); };
function ucFirst(txt) {
	var fTxt=txt.substring(0,1);
	if(fTxt==txt)return txt.toLowerCase();
	var lTxt=txt.substring(1);
	fTxt=fTxt.toUpperCase(); 
	lTxt=lTxt.toLowerCase();
	return fTxt+lTxt;
};
String.prototype.ucFirst = function() { return ucFirst(this); };
function ucWords(txt)  {
	var txtArr=txt.split(" ");
	var txtOut=new String();
	for (var itxt=0, iltxt=txtArr.length;itxt<iltxt;itxt++) {
		txtOut += ucFirst(txtArr[itxt])+' ';
	}
	return txtOut.substring(0,txtOut.length-1);
};
String.prototype.ucWords = function() { return ucWords(this); };
//	array
Array.prototype.inArray = function(val) { 
	for (var i=0, ile=this.length; i<ile; i++) {
		if ( this[i] == val ) {
			return true;
		}
	}
	return false;
};
Array.prototype.find = function(searchStr) {
  var returnArray = false;
  for (i=0; i<this.length; i++) {
    if (typeof(searchStr) == 'function') {
      if (searchStr.test(this[i])) {
        if (!returnArray) { returnArray = [] }
        returnArray.push(i);
      }
    } else {
      if (this[i]===searchStr) {
        if (!returnArray) { returnArray = [] }
        returnArray.push(i);
      }
    }
  }
  return returnArray;
}
Array.prototype.sortNum = function() {
   return this.sort( function (a,b) { return a-b; } );
}
Array.prototype.shuffle = function (){ 
        for(var rnd, tmp, i=this.length; i; rnd=parseInt(Math.random()*i), tmp=this[--i], this[i]=this[rnd], this[rnd]=tmp);
};

function ExtractNumber(value) { 
	var n = parseInt(value); 
	return n == null || isNaN(n) ? 0 : n; 
};
function array_switch(arr) {
	if (!arr) return;
	var w=new Array();
	var len=arr.length;
	for (var i=0; i<len; i++) { 
		w[arr[i]]=i;
	}
	return w;
};
Array.prototype.switchIndexes = function() { array_switch(this); };

function ExtractNumber(value) { 
	var n = parseInt(value); 
	return n == null || isNaN(n) ? 0 : n; 
};

/* 	zdarzenia	*/
function addEvent(obiekt, typ, funkcja) {
	if ( typeof funkcja != "function" ) {
		return false;
	}
	if (obiekt.addEventListener)  {
    	obiekt.addEventListener(typ, funkcja, false);
  	} else if (obiekt.attachEvent) {
    	obiekt["e"+typ+funkcja] = funkcja;
    	obiekt[typ+funkcja] = function()  {
				obiekt["e"+typ+funkcja](window.event); 
			};
		obiekt.attachEvent("on"+typ, obiekt[typ+funkcja]);
  	}
	return obiekt;
};
function getEventObj(e) {
	var el;
	if (window.event && window.event.srcElement) { el = window.event.srcElement; }
	if (e && e.target) { el = e.target; }
	if (!el) { return; }					
	e.preventDefault ? e.preventDefault() : (e.returnValue = false);
	return el;
};
function getMousePosition(e) {
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) {
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) {
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	return ({'x': posx, 'y':posy});
};

/*	klasy 		*/
function hasClass(obj,c) { 
	return obj.className.match(new RegExp('(\\s|^)'+c+'(\\s|$)')); 
};
function addClass (obj, c) {
	var e=obj;
	if (!hasClass(e,c)) { 
		if (!e.className) 
			e.className = c; 
		else { 
			var newClassName = e.className; 
			newClassName += " ";	
			newClassName += c; 
			e.className = newClassName; 
		}
	}
	return e;
};
function removeClass(obj,c) { 
	var e=obj;
	if (hasClass(e,c)) {
		var reg = new RegExp('(\\s|^)'+c+'(\\s|$)'); 
		e.className=e.className.replace(reg,' '); 
	} 
	return e;	
};
function changeClass(obj,a,b) {
	var e=obj;
	if ( hasClass(e,a) ) {
		e.addClass(b);
		e.removeClass(a);
		return e;
	}
	return false;
};
/*	ciasteczka cookies		*/
function setCookie(n,v,d) {
	if (d) {
		var date = new Date();
		date.setTime(date.getTime()+(d*24*60*60*1000));
		var e = "; expires="+date.toGMTString();
	}
	else var e = "";
	document.cookie = n+"="+v+e+"; path=/";
};
function getCookie(n) {
	var name = n + "=";
	var cc;
	var c = document.cookie.split(';');
	for(var i=0;i < c.length;i++) {
		cc = c[i];
		while (cc.charAt(0)==' ') cc = cc.substring(1,cc.length);
		if (cc.indexOf(name) == 0) return cc.substring(name.length,cc.length);
	}
	return false;
};
function getCookieGA(n, par) {
	var name = n + "=";
	var cc;
	var c = document.cookie.split(';');
	for(var i=0;i < c.length;i++) {
		cc = c[i];
		while (cc.charAt(0)==' ') cc = cc.substring(1,cc.length);
		if (cc.indexOf(name) == 0) {
			cc = cc.substring(name.length,cc.length);
			return getUParamGA(par, cc);
		}
	}
	return false;
};
function delCookie(n) {
	setCookie(name,"deleted",-1);
};
/*	PARAMETRY	*/
function getUParam(par, fromString) {
	par=par.toLowerCase();
	qstr=window.location.search;
	if ( typeof fromString != "undefined" && typeof fromString != "function" && fromString!= '' ) {
		qstr=fromString;
	}
	qstr=qstr.toLowerCase();
	if ( qstr.indexOf('=') >=0 && qstr.indexOf(par) >=0 ) {
		var tmp = new RegExp(".*[\\?\\&]+"+par+"=([\\w\\d]+).*").exec(qstr);
		if (tmp) {
			return tmp[1];
		}
	} else { 
		return false;
	}
};
function getUParamCase(par, fromString) {
	qstr=window.location.search;
	if ( typeof fromString != "undefined" && typeof fromString != "function" && fromString!= '' ) {
		qstr=fromString;
	}
	if ( qstr.indexOf('=') >=0 && qstr.indexOf(par) >=0 ) {
		var tmp = new RegExp(".*[\\?\\&]+"+par+"=([\\w\\d]+).*").exec(qstr);
		if (tmp) {
			return tmp[1];
		}
	} else { 
		return false;
	}
};
function _GET(par,fromString) {  return getUParam(par,fromString);  };
function getHashParam(par) { 
	//  parametry podane w formacie name|value|name|value...
	var hash=location.hash.slice(1);
	hash = hash.split('|');
	var w = new Array();
	for (var i=0, ile=hash.length; i<ile; i++) {
		if ( hash[i] && hash[i+1] ) {
			w[hash[i]] = hash[i+1];
		}
	}
	if ( w[par] ) 
		return w[par];
	return false;
};
function getUParamGA(par, fromString) {
	qstr=window.location.search;
	if ( typeof fromString != "undefined" && typeof fromString != "function" && fromString!= '' ) {
		qstr=fromString;
	}
	var tmp = new RegExp(".*[|\\?\\&\\.]"+par+"=([\\(\\w\\d\\)]+)[\\|\\&]*.*").exec(qstr);
	if (tmp) {
		return tmp[1];
	} else {
		return false;
	}
};

function _GEThash(par) { return getHashParam(par); };

function getPageSize() {
	/*
	var de = document.documentElement;
	return { 'width' : window.innerWidth || (de && de.clientWidth ) || document.body.clientWidth,
		'height' : window.innerHeight || (de && de.clientHeight ) || document.body.clientHeight };
	*/
	// rozmiary okna
	if( window.innerHeight  )  {
		pageWidth = window.innerWidth + window.scrollMaxX;
		pageHeight = window.innerHeight + window.scrollMaxY;
	}
	// all but Explorer Mac 
	else if( document.body.scrollHeight > document.body.offsetHeight ) {
		pageWidth = document.body.scrollWidth;
		pageHeight = document.body.scrollHeight;
	}
	// works in Explorer 6 Strict, Mozilla (not FF) and Safari
	else { 
		xScroll = document.getElementsByTagName("html").item(0).offsetWidth;
		yScroll = document.getElementsByTagName("html").item(0).offsetHeight;	
		pageWidth = (xScroll < document.body.offsetWidth) ? document.body.offsetWidth : xScroll; 
		pageHeight = (yScroll < document.body.offsetHeight) ? document.body.offsetHeight : yScroll; 
		//pageHeight = (document.getElementsByTagName("html").item(0).clientHeight == 0) ? document.body.clientHeight : document.getElementsByTagName("html").item(0).clientHeight;
	};
	return { 'width': pageWidth, 'height': pageHeight };
};

function setOpacity(obj, value) {
	obj.style.opacity = value/100;
	obj.style.filter = 'alpha(opacity=' + value + ')';
};

function hide_objects() {
	var objs=document.getElementsByTagName('object');
	for (var i=0; i<objs.length; i++) {
		objs[i].style.visibility='hidden';
		objs[i].fBox_show='1';
	}	
	var objs=document.getElementsByTagName('select');
	for (var i=0; i<objs.length; i++) {
		objs[i].style.visibility='hidden';
		objs[i].fBox_show='1';
	}
};
function show_objects() {
	var objs=document.getElementsByTagName('object');
	for (var i=0; i<objs.length; i++) {
		if ( objs[i].fBox_show=='1' ) {
			objs[i].style.visibility='';
		}
	}	
	var objs=document.getElementsByTagName('select');
	for (var i=0; i<objs.length; i++) {
		if ( objs[i].fBox_show=='1' ) {
			objs[i].style.visibility='';
		}
	}
};
function hideObjects() { hide_objects(); };
function showObjects() { show_objects(); };

function sh(obj) { 
	if ( !obj.style || obj.style.display=="block" ) 
		obj.style.display="none"; 
	else if ( obj.style.display=="none" ) 
		obj.style.display="block"; 
};
function toogle(obj) { sh(obj); };

var z = "";
z = z+" !\"#$%&'()*+,-./0123456789:;<=>?@";
z = z+"AaĄąBbCcĆćDdEeĘęFfGgHhIiJjKkLlŁłMmNnŃńOoÓó";
z = z+"PpQqRrSsŚśTtUuVvWwXxYyZzŹźŻż[\\]^_`{|}~";
z=z.split('');
z=array_switch(z);

function porownajPL(a,b) {
	a=new String(a);
	b=new String(b);
	var a_tab = a.split('');
	var b_tab = b.split('');
	for (var i=0, a_ile=a_tab.length; i<a_ile; i++) {
		if ( typeof z[b_tab[i]] == "undefined" ) 
			return -1;
		if (z[a_tab[i]] > z[b_tab[i]]) {
			return 1;
		} else if (z[a_tab[i]] < z[b_tab[i]]) {
			return -1;
		}
	}
	return 0;
};

function echo(s) { 
	if ( $('#echownik').length == 0 ) {
		$('body').append($('<div></div>').attr('id','echownik'));
	}
	$('#echownik').append(s);
};
function echoN(s) { echo(s +'<br />'); };
function echoA(tab) {
	echo ('<ul>');
	for (i in tab) {
		echo('<li>');
		if ( typeof tab[i] == "function" ) {
			echo ('function -> '+i+'<br />');
		} else if ( typeof tab[i] == 'object' ) {
			echo ('object -> '+i+'<br />');
			echoA( tab[i] );
		} else {
			echo (i+' -> '+tab[i]+'<br/>');
		}
		echo('</li>');
	}
	echo ('</ul>');
};

function dataFromPesel(pesel) {
// TODO: inne daty ( + 30 itd )
	r = pesel.substr(0,2);
	m = pesel.substr(2,2);
	d = pesel.substr(4,2);
	if ( m > 20 && m < 80 ) {
		r = '20' + r;
	} else if ( m > 80 ) {
		r = '18' + r;
	} else {
		r = '19' + r;
	}
	return r+'-'+m+'-'+d;
};

//	losowanie liczby z podanego zakresu
function losowa(a,b) {
 return Math.floor((b-(a-1))*Math.random()) + a;
};

//	INSERT INTO HEAD  CSS, JS files etc
//	nie działa przy jQuery w ciele funkcji $(function() {} );
function insertCSS(href) {
	var cssNode = document.createElement('link');
	cssNode.type = 'text/css';
	cssNode.href = href;
	cssNode.rel = 'stylesheet';
	cssNode.media = 'screen';
	cssNode.title = 'dynamicStyleSheet';
	document.getElementsByTagName("head")[0].appendChild(cssNode);
};
function insertJS(href) {
	var newScript = document.createElement('script');
	newScript.type = 'text/javascript';
	newScript.src = href;
	document.getElementsByTagName("head")[0].appendChild(newScript);
};
function insert(href) {
	if ( href.slice(-3) == '.js' ) {
		//alert('inserJS for '+href);
		insertJS(href);
	} else if ( href.slice(-4) == '.css' ) {
		//alert('insertCSS for '+href);
		insertCSS(href);
	}
};
function include(href) { insert(href); }

//	okienka
function wups(wloc,wdth,hght) {
	if(wdth==0)wdth=620;
	if(hght==0)hght=630;
	var paramki='menubar=no, toolbar=no, location=yes, width='+wdth+', height='+hght+', left=30, top=30, scrollbars=yes, status=yes, resizable=yes';
	var namik=wloc.substring(wloc.lastIndexOf('=')+1);
	if(namik.length>10)namik='openedW';
	nwin=window.open(wloc,namik,paramki);
	nwin.focus();
}
function wop(wloc) {
	window.opener.location.href=wloc;
	window.close();
}
function wopHTML(html) {
//TODO - window open + tresc html
}


/* ---------------------- stałe, zmienne ---------------------------*/
var months=['Styczeń','Luty','Marzec','Kwiecień','Maj','Czerwiec','Lipiec','Sierpień','Wrzesień','Październik','Listopad','Grudzień'];
var months_dop=['stycznia','lutego','marca','kwietnia','maja','czerwca','lipca','sierpnia','września','października','listopada','grudnia'];

