// JavaScript Document
var popUpWin=0;
function popUp(URLStr, width, height)
{
  var left = (screen.width/2) - width/2;
  var top = (screen.height/2) - height/2;
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function OW(url, w, h) { 
	x=(window.screen.width/2)-(w/2);
	y=(window.screen.height/2)-(h/2);
	window.open(url, '_blank','scrollbars=0,width='+w+',height='+h+',top='+y+',left='+x+', toolbar=no,location=no,status=no,menubar=no,resizable=no');
  history.go(-1);
}

function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}

function sprawdz() {
	obj_czymulti = findObj('czy_multi');
	obj_layermulti = findObj('layermulti');
	if (obj_czymulti.checked) obj_layermulti.style.display = '';
	else obj_layermulti.style.display = 'none';
	for (i=0; i<dzialy.length; i++) {
		obj_lay = findObj('layer'+dzialy[i]);
		obj_czy = findObj('czy'+dzialy[i]);
		if (obj_czymulti.checked) {
			obj_lay.style.display = 'none';
		} else {
			if (obj_czy.checked) obj_lay.style.display = '';
			else obj_lay.style.display = 'none';
		}
	}
}

function wyslij() {
	
	var dzial_zaznaczony = false;
	obj_multi = findObj('multi');
	if (findObj('czy_multi').checked) {
		if (obj_multi.value == '') {
			alert('Nie zadano pytania !!!');
			obj_multi.focus();
			return false;
		}
		for (i=0; i<dzialy.length; i++) {
			if (findObj('czy'+dzialy[i]).checked) {
				dzial_zaznaczony = true;
			}
		}
	} else {
		for (i=0; i<dzialy.length; i++) {
			if (findObj('czy'+dzialy[i]).checked) {
				if (findObj('zapytanie'+dzialy[i]).value == '') {
					alert('Nie zadano pytania do wybranego działu');
					findObj('zapytanie'+dzialy[i]).focus();
					return false;
				}
				dzial_zaznaczony = true;
			}
		}
	}
	if (!dzial_zaznaczony) {
		alert('Wybierz dział do którego kierujesz zapytanie');
		return false;
	}
	
for (i=0; i<wymagane.length; i++) {
	obj_wym = findObj(wymagane[i]);
	if (obj_wym.value == '') {
		alert ('Wszystkie pola z danymi wymaganymi (*) muszą być wypełnione');
		obj_wym.focus();
		return false;
	}
}
	
findObj('form1').submit();
}