function onItemClick() {
  var li = this.parentNode;
  if (! li) return true;
  li.className = (li.className.indexOf('expanded') == -1) ? li.className+' expanded' : li.className.replace('expanded','');
  return false;
}
function activateMenu() {
  var arr = Array('submenu','submenu2');
  for( m = 0; m < arr.length; m++ ) {
    var menu = document.getElementById( arr[m] );
    if (! menu) continue;
    var a = menu.getElementsByTagName('A');
    for ( var i=0; i<a.length; i++ ) {
      var tag = a[i].nextSibling;
      // jeśli tekst to pobierz następny element
      if (tag && tag.nodeType == 3) tag = tag.nextSibling;
      // jeśli element listy zawiera podlistę
      if (tag && tag.tagName == 'UL') {
        a[i].onclick = onItemClick;
      }
    }
  }
}

// funkcja przełącza TabSheet
function changeTabSheet() {
  if ((!this) || (this.className == 'front')) return false;
  var ul = this.parentNode;
  var li = ul.getElementsByTagName('LI');
  for (var i=0; i<li.length; i++ ) {
    li[i].className = (li[i]==this) ? li[i].className.replace('back','front') : li[i].className.replace('front','back');
    var pg = document.getElementById('page'+i);
    if (pg) {
      pg.className = (li[i]==this)? pg.className.replace('back','front') : pg.className.replace('front','back');
    }
  }
  return false;
}
function activateTabSheet() {
  var ul = document.getElementsByTagName('UL');
  for( i=0; i<ul.length; i++ ) {
    if (ul[i].className != 'tabs') continue;
    var li = ul[i].getElementsByTagName('LI');
    for( j=0; j<li.length; j++ )
      li[j].onclick = changeTabSheet;
  }
}


window.onload = function() {
  activateMenu();
  activateTabSheet();
}

var arrOpenedWindows = new Array();
function openPhotoWindow(file, name, width, height)
{
	var intLeft = 0;
	var intTop = 0;
	var strScrollbars = 'no';
	
	width += 20;
	height += 80;
	
	if (navigator.userAgent.indexOf("Opera") != -1)
	{
		// Mamy Opere, wiec punkt (0,0) znajduje sie w lewym gornym rogu okna MDI.
		if (height > window.innerHeight - intTop)
		{
			height = window.innerHeight - intTop;
			width += 30;
			strScrollbars = 'yes';
			file += '&scrolling=yes';
		}
	}
	else
	{
		if (height > screen.height - intTop - 50)
		{
			height = screen.height - intTop - 50;
			width += 30;
			strScrollbars = 'yes';
			file += '&scrolling=yes';
		}
	}

	if (width > screen.width - intLeft - 10)
	{
		width = screen.width - intLeft - 10;
		strScrollbars = 'yes';
		file += '&scrolling=yes';
	}

	if (window.arrOpenedWindows[name] && window.arrOpenedWindows[name].close)
	{
		window.arrOpenedWindows[name].close();
	}
	else
	{
		t = window.open('', name, 'toolbar=no, menubar=no, scrollbars=' + strScrollbars + ', resizable=yes, status=no, location=no, directories=no, left=' + intLeft + ', top=' + intTop + ', width=' + width + ', height=' + height);
		t.close();
	}

	t = window.open(file, name, 'toolbar=no, menubar=no, scrollbars=' + strScrollbars + ', resizable=yes, status=no, location=no, directories=no, left=' + intLeft + ', top=' + intTop + ', width=' + width + ', height=' + height);
	t.resizeTo(width, height);
	t.focus();
	arrOpenedWindows[name] = t;

}

/**
 	Sprawdza, czy zaznaczono wymagane checkboxy przy dodawaniu produktu do koszyka.
 	*/
function checkRequiredFeatures(formObject, txt)
{
	if (window.requiredFeatures && window.checkedFeatures)
	{
		var missingFeatures = new Array();
		
		for (featureID in requiredFeatures)
		{
			if (window.checkedFeatures[featureID] && checkedFeatures[featureID] <= 0)
			{
				missingFeatures[missingFeatures.length] = requiredFeatures[featureID];
			}
		}
		
		if (missingFeatures.length)
		{
			var strReturn = new String('');
			strReturn = txt + ' ' + missingFeatures.join(', ') + '.';
			window.alert(strReturn);
			return false;
		}
	}
	return true;
}///~ checkRequiredFeatures()



