//funkcje do podmiany zdjec
function fon(n){document.images[n].src='grafika/'+n+'1.gif';}
function foff(n){document.images[n].src='grafika/'+n+'.gif';}

//funkcja do wyswietlania popupu
var okno_pop='';
function popup(wi,he,uerel,alignx,aligny,scrol)
{
	// Bartosz Szczecinski
	// 20.04.2006
	// Opera 8.x nie obsluguje !okno_pop.closed
	if(okno_pop && okno_pop.closed==false) {
		okno_pop.close()
	}
	if(wi=='100%'){wi=screen.availWidth-30}
	if(he=='100%'){he=screen.availHeight-0}
	if(alignx=='left'){xx=0}
	else if(alignx=='right'){xx=(screen.availWidth-wi)-10}
	else{xx=(screen.availWidth-wi)/2}
	if(aligny=='top'){yy=0}
	else if(aligny=='bottom'){yy=(screen.availHeight-he)}
	else{yy=(screen.availHeight-he)/2}
	okno_pop=window.open(uerel, '_blank', 'scrollbars='+scrol+',height='+he+',width='+wi+',top='+yy+',left='+xx);
}

function popupFrame(wi, he, url, alignX, alignY, scroll) {
	popup(wi, he, 'popup.php?popupFile='+url.replace(/\?/, '&'), alignX, alignY, scroll);
}

function blurall() {
	var links = document.getElementsByTagName('a');
	for (var i=0;i<links.length;i++){
		links[i].onfocus = blurme;
	}
}

function blurme()
{
	this.blur();
}


function printversion(id,path)
{
	var okno='';
	(okno && !okno.closed)?okno.close():'';
	he=400;
	wi=730;
	xx=(screen.availHeight-he)/2-10;
	yy=(screen.availWidth-wi)/2;
	okno=window.open('print_version.php?id='+id, '_blank', 'menubar=yes,scrollbars=yes,height='+he+',width='+wi+',top='+xx+',left='+yy);
}


function tabHandle(obj) {
	var li = obj.parentNode.parentNode.getElementsByTagName('LI');
	for(var i = 0 , j = li.length ; i < j ; i++) {
		li[i].className = '';
	}
	obj.parentNode.className = 'active';
	obj.blur();
	
	var div = obj.parentNode.parentNode.parentNode.getElementsByTagName('DIV');	
	for(var i = 0, j = div.length ; i < j ; i++) {
		
		if(div[i].className.indexOf('isTab') > -1) {
			div[i].style.display = 'none';			
		}
	}
	try {
		document.getElementById(obj.className).style.display = 'block';
	}
	catch(ex) {};
}

var fontSize = 12;  
var fontSizeMin = 10; 
var fontSizeMax = 18;

function changeFont(mod) {
	fontSize += mod;	
	if(fontSize < fontSizeMin) fontSize = fontSizeMin;
	if(fontSize > fontSizeMax) fontSize = fontSizeMax;
	
	document.getElementById('page').style.fontSize = fontSize + 'px';
	
	var ao = new AjaxObject101();
	ao.funcDone = ajaxDataLoaded;
	ao.sndReq('get', 'php_inc/font_size_save.php','size=' + fontSize);
		
	return false;
}

function faqShow(id) {	
	var div = document.getElementById('faq').getElementsByTagName('DIV');
	for(var i = 0 , j = div.length ; i < j ; i++) {
		/*if(div[i].className.indexOf('bipInfo') > -1) continue; ttest */
		div[i].style.display = 'none';
		div[i].parentNode.getElementsByTagName('IMG')[0].style.display = 'inline';
		div[i].parentNode.getElementsByTagName('h3')[0].className = 'noactivef';
	}
	
	if(id != 0) {     
        document.getElementById('faq'+id).className = 'activef';
        
		document.getElementById('f'+id).style.display = 'block';
		document.getElementById('f'+id).parentNode.getElementsByTagName('IMG')[0].style.display = 'none';
		
		var dl = document.location.toString();
		if(dl.indexOf('#') > -1) {
			dl = dl.split('#');
			dl = dl[0];
		}		
		document.location = dl + '#faq' + id;

	}
	else {
		var h3 = document.getElementById('faq').getElementsByTagName('h3');
		for(var i = 0 , j = h3.length ; i < j ; i++) {
			h3[i].getElementsByTagName('IMG')[0].style.display = 'inline';
		}		
	}
}

function faqToggle(id) {
	if(document.getElementById('f'+id).style.display == 'block') faqShow(0);
	else faqShow(id);
}

function elToggle(el, cal) {	
	if(cal.src.indexOf('rozwin') > -1) {
		cal.src = cal.src.toString().replace(/rozwin/, 'zwin');
		el.style.display = 'block';
	}
	else {
		cal.src = cal.src.toString().replace(/zwin/, 'rozwin');
		el.style.display = 'none';
	}
}

function jsOn() {
	var s = document.getElementsByTagName('SPAN');
	for(var i = 0 , j = s.length ; i < j; i++) {
		if(s[i].className.indexOf('jsRequired') > -1) s[i].style.display = 'inline';	
	}
}


var ajaxLoadTarget;
function ajaxLoad(root, param, target, clearTarget) {
	ajaxLoadTarget = target;
	if(clearTarget) {
		clearTarget.options.length = 1;
		clearTarget.selectedIndex = 0;
	}
	
	var ao = new AjaxObject101();
	ao.funcDone = ajaxDataLoaded;
	
	ao.sndReq('get', 'php_inc/select.php',param + '=' + root);
	
}

function ajaxDataLoaded(data) {	
	var ret = data;
	      
	ret = ret.split('^');	
	var o;
	
	ajaxLoadTarget.options.length = 1;		
	
	if(!ret[0]) return;
	for(var i = 0 ; i < ret.length ; i++) {
		ret[i] = ret[i].split(':');
		//o = document.createElement('OPTION');
		//o.value = ret[i][0];
		//o.text = ret[i][1];
		//ajaxLoadTarget.appendChild(o);	
		try {
			ajaxLoadTarget.add(new Option(ret[i][1], ret[i][0]), null);
		}
		catch(e) {
			ajaxLoadTarget.add(new Option(ret[i][1], ret[i][0]));
		}
	}
}


//Created by Sean Kane (http://celtickane.com/labs/feather-ajax/)
//Feather Ajax v1.0.2

function AjaxObject101() {
	this.createRequestObject = function() {
		try {
			var ro = new XMLHttpRequest();
		}
		catch (e) {
			var ro = new ActiveXObject("Microsoft.XMLHTTP");
		}
		return ro;
	}
	this.sndReq = function(action, url, data) {
		if (action.toUpperCase() == "POST") {
			this.http.open(action,url,true);
			this.http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			try {this.http.onreadystatechange = this.handleResponse;}
			catch(ex) {
				this.http.onload = this.handleResponse;
			}
			this.http.send(data);
		}
		else {
			this.http.open(action,url + '?' + data,true);
			try {this.http.onreadystatechange = this.handleResponse;}
			catch(ex) {
				this.http.onload = this.handleResponse;
			}
			this.http.send(null);
		}
	}
	this.handleResponse = function() {
		if ( me.http.readyState == 4) {
			if (typeof me.funcDone == 'function') { me.funcDone(me.http.responseText); return;}
			var rawdata = me.http.responseText.split("|");
			for ( var i = 0; i < rawdata.length; i++ ) {
				var item = (rawdata[i]).split("=>");
				if (item[0] != "") {
					if (item[1].substr(0,3) == "%V%" ) {
						document.getElementById(item[0]).value = item[1].substring(3);
					}
					else {
						document.getElementById(item[0]).innerHTML = item[1];
					}
				}
			}
		}
		if ((me.http.readyState == 1) && (typeof me.funcWait == 'function')) { me.funcWait(); }
	}
	var me = this;
	this.http = this.createRequestObject();
	
	var funcWait = null;
	var funcDone = null;
}

function setTyp(el, isInput) {
	if(!isInput) isInput = 0;
	if(el.selectedIndex == 0) return;
	var key;
	if(!isInput) key = el.options[el.selectedIndex].text.substr(0, 2)
	else key = el.value.substr(0, 2);
	
	var dt = el.parentNode.parentNode.getElementsByTagName('DT');
	var dd = el.parentNode.parentNode.getElementsByTagName('DD');
	
	for(var i = 0 ; i < dd.length ; i++) {		
		if(dd[i].className != '') {
			if(dd[i].className == 'type_' + key) {
				dd[i].style.display = 'block';		
				enableAllIn(dd[i]);
			}
			else if(dd[i].className.indexOf('type_') > -1){
				dd[i].style.display = 'none';
				
			}
		}
	}
	for(var i = 0 ; i < dt.length ; i++) {
		if(dt[i].className == 'head') continue;		
		if(dt[i].className != '') {
			if(dt[i].className == 'type_' + key) {
				dt[i].style.display = 'block';				
			}
			else if(dt[i].className.indexOf('type_') > -1){
				dt[i].style.display = 'none';
				
			}
		}
	}	
}

function enableAllIn(obj) {
	var inp = obj.getElementsByTagName('INPUT');
	for(var i = 0; i < inp.length ; i++) {
		inp[i].disabled = false;		
	}
	
	inp = obj.getElementsByTagName('SELECT');
	for(var i = 0; i < inp.length ; i++) {
		inp[i].disabled = false;		
	}
}

function expandResult(id) {
	document.getElementById('result' + id).style.display = 'block';
	document.getElementById('result' + id).parentNode.getElementsByTagName('IMG')[0].style.visibility = 'hidden';
}

function expandResultToggle(id) {
	if(document.getElementById('result' + id).style.display == 'block') colapseResult(id);
	else expandResult(id);
}

function colapseResult(id) {
	document.getElementById('result' + id).style.display = 'none';
	document.getElementById('result' + id).parentNode.getElementsByTagName('IMG')[0].style.visibility = 'visible';
}

function hoverize(el) { el.onmouseover = supermenuOn; }

var currentSupermenuElement;
function supermenuOn(e) {
	if(currentSupermenuElement != null && currentSupermenuElement != event.srcElement.parentNode) supermenuOff();		
	currentSupermenuElement = event.srcElement.parentNode;	        
	currentSupermenuElement.className = currentSupermenuElement.className + ' level1shown';
}
function supermenuOff() {
	var li = document.getElementById('supermenu').getElementsByTagName('LI');				
	for(var i = 0 ; i < li.length ; i++) {
		if(li[i].className.indexOf('level1') != -1) {				
			li[i].className = li[i].className.replace(/level1shown/, '');
		}
	}	
}

function checkLoggout(e) {
	
	var pos;	
	try {
		pos = getCumulativeOffset(e.currentTarget);
	}
	catch (ex) {
		pos = getCumulativeOffset(e.srcElement);
	}
	var posDelta = e.clientX - pos.x;	
	if(posDelta > 35) return false;
	return true;
}

var getCumulativeOffset = function (obj) {
    var left, top;
    left = top = 0;
    if (obj.offsetParent) {
        do {
            left += obj.offsetLeft;
            top  += obj.offsetTop;
        } while (obj = obj.offsetParent);
    }
    return {
        x : left,
        y : top
    };
};

