var Open = "";
var Closed = "";

var isDOM  = (typeof(document.getElementsByTagName) != 'undefined') ? 1 : 0;
var isIE4  = ((typeof(document.all) != 'undefined') && (parseInt(navigator.appVersion) >= 4)) ? 1 : 0;
var isNS4 = (typeof(document.layers) != 'undefined') ? 1 : 0;
var capable = (isDOM || isIE4 || isNS4) ? 1 : 0;
// Uggly fix for Konqueror and Opera that are not fully DOM compliant
 if (capable && typeof(navigator.userAgent) != 'undefined') {
  var browserName = ' ' + navigator.userAgent.toLowerCase();
   if (browserName.indexOf('opera') > 0) {
     capable = 0;
   }
}

var pressed_key = '';

if (document.images) {
	Open = new Image(16,13); Closed = new Image(16,13);
	Open.src = "/files/gfx/open.gif"; Closed.src = "/files/gfx/closed.gif";
}

function getKeyCode(e) {

	if (window.event)
		return window.event.keyCode;
	else if (e)
		return e.which;
	else
		return null;
}

function keyRestrict(e, validchars) {

	var key = '';
	var keychar = '';
	key = getKeyCode(e);

	if (key == null) return true;

	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	validchars = validchars.toLowerCase();

//	if (e.ctrlKey == true && (keychar == "c" || keychar == "v"))
//		return false;

	if (validchars.indexOf(keychar) != -1)
		return true;

	if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
		return true;

	return false;
}

function shdiv(what,ilosc) {
for (i=0; i<ilosc; i++) {
//  eval('span' + i + '.style.display="none"')

  if (isDOM) { var whichEl = document.getElementById('span' + i); whichEl.style.display  = 'none'; }
  else if (isIE4) { var whichEl = document.all('span' + i); whichEl.style.display  = 'none'; }
  else if (isNS4) { var whichEl = document.layers['span' + i]; whichEl.visibility  = 'hide'; }
}

  if (isDOM) { var whichEl = document.getElementById(what); whichEl.style.display  = 'block'; }
  else if (isIE4) { var whichEl = document.all(what); whichEl.style.display  = 'block'; }
  else if (isNS4) { var whichEl = document.layers[what]; whichEl.visibility  = 'show'; }
}

function showhide(what, what2){
  what2 = document.images[what2];
  if (isDOM) {
    var whichEl = document.getElementById(what);
    if ( whichEl.style.display == 'none' ) { whichEl.style.display  = 'block'; what2.src = '/files/gfx/open.gif'; }
    else { whichEl.style.display  = 'none'; what2.src = '/files/gfx/closed.gif'; }
  }
  else if (isIE4) {
    var whichEl = document.all(what);
    if (whichEl.style.display == 'none') { whichEl.style.display  = 'block'; what2.src = '/files/gfx/open.gif';}
    else { whichEl.style.display  = 'none'; what2.src = '/files/gfx/closed.gif'; }
  }
  else if (isNS4) {
    var whichEl = document.layers[what];
    if (whichEl.visibility == 'hide') { whichEl.visibility  = 'show'; what2.src = '/files/gfx/open.gif';}
    else { whichEl.visibility  = 'hide'; what2.src = '/files/gfx/closed.gif'; }
  }
}

function show5() {
if (!document.layers&&!document.all) return
 var Digital = new Date()
 var     all = Digital

if (document.layers){
 document.layers.liveclock.document.write(all)
 document.layers.liveclock.document.close()
} else if (document.all) liveclock.innerHTML=all

setTimeout("show5()",1000)
}

function divShowHide(what, act){
  if (isDOM) {
    var whichEl = document.getElementById(what);
    if (act == 's') whichEl.style.display  = 'block'
    else if (act == 'h') whichEl.style.display = 'none'
    else if (act == 'a')
        if (whichEl.style.display == 'none') whichEl.style.display  = 'block'
        else whichEl.style.display  = 'none'
  }
  else if (isIE4) {
    var whichEl = document.all(what);
    if (act == 's') whichEl.style.display  = 'block'
    else if (act == 'h') whichEl.style.display = 'none'
    else if (act == 'a')
        if ( whichEl.style.display == 'none' ) { whichEl.style.display  = 'block'; }
        else { whichEl.style.display  = 'none'; }
  }
  else if (isNS4) {
    var whichEl = document.layers[what];
    if (act == 's') whichEl.visibility  = 'block'
    else if (act == 'h') whichEl.visibility = 'none'
    else if (act == 'a')
        if ( whichEl.visibility == 'none' ) { whichEl.visibility  = 'block'; }
        else { whichEl.visibility  = 'none'; }
  }
}


function tabs(x) {
  for (a in Z) {
    divShowHide(Z[a], 'h');
    document.getElementById(Z[a]+'t').className='tabOff'
  }

  divShowHide(x, 's');
  if (x!=Z[0]) document.getElementById(x).style.top = document.getElementById(Z[0]).offsetTop;
  document.getElementById(x+'t').className='tabOn'
}

function tabs2(x, Z) {
  for (a in Z) {
    divShowHide(Z[a], 'h');
    document.getElementById(Z[a]+'t').className='tabOff'
  }

  divShowHide(x, 's');
  if (x!=Z[0]) document.getElementById(x).style.top = document.getElementById(Z[0]).offsetTop;
  document.getElementById(x+'t').className='tabOn'
}

function confirmAction(x) {return confirm(x);}

//////// KAMIL
function sel_input(url){		//	Laduje strone do okreslonej ramki. Adres jest wartoscia pola select.
	url?url:unescape(document.location.pathname);
	document.location = url;
}
function sel_button(name){	//	Laduje strone do okreslonej ramki. Adres jest wartoscia pola select.
	v=document.forms[name][name].value;
	v?sel_input(v):0;
}

var FM=0;
var FI='';

function popupFM(i,u){
	if(FM){FM.close();}
	FM=window.open('','','width=400;height=500;'); FM.location=u;
	FI=i;
}

function setFormValue(i){
// alert('Ustawiles pole '+FI+' na wartosc '+i);
	if (document.forms[0][FI]){document.forms[0][FI].value=i;}
	else {document.forms[1][FI].value=i}
}

function ClearAndSubmit(f,v){for(a=0;a<v.length;a++){if(document.forms[f][v[a]]){document.forms[f][v[a]].selectedIndex = 0;}}document.forms[f].submit()}
function shb(i){	X=document.getElementById(i).style;X.display=X.display=="none"?"block":"none";}
function akcja_select(w){parent.document.frames.main.location="/index.php?mode=t&t="+w;}
function akcja_submit(w){akcja_select(document.forms[w][w].value)}
function pokaz_widok(w){parent.document.frames.main.location="/index.php?mode=t&t=T,dane,"+w;}
function pokaz_widok_button(w){	pokaz_widok(document.forms[w][w].value);}
function locFrame(f,u){parent.document.frames[f].location=u;}
function locDoc(u){	document.location=u;}
function select_submit(t,n){select_change(t,document.forms[n][n].value)}
function refresh(t){u=t?unescape(parent.document.frames[t].location.pathname):unescape(window.location.pathname);
	t?document.frames[t].location=u:window.location=u;
}
function load(t,u){	if(t){parent.document.frames[t].location=u;}
	else{window.location=u}}
function trLight(t,c){	document.getElementById(t.id).className=c;}
function alertYN(t,u){if(confirm(t)){location=u;}}

function g_print_page(browserCanntPrintingPageMessage) {
  if (((navigator.appName.indexOf("Microsoft Internet Explorer")>=0) &&
       (parseFloat(navigator.appVersion.substring(navigator.appVersion.indexOf("MSIE")+5,
        navigator.appVersion.indexOf("MSIE")+8))>4.0)) || (navigator.appName.indexOf("Netscape")>=0))
    this.window.print();
  else
    alert(browserCanntPrintingPageMessage);
}

function getRefToDivMod( divID, oDoc ) {
	if( !oDoc ) { oDoc = document; }
	if( document.getElementById ) { return oDoc.getElementById(divID); }
	if( document.all ) { return oDoc.all[divID]; }
	return document[divID];
}

function resizeWinTo( idOfDiv ) {
	var oH = getRefToDivMod( idOfDiv ); if( !oH ) { return false; }
	var oW = oH.clip ? oH.clip.width : oH.offsetWidth;
	var oH = oH.clip ? oH.clip.height : oH.offsetHeight; if( !oH ) { return false; }
	var x = window; x.resizeTo( oW + 200, oH + 200 );
	var myW = 0, myH = 0, d = x.document.documentElement, b = x.document.body;
	if( x.innerWidth ) { myW = x.innerWidth; myH = x.innerHeight; }
	else if( d && d.clientWidth ) { myW = d.clientWidth; myH = d.clientHeight; }
	else if( b && b.clientWidth ) { myW = b.clientWidth; myH = b.clientHeight; }
	if( window.opera && !document.childNodes ) { myW += 16; }
	x.resizeTo( oW + ( ( oW + 200 ) - myW ), oH + ( (oH + 200 ) - myH ) );
	var scW = screen.availWidth ? screen.availWidth : screen.width;
	var scH = screen.availHeight ? screen.availHeight : screen.height;
	x.moveTo(Math.round((scW-oW)/2),Math.round((scH-oH)/2));
}

function showTableWidth() {
	if (document.body && document.body.scrollHeight && document.body.clientHeight && document.body.clientHeight != document.body.scrollHeight)
		window.resizeBy(0,(document.body.scrollHeight - document.body.clientHeight));
	else
		resizeWinTo( "body" );
}
