	/* hides <select> and <applet> objects (for IE only) */
	function hideElement( elmID, overDiv ) {
		var ie  = document.all;
		if(ie) {
			for(i = 0; i < document.all.tags( elmID ).length; i++) {
				obj = document.all.tags( elmID )[i];
				if(!obj || !obj.offsetParent) continue;

				// Find the element's offsetTop and offsetLeft relative to the BODY tag.
				objLeft   = obj.offsetLeft;
				objTop    = obj.offsetTop;
				objParent = obj.offsetParent;

				while(objParent.tagName.toUpperCase() != 'BODY') {
					objLeft  += objParent.offsetLeft;
					objTop   += objParent.offsetTop;
					objParent = objParent.offsetParent;
				}

				objHeight = obj.offsetHeight;
				objWidth  = obj.offsetWidth;

				if((overDiv.offsetLeft + overDiv.offsetWidth) <= objLeft);
				else if((overDiv.offsetTop + overDiv.offsetHeight) <= objTop);
				/* CHANGE by Charlie Roche for nested TDs*/
				else if(overDiv.offsetTop >= (objTop + objHeight + obj.height));
				/* END CHANGE */
				else if(overDiv.offsetLeft >= (objLeft + objWidth));
				else {
					obj.style.visibility = 'hidden';
				}
			}
		}
	}

	/*
	* unhides <select> and <applet> objects (for IE only)
	*/
	function showElement(elmID) {
		var ie  = document.all;
		if(ie) {
			for(i = 0; i < document.all.tags( elmID ).length; i++) {
				obj = document.all.tags(elmID)[i];
				if(!obj || !obj.offsetParent) continue;
				obj.style.visibility = '';
			}
		}
	}

//Blokada submita
function blokuj(f) {
  if (f.wyslane) { alert("Dane są już wysłane"); return false;}
  f.wyslane=true; 
  return true;
}

//Poprawnosc NIP

function nrnip(nip) {

var data = nip.value
if (data.length > 0)
{

  nip1 = nip.value.replace(/[^0-9]/g,"");

  suma = 0;
  if (nip1.length!=10) {
    alert("NIP błędny, wpisz ponownie")
		nip.focus()

	nip.select()
    return false;

  }
  wagi = new Array(6,5,7,2,3,4,5,6,7);
  for (i=0;i<9;i++) suma += nip1.charAt(i)*wagi[i];
  if ((suma%11)!=nip1.charAt(9)) 
	{
		nip.focus()

	nip.select()
 	 alert("NIP błędny, wpisz ponownie")

	return false;

	}
}
return true;
}
//Pole procent dozwolone liczby i znak %
function checkPercent(evt) {
	evt = (evt) ? evt : window.event

	if  ( window.event.keyCode == 44) {
		window.event.keyCode = 46
		}

	var charCode = (evt.which) ? evt.which : evt.keyCode

		if ((charCode != 46) ) {
	if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 37) {
		window.alert('Dozwolone tylko liczby i znak %')
		return false
	}
	}


	status = ""
	return true
}	


//Pole liczba -  dozwolone liczby i znak -
function checkLiczba(evt) {
	evt = (evt) ? evt : window.event

	if  ( window.event.keyCode == 44) {
		window.event.keyCode = 46
		}

	var charCode = (evt.which) ? evt.which : evt.keyCode

		if ((charCode != 46) && (charCode != 45)) {
	if (charCode > 31 && (charCode < 48 || charCode > 57)) {
		window.alert('Dozwolone tylko liczby')
		return false
	}
	}


	status = ""
	return true
}	


//sprawdza kod pocztowy i wstawia kreske po dwoch znakach, dozwolone tylko liczby
function checkKod(evt,$obj) {

	var $length = $obj.value.length 
	if ($length > 5) 
	return false
	
	evt = (evt) ? evt : window.event
	var charCode = (evt.which) ? evt.which : evt.keyCode

	if (charCode > 31 && (charCode < 48 || charCode > 57)) {
		status = "Dozwolone tylko liczby"
		return false
	}
	
	

	
	if ($length ==  2) {
	$temp = $obj.value
	$temp = $temp + "-"
	$obj.value = $temp
	
	}
	

	status = ""
	return true
}		

//wstawia kursor w pierwsze pole 2 formularza na stronie

function secondFocus() {

if (document.forms[1]) {
var field = document.forms[1];

   if(document.getElementById('przycisk_wywolujacy_formularz_nowego_zasobu')){
      obj = 1;
      return (obj && obj.style);
   }

		for (i = 0; i < field.length; i++) {
		if ((field.elements[i].disabled==false) && ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s"))) {
		


		document.forms[1].elements[i].focus();
		break;
		
			
         }
      }
   }
}



//Sprawdzanie daty

// sprawdzanie miesiecy

function checkMonthLength(mm,dd) {

	var months = new Array("","styczen","luty","marzec","kwiecien","maj","czerwiec","lipiec","sierpien","wrzesien","pazdziernik","listopad","grudzien")

	if ((mm == 4 || mm == 6 || mm == 9 || mm == 11) && dd > 30) {

		alert(months[mm] + " ma tylko 30 dni.")

		return false

	} else if (dd > 31) {

		alert(months[mm] + " ma tylko 31 dni.")

		return false

	}

	return true

}



// Test lutego

function checkLeapMonth(mm,dd,yyyy) {

	if (yyyy % 4 > 0 && dd > 28) {

		alert("Luty w roku " + yyyy + " ma tylko  28 dni.")

		return false

	} else if (dd > 29) {

		alert("Luty w roku " + yyyy + " ma tylko 29 dni.")

		return false

	}

	return true

}


//sprawdzanie formatu
function sprDate(obj){

if(obj.value)
{

var gField = obj.value;

var delim1 = gField.indexOf("-")

var delim2 = gField.lastIndexOf("-")

	if (delim1 == -1 || delim1 == delim2) {

		// tylko jedna kreska - zle

		alert("Data zostala wprowadzona w zlym formacie\n\n Prawidlowy format to YYYY-MM-DD")

		return false

	}



		var yyyy = parseInt(gField.substring(0,delim1),10)
		var mm = parseInt(gField.substring(delim1 + 1,delim2),10)
		var dd = parseInt(gField.substring(delim2 + 1, gField.length),10)


		if (isNaN(mm) || isNaN(dd) || isNaN(yyyy)) {

		// there is a non-numeric character in one of the component values

		alert("Data zostala wprowadzona w zlym formacie\n\n Prawidlowy format to YYYY-MM-DD.")

		return false

	}

	if (mm < 1 || mm > 12) {

		// month value is not 1 thru 12
		alert("Nieprawidłowa wartość miesiąca")


		return false

	}

	if (dd < 1 || dd > 31) {

		// date value is not 1 thru 31

		alert("Dzień musi mieć wartość między 1 a 31")


		return false

	}

	

	if (yyyy < 1990 || yyyy > 2050) {

		// date value is not 1 thru 31
		alert("Nierealistyczna wartość roku")
		return false
	}

	

	if (!checkMonthLength(mm,dd)) {
		return false
	}

	if (mm == 2) {
		if (!checkLeapMonth(mm,dd,yyyy)) {
			return false
		}
	}
}
	return true;

}




//Sprawdz poprawnosc formatu daty


function isValidDate(gField){

var data = gField.value

if (data.length > 0) {

	
	

if (!sprDate(gField)){

		gField.focus()

	gField.select()



	return false	



	}	
}
		

return true

}

function sortuj(k) {
  posortowane=false;
  tr = document.getElementById("tabela").childNodes[0].childNodes;
  while (!posortowane) {
    posortowane=true;
    for (i=1;i<tr.length-1;i++) {
      if (tr[i].childNodes[k].childNodes[0].nodeValue>
        tr[i+1].childNodes[k].childNodes[0].nodeValue) {
        posortowane=false;
        for (j=0;j<tr[i].childNodes.length;j++) {
          tmp = tr[i].childNodes[j].firstChild.nodeValue;
          tr[i].childNodes[j].firstChild.nodeValue 
            = tr[i+1].childNodes[j].firstChild.nodeValue;
          tr[i+1].childNodes[j].firstChild.nodeValue = tmp;
        }
      }
    }
  }
}

var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);

function addOption(theSel, theText, theValue)
{
  var newOpt = new Option(theText, theValue);
  var selLength = theSel.length;
  theSel.options[selLength] = newOpt;
}

function deleteOption(theSel, theIndex)
{ 
  var selLength = theSel.length;
  if(selLength>0)
  {
    theSel.options[theIndex] = null;
  }
}

function moveOptions(theSelFrom, theSelTo)
{
  
  var selLength = theSelFrom.length;
  var selectedText = new Array();
  var selectedValues = new Array();
  var selectedCount = 0;
  
  var i;
  
  // Find the selected Options in reverse order
  // and delete them from the 'from' Select.
  for(i=selLength-1; i>=0; i--)
  {
    if(theSelFrom.options[i].selected)
    {
      selectedText[selectedCount] = theSelFrom.options[i].text;
      selectedValues[selectedCount] = theSelFrom.options[i].value;
      deleteOption(theSelFrom, i);
      selectedCount++;
    }
  }
  
  // Add the selected text/values in reverse order.
  // This will add the Options to the 'to' Select
  // in the same order as they were in the 'from' Select.
  for(i=selectedCount-1; i>=0; i--)
  {
    addOption(theSelTo, selectedText[i], selectedValues[i]);
  }	
  
  if(NS4) history.go(0);
}


function moveOptions_rzedy(theSelFrom, theSelTo)
{
  
  var selLength = theSelFrom.length;
  var selectedText = new Array();
  var selectedValues = new Array();
  var selectedCount = 0;
  
  var i;
  
  // Find the selected Options in reverse order
  // and delete them from the 'from' Select.
  for(i=selLength-1; i>=0; i--)
  {
    if(theSelFrom.options[i].selected)
    {
      selectedText[selectedCount] = theSelFrom.options[i].text;
      selectedValues[selectedCount] = theSelFrom.options[i].value;
      deleteOption(theSelFrom, i);
      selectedCount++;
    }
  }
  
  // Add the selected text/values in reverse order.
  // This will add the Options to the 'to' Select
  // in the same order as they were in the 'from' Select.
  for(i=selectedCount-1; i>=0; i--)
  {
    addOption(theSelTo, selectedText[i], selectedValues[i]);

	if(theSelTo.name=='uczestnicy[]')
		{
			addRow('mytable','myrow', selectedValues[i],selectedText[i]);
		}
	else
		{
			removeRow('mytable',selectedValues[i])
		}
  }	
  
  if(NS4) history.go(0);
}
function selectAllOptions(selStr)
{
  var selObj = document.getElementById(selStr);
  for (var i=0; i<selObj.options.length; i++) {
    selObj.options[i].selected = true;
  }
}

var type = "IE";	//Variable used to hold the browser name

BrowserSniffer();

//detects the capabilities of the browser
function BrowserSniffer() {
	if (navigator.userAgent.indexOf("Opera")!=-1 && document.getElementById) type="OP";		//Opera
	else if (document.all) type="IE";														//Internet Explorer e.g. IE4 upwards
	else if (document.layers) type="NN";													//Netscape Communicator 4
	else if (!document.all && document.getElementById) type="MO";							//Mozila e.g. Netscape 6 upwards
	else type = "IE";		//I assume it will not get here
}

function ShowLayer_bezukrywania(id, action){

if(type=="IE") {


}
	if (type=="IE") eval("document.all." + id + ".style.display='" + action + "'");
	if (type=="NN") eval("document." + id + ".display='" + action + "'");
	if (type=="MO" || type=="OP") eval("document.getElementById('" + id + "').style.display='" + action + "'");
}

//wstawia focus na pierwszym elemencie drugiego formularza
function placeFocus(nazwa) {
if (document.forms.length > 0) {

var field = document.forms[''+nazwa+''];

for (i = 0; i < field.length; i++) {
if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s")) {
document.forms[''+nazwa+''].elements[i].focus();
break;
         }
      }
   }
}
