function PokazUkryj(id) {
	if($(id).style.display == 'block')
		$(id).style.display = 'none';
	else
		$(id).style.display = 'block';
}

function Pokaz(id) {
	var element = $(id);
	if (element)
		element.style.display = 'block';
	
}

function Ukryj(id) {
	var element = $(id);
	if (element)
		element.style.display = 'none';
}

function PokazF(id) {
	var element = $(id);
	if (element) {
		var tablica = element.getElementsByTagName("input");
		for (var i = 0; i < tablica.length; i++)
			tablica[i].disabled = false;
	}
	
}

function UkryjF(id) {
	var element = $(id);
	if (element) {
		var tablica = element.getElementsByTagName("input");
		for (var i = 0; i < tablica.length; i++)
			tablica[i].disabled = true;
	}
	
}

function FUkryj(id) {
	Ukryj(id);
	UkryjF(id);
}

function FPokaz(id) {
	Pokaz(id);
	PokazF(id);
}

function FSubmit(FormName) {
	return document.forms[FormName].submit();
}

function FSubmitSL(FormName) {
	if(m1.length>0) {
		for (i=0; i<m1.length; i++) {
			m1.options[i].selected = true;
		} 
	}
	if(m2.length>0) {
		for (i=0; i<m2.length; i++) {
			m2.options[i].selected = true;
		} 
	}
	return document.forms[FormName].submit();
}

function WyslijAction(FormName,Action) {
	$(FormName).action = Action;
	document.forms[FormName].submit();
}
function WyslijAction2(FormName,Action) {
	$('#' + FormName).attr('action',Action);
	$('#' + FormName).attr('target','_self');
}
function WyslijActionB(FormName,Action) {
	$('#' + FormName).attr('action',Action);
	$('#' + FormName).attr('target','_blank');
	document.forms[FormName].submit();
}

function Potwierdzenie(tekst, url) {
	if (confirm(tekst))
		document.location=url;
}

function PotwierdzenieAction(tekst, FormName, Action) {
	if (confirm(tekst)) {
		$(FormName).action = Action;
		document.forms[FormName].submit();
	}
}

function PotwierdzenieWyslij(tekst, FormName) {
	if (confirm(tekst))
		document.forms[FormName].submit();
}

function popokno(adres, nazwa, szerokosc, wysokosc) {
	if (szerokosc=="")
		szerokosc="550";
	if (wysokosc=="")
		wysokosc="400";
	if (nazwa=="")
		nazwa="popwindow";
	w=window.open(adres, nazwa, 'toolbar=no,menubar=no,location=no,personalbar=no,scrollbars=yes,directories=no,status=no,resizable=yes,copyhistory=no,width='+szerokosc+',height='+wysokosc+',top=50,left=50');
}

function SelectWybor(from,to,update){
	var x=document.getElementById(from);
	var y=document.getElementById(to);
	var z=document.getElementById(update);
	y.options[y.length] = new Option(x.options[x.selectedIndex].text,x.options[x.selectedIndex].value);
	x.remove(x.selectedIndex);
	$('I' + update).value = '';
	for(i=0;i<z.length;i++) {
		old = $('I' + update).value;
		$('I' + update).value = old + z.options[i].value + '|';
		old='';
	}
}

function Print(x){
 var i,strefa=document.getElementById('calosc'),
  W=strefa.getElementsByTagName('div')
 for(i=0;i<W.length;i++)
  W[i].className=x.parentNode==W[i]?'print':'noprint'
 window.print()
}

var thumbnailSize = 150;
 
function imageChange() {
 
    imgObj = new Image();
    imgObj.onload = function() {
      w = this.width; h = this.height; t = document.getElementById('imageThumbnail');
      if (w > thumbnailSize || h > thumbnailSize)
      if (w > h) {
          h = Math.round(h * thumbnailSize / w);
          w = thumbnailSize;
      } else {
          w = Math.round(w * thumbnailSize / h);
          h = thumbnailSize;
      }
      with (t.style) {
          width = w+'px';
          height = h+'px';
          display = 'inline';
      }
      t.src = "file://" + document.getElementById('imageField').value;
      document.getElementById('imageInfo').innerHTML = this.width + ' x ' + this.height;
    };
    imgObj.onerror = function() {
      document.getElementById('imageThumbnail').style.display = 'none';
      document.getElementById('imageInfo').innerHTML = 'Error';
    };
    imgObj.src = "file://" + document.getElementById('imageField').value;
}
 
function updateObjects() {
 
    inputObj = document.getElementById('imageField');
    if (document.all)
      inputObj.onchange = function() { imageChange() }; else
      inputObj.onclick = function() { imageChange() };
}

function thumbPopup(mypage, myname, w, h, caption) {
        if (caption == 'true'){
            caption_name = myname;
        }else{
            caption_name = "";
        }
        var props = '';
        var orig_w = w;
        var scroll = '1';
        var winl = (screen.availWidth - w) / 2;
        var wint = (screen.availHeight - h) / 2;
        if (winl < 0) { winl = 0; w = screen.availWidth -6; scroll = 1;}
        if (wint < 0) { wint = 0; h = screen.availHeight - 32; scroll = 1;}
        winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=yes'
        win = window.open('', 'myThumb', winprops)
        win.document.open();
        win.document.write('<html><head>');
        win.document.write('<scr' + 'ipt type="text/javascr' + 'ipt" language="JavaScr' + 'ipt">');
        win.document.write('</scr' + 'ipt>');
        win.document.write('<title>'+myname+'</title></head>');
        win.document.write('<body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0">');
        win.document.write('<img src="'+mypage+'" border="0" alt="'+myname+'">');
        win.document.write('<br />');
        win.document.write('<div align="middle">'+caption_name+'</div>');
        win.document.write('</body></html>');

        win.document.close();
        if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }

}

function one2two() {
    m1len = m1.length ;
    for ( i=0; i<m1len ; i++){
        if (m1.options[i].selected == true ) {
            m2len = m2.length;
            m2.options[m2len]= new Option(m1.options[i].text,m1.options[i].value);
        }
    }
    for ( i = (m1len -1); i>=0; i--){
        if (m1.options[i].selected == true ) {
            m1.options[i] = null;
        }
    }
}

function two2one() {
    m2len = m2.length ;
        for ( i=0; i<m2len ; i++){
            if (m2.options[i].selected == true ) {
                m1len = m1.length;
                m1.options[m1len]= new Option(m2.options[i].text,m2.options[i].value);
            }
        }
        for ( i=(m2len-1); i>=0; i--) {
            if (m2.options[i].selected == true ) {
                m2.options[i] = null;
            }
        }
}

function WystawFaktury() {
	$('UsersList').action='index.php?akcja=140,0,0,1';
	$('UsersList').submit();
}
function WyslijEmail() {
	$('UsersList').action='index.php?akcja=150,0,0,1';
	$('UsersList').submit();
}

function OpenW(url,width,height,typ)
{
	if(typ=='px') {
	    var left = screen.availWidth/2 - width/2;
    	var top = screen.availHeight/2 - height/2;
	} else {
		width = screen.availWidth * (width/100);
		height = screen.availHeight * (height/100);
	    var left = screen.availWidth/2 - width/2;
    	var top = screen.availHeight/2 - height/2;
	}
    window.open(url, "", "scrollbars=yes,width="+width+"px,height="+height+"px,left="+left+"px,top="+top+"px");
}
