
var arrOpenedWindows = new Array();

function openWindow(file, name, width, height, blnClosePrevious)
{
	if (blnClosePrevious == true && window.arrOpenedWindows[name] && window.arrOpenedWindows[name].close)
	{
		window.arrOpenedWindows[name].close();
	}
	t = window.open(file, name, 'toolbar=no, menubar=no, scrollbars=no, resizable=yes, status=no, location=no, directories=no, top=60, left=100, width=' + width + ', height=' + height);
	t.focus();
	arrOpenedWindows[name] = t;
}

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;

/*
	t = window.open('', name, 'toolbar=no, menubar=no, scrollbars=no, resizable=yes, status=no, location=no, directories=no, top=60, left=100, width=' + (width + 15) + ', height=' + (height + 15));
	t.focus();
	
	t.document.write('<html><head><title>' + title + '</title></head><body marginleft="0" margintop="0" marginright="0" marginbottom="0" style="padding: 0px; margin: 0px; ">');
	t.document.write('<a href="javascript:window.close();" onclick="window.close(); return false;"><img src="' + file + '" border="0" style="margin: 5px; " /></a>');
	t.document.write('</body></html>');

	arrOpenedWindows[name] = t;
*/
}

function getElem(elemID)
{
	if (window.document.all)
	{
		return(window.document.all[elemID]);
	}
	else
	if (window.document.layers)
	{
		return(window.document.layers[elemID]);
	}
	else
	if (window.document.getElementById)
	{
		return(window.document.getElementById(elemID));
	}
}///~ getElem()


/**
 	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;
		}

	}
}///~ checkRequiredFeatures()


function validateRegisterForm(formObject)
{
	validateRegisterFormErrors;
	return true;
}///~ validateRegisterForm()

var productsCompareResultsWindow = null;
function productsCompareShowResultsWindow(formObject, strOnLessThanTwo)
{
	// Najpierw sprawdzamy ile zaznaczono produktow.
	var blnChecked = 0;
	if (window.productsCompareIDs)
	{
	  for (i in productsCompareIDs)
	  {
	    if (formObject['compareProducts[' + i + ']'] && formObject['compareProducts[' + i + ']'].checked)
	    {
	      blnChecked++;
			}
	  }
	  if (blnChecked < 2)
	  {
	    window.alert(strOnLessThanTwo);
	    return false;
	  }
	}

  features = 'left=10, top=10, scrollbars=1, status=1, resizable=1, width=800, height=600';
  productsCompareResultsWindow = window.open('', formObject.target, features);
  if (productsCompareResultsWindow.focus)
  {
    productsCompareResultsWindow.focus();
  }
  return true;
}///~ productsCompareShowResultsWindow()

// Dziala podobnie jak PHP-owa array_search()
function array_search(mixNeedle, arrStack)
{
	if (!arrStack.length)
	{
	  return false;
	}
	for (i in arrStack)
	{
	  if (arrStack[i] == mixNeedle)
	  {
	    return i;
	  }
	}
  return -1;
}

function whBackLink(strTextGoBack)
{
	if (window.history.length)
	{
		return '<a href="javascript:window.history.back(); ">' + strTextGoBack + '</a>';
	}
	else
	{
	  return '';
	}
}///~ whBackLink()

function addToPlaylistClick(intPlaylistId, intFormatId, intFormId, strCheckText, strURL)
{
	var strURLAdd = '';
	strURLAdd += 'addToPlaylist=' + intPlaylistId;
	var blnChecked = false;

	var objForm = document.getElementById(intFormId);

	if (objForm['checkbox_addToPlaylist[]'].length)
	{
		for (i = 0; i < objForm['checkbox_addToPlaylist[]'].length; i++)
		{
		  if (objForm['checkbox_addToPlaylist[]'][i].checked)
		  {
				strURLAdd += ',' + objForm['checkbox_addToPlaylist[]'][i].value;
				blnChecked = true;
			}
		}
	}
	else
	{
	  if (objForm['checkbox_addToPlaylist[]'].checked)
	  {
			strURLAdd += ',' + objForm['checkbox_addToPlaylist[]'].value;
			blnChecked = true;
		}
	}
	if (!blnChecked)
	{
	  alert(strCheckText);
	}
	else
	{
		document.location = strURL + strURLAdd;
	}
}
