
function getElement(elementID)
{
	if (document.all)
		return document.all[elementID];
	else if (document.getElementById)
		return document.getElementById(elementID);
	else
		return false;
}

function choseWordForm( value, wordform1, wordform2, wordform3 )
{
	wordform = wordform3;

	valueStr = new String( value );
	lastDigit = valueStr.substring(-1,1);

	if(value==1)
		wordform = wordform1;
	else if(value==12 || value==13 || value==14 || lastDigit==0 || lastDigit==1 || lastDigit==5 || lastDigit==6 || lastDigit==7 || lastDigit==8 || lastDigit==9)
		wordform = wordform3;
	else if(lastDigit==2 || lastDigit==3 || lastDigit==4)
		wordform = wordform2;

	return wordform;
}


function setButtonStyle(button,state,size)
{
	var isObject = typeof button == 'object';
	
  	style = isObject ? button.style : eval(button+".style");

	var imageName = size > 0 && size < 4 ? "button0" + size : "button01";
    style.backgroundImage = state=='on' ? "url(cms/images/buttons/"+imageName+"_b.gif)" : "url(cms/images/buttons/"+imageName+"_a.gif)";
}


//
// Otwiera nowe okno popup.
//
function openPopupWindow(strName, strLocation, width, height)
{
	if ( strLocation.indexOf("popup=1")<0 )
	{
		// dodaj popup=1 do URL'a
		if ( strLocation.indexOf('?') >=0 )
			strLocation += "&popup=1";
		else
			strLocation += "?popup=1";
	}
	var popupWindow = window.open(strLocation, strName, 'toolbar=no, location=no, height='+height+', width='+width+', '+
		'status=no, menubar=no, scrollbars=yes, resizable=yes, top=' +
		(window.screen.height/2 - height/2) + ', left=' + (window.screen.width/2 - width/2));
	//setTimeout("popupWindow.focus()", 1000);
	popupWindow.focus();
	return popupWindow;
}

//
// Otwiera nowe okno popup. Uzywane przez modul linkman.
//
function linkmanOpenPopup(windowName, location, options)
{
	if ( location.indexOf("popup=1")<0 )
	{
		// dodaj popup=1 do URL'a
		if ( location.indexOf('?') >=0 )
			location += "&popup=1";
		else
			location += "?popup=1";
	}
	var popupWindow = window.open(location, windowName, options);
	//setTimeout("popupWindow.focus()", 1000);
	popupWindow.focus();
	return popupWindow;
}

//--------------------------------------

//
// Funkcje związane z parsowaniem i formatowaniem daty.
//

//
// Dodaje dni do daty.
//
function addDaysToDate(date, numOfDays)
{
	return new Date(date.getFullYear(), date.getMonth(), date.getDate()+numOfDays);
}

//
// Zamienia string w formacie YYYY-MM-DD na obiekt typu Date.
//
function parseDate(dateString)
{
	var str = new String(dateString);
	var array = str.split('-');
	if (array.length!=3)
		return null;
	var year = array[0];
	var month = array[1].charAt(0)=='0' ? parseInt(array[1].substr(1, 1)) : parseInt(array[1]);
	var day = array[2].charAt(0)=='0' ? parseInt(array[2].substr(1, 1)) : parseInt(array[2]);
	var date = new Date(year, month-1, day);
	if (isNaN(date))
		return null;
	date.setHours(0);
	date.setMinutes(0);
	date.setSeconds(0);
	date.setMilliseconds(0);
	return date;
}

//
// Zamienia obiekt Date na string w formacie YYYY-MM-DD.
//
function formatDate(date)
{
	return date.getFullYear() + "-" + formatDatePart(date.getMonth()+1) +
		"-" + formatDatePart(date.getDate());
}

//
// Funkcja pomocnicza dla funckcji formatDate(). Dodaje znak '0' do czesci daty.
//
function formatDatePart(value)
{
	var v = String(value);
	return v.length==1 ? "0"+v : v;
}

//--------------------------------------

//
// Rożne funkcje pomocnicze.
//

//
// Ustawia wartość elementu typu select (rozwijana lista).
//
function setSelectValue( select , valueToSelect )
{
	if( !select.options )
		return;

	var count = select.options.length;

	for( var i=0; i<count; i++ )
	{
		if( select.options[i].value == valueToSelect )
		{
			select.selectedIndex = i;
			break;
		}
	}
}

function button(name, isOver, isKoszyk) {
	var side = new Array ('L', 'M', 'R');
	if (isOver) {
		over = 'over_';
		padding = 3;
	} else {
		over = '';
		padding = 2;
	}
	if (isKoszyk)
		koszyk = 'koszyk_';
	else
		koszyk = '';

	for (var i = 0; i < side.length; i++)
		document.getElementById('button_' + name + '_' + side[i]).style.backgroundImage = 'url(cms/images/buttons/button_' + koszyk + over + side[i] + '.gif)';
	document.getElementById('button_' + name + '_M_inner').style.paddingTop = padding + 'px';
}

