var W3CDOM = (document.createElement && document.getElementsByTagName);

//wyswietla specjalny przycisk w polu fileupload formularza
function initFileUploads(RELPATH) {
	if (!W3CDOM) return;
	var fakeFileUpload = document.createElement('div');
	fakeFileUpload.className = 'fakefile';
	fakeFileUpload.appendChild(document.createElement('input'));
	var image = document.createElement('img');
	image.src= RELPATH+'gfx/przegladaj.jpg';
	fakeFileUpload.appendChild(image);
	var x = document.getElementsByTagName('input');
	for (var i=0;i<x.length;i++) {
		if (x[i].type != 'file') continue;
		if (x[i].parentNode.className != 'fileinputs') continue;
		x[i].className = 'file hidden';
		var clone = fakeFileUpload.cloneNode(true);
		x[i].parentNode.appendChild(clone);
		x[i].relatedElement = clone.getElementsByTagName('input')[0];
		x[i].onchange = x[i].onmouseout = function () {
			this.relatedElement.value = this.value;
		}
	}
}

//podswietlanie wierszy tabeli
function Wiersz(theRow, theNum, theAction,theAdmin,de)
{
 	var theDefaultColor = '';
 	var theMarkColor = '#565b59';
  var theCells = null;
 	var c = null;
 	var newColor = null;	
  var domDetect    = null;
  if((theMarkColor == '')  || typeof(theRow.style) == 'undefined') return false;
  if(typeof(document.getElementsByTagName) != 'undefined')  
    theCells = theRow.getElementsByTagName('td');
  else if(typeof(theRow.cells) != 'undefined')  theCells = theRow.cells;
  else return false;
  var rowCellsCnt  = theCells.length;
  if(typeof(window.opera) == 'undefined'  && typeof(theCells[0].getAttribute) != 'undefined') 
     domDetect = true;
  else 
     domDetect = false;
 	if(theAction=='over') newColor = theMarkColor;
 	else if(theAction=='out' || theAction=='click') newColor = theDefaultColor;
 	if(domDetect) 
 	  for (c = 0; c < rowCellsCnt; c++) 
 			  theCells[c].setAttribute('bgcolor', newColor, 0);
 	else 
 		 for (c = 0; c < rowCellsCnt; c++) 
 			  theCells[c].style.backgroundColor = newColor;
 	if(theAction=='click'){
 		 if(theAdmin) window.location.href = 'index.php?edit='+theNum+(de?'&lang=DE':'');
 		 else window.location.href = 'index.php?show='+theNum+(de?'&lang=DE':'');
 	}
  return true;
}

//proste sprawdzenie poprawnosci wprowadzonych danych przy wysylaniu meila
function SprawdzKontakt(form){
 	var error = '';
 	if(form.elements['Email[name]'].value=="") error ='Proszę wpisać imię i nazwisko';
 	else if(form.elements['Email[tresc]'].value=="") error = 'Proszę wpisać treść wiadomości';
 	else if(form.elements['Email[telefon]'].value=="" && 
 			form.elements['Email[fax]'].value=="" && form.elements['Email[mail]'].value=="") 
 		error = 'Proszę podać telefon, fax lub e-mail';
 	if(error!='') alert(error);
 	else form.submit();
}
