function confirmdel(komunikat,cousunac,po) {
	var agree = window.confirm('Czy na pewno usunąć ' + komunikat + ' ' + unescape(cousunac) + po);
	if (agree)
		return true;
	else
		return false;
}

function confirmadd(komunikat,cododac,po) {
	var agree = window.confirm('Czy na pewno dodać ' + komunikat + ' ' + unescape(cododac) + po);
	if (agree)
		return true;
	else
		return false;
}


function potwierdz(komunikat) {
	var agree = window.confirm(komunikat);
	if (agree)
		return true;

	return false;
}



function powieksz(dzial,plik,szer,wys) {
var wysokosc = parseInt(wys);
var szerokosc = parseInt(szer);
if (szerokosc<100)
	szerokosc = 115;

if (wysokosc<100)
	wysokosc = 115;
else
	wysokosc +=20;

	window.open('show.php?d='+dzial+'&f='+plik+'&szer='+szer+'&wys='+wys+'', 'okienko', 'menubar=no, toolbar=no, location=no, scrollbars=0, resizable=no, status=no, top=0, left=0, width='+szerokosc+', height='+wysokosc+'');
}


//fukncja zlicza ile jeszcze znakow mozna wpisac do pola
function textCounter(field, countfield, maxlimit)
{
if (field.value.length > maxlimit) // if too long...trim it!
	field.value = field.value.substring(0, maxlimit);
else  // otherwise, update 'characters left' counter
	countfield.value = maxlimit - field.value.length;
}


//fukncja zlicza ile jeszcze znakow mozna wpisac do pola SPAN
function ileZnakowZostalo(field, countfield, maxlimit)
{
if (field.value.length > maxlimit) // if too long...trim it!
	field.value = field.value.substring(0, maxlimit);
else  // otherwise, update 'characters left' counter
	countfield.nodeValue = field.value.length + '/' + (maxlimit - field.value.length);
}


//fukncja zmienia dowolny ciag na przyjazny url
function przyjaznyurl(field) {
	wzor = "[^A-Za-z0-9ĄĆĘŁŃÓŚŻ\\\\Źąćęłńóśżź\\-\/ ]";

	var re = new RegExp(wzor, "g");

	var fred = field;
//alert(fred);
	fred = fred.replace(re,""); //wyciecie wszystkich znakow innych niz wzorzec
//alert(fred);
	fred = fred.replace(/^\s+|\s+$/g,""); //trim

	zle_znaki = new Array("Ą","Ć","Ę","Ł","Ń","Ó","Ś","Ż","Ź","ą","ć","ę","ł","ń","ó","ś","ż","ź");
	dobre_znaki = new Array("A","C","E","L","N","O","S","Z","Z","a","c","e","l","n","o","s","z","z");
	
	dl_zle = zle_znaki.length;

	// zamiana polskich znakow na ich proste odpowiedniki
	for(var i=0;i<dl_zle;i++) {
		var foo = eval("/"+zle_znaki[i]+"/g");
		fred = fred.replace(foo,dobre_znaki[i]);
	}

	fred=fred.replace(/( - )|( 8211 )|(8211)|(nbsp)|(ndash)|(mdash)|( 8212 )|(8212)|(\/)|(\\)/g," "); // zamiana " - " na "-"
	fred=fred.replace(/ {1,}/g,"-"); // zamiana grup spacji na myslniki
	fred = fred.toLowerCase(); //zamiana ciagu na male litery

	//nice_field.value = fred;
	return fred;
}

function wstawPrzyjaznyUrl(nice_field, przyjaznyUrl) {
	for(var i=0; i < nice_field.attributes.length; i++) {
		if (nice_field.attributes[i].name=='maxlength') {
			var max = nice_field.attributes[i].value;
		}
	}
	
	var wartosc = przyjaznyUrl.substring(0, max);
	
	nice_field.value = wartosc;
}

function wstawPrzyjaznyUrlDwaPola(nice_field, przyjaznyUrl1, przyjaznyUrl2) {
	nice_field.value = przyjaznyUrl1 + '-' + przyjaznyUrl2;
}


function poleWidok (postid) {
	if(document.getElementById(postid).className=="schowaj")
		document.getElementById(postid).className="pokaz";
	else
		document.getElementById(postid).className="schowaj";
}


//funkcja do pokazywania i chowania tekstu
function pokazPole (postid)
{ 
	if(postid==2) {
		document.getElementById(1).className="schowaj";
	} else if(postid==1) {
		document.getElementById(2).className="schowaj";
	}

	document.getElementById(postid).className="pokaz";
}


var marked_row = new Array;

/**
 * uaktywnia podswietlanie i zaznaczanie wierszy w tabeli
 *
 */
function PMA_markRowsInit() {
    // for every table row ...
if(document.getElementById('dane')) {
	var rows = document.getElementById('dane').getElementsByTagName('tr');
    for ( var i = 0; i < rows.length; i++ ) {
        // ... with the class 'odd' or 'even' ...
        if ( 'w1' != rows[i].className.substr(0,2) && 'w2' != rows[i].className.substr(0,2) ) {
            continue;
        }
        // ... add event listeners ...
        // ... to highlight the row on mouseover ...
        if ( navigator.appName == 'Microsoft Internet Explorer' ) {
        //alert('IE');
            // but only for IE, other browsers are handled by :hover in css
            rows[i].onmouseover = function() {
                this.className += '_hover';
            }
            rows[i].onmouseout = function() {
                this.className = this.className.replace( '_hover', '' );
            }
        }

		// ... and to mark the row on click ...
        rows[i].onmousedown = function() {
            var unique_id;
            var checkbox;

            div = this.getElementsByTagName( 'div' )[0];
            if(div) {
	            if ( div.id.length > 0 ) {
    	            unique_id = div.id;
        	    } else {
            	    return;
	            }
	        }
	        else {
	        	return
	        }

            if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {
                marked_row[unique_id] = true;
            } else {
                marked_row[unique_id] = false;
            }

            if ( marked_row[unique_id] ) {
                this.className += '_zaznaczony';
            } else {
                this.className = this.className.replace('_zaznaczony', '');
            }
        }
    }
}
}
//window.onload=PMA_markRowsInit;


function swap(objID,kolor)
{
//alert(img);
	document.getElementById(objID).style.backgroundColor='#'+kolor;
}

/*
var xmlHttp = createXmlHttpRequestObject(); 

// zwraca obiekt XMLHttpRequest
function createXmlHttpRequestObject() {
	var xmlHttp = false;
	try {
		xmlHttp = new XMLHttpRequest();
	}
	catch (trymicrosoft) {
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (othermicrosoft) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (failed) {
				xmlHttp = false;
			}  
		}
	}
	// zwraca utworzony obiekt lub wyswietla komunikat o błędzie
	if (!xmlHttp)
		alert("Błąd inicjalizacji obiektu XMLHttpRequest!");
	else
		return xmlHttp;
}


function przeniesPlik(plik,skad,dokad) {
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0) {
		if(plik=='' || skad=='' || dokad=='')
			return false;
//	alert(plik + ' = ' + document.getElementById(plik).value+' = '+skad+' = '+dokad);
		xmlHttp.open("GET", "./funkcje/przenies_plik.php?plik="+document.getElementById(plik).value+"&skad="+skad+"&dokad="+dokad, true);  
		xmlHttp.onreadystatechange = przeniesPlikKomunikat;
		xmlHttp.send(null);
	} else {
		setTimeout('przeniesPlik()', 1000);
	}
}


function przeniesPlikKomunikat() 
{
	if (xmlHttp.readyState == 4) {
	//alert(xmlHttp.status);
		if (xmlHttp.status == 200) {
			xmlResponse = xmlHttp.responseXML;
			xmlDocumentElement = xmlResponse.documentElement;
//			alert('plik: '+xmlDocumentElement.childNodes[0].firstChild.nodeValue+' | skad: '+xmlDocumentElement.childNodes[1].firstChild.nodeValue+' | dokad: '+xmlDocumentElement.childNodes[2].firstChild.nodeValue);
			if(xmlDocumentElement.childNodes[0].firstChild.nodeValue==1) {
				alert('dokonano przeniesienia');
				window.location.reload();
			}
			

//			n_f.firstChild.nodeValue = xmlDocumentElement.childNodes[1].firstChild.nodeValue;
			//document.post.numer_faktury.value = xmlDocumentElement.childNodes[1].firstChild.nodeValue;
			//if(xmlDocumentElement.childNodes[0].firstChild.nodeValue) {
	//			typ_faktury.firstChild.nodeValue = xmlDocumentElement.childNodes[0].firstChild.nodeValue;
//			}
		}
		else {
			alert("Wystąpił błąd podczas uzyskiwania dostępu do serwera: " + xmlHttp.statusText);
		}
	}
}
*/


function capitalRewrite(source,target) {
	//alert(source + ' | '+ target);
	val = source.value;
	newVal = '';
	//val = val.replace(/^\s+|\s+$/g,""); //trim
	val = val.replace(/ {1,}/g," "); // zamiana grup spacji na myslniki

	val = val.split(' ');
	for(var c=0; c < val.length; c++) {
		newVal += val[c].substring(0,1).toUpperCase() + val[c].substring(1,val[c].length).toLowerCase() + ' ';
		//alert(newVal);
	}

	document.getElementById(target).value = newVal.replace(/^\s+|\s+$/g,"");
}

function capitalAll(source) {
	val = source.value;
	val = val.replace(/ {1,}/g," "); // wyciecie grup spacji
	val = val.replace(/^\s+|\s+$/g,"")

	source.value = val.toUpperCase();
}

/*
//czas do wylogowania
var i_pasek, j_pasek, d1_pasek, czas_id_pasek;
function ustawPasek() {
	d1_pasek = document.getElementById("d1");//wewnetrzny
	d1_pasek.innerHTML="";
	j_pasek = parseInt(document.getElementById("d2").style.width);
	i_pasek = 0;
	pix = j_pasek/time;
	czas_id_pasek = document.getElementById("czas");
	wpisz('czas',time);
	progBar(); 
}


function progBar() {
	min = Math.floor(time/60); //pozostalo minut
	sek = time%60;             //pozostalo sekund

	if(min<10)                 //formatowanie
		min = "0"+min;
	if(sek<10)
		sek = "0"+sek;

	//wypelnienie pola z czasem
	czas_id_pasek.innerHTML = min+":"+sek;

	if(time>0)
		setTimeout("progBar();", 1000);
		
	time--;
	//i = Math.round(i+pix);
	i_pasek += pix;

	if (i_pasek>30 && i_pasek<=j_pasek) //pokaz procenty dopiero jak sie zmieszcza
		d1_pasek.innerHTML=100-parseInt(i_pasek/j_pasek*100)+"%";
			
	d1_pasek.style.width=Math.floor(i_pasek)+"px";
			
	if(time<0)
		document.location = 'index.php?akcja=logout';

	//wpisz('d3','sz:'+ i_pasek+ '| t: '+ time + ' | obs: '+ parseInt(d1_pasek.style.width));
}

function wpisz(diw,komunikat) {
	document.getElementById(diw).innerHTML = komunikat;
}
*/

//ustawienie kusora na pierwszym polu tekstowym, zaraz po zaladowaniu strony
function firstTxtAreaOnload() {
	if(document.forms[0]){
		for (i = 0; i < document.forms[0].elements.length; i++) {
			if (document.forms[0].elements[i].type == "text" || document.forms[0].elements[i].type == "password") {
				document.forms[0].elements[i].focus();
				break;
			}
		}
	}
}

/**
* New function for handling multiple calls to window.onload and window.unload by pentapenguin
*/
window.onload = function() {
	for (var i = 0; i < funkcjeStartowe.length; i++) {
		eval(funkcjeStartowe[i]);
	}
}
//funkcjeStartowe.push('ustawPasek()');
//funkcjeStartowe.push('firstTxtAreaOnload()');
funkcjeStartowe.push('PMA_markRowsInit()');

/*function functionsOnload() {
	ustawPasek();
	firstTxtAreaOnload();
	PMA_markRowsInit();
//	if(tabs == true)
	//	startList();
}

window.onload = functionsOnload;
*/
//wersja str_pad
String.prototype.pad = function(l, s, t) {//t=0 -> z lewej, t=1 -> z prawej, t=2 -> z prawej i lewej
	return s || (s = " "), (l -= this.length) > 0 ? (s = new Array(Math.ceil(l / s.length)
	+ 1).join(s)).substr(0, t = !t ? l : t == 1 ? 0 : Math.ceil(l / 2))
	+ this + s.substr(0, l - t) : this;
};
